Skip to content

Commit

Permalink
fix top
Browse files Browse the repository at this point in the history
  • Loading branch information
hhugo committed Sep 27, 2023
1 parent f4d1939 commit dcbd7b5
Showing 2 changed files with 30 additions and 4 deletions.
5 changes: 2 additions & 3 deletions compiler/lib-dynlink/js_of_ocaml_compiler_dynlink.ml
Original file line number Diff line number Diff line change
@@ -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
29 changes: 28 additions & 1 deletion runtime/toplevel.js
Original file line number Diff line number Diff line change
@@ -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)")
}

0 comments on commit dcbd7b5

Please sign in to comment.