Skip to content

Commit 2696483

Browse files
committed
Wasm implementation
1 parent 53b4c0f commit 2696483

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

compiler/lib-wasm/gc_target.ml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,6 +1932,22 @@ let internal_primitives =
19321932
in
19331933
let l = List.map ~f:transl_prim_arg vl in
19341934
JavaScript.invoke_fragment name l);
1935+
register "caml_jsoo_runtime" (fun _ l ->
1936+
match l with
1937+
| [ Pc (String name) ] when J.is_ident name ->
1938+
let* x =
1939+
register_import
1940+
~import_module:"js"
1941+
~name
1942+
(Global { mut = false; typ = JavaScript.anyref })
1943+
in
1944+
let* wrap =
1945+
register_import
1946+
~name:"wrap"
1947+
(Fun { params = [ JavaScript.anyref ]; result = [ Type.value ] })
1948+
in
1949+
return (W.Call (wrap, [ GlobalGet x ]))
1950+
| _ -> failwith "Jsoo_runtime.Sys.external_ expects a string literal.");
19351951
!l
19361952

19371953
let externref = W.Ref { nullable = true; typ = Extern }

compiler/lib/specialize_js.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ let specialize_instr opt_count ~target info i =
188188
incr opt_count;
189189
Let (x, Prim (Extern "%direct_int_mod", [ y; z ]))
190190
| _ -> i)
191+
| Let (x, Prim (Extern "caml_jsoo_runtime", [ nm ])), _ -> (
192+
match the_string_of info nm with
193+
| Some nm when Javascript.is_ident nm ->
194+
Let (x, Prim (Extern "caml_jsoo_runtime", [ Pc (String nm) ]))
195+
| _ -> i)
191196
| _, _ -> i
192197

193198
let skip_event cont (Event _ :: l | l) = cont l

0 commit comments

Comments
 (0)