Skip to content

Commit 354c2cb

Browse files
committed
Fix JS type test wrappers
1 parent f981a51 commit 354c2cb

File tree

4 files changed

+42
-20
lines changed

4 files changed

+42
-20
lines changed

interpreter/runtime/value.ml

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

9797
let type_of_op = function
98-
| I32 _ -> Types.I32T
99-
| I64 _ -> Types.I64T
100-
| F32 _ -> Types.F32T
101-
| F64 _ -> Types.F64T
102-
103-
let type_of_vecop = function
104-
| V128 _ -> Types.V128T
105-
106-
let type_of_num = function
10798
| I32 _ -> I32T
10899
| I64 _ -> I64T
109100
| F32 _ -> F32T
110101
| F64 _ -> F64T
111102

112-
let type_of_vec = function
103+
let type_of_vecop = function
113104
| V128 _ -> V128T
114105

106+
let type_of_num = type_of_op
107+
let type_of_vec = type_of_vecop
108+
115109
let type_of_ref' = ref (function _ -> assert false)
116110
let type_of_ref = function
117111
| NullRef t -> (Null, Match.bot_of_heap_type [] t)

interpreter/script/js.ml

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

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+
297315
let assert_return ress ts at =
298316
let test (res, t) =
317+
if not (Match.match_val_type [] t (type_of_result res)) then
318+
[ Br (0l @@ at) @@ at ]
319+
else
299320
match res.it with
300321
| NumResult (NumPat {it = num; at = at'}) ->
301322
let t', reinterpret = reinterpret_of (Value.type_of_op num) in
@@ -362,7 +383,7 @@ let assert_return ress ts at =
362383
VecTest (V128 (V128.I8x16 V128Op.AllTrue)) @@ at;
363384
Test (I32 I32Op.Eqz) @@ at;
364385
BrIf (0l @@ at) @@ at ]
365-
| RefResult (RefPat {it = NullRef t; _}) ->
386+
| RefResult (RefPat {it = NullRef _; _}) ->
366387
[ RefIsNull @@ at;
367388
Test (Value.I32 I32Op.Eqz) @@ at;
368389
BrIf (0l @@ at) @@ at ]
@@ -374,17 +395,16 @@ let assert_return ress ts at =
374395
BrIf (0l @@ at) @@ at ]
375396
| RefResult (RefPat _) ->
376397
assert false
398+
| RefResult (RefTypePat (ExnHT | ExternHT)) ->
399+
[ BrOnNull (0l @@ at) @@ at ]
377400
| RefResult (RefTypePat t) ->
378401
[ RefTest (NoNull, t) @@ at;
379402
Test (I32 I32Op.Eqz) @@ at;
380403
BrIf (0l @@ at) @@ at ]
381404
| 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 ]
388408
in [], List.flatten (List.rev_map test (List.combine ress ts))
389409

390410
let i32 = NumT I32T
@@ -431,10 +451,17 @@ let is_js_num_type = function
431451
| I32T -> true
432452
| I64T | F32T | F64T -> false
433453

454+
let is_js_vec_type = function
455+
| _ -> false
456+
457+
let is_js_ref_type = function
458+
| (_, ExnHT) -> false
459+
| _ -> true
460+
434461
let is_js_val_type = function
435462
| 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
438465
| BotT -> assert false
439466

440467
let is_js_global_type = function

interpreter/script/run.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ let assert_ref_pat r p =
394394
| RefTypePat Types.StructHT, Aggr.StructRef _
395395
| RefTypePat Types.ArrayHT, Aggr.ArrayRef _ -> true
396396
| RefTypePat Types.FuncHT, Instance.FuncRef _
397+
| RefTypePat Types.ExnHT, Value.ExnRef _
397398
| RefTypePat Types.ExternHT, _ -> true
398399
| NullPat, Value.NullRef _ -> true
399400
| _ -> false

interpreter/text/parser.mly

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,7 @@ result :
14491449
| LPAR REF_STRUCT RPAR { RefResult (RefTypePat StructHT) @@ $sloc }
14501450
| LPAR REF_ARRAY RPAR { RefResult (RefTypePat ArrayHT) @@ $sloc }
14511451
| LPAR REF_FUNC RPAR { RefResult (RefTypePat FuncHT) @@ $sloc }
1452-
/*| LPAR REF_EXN RPAR { RefResult (RefTypePat ExnRefType) @@ $sloc }*/
1452+
| LPAR REF_EXN RPAR { RefResult (RefTypePat ExnHT) @@ $sloc }
14531453
| LPAR REF_EXTERN RPAR { RefResult (RefTypePat ExternHT) @@ $sloc }
14541454
| LPAR REF_NULL RPAR { RefResult NullPat @@ $sloc }
14551455
| LPAR VEC_CONST VEC_SHAPE list(numpat) RPAR

0 commit comments

Comments
 (0)