@@ -390,30 +390,33 @@ let abs_mask_of = function
390390 | I32T | F32T -> I32 Int32. max_int
391391 | I64T | F64T -> I64 Int64. max_int
392392
393- let value v t =
394- match v.it, t with
395- | Num n , _ -> [Const (n @@ v.at) @@ v.at]
396- | Vec s , _ -> [VecConst (s @@ v.at) @@ v.at]
397- | Ref NullRef , (RefT (_ , ht )) ->
398- [ RefNull (Match. bot_of_heaptype [] ht) @@ v.at ]
399- | Ref (HostRef n ), _ ->
400- [ Const (I32 n @@ v.at) @@ v.at;
401- Call (hostref_idx @@ v.at) @@ v.at;
393+ let value v at =
394+ match v with
395+ | Num n -> [Const (n @@ at) @@ at]
396+ | Vec s -> [VecConst (s @@ at) @@ at]
397+ | Ref (HostRef n ) ->
398+ [ Const (I32 n @@ at) @@ at;
399+ Call (hostref_idx @@ at) @@ at;
402400 ]
403- | Ref (Extern. ExternRef (HostRef n )), _ ->
404- [ Const (I32 n @@ v. at) @@ v. at;
405- Call (hostref_idx @@ v. at) @@ v. at;
406- ExternConvert Externalize @@ v. at;
401+ | Ref (Extern. ExternRef (HostRef n )) ->
402+ [ Const (I32 n @@ at) @@ at;
403+ Call (hostref_idx @@ at) @@ at;
404+ ExternConvert Externalize @@ at;
407405 ]
408- | Ref _ , _ -> assert false
406+ | Ref _ -> assert false
407+
408+ let literal lit =
409+ match lit.it with
410+ | ValLit v -> value v lit.at
411+ | NullLit ht -> [RefNull (Match. bot_of_heaptype [] ht) @@ lit.at]
409412
410- let invoke dt vs ts at =
413+ let invoke dt lits at =
411414 let dummy = RecT [SubT (Final , [] , FuncT ([] , [] ))] in
412415 let rts0 = Lib.List32. init subject_type_idx (fun i -> dummy, (dummy, i)) in
413416 let rts, i = statify_deftype rts0 dt in
414417 List. map (fun (_ , (rt , _ )) -> rt @@ at) (Lib.List32. drop subject_type_idx rts),
415418 ExternFuncT (Idx i),
416- List. concat (List. map2 value vs ts ) @ [Call (subject_idx @@ at) @@ at]
419+ List. concat (List. map literal lits ) @ [Call (subject_idx @@ at) @@ at]
417420
418421let get t at =
419422 [] , ExternGlobalT t, [GlobalGet (subject_idx @@ at) @@ at]
@@ -435,6 +438,7 @@ let type_of_vec_pat = function
435438let type_of_ref_pat = function
436439 | RefPat ref -> type_of_ref ref .it
437440 | RefTypePat ht -> (NoNull , ht)
441+ | NullPat ht -> (Null , ht)
438442
439443let rec type_of_result res =
440444 match res.it with
@@ -554,6 +558,10 @@ let assert_return ress ts at =
554558 [ RefTest (NoNull , t) @@ at;
555559 Test (I32 I32Op. Eqz ) @@ at;
556560 BrIf (0l @@ at) @@ at ]
561+ | RefResult (NullPat _ ) ->
562+ [ RefIsNull @@ at;
563+ Test (I32 I32Op. Eqz ) @@ at;
564+ BrIf (0l @@ at) @@ at ]
557565 | EitherResult ress ->
558566 let idx = Lib.List32. length ! locals in
559567 locals := ! locals @ [Local t @@ res.at];
@@ -704,12 +712,17 @@ let of_ref r =
704712 | HostRef n | Extern. ExternRef (HostRef n ) -> " hostref(" ^ Int32. to_string n ^ " )"
705713 | _ -> assert false
706714
707- let of_value v =
708- match v.it with
715+ let of_val v =
716+ match v with
709717 | Num n -> of_num n
710718 | Vec v -> of_vec v
711719 | Ref r -> of_ref r
712720
721+ let of_lit lit =
722+ match lit.it with
723+ | ValLit v -> of_val v
724+ | NullLit _ -> " null"
725+
713726let of_nan = function
714727 | CanonicalNan -> " \" nan:canonical\" "
715728 | ArithmeticNan -> " \" nan:arithmetic\" "
@@ -728,6 +741,7 @@ let of_vec_pat = function
728741let of_ref_pat = function
729742 | RefPat r -> of_ref r.it
730743 | RefTypePat t -> " \" ref." ^ string_of_heaptype t ^ " \" "
744+ | NullPat t -> " \" ref.null\" "
731745
732746let rec of_result res =
733747 match res.it with
@@ -753,16 +767,16 @@ let of_wrapper env x_opt name wrap_action wrap_assertion at =
753767
754768let of_action env act =
755769 match act.it with
756- | Invoke (x_opt , name , vs ) ->
770+ | Invoke (x_opt , name , lits ) ->
757771 " call(" ^ of_inst_opt env x_opt ^ " , " ^ of_name name ^ " , " ^
758- " [" ^ String. concat " , " (List. map of_value vs ) ^ " ])" ,
772+ " [" ^ String. concat " , " (List. map of_lit lits ) ^ " ])" ,
759773 (match lookup_export env x_opt name act.at with
760774 | ExternFuncT (Def dt ) ->
761- let (ins, out ) as ft = functype_of_comptype (expand_deftype dt) in
775+ let (_, ts ) as ft = functype_of_comptype (expand_deftype dt) in
762776 if is_js_functype ft then
763777 None
764778 else
765- Some (of_wrapper env x_opt name (invoke dt vs ins ), out )
779+ Some (of_wrapper env x_opt name (invoke dt lits ), ts )
766780 | _ -> None
767781 )
768782 | Get (x_opt , name ) ->
0 commit comments