Skip to content

Commit 29b1fd4

Browse files
authored
[interpreter] Proper fix for JS conversion (#1832)
1 parent 2a30893 commit 29b1fd4

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

interpreter/script/js.ml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ let env () : env =
236236
let current_mod (env : env) = "$$" ^ string_of_int env.current_mod
237237
let of_mod_opt (env : env) = function
238238
| None -> current_mod env
239-
| Some x -> x.it
239+
| Some x -> "$" ^ x.it
240240

241241
let current_inst (env : env) = "$" ^ string_of_int env.current_inst
242242
let of_inst_opt (env : env) = function
@@ -614,24 +614,18 @@ let rec of_result res =
614614
| EitherResult ress ->
615615
"[" ^ String.concat ", " (List.map of_result ress) ^ "]"
616616

617-
let of_module bs =
618-
"module(" ^ of_bytes bs ^ ")"
619-
620617
let rec of_definition def =
621618
match def.it with
622-
| Textual (m, _) -> of_module (Encode.encode m)
623-
| Encoded (_, bs) -> of_module bs.it
619+
| Textual (m, _) -> of_bytes (Encode.encode m)
620+
| Encoded (_, bs) -> of_bytes bs.it
624621
| Quoted (_, s) ->
625622
try of_definition (snd (Parse.Module.parse_string ~offset:s.at s.it))
626-
with Parse.Syntax _ | Custom.Syntax _ -> of_module "<malformed quote>"
627-
628-
let of_instance env x_opt =
629-
"instance(" ^ of_mod_opt env x_opt ^ ")"
623+
with Parse.Syntax _ | Custom.Syntax _ -> of_bytes "<malformed quote>"
630624

631625
let of_wrapper env x_opt name wrap_action wrap_assertion at =
632626
let x = of_inst_opt env x_opt in
633627
let bs = wrap name wrap_action wrap_assertion at in
634-
"call(instance(" ^ of_module bs ^ ", " ^
628+
"call(instance(module(" ^ of_bytes bs ^ "), " ^
635629
"exports(" ^ x ^ ")), " ^ " \"run\", [])"
636630

637631
let of_action env act =
@@ -680,9 +674,9 @@ let of_assertion env ass =
680674
| AssertInvalidCustom (def, _) ->
681675
"assert_invalid_custom(" ^ of_definition def ^ ");"
682676
| AssertUnlinkable (x_opt, _) ->
683-
"assert_unlinkable(" ^ of_instance env x_opt ^ ");"
677+
"assert_unlinkable(" ^ of_mod_opt env x_opt ^ ");"
684678
| AssertUninstantiable (x_opt, _) ->
685-
"assert_uninstantiable(" ^ of_instance env x_opt ^ ");"
679+
"assert_uninstantiable(" ^ of_mod_opt env x_opt ^ ");"
686680
| AssertReturn (act, ress) ->
687681
of_assertion' env act "assert_return" (List.map of_result ress)
688682
(Some (assert_return ress))
@@ -705,7 +699,7 @@ let of_command env cmd =
705699
| Quoted (_, s) ->
706700
unquote (snd (Parse.Module.parse_string ~offset:s.at s.it))
707701
in bind_mod env x_opt (unquote def);
708-
"let " ^ current_mod env ^ " = " ^ of_definition def ^ ";\n" ^
702+
"let " ^ current_mod env ^ " = module(" ^ of_definition def ^ ");\n" ^
709703
(if x_opt = None then "" else
710704
"let " ^ of_mod_opt env x_opt ^ " = " ^ current_mod env ^ ";\n")
711705
| Instance (x1_opt, x2_opt) ->

0 commit comments

Comments
 (0)