@@ -289,8 +289,29 @@ let nan_bitmask_of = function
289
289
| CanonicalNan -> abs_mask_of (* differ from canonical NaN in sign bit *)
290
290
| ArithmeticNan -> canonical_nan_of (* 1 everywhere canonical NaN is *)
291
291
292
+ let type_of_num_pat = function
293
+ | NumPat num -> Value. type_of_num num.it
294
+ | NanPat op -> Value. type_of_op op.it
295
+
296
+ let type_of_vec_pat = function
297
+ | VecPat vec -> Value. type_of_vec vec
298
+
299
+ let type_of_ref_pat = function
300
+ | RefPat ref -> type_of_ref ref .it
301
+ | RefTypePat ht -> (NoNull , ht)
302
+ | NullPat -> (Null , BotHT )
303
+
304
+ let type_of_result res =
305
+ match res.it with
306
+ | NumResult pat -> NumT (type_of_num_pat pat)
307
+ | VecResult pat -> VecT (type_of_vec_pat pat)
308
+ | RefResult pat -> RefT (type_of_ref_pat pat)
309
+
292
310
let assert_return ress ts at =
293
311
let test (res , t ) =
312
+ if not (Match. match_val_type [] t (type_of_result res)) then
313
+ [ Br (0l @@ at) @@ at ]
314
+ else
294
315
match res.it with
295
316
| NumResult (NumPat {it = num ; at = at' } ) ->
296
317
let t', reinterpret = reinterpret_of (Value. type_of_op num) in
@@ -357,7 +378,7 @@ let assert_return ress ts at =
357
378
VecTest (V128 (V128. I8x16 V128Op. AllTrue )) @@ at;
358
379
Test (I32 I32Op. Eqz ) @@ at;
359
380
BrIf (0l @@ at) @@ at ]
360
- | RefResult (RefPat {it = NullRef t ; _} ) ->
381
+ | RefResult (RefPat {it = NullRef _ ; _} ) ->
361
382
[ RefIsNull @@ at;
362
383
Test (Value. I32 I32Op. Eqz ) @@ at;
363
384
BrIf (0l @@ at) @@ at ]
@@ -369,17 +390,16 @@ let assert_return ress ts at =
369
390
BrIf (0l @@ at) @@ at ]
370
391
| RefResult (RefPat _ ) ->
371
392
assert false
393
+ | RefResult (RefTypePat ExternHT) ->
394
+ [ BrOnNull (0l @@ at) @@ at ]
372
395
| RefResult (RefTypePat t ) ->
373
396
[ RefTest (NoNull , t) @@ at;
374
397
Test (I32 I32Op. Eqz ) @@ at;
375
398
BrIf (0l @@ at) @@ at ]
376
399
| RefResult NullPat ->
377
- (match t with
378
- | RefT _ ->
379
- [ BrOnNull (0l @@ at) @@ at ]
380
- | _ ->
381
- [ Br (0l @@ at) @@ at ]
382
- )
400
+ [ RefIsNull @@ at;
401
+ Test (I32 I32Op. Eqz ) @@ at;
402
+ BrIf (0l @@ at) @@ at ]
383
403
in [] , List. flatten (List. rev_map test (List. combine ress ts))
384
404
385
405
let i32 = NumT I32T
@@ -426,10 +446,16 @@ let is_js_num_type = function
426
446
| I32T -> true
427
447
| I64T | F32T | F64T -> false
428
448
449
+ let is_js_vec_type = function
450
+ | _ -> false
451
+
452
+ let is_js_ref_type = function
453
+ | _ -> true
454
+
429
455
let is_js_val_type = function
430
456
| NumT t -> is_js_num_type t
431
- | VecT _ -> false
432
- | RefT _ -> true
457
+ | VecT t -> is_js_vec_type t
458
+ | RefT t -> is_js_ref_type t
433
459
| BotT -> assert false
434
460
435
461
let is_js_global_type = function
0 commit comments