diff --git a/jscomp/core/lam_analysis.ml b/jscomp/core/lam_analysis.ml index 4d96c2a159..9696beb9a6 100644 --- a/jscomp/core/lam_analysis.ml +++ b/jscomp/core/lam_analysis.ml @@ -155,7 +155,7 @@ let rec no_side_effects (lam : Lam.t) : bool = | Pasrint64 | Pint64comp _ (* Operations on big arrays: (unsafe, #dimensions, kind, layout) *) - + | Pbigarrayref _ (* TODO it may raise an exception....*) (* Compile time constants *) | Pctconst _ (* Integer to external pointer *) @@ -182,6 +182,9 @@ let rec no_side_effects (lam : Lam.t) : bool = | Pbytessetu | Pbytessets (* Operations on boxed integers (Nativeint.t, Int32.t, Int64.t) *) + | Pbigarrayset _ + (* size of the nth dimension of a big array *) + | Pbigarraydim _ | Parraysets (* byte swap *) | Parraysetu diff --git a/jscomp/core/lam_compat.ml b/jscomp/core/lam_compat.ml index 804f8cd83f..45b7732c30 100644 --- a/jscomp/core/lam_compat.ml +++ b/jscomp/core/lam_compat.ml @@ -175,4 +175,34 @@ type set_field_dbg_info = Lambda.set_field_dbg_info = | Fld_record_extension_set of string - +type bigarray_kind = Lambda.bigarray_kind = + Pbigarray_unknown + | Pbigarray_float32 | Pbigarray_float64 + | Pbigarray_sint8 | Pbigarray_uint8 + | Pbigarray_sint16 | Pbigarray_uint16 + | Pbigarray_int32 | Pbigarray_int64 + | Pbigarray_caml_int | Pbigarray_native_int + | Pbigarray_complex32 | Pbigarray_complex64 + + +(* let eq_bigarray_kind (p : bigarray_kind) (p1 : bigarray_kind) = + match p with + | Pbigarray_unknown -> p1 = Pbigarray_unknown + | Pbigarray_float32 -> p1 = Pbigarray_float32 + | Pbigarray_float64 -> p1 = Pbigarray_float64 + | Pbigarray_sint8 -> p1 = Pbigarray_sint8 + | Pbigarray_uint8 -> p1 = Pbigarray_uint8 + | Pbigarray_sint16 -> p1 = Pbigarray_sint16 + | Pbigarray_uint16 -> p1 = Pbigarray_uint16 + | Pbigarray_int32 -> p1 = Pbigarray_int32 + | Pbigarray_int64 -> p1 = Pbigarray_int64 + | Pbigarray_caml_int -> p1 = Pbigarray_caml_int + | Pbigarray_native_int -> p1 = Pbigarray_native_int + | Pbigarray_complex32 -> p1 = Pbigarray_complex32 + | Pbigarray_complex64 -> p1 = Pbigarray_complex64 *) + + +type bigarray_layout = Lambda.bigarray_layout = + Pbigarray_unknown_layout + | Pbigarray_c_layout + | Pbigarray_fortran_layout diff --git a/jscomp/core/lam_compat.mli b/jscomp/core/lam_compat.mli index bfe9e278fb..7e900b3158 100644 --- a/jscomp/core/lam_compat.mli +++ b/jscomp/core/lam_compat.mli @@ -81,6 +81,20 @@ type set_field_dbg_info = Lambda.set_field_dbg_info = | Fld_record_inline_set of string | Fld_record_extension_set of string +type bigarray_kind = Lambda.bigarray_kind = + Pbigarray_unknown + | Pbigarray_float32 | Pbigarray_float64 + | Pbigarray_sint8 | Pbigarray_uint8 + | Pbigarray_sint16 | Pbigarray_uint16 + | Pbigarray_int32 | Pbigarray_int64 + | Pbigarray_caml_int | Pbigarray_native_int + | Pbigarray_complex32 | Pbigarray_complex64 + + +type bigarray_layout = Lambda.bigarray_layout = + Pbigarray_unknown_layout + | Pbigarray_c_layout + | Pbigarray_fortran_layout val cmp_int32 : integer_comparison -> int32 -> int32 -> bool val cmp_int64 : integer_comparison -> int64 -> int64 -> bool diff --git a/jscomp/core/lam_compile_primitive.ml b/jscomp/core/lam_compile_primitive.ml index 551a93b314..22b71ce0a8 100644 --- a/jscomp/core/lam_compile_primitive.ml +++ b/jscomp/core/lam_compile_primitive.ml @@ -509,7 +509,58 @@ let translate loc ) | Pduprecord (Record_regular| Record_extension| Record_inlined _ ) -> Lam_dispatch_primitive.translate loc "caml_obj_dup" args + | Pbigarrayref (unsafe, dimension, kind, layout) + -> + (* can be refined to + [caml_bigarray_float32_c_get_1] + note that kind can be [generic] + and layout can be [unknown], + dimension is always available + *) + begin match dimension, kind, layout, unsafe with + | 1, ( Pbigarray_float32 | Pbigarray_float64 + | Pbigarray_sint8 | Pbigarray_uint8 + | Pbigarray_sint16 | Pbigarray_uint16 + | Pbigarray_int32 | Pbigarray_int64 + | Pbigarray_caml_int | Pbigarray_native_int + | Pbigarray_complex32 | Pbigarray_complex64), Pbigarray_c_layout, _ + -> + begin match args with + | [_x;_indx] -> E.runtime_call Js_runtime_modules.bigarray + ("caml_ba_get_" ^ string_of_int dimension ) args + | _ -> assert false + end + | _, _, _ ,_ -> + E.runtime_call Js_runtime_modules.bigarray + ("caml_ba_get_" ^ string_of_int dimension ) args + end + | Pbigarrayset (unsafe, dimension, kind, layout) + -> + begin match dimension, kind, layout, unsafe with + | 1, ( Pbigarray_float32 | Pbigarray_float64 + | Pbigarray_sint8 | Pbigarray_uint8 + | Pbigarray_sint16 | Pbigarray_uint16 + | Pbigarray_int32 | Pbigarray_int64 + | Pbigarray_caml_int | Pbigarray_native_int + | Pbigarray_complex32 | Pbigarray_complex64), Pbigarray_c_layout, _ + -> + begin match args with + | [_x; _index; _value] -> + E.runtime_call Js_runtime_modules.bigarray + ("caml_ba_set_" ^ string_of_int dimension) args + | _ -> assert false + end + + | _ , _, _,_ + -> + E.runtime_call Js_runtime_modules.bigarray + ("caml_ba_set_" ^ string_of_int dimension) args + end + | Pbigarraydim i + -> + E.runtime_call Js_runtime_modules.bigarray + ("caml_ba_dim_" ^ string_of_int i) args | Plazyforce (* FIXME: we don't inline lazy force or at least let buckle handle it diff --git a/jscomp/core/lam_convert.ml b/jscomp/core/lam_convert.ml index a144ae67c4..98dbf3e49a 100644 --- a/jscomp/core/lam_convert.ml +++ b/jscomp/core/lam_convert.ml @@ -477,7 +477,9 @@ let lam_prim ~primitive:( p : Lambda.primitive) ~args loc : Lam.t = | Pint32 -> prim ~primitive:(Pasrint) ~args loc | Pint64 -> prim ~primitive:(Pasrint64) ~args loc end - | Pbigarraydim _ + | Pbigarraydim x -> prim ~primitive:(Pbigarraydim x) ~args loc + | Pbigarrayref (unsafe, dimension, kind, layout) -> prim ~primitive:(Pbigarrayref (unsafe, dimension, kind, layout)) ~args loc + | Pbigarrayset (unsafe, dimension, kind, layout) -> prim ~primitive:(Pbigarrayset (unsafe, dimension, kind, layout)) ~args loc | Pbigstring_load_16 _ | Pbigstring_load_32 _ | Pbigstring_load_64 _ @@ -492,9 +494,7 @@ let lam_prim ~primitive:( p : Lambda.primitive) ~args loc : Lam.t = | Pbytes_set_64 _ | Pstring_load_16 _ | Pstring_load_32 _ - | Pstring_load_64 _ - | Pbigarrayref _ - | Pbigarrayset _ -> + | Pstring_load_64 _ -> Location.raise_errorf ~loc "unsupported primitive" | Pctconst x -> begin match x with diff --git a/jscomp/core/lam_dispatch_primitive.ml b/jscomp/core/lam_dispatch_primitive.ml index 38deb43d9b..1d97cf7bb3 100644 --- a/jscomp/core/lam_dispatch_primitive.ml +++ b/jscomp/core/lam_dispatch_primitive.ml @@ -607,7 +607,34 @@ let translate loc (prim_name : string) E.unchecked_int32_mul e1 e2 | _ -> assert false end - + | "caml_ba_create" -> call Js_runtime_modules.bigarray + | "caml_ba_get_generic" -> call Js_runtime_modules.bigarray + | "caml_ba_set_generic" -> call Js_runtime_modules.bigarray + | "caml_ba_num_dims" -> call Js_runtime_modules.bigarray + | "caml_ba_dim" -> call Js_runtime_modules.bigarray + | "caml_ba_kind" -> call Js_runtime_modules.bigarray + | "caml_ba_layout" -> call Js_runtime_modules.bigarray + | "caml_ba_change_layout" -> call Js_runtime_modules.bigarray + | "caml_ba_blit" -> call Js_runtime_modules.bigarray + | "caml_ba_fill" -> call Js_runtime_modules.bigarray + | "caml_ba_get_1" -> call Js_runtime_modules.bigarray + | "caml_ba_set_1" -> call Js_runtime_modules.bigarray + | "caml_ba_unsafe_get_1" -> call Js_runtime_modules.bigarray + | "caml_ba_unsafe_set_1" -> call Js_runtime_modules.bigarray + | "caml_ba_dim_1" -> call Js_runtime_modules.bigarray + | "caml_ba_sub" -> call Js_runtime_modules.bigarray + | "caml_ba_get_2" -> call Js_runtime_modules.bigarray + | "caml_ba_set_2" -> call Js_runtime_modules.bigarray + | "caml_ba_unsafe_get_2" -> call Js_runtime_modules.bigarray + | "caml_ba_unsafe_set_2" -> call Js_runtime_modules.bigarray + | "caml_ba_dim_2" -> call Js_runtime_modules.bigarray + | "caml_ba_get_3" -> call Js_runtime_modules.bigarray + | "caml_ba_set_3" -> call Js_runtime_modules.bigarray + | "caml_ba_unsafe_get_3" -> call Js_runtime_modules.bigarray + | "caml_ba_unsafe_set_3" -> call Js_runtime_modules.bigarray + | "caml_ba_dim_3" -> call Js_runtime_modules.bigarray + | "caml_ba_slice" -> call Js_runtime_modules.bigarray + | "caml_ba_reshape" -> call Js_runtime_modules.bigarray | _ -> Bs_warnings.warn_missing_primitive loc prim_name ; E.resolve_and_apply prim_name args diff --git a/jscomp/core/lam_primitive.ml b/jscomp/core/lam_primitive.ml index 1b8df21e0a..b6596bddb9 100644 --- a/jscomp/core/lam_primitive.ml +++ b/jscomp/core/lam_primitive.ml @@ -149,6 +149,10 @@ type t = | Pfield_computed (* Mostly used in object compilation *) | Psetfield_computed + | Pbigarrayref of bool * int * Lam_compat.bigarray_kind * Lam_compat.bigarray_layout + | Pbigarrayset of bool * int * Lam_compat.bigarray_kind * Lam_compat.bigarray_layout + (* size of the nth dimension of a big array *) + | Pbigarraydim of int @@ -285,8 +289,11 @@ let eq_primitive_approx ( lhs : t) (rhs : t) = | Pvoid_run -> rhs = Pvoid_run | Pfull_apply -> rhs = Pfull_apply | Pjs_fn_method -> rhs = Pjs_fn_method + | Pbigarrayref _ + | Pbigarrayset _ | Praw_js_code _ -> false (* TOO lazy, here comparison is only approximation*) | Pfield_computed -> rhs = Pfield_computed | Psetfield_computed -> rhs = Psetfield_computed + | Pbigarraydim dim -> (match rhs with Pbigarraydim dim1 -> dim = dim1 | _ -> false ) diff --git a/jscomp/core/lam_primitive.mli b/jscomp/core/lam_primitive.mli index 7307c73204..38a963afba 100644 --- a/jscomp/core/lam_primitive.mli +++ b/jscomp/core/lam_primitive.mli @@ -144,5 +144,10 @@ type t = | Pfield_computed (* Mostly used in object compilation *) | Psetfield_computed + (* Operations on big arrays: (unsafe, #dimensions, kind, layout) *) + | Pbigarrayref of bool * int * Lam_compat.bigarray_kind * Lam_compat.bigarray_layout + | Pbigarrayset of bool * int * Lam_compat.bigarray_kind * Lam_compat.bigarray_layout + (* size of the nth dimension of a big array *) + | Pbigarraydim of int val eq_primitive_approx : t -> t -> bool diff --git a/jscomp/core/lam_print.ml b/jscomp/core/lam_print.ml index b7d9e12ae5..7643f878bb 100644 --- a/jscomp/core/lam_print.ml +++ b/jscomp/core/lam_print.ml @@ -48,6 +48,28 @@ let rec struct_const ppf (cst : Lam_constant.t) = fprintf ppf "@[<1>[|@[%s%a@]|]@]" f1 floats fl +let print_bigarray name unsafe (kind : Lam_compat.bigarray_kind) ppf + (layout : Lam_compat.bigarray_layout) = + fprintf ppf "Bigarray.%s[%s,%s]" + (if unsafe then "unsafe_"^ name else name) + (match kind with + | Lam_compat.Pbigarray_unknown -> "generic" + | Pbigarray_float32 -> "float32" + | Pbigarray_float64 -> "float64" + | Pbigarray_sint8 -> "sint8" + | Pbigarray_uint8 -> "uint8" + | Pbigarray_sint16 -> "sint16" + | Pbigarray_uint16 -> "uint16" + | Pbigarray_int32 -> "int32" + | Pbigarray_int64 -> "int64" + | Pbigarray_caml_int -> "camlint" + | Pbigarray_native_int -> "nativeint" + | Pbigarray_complex32 -> "complex32" + | Pbigarray_complex64 -> "complex64") + (match layout with + | Lam_compat.Pbigarray_unknown_layout -> "unknown" + | Pbigarray_c_layout -> "C" + | Pbigarray_fortran_layout -> "Fortran") let record_rep ppf (r : Lam_primitive.record_representation) = match r with @@ -224,7 +246,11 @@ let primitive ppf (prim : Lam_primitive.t) = match prim with | Pint64comp(Cgt) -> fprintf ppf ">" | Pint64comp(Cle) -> fprintf ppf "<=" | Pint64comp(Cge) -> fprintf ppf ">=" - + | Pbigarrayref(unsafe, _n, kind, layout) -> + print_bigarray "get" unsafe kind ppf layout + | Pbigarrayset(unsafe, _n, kind, layout) -> + print_bigarray "set" unsafe kind ppf layout + | Pbigarraydim(n) -> fprintf ppf "Bigarray.dim_%i" n type print_kind = diff --git a/jscomp/ext/js_runtime_modules.ml b/jscomp/ext/js_runtime_modules.ml index 22042948e7..88cfaaa049 100644 --- a/jscomp/ext/js_runtime_modules.ml +++ b/jscomp/ext/js_runtime_modules.ml @@ -43,7 +43,7 @@ let caml_primitive = "Caml" let int64 = "Caml_int64" let md5 = "Caml_md5" let int32 = "Caml_int32" - +let bigarray = "Caml_bigarray" let option = "Caml_option" let module_ = "Caml_module" diff --git a/jscomp/runtime/caml_bigarray.ml b/jscomp/runtime/caml_bigarray.ml new file mode 100644 index 0000000000..9d21457d47 --- /dev/null +++ b/jscomp/runtime/caml_bigarray.ml @@ -0,0 +1,477 @@ +(* Bigarray. - all bigarray types including Int64 and Complex. - fortran + c + layouts - sub/slice/reshape - retain fast path for 1d array access *) + +module Array = Caml_array_extern + +let caml_invalid_argument err = raise (Invalid_argument err) + +let caml_array_bound_error () = caml_invalid_argument "index out of bounds" + +let caml_ba_custom_name = "_bigarr02" + +[%%bs.raw +{| + function Ml_Bigarray (kind, layout, dims, buffer) { + this.kind = kind ; + this.layout = layout; + this.dims = dims; + this.data = buffer; + } + + Ml_Bigarray.prototype.caml_custom = caml_ba_custom_name; + + Ml_Bigarray.prototype.offset = function (arg) { + var ofs = 0; + if(typeof arg === "number") arg = [arg]; + if (! (arg instanceof Array)) caml_invalid_argument("genarray.js: invalid offset"); + if (this.dims.length != arg.length) + caml_invalid_argument("Bigarray.get/set: bad number of dimensions"); + if(this.layout == 0 /* c_layout */) { + for (var i = 0; i < this.dims.length; i++) { + if (arg[i] < 0 || arg[i] >= this.dims[i]) + caml_array_bound_error(); + ofs = (ofs * this.dims[i]) + arg[i]; + } + } else { + for (var i = this.dims.length - 1; i >= 0; i--) { + if (arg[i] < 1 || arg[i] > this.dims[i]){ + caml_array_bound_error(); + } + ofs = (ofs * this.dims[i]) + (arg[i] - 1); + } + } + return ofs; + } + + Ml_Bigarray.prototype.get = function (ofs) { + switch(this.kind){ + case 7: + // Int64 + var l = this.data[ofs * 2 + 0]; + var h = this.data[ofs * 2 + 1]; + return [h, l]; + case 10: case 11: + // Complex32, Complex64 + var r = this.data[ofs * 2 + 0]; + var i = this.data[ofs * 2 + 1]; + return {re: r, im: i}; + default: + return this.data[ofs] + } + } + + Ml_Bigarray.prototype.set = function (ofs,v) { + switch(this.kind){ + case 7: + // Int64 + this.data[ofs * 2 + 0] = v[1]; + this.data[ofs * 2 + 1] = v[0]; + break; + case 10: case 11: + // Complex32, Complex64 + this.data[ofs * 2 + 0] = v.im; + this.data[ofs * 2 + 1] = v.re; + break; + default: + this.data[ofs] = v; + break; + } + return 0 + } + + Ml_Bigarray.prototype.fill = function (v) { + switch(this.kind){ + case 7: + // Int64 + var a = v[1]; + var b = v[0]; + if(a == b){ + this.data.fill(a); + } + else { + for(var i = 0; i y) + return 1; + if (x != y) { + if (!total) return NaN; + if (x == x) return 1; + if (y == y) return -1; + } + } + break; + case 7: + // Int64 + for (var i = 0; i < this.data.length; i+=2) { + // Check highest bits first + if (this.data[i+1] < b.data[i+1]) + return -1; + if (this.data[i+1] > b.data[i+1]) + return 1; + if ((this.data[i] >>> 0) < (b.data[i] >>> 0)) + return -1; + if ((this.data[i] >>> 0) > (b.data[i] >>> 0)) + return 1; + } + break; + case 2: + case 3: + case 4: + case 5: + case 6: + case 8: + case 9: + case 12: + for (var i = 0; i < this.data.length; i++) { + if (this.data[i] < b.data[i]) + return -1; + if (this.data[i] > b.data[i]) + return 1; + } + break; + } + return 0; + } +|}] + +[%%bs.raw +{| + function Ml_Bigarray_c_1_1(kind, layout, dims, buffer) { + this.kind = kind ; + this.layout = layout; + this.dims = dims; + this.data = buffer; + } + + Ml_Bigarray_c_1_1.prototype = new Ml_Bigarray() + Ml_Bigarray_c_1_1.prototype.offset = function (arg) { + if(typeof arg !== "number"){ + if((arg instanceof Array) && arg.length == 1) + arg = arg[0]; + else caml_invalid_argument("Ml_Bigarray_c_1_1.offset"); + } + if (arg < 0 || arg >= this.dims[0]) + caml_array_bound_error(); + return arg; + } + + Ml_Bigarray_c_1_1.prototype.get = function (ofs) { + return this.data[ofs]; + } + + Ml_Bigarray_c_1_1.prototype.set = function (ofs,v) { + this.data[ofs] = v; + return 0 + } + + Ml_Bigarray_c_1_1.prototype.fill = function (v) { + this.data.fill(v); + return 0 + } +|}] + +type buffer + +type ('a, 'b, 'c) genarray + +external ml_Bigarray + : int + -> int + -> int array + -> buffer + -> ('a, 'b, 'c) genarray + = "Ml_Bigarray" + [@@bs.new] + +external ml_Bigarray_c_1_1 + : int + -> int + -> int array + -> buffer + -> ('a, 'b, 'c) genarray + = "Ml_Bigarray_c_1_1" + [@@bs.new] + +external buffer : ('a, 'b, 'c) genarray -> buffer = "data" [@@bs.get] + +external buffer_set : buffer -> buffer -> unit = "set" [@@bs.send] + +external sub : buffer -> int -> int -> buffer = "subarray" [@@bs.send] + +external buffer_length : buffer -> int = "length" [@@bs.get] + +external dims : ('a, 'b, 'c) genarray -> int array = "dims" [@@bs.get] + +external get_dim : ('a, 'b, 'c) genarray -> int -> int = "" + [@@bs.scope "dims"] [@@bs.get_index] + +external offset : ('a, 'b, 'c) genarray -> int array -> int = "offset" + [@@bs.send] + +external get : ('a, 'b, 'c) genarray -> int -> 'a = "get" [@@bs.send] + +external set : ('a, 'b, 'c) genarray -> int -> 'a -> unit = "set" [@@bs.send] + +external fill : ('a, 'b, 'c) genarray -> 'a -> unit = "fill" [@@bs.send] + +let caml_ba_get_size (dims: int array) = + let n_dims = Array.length dims in + let size = { contents = 1 } in + for i = 0 to n_dims - 1 do + if Array.unsafe_get dims i < 0 then + caml_invalid_argument "Bigarray.create: negative dimension"; + size.contents <- size.contents * Array.unsafe_get dims i + done; + size.contents + +let caml_ba_get_size_per_element = function 7 | 10 | 11 -> 2 | _ -> 1 + +let caml_ba_create_buffer : int -> int -> buffer = + [%raw + {| + function (kind, size){ + var view; + switch(kind){ + case 0: view = Float32Array; break; + case 1: view = Float64Array; break; + case 2: view = Int8Array; break; + case 3: view = Uint8Array; break; + case 4: view = Int16Array; break; + case 5: view = Uint16Array; break; + case 6: view = Int32Array; break; + case 7: view = Int32Array; break; + case 8: view = Int32Array; break; + case 9: view = Int32Array; break; + case 10: view = Float32Array; break; + case 11: view = Float64Array; break; + case 12: view = Uint8Array; break; + } + if (!view) caml_invalid_argument("Bigarray.create: unsupported kind"); + var data = new view(size * caml_ba_get_size_per_element(kind)); + return data; + } +|}] + +let caml_ba_create_unsafe kind layout dims data = + let size_per_element = caml_ba_get_size_per_element kind in + if caml_ba_get_size dims * size_per_element != buffer_length data then + caml_invalid_argument "length doesn't match dims"; + if layout = 0 && Array.length dims = 1 && size_per_element = 1 then + ml_Bigarray_c_1_1 kind layout dims data + else + ml_Bigarray kind layout dims data + +let caml_ba_create kind layout dims = + let data = caml_ba_create_buffer kind (caml_ba_get_size dims) in + caml_ba_create_unsafe kind layout dims data + +external caml_ba_kind : ('a, 'b, 'c) genarray -> int = "kind" [@@bs.get] + +external caml_ba_layout : ('a, 'b, 'c) genarray -> int = "layout" [@@bs.get] + +let caml_ba_kind ba = caml_ba_kind ba + +let caml_ba_layout ba = caml_ba_layout ba + +let caml_ba_num_dims ba = Array.length (dims ba) + +let caml_ba_change_layout ba layout = + if caml_ba_layout ba == layout then + ba + else + let new_dims = Array.new_uninitialized 0 in + for i = 0 to caml_ba_num_dims ba - 1 do + Array.unsafe_set new_dims i (get_dim ba (caml_ba_num_dims ba - i - 1)) + done; + caml_ba_create_unsafe (caml_ba_kind ba) layout new_dims (buffer ba) + +let caml_ba_dim ba i = + if i < 0 || i >= caml_ba_num_dims ba then caml_invalid_argument "Bigarray.dim"; + get_dim ba i + +let caml_ba_dim_1 ba = caml_ba_dim ba 0 + +let caml_ba_dim_2 ba = caml_ba_dim ba 1 + +let caml_ba_dim_3 ba = caml_ba_dim ba 2 + +let caml_ba_get_generic ba i = + let ofs = offset ba i in + get ba ofs + +let caml_ba_get_1 ba i0 = get ba (offset ba [| i0 |]) + +let caml_ba_unsafe_get_1 = caml_ba_get_1 + +let caml_ba_get_2 ba i0 i1 = get ba (offset ba [| i0; i1 |]) + +let caml_ba_unsafe_get_2 = caml_ba_get_2 + +let caml_ba_get_3 ba i0 i1 i2 = get ba (offset ba [| i0; i1; i2 |]) + +let caml_ba_unsafe_get_3 = caml_ba_get_3 + +let caml_ba_set_generic ba i v = + let ofs = offset ba i in + set ba ofs v + +let caml_ba_set_1 ba i0 v = set ba (offset ba [| i0 |]) v + +let caml_ba_unsafe_set_1 = caml_ba_set_1 + +let caml_ba_set_2 ba i0 i1 v = set ba (offset ba [| i0; i1 |]) v + +let caml_ba_unsafe_set_2 = caml_ba_set_2 + +let caml_ba_set_3 ba i0 i1 i2 v = set ba (offset ba [| i0; i1; i2 |]) v + +let caml_ba_unsafe_set_3 = caml_ba_set_3 + +let caml_ba_fill ba v = fill ba v + +let caml_ba_blit src dst = + if caml_ba_num_dims dst != caml_ba_num_dims src then + caml_invalid_argument "Bigarray.blit: dimension mismatch"; + for i = 0 to caml_ba_num_dims dst - 1 do + if get_dim dst i != get_dim src i then + caml_invalid_argument "Bigarray.blit: dimension mismatch" + done; + buffer_set (buffer dst) (buffer src) + +let caml_ba_sub ba ofs len = + let changed_dim = { contents = 0 } in + let mul = { contents = 1 } in + let ofs = { contents = ofs } in + if caml_ba_layout ba = 0 then + for i = 1 to caml_ba_num_dims ba - 1 do + mul.contents <- mul.contents * get_dim ba i + done + else + for i = 0 to caml_ba_num_dims ba - 2 do + mul.contents <- mul.contents * get_dim ba i + done; + changed_dim.contents <- caml_ba_num_dims ba - 1; + ofs.contents <- ofs.contents - 1; + if + ofs.contents < 0 + || len < 0 + || ofs.contents + len > get_dim ba changed_dim.contents + then + caml_invalid_argument "Bigarray.sub: bad sub-array"; + let new_dims = Array.new_uninitialized 0 in + for i = 0 to caml_ba_num_dims ba - 1 do + Array.unsafe_set new_dims i (get_dim ba i) + done; + Array.unsafe_set new_dims changed_dim.contents len; + mul.contents <- mul.contents * caml_ba_get_size_per_element (caml_ba_kind ba); + let new_data = + sub + (buffer ba) + (ofs.contents * mul.contents) + ((ofs.contents + len) * mul.contents) + in + caml_ba_create_unsafe (caml_ba_kind ba) (caml_ba_layout ba) new_dims new_data + +let caml_ba_slice ba (vind : int array) = + let num_inds = Array.length vind in + let index = Array.new_uninitialized 0 in + let sub_dims = { contents = Array.new_uninitialized 0 } in + if num_inds > caml_ba_num_dims ba then + caml_invalid_argument "Bigarray.slice: too many indices"; + if caml_ba_layout ba = 0 then ( + for i = 0 to num_inds - 1 do + Array.unsafe_set index i (Array.unsafe_get vind i) + done; + for i = num_inds - 1 to caml_ba_num_dims ba - 1 do + Array.unsafe_set index i 0 + done; + sub_dims.contents <- [%raw {|ba.dims.slice(num_inds)|}]) + else ( + for i = 0 to num_inds - 1 do + Array.unsafe_set + index + (caml_ba_num_dims ba - num_inds + i) + (Array.unsafe_get vind i) + done; + for i = 0 to caml_ba_num_dims ba - num_inds - 1 do + Array.unsafe_set index i 1 + done; + sub_dims.contents <- [%raw {|ba.dims.slice(0, ba.dims.length - num_inds)|}]); + let ofs = offset ba index in + let size = caml_ba_get_size sub_dims.contents in + let size_per_element = caml_ba_get_size_per_element (caml_ba_kind ba) in + let new_data = + sub (buffer ba) (ofs * size_per_element) ((ofs + size) * size_per_element) + in + caml_ba_create_unsafe + (caml_ba_kind ba) + (caml_ba_layout ba) + sub_dims.contents + new_data + +let caml_ba_reshape ba (vind : int array) = + let new_dim = Array.new_uninitialized 0 in + let num_dims = Array.length vind in + if num_dims < 0 || num_dims > 16 then + caml_invalid_argument "Bigarray.reshape: bad number of dimensions"; + let num_elts = { contents = 1 } in + for i = 0 to num_dims - 1 do + Array.unsafe_set new_dim i (Array.unsafe_get vind i); + if Array.unsafe_get new_dim i < 0 then + caml_invalid_argument "Bigarray.reshape: negative dimension"; + num_elts.contents <- num_elts.contents * Array.unsafe_get new_dim i + done; + let size = caml_ba_get_size (dims ba) in + if num_elts.contents != size then + caml_invalid_argument "Bigarray.reshape: size mismatch"; + caml_ba_create_unsafe + (caml_ba_kind ba) + (caml_ba_layout ba) + new_dim + (buffer ba) diff --git a/jscomp/runtime/caml_bigarray.mli b/jscomp/runtime/caml_bigarray.mli new file mode 100644 index 0000000000..b02f164c48 --- /dev/null +++ b/jscomp/runtime/caml_bigarray.mli @@ -0,0 +1,90 @@ +type buffer + +type ('a, 'b, 'c) genarray + +val caml_array_bound_error : unit -> 'a + +val caml_invalid_argument : string -> 'a + +val caml_ba_custom_name : string + +val caml_ba_get_size : int array -> int + +val caml_ba_get_size_per_element : int -> int + +val caml_ba_create_buffer : int -> int -> buffer + +val caml_ba_create_unsafe + : int + -> int + -> int array + -> buffer + -> ('a, 'b, 'c) genarray + +val caml_ba_create : int -> int -> int array -> ('a, 'b, 'c) genarray + +val caml_ba_kind : ('a, 'b, 'c) genarray -> int + +val caml_ba_layout : ('a, 'b, 'c) genarray -> int + +val caml_ba_num_dims : ('a, 'b, 'c) genarray -> int + +val caml_ba_change_layout + : ('a, 'b, 'c) genarray + -> int + -> ('a, 'b, 'c) genarray + +val caml_ba_dim : ('a, 'b, 'c) genarray -> int -> int + +val caml_ba_dim_1 : ('a, 'b, 'c) genarray -> int + +val caml_ba_dim_2 : ('a, 'b, 'c) genarray -> int + +val caml_ba_dim_3 : ('a, 'b, 'c) genarray -> int + +val caml_ba_get_generic : ('a, 'b, 'c) genarray -> int array -> 'a + +val caml_ba_get_1 : ('a, 'b, 'c) genarray -> int -> 'a + +val caml_ba_unsafe_get_1 : ('a, 'b, 'c) genarray -> int -> 'a + +val caml_ba_get_2 : ('a, 'b, 'c) genarray -> int -> int -> 'a + +val caml_ba_unsafe_get_2 : ('a, 'b, 'c) genarray -> int -> int -> 'a + +val caml_ba_get_3 : ('a, 'b, 'c) genarray -> int -> int -> int -> 'a + +val caml_ba_unsafe_get_3 : ('a, 'b, 'c) genarray -> int -> int -> int -> 'a + +val caml_ba_set_generic : ('a, 'b, 'c) genarray -> int array -> 'a -> unit + +val caml_ba_set_1 : ('a, 'b, 'c) genarray -> int -> 'a -> unit + +val caml_ba_unsafe_set_1 : ('a, 'b, 'c) genarray -> int -> 'a -> unit + +val caml_ba_set_2 : ('a, 'b, 'c) genarray -> int -> int -> 'a -> unit + +val caml_ba_unsafe_set_2 : ('a, 'b, 'c) genarray -> int -> int -> 'a -> unit + +val caml_ba_set_3 : ('a, 'b, 'c) genarray -> int -> int -> int -> 'a -> unit + +val caml_ba_unsafe_set_3 + : ('a, 'b, 'c) genarray + -> int + -> int + -> int + -> 'a + -> unit + +val caml_ba_fill : ('a, 'b, 'c) genarray -> 'a -> unit + +val caml_ba_blit : ('a, 'b, 'c) genarray -> ('d, 'e, 'f) genarray -> unit + +val caml_ba_sub : ('a, 'b, 'c) genarray -> int -> int -> ('d, 'e, 'f) genarray + +val caml_ba_slice : ('a, 'b, 'c) genarray -> int array -> ('d, 'e, 'f) genarray + +val caml_ba_reshape + : ('a, 'b, 'c) genarray + -> int array + -> ('d, 'e, 'f) genarray diff --git a/jscomp/runtime/dune.gen b/jscomp/runtime/dune.gen index f486eb5e6e..f82d6370b8 100644 --- a/jscomp/runtime/dune.gen +++ b/jscomp/runtime/dune.gen @@ -49,6 +49,22 @@ (run %{workspace_root}/jscomp/main/js_main.exe -bs-cmi -bs-cmj -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -make-runtime -nopervasives -unsafe -w +50 -warn-error A -open Bs_stdlib_mini -I . %{inputs}))) + (rule + (targets caml_bigarray.cmj ) + (deps (:inputs caml_bigarray.ml) caml_array_extern.cmj caml_bigarray.cmi) + + (action + (run %{workspace_root}/jscomp/main/js_main.exe -bs-read-cmi -bs-cmi -bs-cmj -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -make-runtime -nopervasives -unsafe -w +50 -warn-error A -open Bs_stdlib_mini -I . %{inputs}))) + + + (rule + (targets caml_bigarray.cmi ) + (deps (:inputs caml_bigarray.mli) bs_stdlib_mini.cmi js.cmi js.cmj) + + (action + (run %{workspace_root}/jscomp/main/js_main.exe -bs-cmi -bs-cmj -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -make-runtime -nopervasives -unsafe -w +50 -warn-error A -open Bs_stdlib_mini -I . %{inputs}))) + + (rule (targets caml_bytes.cmj ) (deps (:inputs caml_bytes.ml) caml_bytes.cmi caml_string_extern.cmj) @@ -451,5 +467,5 @@ (alias (name runtime) - (deps bs_stdlib_mini.cmi js.cmj js.cmi caml.cmi caml.cmj caml_array.cmi caml_array.cmj caml_bytes.cmi caml_bytes.cmj caml_float.cmi caml_float.cmj caml_format.cmi caml_format.cmj caml_gc.cmi caml_gc.cmj caml_hash.cmi caml_hash.cmj caml_hash_primitive.cmi caml_hash_primitive.cmj caml_int32.cmi caml_int32.cmj caml_int64.cmi caml_int64.cmj caml_io.cmi caml_io.cmj caml_lexer.cmi caml_lexer.cmj caml_md5.cmi caml_md5.cmj caml_module.cmi caml_module.cmj caml_obj.cmi caml_obj.cmj caml_oo.cmi caml_oo.cmj caml_option.cmi caml_option.cmj caml_parser.cmi caml_parser.cmj caml_splice_call.cmi caml_splice_call.cmj caml_string.cmi caml_string.cmj caml_sys.cmi caml_sys.cmj caml_array_extern.cmi caml_array_extern.cmj caml_exceptions.cmi caml_exceptions.cmj caml_external_polyfill.cmi caml_external_polyfill.cmj caml_float_extern.cmi caml_float_extern.cmj caml_int32_extern.cmi caml_int32_extern.cmj caml_int64_extern.cmi caml_int64_extern.cmj caml_js_exceptions.cmi caml_js_exceptions.cmj caml_nativeint_extern.cmi caml_nativeint_extern.cmj caml_oo_curry.cmi caml_oo_curry.cmj caml_string_extern.cmi caml_string_extern.cmj caml_undefined_extern.cmi caml_undefined_extern.cmj curry.cmi curry.cmj)) + (deps bs_stdlib_mini.cmi js.cmj js.cmi caml.cmi caml.cmj caml_array.cmi caml_array.cmj caml_bigarray.cmi caml_bigarray.cmj caml_bytes.cmi caml_bytes.cmj caml_float.cmi caml_float.cmj caml_format.cmi caml_format.cmj caml_gc.cmi caml_gc.cmj caml_hash.cmi caml_hash.cmj caml_hash_primitive.cmi caml_hash_primitive.cmj caml_int32.cmi caml_int32.cmj caml_int64.cmi caml_int64.cmj caml_io.cmi caml_io.cmj caml_lexer.cmi caml_lexer.cmj caml_md5.cmi caml_md5.cmj caml_module.cmi caml_module.cmj caml_obj.cmi caml_obj.cmj caml_oo.cmi caml_oo.cmj caml_option.cmi caml_option.cmj caml_parser.cmi caml_parser.cmj caml_splice_call.cmi caml_splice_call.cmj caml_string.cmi caml_string.cmj caml_sys.cmi caml_sys.cmj caml_array_extern.cmi caml_array_extern.cmj caml_exceptions.cmi caml_exceptions.cmj caml_external_polyfill.cmi caml_external_polyfill.cmj caml_float_extern.cmi caml_float_extern.cmj caml_int32_extern.cmi caml_int32_extern.cmj caml_int64_extern.cmi caml_int64_extern.cmj caml_js_exceptions.cmi caml_js_exceptions.cmj caml_nativeint_extern.cmi caml_nativeint_extern.cmj caml_oo_curry.cmi caml_oo_curry.cmj caml_string_extern.cmi caml_string_extern.cmj caml_undefined_extern.cmi caml_undefined_extern.cmj curry.cmi curry.cmj)) diff --git a/jscomp/stdlib-412/stdlib.ml b/jscomp/stdlib-412/stdlib.ml index 7b689dd1a2..a10c767a17 100644 --- a/jscomp/stdlib-412/stdlib.ml +++ b/jscomp/stdlib-412/stdlib.ml @@ -5,10 +5,7 @@ module Arg = Arg module Array = Array module ArrayLabels = ArrayLabels module Atomic = Atomic -#if BS then -#else module Bigarray = Bigarray -#end module Bool = Bool module Buffer = Buffer module Bytes = Bytes diff --git a/jscomp/stdlib-412/stdlib.mli b/jscomp/stdlib-412/stdlib.mli index 1ed44a1020..7897ef0e92 100644 --- a/jscomp/stdlib-412/stdlib.mli +++ b/jscomp/stdlib-412/stdlib.mli @@ -1469,10 +1469,7 @@ module Arg = Arg module Array = Array module ArrayLabels = ArrayLabels module Atomic = Atomic -#if BS then -#else module Bigarray = Bigarray -#end module Bool = Bool module Buffer = Buffer module Bytes = Bytes diff --git a/jscomp/stdlib-412/stdlib_modules/bigarray.ml b/jscomp/stdlib-412/stdlib_modules/bigarray.ml new file mode 100644 index 0000000000..b3c63429af --- /dev/null +++ b/jscomp/stdlib-412/stdlib_modules/bigarray.ml @@ -0,0 +1,315 @@ +(**************************************************************************) +(* *) +(* OCaml *) +(* *) +(* Manuel Serrano et Xavier Leroy, INRIA Rocquencourt *) +(* *) +(* Copyright 2000 Institut National de Recherche en Informatique et *) +(* en Automatique. *) +(* *) +(* All rights reserved. This file is distributed under the terms of *) +(* the GNU Lesser General Public License version 2.1, with the *) +(* special exception on linking described in the file LICENSE. *) +(* *) +(**************************************************************************) +[@@@bs.config { flags = [|"-bs-no-cross-module-opt" |]}] +(* Module [Bigarray]: large, multi-dimensional, numerical arrays *) + + +include CamlinternalBigarray + +(* Keep those constants in sync with the caml_ba_kind enumeration + in bigarray.h *) + +let float32 = Float32 +let float64 = Float64 +let int8_signed = Int8_signed +let int8_unsigned = Int8_unsigned +let int16_signed = Int16_signed +let int16_unsigned = Int16_unsigned +let int32 = Int32 +let int64 = Int64 +let int = Int +let nativeint = Nativeint +let complex32 = Complex32 +let complex64 = Complex64 +let char = Char + +let kind_size_in_bytes : type a b. (a, b) kind -> int = function + | Float32 -> 4 + | Float64 -> 8 + | Int8_signed -> 1 + | Int8_unsigned -> 1 + | Int16_signed -> 2 + | Int16_unsigned -> 2 + | Int32 -> 4 + | Int64 -> 8 + | Int -> Sys.word_size / 8 + | Nativeint -> Sys.word_size / 8 + | Complex32 -> 8 + | Complex64 -> 16 + | Char -> 1 + +(* Keep those constants in sync with the caml_ba_layout enumeration + in bigarray.h *) + +let c_layout = C_layout +let fortran_layout = Fortran_layout + +module Genarray = struct + type ('a, 'b, 'c) t = ('a, 'b, 'c) genarray + external create: ('a, 'b) kind -> 'c layout -> int array -> ('a, 'b, 'c) t + = "caml_ba_create" + external get: ('a, 'b, 'c) t -> int array -> 'a + = "caml_ba_get_generic" + external set: ('a, 'b, 'c) t -> int array -> 'a -> unit + = "caml_ba_set_generic" + external num_dims: ('a, 'b, 'c) t -> int = "caml_ba_num_dims" + external nth_dim: ('a, 'b, 'c) t -> int -> int = "caml_ba_dim" + let dims a = + let n = num_dims a in + let d = Array.make n 0 in + for i = 0 to n-1 do d.(i) <- nth_dim a i done; + d + + external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "caml_ba_kind" + external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" + external change_layout: ('a, 'b, 'c) t -> 'd layout -> ('a, 'b, 'd) t + = "caml_ba_change_layout" + + let size_in_bytes arr = + (kind_size_in_bytes (kind arr)) * (Array.fold_left ( * ) 1 (dims arr)) + + external sub_left: ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) t + = "caml_ba_sub" + external sub_right: ('a, 'b, fortran_layout) t -> int -> int -> + ('a, 'b, fortran_layout) t + = "caml_ba_sub" + external slice_left: ('a, 'b, c_layout) t -> int array -> + ('a, 'b, c_layout) t + = "caml_ba_slice" + external slice_right: ('a, 'b, fortran_layout) t -> int array -> + ('a, 'b, fortran_layout) t + = "caml_ba_slice" + external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit + = "caml_ba_blit" + external fill: ('a, 'b, 'c) t -> 'a -> unit = "caml_ba_fill" +end + +module Array0 = struct + type ('a, 'b, 'c) t = ('a, 'b, 'c) Genarray.t + let create kind layout = + Genarray.create kind layout [||] + let get arr = Genarray.get arr [||] + let set arr = Genarray.set arr [||] + external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "caml_ba_kind" + external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" + + external change_layout: ('a, 'b, 'c) t -> 'd layout -> ('a, 'b, 'd) t + = "caml_ba_change_layout" + + let size_in_bytes arr = kind_size_in_bytes (kind arr) + + external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit = "caml_ba_blit" + external fill: ('a, 'b, 'c) t -> 'a -> unit = "caml_ba_fill" + + let of_value kind layout v = + let a = create kind layout in + set a v; + a +end + +module Array1 = struct + type ('a, 'b, 'c) t = ('a, 'b, 'c) Genarray.t + let create kind layout dim = + Genarray.create kind layout [|dim|] + external get: ('a, 'b, 'c) t -> int -> 'a = "caml_ba_get_1" + external set: ('a, 'b, 'c) t -> int -> 'a -> unit = "caml_ba_set_1" + external unsafe_get: ('a, 'b, 'c) t -> int -> 'a = "caml_ba_unsafe_get_1" + external unsafe_set: ('a, 'b, 'c) t -> int -> 'a -> unit + = "caml_ba_unsafe_set_1" + external dim: ('a, 'b, 'c) t -> int = "caml_ba_dim_1" + external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "caml_ba_kind" + external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" + + external change_layout: ('a, 'b, 'c) t -> 'd layout -> ('a, 'b, 'd) t + = "caml_ba_change_layout" + + let size_in_bytes arr = + (kind_size_in_bytes (kind arr)) * (dim arr) + + external sub: ('a, 'b, 'c) t -> int -> int -> ('a, 'b, 'c) t = "caml_ba_sub" + let slice (type t) (a : (_, _, t) Genarray.t) n = + match layout a with + | C_layout -> (Genarray.slice_left a [|n|] : (_, _, t) Genarray.t) + | Fortran_layout -> (Genarray.slice_right a [|n|]: (_, _, t) Genarray.t) + external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit = "caml_ba_blit" + external fill: ('a, 'b, 'c) t -> 'a -> unit = "caml_ba_fill" + let of_array (type t) kind (layout: t layout) data = + let ba = create kind layout (Array.length data) in + let ofs = + match layout with + C_layout -> 0 + | Fortran_layout -> 1 + in + for i = 0 to Array.length data - 1 do unsafe_set ba (i + ofs) data.(i) done; + ba +end + +module Array2 = struct + type ('a, 'b, 'c) t = ('a, 'b, 'c) Genarray.t + let create kind layout dim1 dim2 = + Genarray.create kind layout [|dim1; dim2|] + external get: ('a, 'b, 'c) t -> int -> int -> 'a = "caml_ba_get_2" + external set: ('a, 'b, 'c) t -> int -> int -> 'a -> unit = "caml_ba_set_2" + external unsafe_get: ('a, 'b, 'c) t -> int -> int -> 'a + = "caml_ba_unsafe_get_2" + external unsafe_set: ('a, 'b, 'c) t -> int -> int -> 'a -> unit + = "caml_ba_unsafe_set_2" + external dim1: ('a, 'b, 'c) t -> int = "caml_ba_dim_1" + external dim2: ('a, 'b, 'c) t -> int = "caml_ba_dim_2" + external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "caml_ba_kind" + external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" + + external change_layout: ('a, 'b, 'c) t -> 'd layout -> ('a, 'b, 'd) t + = "caml_ba_change_layout" + + let size_in_bytes arr = + (kind_size_in_bytes (kind arr)) * (dim1 arr) * (dim2 arr) + + external sub_left: ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) t + = "caml_ba_sub" + external sub_right: + ('a, 'b, fortran_layout) t -> int -> int -> ('a, 'b, fortran_layout) t + = "caml_ba_sub" + let slice_left a n = Genarray.slice_left a [|n|] + let slice_right a n = Genarray.slice_right a [|n|] + external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit = "caml_ba_blit" + external fill: ('a, 'b, 'c) t -> 'a -> unit = "caml_ba_fill" + let of_array (type t) kind (layout: t layout) data = + let dim1 = Array.length data in + let dim2 = if dim1 = 0 then 0 else Array.length data.(0) in + let ba = create kind layout dim1 dim2 in + let ofs = + match layout with + C_layout -> 0 + | Fortran_layout -> 1 + in + for i = 0 to dim1 - 1 do + let row = data.(i) in + if Array.length row <> dim2 then + invalid_arg("Bigarray.Array2.of_array: non-rectangular data"); + for j = 0 to dim2 - 1 do + unsafe_set ba (i + ofs) (j + ofs) row.(j) + done + done; + ba +end + +module Array3 = struct + type ('a, 'b, 'c) t = ('a, 'b, 'c) Genarray.t + let create kind layout dim1 dim2 dim3 = + Genarray.create kind layout [|dim1; dim2; dim3|] + external get: ('a, 'b, 'c) t -> int -> int -> int -> 'a = "caml_ba_get_3" + external set: ('a, 'b, 'c) t -> int -> int -> int -> 'a -> unit + = "caml_ba_set_3" + external unsafe_get: ('a, 'b, 'c) t -> int -> int -> int -> 'a + = "caml_ba_unsafe_get_3" + external unsafe_set: ('a, 'b, 'c) t -> int -> int -> int -> 'a -> unit + = "caml_ba_unsafe_set_3" + external dim1: ('a, 'b, 'c) t -> int = "caml_ba_dim_1" + external dim2: ('a, 'b, 'c) t -> int = "caml_ba_dim_2" + external dim3: ('a, 'b, 'c) t -> int = "caml_ba_dim_3" + external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "caml_ba_kind" + external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" + + external change_layout: ('a, 'b, 'c) t -> 'd layout -> ('a, 'b, 'd) t + = "caml_ba_change_layout" + + let size_in_bytes arr = + (kind_size_in_bytes (kind arr)) * (dim1 arr) * (dim2 arr) * (dim3 arr) + + external sub_left: ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) t + = "caml_ba_sub" + external sub_right: + ('a, 'b, fortran_layout) t -> int -> int -> ('a, 'b, fortran_layout) t + = "caml_ba_sub" + let slice_left_1 a n m = Genarray.slice_left a [|n; m|] + let slice_right_1 a n m = Genarray.slice_right a [|n; m|] + let slice_left_2 a n = Genarray.slice_left a [|n|] + let slice_right_2 a n = Genarray.slice_right a [|n|] + external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit = "caml_ba_blit" + external fill: ('a, 'b, 'c) t -> 'a -> unit = "caml_ba_fill" + let of_array (type t) kind (layout: t layout) data = + let dim1 = Array.length data in + let dim2 = if dim1 = 0 then 0 else Array.length data.(0) in + let dim3 = if dim2 = 0 then 0 else Array.length data.(0).(0) in + let ba = create kind layout dim1 dim2 dim3 in + let ofs = + match layout with + C_layout -> 0 + | Fortran_layout -> 1 + in + for i = 0 to dim1 - 1 do + let row = data.(i) in + if Array.length row <> dim2 then + invalid_arg("Bigarray.Array3.of_array: non-cubic data"); + for j = 0 to dim2 - 1 do + let col = row.(j) in + if Array.length col <> dim3 then + invalid_arg("Bigarray.Array3.of_array: non-cubic data"); + for k = 0 to dim3 - 1 do + unsafe_set ba (i + ofs) (j + ofs) (k + ofs) col.(k) + done + done + done; + ba + +end + +external genarray_of_array0: ('a, 'b, 'c) Array0.t -> ('a, 'b, 'c) Genarray.t + = "%identity" +external genarray_of_array1: ('a, 'b, 'c) Array1.t -> ('a, 'b, 'c) Genarray.t + = "%identity" +external genarray_of_array2: ('a, 'b, 'c) Array2.t -> ('a, 'b, 'c) Genarray.t + = "%identity" +external genarray_of_array3: ('a, 'b, 'c) Array3.t -> ('a, 'b, 'c) Genarray.t + = "%identity" +let array0_of_genarray a = + if Genarray.num_dims a = 0 then a + else invalid_arg "Bigarray.array0_of_genarray" +let array1_of_genarray a = + if Genarray.num_dims a = 1 then a + else invalid_arg "Bigarray.array1_of_genarray" +let array2_of_genarray a = + if Genarray.num_dims a = 2 then a + else invalid_arg "Bigarray.array2_of_genarray" +let array3_of_genarray a = + if Genarray.num_dims a = 3 then a + else invalid_arg "Bigarray.array3_of_genarray" + +external reshape: + ('a, 'b, 'c) Genarray.t -> int array -> ('a, 'b, 'c) Genarray.t + = "caml_ba_reshape" +let reshape_0 a = reshape a [||] +let reshape_1 a dim1 = reshape a [|dim1|] +let reshape_2 a dim1 dim2 = reshape a [|dim1;dim2|] +let reshape_3 a dim1 dim2 dim3 = reshape a [|dim1;dim2;dim3|] + +(* Force caml_ba_get_{1,2,3,N} to be linked in, since we don't refer + to those primitives directly in this file *) + +let _ = + let _ = Genarray.get in + let _ = Array1.get in + let _ = Array2.get in + let _ = Array3.get in + () + +[@@@ocaml.warning "-32"] +external get1: unit -> unit = "caml_ba_get_1" +external get2: unit -> unit = "caml_ba_get_2" +external get3: unit -> unit = "caml_ba_get_3" +external set1: unit -> unit = "caml_ba_set_1" +external set2: unit -> unit = "caml_ba_set_2" +external set3: unit -> unit = "caml_ba_set_3" \ No newline at end of file diff --git a/jscomp/stdlib-412/stdlib_modules/bigarray.mli b/jscomp/stdlib-412/stdlib_modules/bigarray.mli new file mode 100644 index 0000000000..c398bfcb9b --- /dev/null +++ b/jscomp/stdlib-412/stdlib_modules/bigarray.mli @@ -0,0 +1,937 @@ +(**************************************************************************) +(* *) +(* OCaml *) +(* *) +(* Manuel Serrano and Xavier Leroy, INRIA Rocquencourt *) +(* *) +(* Copyright 2000 Institut National de Recherche en Informatique et *) +(* en Automatique. *) +(* *) +(* All rights reserved. This file is distributed under the terms of *) +(* the GNU Lesser General Public License version 2.1, with the *) +(* special exception on linking described in the file LICENSE. *) +(* *) +(**************************************************************************) + +(** Large, multi-dimensional, numerical arrays. + + This module implements multi-dimensional arrays of integers and + floating-point numbers, thereafter referred to as 'big arrays'. + The implementation allows efficient sharing of large numerical + arrays between OCaml code and C or Fortran numerical libraries. + + Concerning the naming conventions, users of this module are encouraged + to do [open Bigarray] in their source, then refer to array types and + operations via short dot notation, e.g. [Array1.t] or [Array2.sub]. + + Big arrays support all the OCaml ad-hoc polymorphic operations: + - comparisons ([=], [<>], [<=], etc, as well as {!Pervasives.compare}); + - hashing (module [Hash]); + - and structured input-output (the functions from the + {!Marshal} module, as well as {!Pervasives.output_value} + and {!Pervasives.input_value}). +*) + +(** {1 Element kinds} *) + +(** Big arrays can contain elements of the following kinds: +- IEEE single precision (32 bits) floating-point numbers + ({!Bigarray.float32_elt}), +- IEEE double precision (64 bits) floating-point numbers + ({!Bigarray.float64_elt}), +- IEEE single precision (2 * 32 bits) floating-point complex numbers + ({!Bigarray.complex32_elt}), +- IEEE double precision (2 * 64 bits) floating-point complex numbers + ({!Bigarray.complex64_elt}), +- 8-bit integers (signed or unsigned) + ({!Bigarray.int8_signed_elt} or {!Bigarray.int8_unsigned_elt}), +- 16-bit integers (signed or unsigned) + ({!Bigarray.int16_signed_elt} or {!Bigarray.int16_unsigned_elt}), +- OCaml integers (signed, 31 bits on 32-bit architectures, + 63 bits on 64-bit architectures) ({!Bigarray.int_elt}), +- 32-bit signed integers ({!Bigarray.int32_elt}), +- 64-bit signed integers ({!Bigarray.int64_elt}), +- platform-native signed integers (32 bits on 32-bit architectures, + 64 bits on 64-bit architectures) ({!Bigarray.nativeint_elt}). + + Each element kind is represented at the type level by one of the + [*_elt] types defined below (defined with a single constructor instead + of abstract types for technical injectivity reasons). +*) + +type float32_elt = CamlinternalBigarray.float32_elt = Float32_elt +type float64_elt = CamlinternalBigarray.float64_elt = Float64_elt +type int8_signed_elt = CamlinternalBigarray.int8_signed_elt = Int8_signed_elt +type int8_unsigned_elt = CamlinternalBigarray.int8_unsigned_elt = + Int8_unsigned_elt +type int16_signed_elt = CamlinternalBigarray.int16_signed_elt = + Int16_signed_elt +type int16_unsigned_elt = CamlinternalBigarray.int16_unsigned_elt = + Int16_unsigned_elt +type int32_elt = CamlinternalBigarray.int32_elt = Int32_elt +type int64_elt = CamlinternalBigarray.int64_elt = Int64_elt +type int_elt = CamlinternalBigarray.int_elt = Int_elt +type nativeint_elt = CamlinternalBigarray.nativeint_elt = Nativeint_elt +type complex32_elt = CamlinternalBigarray.complex32_elt = Complex32_elt +type complex64_elt = CamlinternalBigarray.complex64_elt = Complex64_elt + +type ('a, 'b) kind = ('a, 'b) CamlinternalBigarray.kind = + Float32 : (float, float32_elt) kind + | Float64 : (float, float64_elt) kind + | Int8_signed : (int, int8_signed_elt) kind + | Int8_unsigned : (int, int8_unsigned_elt) kind + | Int16_signed : (int, int16_signed_elt) kind + | Int16_unsigned : (int, int16_unsigned_elt) kind + | Int32 : (int32, int32_elt) kind + | Int64 : (int64, int64_elt) kind + | Int : (int, int_elt) kind + | Nativeint : (nativeint, nativeint_elt) kind + | Complex32 : (Complex.t, complex32_elt) kind + | Complex64 : (Complex.t, complex64_elt) kind + | Char : (char, int8_unsigned_elt) kind (**) +(** To each element kind is associated an OCaml type, which is + the type of OCaml values that can be stored in the big array + or read back from it. This type is not necessarily the same + as the type of the array elements proper: for instance, + a big array whose elements are of kind [float32_elt] contains + 32-bit single precision floats, but reading or writing one of + its elements from OCaml uses the OCaml type [float], which is + 64-bit double precision floats. + + The GADT type [('a, 'b) kind] captures this association + of an OCaml type ['a] for values read or written in the big array, + and of an element kind ['b] which represents the actual contents + of the big array. Its constructors list all possible associations + of OCaml types with element kinds, and are re-exported below for + backward-compatibility reasons. + + Using a generalized algebraic datatype (GADT) here allows to write + well-typed polymorphic functions whose return type depend on the + argument type, such as: + +{[ + let zero : type a b. (a, b) kind -> a = function + | Float32 -> 0.0 | Complex32 -> Complex.zero + | Float64 -> 0.0 | Complex64 -> Complex.zero + | Int8_signed -> 0 | Int8_unsigned -> 0 + | Int16_signed -> 0 | Int16_unsigned -> 0 + | Int32 -> 0l | Int64 -> 0L + | Int -> 0 | Nativeint -> 0n + | Char -> '\000' +]} +*) + +val float32 : (float, float32_elt) kind +(** See {!Bigarray.char}. *) + +val float64 : (float, float64_elt) kind +(** See {!Bigarray.char}. *) + +val complex32 : (Complex.t, complex32_elt) kind +(** See {!Bigarray.char}. *) + +val complex64 : (Complex.t, complex64_elt) kind +(** See {!Bigarray.char}. *) + +val int8_signed : (int, int8_signed_elt) kind +(** See {!Bigarray.char}. *) + +val int8_unsigned : (int, int8_unsigned_elt) kind +(** See {!Bigarray.char}. *) + +val int16_signed : (int, int16_signed_elt) kind +(** See {!Bigarray.char}. *) + +val int16_unsigned : (int, int16_unsigned_elt) kind +(** See {!Bigarray.char}. *) + +val int : (int, int_elt) kind +(** See {!Bigarray.char}. *) + +val int32 : (int32, int32_elt) kind +(** See {!Bigarray.char}. *) + +val int64 : (int64, int64_elt) kind +(** See {!Bigarray.char}. *) + +val nativeint : (nativeint, nativeint_elt) kind +(** See {!Bigarray.char}. *) + +val char : (char, int8_unsigned_elt) kind +(** As shown by the types of the values above, + big arrays of kind [float32_elt] and [float64_elt] are + accessed using the OCaml type [float]. Big arrays of complex kinds + [complex32_elt], [complex64_elt] are accessed with the OCaml type + {!Complex.t}. Big arrays of + integer kinds are accessed using the smallest OCaml integer + type large enough to represent the array elements: + [int] for 8- and 16-bit integer bigarrays, as well as OCaml-integer + bigarrays; [int32] for 32-bit integer bigarrays; [int64] + for 64-bit integer bigarrays; and [nativeint] for + platform-native integer bigarrays. Finally, big arrays of + kind [int8_unsigned_elt] can also be accessed as arrays of + characters instead of arrays of small integers, by using + the kind value [char] instead of [int8_unsigned]. *) + +val kind_size_in_bytes : ('a, 'b) kind -> int +(** [kind_size_in_bytes k] is the number of bytes used to store + an element of type [k]. + + @since 4.03.0 *) + +(** {1 Array layouts} *) + +type c_layout = CamlinternalBigarray.c_layout = C_layout_typ (**) +(** See {!Bigarray.fortran_layout}.*) + +type fortran_layout = CamlinternalBigarray.fortran_layout = + Fortran_layout_typ (**) +(** To facilitate interoperability with existing C and Fortran code, + this library supports two different memory layouts for big arrays, + one compatible with the C conventions, + the other compatible with the Fortran conventions. + + In the C-style layout, array indices start at 0, and + multi-dimensional arrays are laid out in row-major format. + That is, for a two-dimensional array, all elements of + row 0 are contiguous in memory, followed by all elements of + row 1, etc. In other terms, the array elements at [(x,y)] + and [(x, y+1)] are adjacent in memory. + + In the Fortran-style layout, array indices start at 1, and + multi-dimensional arrays are laid out in column-major format. + That is, for a two-dimensional array, all elements of + column 0 are contiguous in memory, followed by all elements of + column 1, etc. In other terms, the array elements at [(x,y)] + and [(x+1, y)] are adjacent in memory. + + Each layout style is identified at the type level by the + phantom types {!Bigarray.c_layout} and {!Bigarray.fortran_layout} + respectively. *) + +(** {7 Supported layouts} + + The GADT type ['a layout] represents one of the two supported + memory layouts: C-style or Fortran-style. Its constructors are + re-exported as values below for backward-compatibility reasons. +*) + +type 'a layout = 'a CamlinternalBigarray.layout = + C_layout: c_layout layout + | Fortran_layout: fortran_layout layout + +val c_layout : c_layout layout +val fortran_layout : fortran_layout layout + + +(** {1 Generic arrays (of arbitrarily many dimensions)} *) + +module Genarray : + sig + type ('a, 'b, 'c) t = ('a, 'b, 'c) CamlinternalBigarray.genarray + (** The type [Genarray.t] is the type of big arrays with variable + numbers of dimensions. Any number of dimensions between 0 and 16 + is supported. + + The three type parameters to [Genarray.t] identify the array element + kind and layout, as follows: + - the first parameter, ['a], is the OCaml type for accessing array + elements ([float], [int], [int32], [int64], [nativeint]); + - the second parameter, ['b], is the actual kind of array elements + ([float32_elt], [float64_elt], [int8_signed_elt], [int8_unsigned_elt], + etc); + - the third parameter, ['c], identifies the array layout + ([c_layout] or [fortran_layout]). + + For instance, [(float, float32_elt, fortran_layout) Genarray.t] + is the type of generic big arrays containing 32-bit floats + in Fortran layout; reads and writes in this array use the + OCaml type [float]. *) + + external create: ('a, 'b) kind -> 'c layout -> int array -> ('a, 'b, 'c) t + = "caml_ba_create" + (** [Genarray.create kind layout dimensions] returns a new big array + whose element kind is determined by the parameter [kind] (one of + [float32], [float64], [int8_signed], etc) and whose layout is + determined by the parameter [layout] (one of [c_layout] or + [fortran_layout]). The [dimensions] parameter is an array of + integers that indicate the size of the big array in each dimension. + The length of [dimensions] determines the number of dimensions + of the bigarray. + + For instance, [Genarray.create int32 c_layout [|4;6;8|]] + returns a fresh big array of 32-bit integers, in C layout, + having three dimensions, the three dimensions being 4, 6 and 8 + respectively. + + Big arrays returned by [Genarray.create] are not initialized: + the initial values of array elements is unspecified. + + [Genarray.create] raises [Invalid_argument] if the number of dimensions + is not in the range 0 to 16 inclusive, or if one of the dimensions + is negative. *) + + external num_dims: ('a, 'b, 'c) t -> int = "caml_ba_num_dims" + (** Return the number of dimensions of the given big array. *) + + val dims : ('a, 'b, 'c) t -> int array + (** [Genarray.dims a] returns all dimensions of the big array [a], + as an array of integers of length [Genarray.num_dims a]. *) + + external nth_dim: ('a, 'b, 'c) t -> int -> int = "caml_ba_dim" + (** [Genarray.nth_dim a n] returns the [n]-th dimension of the + big array [a]. The first dimension corresponds to [n = 0]; + the second dimension corresponds to [n = 1]; the last dimension, + to [n = Genarray.num_dims a - 1]. + Raise [Invalid_argument] if [n] is less than 0 or greater or equal than + [Genarray.num_dims a]. *) + + external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "caml_ba_kind" + (** Return the kind of the given big array. *) + + external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" + (** Return the layout of the given big array. *) + + external change_layout: ('a, 'b, 'c) t -> 'd layout -> ('a, 'b, 'd) t + = "caml_ba_change_layout" + (** [Genarray.change_layout a layout] returns a bigarray with the + specified [layout], sharing the data with [a] (and hence having + the same dimensions as [a]). No copying of elements is involved: the + new array and the original array share the same storage space. + The dimensions are reversed, such that [get v [| a; b |]] in + C layout becomes [get v [| b+1; a+1 |]] in Fortran layout. + + @since 4.04.0 + *) + + val size_in_bytes : ('a, 'b, 'c) t -> int + (** [size_in_bytes a] is the number of elements in [a] multiplied + by [a]'s {!kind_size_in_bytes}. + + @since 4.03.0 *) + + external get: ('a, 'b, 'c) t -> int array -> 'a = "caml_ba_get_generic" + (** Read an element of a generic big array. + [Genarray.get a [|i1; ...; iN|]] returns the element of [a] + whose coordinates are [i1] in the first dimension, [i2] in + the second dimension, ..., [iN] in the [N]-th dimension. + + If [a] has C layout, the coordinates must be greater or equal than 0 + and strictly less than the corresponding dimensions of [a]. + If [a] has Fortran layout, the coordinates must be greater or equal + than 1 and less or equal than the corresponding dimensions of [a]. + Raise [Invalid_argument] if the array [a] does not have exactly [N] + dimensions, or if the coordinates are outside the array bounds. + + If [N > 3], alternate syntax is provided: you can write + [a.{i1, i2, ..., iN}] instead of [Genarray.get a [|i1; ...; iN|]]. + (The syntax [a.{...}] with one, two or three coordinates is + reserved for accessing one-, two- and three-dimensional arrays + as described below.) *) + + external set: ('a, 'b, 'c) t -> int array -> 'a -> unit + = "caml_ba_set_generic" + (** Assign an element of a generic big array. + [Genarray.set a [|i1; ...; iN|] v] stores the value [v] in the + element of [a] whose coordinates are [i1] in the first dimension, + [i2] in the second dimension, ..., [iN] in the [N]-th dimension. + + The array [a] must have exactly [N] dimensions, and all coordinates + must lie inside the array bounds, as described for [Genarray.get]; + otherwise, [Invalid_argument] is raised. + + If [N > 3], alternate syntax is provided: you can write + [a.{i1, i2, ..., iN} <- v] instead of + [Genarray.set a [|i1; ...; iN|] v]. + (The syntax [a.{...} <- v] with one, two or three coordinates is + reserved for updating one-, two- and three-dimensional arrays + as described below.) *) + + external sub_left: ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) t + = "caml_ba_sub" + (** Extract a sub-array of the given big array by restricting the + first (left-most) dimension. [Genarray.sub_left a ofs len] + returns a big array with the same number of dimensions as [a], + and the same dimensions as [a], except the first dimension, + which corresponds to the interval [[ofs ... ofs + len - 1]] + of the first dimension of [a]. No copying of elements is + involved: the sub-array and the original array share the same + storage space. In other terms, the element at coordinates + [[|i1; ...; iN|]] of the sub-array is identical to the + element at coordinates [[|i1+ofs; ...; iN|]] of the original + array [a]. + + [Genarray.sub_left] applies only to big arrays in C layout. + Raise [Invalid_argument] if [ofs] and [len] do not designate + a valid sub-array of [a], that is, if [ofs < 0], or [len < 0], + or [ofs + len > Genarray.nth_dim a 0]. *) + + external sub_right: + ('a, 'b, fortran_layout) t -> int -> int -> ('a, 'b, fortran_layout) t + = "caml_ba_sub" + (** Extract a sub-array of the given big array by restricting the + last (right-most) dimension. [Genarray.sub_right a ofs len] + returns a big array with the same number of dimensions as [a], + and the same dimensions as [a], except the last dimension, + which corresponds to the interval [[ofs ... ofs + len - 1]] + of the last dimension of [a]. No copying of elements is + involved: the sub-array and the original array share the same + storage space. In other terms, the element at coordinates + [[|i1; ...; iN|]] of the sub-array is identical to the + element at coordinates [[|i1; ...; iN+ofs|]] of the original + array [a]. + + [Genarray.sub_right] applies only to big arrays in Fortran layout. + Raise [Invalid_argument] if [ofs] and [len] do not designate + a valid sub-array of [a], that is, if [ofs < 1], or [len < 0], + or [ofs + len > Genarray.nth_dim a (Genarray.num_dims a - 1)]. *) + + external slice_left: + ('a, 'b, c_layout) t -> int array -> ('a, 'b, c_layout) t + = "caml_ba_slice" + (** Extract a sub-array of lower dimension from the given big array + by fixing one or several of the first (left-most) coordinates. + [Genarray.slice_left a [|i1; ... ; iM|]] returns the 'slice' + of [a] obtained by setting the first [M] coordinates to + [i1], ..., [iM]. If [a] has [N] dimensions, the slice has + dimension [N - M], and the element at coordinates + [[|j1; ...; j(N-M)|]] in the slice is identical to the element + at coordinates [[|i1; ...; iM; j1; ...; j(N-M)|]] in the original + array [a]. No copying of elements is involved: the slice and + the original array share the same storage space. + + [Genarray.slice_left] applies only to big arrays in C layout. + Raise [Invalid_argument] if [M >= N], or if [[|i1; ... ; iM|]] + is outside the bounds of [a]. *) + + external slice_right: + ('a, 'b, fortran_layout) t -> int array -> ('a, 'b, fortran_layout) t + = "caml_ba_slice" + (** Extract a sub-array of lower dimension from the given big array + by fixing one or several of the last (right-most) coordinates. + [Genarray.slice_right a [|i1; ... ; iM|]] returns the 'slice' + of [a] obtained by setting the last [M] coordinates to + [i1], ..., [iM]. If [a] has [N] dimensions, the slice has + dimension [N - M], and the element at coordinates + [[|j1; ...; j(N-M)|]] in the slice is identical to the element + at coordinates [[|j1; ...; j(N-M); i1; ...; iM|]] in the original + array [a]. No copying of elements is involved: the slice and + the original array share the same storage space. + + [Genarray.slice_right] applies only to big arrays in Fortran layout. + Raise [Invalid_argument] if [M >= N], or if [[|i1; ... ; iM|]] + is outside the bounds of [a]. *) + + external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit + = "caml_ba_blit" + (** Copy all elements of a big array in another big array. + [Genarray.blit src dst] copies all elements of [src] into + [dst]. Both arrays [src] and [dst] must have the same number of + dimensions and equal dimensions. Copying a sub-array of [src] + to a sub-array of [dst] can be achieved by applying [Genarray.blit] + to sub-array or slices of [src] and [dst]. *) + + external fill: ('a, 'b, 'c) t -> 'a -> unit = "caml_ba_fill" + (** Set all elements of a big array to a given value. + [Genarray.fill a v] stores the value [v] in all elements of + the big array [a]. Setting only some elements of [a] to [v] + can be achieved by applying [Genarray.fill] to a sub-array + or a slice of [a]. *) + + end + +(** {1 Zero-dimensional arrays} *) + +(** Zero-dimensional arrays. The [Array0] structure provides operations + similar to those of {!Bigarray.Genarray}, but specialized to the case + of zero-dimensional arrays that only contain a single scalar value. + Statically knowing the number of dimensions of the array allows + faster operations, and more precise static type-checking. + @since 4.05.0 *) +module Array0 : sig + type ('a, 'b, 'c) t + (** The type of zero-dimensional big arrays whose elements have + OCaml type ['a], representation kind ['b], and memory layout ['c]. *) + + val create: ('a, 'b) kind -> 'c layout -> ('a, 'b, 'c) t + (** [Array0.create kind layout] returns a new bigarray of zero dimension. + [kind] and [layout] determine the array element kind and the array + layout as described for {!Genarray.create}. *) + + external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "caml_ba_kind" + (** Return the kind of the given big array. *) + + external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" + (** Return the layout of the given big array. *) + + val change_layout: ('a, 'b, 'c) t -> 'd layout -> ('a, 'b, 'd) t + (** [Array0.change_layout a layout] returns a big array with the + specified [layout], sharing the data with [a]. No copying of elements + is involved: the new array and the original array share the same + storage space. + + @since 4.06.0 + *) + + val size_in_bytes : ('a, 'b, 'c) t -> int + (** [size_in_bytes a] is [a]'s {!kind_size_in_bytes}. *) + + val get: ('a, 'b, 'c) t -> 'a + (** [Array0.get a] returns the only element in [a]. *) + + val set: ('a, 'b, 'c) t -> 'a -> unit + (** [Array0.set a x v] stores the value [v] in [a]. *) + + external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit = "caml_ba_blit" + (** Copy the first big array to the second big array. + See {!Genarray.blit} for more details. *) + + external fill: ('a, 'b, 'c) t -> 'a -> unit = "caml_ba_fill" + (** Fill the given big array with the given value. + See {!Genarray.fill} for more details. *) + + val of_value: ('a, 'b) kind -> 'c layout -> 'a -> ('a, 'b, 'c) t + (** Build a zero-dimensional big array initialized from the + given value. *) + +end + + +(** {1 One-dimensional arrays} *) + +(** One-dimensional arrays. The [Array1] structure provides operations + similar to those of + {!Bigarray.Genarray}, but specialized to the case of one-dimensional arrays. + (The {!Array2} and {!Array3} structures below provide operations + specialized for two- and three-dimensional arrays.) + Statically knowing the number of dimensions of the array allows + faster operations, and more precise static type-checking. *) +module Array1 : sig + type ('a, 'b, 'c) t + (** The type of one-dimensional big arrays whose elements have + OCaml type ['a], representation kind ['b], and memory layout ['c]. *) + + val create: ('a, 'b) kind -> 'c layout -> int -> ('a, 'b, 'c) t + (** [Array1.create kind layout dim] returns a new bigarray of + one dimension, whose size is [dim]. [kind] and [layout] + determine the array element kind and the array layout + as described for {!Genarray.create}. *) + + external dim: ('a, 'b, 'c) t -> int = "caml_ba_dim_1" + (** Return the size (dimension) of the given one-dimensional + big array. *) + + external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "caml_ba_kind" + (** Return the kind of the given big array. *) + + external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" + (** Return the layout of the given big array. *) + + val change_layout: ('a, 'b, 'c) t -> 'd layout -> ('a, 'b, 'd) t + (** [Array1.change_layout a layout] returns a bigarray with the + specified [layout], sharing the data with [a] (and hence having + the same dimension as [a]). No copying of elements is involved: the + new array and the original array share the same storage space. + + @since 4.06.0 + *) + + + val size_in_bytes : ('a, 'b, 'c) t -> int + (** [size_in_bytes a] is the number of elements in [a] + multiplied by [a]'s {!kind_size_in_bytes}. + + @since 4.03.0 *) + + external get: ('a, 'b, 'c) t -> int -> 'a = "caml_ba_get_1" + (** [Array1.get a x], or alternatively [a.{x}], + returns the element of [a] at index [x]. + [x] must be greater or equal than [0] and strictly less than + [Array1.dim a] if [a] has C layout. If [a] has Fortran layout, + [x] must be greater or equal than [1] and less or equal than + [Array1.dim a]. Otherwise, [Invalid_argument] is raised. *) + + external set: ('a, 'b, 'c) t -> int -> 'a -> unit = "caml_ba_set_1" + (** [Array1.set a x v], also written [a.{x} <- v], + stores the value [v] at index [x] in [a]. + [x] must be inside the bounds of [a] as described in + {!Bigarray.Array1.get}; + otherwise, [Invalid_argument] is raised. *) + + external sub: ('a, 'b, 'c) t -> int -> int -> ('a, 'b, 'c) t + = "caml_ba_sub" + (** Extract a sub-array of the given one-dimensional big array. + See {!Genarray.sub_left} for more details. *) + + val slice: ('a, 'b, 'c) t -> int -> ('a, 'b, 'c) Array0.t + (** Extract a scalar (zero-dimensional slice) of the given one-dimensional + big array. The integer parameter is the index of the scalar to + extract. See {!Bigarray.Genarray.slice_left} and + {!Bigarray.Genarray.slice_right} for more details. + @since 4.05.0 *) + + external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit + = "caml_ba_blit" + (** Copy the first big array to the second big array. + See {!Genarray.blit} for more details. *) + + external fill: ('a, 'b, 'c) t -> 'a -> unit = "caml_ba_fill" + (** Fill the given big array with the given value. + See {!Genarray.fill} for more details. *) + + val of_array: ('a, 'b) kind -> 'c layout -> 'a array -> ('a, 'b, 'c) t + (** Build a one-dimensional big array initialized from the + given array. *) + + + external unsafe_get: ('a, 'b, 'c) t -> int -> 'a = "caml_ba_unsafe_get_1" + (** Like {!Bigarray.Array1.get}, but bounds checking is not always performed. + Use with caution and only when the program logic guarantees that + the access is within bounds. *) + + external unsafe_set: ('a, 'b, 'c) t -> int -> 'a -> unit + = "caml_ba_unsafe_set_1" + (** Like {!Bigarray.Array1.set}, but bounds checking is not always performed. + Use with caution and only when the program logic guarantees that + the access is within bounds. *) + +end + + +(** {1 Two-dimensional arrays} *) + +(** Two-dimensional arrays. The [Array2] structure provides operations + similar to those of {!Bigarray.Genarray}, but specialized to the + case of two-dimensional arrays. *) +module Array2 : + sig + type ('a, 'b, 'c) t + (** The type of two-dimensional big arrays whose elements have + OCaml type ['a], representation kind ['b], and memory layout ['c]. *) + + val create: ('a, 'b) kind -> 'c layout -> int -> int -> ('a, 'b, 'c) t + (** [Array2.create kind layout dim1 dim2] returns a new bigarray of + two dimension, whose size is [dim1] in the first dimension + and [dim2] in the second dimension. [kind] and [layout] + determine the array element kind and the array layout + as described for {!Bigarray.Genarray.create}. *) + + external dim1: ('a, 'b, 'c) t -> int = "caml_ba_dim_1" + (** Return the first dimension of the given two-dimensional big array. *) + + external dim2: ('a, 'b, 'c) t -> int = "caml_ba_dim_2" + (** Return the second dimension of the given two-dimensional big array. *) + + external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "caml_ba_kind" + (** Return the kind of the given big array. *) + + external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" + (** Return the layout of the given big array. *) + + val change_layout: ('a, 'b, 'c) t -> 'd layout -> ('a, 'b, 'd) t + (** [Array2.change_layout a layout] returns a bigarray with the + specified [layout], sharing the data with [a] (and hence having + the same dimensions as [a]). No copying of elements is involved: the + new array and the original array share the same storage space. + The dimensions are reversed, such that [get v [| a; b |]] in + C layout becomes [get v [| b+1; a+1 |]] in Fortran layout. + + @since 4.06.0 + *) + + + val size_in_bytes : ('a, 'b, 'c) t -> int + (** [size_in_bytes a] is the number of elements in [a] + multiplied by [a]'s {!kind_size_in_bytes}. + + @since 4.03.0 *) + + external get: ('a, 'b, 'c) t -> int -> int -> 'a = "caml_ba_get_2" + (** [Array2.get a x y], also written [a.{x,y}], + returns the element of [a] at coordinates ([x], [y]). + [x] and [y] must be within the bounds + of [a], as described for {!Bigarray.Genarray.get}; + otherwise, [Invalid_argument] is raised. *) + + external set: ('a, 'b, 'c) t -> int -> int -> 'a -> unit = "caml_ba_set_2" + (** [Array2.set a x y v], or alternatively [a.{x,y} <- v], + stores the value [v] at coordinates ([x], [y]) in [a]. + [x] and [y] must be within the bounds of [a], + as described for {!Bigarray.Genarray.set}; + otherwise, [Invalid_argument] is raised. *) + + external sub_left: ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) t + = "caml_ba_sub" + (** Extract a two-dimensional sub-array of the given two-dimensional + big array by restricting the first dimension. + See {!Bigarray.Genarray.sub_left} for more details. + [Array2.sub_left] applies only to arrays with C layout. *) + + external sub_right: + ('a, 'b, fortran_layout) t -> int -> int -> ('a, 'b, fortran_layout) t + = "caml_ba_sub" + (** Extract a two-dimensional sub-array of the given two-dimensional + big array by restricting the second dimension. + See {!Bigarray.Genarray.sub_right} for more details. + [Array2.sub_right] applies only to arrays with Fortran layout. *) + + val slice_left: ('a, 'b, c_layout) t -> int -> ('a, 'b, c_layout) Array1.t + (** Extract a row (one-dimensional slice) of the given two-dimensional + big array. The integer parameter is the index of the row to + extract. See {!Bigarray.Genarray.slice_left} for more details. + [Array2.slice_left] applies only to arrays with C layout. *) + + val slice_right: + ('a, 'b, fortran_layout) t -> int -> ('a, 'b, fortran_layout) Array1.t + (** Extract a column (one-dimensional slice) of the given + two-dimensional big array. The integer parameter is the + index of the column to extract. See {!Bigarray.Genarray.slice_right} + for more details. [Array2.slice_right] applies only to arrays + with Fortran layout. *) + + external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit + = "caml_ba_blit" + (** Copy the first big array to the second big array. + See {!Bigarray.Genarray.blit} for more details. *) + + external fill: ('a, 'b, 'c) t -> 'a -> unit = "caml_ba_fill" + (** Fill the given big array with the given value. + See {!Bigarray.Genarray.fill} for more details. *) + + val of_array: ('a, 'b) kind -> 'c layout -> 'a array array -> ('a, 'b, 'c) t + (** Build a two-dimensional big array initialized from the + given array of arrays. *) + + external unsafe_get: ('a, 'b, 'c) t -> int -> int -> 'a + = "caml_ba_unsafe_get_2" + (** Like {!Bigarray.Array2.get}, but bounds checking is not always + performed. *) + + external unsafe_set: ('a, 'b, 'c) t -> int -> int -> 'a -> unit + = "caml_ba_unsafe_set_2" + (** Like {!Bigarray.Array2.set}, but bounds checking is not always + performed. *) + +end + +(** {1 Three-dimensional arrays} *) + +(** Three-dimensional arrays. The [Array3] structure provides operations + similar to those of {!Bigarray.Genarray}, but specialized to the case + of three-dimensional arrays. *) +module Array3 : + sig + type ('a, 'b, 'c) t + (** The type of three-dimensional big arrays whose elements have + OCaml type ['a], representation kind ['b], and memory layout ['c]. *) + + val create: ('a, 'b) kind -> 'c layout -> int -> int -> int -> ('a, 'b, 'c) t + (** [Array3.create kind layout dim1 dim2 dim3] returns a new bigarray of + three dimension, whose size is [dim1] in the first dimension, + [dim2] in the second dimension, and [dim3] in the third. + [kind] and [layout] determine the array element kind and + the array layout as described for {!Bigarray.Genarray.create}. *) + + external dim1: ('a, 'b, 'c) t -> int = "caml_ba_dim_1" + (** Return the first dimension of the given three-dimensional big array. *) + + external dim2: ('a, 'b, 'c) t -> int = "caml_ba_dim_2" + (** Return the second dimension of the given three-dimensional big array. *) + + external dim3: ('a, 'b, 'c) t -> int = "caml_ba_dim_3" + (** Return the third dimension of the given three-dimensional big array. *) + + external kind: ('a, 'b, 'c) t -> ('a, 'b) kind = "caml_ba_kind" + (** Return the kind of the given big array. *) + + external layout: ('a, 'b, 'c) t -> 'c layout = "caml_ba_layout" + (** Return the layout of the given big array. *) + + + val change_layout: ('a, 'b, 'c) t -> 'd layout -> ('a, 'b, 'd) t + (** [Array3.change_layout a layout] returns a bigarray with the + specified [layout], sharing the data with [a] (and hence having + the same dimensions as [a]). No copying of elements is involved: the + new array and the original array share the same storage space. + The dimensions are reversed, such that [get v [| a; b; c |]] in + C layout becomes [get v [| c+1; b+1; a+1 |]] in Fortran layout. + + @since 4.06.0 + *) + + val size_in_bytes : ('a, 'b, 'c) t -> int + (** [size_in_bytes a] is the number of elements in [a] + multiplied by [a]'s {!kind_size_in_bytes}. + + @since 4.03.0 *) + + external get: ('a, 'b, 'c) t -> int -> int -> int -> 'a = "caml_ba_get_3" + (** [Array3.get a x y z], also written [a.{x,y,z}], + returns the element of [a] at coordinates ([x], [y], [z]). + [x], [y] and [z] must be within the bounds of [a], + as described for {!Bigarray.Genarray.get}; + otherwise, [Invalid_argument] is raised. *) + + external set: ('a, 'b, 'c) t -> int -> int -> int -> 'a -> unit + = "caml_ba_set_3" + (** [Array3.set a x y v], or alternatively [a.{x,y,z} <- v], + stores the value [v] at coordinates ([x], [y], [z]) in [a]. + [x], [y] and [z] must be within the bounds of [a], + as described for {!Bigarray.Genarray.set}; + otherwise, [Invalid_argument] is raised. *) + + external sub_left: ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) t + = "caml_ba_sub" + (** Extract a three-dimensional sub-array of the given + three-dimensional big array by restricting the first dimension. + See {!Bigarray.Genarray.sub_left} for more details. [Array3.sub_left] + applies only to arrays with C layout. *) + + external sub_right: + ('a, 'b, fortran_layout) t -> int -> int -> ('a, 'b, fortran_layout) t + = "caml_ba_sub" + (** Extract a three-dimensional sub-array of the given + three-dimensional big array by restricting the second dimension. + See {!Bigarray.Genarray.sub_right} for more details. [Array3.sub_right] + applies only to arrays with Fortran layout. *) + + val slice_left_1: + ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) Array1.t + (** Extract a one-dimensional slice of the given three-dimensional + big array by fixing the first two coordinates. + The integer parameters are the coordinates of the slice to + extract. See {!Bigarray.Genarray.slice_left} for more details. + [Array3.slice_left_1] applies only to arrays with C layout. *) + + val slice_right_1: + ('a, 'b, fortran_layout) t -> + int -> int -> ('a, 'b, fortran_layout) Array1.t + (** Extract a one-dimensional slice of the given three-dimensional + big array by fixing the last two coordinates. + The integer parameters are the coordinates of the slice to + extract. See {!Bigarray.Genarray.slice_right} for more details. + [Array3.slice_right_1] applies only to arrays with Fortran + layout. *) + + val slice_left_2: ('a, 'b, c_layout) t -> int -> ('a, 'b, c_layout) Array2.t + (** Extract a two-dimensional slice of the given three-dimensional + big array by fixing the first coordinate. + The integer parameter is the first coordinate of the slice to + extract. See {!Bigarray.Genarray.slice_left} for more details. + [Array3.slice_left_2] applies only to arrays with C layout. *) + + val slice_right_2: + ('a, 'b, fortran_layout) t -> int -> ('a, 'b, fortran_layout) Array2.t + (** Extract a two-dimensional slice of the given + three-dimensional big array by fixing the last coordinate. + The integer parameter is the coordinate of the slice + to extract. See {!Bigarray.Genarray.slice_right} for more details. + [Array3.slice_right_2] applies only to arrays with Fortran + layout. *) + + external blit: ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit + = "caml_ba_blit" + (** Copy the first big array to the second big array. + See {!Bigarray.Genarray.blit} for more details. *) + + external fill: ('a, 'b, 'c) t -> 'a -> unit = "caml_ba_fill" + (** Fill the given big array with the given value. + See {!Bigarray.Genarray.fill} for more details. *) + + val of_array: + ('a, 'b) kind -> 'c layout -> 'a array array array -> ('a, 'b, 'c) t + (** Build a three-dimensional big array initialized from the + given array of arrays of arrays. *) + + + external unsafe_get: ('a, 'b, 'c) t -> int -> int -> int -> 'a + = "caml_ba_unsafe_get_3" + (** Like {!Bigarray.Array3.get}, but bounds checking is not always + performed. *) + + external unsafe_set: ('a, 'b, 'c) t -> int -> int -> int -> 'a -> unit + = "caml_ba_unsafe_set_3" + (** Like {!Bigarray.Array3.set}, but bounds checking is not always + performed. *) + +end + +(** {1 Coercions between generic big arrays and fixed-dimension big arrays} *) + +external genarray_of_array0 : + ('a, 'b, 'c) Array0.t -> ('a, 'b, 'c) Genarray.t = "%identity" +(** Return the generic big array corresponding to the given zero-dimensional + big array. @since 4.05.0 *) + +external genarray_of_array1 : + ('a, 'b, 'c) Array1.t -> ('a, 'b, 'c) Genarray.t = "%identity" +(** Return the generic big array corresponding to the given one-dimensional + big array. *) + +external genarray_of_array2 : + ('a, 'b, 'c) Array2.t -> ('a, 'b, 'c) Genarray.t = "%identity" +(** Return the generic big array corresponding to the given two-dimensional + big array. *) + +external genarray_of_array3 : + ('a, 'b, 'c) Array3.t -> ('a, 'b, 'c) Genarray.t = "%identity" +(** Return the generic big array corresponding to the given three-dimensional + big array. *) + +val array0_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array0.t +(** Return the zero-dimensional big array corresponding to the given + generic big array. Raise [Invalid_argument] if the generic big array + does not have exactly zero dimension. + @since 4.05.0 *) + +val array1_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array1.t +(** Return the one-dimensional big array corresponding to the given + generic big array. Raise [Invalid_argument] if the generic big array + does not have exactly one dimension. *) + +val array2_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array2.t +(** Return the two-dimensional big array corresponding to the given + generic big array. Raise [Invalid_argument] if the generic big array + does not have exactly two dimensions. *) + +val array3_of_genarray : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array3.t +(** Return the three-dimensional big array corresponding to the given + generic big array. Raise [Invalid_argument] if the generic big array + does not have exactly three dimensions. *) + + +(** {1 Re-shaping big arrays} *) + +val reshape : ('a, 'b, 'c) Genarray.t -> int array -> ('a, 'b, 'c) Genarray.t +(** [reshape b [|d1;...;dN|]] converts the big array [b] to a + [N]-dimensional array of dimensions [d1]...[dN]. The returned + array and the original array [b] share their data + and have the same layout. For instance, assuming that [b] + is a one-dimensional array of dimension 12, [reshape b [|3;4|]] + returns a two-dimensional array [b'] of dimensions 3 and 4. + If [b] has C layout, the element [(x,y)] of [b'] corresponds + to the element [x * 3 + y] of [b]. If [b] has Fortran layout, + the element [(x,y)] of [b'] corresponds to the element + [x + (y - 1) * 4] of [b]. + The returned big array must have exactly the same number of + elements as the original big array [b]. That is, the product + of the dimensions of [b] must be equal to [i1 * ... * iN]. + Otherwise, [Invalid_argument] is raised. *) + +val reshape_0 : ('a, 'b, 'c) Genarray.t -> ('a, 'b, 'c) Array0.t +(** Specialized version of {!Bigarray.reshape} for reshaping to + zero-dimensional arrays. + @since 4.05.0 *) + +val reshape_1 : ('a, 'b, 'c) Genarray.t -> int -> ('a, 'b, 'c) Array1.t +(** Specialized version of {!Bigarray.reshape} for reshaping to + one-dimensional arrays. *) + +val reshape_2 : ('a, 'b, 'c) Genarray.t -> int -> int -> ('a, 'b, 'c) Array2.t +(** Specialized version of {!Bigarray.reshape} for reshaping to + two-dimensional arrays. *) + +val reshape_3 : + ('a, 'b, 'c) Genarray.t -> int -> int -> int -> ('a, 'b, 'c) Array3.t +(** Specialized version of {!Bigarray.reshape} for reshaping to + three-dimensional arrays. *) \ No newline at end of file diff --git a/jscomp/stdlib-412/stdlib_modules/camlinternalBigarray.ml b/jscomp/stdlib-412/stdlib_modules/camlinternalBigarray.ml new file mode 100644 index 0000000000..f8713080d7 --- /dev/null +++ b/jscomp/stdlib-412/stdlib_modules/camlinternalBigarray.ml @@ -0,0 +1,36 @@ +type float32_elt = Float32_elt +type float64_elt = Float64_elt +type int8_signed_elt = Int8_signed_elt +type int8_unsigned_elt = Int8_unsigned_elt +type int16_signed_elt = Int16_signed_elt +type int16_unsigned_elt = Int16_unsigned_elt +type int32_elt = Int32_elt +type int64_elt = Int64_elt +type int_elt = Int_elt +type nativeint_elt = Nativeint_elt +type complex32_elt = Complex32_elt +type complex64_elt = Complex64_elt + +type ('a, 'b) kind = + Float32 : (float, float32_elt) kind + | Float64 : (float, float64_elt) kind + | Int8_signed : (int, int8_signed_elt) kind + | Int8_unsigned : (int, int8_unsigned_elt) kind + | Int16_signed : (int, int16_signed_elt) kind + | Int16_unsigned : (int, int16_unsigned_elt) kind + | Int32 : (int32, int32_elt) kind + | Int64 : (int64, int64_elt) kind + | Int : (int, int_elt) kind + | Nativeint : (nativeint, nativeint_elt) kind + | Complex32 : (Complex.t, complex32_elt) kind + | Complex64 : (Complex.t, complex64_elt) kind + | Char : (char, int8_unsigned_elt) kind + +type c_layout = C_layout_typ +type fortran_layout = Fortran_layout_typ + +type 'a layout = + C_layout: c_layout layout + | Fortran_layout: fortran_layout layout + +type ('a, 'b, 'c) genarray \ No newline at end of file diff --git a/jscomp/stdlib-412/stdlib_modules/camlinternalBigarray.mli b/jscomp/stdlib-412/stdlib_modules/camlinternalBigarray.mli new file mode 100644 index 0000000000..f8713080d7 --- /dev/null +++ b/jscomp/stdlib-412/stdlib_modules/camlinternalBigarray.mli @@ -0,0 +1,36 @@ +type float32_elt = Float32_elt +type float64_elt = Float64_elt +type int8_signed_elt = Int8_signed_elt +type int8_unsigned_elt = Int8_unsigned_elt +type int16_signed_elt = Int16_signed_elt +type int16_unsigned_elt = Int16_unsigned_elt +type int32_elt = Int32_elt +type int64_elt = Int64_elt +type int_elt = Int_elt +type nativeint_elt = Nativeint_elt +type complex32_elt = Complex32_elt +type complex64_elt = Complex64_elt + +type ('a, 'b) kind = + Float32 : (float, float32_elt) kind + | Float64 : (float, float64_elt) kind + | Int8_signed : (int, int8_signed_elt) kind + | Int8_unsigned : (int, int8_unsigned_elt) kind + | Int16_signed : (int, int16_signed_elt) kind + | Int16_unsigned : (int, int16_unsigned_elt) kind + | Int32 : (int32, int32_elt) kind + | Int64 : (int64, int64_elt) kind + | Int : (int, int_elt) kind + | Nativeint : (nativeint, nativeint_elt) kind + | Complex32 : (Complex.t, complex32_elt) kind + | Complex64 : (Complex.t, complex64_elt) kind + | Char : (char, int8_unsigned_elt) kind + +type c_layout = C_layout_typ +type fortran_layout = Fortran_layout_typ + +type 'a layout = + C_layout: c_layout layout + | Fortran_layout: fortran_layout layout + +type ('a, 'b, 'c) genarray \ No newline at end of file diff --git a/jscomp/stdlib-412/stdlib_modules/dune.gen b/jscomp/stdlib-412/stdlib_modules/dune.gen index 6d9e7bddb1..eb83329479 100644 --- a/jscomp/stdlib-412/stdlib_modules/dune.gen +++ b/jscomp/stdlib-412/stdlib_modules/dune.gen @@ -104,6 +104,22 @@ (run %{workspace_root}/jscomp/main/js_main.exe -bs-cmi -bs-cmj -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -make-runtime -w -106 -warn-error A -I ../../runtime -I ../../others -nopervasives -open Stdlib__no_aliases -I . %{inputs}))) + (rule + (targets bigarray.cmj ) + (deps (:inputs bigarray.ml) (alias ../../others/others) array.cmj bigarray.cmi camlinternalBigarray.cmj sys.cmj) + + (action + (run %{workspace_root}/jscomp/main/js_main.exe -bs-read-cmi -bs-cmi -bs-cmj -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -make-runtime -w -106 -warn-error A -I ../../runtime -I ../../others -nopervasives -open Stdlib__no_aliases -I . %{inputs}))) + + + (rule + (targets bigarray.cmi ) + (deps (:inputs bigarray.mli) (alias ../../others/others) camlinternalBigarray.cmi complex.cmi stdlib__no_aliases.cmj) + + (action + (run %{workspace_root}/jscomp/main/js_main.exe -bs-cmi -bs-cmj -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -make-runtime -w -106 -warn-error A -I ../../runtime -I ../../others -nopervasives -open Stdlib__no_aliases -I . %{inputs}))) + + (rule (targets bool.cmj ) (deps (:inputs bool.ml) (alias ../../others/others) bool.cmi) @@ -184,6 +200,22 @@ (run %{workspace_root}/jscomp/main/js_main.exe -bs-cmi -bs-cmj -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -make-runtime -w -106 -warn-error A -I ../../runtime -I ../../others -nopervasives -open Stdlib__no_aliases -I . %{inputs}))) + (rule + (targets camlinternalBigarray.cmj ) + (deps (:inputs camlinternalBigarray.ml) (alias ../../others/others) camlinternalBigarray.cmi complex.cmj) + + (action + (run %{workspace_root}/jscomp/main/js_main.exe -bs-read-cmi -bs-cmi -bs-cmj -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -make-runtime -w -106 -warn-error A -I ../../runtime -I ../../others -nopervasives -open Stdlib__no_aliases -I . %{inputs}))) + + + (rule + (targets camlinternalBigarray.cmi ) + (deps (:inputs camlinternalBigarray.mli) (alias ../../others/others) complex.cmi stdlib__no_aliases.cmj) + + (action + (run %{workspace_root}/jscomp/main/js_main.exe -bs-cmi -bs-cmj -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -make-runtime -w -106 -warn-error A -I ../../runtime -I ../../others -nopervasives -open Stdlib__no_aliases -I . %{inputs}))) + + (rule (targets camlinternalFormat.cmj ) (deps (:inputs camlinternalFormat.ml) (alias ../../others/others) bool.cmj buffer.cmj bytes.cmj camlinternalFormat.cmi camlinternalFormatBasics.cmj char.cmj float.cmj int.cmj int32.cmj int64.cmj string.cmj sys.cmj) @@ -954,5 +986,5 @@ (alias (name stdlib) - (deps camlinternalFormatBasics.cmi camlinternalFormatBasics.cmj stdlib__no_aliases.cmi arg.cmi arg.cmj array.cmi array.cmj arrayLabels.cmi arrayLabels.cmj atomic.cmi atomic.cmj bool.cmi bool.cmj buffer.cmi buffer.cmj bytes.cmi bytes.cmj bytesLabels.cmi bytesLabels.cmj callback.cmi callback.cmj camlinternalFormat.cmi camlinternalFormat.cmj camlinternalLazy.cmi camlinternalLazy.cmj camlinternalMod.cmi camlinternalMod.cmj camlinternalOO.cmi camlinternalOO.cmj char.cmi char.cmj complex.cmi complex.cmj digest.cmi digest.cmj either.cmi either.cmj ephemeron.cmi ephemeron.cmj filename.cmi filename.cmj float.cmi float.cmj format.cmi format.cmj fun.cmi fun.cmj gc.cmi gc.cmj genlex.cmi genlex.cmj hashtbl.cmi hashtbl.cmj int.cmi int.cmj int32.cmi int32.cmj int64.cmi int64.cmj lazy.cmi lazy.cmj lexing.cmi lexing.cmj list.cmi list.cmj listLabels.cmi listLabels.cmj map.cmi map.cmj marshal.cmi marshal.cmj moreLabels.cmi moreLabels.cmj obj.cmi obj.cmj oo.cmi oo.cmj option.cmi option.cmj parsing.cmi parsing.cmj pervasives.cmi pervasives.cmj printexc.cmi printexc.cmj printf.cmi printf.cmj queue.cmi queue.cmj random.cmi random.cmj result.cmi result.cmj scanf.cmi scanf.cmj seq.cmi seq.cmj set.cmi set.cmj stack.cmi stack.cmj stdLabels.cmi stdLabels.cmj std_exit.cmi std_exit.cmj stream.cmi stream.cmj string.cmi string.cmj stringLabels.cmi stringLabels.cmj sys.cmi sys.cmj uchar.cmi uchar.cmj unit.cmi unit.cmj weak.cmi weak.cmj)) + (deps camlinternalFormatBasics.cmi camlinternalFormatBasics.cmj stdlib__no_aliases.cmi arg.cmi arg.cmj array.cmi array.cmj arrayLabels.cmi arrayLabels.cmj atomic.cmi atomic.cmj bigarray.cmi bigarray.cmj bool.cmi bool.cmj buffer.cmi buffer.cmj bytes.cmi bytes.cmj bytesLabels.cmi bytesLabels.cmj callback.cmi callback.cmj camlinternalBigarray.cmi camlinternalBigarray.cmj camlinternalFormat.cmi camlinternalFormat.cmj camlinternalLazy.cmi camlinternalLazy.cmj camlinternalMod.cmi camlinternalMod.cmj camlinternalOO.cmi camlinternalOO.cmj char.cmi char.cmj complex.cmi complex.cmj digest.cmi digest.cmj either.cmi either.cmj ephemeron.cmi ephemeron.cmj filename.cmi filename.cmj float.cmi float.cmj format.cmi format.cmj fun.cmi fun.cmj gc.cmi gc.cmj genlex.cmi genlex.cmj hashtbl.cmi hashtbl.cmj int.cmi int.cmj int32.cmi int32.cmj int64.cmi int64.cmj lazy.cmi lazy.cmj lexing.cmi lexing.cmj list.cmi list.cmj listLabels.cmi listLabels.cmj map.cmi map.cmj marshal.cmi marshal.cmj moreLabels.cmi moreLabels.cmj obj.cmi obj.cmj oo.cmi oo.cmj option.cmi option.cmj parsing.cmi parsing.cmj pervasives.cmi pervasives.cmj printexc.cmi printexc.cmj printf.cmi printf.cmj queue.cmi queue.cmj random.cmi random.cmj result.cmi result.cmj scanf.cmi scanf.cmj seq.cmi seq.cmj set.cmi set.cmj stack.cmi stack.cmj stdLabels.cmi stdLabels.cmj std_exit.cmi std_exit.cmj stream.cmi stream.cmj string.cmi string.cmj stringLabels.cmi stringLabels.cmj sys.cmi sys.cmj uchar.cmi uchar.cmj unit.cmi unit.cmj weak.cmi weak.cmj)) diff --git a/lib/js/dune b/lib/js/dune deleted file mode 100644 index e69de29bb2..0000000000