From 29b1fd4d3771b08d6a505fdce4bb2b3373dd7d61 Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Tue, 8 Oct 2024 15:41:38 +0200 Subject: [PATCH] [interpreter] Proper fix for JS conversion (#1832) --- interpreter/script/js.ml | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/interpreter/script/js.ml b/interpreter/script/js.ml index 2e796f7e72..adc072cb1c 100644 --- a/interpreter/script/js.ml +++ b/interpreter/script/js.ml @@ -236,7 +236,7 @@ let env () : env = let current_mod (env : env) = "$$" ^ string_of_int env.current_mod let of_mod_opt (env : env) = function | None -> current_mod env - | Some x -> x.it + | Some x -> "$" ^ x.it let current_inst (env : env) = "$" ^ string_of_int env.current_inst let of_inst_opt (env : env) = function @@ -614,24 +614,18 @@ let rec of_result res = | EitherResult ress -> "[" ^ String.concat ", " (List.map of_result ress) ^ "]" -let of_module bs = - "module(" ^ of_bytes bs ^ ")" - let rec of_definition def = match def.it with - | Textual (m, _) -> of_module (Encode.encode m) - | Encoded (_, bs) -> of_module bs.it + | Textual (m, _) -> of_bytes (Encode.encode m) + | Encoded (_, bs) -> of_bytes bs.it | Quoted (_, s) -> try of_definition (snd (Parse.Module.parse_string ~offset:s.at s.it)) - with Parse.Syntax _ | Custom.Syntax _ -> of_module "" - -let of_instance env x_opt = - "instance(" ^ of_mod_opt env x_opt ^ ")" + with Parse.Syntax _ | Custom.Syntax _ -> of_bytes "" let of_wrapper env x_opt name wrap_action wrap_assertion at = let x = of_inst_opt env x_opt in let bs = wrap name wrap_action wrap_assertion at in - "call(instance(" ^ of_module bs ^ ", " ^ + "call(instance(module(" ^ of_bytes bs ^ "), " ^ "exports(" ^ x ^ ")), " ^ " \"run\", [])" let of_action env act = @@ -680,9 +674,9 @@ let of_assertion env ass = | AssertInvalidCustom (def, _) -> "assert_invalid_custom(" ^ of_definition def ^ ");" | AssertUnlinkable (x_opt, _) -> - "assert_unlinkable(" ^ of_instance env x_opt ^ ");" + "assert_unlinkable(" ^ of_mod_opt env x_opt ^ ");" | AssertUninstantiable (x_opt, _) -> - "assert_uninstantiable(" ^ of_instance env x_opt ^ ");" + "assert_uninstantiable(" ^ of_mod_opt env x_opt ^ ");" | AssertReturn (act, ress) -> of_assertion' env act "assert_return" (List.map of_result ress) (Some (assert_return ress)) @@ -705,7 +699,7 @@ let of_command env cmd = | Quoted (_, s) -> unquote (snd (Parse.Module.parse_string ~offset:s.at s.it)) in bind_mod env x_opt (unquote def); - "let " ^ current_mod env ^ " = " ^ of_definition def ^ ";\n" ^ + "let " ^ current_mod env ^ " = module(" ^ of_definition def ^ ");\n" ^ (if x_opt = None then "" else "let " ^ of_mod_opt env x_opt ^ " = " ^ current_mod env ^ ";\n") | Instance (x1_opt, x2_opt) ->