@@ -268,9 +268,60 @@ export function opMathTrunc(a: EjNumber): EjNumber {
268
268
269
269
// EJson Runtime Operators
270
270
271
- // TODO: this seems to be redundant with opStrictEqual, is it?
272
271
export function runtimeEqual ( a : EjValue , b : EjValue ) : EjBool {
273
- return opStrictEqual ( a , b ) ;
272
+ if ( a instanceof EjNull && b instanceof EjNull ) {
273
+ return c_true ;
274
+ }
275
+ if ( a instanceof EjBool && b instanceof EjBool ) {
276
+ let aa : EjBool = changetype < EjBool > ( a ) ;
277
+ let bb : EjBool = changetype < EjBool > ( b ) ;
278
+ return aa . value == bb . value ? c_true : c_false ;
279
+ }
280
+ if ( a instanceof EjNumber && b instanceof EjNumber ) {
281
+ let aa : EjNumber = changetype < EjNumber > ( a ) ;
282
+ let bb : EjNumber = changetype < EjNumber > ( b ) ;
283
+ return aa . value == bb . value ? c_true : c_false ;
284
+ }
285
+ if ( a instanceof EjBigInt && b instanceof EjBigInt ) {
286
+ let aa : EjBigInt = changetype < EjBigInt > ( a ) ;
287
+ let bb : EjBigInt = changetype < EjBigInt > ( b ) ;
288
+ return aa . value == bb . value ? c_true : c_false ;
289
+ }
290
+ if ( a instanceof EjString && b instanceof EjString ) {
291
+ let aa : EjString = changetype < EjString > ( a ) ;
292
+ let bb : EjString = changetype < EjString > ( b ) ;
293
+ return aa . value == bb . value ? c_true : c_false ;
294
+ }
295
+ if ( a instanceof EjArray && b instanceof EjArray ) {
296
+ let aa : EjArray = changetype < EjArray > ( a ) ;
297
+ let bb : EjArray = changetype < EjArray > ( b ) ;
298
+ if ( aa . values . length != bb . values . length ) {
299
+ return c_false ;
300
+ }
301
+ for ( let i = 0 ; i < aa . values . length ; i ++ ) {
302
+ if ( ! runtimeEqual ( aa . values [ i ] , bb . values [ i ] ) . value ) {
303
+ return c_false ;
304
+ }
305
+ }
306
+ return c_true ;
307
+ }
308
+ if ( a instanceof EjObject && b instanceof EjObject ) {
309
+ let aa : EjObject = changetype < EjObject > ( a ) ;
310
+ let bb : EjObject = changetype < EjObject > ( b ) ;
311
+ if ( aa . values . size != bb . values . size ) {
312
+ return c_false ;
313
+ }
314
+ let keys = aa . values . keys ( ) ;
315
+ for ( let i = 0 ; i < keys . length ; i ++ ) {
316
+ let k = keys [ i ] ;
317
+ if ( ! bb . values . has ( k ) ||
318
+ ! runtimeEqual ( aa . values [ k ] , bb . values [ k ] ) . value ) {
319
+ return c_false ;
320
+ }
321
+ }
322
+ return c_true ;
323
+ }
324
+ return unreachable ( ) ;
274
325
}
275
326
276
327
function compare < T > ( a : T , b : T ) : EjNumber {
@@ -293,7 +344,38 @@ export function runtimeCompare(a: EjValue, b: EjValue): EjNumber {
293
344
return unreachable ( ) ;
294
345
}
295
346
296
- // TODO: this seems to be redundant with opAccess, is it?
297
- export function runtimeRecDot ( a : EjObject , b :EjString ) : EjValue {
298
- return opAccess ( a , b ) ;
347
+ // TODO: recConcat which argument "wins" in case of a conflict?
348
+ export function runtimeRecConcat ( a : EjObject , b :EjObject ) : EjObject {
349
+ let r = new EjObject ( ) ;
350
+ let k = a . values . keys ( ) ;
351
+ for ( let i = 0 ; i < k . length ; i ++ ) {
352
+ r . values . set ( k [ i ] , a . values . get ( k [ i ] ) ) ;
353
+ }
354
+ k = b . values . keys ( ) ;
355
+ for ( let i = 0 ; i < k . length ; i ++ ) {
356
+ r . values . set ( k [ i ] , b . values . get ( k [ i ] ) ) ;
357
+ }
358
+ return r ;
359
+ }
360
+
361
+ export function runtimeRecDot ( a : EjObject , k :EjString ) : EjValue {
362
+ // TODO: runtimeRecDot redundant with opAccess?
363
+ // TODO: runtimeRecDot: check for key not found needed?
364
+ return a . values . get ( k . value ) ;
365
+ }
366
+
367
+ export function runtimeEither ( a : EjValue ) : EjBool {
368
+ if ( a instanceof EjLeft || a instanceof EjRight ) {
369
+ return c_true ;
370
+ } else {
371
+ return c_false ;
372
+ }
373
+ }
374
+
375
+ export function runtimeToLeft ( a : EjLeft ) : EjValue {
376
+ return a . value ;
377
+ }
378
+
379
+ export function runtimeToRight ( a : EjRight ) : EjValue {
380
+ return a . value ;
299
381
}
0 commit comments