diff --git a/lib/js_of_ocaml/js_of_ocaml_stubs.c b/lib/js_of_ocaml/js_of_ocaml_stubs.c index 0ddf5aee81..d12fb70c91 100644 --- a/lib/js_of_ocaml/js_of_ocaml_stubs.c +++ b/lib/js_of_ocaml/js_of_ocaml_stubs.c @@ -1,7 +1,7 @@ #include -void caml_bytes_of_array () { - caml_fatal_error("Unimplemented Javascript primitive caml_bytes_of_array!"); +void caml_bytes_of_uint8_array () { + caml_fatal_error("Unimplemented Javascript primitive caml_bytes_of_uint8_array!"); } void caml_custom_identifier () { diff --git a/lib/js_of_ocaml/typed_array.ml b/lib/js_of_ocaml/typed_array.ml index 98def83222..e29be12828 100644 --- a/lib/js_of_ocaml/typed_array.ml +++ b/lib/js_of_ocaml/typed_array.ml @@ -274,7 +274,7 @@ module String = struct end module Bytes = struct - external of_uint8Array : uint8Array Js.t -> bytes = "caml_bytes_of_array" + external of_uint8Array : uint8Array Js.t -> bytes = "caml_bytes_of_uint8_array" external to_uint8Array : bytes -> uint8Array Js.t = "caml_uint8_array_of_bytes" diff --git a/runtime/js/bigstring.js b/runtime/js/bigstring.js index 230652c3af..eb87cdb1c5 100644 --- a/runtime/js/bigstring.js +++ b/runtime/js/bigstring.js @@ -107,7 +107,7 @@ function caml_bigstring_blit_bytes_to_ba(str1, pos1, ba2, pos2, len) { //Provides: caml_bigstring_blit_ba_to_bytes //Requires: caml_invalid_argument, caml_array_bound_error -//Requires: caml_blit_bytes, caml_bytes_of_array +//Requires: caml_blit_bytes, caml_bytes_of_uint8_array //Requires: caml_ml_bytes_length function caml_bigstring_blit_ba_to_bytes(ba1, pos1, bytes2, pos2, len) { if (12 !== ba1.kind) @@ -121,6 +121,6 @@ function caml_bigstring_blit_ba_to_bytes(ba1, pos1, bytes2, pos2, len) { caml_array_bound_error(); } var slice = ba1.data.subarray(ofs1, ofs1 + len); - caml_blit_bytes(caml_bytes_of_array(slice), 0, bytes2, pos2, len); + caml_blit_bytes(caml_bytes_of_uint8_array(slice), 0, bytes2, pos2, len); return 0; } diff --git a/runtime/js/fs_fake.js b/runtime/js/fs_fake.js index 8771424890..b487c6f5df 100644 --- a/runtime/js/fs_fake.js +++ b/runtime/js/fs_fake.js @@ -307,7 +307,7 @@ MlFakeDevice.prototype.constructor = MlFakeDevice; //Provides: MlFakeFile //Requires: MlFile //Requires: caml_create_bytes, caml_ml_bytes_length, caml_blit_bytes -//Requires: caml_uint8_array_of_bytes, caml_bytes_of_array +//Requires: caml_uint8_array_of_bytes, caml_bytes_of_uint8_array function MlFakeFile(content) { this.data = content; } @@ -329,7 +329,7 @@ MlFakeFile.prototype.write = function (offset, buf, pos, len) { this.data = new_str; caml_blit_bytes(old_data, 0, this.data, 0, clen); } - caml_blit_bytes(caml_bytes_of_array(buf), pos, this.data, offset, len); + caml_blit_bytes(caml_bytes_of_uint8_array(buf), pos, this.data, offset, len); return 0; }; MlFakeFile.prototype.read = function (offset, buf, pos, len) { @@ -346,7 +346,7 @@ MlFakeFile.prototype.read = function (offset, buf, pos, len) { }; //Provides: MlFakeFd_out -//Requires: MlFakeFile, caml_create_bytes, caml_blit_bytes, caml_bytes_of_array +//Requires: MlFakeFile, caml_create_bytes, caml_blit_bytes, caml_bytes_of_uint8_array //Requires: caml_raise_sys_error function MlFakeFd_out(fd, flags) { MlFakeFile.call(this, caml_create_bytes(0)); @@ -374,7 +374,7 @@ MlFakeFd_out.prototype.write = function (offset, buf, pos, len) { // Do not output the last \n if present // as console logging display a newline at the end var src = caml_create_bytes(len); - caml_blit_bytes(caml_bytes_of_array(buf), pos, src, 0, len); + caml_blit_bytes(caml_bytes_of_uint8_array(buf), pos, src, 0, len); this.log(src.toUtf16()); return 0; } diff --git a/runtime/js/io.js b/runtime/js/io.js index 511825cde7..93378cf46e 100644 --- a/runtime/js/io.js +++ b/runtime/js/io.js @@ -409,7 +409,7 @@ function caml_ml_input_block(chanid, ba, i, l) { } //Provides: caml_input_value -//Requires: caml_marshal_data_size, caml_input_value_from_bytes, caml_create_bytes, caml_ml_channel_get, caml_bytes_of_array +//Requires: caml_marshal_data_size, caml_input_value_from_bytes, caml_create_bytes, caml_ml_channel_get, caml_bytes_of_uint8_array //Requires: caml_refill, caml_failwith, caml_raise_end_of_file //Requires: caml_marshal_header_size function caml_input_value(chanid) { @@ -434,12 +434,12 @@ function caml_input_value(chanid) { if (r === 0) caml_raise_end_of_file(); else if (r < caml_marshal_header_size) caml_failwith("input_value: truncated object"); - var len = caml_marshal_data_size(caml_bytes_of_array(header), 0); + var len = caml_marshal_data_size(caml_bytes_of_uint8_array(header), 0); var buf = new Uint8Array(len + caml_marshal_header_size); buf.set(header, 0); var r = block(buf, caml_marshal_header_size, len); if (r < len) caml_failwith("input_value: truncated object " + r + " " + len); - var res = caml_input_value_from_bytes(caml_bytes_of_array(buf), 0); + var res = caml_input_value_from_bytes(caml_bytes_of_uint8_array(buf), 0); return res; } diff --git a/runtime/js/marshal.js b/runtime/js/marshal.js index d3a0a9cf83..afd8db42f5 100644 --- a/runtime/js/marshal.js +++ b/runtime/js/marshal.js @@ -871,16 +871,16 @@ function caml_output_value_to_string(v, flags) { } //Provides: caml_output_value_to_bytes mutable -//Requires: caml_output_val, caml_bytes_of_array +//Requires: caml_output_val, caml_bytes_of_uint8_array function caml_output_value_to_bytes(v, flags) { - return caml_bytes_of_array(caml_output_val(v, flags)); + return caml_bytes_of_uint8_array(caml_output_val(v, flags)); } //Provides: caml_output_value_to_buffer -//Requires: caml_output_val, caml_failwith, caml_blit_bytes, caml_bytes_of_array +//Requires: caml_output_val, caml_failwith, caml_blit_bytes, caml_bytes_of_uint8_array function caml_output_value_to_buffer(s, ofs, len, v, flags) { var t = caml_output_val(v, flags); if (t.length > len) caml_failwith("Marshal.to_buffer: buffer overflow"); - caml_blit_bytes(caml_bytes_of_array(t), 0, s, ofs, t.length); + caml_blit_bytes(caml_bytes_of_uint8_array(t), 0, s, ofs, t.length); return 0; } diff --git a/runtime/js/mlBytes.js b/runtime/js/mlBytes.js index c5277298a0..cdfc0665e2 100644 --- a/runtime/js/mlBytes.js +++ b/runtime/js/mlBytes.js @@ -526,6 +526,12 @@ function caml_bytes_of_array(a) { return new MlBytes(4, a, a.length); } +//Provides: caml_bytes_of_uint8_array +//Requires: MlBytes +function caml_bytes_of_uint8_array(a) { + return new MlBytes(4, a, a.length); +} + //Provides: caml_bytes_compare mutable //Requires: caml_convert_string_to_bytes function caml_bytes_compare(s1, s2) { diff --git a/runtime/wasm/bigarray.wat b/runtime/wasm/bigarray.wat index c4b480b5bb..d91f347518 100644 --- a/runtime/wasm/bigarray.wat +++ b/runtime/wasm/bigarray.wat @@ -2020,7 +2020,7 @@ (i32.wrap_i64 (i64.shr_u (local.get $d) (i64.const 32)))) (ref.i31 (i32.const 0))) - (export "caml_bytes_of_array" (func $caml_string_of_uint8_array)) + (export "caml_bytes_of_uint8_array" (func $caml_string_of_uint8_array)) (func $caml_string_of_uint8_array (export "caml_string_of_uint8_array") (param (ref eq)) (result (ref eq)) ;; used to convert a typed array to a string