Skip to content

Commit 9196cfe

Browse files
committed
OxCaml support: toplevel
It pretends to be 5.2 but uses the new API to reify bytecode
1 parent a749c75 commit 9196cfe

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

runtime/js/toplevel.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function jsoo_toplevel_init_reloc(f) {
103103
//Requires: caml_callback
104104
//Requires: caml_string_of_uint8_array, caml_ba_to_typed_array
105105
//Requires: jsoo_toplevel_compile, caml_failwith
106-
//Version: >= 5.2
106+
//Version: >= 5.3
107107
function caml_reify_bytecode(code, debug, _digest) {
108108
if (!jsoo_toplevel_compile) {
109109
caml_failwith("Toplevel not initialized (jsoo_toplevel_compile)");
@@ -137,6 +137,39 @@ function caml_reify_bytecode(code, debug, _digest) {
137137
return [0, 0, caml_callback(jsoo_toplevel_compile, [code, debug])];
138138
}
139139

140+
//Provides: caml_reify_bytecode
141+
//Requires: caml_callback
142+
//Requires: caml_string_of_uint8_array, caml_uint8_array_of_bytes
143+
//Requires: caml_ba_to_typed_array
144+
//Requires: jsoo_toplevel_compile, caml_failwith
145+
//Version: >= 5.2, < 5.3
146+
//Compatible with OxCaml
147+
function caml_reify_bytecode(code, debug, _digest) {
148+
if (!jsoo_toplevel_compile) {
149+
caml_failwith("Toplevel not initialized (jsoo_toplevel_compile)");
150+
}
151+
if (code.data) {
152+
//Version: >= 5.2
153+
code = caml_ba_to_typed_array(code);
154+
} else {
155+
// Oxcaml or version < 5.2
156+
var len = 0;
157+
var all = [];
158+
for (var i = 1; i < code.length; i++) {
159+
var a = caml_uint8_array_of_bytes(code[i]);
160+
all.push(a);
161+
len += a.length;
162+
}
163+
code = new Uint8Array(len);
164+
for (var i = 0, len = 0; i < all.length; i++) {
165+
code.set(all[i], len);
166+
len += all[i].length;
167+
}
168+
}
169+
code = caml_string_of_uint8_array(code);
170+
return [0, 0, caml_callback(jsoo_toplevel_compile, [code, debug])];
171+
}
172+
140173
//Provides: caml_static_release_bytecode
141174
function caml_static_release_bytecode() {
142175
return 0;

0 commit comments

Comments
 (0)