Skip to content

Commit f8190d1

Browse files
committed
Fix JS type test wrappers
1 parent 7b731c8 commit f8190d1

File tree

2 files changed

+39
-19
lines changed

2 files changed

+39
-19
lines changed

interpreter/runtime/value.ml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,17 @@ let is_null_ref = function
9393
(* Typing *)
9494

9595
let type_of_op = function
96-
| I32 _ -> Types.I32T
97-
| I64 _ -> Types.I64T
98-
| F32 _ -> Types.F32T
99-
| F64 _ -> Types.F64T
100-
101-
let type_of_vecop = function
102-
| V128 _ -> Types.V128T
103-
104-
let type_of_num = function
10596
| I32 _ -> I32T
10697
| I64 _ -> I64T
10798
| F32 _ -> F32T
10899
| F64 _ -> F64T
109100

110-
let type_of_vec = function
101+
let type_of_vecop = function
111102
| V128 _ -> V128T
112103

104+
let type_of_num = type_of_op
105+
let type_of_vec = type_of_vecop
106+
113107
let type_of_ref' = ref (function _ -> assert false)
114108
let type_of_ref = function
115109
| NullRef t -> (Null, Match.bot_of_heap_type [] t)

interpreter/script/js.ml

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,29 @@ let nan_bitmask_of = function
289289
| CanonicalNan -> abs_mask_of (* differ from canonical NaN in sign bit *)
290290
| ArithmeticNan -> canonical_nan_of (* 1 everywhere canonical NaN is *)
291291

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+
292310
let assert_return ress ts at =
293311
let test (res, t) =
312+
if not (Match.match_val_type [] t (type_of_result res)) then
313+
[ Br (0l @@ at) @@ at ]
314+
else
294315
match res.it with
295316
| NumResult (NumPat {it = num; at = at'}) ->
296317
let t', reinterpret = reinterpret_of (Value.type_of_op num) in
@@ -357,7 +378,7 @@ let assert_return ress ts at =
357378
VecTest (V128 (V128.I8x16 V128Op.AllTrue)) @@ at;
358379
Test (I32 I32Op.Eqz) @@ at;
359380
BrIf (0l @@ at) @@ at ]
360-
| RefResult (RefPat {it = NullRef t; _}) ->
381+
| RefResult (RefPat {it = NullRef _; _}) ->
361382
[ RefIsNull @@ at;
362383
Test (Value.I32 I32Op.Eqz) @@ at;
363384
BrIf (0l @@ at) @@ at ]
@@ -369,17 +390,16 @@ let assert_return ress ts at =
369390
BrIf (0l @@ at) @@ at ]
370391
| RefResult (RefPat _) ->
371392
assert false
393+
| RefResult (RefTypePat ExternHT) ->
394+
[ BrOnNull (0l @@ at) @@ at ]
372395
| RefResult (RefTypePat t) ->
373396
[ RefTest (NoNull, t) @@ at;
374397
Test (I32 I32Op.Eqz) @@ at;
375398
BrIf (0l @@ at) @@ at ]
376399
| 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 ]
383403
in [], List.flatten (List.rev_map test (List.combine ress ts))
384404

385405
let i32 = NumT I32T
@@ -426,10 +446,16 @@ let is_js_num_type = function
426446
| I32T -> true
427447
| I64T | F32T | F64T -> false
428448

449+
let is_js_vec_type = function
450+
| _ -> false
451+
452+
let is_js_ref_type = function
453+
| _ -> true
454+
429455
let is_js_val_type = function
430456
| 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
433459
| BotT -> assert false
434460

435461
let is_js_global_type = function

0 commit comments

Comments
 (0)