@@ -294,8 +294,29 @@ let nan_bitmask_of = function
294
294
| CanonicalNan -> abs_mask_of (* differ from canonical NaN in sign bit *)
295
295
| ArithmeticNan -> canonical_nan_of (* 1 everywhere canonical NaN is *)
296
296
297
+ let type_of_num_pat = function
298
+ | NumPat num -> Value. type_of_num num.it
299
+ | NanPat op -> Value. type_of_op op.it
300
+
301
+ let type_of_vec_pat = function
302
+ | VecPat vec -> Value. type_of_vec vec
303
+
304
+ let type_of_ref_pat = function
305
+ | RefPat ref -> type_of_ref ref .it
306
+ | RefTypePat ht -> (NoNull , ht)
307
+ | NullPat -> (Null , BotHT )
308
+
309
+ let type_of_result res =
310
+ match res.it with
311
+ | NumResult pat -> NumT (type_of_num_pat pat)
312
+ | VecResult pat -> VecT (type_of_vec_pat pat)
313
+ | RefResult pat -> RefT (type_of_ref_pat pat)
314
+
297
315
let assert_return ress ts at =
298
316
let test (res , t ) =
317
+ if not (Match. match_val_type [] t (type_of_result res)) then
318
+ [ Br (0l @@ at) @@ at ]
319
+ else
299
320
match res.it with
300
321
| NumResult (NumPat {it = num ; at = at' } ) ->
301
322
let t', reinterpret = reinterpret_of (Value. type_of_op num) in
@@ -362,7 +383,7 @@ let assert_return ress ts at =
362
383
VecTest (V128 (V128. I8x16 V128Op. AllTrue )) @@ at;
363
384
Test (I32 I32Op. Eqz ) @@ at;
364
385
BrIf (0l @@ at) @@ at ]
365
- | RefResult (RefPat {it = NullRef t ; _} ) ->
386
+ | RefResult (RefPat {it = NullRef _ ; _} ) ->
366
387
[ RefIsNull @@ at;
367
388
Test (Value. I32 I32Op. Eqz ) @@ at;
368
389
BrIf (0l @@ at) @@ at ]
@@ -374,17 +395,16 @@ let assert_return ress ts at =
374
395
BrIf (0l @@ at) @@ at ]
375
396
| RefResult (RefPat _ ) ->
376
397
assert false
398
+ | RefResult (RefTypePat (ExnHT | ExternHT )) ->
399
+ [ BrOnNull (0l @@ at) @@ at ]
377
400
| RefResult (RefTypePat t ) ->
378
401
[ RefTest (NoNull , t) @@ at;
379
402
Test (I32 I32Op. Eqz ) @@ at;
380
403
BrIf (0l @@ at) @@ at ]
381
404
| RefResult NullPat ->
382
- (match t with
383
- | RefT _ ->
384
- [ BrOnNull (0l @@ at) @@ at ]
385
- | _ ->
386
- [ Br (0l @@ at) @@ at ]
387
- )
405
+ [ RefIsNull @@ at;
406
+ Test (I32 I32Op. Eqz ) @@ at;
407
+ BrIf (0l @@ at) @@ at ]
388
408
in [] , List. flatten (List. rev_map test (List. combine ress ts))
389
409
390
410
let i32 = NumT I32T
@@ -431,10 +451,17 @@ let is_js_num_type = function
431
451
| I32T -> true
432
452
| I64T | F32T | F64T -> false
433
453
454
+ let is_js_vec_type = function
455
+ | _ -> false
456
+
457
+ let is_js_ref_type = function
458
+ | (_ , ExnHT) -> false
459
+ | _ -> true
460
+
434
461
let is_js_val_type = function
435
462
| NumT t -> is_js_num_type t
436
- | VecT _ -> false
437
- | RefT _ -> true
463
+ | VecT t -> is_js_vec_type t
464
+ | RefT t -> is_js_ref_type t
438
465
| BotT -> assert false
439
466
440
467
let is_js_global_type = function
0 commit comments