From dcbd7b5ba1e17457e032bf3bf908fc617109da3e Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Wed, 27 Sep 2023 09:36:16 +0200 Subject: [PATCH] fix top --- .../js_of_ocaml_compiler_dynlink.ml | 5 ++-- runtime/toplevel.js | 29 ++++++++++++++++++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/compiler/lib-dynlink/js_of_ocaml_compiler_dynlink.ml b/compiler/lib-dynlink/js_of_ocaml_compiler_dynlink.ml index 04b7535c23..5b7e6f3708 100644 --- a/compiler/lib-dynlink/js_of_ocaml_compiler_dynlink.ml +++ b/compiler/lib-dynlink/js_of_ocaml_compiler_dynlink.ml @@ -20,9 +20,8 @@ let () = Config.Flag.set "use-js-string" (Jsoo_runtime.Sys.Config.use_js_string ()); Config.Flag.set "effects" (Jsoo_runtime.Sys.Config.effects ()); (* this needs to stay synchronized with toplevel.js *) - let toplevel_compile (s : _ Bigarray.Array1.t) (debug : Instruct.debug_event list array) - : unit -> J.t = - let s = String.init (Bigarray.Array1.dim s) ~f:(fun i -> Bigarray.Array1.get s i) in + let toplevel_compile (s : string) (debug : Instruct.debug_event list array) : + unit -> J.t = let prims = split_primitives (Symtable.data_primitive_names ()) in let b = Buffer.create 100 in let fmt = Pretty_print.to_buffer b in diff --git a/runtime/toplevel.js b/runtime/toplevel.js index 3a3c911b79..f6d2fab90f 100644 --- a/runtime/toplevel.js +++ b/runtime/toplevel.js @@ -50,9 +50,36 @@ function caml_get_section_table () { //Provides: caml_reify_bytecode //Requires: caml_failwith,caml_callback +//Requires: caml_string_of_array, caml_ba_to_typed_array +//Version: >= 5.2 function caml_reify_bytecode (code, debug,_digest) { - if(globalThis.toplevelCompile) + if(globalThis.toplevelCompile){ + code=caml_string_of_array(caml_ba_to_typed_array(code)); return [0, 0, caml_callback(globalThis.toplevelCompile, [code,debug])]; + } + else caml_failwith("Toplevel not initialized (toplevelCompile)") +} + +//Provides: caml_reify_bytecode +//Requires: caml_failwith,caml_callback +//Requires: caml_string_of_array, caml_uint8_array_of_bytes +//Version: < 5.2 +function caml_reify_bytecode (code, debug,_digest) { + if(globalThis.toplevelCompile){ + var len = 0; + var all = []; + for(var i = 1; i < code.length; i++) { + var a = caml_uint8_array_of_bytes(code[i]); + all.push(a); + len += a.length; + } + code = new Uint8Array(len); + for(var i = 0, len = 0; i < all.length; i++){ + code.set(all[i], len); + } + code = caml_string_of_array(code); + return [0, 0, caml_callback(globalThis.toplevelCompile, [code,debug])]; + } else caml_failwith("Toplevel not initialized (toplevelCompile)") }