diff --git a/Makefile b/Makefile index 8bb9fd0741..8fe4aa627d 100644 --- a/Makefile +++ b/Makefile @@ -82,16 +82,18 @@ checkformat: clean-gentype: make -C jscomp/gentype_tests/typescript-react-example clean +clean-rewatch: + cargo clean --manifest-path rewatch/Cargo.toml && rm -f rewatch/rewatch + clean: dune clean - cargo clean --manifest-path rewatch/Cargo.toml && rm -f rewatch/rewatch ./scripts/ninja.js clean && rm -f ninja/ninja -clean-all: clean clean-gentype +clean-all: clean clean-gentype clean-rewatch dev-container: docker build -t rescript-dev-container docker .DEFAULT_GOAL := build -.PHONY: build watch rewatch ninja bench dce test test-syntax test-syntax-roundtrip test-gentype test-all lib playground playground-cmijs playground-release artifacts format checkformat clean-gentype clean clean-all dev-container +.PHONY: build watch rewatch ninja bench dce test test-syntax test-syntax-roundtrip test-gentype test-all lib playground playground-cmijs playground-release artifacts format checkformat clean-gentype clean-rewatch clean clean-all dev-container diff --git a/jscomp/build_tests/super_errors/expected/modules2.res.expected b/jscomp/build_tests/super_errors/expected/modules2.res.expected index b1b5ad1b34..633a4a99cd 100644 --- a/jscomp/build_tests/super_errors/expected/modules2.res.expected +++ b/jscomp/build_tests/super_errors/expected/modules2.res.expected @@ -1,8 +1,8 @@ We've found a bug for you! - /.../fixtures/modules2.res:1:9-14 + /.../fixtures/modules2.res:1:9-19 - 1 │ let b = List.b + 1 │ let b = Belt.List.b 2 │ - The value b can't be found in List \ No newline at end of file + The value b can't be found in Belt.List \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/expected/primitives7.res.expected b/jscomp/build_tests/super_errors/expected/primitives7.res.expected index 0f7375f708..95aa2472c5 100644 --- a/jscomp/build_tests/super_errors/expected/primitives7.res.expected +++ b/jscomp/build_tests/super_errors/expected/primitives7.res.expected @@ -1,17 +1,20 @@ We've found a bug for you! - /.../fixtures/primitives7.res:3:24 + /.../fixtures/primitives7.res:3:23 1 │ /* Wanted list(float), found list(int) */ 2 │ let a = list{1, 2, 3} - 3 │ List.map(n => n +. 2., a) + 3 │ a->Belt.List.map(n => n +. 2.) 4 │ - This has type: list - But this function argument is expecting: list - - The incompatible parts: - int vs float + This has type: int + But it's being used with the +. operator, which works on: float + + Floats and ints have their own mathematical operators. This means you cannot add a float and an int without converting between the two. + + Possible solutions: + - Ensure all values in this calculation has the type float. You can convert between floats and ints via Belt.Float.toInt and Belt.Int.fromFloat. + - Change the operator to +, which works on int You can convert int to float with Belt.Int.toFloat. If this is a literal, try a number with a trailing dot (e.g. 20.). \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/expected/warnings3.res.expected b/jscomp/build_tests/super_errors/expected/warnings3.res.expected deleted file mode 100644 index 11f5a87056..0000000000 --- a/jscomp/build_tests/super_errors/expected/warnings3.res.expected +++ /dev/null @@ -1,34 +0,0 @@ - - Warning number 3 - /.../fixtures/warnings3.res:1:9-23 - - 1 │ let _ = string_of_float(34.) - 2 │ let _ = string_of_float(34.) - 3 │ let _ = string_of_float(34.) - - deprecated: Pervasives.string_of_float - Please use Js.Float.toString instead, string_of_float generates unparseable floats - - - Warning number 3 - /.../fixtures/warnings3.res:2:9-23 - - 1 │ let _ = string_of_float(34.) - 2 │ let _ = string_of_float(34.) - 3 │ let _ = string_of_float(34.) - 4 │ - - deprecated: Pervasives.string_of_float - Please use Js.Float.toString instead, string_of_float generates unparseable floats - - - Warning number 3 - /.../fixtures/warnings3.res:3:9-23 - - 1 │ let _ = string_of_float(34.) - 2 │ let _ = string_of_float(34.) - 3 │ let _ = string_of_float(34.) - 4 │ - - deprecated: Pervasives.string_of_float - Please use Js.Float.toString instead, string_of_float generates unparseable floats \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/fixtures/modules2.res b/jscomp/build_tests/super_errors/fixtures/modules2.res index 9f17e8b2b9..336b4a1f1a 100644 --- a/jscomp/build_tests/super_errors/fixtures/modules2.res +++ b/jscomp/build_tests/super_errors/fixtures/modules2.res @@ -1 +1 @@ -let b = List.b +let b = Belt.List.b diff --git a/jscomp/build_tests/super_errors/fixtures/primitives7.res b/jscomp/build_tests/super_errors/fixtures/primitives7.res index d456521d78..1df613d45f 100644 --- a/jscomp/build_tests/super_errors/fixtures/primitives7.res +++ b/jscomp/build_tests/super_errors/fixtures/primitives7.res @@ -1,3 +1,3 @@ /* Wanted list(float), found list(int) */ let a = list{1, 2, 3} -List.map(n => n +. 2., a) +a->Belt.List.map(n => n +. 2.) diff --git a/jscomp/build_tests/super_errors/fixtures/warnings3.res b/jscomp/build_tests/super_errors/fixtures/warnings3.res deleted file mode 100644 index 92498ef2ad..0000000000 --- a/jscomp/build_tests/super_errors/fixtures/warnings3.res +++ /dev/null @@ -1,3 +0,0 @@ -let _ = string_of_float(34.) -let _ = string_of_float(34.) -let _ = string_of_float(34.) diff --git a/jscomp/core/j.ml b/jscomp/core/j.ml index d89e5a9637..c9b4961c37 100644 --- a/jscomp/core/j.ml +++ b/jscomp/core/j.ml @@ -66,7 +66,7 @@ and vident = Id of ident | Qualified of module_id * string option pattern match we can ignore the first one for simplicity for example {[ - Qualified (_, Runtime, Some "caml_int_compare") + Qualified (_, Runtime, Some "compare") ]} *) diff --git a/jscomp/core/js_analyzer.ml b/jscomp/core/js_analyzer.ml index 7a4f0d1954..b88c77e6ca 100644 --- a/jscomp/core/js_analyzer.ml +++ b/jscomp/core/js_analyzer.ml @@ -210,8 +210,6 @@ let rec eq_expression ({ expression_desc = x0 } : J.expression) | Length _ | Is_null_or_undefined _ | String_append _ | Typeof _ | Js_not _ | Cond _ | FlatCall _ | New _ | Fun _ | Raw_js_code _ | Array _ | Caml_block_tag _ | Object _ | Tagged_template _ - | Number (Uint _) -> - false | Await _ -> false | Spread _ -> false diff --git a/jscomp/core/js_block_runtime.ml b/jscomp/core/js_block_runtime.ml index 8d80405ccd..3f529b5476 100644 --- a/jscomp/core/js_block_runtime.ml +++ b/jscomp/core/js_block_runtime.ml @@ -22,9 +22,9 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -let option_id = Ident.create_persistent Js_runtime_modules.option +let option_id = Ident.create_persistent Primitive_modules.option -let curry_id = Ident.create_persistent Js_runtime_modules.curry +let curry_id = Ident.create_persistent Primitive_modules.curry let check_additional_id (x : J.expression) : Ident.t option = match x.expression_desc with diff --git a/jscomp/core/js_dump.ml b/jscomp/core/js_dump.ml index 8ace87383c..6d83b5243a 100644 --- a/jscomp/core/js_dump.ml +++ b/jscomp/core/js_dump.ml @@ -74,7 +74,7 @@ module L = Js_dump_lit module Curry_gen = struct let pp_curry_dot f = - P.string f Js_runtime_modules.curry; + P.string f Primitive_modules.curry; P.string f L.dot let pp_optimize_curry (f : P.t) (len : int) = @@ -642,7 +642,6 @@ and expression_desc cxt ~(level : int) f x : cxt = | Int { i; c = None } -> Int32.to_string i (* check , js convention with ocaml lexical convention *) - | Uint i -> Format.asprintf "%lu" i | BigInt {positive; value} -> Format.asprintf "%sn" (Bigint_utils.to_string positive value) in let need_paren = @@ -651,8 +650,7 @@ and expression_desc cxt ~(level : int) f x : cxt = else level = 15 (* Parenthesize as well when followed by a dot. *) && s.[0] <> 'I' (* Infinity *) - && s.[0] <> 'N' - (* NaN *) + && s.[0] <> 'N' (* NaN *) in let action _ = P.string f s in if need_paren then P.paren f action else action (); @@ -722,7 +720,7 @@ and expression_desc cxt ~(level : int) f x : cxt = | Optional_block (e, identity) -> expression ~level cxt f (if identity then e - else E.runtime_call Js_runtime_modules.option "some" [ e ]) + else E.runtime_call Primitive_modules.option "some" [ e ]) | Caml_block (el, _, _, Blk_module fields) -> expression_desc cxt ~level f (Object (None, diff --git a/jscomp/core/js_exp_make.ml b/jscomp/core/js_exp_make.ml index 9432676b48..fd37ab75dc 100644 --- a/jscomp/core/js_exp_make.ml +++ b/jscomp/core/js_exp_make.ml @@ -793,18 +793,6 @@ let rec float_equal ?comment (e0 : t) (e1 : t) : t = let int_equal = float_equal -let string_equal ?comment (e0 : t) (e1 : t) : t = - let default () : t = { expression_desc = Bin (EqEqEq, e0, e1); comment } in - match (e0.expression_desc, e1.expression_desc) with - | Str { txt = a0; delim = d0 }, Str { txt = a1; delim = d1 } when d0 = d1 -> - (match str_equal a0 d0 a1 d1 with - | Some b -> bool b - | None -> default ()) - | _, _ -> default () - -let is_type_number ?comment (e : t) : t = - string_equal ?comment (typeof e) (str "number") - let tag_type = function | Ast_untagged_variants.String s -> str s ~delim:DStarJ | Int i -> small_int i @@ -853,11 +841,6 @@ let is_int_tag ?has_null_undefined_other e = let check = Ast_untagged_variants.DynamicChecks.is_int_tag ?has_null_undefined_other (Expr e) in emit_check check -let is_type_string ?comment (e : t) : t = - string_equal ?comment (typeof e) (str "string") - -let is_type_object (e : t) : t = string_equal (typeof e) (str "object") - (* we are calling [Caml_primitive.primitive_name], since it's under our control, we should make it follow the javascript name convention, and call plain [dot] @@ -882,56 +865,48 @@ let tag ?comment ?(name=Js_dump_lit.tag) e : t = let rec int32_bor ?comment (e1 : J.expression) (e2 : J.expression) : J.expression = match (e1.expression_desc, e2.expression_desc) with - | Number (Int { i = i1 } | Uint i1), Number (Int { i = i2 }) -> + | Number (Int { i = i1 }), Number (Int { i = i2 }) -> int ?comment (Int32.logor i1 i2) - | _, Bin (Lsr, e2, { expression_desc = Number (Int { i = 0l } | Uint 0l); _ }) + | _, Bin (Lsr, e2, { expression_desc = Number (Int { i = 0l }); _ }) -> int32_bor e1 e2 - | Bin (Lsr, e1, { expression_desc = Number (Int { i = 0l } | Uint 0l); _ }), _ + | Bin (Lsr, e1, { expression_desc = Number (Int { i = 0l }); _ }), _ -> int32_bor e1 e2 - | ( Bin (Lsr, _, { expression_desc = Number (Int { i } | Uint i); _ }), - Number (Int { i = 0l } | Uint 0l) ) + | ( Bin (Lsr, _, { expression_desc = Number (Int { i }); _ }), + Number (Int { i = 0l }) ) when i > 0l -> (* a >>> 3 | 0 -> a >>> 3 *) e1 - | ( Bin (Bor, e1, { expression_desc = Number (Int { i = 0l } | Uint 0l); _ }), - Number (Int { i = 0l } | Uint 0l) ) -> + | ( Bin (Bor, e1, { expression_desc = Number (Int { i = 0l }); _ }), + Number (Int { i = 0l }) ) -> int32_bor e1 e2 | _ -> { comment; expression_desc = Bin (Bor, e1, e2) } -(* Arithmatic operations - TODO: distinguish between int and float - TODO: Note that we have to use Int64 to avoid integer overflow, this is fine - since Js only have . - - like code below - {[ - MAX_INT_VALUE - (MAX_INT_VALUE - 100) + 20 - ]} - - {[ - MAX_INT_VALUE - x + 30 - ]} - - check: Re-association: avoid integer overflow -*) let to_int32 ?comment (e : J.expression) : J.expression = int32_bor ?comment e zero_int_literal (* TODO: if we already know the input is int32, [x|0] can be reduced into [x] *) -let uint32 ?comment n : J.expression = - { expression_desc = Number (Uint n); comment } - -let string_comp (cmp : J.binop) ?comment (e0 : t) (e1 : t) = +let string_comp (cmp : Lam_compat.comparison) ?comment (e0 : t) (e1 : t) = match (e0.expression_desc, e1.expression_desc) with | Str { txt = a0; delim = d0 }, Str { txt = a1; delim = d1 } -> ( match cmp, str_equal a0 d0 a1 d1 with - | EqEqEq, Some b -> bool b - | NotEqEq, Some b -> bool (b = false) + | Ceq, Some b -> bool b + | Cneq, Some b -> bool (b = false) | _ -> - bin ?comment cmp e0 e1) - | _ -> bin ?comment cmp e0 e1 + bin ?comment (Lam_compile_util.jsop_of_comp cmp) e0 e1) + | _ -> bin ?comment (Lam_compile_util.jsop_of_comp cmp) e0 e1 + +let string_equal ?comment (e0 : t) (e1 : t) : t = + string_comp Ceq ?comment e0 e1 + +let is_type_number ?comment (e : t) : t = + string_equal ?comment (typeof e) (str "number") + +let is_type_string ?comment (e : t) : t = + string_equal ?comment (typeof e) (str "string") + +let is_type_object (e : t) : t = string_equal (typeof e) (str "object") let obj_length ?comment e : t = to_int32 { expression_desc = Length (e, Caml_block); comment } @@ -947,55 +922,21 @@ let compare_int_aux (cmp : Lam_compat.comparison) (l : int) r = let rec int_comp (cmp : Lam_compat.comparison) ?comment (e0 : t) (e1 : t) = match (cmp, e0.expression_desc, e1.expression_desc) with - | _, Number ((Int _ | Uint _) as l), Number ((Int _ | Uint _) as r) -> - let l = - match l with - | Uint l -> Ext_int.int32_unsigned_to_int l - | Int { i = l } -> Int32.to_int l - | _ -> assert false - in - let r = - match r with - | Uint l -> Ext_int.int32_unsigned_to_int l - | Int { i = l } -> Int32.to_int l - | _ -> assert false - in + | _, Number ((Int { i = l })), Number ((Int { i = r })) -> + let l = Ext_int.int32_unsigned_to_int l in + let r = Int32.to_int r in bool (compare_int_aux cmp l r) | ( _, Call ( { expression_desc = - Var (Qualified ({ kind = Runtime }, Some "int_compare")); + Var (Qualified ({ kind = Runtime }, Some "compare")); _; }, [ l; r ], _ ), Number (Int { i = 0l }) ) -> int_comp cmp l r (* = 0 > 0 < 0 *) - | ( Ceq, - Call - ( ({ - expression_desc = - Var - (Qualified - (({ id = _; kind = Runtime } as iid), Some "compare")); - _; - } as fn), - ([ _; _ ] as args), - call_info ), - Number (Int { i = 0l }) ) -> - (* This is now generalized for runtime modules - `RuntimeModule.compare x y = 0 ` --> - `RuntimeModule.equal x y` - *) - { - e0 with - expression_desc = - Call - ( { fn with expression_desc = Var (Qualified (iid, Some "equal")) }, - args, - call_info ); - } | Ceq, Optional_block _, Undefined _ | Ceq, Undefined _, Optional_block _ -> false_ | Ceq, _, _ -> int_equal e0 e1 @@ -1041,20 +982,17 @@ let js_comp cmp ?comment e0 e1 = let rec int32_lsr ?comment (e1 : J.expression) (e2 : J.expression) : J.expression = - let aux i1 i = uint32 (Int32.shift_right_logical i1 i) in + let aux i1 i = int (Int32.shift_right_logical i1 i) in match (e1.expression_desc, e2.expression_desc) with - | Number (Int { i = i1 } | Uint i1), Number (Int { i = i2 } | Uint i2) -> + | Number (Int { i = i1 }), Number (Int { i = i2 }) -> aux i1 (Int32.to_int i2) - | Bin (Lsr, _, _), Number (Int { i = 0l } | Uint 0l) -> + | Bin (Lsr, _, _), Number (Int { i = 0l }) -> e1 (* TODO: more opportunities here *) | ( Bin - (Bor, e1, { expression_desc = Number (Int { i = 0l; _ } | Uint 0l); _ }), - Number (Int { i = 0l } | Uint 0l) ) -> + (Bor, e1, { expression_desc = Number (Int { i = 0l; _ }); _ }), + Number (Int { i = 0l }) ) -> int32_lsr ?comment e1 e2 - | _, _ -> { comment; expression_desc = Bin (Lsr, e1, e2) (* uint32 *) } - -let to_uint32 ?comment (e : J.expression) : J.expression = - int32_lsr ?comment e zero_int_literal + | _, _ -> { comment; expression_desc = Bin (Lsr, e1, e2) } (* TODO: we can apply a more general optimization here, @@ -1110,10 +1048,11 @@ let rec is_out ?comment (e : t) (range : t) : t = { expression_desc = Var _; _ }, { expression_desc = Number (Int { i = _; _ }) } ) ); } as e), - { expression_desc = Number (Int { i = 0l } | Uint 0l); _ } ) ) -> + { expression_desc = Number (Int { i = 0l }); _ } ) ) -> (* TODO: check correctness *) is_out ?comment e range - | _, _ -> int_comp ?comment Cgt (to_uint32 e) range + | _, _ -> + int_comp ?comment Cgt e range let rec float_add ?comment (e1 : t) (e2 : t) = match (e1.expression_desc, e2.expression_desc) with @@ -1174,13 +1113,13 @@ let int32_asr ?comment e1 e2 : J.expression = (** Division by zero is undefined behavior*) let int32_div ~checked ?comment (e1 : t) (e2 : t) : t = match (e1.expression_desc, e2.expression_desc) with - | Length _, Number (Int { i = 2l } | Uint 2l) -> int32_asr e1 one_int_literal + | Length _, Number (Int { i = 2l }) -> int32_asr e1 one_int_literal | e1_desc, Number (Int { i = i1 }) when i1 <> 0l -> ( match e1_desc with | Number (Int { i = i0 }) -> int (Int32.div i0 i1) | _ -> to_int32 (float_div ?comment e1 e2)) | _, _ -> - if checked then runtime_call Js_runtime_modules.int32 "div" [ e1; e2 ] + if checked then runtime_call Primitive_modules.int "div" [ e1; e2 ] else to_int32 (float_div ?comment e1 e2) let int32_mod ~checked ?comment e1 (e2 : t) : J.expression = @@ -1188,15 +1127,15 @@ let int32_mod ~checked ?comment e1 (e2 : t) : J.expression = | Number (Int { i }) when i <> 0l -> { comment; expression_desc = Bin (Mod, e1, e2) } | _ -> - if checked then runtime_call Js_runtime_modules.int32 "mod_" [ e1; e2 ] + if checked then runtime_call Primitive_modules.int "mod_" [ e1; e2 ] else { comment; expression_desc = Bin (Mod, e1, e2) } let float_mul ?comment e1 e2 = bin ?comment Mul e1 e2 let int32_lsl ?comment (e1 : J.expression) (e2 : J.expression) : J.expression = match (e1, e2) with - | ( { expression_desc = Number (Int { i = i0 } | Uint i0) }, - { expression_desc = Number (Int { i = i1 } | Uint i1) } ) -> + | ( { expression_desc = Number (Int { i = i0 }) }, + { expression_desc = Number (Int { i = i1 }) } ) -> int ?comment (Int32.shift_left i0 (Int32.to_int i1)) | _ -> { comment; expression_desc = Bin (Lsl, e1, e2) } @@ -1212,17 +1151,17 @@ let is_pos_pow n = let int32_mul ?comment (e1 : J.expression) (e2 : J.expression) : J.expression = match (e1, e2) with - | { expression_desc = Number (Int { i = 0l } | Uint 0l); _ }, x + | { expression_desc = Number (Int { i = 0l }); _ }, x when Js_analyzer.no_side_effect_expression x -> zero_int_literal - | x, { expression_desc = Number (Int { i = 0l } | Uint 0l); _ } + | x, { expression_desc = Number (Int { i = 0l }); _ } when Js_analyzer.no_side_effect_expression x -> zero_int_literal | ( { expression_desc = Number (Int { i = i0 }); _ }, { expression_desc = Number (Int { i = i1 }); _ } ) -> int (Int32.mul i0 i1) - | e, { expression_desc = Number (Int { i = i0 } | Uint i0); _ } - | { expression_desc = Number (Int { i = i0 } | Uint i0); _ }, e -> + | e, { expression_desc = Number (Int { i = i0 }); _ } + | { expression_desc = Number (Int { i = i0 }); _ }, e -> let i = is_pos_pow i0 in if i >= 0 then int32_lsl e (small_int i) else @@ -1241,10 +1180,10 @@ let rec int32_bxor ?comment (e1 : t) (e2 : t) : J.expression = match (e1.expression_desc, e2.expression_desc) with | Number (Int { i = i1 }), Number (Int { i = i2 }) -> int ?comment (Int32.logxor i1 i2) - | _, Bin (Lsr, e2, { expression_desc = Number (Int { i = 0l } | Uint 0l); _ }) + | _, Bin (Lsr, e2, { expression_desc = Number (Int { i = 0l }); _ }) -> int32_bxor e1 e2 - | Bin (Lsr, e1, { expression_desc = Number (Int { i = 0l } | Uint 0l); _ }), _ + | Bin (Lsr, e1, { expression_desc = Number (Int { i = 0l }); _ }), _ -> int32_bxor e1 e2 | _ -> { comment; expression_desc = Bin (Bxor, e1, e2) } @@ -1292,13 +1231,13 @@ let bigint_comp (cmp : Lam_compat.comparison) ?comment (e0: t) (e1: t) = let bigint_div ~checked ?comment (e0: t) (e1: t) = if checked then - runtime_call Js_runtime_modules.bigint "div" [e0; e1] + runtime_call Primitive_modules.bigint "div" [e0; e1] else bigint_op ?comment Div e0 e1 let bigint_mod ~checked ?comment (e0: t) (e1: t) = if checked then - runtime_call Js_runtime_modules.bigint "mod_" [e0; e1] + runtime_call Primitive_modules.bigint "mod_" [e0; e1] else bigint_op ?comment Mod e0 e1 @@ -1367,7 +1306,7 @@ let neq_null_undefined_boolean ?comment (a : t) (b : t) = | _ -> { expression_desc = Bin (NotEqEq, a, b); comment } let make_exception (s : string) = - pure_runtime_call Js_runtime_modules.exceptions Literals.create [ str s ] + pure_runtime_call Primitive_modules.exceptions Literals.create [ str s ] let rec variadic_args (args : t list) = match args with diff --git a/jscomp/core/js_exp_make.mli b/jscomp/core/js_exp_make.mli index c43de58f4c..99bbca10d5 100644 --- a/jscomp/core/js_exp_make.mli +++ b/jscomp/core/js_exp_make.mli @@ -108,8 +108,6 @@ val econd : ?comment:string -> t -> t -> t -> t val int : ?comment:string -> ?c:int -> int32 -> t -val uint32 : ?comment:string -> int32 -> t - val small_int : int -> t val bigint : ?comment:string -> bool -> string -> t @@ -225,8 +223,6 @@ val is_array : t -> t val to_int32 : ?comment:string -> t -> t -val to_uint32 : ?comment:string -> t -> t - val unchecked_int32_add : ?comment:string -> t -> t -> t val int32_add : ?comment:string -> t -> t -> t @@ -273,7 +269,7 @@ val int_comp : Lam_compat.comparison -> ?comment:string -> t -> t -> t val bool_comp : Lam_compat.comparison -> ?comment:string -> t -> t -> t -val string_comp : Js_op.binop -> ?comment:string -> t -> t -> t +val string_comp : Lam_compat.comparison -> ?comment:string -> t -> t -> t val float_comp : Lam_compat.comparison -> ?comment:string -> t -> t -> t diff --git a/jscomp/core/js_long.ml b/jscomp/core/js_long.ml deleted file mode 100644 index 9e4e347a34..0000000000 --- a/jscomp/core/js_long.ml +++ /dev/null @@ -1,160 +0,0 @@ -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * Copyright (C) 2016 - Hongbo Zhang, Authors of ReScript - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -module E = Js_exp_make - -type int64_call = J.expression list -> J.expression - -let int64_call (fn : string) args = - E.runtime_call Js_runtime_modules.int64 fn args - -(* below should not depend on layout *) - -let of_const (v : Int64.t) = - match v with - | 0L -> E.runtime_var_dot Js_runtime_modules.int64 "zero" - | 1L -> E.runtime_var_dot Js_runtime_modules.int64 "one" - | -1L -> E.runtime_var_dot Js_runtime_modules.int64 "neg_one" - | 9223372036854775807L -> E.runtime_var_dot Js_runtime_modules.int64 "max_int" - | -9223372036854775808L -> - E.runtime_var_dot Js_runtime_modules.int64 "min_int" - | _ -> - let unsigned_lo = E.uint32 (Int64.to_int32 v) in - let hi = E.int (Int64.to_int32 (Int64.shift_right v 32)) in - E.array Immutable [ hi; unsigned_lo ] -(* Assume the encoding of Int64 *) - -let to_int32 args = int64_call "to_int32" args - -(* let get_lo x = E.array_index_by_int x 1l *) -(* E.to_int32 @@ get_lo (Ext_list.singleton_exn args) *) - -let of_int32 (args : J.expression list) = - match args with - | [ { expression_desc = Number (Int { i }); _ } ] -> - of_const (Int64.of_int32 i) - | _ -> int64_call "of_int32" args - -let comp (cmp : Lam_compat.comparison) args = - E.runtime_call Js_runtime_modules.caml_primitive - (match cmp with - | Ceq -> "i64_eq" - | Cneq -> "i64_neq" - | Clt -> "i64_lt" - | Cgt -> "i64_gt" - | Cle -> "i64_le" - | Cge -> "i64_ge") - args - -let min args = E.runtime_call Js_runtime_modules.caml_primitive "i64_min" args - -let max args = E.runtime_call Js_runtime_modules.caml_primitive "i64_max" args - -let neg args = int64_call "neg" args - -let add args = int64_call "add" args - -let sub args = int64_call "sub" args - -let mul args = int64_call "mul" args - -let div args = int64_call "div" args - -(** Note if operands are not pure, we need hold shared value, - which is a statement [var x = ... ; x ], it does not fit - current pipe-line fall back to a function call -*) -let bit_op (* op : E.t -> E.t -> E.t*) runtime_call args = - int64_call runtime_call args - -(*disable optimizations relying on int64 representations - this maybe outdated when we switch to bigint -*) -(* match args with - | [l;r] -> - (* Int64 is a block in ocaml, a little more conservative in inlining *) - if Js_analyzer.is_okay_to_duplicate l && - Js_analyzer.is_okay_to_duplicate r then - make ~lo:(op (get_lo l) (get_lo r)) - ~hi:(op (get_hi l) (get_hi r)) - else - | _ -> assert false *) - -let xor = bit_op "xor" - -let or_ = bit_op "or_" - -let and_ = bit_op "and_" - -let lsl_ args = int64_call "lsl_" args - -let lsr_ args = int64_call "lsr_" args - -let asr_ args = int64_call "asr_" args - -let mod_ args = int64_call "mod_" args - -let swap args = int64_call "swap" args - -(* Safe constant propgation - {[ - Number.MAX_SAFE_INTEGER: - Math.pow(2,53) - 1 - ]} - {[ - Number.MIN_SAFE_INTEGER: - - (Math.pow(2,53) -1) - ]} - Note that [Number._SAFE_INTEGER] is in ES6, - we can hard code this number without bringing browser issue. -*) -let of_float (args : J.expression list) = int64_call "of_float" args - -let compare (args : J.expression list) = int64_call "compare" args - -(* let of_string (args : J.expression list) = - int64_call "of_string" args *) -(* let get64 = int64_call "get64" *) -let float_of_bits = int64_call "float_of_bits" - -let bits_of_float = int64_call "bits_of_float" - -let equal_null args = int64_call "equal_null" args - -let equal_undefined args = int64_call "equal_undefined" args - -let equal_nullable args = int64_call "equal_nullable" args - -let to_float (args : J.expression list) = - match args with - (* | [ {expression_desc *) - (* = Caml_block ( *) - (* [lo = *) - (* {expression_desc = Number (Int {i = lo; _}) }; *) - (* hi = *) - (* {expression_desc = Number (Int {i = hi; _}) }; *) - (* ], _, _, _); _ }] *) - (* -> *) - | [ _ ] -> int64_call "to_float" args - | _ -> assert false diff --git a/jscomp/core/js_long.mli b/jscomp/core/js_long.mli deleted file mode 100644 index 8b091a90f6..0000000000 --- a/jscomp/core/js_long.mli +++ /dev/null @@ -1,83 +0,0 @@ -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * Copyright (C) 2016 - Hongbo Zhang, Authors of ReScript - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -type int64_call = J.expression list -> J.expression - -(* val make_const : lo:Int32.t -> hi:Int32.t -> J.expression *) - -val of_const : int64 -> J.expression - -val to_int32 : int64_call - -val of_int32 : int64_call - -val comp : Lam_compat.comparison -> int64_call - -val neg : int64_call - -val add : int64_call - -val sub : int64_call - -val mul : int64_call - -val div : int64_call - -val xor : int64_call - -val mod_ : int64_call - -val lsl_ : int64_call - -val lsr_ : int64_call - -val asr_ : int64_call - -val and_ : int64_call - -val or_ : int64_call - -val swap : int64_call - -val min : int64_call - -val max : int64_call - -val equal_null : int64_call - -val equal_undefined : int64_call - -val equal_nullable : int64_call - -val to_float : int64_call - -val of_float : int64_call - -val compare : int64_call - -(* val of_string : int64_call *) -val float_of_bits : int64_call - -val bits_of_float : int64_call -(* val get64 : int64_call *) diff --git a/jscomp/core/js_of_lam_array.ml b/jscomp/core/js_of_lam_array.ml index c63d702090..e80f0e5a55 100644 --- a/jscomp/core/js_of_lam_array.ml +++ b/jscomp/core/js_of_lam_array.ml @@ -22,28 +22,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -(* - construct array, - set array, - ref array, - - Also make sure, don't call any primitive array method, i.e [E.array_index_by_int] - - We also need check primitive [caml_make_vect], i.e, - [Caml_primitive['caml_make_vect']] see if it's correct - - [caml_make_vect] - [caml_array_sub] - [caml_array_append] - [caml_array_concat] - [caml_make_float_vect] - [caml_array_blit] - - research: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays - - - *) - module E = Js_exp_make (* Parrayref(u|s) *) diff --git a/jscomp/core/js_of_lam_array.mli b/jscomp/core/js_of_lam_array.mli index 14aaba7543..d3a54f8369 100644 --- a/jscomp/core/js_of_lam_array.mli +++ b/jscomp/core/js_of_lam_array.mli @@ -28,8 +28,5 @@ val make_array : J.mutable_flag -> J.expression list -> J.expression (** create an array *) val set_array : J.expression -> J.expression -> J.expression -> J.expression -(** Here we don't care about [array_kind], - In the future, we might used TypedArray for FloatArray -*) val ref_array : J.expression -> J.expression -> J.expression diff --git a/jscomp/core/js_of_lam_option.ml b/jscomp/core/js_of_lam_option.ml index 7c2edf133b..7660846caf 100644 --- a/jscomp/core/js_of_lam_option.ml +++ b/jscomp/core/js_of_lam_option.ml @@ -66,7 +66,7 @@ let is_not_none (e : J.expression) : J.expression = let val_from_option (arg : J.expression) = match arg.expression_desc with | Optional_block (x, _) -> x - | _ -> E.runtime_call Js_runtime_modules.option "valFromOption" [ arg ] + | _ -> E.runtime_call Primitive_modules.option "valFromOption" [ arg ] let get_default_undefined_from_optional (arg : J.expression) : J.expression = let desc = arg.expression_desc in @@ -78,7 +78,7 @@ let get_default_undefined_from_optional (arg : J.expression) : J.expression = if Js_analyzer.is_okay_to_duplicate arg then (* FIXME: no need do such inlining*) E.econd (is_not_none arg) (val_from_option arg) E.undefined - else E.runtime_call Js_runtime_modules.option "option_get" [ arg ] + else E.runtime_call Primitive_modules.option "toUndefined" [ arg ] let option_unwrap (arg : J.expression) : J.expression = let desc = arg.expression_desc in @@ -87,7 +87,7 @@ let option_unwrap (arg : J.expression) : J.expression = match desc with | Optional_block (x, _) -> E.poly_var_value_access x (* invariant: option encoding *) - | _ -> E.runtime_call Js_runtime_modules.option "option_unwrap" [ arg ] + | _ -> E.runtime_call Primitive_modules.option "unwrapPolyVar" [ arg ] let destruct_optional ~for_sure_none ~for_sure_some ~not_sure (arg : J.expression) = diff --git a/jscomp/core/js_of_lam_string.ml b/jscomp/core/js_of_lam_string.ml index 1ec3f77e98..765a9d3ee7 100644 --- a/jscomp/core/js_of_lam_string.ml +++ b/jscomp/core/js_of_lam_string.ml @@ -34,15 +34,6 @@ let const_char (i : int) = E.int ~c:i (Int32.of_int @@ i) (* string [s[i]] expects to return a [ocaml_char] *) let ref_string e e1 = E.string_index e e1 -(* [s[i]] excepts to return a [ocaml_char] - We use normal array for [bytes] - TODO: we can use [Buffer] in the future -*) -let ref_byte e e0 = E.array_index e e0 - -(* {Bytes.set : bytes -> int -> char -> unit }*) -let set_byte e e0 e1 = E.assign (E.array_index e e0) e1 - (** Note that [String.fromCharCode] also works, but it only work for small arrays, however, for {bytes_to_string} it is likely the bytes @@ -59,5 +50,3 @@ let set_byte e e0 e1 = E.assign (E.array_index e e0) e1 Maxiume call stack size exceeded ]} *) -let bytes_to_string e = - E.runtime_call Js_runtime_modules.bytes_ "to_string" [ e ] diff --git a/jscomp/core/js_of_lam_string.mli b/jscomp/core/js_of_lam_string.mli index eb6ca708dd..68feda72ad 100644 --- a/jscomp/core/js_of_lam_string.mli +++ b/jscomp/core/js_of_lam_string.mli @@ -30,10 +30,4 @@ val ref_string : J.expression -> J.expression -> J.expression -val ref_byte : J.expression -> J.expression -> J.expression - -val set_byte : J.expression -> J.expression -> J.expression -> J.expression - val const_char : int -> J.expression - -val bytes_to_string : J.expression -> J.expression diff --git a/jscomp/core/js_op.ml b/jscomp/core/js_op.ml index 9315f73c6d..2d626ad08e 100644 --- a/jscomp/core/js_op.ml +++ b/jscomp/core/js_op.ml @@ -131,7 +131,6 @@ type bigint_lit = { positive: bool; value: string } type number = | Float of float_lit | Int of { i : int32; c : int option } - | Uint of int32 | BigInt of bigint_lit (* becareful when constant folding +/-, diff --git a/jscomp/core/lam.ml b/jscomp/core/lam.ml index eb1df4154a..79a4bdeeab 100644 --- a/jscomp/core/lam.ml +++ b/jscomp/core/lam.ml @@ -291,7 +291,7 @@ let rec apply fn args (ap_info : ap_info) : t = { primitive = ( Pundefined_to_opt | Pnull_to_opt | Pnull_undefined_to_opt - | Pis_null | Pis_null_undefined | Pjs_typeof ) as wrap; + | Pis_null | Pis_null_undefined | Ptypeof ) as wrap; args = [ Lprim ({ primitive = _; args = inner_args } as primitive_call); @@ -461,17 +461,8 @@ module Lift = struct let bool b = if b then true_ else false_ - (* ATTENTION: [float, nativeint] constant propogaton is not done - yet , due to cross platform problem - *) - (* let float b : t = - Lconst ((Const_float b)) *) - - (* let nativeint b : t = - Lconst ((Const_nativeint b)) *) - - let int64 b : t = Lconst (Const_int64 b) let string s : t = Lconst (Const_string { s; unicode = false }) + let char b : t = Lconst (Const_char b) end @@ -492,14 +483,11 @@ let prim ~primitive:(prim : Lam_primitive.t) ~args loc : t = (* | Pnegbint Pnativeint, ( (Const_nativeint i)) *) (* -> *) (* Lift.nativeint (Nativeint.neg i) *) - | Pnegint64, Const_int64 a -> Lift.int64 (Int64.neg a) | Pnot, Const_js_true -> false_ | Pnot, Const_js_false -> true_ | _ -> default ()) | [ Lconst a; Lconst b ] -> ( match (prim, a, b) with - | Pint64comp cmp, Const_int64 a, Const_int64 b -> - Lift.bool (Lam_compat.cmp_int64 cmp a b) | Pintcomp cmp, Const_int a, Const_int b -> Lift.bool (Lam_compat.cmp_int32 cmp a.i b.i) | Pfloatcomp cmp, Const_float a, Const_float b -> @@ -532,28 +520,6 @@ let prim ~primitive:(prim : Lam_primitive.t) ~args loc : t = | Plsrint -> int_ (Int32.shift_right_logical aa (Int32.to_int bb)) | Pasrint -> int_ (Int32.shift_right aa (Int32.to_int bb)) | _ -> default ()) - | ( ( Paddint64 | Psubint64 | Pmulint64 | Pdivint64 | Pmodint64 - | Pandint64 | Porint64 | Pxorint64 ), - Const_int64 aa, - Const_int64 bb ) -> ( - match prim with - | Paddint64 -> Lift.int64 (Int64.add aa bb) - | Psubint64 -> Lift.int64 (Int64.sub aa bb) - | Pmulint64 -> Lift.int64 (Int64.mul aa bb) - | Pdivint64 -> ( - try Lift.int64 (Int64.div aa bb) with _ -> default ()) - | Pmodint64 -> ( - try Lift.int64 (Int64.rem aa bb) with _ -> default ()) - | Pandint64 -> Lift.int64 (Int64.logand aa bb) - | Porint64 -> Lift.int64 (Int64.logor aa bb) - | Pxorint64 -> Lift.int64 (Int64.logxor aa bb) - | _ -> default ()) - | Plslint64, Const_int64 aa, Const_int { i = b } -> - Lift.int64 (Int64.shift_left aa (Int32.to_int b)) - | Plsrint64, Const_int64 aa, Const_int { i = b } -> - Lift.int64 (Int64.shift_right_logical aa (Int32.to_int b)) - | Pasrint64, Const_int64 aa, Const_int { i = b } -> - Lift.int64 (Int64.shift_right aa (Int32.to_int b)) | Psequand, Const_js_false, (Const_js_true | Const_js_false) -> false_ | Psequand, Const_js_true, Const_js_true -> true_ | Psequand, Const_js_true, Const_js_false -> false_ @@ -616,9 +582,13 @@ let has_boolean_type (x : t) = | Lprim { primitive = - ( Pnot | Psequand | Psequor | Pisout _ | Pintcomp _ | Pis_not_none + ( Pnot | Psequand | Psequor | Pisout _ | Pis_not_none + | Pobjcomp _ + | Pboolcomp _ + | Pintcomp _ | Pfloatcomp _ - | Pccall { prim_name = "caml_string_equal" | "caml_string_notequal" } + | Pbigintcomp _ + | Pstringcomp _ ); loc; } -> @@ -639,12 +609,10 @@ let rec eval_const_as_bool (v : Lam_constant.t) : bool = match v with | Const_int { i = x } -> x <> 0l | Const_char x -> x <> 0 - | Const_int64 x -> x <> 0L | Const_js_false | Const_js_null | Const_module_alias | Const_js_undefined _ -> false | Const_js_true | Const_string _ | Const_pointer _ | Const_float _ | Const_bigint _ - | Const_block _ | Const_float_array _ -> - true + | Const_block _ -> true | Const_some b -> eval_const_as_bool b let if_ (a : t) (b : t) (c : t) : t = diff --git a/jscomp/core/lam_analysis.ml b/jscomp/core/lam_analysis.ml index 0a377dd5db..879ff913db 100644 --- a/jscomp/core/lam_analysis.ml +++ b/jscomp/core/lam_analysis.ml @@ -26,7 +26,6 @@ let not_zero_constant (x : Lam_constant.t) = match x with | Const_int { i } -> i <> 0l - | Const_int64 i -> i <> 0L | Const_bigint (_, i) -> i <> "0" | _ -> false @@ -41,59 +40,58 @@ let rec no_side_effects (lam : Lam.t) : bool = Ext_list.for_all args no_side_effects && match primitive with - | Pccall { prim_name } -> ( - match (prim_name, args) with - | ( (* register to c runtime does not make sense in ocaml *) - ( "?int64_float_of_bits" - (* more safe to check if arguments are constant *) - (* non-observable side effect *) - | "?sys_get_argv" (* should be fine *) - | "?string_repeat" | "?make_vect" | "?create_bytes" - | "caml_array_dup" | "?nativeint_add" | "?nativeint_div" - | "?nativeint_mod" | "?nativeint_lsr" | "?nativeint_mul" ), - _ ) -> - true - | _, _ -> false) - | Pmodint | Pdivint | Pdivint64 | Pmodint64 | Pdivbigint | Pmodbigint -> ( + | Pmodint | Pdivint | Pdivbigint | Pmodbigint -> ( match args with | [ _; Lconst cst ] -> not_zero_constant cst | _ -> false) - | Pcreate_extension _ | Pjs_typeof | Pis_null | Pis_not_none | Psome + | Pcreate_extension _ | Ptypeof | Pis_null | Pis_not_none | Psome | Psome_not_nest | Pis_undefined | Pis_null_undefined | Pnull_to_opt | Pundefined_to_opt | Pnull_undefined_to_opt | Pjs_fn_make _ | Pjs_fn_make_unit | Pjs_object_create _ | Pimport (* TODO: check *) - | Pbytes_to_string | Pmakeblock _ + | Pmakeblock _ (* whether it's mutable or not *) | Pfield _ | Pval_from_option | Pval_from_option_not_nest (* NOP The compiler already [t option] is the same as t *) | Pduprecord - (* Boolean operations *) + (* generic primitives *) + | Pobjcomp _ | Pobjorder | Pobjmin | Pobjmax | Pobjtag | Pobjsize + (* bool primitives *) | Psequand | Psequor | Pnot - (* Integer operations *) + | Pboolcomp _ | Pboolorder | Pboolmin | Pboolmax + (* int primitives *) | Pnegint | Paddint | Psubint | Pmulint | Pandint | Porint | Pxorint | Plslint | Plsrint | Pasrint | Pintcomp _ - (* Float operations *) + | Pintorder | Pintmin | Pintmax + (* float primitives *) | Pintoffloat | Pfloatofint | Pnegfloat - (* | Pabsfloat *) - | Paddfloat | Psubfloat | Pmulfloat | Pdivfloat | Pfloatcomp _ | Pjscomp _ + | Paddfloat | Psubfloat | Pmulfloat | Pdivfloat | Pmodfloat + | Pfloatcomp _ | Pjscomp _ | Pfloatorder | Pfloatmin | Pfloatmax + (* bigint primitives *) | Pnegbigint | Paddbigint | Psubbigint | Pmulbigint | Ppowbigint | Pandbigint | Porbigint | Pxorbigint | Plslbigint | Pasrbigint - | Pbigintcomp _ - (* String operations *) - | Pstringlength | Pstringrefu | Pstringrefs | Pbyteslength | Pbytesrefu - | Pbytesrefs | Pmakearray | Parraylength | Parrayrefu | Parrayrefs + | Pbigintcomp _ | Pbigintorder | Pbigintmin | Pbigintmax + (* string primitives *) + | Pstringlength | Pstringrefu | Pstringrefs + | Pstringcomp _ | Pstringorder | Pstringmin | Pstringmax + (* array primitives *) + | Pmakearray | Parraylength | Parrayrefu | Parrayrefs + (* list primitives *) + | Pmakelist + (* dict primitives *) + | Pmakedict (* Test if the argument is a block or an immediate integer *) | Pisint | Pis_poly_var_block (* Test if the (integer) argument is outside an interval *) - | Pisout _ | Pint64ofint | Pintofint64 | Pnegint64 | Paddint64 | Psubint64 - | Pmulint64 | Pandint64 | Porint64 | Pxorint64 | Plslint64 | Plsrint64 - | Pasrint64 | Pint64comp _ + | Pisout _ (* Operations on big arrays: (unsafe, #dimensions, kind, layout) *) (* Compile time constants *) - | Pctconst _ (* Integer to external pointer *) - | Poffsetint _ | Pstringadd | Pjs_function_length | Pcaml_obj_length + | Poffsetint _ | Pstringadd | Pfn_arity | Pwrap_exn + | Phash + | Phash_mixstring + | Phash_mixint + | Phash_finalmix | Praw_js_code { code_info = @@ -101,14 +99,14 @@ let rec no_side_effects (lam : Lam.t) : bool = } -> true | Pjs_apply | Pjs_runtime_apply | Pjs_call _ | Pinit_mod | Pupdate_mod - | Pjs_unsafe_downgrade _ | Pdebugger | Pvoid_run | Pfull_apply + | Pjs_unsafe_downgrade _ | Pdebugger | Pjs_fn_method + (* Await promise *) + | Pawait (* TODO *) - | Praw_js_code _ | Pbytessetu | Pbytessets - (* Operations on boxed integers (Nativeint.t, Int32.t, Int64.t) *) - | Parraysets + | Praw_js_code _ (* byte swap *) - | Parraysetu | Poffsetref _ | Praise | Plazyforce | Psetfield _ -> + | Parraysets | Parraysetu | Poffsetref _ | Praise | Plazyforce | Psetfield _ -> false) | Llet (_, _, arg, body) -> no_side_effects arg && no_side_effects body | Lswitch (_, _) -> false @@ -197,7 +195,7 @@ let rec size (lam : Lam.t) = and size_constant x = match x with - | Const_int _ | Const_char _ | Const_float _ | Const_int64 _ | Const_bigint _ | Const_pointer _ + | Const_int _ | Const_char _ | Const_float _ | Const_bigint _ | Const_pointer _ | Const_js_null | Const_js_undefined _ | Const_module_alias | Const_js_true | Const_js_false -> 1 @@ -206,7 +204,6 @@ and size_constant x = | Const_some s -> size_constant s | Const_block (_, _, str) -> Ext_list.fold_left str 0 (fun acc x -> acc + size_constant x) - | Const_float_array xs -> List.length xs and size_lams acc (lams : Lam.t list) = Ext_list.fold_left lams acc (fun acc l -> acc + size l) diff --git a/jscomp/core/lam_arity_analysis.ml b/jscomp/core/lam_arity_analysis.ml index d77477dcb4..dcc045858c 100644 --- a/jscomp/core/lam_arity_analysis.ml +++ b/jscomp/core/lam_arity_analysis.ml @@ -65,9 +65,6 @@ let rec get_arity (meta : Lam_stats.t) (lam : Lam.t) : Lam_arity.t = match (Lam_compile_env.query_external_id_info ~dynamic_import id name).arity with | Submodule subs -> subs.(m) (* TODO: shall we store it as array?*) | Single _ -> Lam_arity.na) - (* TODO: all information except Pccall is complete, we could - get more arity information - *) | Lprim { primitive = Praw_js_code { code_info = Exp (Js_function { arity }) } } -> diff --git a/jscomp/core/lam_compat.ml b/jscomp/core/lam_compat.ml index 3fb76f455c..2bc69baaca 100644 --- a/jscomp/core/lam_compat.ml +++ b/jscomp/core/lam_compat.ml @@ -22,14 +22,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -type boxed_integer = Lambda.boxed_integer = Pbigint | Pint32 | Pint64 - -let eq_boxed_integer (p : boxed_integer) (p1 : boxed_integer) = - match p with - | Pbigint -> p1 = Pbigint - | Pint32 -> p1 = Pint32 - | Pint64 -> p1 = Pint64 - type comparison = Lambda.comparison = Ceq | Cneq | Clt | Cgt | Cle | Cge let eq_comparison (p : comparison) (p1 : comparison) = @@ -50,15 +42,6 @@ let cmp_int32 (cmp : comparison) (a : int32) b : bool = | Clt -> a < b | Cge -> a >= b -let cmp_int64 (cmp : comparison) (a : int64) b : bool = - match cmp with - | Ceq -> a = b - | Cneq -> a <> b - | Cgt -> a > b - | Cle -> a <= b - | Clt -> a < b - | Cge -> a >= b - let cmp_float (cmp : comparison) (a : float) b : bool = match cmp with | Ceq -> a = b @@ -77,18 +60,6 @@ let cmp_int (cmp : comparison) (a : int) b : bool = | Clt -> a < b | Cge -> a >= b -type compile_time_constant = - | Big_endian - | Ostype_unix - | Ostype_win32 - | Ostype - | Backend_type - -(** relies on the fact that [compile_time_constant] is enum type *) -let eq_compile_time_constant (p : compile_time_constant) - (p1 : compile_time_constant) = - p = p1 - type let_kind = Lambda.let_kind = Strict | Alias | StrictOpt | Variable type field_dbg_info = Lambda.field_dbg_info = diff --git a/jscomp/core/lam_compat.mli b/jscomp/core/lam_compat.mli index de022543be..58934e0ae0 100644 --- a/jscomp/core/lam_compat.mli +++ b/jscomp/core/lam_compat.mli @@ -22,17 +22,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -type boxed_integer = Lambda.boxed_integer = Pbigint | Pint32 | Pint64 - type comparison = Lambda.comparison = Ceq | Cneq | Clt | Cgt | Cle | Cge -type compile_time_constant = - | Big_endian - | Ostype_unix - | Ostype_win32 - | Ostype - | Backend_type - type let_kind = Lambda.let_kind = Strict | Alias | StrictOpt | Variable type field_dbg_info = Lambda.field_dbg_info = @@ -57,15 +48,8 @@ type set_field_dbg_info = Lambda.set_field_dbg_info = val cmp_int32 : comparison -> int32 -> int32 -> bool -val cmp_int64 : comparison -> int64 -> int64 -> bool - val cmp_float : comparison -> float -> float -> bool val cmp_int : comparison -> int -> int -> bool val eq_comparison : comparison -> comparison -> bool - -val eq_boxed_integer : boxed_integer -> boxed_integer -> bool - -val eq_compile_time_constant : - compile_time_constant -> compile_time_constant -> bool diff --git a/jscomp/core/lam_compile.ml b/jscomp/core/lam_compile.ml index dfd678d97f..7b9c511bbb 100644 --- a/jscomp/core/lam_compile.ml +++ b/jscomp/core/lam_compile.ml @@ -446,8 +446,8 @@ and compile_recursive_let ~all_bindings (cxt : Lam_compile_context.t) (Ext_list.append b [ S.exp - (E.runtime_call Js_runtime_modules.obj_runtime - "update_dummy" [ E.var id; v ]); + (E.runtime_call Primitive_modules.object_ + "updateDummy" [ E.var id; v ]); ]), [ S.define_variable ~kind:Variable id (E.dummy_obj tag_info) ] ) | _ -> assert false) @@ -1582,24 +1582,6 @@ and compile_prim (prim_info : Lam.prim_info) (E.seq (E.assign (E.dot (E.var obj) property) value) E.unit))) | { primitive = Pjs_unsafe_downgrade _; args } -> assert false - | { primitive = Pfull_apply | Pvoid_run; args; loc } -> ( - (* 1. uncurried call should not do eta-conversion - since `fn.length` will broken - 2. invariant: `external` declaration will guarantee - the function application is saturated - 3. we need a location for Pccall in the call site - *) - match args with - | fn :: rest -> - compile_lambda lambda_cxt - (Lam.apply fn rest - { - ap_loc = loc; - ap_inlined = Default_inline; - ap_status = App_uncurry; - }) - (*FIXME: should pass info down: `f a [@bs][@inlined]`*) - | [] -> assert false) | { primitive = Pjs_fn_method; args = args_lambda } -> ( match args_lambda with | [ Lfunction { params; body; attr = { return_unit } } ] -> diff --git a/jscomp/core/lam_compile_const.ml b/jscomp/core/lam_compile_const.ml index 275f17830c..1449eeecb8 100644 --- a/jscomp/core/lam_compile_const.ml +++ b/jscomp/core/lam_compile_const.ml @@ -55,25 +55,6 @@ and translate (x : Lam_constant.t) : J.expression = | Const_int { i; comment } -> E.int i ?comment:(Lam_constant.string_of_pointer_info comment) | Const_char i -> Js_of_lam_string.const_char i - (* E.float (Int32.to_string i) *) - | Const_int64 i -> - (* - TODO: - {[ - Int64.to_string 0x7FFFFFFFFFFFFFFFL;; - - : string = "9223372036854775807" - ]} - {[ - Int64.(to_float max_int);; - - : float = 9.22337203685477581e+18 - ]} - Note we should compile it to Int64 as JS's - speical representation -- - it is not representatble in JS number - *) - (* E.float (Int64.to_string i) *) - Js_long.of_const i - (* https://github.com/google/closure-library/blob/master/closure%2Fgoog%2Fmath%2Flong.js *) | Const_bigint (sign, i) -> E.bigint sign i | Const_float f -> E.float f (* TODO: preserve float *) | Const_string { s; unicode = false } -> E.str s @@ -82,19 +63,6 @@ and translate (x : Lam_constant.t) : J.expression = | Const_block (tag, tag_info, xs) -> Js_of_lam_block.make_block NA tag_info (E.small_int tag) (Ext_list.map xs translate) - | Const_float_array ars -> - (* according to the compiler - const_float_array is immutable - {[ Lprim(Pccall prim_obj_dup, [master]) ]}, - however, we can not translate - {[ prim_obj_dup(x) => x' ]} - since x' is now mutable, prim_obj_dup does a copy, - - the compiler does this is mainly to extract common data into data section, - we deoptimized this in js backend? so it is actually mutable - *) - (* TODO-- *) - Js_of_lam_array.make_array Mutable (Ext_list.map ars E.float) (* E.arr Mutable ~comment:"float array" *) (* (Ext_list.map (fun x -> E.float x ) ars) *) diff --git a/jscomp/core/lam_compile_primitive.ml b/jscomp/core/lam_compile_primitive.ml index 335a892838..613d0220e5 100644 --- a/jscomp/core/lam_compile_primitive.ml +++ b/jscomp/core/lam_compile_primitive.ml @@ -78,8 +78,8 @@ let translate output_prefix loc (cxt : Lam_compile_context.t) | Pis_not_none -> Js_of_lam_option.is_not_none (Ext_list.singleton_exn args) | Pcreate_extension s -> E.make_exception s | Pwrap_exn -> - E.runtime_call Js_runtime_modules.caml_js_exceptions - "internalToOCamlException" args + E.runtime_call Primitive_modules.exceptions + "internalToException" args | Praw_js_code { code; code_info } -> E.raw_js_code code_info code (* FIXME: save one allocation trim can not be done before syntax checking @@ -96,7 +96,7 @@ let translate output_prefix loc (cxt : Lam_compile_context.t) | [ e ] -> ( match e.expression_desc with | Var _ | Undefined _ | Null -> Js_of_lam_option.null_to_opt e - | _ -> E.runtime_call Js_runtime_modules.option "null_to_opt" args) + | _ -> E.runtime_call Primitive_modules.option "fromNull" args) | _ -> assert false) | Pundefined_to_opt -> ( match args with @@ -104,17 +104,17 @@ let translate output_prefix loc (cxt : Lam_compile_context.t) match e.expression_desc with | Var _ | Undefined _ | Null -> Js_of_lam_option.undef_to_opt e | _ -> - E.runtime_call Js_runtime_modules.option "undefined_to_opt" args) + E.runtime_call Primitive_modules.option "fromUndefined" args) | _ -> assert false) | Pnull_undefined_to_opt -> ( match args with | [ e ] -> ( match e.expression_desc with | Var _ | Undefined _ | Null -> Js_of_lam_option.null_undef_to_opt e - | _ -> E.runtime_call Js_runtime_modules.option "nullable_to_opt" args + | _ -> E.runtime_call Primitive_modules.option "fromNullable" args ) | _ -> assert false) - (* Compile #import: The module argument for dynamic import is represented as a path, + (* Compile %import: The module argument for dynamic import is represented as a path, and the module value is expressed through wrapping it with promise.then *) | Pimport -> ( match args with @@ -139,20 +139,19 @@ let translate output_prefix loc (cxt : Lam_compile_context.t) | [] | _ -> Location.raise_errorf ~loc "Invalid argument: Dynamic import must take a single module or module value as its argument.") - | Pjs_function_length -> E.function_length (Ext_list.singleton_exn args) - | Pcaml_obj_length -> E.obj_length (Ext_list.singleton_exn args) + | Pfn_arity -> E.function_length (Ext_list.singleton_exn args) + | Pobjsize -> E.obj_length (Ext_list.singleton_exn args) | Pis_null -> E.is_null (Ext_list.singleton_exn args) | Pis_undefined -> E.is_undef (Ext_list.singleton_exn args) | Pis_null_undefined -> E.is_null_undefined (Ext_list.singleton_exn args) - | Pjs_typeof -> E.typeof (Ext_list.singleton_exn args) - | Pjs_unsafe_downgrade _ | Pdebugger | Pvoid_run | Pfull_apply | Pjs_fn_make _ | Pjs_fn_make_unit + | Ptypeof -> E.typeof (Ext_list.singleton_exn args) + | Pjs_unsafe_downgrade _ | Pdebugger | Pjs_fn_make _ | Pjs_fn_make_unit | Pjs_fn_method -> assert false (* already handled by {!Lam_compile} *) - | Pjs_fn_method -> assert false | Pstringadd -> ( match args with [ a; b ] -> E.string_append a b | _ -> assert false) - | Pinit_mod -> E.runtime_call Js_runtime_modules.module_ "init_mod" args - | Pupdate_mod -> E.runtime_call Js_runtime_modules.module_ "update_mod" args + | Pinit_mod -> E.runtime_call Primitive_modules.module_ "init" args + | Pupdate_mod -> E.runtime_call Primitive_modules.module_ "update" args | Psome -> ( let arg = Ext_list.singleton_exn args in match arg.expression_desc with @@ -181,39 +180,36 @@ let translate output_prefix loc (cxt : Lam_compile_context.t) | Pnegint -> (* #977 *) E.int32_minus E.zero_int_literal (Ext_list.singleton_exn args) - | Pnegint64 -> Js_long.neg args | Pnegfloat -> E.float_minus E.zero_float_lit (Ext_list.singleton_exn args) | Pnegbigint -> E.bigint_op Minus E.zero_bigint_literal (Ext_list.singleton_exn args) (* Negate boxed int end*) (* Int addition and subtraction *) | Paddint -> ( match args with [ e1; e2 ] -> E.int32_add e1 e2 | _ -> assert false) - | Paddint64 -> Js_long.add args | Paddfloat -> ( match args with [ e1; e2 ] -> E.float_add e1 e2 | _ -> assert false) | Paddbigint -> ( match args with [ e1; e2 ] -> E.bigint_op Plus e1 e2 | _ -> assert false) | Psubint -> ( match args with [ e1; e2 ] -> E.int32_minus e1 e2 | _ -> assert false) - | Psubint64 -> Js_long.sub args | Psubfloat -> ( match args with [ e1; e2 ] -> E.float_minus e1 e2 | _ -> assert false) | Psubbigint -> ( match args with [ e1; e2 ] -> E.bigint_op Minus e1 e2 | _ -> assert false) | Pmulint -> ( match args with [ e1; e2 ] -> E.int32_mul e1 e2 | _ -> assert false) - | Pmulint64 -> Js_long.mul args | Pmulfloat -> ( match args with [ e1; e2 ] -> E.float_mul e1 e2 | _ -> assert false) | Pmulbigint -> ( match args with [ e1; e2 ] -> E.bigint_op Mul e1 e2 | _ -> assert false) | Pdivfloat -> ( match args with [ e1; e2 ] -> E.float_div e1 e2 | _ -> assert false) + | Pmodfloat -> ( + match args with [ e1; e2 ] -> E.float_mod e1 e2 | _ -> assert false) | Pdivint -> ( match args with | [ e1; e2 ] -> E.int32_div ~checked:!Js_config.check_div_by_zero e1 e2 | _ -> assert false) - | Pdivint64 -> Js_long.div args | Pdivbigint -> ( match args with | [ e1; e2 ] -> E.bigint_div ~checked:!Js_config.check_div_by_zero e1 e2 @@ -222,7 +218,6 @@ let translate output_prefix loc (cxt : Lam_compile_context.t) match args with | [ e1; e2 ] -> E.int32_mod ~checked:!Js_config.check_div_by_zero e1 e2 | _ -> assert false) - | Pmodint64 -> Js_long.mod_ args | Pmodbigint -> ( match args with | [ e1; e2 ] -> E.bigint_mod ~checked:!Js_config.check_div_by_zero e1 e2 @@ -230,39 +225,36 @@ let translate output_prefix loc (cxt : Lam_compile_context.t) | Ppowbigint -> (match args with [ e1; e2 ] -> E.bigint_op Pow e1 e2 | _ -> assert false) | Plslint -> ( match args with [ e1; e2 ] -> E.int32_lsl e1 e2 | _ -> assert false) - | Plslint64 -> Js_long.lsl_ args | Plslbigint -> ( match args with [ e1; e2 ] -> E.bigint_op Lsl e1 e2 | _ -> assert false) | Plsrint -> ( match args with - | [ e1; { J.expression_desc = Number (Int { i = 0l; _ } | Uint 0l); _ } ] + | [ e1; { J.expression_desc = Number (Int { i = 0l; _ }); _ } ] -> e1 | [ e1; e2 ] -> E.to_int32 @@ E.int32_lsr e1 e2 | _ -> assert false) - | Plsrint64 -> Js_long.lsr_ args | Pasrint -> ( match args with [ e1; e2 ] -> E.int32_asr e1 e2 | _ -> assert false) - | Pasrint64 -> Js_long.asr_ args | Pasrbigint -> ( match args with [ e1; e2 ] -> E.bigint_op Asr e1 e2 | _ -> assert false) | Pandint -> ( match args with [ e1; e2 ] -> E.int32_band e1 e2 | _ -> assert false) - | Pandint64 -> Js_long.and_ args | Pandbigint -> ( match args with [ e1; e2 ] -> E.bigint_op Band e1 e2 | _ -> assert false) | Porint -> ( match args with [ e1; e2 ] -> E.int32_bor e1 e2 | _ -> assert false) - | Porint64 -> Js_long.or_ args | Porbigint -> ( match args with [ e1; e2 ] -> E.bigint_op Bor e1 e2 | _ -> assert false) | Pxorint -> ( match args with [ e1; e2 ] -> E.int32_bxor e1 e2 | _ -> assert false) - | Pxorint64 -> Js_long.xor args | Pxorbigint -> ( match args with [ e1; e2 ] -> E.bigint_op Bxor e1 e2 | _ -> assert false) | Pjscomp cmp -> ( match args with [ l; r ] -> E.js_comp cmp l r | _ -> assert false) + | Pboolcomp cmp -> ( + match args with [ e1; e2 ] -> E.bool_comp cmp e1 e2 | _ -> assert false + ) | Pfloatcomp cmp | Pintcomp cmp -> ( (* Global Builtin Exception is an int, like [Not_found] or [Invalid_argument] ? @@ -273,12 +265,12 @@ let translate output_prefix loc (cxt : Lam_compile_context.t) (* List --> stamp = 0 Assert_false --> stamp = 26 *) - | Pint64comp cmp -> Js_long.comp cmp args + | Pstringcomp cmp -> ( + match args with [ e1; e2 ] -> E.string_comp cmp e1 e2 | _ -> assert false + ) | Pintoffloat -> ( match args with [ e ] -> E.to_int32 e | _ -> assert false) - | Pint64ofint -> Js_long.of_int32 args | Pfloatofint -> Ext_list.singleton_exn args - | Pintofint64 -> Js_long.to_int32 args | Pnot -> E.not (Ext_list.singleton_exn args) | Poffsetint n -> E.offset (Ext_list.singleton_exn args) n | Poffsetref n -> @@ -308,33 +300,143 @@ let translate output_prefix loc (cxt : Lam_compile_context.t) *) | [ range; e ] -> E.is_out (E.offset e off) range | _ -> assert false) - | Pbytes_to_string -> - Js_of_lam_string.bytes_to_string (Ext_list.singleton_exn args) | Pstringlength -> E.string_length (Ext_list.singleton_exn args) - | Pbyteslength -> E.bytes_length (Ext_list.singleton_exn args) - (* This should only be Pbyteset(u|s), which in js, is an int array - Bytes is an int array in javascript - *) - | Pbytessetu -> ( + | Pstringrefs | Pstringrefu -> ( match args with - | [ e; e0; e1 ] -> - ensure_value_unit cxt.continuation (Js_of_lam_string.set_byte e e0 e1) + | [ e; e1 ] -> E.runtime_call Primitive_modules.string "getChar" args | _ -> assert false) - | Pbytessets -> E.runtime_call Js_runtime_modules.bytes "set" args - | Pbytesrefu -> ( + (* polymorphic operations *) + | Pobjcomp cmp -> ( match args with - | [ e; e1 ] -> Js_of_lam_string.ref_byte e e1 + | [ e1; e2 ] + when cmp = Ceq && (E.for_sure_js_null_undefined e1 || E.for_sure_js_null_undefined e2) + -> + E.eq_null_undefined_boolean e1 e2 + | [ e1; e2 ] + when cmp = Cneq && (E.for_sure_js_null_undefined e1 || E.for_sure_js_null_undefined e2) + -> + E.neq_null_undefined_boolean e1 e2 + | [ e1; e2 ] -> + Location.prerr_warning loc Warnings.Bs_polymorphic_comparison; + E.runtime_call Primitive_modules.object_ + (Lam_compile_util.runtime_of_comp cmp) args | _ -> assert false) - | Pbytesrefs -> E.runtime_call Js_runtime_modules.bytes "get" args - | Pstringrefs -> E.runtime_call Js_runtime_modules.string "get" args - (* For bytes and string, they both return [int] in ocaml - we need tell Pbyteref from Pstringref - 1. Pbyteref -> a[i] - 2. Pstringref -> a.charCodeAt (a[i] is wrong) - *) - | Pstringrefu -> ( + | Pobjorder -> ( + Location.prerr_warning loc Warnings.Bs_polymorphic_comparison; + match args with + | [ a; b ] -> E.runtime_call Primitive_modules.object_ "compare" args + | _ -> assert false) + | Pobjmin -> ( + Location.prerr_warning loc Warnings.Bs_polymorphic_comparison; + match args with + | [ a; b ] -> E.runtime_call Primitive_modules.object_ "min" args + | _ -> assert false) + | Pobjmax -> ( + Location.prerr_warning loc Warnings.Bs_polymorphic_comparison; + match args with + | [ a; b ] -> E.runtime_call Primitive_modules.object_ "max" args + | _ -> assert false) + | Pobjtag -> ( + (* Note that in ocaml, [int] has tag [1000] and [string] has tag [252] + also now we need do nullary check + *) + match args with [ e ] -> E.tag e | _ -> assert false) + | Pboolorder -> ( + match args with + | [ { expression_desc = Bool a }; { expression_desc = Bool b } ] -> + let c = compare (a : bool) b in + E.int (if c = 0 then 0l else if c > 0 then 1l else -1l) + | [ a; b ] -> E.runtime_call Primitive_modules.bool "compare" args + | _ -> assert false) + | Pboolmin -> ( + match args with + | [ { expression_desc = Bool _ } as a; { expression_desc = Bool _ } as b ] -> + if + Js_analyzer.is_okay_to_duplicate a + && Js_analyzer.is_okay_to_duplicate b + then E.econd (E.js_comp Clt a b) a b + else E.runtime_call Primitive_modules.bool "min" args + | [ a; b ] -> E.runtime_call Primitive_modules.bool "min" args + | _ -> assert false) + | Pboolmax -> ( + match args with + | [ { expression_desc = Bool _ } as a; { expression_desc = Bool _ } as b ] + when Js_analyzer.is_okay_to_duplicate a && Js_analyzer.is_okay_to_duplicate b -> + E.econd (E.js_comp Cgt a b) a b + | [ a; b ] -> E.runtime_call Primitive_modules.bool "max" args + | _ -> assert false) + | Pintorder -> ( + match args with + | [ a; b ] -> E.runtime_call Primitive_modules.int "compare" args + | _ -> assert false) + | Pintmin -> ( + match args with + | [ { expression_desc = Number (Int _) } as a; { expression_desc = Number (Int _) } as b ] + when Js_analyzer.is_okay_to_duplicate a && Js_analyzer.is_okay_to_duplicate b -> + E.econd (E.js_comp Clt a b) a b + | [ a; b ] -> E.runtime_call Primitive_modules.int "min" args + | _ -> assert false) + | Pintmax -> ( match args with - | [ e; e1 ] -> Js_of_lam_string.ref_string e e1 + | [ { expression_desc = Number (Int _) } as a; { expression_desc = Number (Int _) } as b ] + when Js_analyzer.is_okay_to_duplicate a && Js_analyzer.is_okay_to_duplicate b -> + E.econd (E.js_comp Cgt a b) a b + | [ a; b ] -> E.runtime_call Primitive_modules.int "max" args + | _ -> assert false) + | Pfloatorder -> ( + match args with + | [ a; b ] as args -> + E.runtime_call Primitive_modules.float "compare" args + | _ -> assert false) + | Pfloatmin -> ( + match args with + | [ { expression_desc = Number (Float _) } as a; { expression_desc = Number (Float _) } as b ] + when Js_analyzer.is_okay_to_duplicate a && Js_analyzer.is_okay_to_duplicate b -> + E.econd (E.js_comp Clt a b) a b + | [ a; b ] -> E.runtime_call Primitive_modules.float "min" args + | _ -> assert false) + | Pfloatmax -> ( + match args with + | [ { expression_desc = Number (Float _) } as a; { expression_desc = Number (Float _) } as b ] + when Js_analyzer.is_okay_to_duplicate a && Js_analyzer.is_okay_to_duplicate b -> + E.econd (E.js_comp Cgt a b) a b + | [ a; b ] -> E.runtime_call Primitive_modules.float "max" args + | _ -> assert false) + | Pbigintorder -> ( + match args with + | [ a; b ] -> E.runtime_call Primitive_modules.bigint "compare" args + | _ -> assert false) + | Pbigintmin -> ( + match args with + | [ { expression_desc = Number (BigInt _) } as a; { expression_desc = Number (BigInt _) } as b ] + when Js_analyzer.is_okay_to_duplicate a && Js_analyzer.is_okay_to_duplicate b -> + E.econd (E.js_comp Clt a b) a b + | [ a; b ] -> E.runtime_call Primitive_modules.bigint "min" args + | _ -> assert false) + | Pbigintmax -> ( + match args with + | [ { expression_desc = Number (Float _) } as a; { expression_desc = Number (Float _) } as b ] + when Js_analyzer.is_okay_to_duplicate a && Js_analyzer.is_okay_to_duplicate b -> + E.econd (E.js_comp Cgt a b) a b + | [ a; b ] -> E.runtime_call Primitive_modules.bigint "max" args + | _ -> assert false) + | Pstringorder -> ( + match args with + | [ a; b ] -> E.runtime_call Primitive_modules.string "compare" args + | _ -> assert false) + | Pstringmin -> ( + match args with + | [ { expression_desc = Str _ } as a; { expression_desc = Str _ } as b ] + when Js_analyzer.is_okay_to_duplicate a && Js_analyzer.is_okay_to_duplicate b -> + E.econd (E.js_comp Clt a b) a b + | [a; b] -> E.runtime_call Primitive_modules.string "min" args + | _ -> assert false) + | Pstringmax -> ( + match args with + | [ { expression_desc = Str _ } as a; { expression_desc = Str _ } as b ] + when Js_analyzer.is_okay_to_duplicate a && Js_analyzer.is_okay_to_duplicate b -> + E.econd (E.js_comp Cgt a b) a b + | [a; b] -> E.runtime_call Primitive_modules.string "max" args | _ -> assert false) (* only when Lapply -> expand = true*) | Praise -> assert false (* handled before here *) @@ -352,16 +454,36 @@ let translate output_prefix loc (cxt : Lam_compile_context.t) match args with | [ e; e1 ] -> Js_of_lam_array.ref_array e e1 (* Todo: Constant Folding *) | _ -> assert false) - | Parrayrefs -> E.runtime_call Js_runtime_modules.array "get" args - | Parraysets -> E.runtime_call Js_runtime_modules.array "set" args + | Parrayrefs -> E.runtime_call Primitive_modules.array "get" args + | Parraysets -> E.runtime_call Primitive_modules.array "set" args | Pmakearray -> Js_of_lam_array.make_array Mutable args + | Pmakelist -> + Js_of_lam_block.make_block + (Js_op_util.of_lam_mutable_flag Mutable) + (Blk_constructor { name = "::"; num_nonconst = 1; tag = 0; attrs = [] }) + (E.small_int 0) + args + | Pmakedict -> ( + match args with + | [{expression_desc = Array (items, _)}] -> + E.obj + (items + |> List.filter_map (fun (exp : J.expression) -> + match exp.expression_desc with + | Caml_block ([{expression_desc = Str {txt}}; expr], _, _, _) -> + Some (Js_op.Lit txt, expr) + | _ -> None)) + | _ -> assert false) | Parraysetu -> ( match args with (* wrong*) | [ e; e0; e1 ] -> ensure_value_unit cxt.continuation (Js_of_lam_array.set_array e e0 e1) | _ -> assert false) - | Pccall prim -> Lam_dispatch_primitive.translate loc prim.prim_name args + | Pawait -> ( + match args with + | [e] -> {e with expression_desc = Await e} + | _ -> assert false) (* Lam_compile_external_call.translate loc cxt prim args *) (* Test if the argument is a block or an immediate integer *) | Pjs_object_create _ -> assert false @@ -370,31 +492,26 @@ let translate output_prefix loc (cxt : Lam_compile_context.t) (* FIXME, this can be removed later *) | Pisint -> E.is_type_number (Ext_list.singleton_exn args) | Pis_poly_var_block -> E.is_type_object (Ext_list.singleton_exn args) - | Pctconst ct -> ( - match ct with - | Big_endian -> E.bool Sys.big_endian - | Ostype -> E.runtime_call Js_runtime_modules.sys "os_type" args - | Ostype_unix -> - E.string_equal - (E.runtime_call Js_runtime_modules.sys "os_type" args) - (E.str "Unix") - | Ostype_win32 -> - E.string_equal - (E.runtime_call Js_runtime_modules.sys "os_type" args) - (E.str "Win32") - (* | Max_wosize -> - (* max_array_length*) - E.int 2147483647l (* 2 ^ 31 - 1 *) *) - (* 4_294_967_295l not representable*) - (* 2 ^ 32 - 1*) - | Backend_type -> - E.make_block E.zero_int_literal - (Blk_constructor { name = "Other"; num_nonconst = 1; tag = 0; attrs = [] }) - [ E.str "BS" ] Immutable) | Pduprecord -> ( match args with | [ e1 ] -> E.obj ~dup:e1 [] | _ -> assert false) + | Phash -> ( + match args with + | [ e1; e2; e3; e4 ] -> E.runtime_call Primitive_modules.hash "hash" args + | _ -> assert false) + | Phash_mixint -> ( + match args with + | [ e1; e2 ] -> E.runtime_call Primitive_modules.hash "hash_mix_int" args + | _ -> assert false) + | Phash_mixstring -> ( + match args with + | [ e1; e2 ] -> E.runtime_call Primitive_modules.hash "hash_mix_string" args + | _ -> assert false) + | Phash_finalmix -> ( + match args with + | [ e1 ] -> E.runtime_call Primitive_modules.hash "hash_final_mix" args + | _ -> assert false) | Plazyforce (* FIXME: we don't inline lazy force or at least let buckle handle it diff --git a/jscomp/core/lam_compile_util.ml b/jscomp/core/lam_compile_util.ml index e86e3f56f8..a2c3a48437 100644 --- a/jscomp/core/lam_compile_util.ml +++ b/jscomp/core/lam_compile_util.ml @@ -30,3 +30,12 @@ let jsop_of_comp (cmp : Lam_compat.comparison) : Js_op.binop = | Cgt -> Gt | Cle -> Le | Cge -> Ge + +let runtime_of_comp (cmp : Lam_compat.comparison) : string = + match cmp with + | Ceq -> "equal" + | Cneq -> "notequal" + | Clt -> "lessthan" + | Cgt -> "greaterthan" + | Cle -> "lessequal" + | Cge -> "greaterequal" diff --git a/jscomp/core/lam_compile_util.mli b/jscomp/core/lam_compile_util.mli index 2d1f091d3d..3b12a28ac9 100644 --- a/jscomp/core/lam_compile_util.mli +++ b/jscomp/core/lam_compile_util.mli @@ -25,3 +25,5 @@ (** Some utilities for lambda compilation*) val jsop_of_comp : Lam_compat.comparison -> Js_op.binop + +val runtime_of_comp : Lam_compat.comparison -> string diff --git a/jscomp/core/lam_constant_convert.ml b/jscomp/core/lam_constant_convert.ml index 91e2201a1d..7d1f1c5ce2 100644 --- a/jscomp/core/lam_constant_convert.ml +++ b/jscomp/core/lam_constant_convert.ml @@ -35,7 +35,7 @@ let rec convert_constant (const : Lambda.structured_constant) : Lam_constant.t = Const_string { s; unicode } | Const_base (Const_float i) -> Const_float i | Const_base (Const_int32 i) -> Const_int { i; comment = None } - | Const_base (Const_int64 i) -> Const_int64 i + | Const_base (Const_int64 _) -> assert false | Const_base (Const_bigint (sign, i)) -> Const_bigint (sign, i) | Const_pointer (0, Pt_constructor { name = "()"; const = 1; non_const = 0 }) -> @@ -60,7 +60,7 @@ let rec convert_constant (const : Lambda.structured_constant) : Lam_constant.t = Const_int { i = Ext_string.hash_number_as_i32_exn name; comment = None } else Const_pointer name) - | Const_float_array s -> Const_float_array s + | Const_float_array s -> assert false | Const_immstring s -> Const_string { s; unicode = false } | Const_block (t, xs) -> ( let tag = Lambda.tag_of_tag_info t in diff --git a/jscomp/core/lam_convert.ml b/jscomp/core/lam_convert.ml index adc645747f..40c0d1ca52 100644 --- a/jscomp/core/lam_convert.ml +++ b/jscomp/core/lam_convert.ml @@ -158,13 +158,22 @@ let unit = Lam.unit let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t = match p with | Pidentity -> Ext_list.singleton_exn args + | Pnull -> Lam.const Const_js_null + | Pundefined -> Lam.const (Const_js_undefined { is_unit = false }) | Pccall _ -> assert false | Prevapply -> assert false | Pdirapply -> assert false | Ploc _ -> assert false (* already compiled away here*) - | Pbytes_to_string (* handled very early *) -> - prim ~primitive:Pbytes_to_string ~args loc | Pcreate_extension s -> prim ~primitive:(Pcreate_extension s) ~args loc + | Pextension_slot_eq -> ( + match args with + | [ lhs; rhs ] -> + prim + ~primitive:(Pstringcomp Ceq) + ~args:[ lam_extension_id loc lhs; rhs ] + loc + | _ -> assert false) + | Pwrap_exn -> prim ~primitive:Pwrap_exn ~args loc | Pignore -> (* Pignore means return unit, it is not an nop *) seq (Ext_list.singleton_exn args) unit @@ -212,14 +221,35 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t = ~primitive:(Pmakeblock (tag, lazy_block_info, Mutable)) ~args loc | _ -> assert false)) + | Pfn_arity -> prim ~primitive:Pfn_arity ~args loc + | Pdebugger -> prim ~primitive:Pdebugger ~args loc + | Ptypeof -> prim ~primitive:Ptypeof ~args loc + | Pisnullable -> prim ~primitive:Pis_null_undefined ~args loc + | Pnull_to_opt -> prim ~primitive:Pnull_to_opt ~args loc + | Pnullable_to_opt -> prim ~primitive:Pnull_undefined_to_opt ~args loc + | Pundefined_to_opt -> prim ~primitive:Pundefined_to_opt ~args loc + | Pis_not_none -> prim ~primitive:Pis_not_none ~args loc + | Pval_from_option -> prim ~primitive:Pval_from_option ~args loc + | Pval_from_option_not_nest -> prim ~primitive:Pval_from_option_not_nest ~args loc + | Pjscomp x -> prim ~primitive:(Pjscomp x) ~args loc | Pfield (id, info) -> prim ~primitive:(Pfield (id, info)) ~args loc | Psetfield (id, info) -> prim ~primitive:(Psetfield (id, info)) ~args loc | Pduprecord -> prim ~primitive:Pduprecord ~args loc | Plazyforce -> prim ~primitive:Plazyforce ~args loc | Praise _ -> prim ~primitive:Praise ~args loc + | Pobjcomp x -> prim ~primitive:(Pobjcomp x) ~args loc + | Pobjorder -> prim ~primitive:Pobjorder ~args loc + | Pobjmin -> prim ~primitive:Pobjmin ~args loc + | Pobjmax -> prim ~primitive:Pobjmax ~args loc + | Pobjtag -> prim ~primitive:Pobjtag ~args loc + | Pobjsize -> prim ~primitive:Pobjsize ~args loc | Psequand -> prim ~primitive:Psequand ~args loc | Psequor -> prim ~primitive:Psequor ~args loc | Pnot -> prim ~primitive:Pnot ~args loc + | Pboolcomp x -> prim ~primitive:(Pboolcomp x) ~args loc + | Pboolorder -> prim ~primitive:Pboolorder ~args loc + | Pboolmin -> prim ~primitive:Pboolmin ~args loc + | Pboolmax -> prim ~primitive:Pboolmax ~args loc | Pnegint -> prim ~primitive:Pnegint ~args loc | Paddint -> prim ~primitive:Paddint ~args loc | Psubint -> prim ~primitive:Psubint ~args loc @@ -232,15 +262,18 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t = | Plslint -> prim ~primitive:Plslint ~args loc | Plsrint -> prim ~primitive:Plsrint ~args loc | Pasrint -> prim ~primitive:Pasrint ~args loc + | Pintorder -> prim ~primitive:Pintorder ~args loc + | Pintmin -> prim ~primitive:Pintmin ~args loc + | Pintmax -> prim ~primitive:Pintmax ~args loc | Pstringlength -> prim ~primitive:Pstringlength ~args loc | Pstringrefu -> prim ~primitive:Pstringrefu ~args loc + | Pstringcomp x -> prim ~primitive:(Pstringcomp x) ~args loc + | Pstringorder -> prim ~primitive:Pstringorder ~args loc + | Pstringmin -> prim ~primitive:Pstringmin ~args loc + | Pstringmax -> prim ~primitive:Pstringmax ~args loc + | Pstringadd -> prim ~primitive:Pstringadd ~args loc | Pabsfloat -> assert false | Pstringrefs -> prim ~primitive:Pstringrefs ~args loc - | Pbyteslength -> prim ~primitive:Pbyteslength ~args loc - | Pbytesrefu -> prim ~primitive:Pbytesrefu ~args loc - | Pbytessetu -> prim ~primitive:Pbytessetu ~args loc - | Pbytesrefs -> prim ~primitive:Pbytesrefs ~args loc - | Pbytessets -> prim ~primitive:Pbytessets ~args loc | Pisint -> prim ~primitive:Pisint ~args loc | Pisout -> ( match args with @@ -254,6 +287,10 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t = | Psubfloat -> prim ~primitive:Psubfloat ~args loc | Pmulfloat -> prim ~primitive:Pmulfloat ~args loc | Pdivfloat -> prim ~primitive:Pdivfloat ~args loc + | Pmodfloat -> prim ~primitive:Pmodfloat ~args loc + | Pfloatorder -> prim ~primitive:Pfloatorder ~args loc + | Pfloatmin -> prim ~primitive:Pfloatmin ~args loc + | Pfloatmax -> prim ~primitive:Pfloatmax ~args loc | Pnegbigint -> prim ~primitive:Pnegbigint ~args loc | Paddbigint -> prim ~primitive:Paddbigint ~args loc | Psubbigint -> prim ~primitive:Psubbigint ~args loc @@ -267,6 +304,9 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t = | Plslbigint -> prim ~primitive:Plslbigint ~args loc | Pasrbigint -> prim ~primitive:Pasrbigint ~args loc | Pbigintcomp x -> prim ~primitive:(Pbigintcomp x) ~args loc + | Pbigintorder -> prim ~primitive:Pbigintorder ~args loc + | Pbigintmin -> prim ~primitive:Pbigintorder ~args loc + | Pbigintmax -> prim ~primitive:Pbigintorder ~args loc | Pintcomp x -> prim ~primitive:(Pintcomp x) ~args loc | Poffsetint x -> prim ~primitive:(Poffsetint x) ~args loc | Poffsetref x -> prim ~primitive:(Poffsetref x) ~args loc @@ -277,83 +317,36 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t = | Parraysetu -> prim ~primitive:Parraysetu ~args loc | Parrayrefs -> prim ~primitive:Parrayrefs ~args loc | Parraysets -> prim ~primitive:Parraysets ~args loc - | Pbintofint x -> ( - match x with - | Pint32 | Pbigint -> Ext_list.singleton_exn args - | Pint64 -> prim ~primitive:Pint64ofint ~args loc) - | Pintofbint x -> ( - match x with - | Pint32 | Pbigint -> Ext_list.singleton_exn args - | Pint64 -> prim ~primitive:Pintofint64 ~args loc) - | Pnegbint x -> ( - match x with - | Pbigint | Pint32 -> prim ~primitive:Pnegint ~args loc - | Pint64 -> prim ~primitive:Pnegint64 ~args loc) - | Paddbint x -> ( - match x with - | Pbigint | Pint32 -> prim ~primitive:Paddint ~args loc - | Pint64 -> prim ~primitive:Paddint64 ~args loc) - | Psubbint x -> ( - match x with - | Pbigint | Pint32 -> prim ~primitive:Psubint ~args loc - | Pint64 -> prim ~primitive:Psubint64 ~args loc) - | Pmulbint x -> ( - match x with - | Pbigint | Pint32 -> prim ~primitive:Pmulint ~args loc - | Pint64 -> prim ~primitive:Pmulint64 ~args loc) - | Pdivbint { size = x; is_safe = _ } (*FIXME*) -> ( - match x with - | Pbigint | Pint32 -> prim ~primitive:Pdivint ~args loc - | Pint64 -> prim ~primitive:Pdivint64 ~args loc) - | Pmodbint { size = x; is_safe = _ } (*FIXME*) -> ( - match x with - | Pbigint | Pint32 -> prim ~primitive:Pmodint ~args loc - | Pint64 -> prim ~primitive:Pmodint64 ~args loc) - | Pandbint x -> ( - match x with - | Pbigint | Pint32 -> prim ~primitive:Pandint ~args loc - | Pint64 -> prim ~primitive:Pandint64 ~args loc) - | Porbint x -> ( - match x with - | Pbigint | Pint32 -> prim ~primitive:Porint ~args loc - | Pint64 -> prim ~primitive:Porint64 ~args loc) - | Pxorbint x -> ( - match x with - | Pbigint | Pint32 -> prim ~primitive:Pxorint ~args loc - | Pint64 -> prim ~primitive:Pxorint64 ~args loc) - | Plslbint x -> ( - match x with - | Pbigint | Pint32 -> prim ~primitive:Plslint ~args loc - | Pint64 -> prim ~primitive:Plslint64 ~args loc) - | Plsrbint x -> ( - match x with - | Pbigint | Pint32 -> prim ~primitive:Plsrint ~args loc - | Pint64 -> prim ~primitive:Plsrint64 ~args loc) - | Pasrbint x -> ( - match x with - | Pbigint | Pint32 -> prim ~primitive:Pasrint ~args loc - | Pint64 -> prim ~primitive:Pasrint64 ~args loc) - | Pctconst x -> ( - match x with - | Word_size | Int_size -> - Lam.const (Const_int { i = 32l; comment = None }) - | Max_wosize -> - Lam.const (Const_int { i = 2147483647l; comment = Some "Max_wosize" }) - | Big_endian -> prim ~primitive:(Pctconst Big_endian) ~args loc - | Ostype_unix -> prim ~primitive:(Pctconst Ostype_unix) ~args loc - | Ostype_win32 -> prim ~primitive:(Pctconst Ostype_win32) ~args loc - | Ostype_cygwin -> Lam.false_ - | Backend_type -> prim ~primitive:(Pctconst Backend_type) ~args loc) - | Pcvtbint (a, b) -> ( - match (a, b) with - | (Pbigint | Pint32), (Pbigint | Pint32) | Pint64, Pint64 -> - Ext_list.singleton_exn args - | Pint64, (Pbigint | Pint32) -> prim ~primitive:Pintofint64 ~args loc - | (Pbigint | Pint32), Pint64 -> prim ~primitive:Pint64ofint ~args loc) - | Pbintcomp (a, b) -> ( - match a with - | Pbigint | Pint32 -> prim ~primitive:(Pintcomp b) ~args loc - | Pint64 -> prim ~primitive:(Pint64comp b) ~args loc) + | Pmakelist _mutable_flag (*FIXME*) -> prim ~primitive:Pmakelist ~args loc + | Pmakedict -> prim ~primitive:Pmakedict ~args loc + | Pawait -> prim ~primitive:Pawait ~args loc + | Pimport -> prim ~primitive:Pimport ~args loc + | Pinit_mod -> ( + match args with + | [ _loc; Lconst (Const_block (0, _, [ Const_block (0, _, []) ])) ] -> + Lam.unit + | _ -> prim ~primitive:Pinit_mod ~args loc) + | Pupdate_mod -> ( + match args with + | [ Lconst (Const_block (0, _, [ Const_block (0, _, []) ])); _; _ ] -> + Lam.unit + | _ -> prim ~primitive:Pupdate_mod ~args loc) + | Phash -> prim ~primitive:Phash ~args loc + | Phash_mixint -> prim ~primitive:Phash_mixint ~args loc + | Phash_mixstring -> prim ~primitive:Phash_mixstring ~args loc + | Phash_finalmix -> prim ~primitive:Phash_finalmix ~args loc + | Pcurry_apply _ -> prim ~primitive:Pjs_apply ~args loc + | Pis_poly_var_block -> prim ~primitive:Pis_poly_var_block ~args loc + | Pjs_raw_expr -> assert false + | Pjs_raw_stmt -> assert false + | Pjs_fn_make arity -> prim ~primitive:(Pjs_fn_make arity) ~args loc + | Pjs_fn_make_unit -> prim ~primitive:Pjs_fn_make_unit ~args loc + | Pjs_fn_method -> prim ~primitive:Pjs_fn_method ~args loc + | Pjs_unsafe_downgrade -> + let primitive: Lam_primitive.t = + Pjs_unsafe_downgrade { name = Ext_string.empty; setter = false } + in + prim ~primitive ~args loc (* Does not exist since we compile array in js backend unlike native backend *) @@ -394,14 +387,7 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) : let rec convert_ccall (a_prim : Primitive.description) (args : Lambda.lambda list) loc ~dynamic_import : Lam.t = let prim_name = a_prim.prim_name in - let prim_name_len = String.length prim_name in match External_ffi_types.from_string a_prim.prim_native_name with - | Ffi_normal -> - if prim_name_len > 0 && String.unsafe_get prim_name 0 = '#' then - convert_js_primitive a_prim args loc - else - let args = Ext_list.map args convert_aux in - prim ~primitive:(Pccall { prim_name }) ~args loc | Ffi_obj_create labels -> let args = Ext_list.map args convert_aux in prim ~primitive:(Pjs_object_create labels) ~args loc @@ -414,112 +400,11 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) : let args = Ext_list.map args convert_aux in Lam.handle_bs_non_obj_ffi arg_types result_type ffi args loc prim_name ~dynamic_import | Ffi_inline_const i -> Lam.const i - and convert_js_primitive (p : Primitive.description) - (args : Lambda.lambda list) loc : Lam.t = - let s = p.prim_name in - match () with - | _ when s = "#is_not_none" -> - prim ~primitive:Pis_not_none ~args:(Ext_list.map args convert_aux) loc - | _ when s = "#val_from_unnest_option" -> - let v = convert_aux (Ext_list.singleton_exn args) in - prim ~primitive:Pval_from_option_not_nest ~args:[ v ] loc - | _ when s = "#val_from_option" -> - prim ~primitive:Pval_from_option - ~args:(Ext_list.map args convert_aux) - loc - | _ when s = "#is_poly_var_block" -> - prim ~primitive:Pis_poly_var_block - ~args:(Ext_list.map args convert_aux) - loc - | _ when s = "#raw_expr" -> ( - match args with - | [ Lconst (Const_base (Const_string (code, _))) ] -> - (* js parsing here *) - let kind = Classify_function.classify code in - prim - ~primitive:(Praw_js_code { code; code_info = Exp kind }) - ~args:[] loc - | _ -> assert false) - | _ when s = "#raw_stmt" -> ( - match args with - | [ Lconst (Const_base (Const_string (code, _))) ] -> - let kind = Classify_function.classify_stmt code in - prim - ~primitive:(Praw_js_code { code; code_info = Stmt kind }) - ~args:[] loc - | _ -> assert false) - | _ when s = "#debugger" -> - (* ATT: Currently, the arity is one due to PPX *) - prim ~primitive:Pdebugger ~args:[] loc - | _ when s = "#null" -> Lam.const Const_js_null - | _ when s = "#os_type" -> - prim ~primitive:(Pctconst Ostype) ~args:[ unit ] loc - | _ when s = "#undefined" -> Lam.const (Const_js_undefined {is_unit = false}) - | _ when s = "#init_mod" -> ( - let args = Ext_list.map args convert_aux in - match args with - | [ _loc; Lconst (Const_block (0, _, [ Const_block (0, _, []) ])) ] -> - Lam.unit - | _ -> prim ~primitive:Pinit_mod ~args loc) - | _ when s = "#update_mod" -> ( - let args = Ext_list.map args convert_aux in - match args with - | [ Lconst (Const_block (0, _, [ Const_block (0, _, []) ])); _; _ ] -> - Lam.unit - | _ -> prim ~primitive:Pupdate_mod ~args loc) - | _ when s = "#extension_slot_eq" -> ( - match Ext_list.map args convert_aux with - | [ lhs; rhs ] -> - prim - ~primitive:(Pccall { prim_name = "caml_string_equal" }) - ~args:[ lam_extension_id loc lhs; rhs ] - loc - | _ -> assert false) - | _ -> - let primitive : Lam_primitive.t = - match s with - | "#apply" -> Pjs_runtime_apply - | "#apply1" | "#apply2" | "#apply3" | "#apply4" | "#apply5" - | "#apply6" | "#apply7" | "#apply8" -> - Pjs_apply - | "#makemutablelist" -> - Pmakeblock - ( 0, - Blk_constructor { name = "::"; num_nonconst = 1; tag = 0; attrs = [] }, - Mutable ) - | "#undefined_to_opt" -> Pundefined_to_opt - | "#nullable_to_opt" -> Pnull_undefined_to_opt - | "#null_to_opt" -> Pnull_to_opt - | "#is_nullable" -> Pis_null_undefined - | "#import" ->Pimport - | "#string_append" -> Pstringadd - | "#wrap_exn" -> Pwrap_exn - | "#obj_length" -> Pcaml_obj_length - | "#function_length" -> Pjs_function_length - | "#unsafe_lt" -> Pjscomp Clt - | "#unsafe_gt" -> Pjscomp Cgt - | "#unsafe_le" -> Pjscomp Cle - | "#unsafe_ge" -> Pjscomp Cge - | "#unsafe_eq" -> Pjscomp Ceq - | "#unsafe_neq" -> Pjscomp Cneq - | "#typeof" -> Pjs_typeof - | "#run" -> Pvoid_run - | "#fn_mk" -> - Pjs_fn_make (Ext_pervasives.nat_of_string_exn p.prim_native_name) - | "#fn_mk_unit" -> - Pjs_fn_make_unit - | "#fn_method" -> Pjs_fn_method - | "#unsafe_downgrade" -> - Pjs_unsafe_downgrade { name = Ext_string.empty; setter = false } - | _ -> - Location.raise_errorf ~loc - "@{Error:@} internal error, using unrecognized \ - primitive %s" - s - in - let dynamic_import = primitive = Pimport in - let args = Ext_list.map args (convert_aux ~dynamic_import) in - prim ~primitive ~args loc + | Ffi_normal -> Location.raise_errorf ~loc + "@{Error:@} internal error, using unrecognized \ + primitive %s" + prim_name + and convert_aux ?(dynamic_import = false) (lam : Lambda.lambda) : Lam.t = match lam with | Lvar x -> Lam.var (Hash_ident.find_default alias_tbl x x) @@ -573,6 +458,23 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) : | Lprim (Prevapply, _, _) -> assert false | Lprim (Pdirapply, _, _) -> assert false | Lprim (Pccall a, args, loc) -> convert_ccall a args loc ~dynamic_import + | Lprim (Pjs_raw_expr, args, loc) -> ( + match args with + | [ Lconst (Const_base (Const_string (code, _))) ] -> + (* js parsing here *) + let kind = Classify_function.classify code in + prim + ~primitive:(Praw_js_code { code; code_info = Exp kind }) + ~args:[] loc + | _ -> assert false) + | Lprim(Pjs_raw_stmt, args, loc) -> ( + match args with + | [ Lconst (Const_base (Const_string (code, _))) ] -> + let kind = Classify_function.classify_stmt code in + prim + ~primitive:(Praw_js_code { code; code_info = Stmt kind }) + ~args:[] loc + | _ -> assert false) | Lprim (Pgetglobal id, args, _) -> let args = Ext_list.map args convert_aux in if Ident.is_predef_exn id then @@ -581,6 +483,9 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) : may_depend may_depends (Lam_module_ident.of_ml ~dynamic_import id); assert (args = []); Lam.global_module ~dynamic_import id) + | Lprim (Pimport, args, loc) -> + let args = Ext_list.map args (convert_aux ~dynamic_import:true) in + lam_prim ~primitive:Pimport ~args loc | Lprim (primitive, args, loc) -> let args = Ext_list.map args (convert_aux ~dynamic_import) in lam_prim ~primitive ~args loc diff --git a/jscomp/core/lam_dispatch_primitive.ml b/jscomp/core/lam_dispatch_primitive.ml deleted file mode 100644 index 4b72174275..0000000000 --- a/jscomp/core/lam_dispatch_primitive.ml +++ /dev/null @@ -1,279 +0,0 @@ -(* Copyright (C) 2015 - 2016 Bloomberg Finance L.P. - * Copyright (C) 2017 - Hongbo Zhang, Authors of ReScript - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -module E = Js_exp_make -(* module S = Js_stmt_make *) - -(** - There are two things we need consider: - 1. For some primitives we can replace caml-primitive with js primitives directly - 2. For some standard library functions, we prefer to replace with javascript primitives - For example [Pervasives["^"] -> ^] - We can collect all mli files in OCaml and replace it with an efficient javascript runtime - - TODO: return type to be expression is ugly, - we should allow return block -*) -let translate loc (prim_name : string) (args : J.expression list) : J.expression - = - let[@inline] call ?name m = - let name = - match name with - | None -> - if prim_name.[0] = '?' then - String.sub prim_name 1 (String.length prim_name - 1) - else if Ext_string.starts_with prim_name "caml_" then - String.sub prim_name 5 (String.length prim_name - 5) - else assert false (* prim_name *) - | Some x -> x - in - E.runtime_call m name args - in - match prim_name with - | "caml_notequal" -> ( - match args with - | [ a1; b1 ] - when E.for_sure_js_null_undefined a1 || E.for_sure_js_null_undefined b1 - -> - E.neq_null_undefined_boolean a1 b1 - (* FIXME address_equal *) - | _ -> - Location.prerr_warning loc Warnings.Bs_polymorphic_comparison; - call Js_runtime_modules.obj_runtime) - | "caml_equal" -> ( - match args with - | [ a1; b1 ] - when E.for_sure_js_null_undefined a1 || E.for_sure_js_null_undefined b1 - -> - E.eq_null_undefined_boolean a1 b1 - (* FIXME address_equal *) - | _ -> - Location.prerr_warning loc Warnings.Bs_polymorphic_comparison; - call Js_runtime_modules.obj_runtime) - | "caml_min" | "caml_max" | "caml_compare" | "caml_greaterequal" - | "caml_greaterthan" | "caml_lessequal" | "caml_lessthan" | "caml_equal_null" - | "caml_equal_undefined" | "caml_equal_nullable" -> - Location.prerr_warning loc Warnings.Bs_polymorphic_comparison; - call Js_runtime_modules.obj_runtime - (* generated by the compiler, not user facing *) - | "caml_bytes_greaterthan" | "caml_bytes_greaterequal" | "caml_bytes_lessthan" - | "caml_bytes_lessequal" | "caml_bytes_compare" | "caml_bytes_equal" -> - call Js_runtime_modules.bytes - | "caml_string_equal" -> ( - match args with [ e0; e1 ] -> E.string_equal e0 e1 | _ -> assert false) - | "caml_string_notequal" -> ( - match args with - | [ e0; e1 ] -> E.string_comp NotEqEq e0 e1 - (* TODO: convert to ocaml ones*) - | _ -> assert false) - | "caml_string_lessequal" -> ( - match args with [ e0; e1 ] -> E.string_comp Le e0 e1 | _ -> assert false) - | "caml_string_lessthan" -> ( - match args with [ e0; e1 ] -> E.string_comp Lt e0 e1 | _ -> assert false) - | "caml_string_greaterequal" -> ( - match args with [ e0; e1 ] -> E.string_comp Ge e0 e1 | _ -> assert false) - | "caml_int64_equal_null" -> Js_long.equal_null args - | "caml_int64_equal_undefined" -> Js_long.equal_undefined args - | "caml_int64_equal_nullable" -> Js_long.equal_nullable args - | "caml_int64_min" -> Js_long.min args - | "caml_int64_max" -> Js_long.max args - | "caml_int64_compare" -> Js_long.compare args - | "caml_string_greaterthan" -> ( - match args with [ e0; e1 ] -> E.string_comp Gt e0 e1 | _ -> assert false) - | "caml_bool_notequal" -> ( - match args with - | [ e0; e1 ] -> E.bool_comp Cneq e0 e1 - (* TODO: specialized in OCaml ones*) - | _ -> assert false) - | "caml_bool_lessequal" -> ( - match args with [ e0; e1 ] -> E.bool_comp Cle e0 e1 | _ -> assert false) - | "caml_bool_lessthan" -> ( - match args with [ e0; e1 ] -> E.bool_comp Clt e0 e1 | _ -> assert false) - | "caml_bool_greaterequal" -> ( - match args with [ e0; e1 ] -> E.bool_comp Cge e0 e1 | _ -> assert false) - | "caml_bool_greaterthan" -> ( - match args with [ e0; e1 ] -> E.bool_comp Cgt e0 e1 | _ -> assert false) - | "caml_bool_equal" | "caml_bool_equal_null" | "caml_bool_equal_nullable" - | "caml_bool_equal_undefined" -> ( - match args with [ e0; e1 ] -> E.bool_comp Ceq e0 e1 | _ -> assert false) - | "caml_int_equal_null" | "caml_int_equal_nullable" - | "caml_int_equal_undefined" -> ( - match args with [ e0; e1 ] -> E.int_comp Ceq e0 e1 | _ -> assert false) - | "caml_float_equal_null" | "caml_float_equal_nullable" - | "caml_float_equal_undefined" -> ( - match args with [ e0; e1 ] -> E.float_comp Ceq e0 e1 | _ -> assert false) - | "caml_bigint_equal_null" | "caml_bigint_equal_nullable" - | "caml_bigint_equal_undefined" -> ( - match args with [ e0; e1 ] -> E.bigint_comp Ceq e0 e1 | _ -> assert false) - | "caml_string_equal_null" | "caml_string_equal_nullable" - | "caml_string_equal_undefined" -> ( - match args with - | [ e0; e1 ] -> E.string_comp EqEqEq e0 e1 - | _ -> assert false) - | "caml_bool_compare" -> ( - match args with - | [ { expression_desc = Bool a }; { expression_desc = Bool b } ] -> - let c = compare (a : bool) b in - E.int (if c = 0 then 0l else if c > 0 then 1l else -1l) - | _ -> call Js_runtime_modules.caml_primitive) - | "caml_int_compare" -> - E.runtime_call Js_runtime_modules.caml_primitive "int_compare" args - | "caml_float_compare" -> call Js_runtime_modules.caml_primitive - | "caml_bigint_compare" -> call Js_runtime_modules.caml_primitive - | "caml_string_compare" -> call Js_runtime_modules.caml_primitive - | "caml_bool_min" | "caml_int_min" | "caml_float_min" | "caml_bigint_min" | "caml_string_min" -> ( - match args with - | [ a; b ] -> - if - Js_analyzer.is_okay_to_duplicate a - && Js_analyzer.is_okay_to_duplicate b - then E.econd (E.js_comp Clt a b) a b - else call Js_runtime_modules.caml_primitive - | _ -> assert false) - | "caml_bool_max" | "caml_int_max" | "caml_float_max" | "caml_bigint_max" | "caml_string_max" -> ( - match args with - | [ a; b ] -> - if - Js_analyzer.is_okay_to_duplicate a - && Js_analyzer.is_okay_to_duplicate b - then E.econd (E.js_comp Cgt a b) a b - else call Js_runtime_modules.caml_primitive - | _ -> assert false) - (******************************************************************************) - (************************* customized primitives ******************************) - (******************************************************************************) - | "?int_of_float" -> ( - match args with [ e ] -> E.to_int32 e | _ -> assert false) - | "?int64_succ" -> E.runtime_call Js_runtime_modules.int64 "succ" args - | "?int64_to_string" -> - E.runtime_call Js_runtime_modules.int64 "to_string" args - | "?int64_to_float" -> Js_long.to_float args - | "?int64_of_float" -> Js_long.of_float args - | "?int64_bits_of_float" -> Js_long.bits_of_float args - | "?int64_float_of_bits" -> Js_long.float_of_bits args - | "?int_float_of_bits" | "?int_bits_of_float" | "?modf_float" | "?ldexp_float" - | "?frexp_float" | "?copysign_float" | "?expm1_float" | "?hypot_float" -> - call Js_runtime_modules.float - | "?fmod_float" (* float module like js number module *) -> ( - match args with [ e0; e1 ] -> E.float_mod e0 e1 | _ -> assert false) - | "?string_repeat" -> ( - match args with - | [ n; { expression_desc = Number (Int { i }) } ] -> ( - let str = String.make 1 (Char.chr (Int32.to_int i)) in - match n.expression_desc with - | Number (Int { i = 1l }) -> E.str str - | _ -> - E.call - (E.dot (E.str str) "repeat") - [ n ] ~info:Js_call_info.builtin_runtime_call) - | _ -> E.runtime_call Js_runtime_modules.string "make" args) - | "?create_bytes" -> ( - (* Bytes.create *) - (* Note that for invalid range, JS raise an Exception RangeError, - here in OCaml it's [Invalid_argument], we have to preserve this semantics. - Also, it's creating a [bytes] which is a js array actually. - *) - match args with - | [ { expression_desc = Number (Int { i; _ }); _ } ] when i < 8l -> - (*Invariants: assuming bytes are [int array]*) - E.array NA - (if i = 0l then [] - else Ext_list.init (Int32.to_int i) (fun _ -> E.zero_int_literal)) - | _ -> E.runtime_call Js_runtime_modules.bytes "create" args) - (* Note we captured [exception/extension] creation in the early pass, this primitive is - like normal one to set the identifier *) - | "?exn_slot_name" | "?is_extension" -> call Js_runtime_modules.exceptions - | "?as_js_exn" -> call Js_runtime_modules.caml_js_exceptions - | "?sys_get_argv" | "?sys_file_exists" | "?sys_time" | "?sys_getenv" - | "?sys_getcwd" (* check browser or nodejs *) - | "?sys_is_directory" | "?sys_exit" -> - call Js_runtime_modules.sys - | "?lex_engine" | "?new_lex_engine" -> call Js_runtime_modules.lexer - | "?parse_engine" | "?set_parser_trace" -> call Js_runtime_modules.parser - | "?make_float_vect" - | "?floatarray_create" (* TODO: compile float array into TypedArray*) -> - E.runtime_call Js_runtime_modules.array "make_float" args - | "?array_sub" -> E.runtime_call Js_runtime_modules.array "sub" args - | "?array_concat" -> E.runtime_call Js_runtime_modules.array "concat" args - (*external concat: 'a array list -> 'a array - Not good for inline *) - | "?array_blit" -> E.runtime_call Js_runtime_modules.array "blit" args - | "?make_vect" -> E.runtime_call Js_runtime_modules.array "make" args - | "?format_float" | "?hexstring_of_float" | "?float_of_string" - | "?int_of_string" (* what is the semantics?*) - | "?int64_format" | "?int64_of_string" | "?format_int" -> - call Js_runtime_modules.format - | "?obj_tag" -> ( - (* Note that in ocaml, [int] has tag [1000] and [string] has tag [252] - also now we need do nullary check - *) - match args with [ e ] -> E.tag e | _ -> assert false) - | "?md5_string" -> call Js_runtime_modules.md5 - | "?hash_mix_string" | "?hash_mix_int" | "?hash_final_mix" -> - call Js_runtime_modules.hash_primitive - | "?hash" -> call Js_runtime_modules.hash - | "?nativeint_add" -> ( - match args with - | [ e1; e2 ] -> E.unchecked_int32_add e1 e2 - | _ -> assert false) - | "?nativeint_div" -> ( - match args with - | [ e1; e2 ] -> E.int32_div e1 e2 ~checked:false - | _ -> assert false) - | "?nativeint_mod" -> ( - match args with - | [ e1; e2 ] -> E.int32_mod e1 e2 ~checked:false - | _ -> assert false) - | "?nativeint_lsr" -> ( - match args with [ e1; e2 ] -> E.int32_lsr e1 e2 | _ -> assert false) - | "?nativeint_mul" -> ( - match args with - | [ e1; e2 ] -> E.unchecked_int32_mul e1 e2 - | _ -> assert false) - | "?bigint_div" -> ( - match args with - | [ e1; e2 ] -> E.bigint_div e1 e2 ~checked:false - | _ -> assert false) - | "?bigint_mod" -> ( - match args with - | [ e1; e2 ] -> E.bigint_mod e1 e2 ~checked:false - | _ -> assert false) - | "?await" -> ( - match args with - | [e] -> {e with expression_desc = Await e} - | _ -> assert false) - | "?create_dict" -> ( - match args with - | [{expression_desc = Array (items, _)}] -> - E.obj - (items - |> List.filter_map (fun (exp : J.expression) -> - match exp.expression_desc with - | Caml_block ([{expression_desc = Str {txt}}; expr], _, _, _) -> - Some (Js_op.Lit txt, expr) - | _ -> None)) - | _ -> assert false) - | missing_impl -> - let msg = Warnings.message (Bs_unimplemented_primitive missing_impl) in - Location.raise_errorf ~loc "%s" msg diff --git a/jscomp/core/lam_eta_conversion.ml b/jscomp/core/lam_eta_conversion.ml index 8f977b3062..50ec2e8357 100644 --- a/jscomp/core/lam_eta_conversion.ml +++ b/jscomp/core/lam_eta_conversion.ml @@ -43,7 +43,7 @@ let transform_under_supply n ap_info fn args = | Lvar _ | Lconst ( Const_int _ | Const_char _ | Const_string _ | Const_float _ | Const_bigint _ - | Const_int64 _ | Const_pointer _ | Const_js_true | Const_js_false + | Const_pointer _ | Const_js_true | Const_js_false | Const_js_undefined _ ) | Lprim { primitive = Pfield (_, Fld_module _); _ } | Lfunction _ -> diff --git a/jscomp/core/lam_pass_lets_dce.ml b/jscomp/core/lam_pass_lets_dce.ml index 7f3c399007..0833c8f73a 100644 --- a/jscomp/core/lam_pass_lets_dce.ml +++ b/jscomp/core/lam_pass_lets_dce.ml @@ -189,31 +189,6 @@ let lets_helper (count_var : Ident.t -> Lam_pass_count.used_info) lam : Lam.t = Lam.const (Const_string { s = l_s^r_s; unicode = false }) end end - - | Lprim {primitive = (Pstringrefu|Pstringrefs) as primitive ; - args = [l;r] ; loc - } -> (* TODO: introudce new constant *) - let l' = simplif l in - let r' = simplif r in - let opt_l = - match l' with - | Lconst (Const_string { s = ls; unicode = false }) -> - Some ls - | Lvar i -> Hash_ident.find_opt string_table i - | _ -> None in - begin match opt_l with - | None -> Lam.prim ~primitive ~args:[l';r'] loc - | Some l_s -> - match r with - |Lconst((Const_int {i})) -> - let i = Int32.to_int i in - if i < String.length l_s && i >= 0 then - Lam.const ((Const_char (Char.code l_s.[i]))) - else - Lam.prim ~primitive ~args:[l';r'] loc - | _ -> - Lam.prim ~primitive ~args:[l';r'] loc - end | Lglobal_module _ -> lam | Lprim {primitive; args; loc} -> Lam.prim ~primitive ~args:(Ext_list.map args simplif) loc diff --git a/jscomp/core/lam_pass_remove_alias.ml b/jscomp/core/lam_pass_remove_alias.ml index e0cfa65fe7..47f5385d66 100644 --- a/jscomp/core/lam_pass_remove_alias.ml +++ b/jscomp/core/lam_pass_remove_alias.ml @@ -64,49 +64,6 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t = | Some (OptionalBlock (l, _)) -> l | _ -> if p = Pval_from_option_not_nest then lvar else x) | Lglobal_module _ -> lam - | Lprim { primitive = Pfull_apply; args = Lvar v :: ap_args as args; loc } - -> ( - (* Inline uncurried application when safe *) - let normal () = - Lam.prim ~primitive:Pfull_apply ~args:(Ext_list.map args simpl) loc - in - let ap_args = Ext_list.map ap_args simpl in - match Hash_ident.find_opt meta.ident_tbl v with - | Some - (FunctionId - { - lambda = - Some - ( Lfunction - ({ params; body; attr = { is_a_functor = false } } as m), - rec_flag ); - }) - when Ext_list.same_length ap_args params - && Lam_analysis.lfunction_can_be_inlined m - && Lam_analysis.ok_to_inline_fun_when_app m ap_args -> ( - let param_map = - Lam_closure.is_closed_with_map meta.export_idents params body - in - let is_export_id = Set_ident.mem meta.export_idents v in - match (is_export_id, param_map) with - | false, (_, param_map) | true, (true, param_map) -> ( - match rec_flag with - | Lam_rec -> - Lam_beta_reduce.propagate_beta_reduce_with_map meta - param_map params body ap_args - | Lam_self_rec -> normal () - | Lam_non_rec -> - if - Ext_list.exists ap_args (fun lam -> - Lam_hit.hit_variable v lam) - (*avoid nontermination, e.g, `g(g)`*) - then normal () - else - simpl - (Lam_beta_reduce.propagate_beta_reduce_with_map meta - param_map params body ap_args)) - | _ -> normal ()) - | _ -> normal ()) | Lprim { primitive; args; loc } -> Lam.prim ~primitive ~args:(Ext_list.map args simpl) loc | Lifthenelse diff --git a/jscomp/core/lam_primitive.ml b/jscomp/core/lam_primitive.ml index 3280a095d0..dca75bce3c 100644 --- a/jscomp/core/lam_primitive.ml +++ b/jscomp/core/lam_primitive.ml @@ -33,17 +33,18 @@ type record_representation = (* Inlined record under extension *) type t = - | Pbytes_to_string (* Operations on heap blocks *) | Pmakeblock of int * Lam_tag_info.t * Asttypes.mutable_flag | Pfield of int * Lam_compat.field_dbg_info | Psetfield of int * Lam_compat.set_field_dbg_info + (* could have field info at least for record *) | Pduprecord + (* Force lazy values *) | Plazyforce + (* External call *) - | Pccall of { prim_name : string } | Pjs_call of { prim_name : string; arg_types : External_arg_spec.params; @@ -51,13 +52,29 @@ type t = dynamic_import: bool; } | Pjs_object_create of External_arg_spec.obj_params + (* Exceptions *) | Praise - (* Boolean operations *) + + (* object primitives *) + | Pobjcomp of Lam_compat.comparison + | Pobjorder + | Pobjmin + | Pobjmax + | Pobjtag + | Pobjsize + + (* Boolean primitives *) | Psequand | Psequor | Pnot - (* Integer operations *) + | Pboolcomp of Lam_compat.comparison + | Pboolorder + | Pboolmin + | Pboolmax + + (* Integer primitives *) + | Pisint | Pnegint | Paddint | Psubint @@ -72,7 +89,12 @@ type t = | Pasrint | Poffsetint of int | Poffsetref of int - (* Float operations *) + | Pintcomp of Lam_compat.comparison + | Pintorder + | Pintmin + | Pintmax + + (* Float primitives *) | Pintoffloat | Pfloatofint | Pnegfloat @@ -80,6 +102,12 @@ type t = | Psubfloat | Pmulfloat | Pdivfloat + | Pmodfloat + | Pfloatcomp of Lam_compat.comparison + | Pfloatorder + | Pfloatmin + | Pfloatmax + (* BigInt operations *) | Pnegbigint | Paddbigint @@ -93,51 +121,44 @@ type t = | Pxorbigint | Plslbigint | Pasrbigint - | Pintcomp of Lam_compat.comparison - | Pfloatcomp of Lam_compat.comparison - | Pjscomp of Lam_compat.comparison - | Pint64comp of Lam_compat.comparison | Pbigintcomp of Lam_compat.comparison - | Pjs_apply (*[f;arg0;arg1; arg2; ... argN]*) - | Pjs_runtime_apply (* [f; [...]] *) - (* String operations *) + | Pbigintorder + | Pbigintmin + | Pbigintmax + + (* String primitives *) | Pstringlength | Pstringrefu | Pstringrefs | Pstringadd - | Pbyteslength - | Pbytesrefu - | Pbytessetu - | Pbytesrefs - | Pbytessets - (* Array operations *) + | Pstringcomp of Lam_compat.comparison + | Pstringorder + | Pstringmin + | Pstringmax + + (* Array primitives *) | Pmakearray | Parraylength | Parrayrefu | Parraysetu | Parrayrefs | Parraysets - (* Test if the argument is a block or an immediate integer *) - | Pisint + + (* List primitives *) + | Pmakelist + + (* dict primitives *) + | Pmakedict + + (* promise *) + | Pawait + + (* etc or deprecated *) | Pis_poly_var_block - (* Test if the (integer) argument is outside an interval *) | Pisout of int - | Pint64ofint - | Pintofint64 - | Pnegint64 - | Paddint64 - | Psubint64 - | Pmulint64 - | Pdivint64 - | Pmodint64 - | Pandint64 - | Porint64 - | Pxorint64 - | Plslint64 - | Plsrint64 - | Pasrint64 - (* Compile time constants *) - | Pctconst of Lam_compat.compile_time_constant (* Integer to external pointer *) + | Pjscomp of Lam_compat.comparison + | Pjs_apply (*[f;arg0;arg1; arg2; ... argN]*) + | Pjs_runtime_apply (* [f; [...]] *) | Pdebugger | Pjs_unsafe_downgrade of { name : string; setter : bool } | Pinit_mod @@ -145,8 +166,6 @@ type t = | Praw_js_code of Js_raw_info.t | Pjs_fn_make of int | Pjs_fn_make_unit - | Pvoid_run - | Pfull_apply (* we wrap it when do the conversion to prevent accendential optimization play safe first @@ -159,9 +178,8 @@ type t = | Pis_undefined | Pis_null_undefined | Pimport - | Pjs_typeof - | Pjs_function_length - | Pcaml_obj_length + | Ptypeof + | Pfn_arity | Pwrap_exn (* convert either JS exception or OCaml exception into OCaml format *) | Pcreate_extension of string | Pis_not_none (* no info about its type *) @@ -169,6 +187,10 @@ type t = | Pval_from_option_not_nest | Psome | Psome_not_nest + | Phash + | Phash_mixstring + | Phash_mixint + | Phash_finalmix let eq_field_dbg_info (x : Lam_compat.field_dbg_info) (y : Lam_compat.field_dbg_info) = @@ -184,84 +206,122 @@ let eq_tag_info (x : Lam_tag_info.t) y = x = y let eq_primitive_approx (lhs : t) (rhs : t) = match lhs with + | Pwrap_exn + | Praise + (* generic comparison *) + | Pobjorder + | Pobjmin + | Pobjmax + | Pobjtag + | Pobjsize + (* bool primitives *) + | Psequand + | Psequor + | Pnot + | Pboolcomp _ + | Pboolorder + | Pboolmin + | Pboolmax + (* int primitives *) + | Pisint + | Pnegint + | Paddint + | Psubint + | Pmulint + | Pdivint + | Pmodint + | Pandint + | Porint + | Pxorint + | Plslint + | Plsrint + | Pasrint + | Pintorder + | Pintmin + | Pintmax + (* float primitives *) + | Pintoffloat + | Pfloatofint + | Pnegfloat + | Paddfloat + | Psubfloat + | Pmulfloat + | Pdivfloat + | Pmodfloat + | Pfloatorder + | Pfloatmin + | Pfloatmax + (* bigint primitives *) + | Pnegbigint + | Paddbigint + | Psubbigint + | Pmulbigint + | Pdivbigint + | Pmodbigint + | Ppowbigint + | Pandbigint + | Porbigint + | Pxorbigint + | Plslbigint + | Pasrbigint + | Pbigintorder + | Pbigintmin + | Pbigintmax + (* string primitives *) + | Pstringlength + | Pstringrefu + | Pstringrefs + | Pstringadd + | Pstringcomp _ + | Pstringorder + | Pstringmin + | Pstringmax + (* List primitives *) + | Pmakelist + (* dict primitives *) + | Pmakedict + (* promise *) + | Pawait + (* etc *) + | Pjs_apply + | Pjs_runtime_apply + | Pval_from_option + | Pval_from_option_not_nest + | Pundefined_to_opt + | Pnull_to_opt + | Pnull_undefined_to_opt + | Pis_null + | Pis_not_none + | Psome + | Psome_not_nest + | Pis_undefined + | Pis_null_undefined + | Pimport + | Ptypeof + | Pfn_arity + | Plazyforce + | Pis_poly_var_block + | Pdebugger + | Pinit_mod + | Pupdate_mod + | Pduprecord + | Pmakearray + | Parraylength + | Parrayrefu + | Parraysetu + | Parrayrefs + | Parraysets + | Pjs_fn_make_unit + | Pjs_fn_method + | Phash + | Phash_mixstring + | Phash_mixint + | Phash_finalmix + -> rhs = lhs | Pcreate_extension a -> ( match rhs with Pcreate_extension b -> a = (b : string) | _ -> false) - | Pwrap_exn -> rhs = Pwrap_exn - | Pbytes_to_string -> rhs = Pbytes_to_string - | Praise -> rhs = Praise - | Psequand -> rhs = Psequand - | Psequor -> rhs = Psequor - | Pnot -> rhs = Pnot - | Pnegint -> rhs = Pnegint - | Paddint -> rhs = Paddint - | Psubint -> rhs = Psubint - | Pmulint -> rhs = Pmulint - | Pdivint -> rhs = Pdivint - | Pmodint -> rhs = Pmodint - | Pandint -> rhs = Pandint - | Porint -> rhs = Porint - | Pxorint -> rhs = Pxorint - | Plslint -> rhs = Plslint - | Plsrint -> rhs = Plsrint - | Pasrint -> rhs = Pasrint - | Pval_from_option -> rhs = Pval_from_option - | Pval_from_option_not_nest -> rhs = Pval_from_option_not_nest - | Plazyforce -> rhs = Plazyforce - | Pintoffloat -> rhs = Pintoffloat - | Pfloatofint -> rhs = Pfloatofint - | Pnegfloat -> rhs = Pnegfloat - (* | Pabsfloat -> rhs = Pabsfloat *) - | Paddfloat -> rhs = Paddfloat - | Psubfloat -> rhs = Psubfloat - | Pmulfloat -> rhs = Pmulfloat - | Pdivfloat -> rhs = Pdivfloat - | Pnegbigint -> rhs = Pnegbigint - | Paddbigint -> rhs = Paddbigint - | Psubbigint -> rhs = Psubbigint - | Pmulbigint -> rhs = Pmulbigint - | Pdivbigint -> rhs = Pdivbigint - | Pmodbigint -> rhs = Pmodbigint - | Ppowbigint -> rhs = Ppowbigint - | Pandbigint -> rhs = Pandbigint - | Porbigint -> rhs = Porbigint - | Pxorbigint -> rhs = Pxorbigint - | Plslbigint -> rhs = Plslbigint - | Pasrbigint -> rhs = Pasrbigint - | Pjs_apply -> rhs = Pjs_apply - | Pjs_runtime_apply -> rhs = Pjs_runtime_apply - | Pstringlength -> rhs = Pstringlength - | Pstringrefu -> rhs = Pstringrefu - | Pstringrefs -> rhs = Pstringrefs - | Pstringadd -> rhs = Pstringadd - | Pbyteslength -> rhs = Pbyteslength - | Pbytesrefu -> rhs = Pbytesrefu - | Pbytessetu -> rhs = Pbytessetu - | Pbytesrefs -> rhs = Pbytesrefs - | Pbytessets -> rhs = Pbytessets - | Pundefined_to_opt -> rhs = Pundefined_to_opt - | Pnull_to_opt -> rhs = Pnull_to_opt - | Pnull_undefined_to_opt -> rhs = Pnull_undefined_to_opt - | Pis_null -> rhs = Pis_null - | Pis_not_none -> rhs = Pis_not_none - | Psome -> rhs = Psome - | Psome_not_nest -> rhs = Psome_not_nest - | Pis_undefined -> rhs = Pis_undefined - | Pis_null_undefined -> rhs = Pis_null_undefined - | Pimport -> rhs = Pimport - | Pjs_typeof -> rhs = Pjs_typeof - | Pisint -> rhs = Pisint - | Pis_poly_var_block -> rhs = Pis_poly_var_block | Pisout l -> ( match rhs with Pisout r -> l = r | _ -> false) - | Pdebugger -> rhs = Pdebugger - | Pinit_mod -> rhs = Pinit_mod - | Pupdate_mod -> rhs = Pupdate_mod - | Pjs_function_length -> rhs = Pjs_function_length - (* | Pjs_string_of_small_array -> rhs = Pjs_string_of_small_array *) - (* | Pjs_is_instance_array -> rhs = Pjs_is_instance_array *) - | Pcaml_obj_length -> rhs = Pcaml_obj_length (* | Pcaml_obj_set_length -> rhs = Pcaml_obj_set_length *) - | Pccall { prim_name = n0 } -> ( - match rhs with Pccall { prim_name = n1 } -> n0 = n1 | _ -> false) | Pfield (n0, info0) -> ( match rhs with | Pfield (n1, info1) -> n0 = n1 && eq_field_dbg_info info0 info1 @@ -275,7 +335,6 @@ let eq_primitive_approx (lhs : t) (rhs : t) = | Pmakeblock (i1, info1, flag1) -> i0 = i1 && flag0 = flag1 && eq_tag_info info0 info1 | _ -> false) - | Pduprecord -> rhs = Pduprecord | Pjs_call { prim_name; arg_types; ffi; dynamic_import } -> ( match rhs with | Pjs_call rhs -> @@ -286,6 +345,10 @@ let eq_primitive_approx (lhs : t) (rhs : t) = match rhs with | Pjs_object_create obj_create1 -> obj_create = obj_create1 | _ -> false) + | Pobjcomp comparison -> ( + match rhs with + | Pobjcomp comparison1 -> Lam_compat.eq_comparison comparison comparison1 + | _ -> false) | Pintcomp comparison -> ( match rhs with | Pintcomp comparison1 -> Lam_compat.eq_comparison comparison comparison1 @@ -306,45 +369,11 @@ let eq_primitive_approx (lhs : t) (rhs : t) = | _ -> false) | Poffsetint i0 -> ( match rhs with Poffsetint i1 -> i0 = i1 | _ -> false) | Poffsetref i0 -> ( match rhs with Poffsetref i1 -> i0 = i1 | _ -> false) - | Pmakearray -> rhs = Pmakearray - | Parraylength -> rhs = Parraylength - | Parrayrefu -> rhs = Parrayrefu - | Parraysetu -> rhs = Parraysetu - | Parrayrefs -> rhs = Parrayrefs - | Parraysets -> rhs = Parraysets - | Pint64ofint -> rhs = Pint64ofint - | Pintofint64 -> rhs = Pintofint64 - | Pnegint64 -> rhs = Pnegint64 - | Paddint64 -> rhs = Paddint64 - | Psubint64 -> rhs = Psubint64 - | Pmulint64 -> rhs = Pmulint64 - | Pdivint64 -> rhs = Pdivint64 - | Pmodint64 -> rhs = Pmodint64 - | Pandint64 -> rhs = Pandint64 - | Porint64 -> rhs = Porint64 - | Pxorint64 -> rhs = Pxorint64 - | Plslint64 -> rhs = Plslint64 - | Plsrint64 -> rhs = Plsrint64 - | Pasrint64 -> rhs = Pasrint64 - | Pint64comp comparison -> ( - match rhs with - | Pint64comp comparison1 -> - Lam_compat.eq_comparison comparison comparison1 - | _ -> false) - | Pctconst compile_time_constant -> ( - match rhs with - | Pctconst compile_time_constant1 -> - Lam_compat.eq_compile_time_constant compile_time_constant - compile_time_constant1 - | _ -> false) | Pjs_unsafe_downgrade { name; setter } -> ( match rhs with | Pjs_unsafe_downgrade rhs -> name = rhs.name && setter = rhs.setter | _ -> false) | Pjs_fn_make i -> ( match rhs with Pjs_fn_make i1 -> i = i1 | _ -> false) - | Pjs_fn_make_unit -> rhs = Pjs_fn_make_unit - | Pvoid_run -> rhs = Pvoid_run - | Pfull_apply -> rhs = Pfull_apply - | Pjs_fn_method -> rhs = Pjs_fn_method + | Praw_js_code _ -> false (* TOO lazy, here comparison is only approximation*) diff --git a/jscomp/core/lam_primitive.mli b/jscomp/core/lam_primitive.mli index 31ba475096..7d29d6afa1 100644 --- a/jscomp/core/lam_primitive.mli +++ b/jscomp/core/lam_primitive.mli @@ -31,13 +31,11 @@ type record_representation = (* Inlined record under extension *) type t = - | Pbytes_to_string | Pmakeblock of int * Lam_tag_info.t * Asttypes.mutable_flag | Pfield of int * Lambda.field_dbg_info | Psetfield of int * Lambda.set_field_dbg_info | Pduprecord | Plazyforce - | Pccall of { prim_name : string } | Pjs_call of { (* Location.t * [loc] is passed down *) prim_name : string; @@ -47,9 +45,26 @@ type t = } | Pjs_object_create of External_arg_spec.obj_params | Praise + + (* object primitives *) + | Pobjcomp of Lam_compat.comparison + | Pobjorder + | Pobjmin + | Pobjmax + | Pobjtag + | Pobjsize + + (* bool primitives *) | Psequand | Psequor | Pnot + | Pboolcomp of Lam_compat.comparison + | Pboolorder + | Pboolmin + | Pboolmax + + (* int primitives *) + | Pisint | Pnegint | Paddint | Psubint @@ -64,6 +79,12 @@ type t = | Pasrint | Poffsetint of int | Poffsetref of int + | Pintcomp of Lam_compat.comparison + | Pintorder + | Pintmin + | Pintmax + + (* float primitives *) | Pintoffloat | Pfloatofint | Pnegfloat @@ -71,6 +92,13 @@ type t = | Psubfloat | Pmulfloat | Pdivfloat + | Pmodfloat + | Pfloatcomp of Lam_compat.comparison + | Pfloatorder + | Pfloatmin + | Pfloatmax + + (* bigint primitives *) | Pnegbigint | Paddbigint | Psubbigint @@ -83,52 +111,44 @@ type t = | Pxorbigint | Plslbigint | Pasrbigint - | Pintcomp of Lam_compat.comparison - | Pfloatcomp of Lam_compat.comparison - | Pjscomp of Lam_compat.comparison - | Pint64comp of Lam_compat.comparison | Pbigintcomp of Lam_compat.comparison - | Pjs_apply (*[f;arg0;arg1; arg2; ... argN]*) - | Pjs_runtime_apply (* [f; [...]] *) + | Pbigintorder + | Pbigintmin + | Pbigintmax + + (* string primitives *) | Pstringlength | Pstringrefu | Pstringrefs | Pstringadd - | Pbyteslength - | Pbytesrefu - | Pbytessetu - | Pbytesrefs - | Pbytessets - (* Array operations *) + | Pstringcomp of Lam_compat.comparison + | Pstringorder + | Pstringmin + | Pstringmax + + (* Array primitives *) | Pmakearray | Parraylength | Parrayrefu | Parraysetu | Parrayrefs | Parraysets - (* Test if the argument is a block or an immediate integer *) - | Pisint + + (* List primitives *) + | Pmakelist + + (* dict primitives *) + | Pmakedict + + (* promise *) + | Pawait + + (* etc or deprecated *) | Pis_poly_var_block - (* Test if the (integer) argument is outside an interval *) | Pisout of int - (* Operations on boxed integers (Nativeint.t, Int32.t, Int64.t) *) - | Pint64ofint - | Pintofint64 - | Pnegint64 - | Paddint64 - | Psubint64 - | Pmulint64 - | Pdivint64 - | Pmodint64 - | Pandint64 - | Porint64 - | Pxorint64 - | Plslint64 - | Plsrint64 - | Pasrint64 - (* Compile time constants *) - | Pctconst of Lam_compat.compile_time_constant - (* Integer to external pointer *) + | Pjscomp of Lam_compat.comparison + | Pjs_apply (*[f;arg0;arg1; arg2; ... argN]*) + | Pjs_runtime_apply (* [f; [...]] *) | Pdebugger | Pjs_unsafe_downgrade of { name : string; setter : bool } | Pinit_mod @@ -136,8 +156,6 @@ type t = | Praw_js_code of Js_raw_info.t | Pjs_fn_make of int | Pjs_fn_make_unit - | Pvoid_run - | Pfull_apply | Pjs_fn_method | Pundefined_to_opt | Pnull_to_opt @@ -146,9 +164,8 @@ type t = | Pis_undefined | Pis_null_undefined | Pimport - | Pjs_typeof - | Pjs_function_length - | Pcaml_obj_length + | Ptypeof + | Pfn_arity | Pwrap_exn (* convert either JS exception or OCaml exception into OCaml format *) | Pcreate_extension of string | Pis_not_none @@ -156,5 +173,9 @@ type t = | Pval_from_option_not_nest | Psome | Psome_not_nest + | Phash + | Phash_mixstring + | Phash_mixint + | Phash_finalmix val eq_primitive_approx : t -> t -> bool diff --git a/jscomp/core/lam_print.ml b/jscomp/core/lam_print.ml index 47496d04ed..df76a4636b 100644 --- a/jscomp/core/lam_print.ml +++ b/jscomp/core/lam_print.ml @@ -24,7 +24,6 @@ let rec struct_const ppf (cst : Lam_constant.t) = | Const_char i -> fprintf ppf "%s" (Ext_util.string_of_int_as_char i) | Const_string { s } -> fprintf ppf "%S" s | Const_float f -> fprintf ppf "%s" f - | Const_int64 n -> fprintf ppf "%LiL" n | Const_bigint (sign, i) -> fprintf ppf "%sn" (Bigint_utils.to_string sign i) | Const_pointer name -> fprintf ppf "`%s" name | Const_some n -> fprintf ppf "[some-c]%a" struct_const n @@ -34,10 +33,6 @@ let rec struct_const ppf (cst : Lam_constant.t) = List.iter (fun sc -> fprintf ppf "@ %a" struct_const sc) scl in fprintf ppf "@[<1>[%i:@ @[%a%a@]]@]" tag struct_const sc1 sconsts scl - | Const_float_array [] -> fprintf ppf "[| |]" - | Const_float_array (f1 :: fl) -> - let floats ppf fl = List.iter (fun f -> fprintf ppf "@ %s" f) fl in - fprintf ppf "@[<1>[|@[%s%a@]|]@]" f1 floats fl (* let string_of_loc_kind (loc : Lambda.loc_kind) = match loc with @@ -52,23 +47,19 @@ let primitive ppf (prim : Lam_primitive.t) = (* | Pcreate_exception s -> fprintf ppf "[exn-create]%S" s *) | Pcreate_extension s -> fprintf ppf "[ext-create]%S" s | Pwrap_exn -> fprintf ppf "#exn" - | Pcaml_obj_length -> fprintf ppf "#obj_length" | Pinit_mod -> fprintf ppf "init_mod!" | Pupdate_mod -> fprintf ppf "update_mod!" - | Pbytes_to_string -> fprintf ppf "bytes_to_string" | Pjs_apply -> fprintf ppf "#apply" | Pjs_runtime_apply -> fprintf ppf "#runtime_apply" | Pjs_unsafe_downgrade { name; setter } -> if setter then fprintf ppf "##%s#=" name else fprintf ppf "##%s" name - | Pjs_function_length -> fprintf ppf "#function_length" - | Pvoid_run -> fprintf ppf "#run" - | Pfull_apply -> fprintf ppf "#full_apply" + | Pfn_arity -> fprintf ppf "fn.length" | Pjs_fn_make i -> fprintf ppf "js_fn_make_%i" i | Pjs_fn_make_unit -> fprintf ppf "js_fn_make_unit" | Pjs_fn_method -> fprintf ppf "js_fn_method" | Pdebugger -> fprintf ppf "debugger" | Praw_js_code _ -> fprintf ppf "[raw]" - | Pjs_typeof -> fprintf ppf "[typeof]" + | Ptypeof -> fprintf ppf "typeof" | Pnull_to_opt -> fprintf ppf "[null->opt]" | Pundefined_to_opt -> fprintf ppf "[undefined->opt]" | Pnull_undefined_to_opt -> fprintf ppf "[null/undefined->opt]" @@ -92,13 +83,32 @@ let primitive ppf (prim : Lam_primitive.t) = fprintf ppf "%s%i" instr n | Pduprecord -> fprintf ppf "duprecord" | Plazyforce -> fprintf ppf "force" - | Pccall p -> fprintf ppf "%s" p.prim_name | Pjs_call { prim_name } -> fprintf ppf "%s[js]" prim_name | Pjs_object_create _ -> fprintf ppf "[js.obj]" | Praise -> fprintf ppf "raise" + | Pobjcomp Ceq -> fprintf ppf "==" + | Pobjcomp Cneq -> fprintf ppf "!=" + | Pobjcomp Clt -> fprintf ppf "<" + | Pobjcomp Cle -> fprintf ppf "<=" + | Pobjcomp Cgt -> fprintf ppf ">" + | Pobjcomp Cge -> fprintf ppf ">=" + | Pobjorder -> fprintf ppf "compare" + | Pobjmin -> fprintf ppf "min" + | Pobjmax -> fprintf ppf "max" + | Pobjtag -> fprintf ppf "tag" + | Pobjsize -> fprintf ppf "length" | Psequand -> fprintf ppf "&&" | Psequor -> fprintf ppf "||" | Pnot -> fprintf ppf "not" + | Pboolcomp Ceq -> fprintf ppf "==" + | Pboolcomp Cneq -> fprintf ppf "!=" + | Pboolcomp Clt -> fprintf ppf "<" + | Pboolcomp Cle -> fprintf ppf "<=" + | Pboolcomp Cgt -> fprintf ppf ">" + | Pboolcomp Cge -> fprintf ppf ">=" + | Pboolorder -> fprintf ppf "compare" + | Pboolmin -> fprintf ppf "min" + | Pboolmax -> fprintf ppf "max" | Pnegint -> fprintf ppf "~" | Paddint -> fprintf ppf "+" | Pstringadd -> fprintf ppf "+*" @@ -118,22 +128,28 @@ let primitive ppf (prim : Lam_primitive.t) = | Pintcomp Cle -> fprintf ppf "<=" | Pintcomp Cgt -> fprintf ppf ">" | Pintcomp Cge -> fprintf ppf ">=" + | Pintorder -> fprintf ppf "compare" + | Pintmin -> fprintf ppf "min" + | Pintmax -> fprintf ppf "max" | Poffsetint n -> fprintf ppf "%i+" n | Poffsetref n -> fprintf ppf "+:=%i" n | Pintoffloat -> fprintf ppf "int_of_float" | Pfloatofint -> fprintf ppf "float_of_int" | Pnegfloat -> fprintf ppf "~." - (* | Pabsfloat -> fprintf ppf "abs." *) | Paddfloat -> fprintf ppf "+." | Psubfloat -> fprintf ppf "-." | Pmulfloat -> fprintf ppf "*." | Pdivfloat -> fprintf ppf "/." + | Pmodfloat -> fprintf ppf "mod" | Pfloatcomp Ceq -> fprintf ppf "==." | Pfloatcomp Cneq -> fprintf ppf "!=." | Pfloatcomp Clt -> fprintf ppf "<." | Pfloatcomp Cle -> fprintf ppf "<=." | Pfloatcomp Cgt -> fprintf ppf ">." | Pfloatcomp Cge -> fprintf ppf ">=." + | Pfloatorder -> fprintf ppf "compare" + | Pfloatmin -> fprintf ppf "min" + | Pfloatmax -> fprintf ppf "max" | Pnegbigint -> fprintf ppf "~" | Paddbigint -> fprintf ppf "+" | Psubbigint -> fprintf ppf "-" @@ -152,6 +168,9 @@ let primitive ppf (prim : Lam_primitive.t) = | Pbigintcomp Cle -> fprintf ppf "<=" | Pbigintcomp Cgt -> fprintf ppf ">" | Pbigintcomp Cge -> fprintf ppf ">=" + | Pbigintorder -> fprintf ppf "compare" + | Pbigintmin -> fprintf ppf "min" + | Pbigintmax -> fprintf ppf "max" | Pjscomp Ceq -> fprintf ppf "#==" | Pjscomp Cneq -> fprintf ppf "#!=" | Pjscomp Clt -> fprintf ppf "#<" @@ -161,50 +180,31 @@ let primitive ppf (prim : Lam_primitive.t) = | Pstringlength -> fprintf ppf "string.length" | Pstringrefu -> fprintf ppf "string.unsafe_get" | Pstringrefs -> fprintf ppf "string.get" - | Pbyteslength -> fprintf ppf "bytes.length" - | Pbytesrefu -> fprintf ppf "bytes.unsafe_get" - | Pbytessetu -> fprintf ppf "bytes.unsafe_set" - | Pbytesrefs -> fprintf ppf "bytes.get" - | Pbytessets -> fprintf ppf "bytes.set" + | Pstringcomp Ceq -> fprintf ppf "==" + | Pstringcomp Cneq -> fprintf ppf "!=" + | Pstringcomp Clt -> fprintf ppf "<" + | Pstringcomp Cle -> fprintf ppf "<=" + | Pstringcomp Cgt -> fprintf ppf ">" + | Pstringcomp Cge -> fprintf ppf ">=" + | Pstringorder -> fprintf ppf "compare" + | Pstringmin -> fprintf ppf "min" + | Pstringmax -> fprintf ppf "max" | Parraylength -> fprintf ppf "array.length" | Pmakearray -> fprintf ppf "makearray" + | Pmakelist -> fprintf ppf "makelist" + | Pmakedict -> fprintf ppf "makedict" | Parrayrefu -> fprintf ppf "array.unsafe_get" | Parraysetu -> fprintf ppf "array.unsafe_set" | Parrayrefs -> fprintf ppf "array.get" | Parraysets -> fprintf ppf "array.set" - | Pctconst c -> - let const_name = - match c with - | Big_endian -> "big_endian" - | Ostype_unix -> "ostype_unix" - | Ostype_win32 -> "ostype_win32" - | Ostype -> "ostype" - | Backend_type -> "backend_type" - in - fprintf ppf "sys.constant_%s" const_name | Pisint -> fprintf ppf "isint" | Pis_poly_var_block -> fprintf ppf "#is_poly_var_block" | Pisout i -> fprintf ppf "isout %d" i - | Pint64ofint -> fprintf ppf "of_int" - | Pintofint64 -> fprintf ppf "to_int" - | Pnegint64 -> fprintf ppf "neg64" - | Paddint64 -> fprintf ppf "add64" - | Psubint64 -> fprintf ppf "sub64" - | Pmulint64 -> fprintf ppf "mul64" - | Pdivint64 -> fprintf ppf "div64" - | Pmodint64 -> fprintf ppf "mod64" - | Pandint64 -> fprintf ppf "and64" - | Porint64 -> fprintf ppf "or64" - | Pxorint64 -> fprintf ppf "xor64" - | Plslint64 -> fprintf ppf "lsl64" - | Plsrint64 -> fprintf ppf "lsr64" - | Pasrint64 -> fprintf ppf "asr64" - | Pint64comp Ceq -> fprintf ppf "==" - | Pint64comp Cneq -> fprintf ppf "!=" - | Pint64comp Clt -> fprintf ppf "<" - | Pint64comp Cgt -> fprintf ppf ">" - | Pint64comp Cle -> fprintf ppf "<=" - | Pint64comp Cge -> fprintf ppf ">=" + | Pawait -> fprintf ppf "await" + | Phash -> fprintf ppf "hash" + | Phash_mixint -> fprintf ppf "hash_mix_int" + | Phash_mixstring -> fprintf ppf "hash_mix_string" + | Phash_finalmix -> fprintf ppf "hash_final_mix" type print_kind = Alias | Strict | StrictOpt | Variable | Recursive diff --git a/jscomp/ext/ext_pervasives.ml b/jscomp/ext/ext_pervasives.ml index ede7f8a222..a8540f5a5e 100644 --- a/jscomp/ext/ext_pervasives.ml +++ b/jscomp/ext/ext_pervasives.ml @@ -22,7 +22,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -external reraise : exn -> 'a = "%reraise" +external reraise : exn -> 'a = "%raise" let finally v ~clean:action f = match f v with diff --git a/jscomp/ext/ext_pervasives.mli b/jscomp/ext/ext_pervasives.mli index a4761900b1..970898dc89 100644 --- a/jscomp/ext/ext_pervasives.mli +++ b/jscomp/ext/ext_pervasives.mli @@ -25,7 +25,7 @@ (** Extension to standard library [Pervavives] module, safe to open *) -external reraise : exn -> 'a = "%reraise" +external reraise : exn -> 'a = "%raise" val finally : 'a -> clean:('a -> unit) -> ('a -> 'b) -> 'b diff --git a/jscomp/ext/js_runtime_modules.ml b/jscomp/ext/js_runtime_modules.ml deleted file mode 100644 index 40f6ddf945..0000000000 --- a/jscomp/ext/js_runtime_modules.ml +++ /dev/null @@ -1,74 +0,0 @@ -(* Copyright (C) 2017 Hongbo Zhang, Authors of ReScript - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -let exceptions = "Caml_exceptions" - -let io = "Caml_io" - -let sys = "Caml_sys" - -let lexer = "Caml_lexer" - -let parser = "Caml_parser" - -let obj_runtime = "Caml_obj" - -let array = "Caml_array" - -let format = "Caml_format" - -let string = "Caml_string" - -let bytes = "Caml_bytes" -let bytes_ = "Bytes" - -let float = "Caml_float" - -let hash_primitive = "Caml_hash_primitive" - -let hash = "Caml_hash" - -let curry = "Curry" - -let caml_primitive = "Caml" - -let int64 = "Caml_int64" - -let md5 = "Caml_md5" - -let int32 = "Caml_int32" - -let bigint = "Caml_bigint" - -let option = "Caml_option" - -let module_ = "Caml_module" - -let caml_js_exceptions = "Caml_js_exceptions" - -let deriving = "Runtime_deriving" - -let promise = "Runtime_promise" - -let astExtensions = "Runtime_ast_extensions" diff --git a/jscomp/ext/misc.ml b/jscomp/ext/misc.ml index 1568d14def..c1d5261b01 100644 --- a/jscomp/ext/misc.ml +++ b/jscomp/ext/misc.ml @@ -138,9 +138,10 @@ let expand_directory alt s = (* Hashtable functions *) -let create_hashtable size init = +let create_hashtable init = + let size = Array.length init in let tbl = Hashtbl.create size in - List.iter (fun (key, data) -> Hashtbl.add tbl key data) init; + Array.iter (fun (key, data) -> Hashtbl.add tbl key data) init; tbl (* File copy *) diff --git a/jscomp/ext/misc.mli b/jscomp/ext/misc.mli index b9163e3568..5f9cbb05b8 100644 --- a/jscomp/ext/misc.mli +++ b/jscomp/ext/misc.mli @@ -62,7 +62,7 @@ val expand_directory: string -> string -> string (* [expand_directory alt file] eventually expands a [+] at the beginning of file into [alt] (an alternate root directory) *) -val create_hashtable: int -> ('a * 'b) list -> ('a, 'b) Hashtbl.t +val create_hashtable: ('a * 'b) array -> ('a, 'b) Hashtbl.t (* Create a hashtable of the given size and fills it with the given bindings. *) diff --git a/jscomp/core/lam_dispatch_primitive.mli b/jscomp/ext/primitive_modules.ml similarity index 67% rename from jscomp/core/lam_dispatch_primitive.mli rename to jscomp/ext/primitive_modules.ml index 09084943fe..af57d0be8b 100644 --- a/jscomp/core/lam_dispatch_primitive.mli +++ b/jscomp/ext/primitive_modules.ml @@ -1,5 +1,5 @@ -(* Copyright (C) 2015 - 2016 Bloomberg Finance L.P. - * Copyright (C) 2017 - Hongbo Zhang, Authors of ReScript +(* Copyright (C) 2017 Hongbo Zhang, Authors of ReScript + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or @@ -17,14 +17,41 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -(** Compile lambda primitives (note this is different external c calls) *) +let bool = "Primitive_bool" + +let int = "Primitive_int" + +let float = "Primitive_float" + +let bigint = "Primitive_bigint" + +let string = "Primitive_string" + +let array = "Primitive_array" + +let dict = "Primitive_dict" + +let object_ = "Primitive_object" + +let promise = "Primitive_promise" + +let module_ = "Primitive_module" + +let lazy_ = "Primitive_lazy" + +let option = "Primitive_option" + +let hash = "Primitive_hash" + +let exceptions = "Primitive_exceptions" + +let curry = "Primitive_curry" + +let util = "Primitive_util" -val translate : Location.t -> string -> J.expression list -> J.expression -(** - @return None when the primitives are not handled in pre-processing -*) +let pervasives = "Pervasives" diff --git a/jscomp/frontend/ast_core_type.ml b/jscomp/frontend/ast_core_type.ml index af9021f644..7762925487 100644 --- a/jscomp/frontend/ast_core_type.ml +++ b/jscomp/frontend/ast_core_type.ml @@ -47,9 +47,7 @@ open Ast_helper let is_builtin_rank0_type txt = match txt with - | "int" | "char" | "bytes" | "float" | "bool" | "unit" | "exn" | "int64" - | "string" -> - true + | "int" | "char" | "float" | "bool" | "unit" | "exn" | "string" -> true | _ -> false let is_unit (ty : t) = diff --git a/jscomp/frontend/ast_derive_js_mapper.ml b/jscomp/frontend/ast_derive_js_mapper.ml index dae52806d8..43c4b30369 100644 --- a/jscomp/frontend/ast_derive_js_mapper.ml +++ b/jscomp/frontend/ast_derive_js_mapper.ml @@ -130,7 +130,7 @@ let app2 = Ast_compatible.app2 let ( ->~ ) a b = Ast_compatible.arrow a b let raise_when_not_found_ident = - Longident.Ldot (Lident Js_runtime_modules.deriving, "raiseWhenNotFound") + Longident.Ldot (Lident Primitive_modules.util, "raiseWhenNotFound") let raise_when_not_found x = app1 (Exp.ident {loc = noloc; txt = raise_when_not_found_ident}) x diff --git a/jscomp/frontend/ast_exp_handle_external.ml b/jscomp/frontend/ast_exp_handle_external.ml index 0e7eb9fd5c..7fbeb6b30e 100644 --- a/jscomp/frontend/ast_exp_handle_external.ml +++ b/jscomp/frontend/ast_exp_handle_external.ml @@ -67,7 +67,7 @@ let handle_external loc (x : string) : Parsetree.expression = let handle_debugger loc (payload : Ast_payload.t) = match payload with | PStr [] -> - Ast_external_mk.local_external_apply loc ~pval_prim:["#debugger"] + Ast_external_mk.local_external_apply loc ~pval_prim:["%debugger"] ~pval_type:(Typ.arrow Nolabel (Typ.any ()) (Ast_literal.type_unit ())) [Ast_literal.val_unit ~loc ()] | _ -> diff --git a/jscomp/frontend/ast_literal.ml b/jscomp/frontend/ast_literal.ml index af71328945..367f7f44ec 100644 --- a/jscomp/frontend/ast_literal.ml +++ b/jscomp/frontend/ast_literal.ml @@ -49,20 +49,28 @@ module Lid = struct let type_bool : t = Lident "bool" (* use *predef* *) + let pervasives : t = Lident Primitive_modules.pervasives + + (* FIXME: Use primitive module *) let js_oo : t = Lident "Js_OO" + (* FIXME: Use primitive module *) let js_meth_callback : t = Ldot (js_oo, "Callback") - let ignore_id : t = Ldot (Lident "Pervasives", "ignore") + let ignore_id : t = Ldot (pervasives, "ignore") let hidden_field n : t = Lident ("I" ^ n) + (* FIXME: Use primitive module *) let js_null : t = Ldot (Lident "Js", "null") + (* FIXME: Use primitive module *) let js_undefined : t = Ldot (Lident "Js", "undefined") + (* FIXME: Use primitive module *) let js_null_undefined : t = Ldot (Lident "Js", "null_undefined") + (* FIXME: Use primitive module *) let js_re_id : t = Ldot (Ldot (Lident "Js", "Re"), "t") end @@ -136,10 +144,6 @@ let type_int ?loc () = | Some loc -> Ast_helper.Typ.mk ~loc (Ptyp_constr ({txt = Lid.type_int; loc}, [])) -let type_int64 = - Ast_helper.Typ.mk - (Ptyp_constr ({txt = Lident "int64"; loc = Location.none}, [])) - let type_float = Ast_helper.Typ.mk (Ptyp_constr ({txt = Lident "float"; loc = Location.none}, [])) diff --git a/jscomp/frontend/ast_literal.mli b/jscomp/frontend/ast_literal.mli index 059b178dac..0b34d29d80 100644 --- a/jscomp/frontend/ast_literal.mli +++ b/jscomp/frontend/ast_literal.mli @@ -41,6 +41,8 @@ module Lid : sig val type_bigint : t + val pervasives : t + val js_oo : t val js_meth_callback : t @@ -76,8 +78,6 @@ val type_bool : core_type_lit val type_int : core_type_lit -val type_int64 : Parsetree.core_type - val type_float : Parsetree.core_type val type_bigint : core_type_lit diff --git a/jscomp/frontend/bs_builtin_ppx.ml b/jscomp/frontend/bs_builtin_ppx.ml index bf9bdb53ad..02ec4b1c90 100644 --- a/jscomp/frontend/bs_builtin_ppx.ml +++ b/jscomp/frontend/bs_builtin_ppx.ml @@ -317,19 +317,6 @@ let signature_item_mapper (self : mapper) (sigi : Parsetree.signature_item) : pval_attributes = []; }; } - | Pexp_constant (Pconst_integer (s, Some 'L')) -> - let s = Int64.of_string s in - succeed attr pval_attributes; - { - sigi with - psig_desc = - Psig_value - { - value_desc with - pval_prim = External_ffi_types.inline_int64_primitive s; - pval_attributes = []; - }; - } | Pexp_constant (Pconst_integer (s, Some 'n')) -> succeed attr pval_attributes; { @@ -424,21 +411,6 @@ let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) : pval_prim = External_ffi_types.inline_int_primitive s; }; } - | Some attr, Pexp_constant (Pconst_integer (s, Some 'L')) -> - let s = Int64.of_string s in - succeed attr pvb_attributes; - { - str with - pstr_desc = - Pstr_primitive - { - pval_name; - pval_type = Ast_literal.type_int64; - pval_loc = pvb_loc; - pval_attributes = []; - pval_prim = External_ffi_types.inline_int64_primitive s; - }; - } | Some attr, Pexp_constant (Pconst_float (s, None)) -> succeed attr pvb_attributes; { diff --git a/jscomp/frontend/external_ffi_types.ml b/jscomp/frontend/external_ffi_types.ml index 5146deef45..8045418ebf 100644 --- a/jscomp/frontend/external_ffi_types.ml +++ b/jscomp/frontend/external_ffi_types.ml @@ -296,9 +296,6 @@ let inline_bool_primitive b : string list = let inline_int_primitive (i : int32) : string list = [""; to_string (Ffi_inline_const (Const_int {i; comment = None}))] -let inline_int64_primitive (i : int64) : string list = - [""; to_string (Ffi_inline_const (Const_int64 i))] - let inline_bigint_primitive (i : string) : string list = let sign, i = Bigint_utils.parse_bigint i in [""; to_string (Ffi_inline_const (Const_bigint (sign, i)))] diff --git a/jscomp/frontend/external_ffi_types.mli b/jscomp/frontend/external_ffi_types.mli index a96c06cbe3..b661c3124b 100644 --- a/jscomp/frontend/external_ffi_types.mli +++ b/jscomp/frontend/external_ffi_types.mli @@ -103,8 +103,6 @@ val inline_bool_primitive : bool -> string list val inline_int_primitive : int32 -> string list -val inline_int64_primitive : int64 -> string list - val inline_float_primitive : string -> string list val inline_bigint_primitive : string -> string list diff --git a/jscomp/frontend/lam_constant.ml b/jscomp/frontend/lam_constant.ml index 5e534668d7..f5a54fed94 100644 --- a/jscomp/frontend/lam_constant.ml +++ b/jscomp/frontend/lam_constant.ml @@ -49,11 +49,9 @@ type t = | Const_char of int | Const_string of {s: string; unicode: bool} | Const_float of string - | Const_int64 of int64 | Const_bigint of bool * string | Const_pointer of string | Const_block of int * Lambda.tag_info * t list - | Const_float_array of string list | Const_some of t | Const_module_alias (* eventually we can remove it, since we know @@ -83,10 +81,6 @@ let rec eq_approx (x : t) (y : t) = match y with | Const_float iy -> ix = iy | _ -> false) - | Const_int64 ix -> ( - match y with - | Const_int64 iy -> ix = iy - | _ -> false) | Const_bigint (sx, ix) -> ( match y with | Const_bigint (sy, iy) -> sx = sy && ix = iy @@ -100,10 +94,6 @@ let rec eq_approx (x : t) (y : t) = | Const_block (iy, _, iys) -> ix = iy && Ext_list.for_all2_no_exn ixs iys eq_approx | _ -> false) - | Const_float_array ixs -> ( - match y with - | Const_float_array iys -> Ext_list.for_all2_no_exn ixs iys Ext_string.equal - | _ -> false) | Const_some ix -> ( match y with | Const_some iy -> eq_approx ix iy diff --git a/jscomp/frontend/lam_constant.mli b/jscomp/frontend/lam_constant.mli index 5d2fc05deb..41cec0c799 100644 --- a/jscomp/frontend/lam_constant.mli +++ b/jscomp/frontend/lam_constant.mli @@ -45,11 +45,9 @@ type t = | Const_char of int | Const_string of {s: string; unicode: bool} | Const_float of string - | Const_int64 of int64 | Const_bigint of bool * string | Const_pointer of string | Const_block of int * Lambda.tag_info * t list - | Const_float_array of string list | Const_some of t (* eventually we can remove it, since we know [constant] is [undefined] or not diff --git a/jscomp/gentype/GenTypeCommon.ml b/jscomp/gentype/GenTypeCommon.ml index 5839f447b0..89fa17907d 100644 --- a/jscomp/gentype/GenTypeCommon.ml +++ b/jscomp/gentype/GenTypeCommon.ml @@ -195,7 +195,6 @@ let string_t = ident "string" let unit_t = ident "void" let weakmap_t (x, y) = ident ~type_args:[x; y] "WeakMap" let weakset_t x = ident ~type_args:[x] "WeakSet" -let int64_t = Tuple [number_t; number_t] module NodeFilename = struct include Filename diff --git a/jscomp/gentype/TranslateTypeExprFromTypes.ml b/jscomp/gentype/TranslateTypeExprFromTypes.ml index dc067d92eb..ab51dcdce4 100644 --- a/jscomp/gentype/TranslateTypeExprFromTypes.ml +++ b/jscomp/gentype/TranslateTypeExprFromTypes.ml @@ -77,7 +77,6 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env = match (path |> path_to_list |> List.rev, params_translation) with | (["FB"; "bool"] | ["bool"]), [] -> {dependencies = []; type_ = boolean_t} | (["FB"; "int"] | ["int"]), [] -> {dependencies = []; type_ = number_t} - | (["Int64"; "t"] | ["int64"]), [] -> {dependencies = []; type_ = int64_t} | (["FB"; "float"] | ["float"]), [] -> {dependencies = []; type_ = number_t} | ( ( ["FB"; "string"] | ["string"] diff --git a/jscomp/gentype_tests/typescript-react-example/package-lock.json b/jscomp/gentype_tests/typescript-react-example/package-lock.json index ebc3934ee5..be9ccf6fe0 100644 --- a/jscomp/gentype_tests/typescript-react-example/package-lock.json +++ b/jscomp/gentype_tests/typescript-react-example/package-lock.json @@ -22,7 +22,7 @@ }, "../../..": { "name": "rescript", - "version": "12.0.0-alpha.2", + "version": "12.0.0-alpha.4", "dev": true, "hasInstallScript": true, "license": "SEE LICENSE IN LICENSE", @@ -30,7 +30,7 @@ "bsc": "bsc", "bstracing": "lib/bstracing", "rescript": "rescript", - "rewatch": "scripts/rewatch" + "rewatch": "cli/rewatch" }, "devDependencies": { "@biomejs/biome": "1.8.3", diff --git a/jscomp/gentype_tests/typescript-react-example/rescript.json b/jscomp/gentype_tests/typescript-react-example/rescript.json index bc4baeebd3..bcee761acf 100644 --- a/jscomp/gentype_tests/typescript-react-example/rescript.json +++ b/jscomp/gentype_tests/typescript-react-example/rescript.json @@ -5,6 +5,7 @@ "importPath": "relative", "shims": { "Js": "Js", + "Belt": "Belt", "ReactEvent": "ReactEvent", "RescriptPervasives": "RescriptPervasives", "ReasonReact": "ReactShim" diff --git a/jscomp/gentype_tests/typescript-react-example/src/CreateErrorHandler2.res b/jscomp/gentype_tests/typescript-react-example/src/CreateErrorHandler2.res index 394907545e..c5a02884f1 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/CreateErrorHandler2.res +++ b/jscomp/gentype_tests/typescript-react-example/src/CreateErrorHandler2.res @@ -1,6 +1,6 @@ module Error2 = { type t = int - let notification = n => (string_of_int(n), "") + let notification = n => (Belt.Int.toString(n), "") } module MyErrorHandler = ErrorHandler.Make(Error2) /* MyErrorHandler.notify(42) */ diff --git a/jscomp/gentype_tests/typescript-react-example/src/Docstrings.res b/jscomp/gentype_tests/typescript-react-example/src/Docstrings.res index e7a59c3356..4a5abaeccf 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Docstrings.res +++ b/jscomp/gentype_tests/typescript-react-example/src/Docstrings.res @@ -10,7 +10,7 @@ let flat = 34 * @returns A signed message */ @genType -let signMessage = (. message, key) => message ++ string_of_int(key) +let signMessage = (. message, key) => message ++ Belt.Int.toString(key) @genType let one = a => a + 0 diff --git a/jscomp/gentype_tests/typescript-react-example/src/Hooks.res b/jscomp/gentype_tests/typescript-react-example/src/Hooks.res index ee7569adf3..862c593abb 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Hooks.res +++ b/jscomp/gentype_tests/typescript-react-example/src/Hooks.res @@ -9,7 +9,7 @@ let make = (~vehicle) => {

{React.string( - "Hooks example " ++ (vehicle.name ++ (" clicked " ++ (string_of_int(count) ++ " times"))), + "Hooks example " ++ (vehicle.name ++ (" clicked " ++ (Belt.Int.toString(count) ++ " times"))), )}

diff --git a/jscomp/gentype_tests/typescript-react-example/src/Hooks.res.js b/jscomp/gentype_tests/typescript-react-example/src/Hooks.res.js index 1a0a3edf28..4a35b38c0f 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Hooks.res.js +++ b/jscomp/gentype_tests/typescript-react-example/src/Hooks.res.js @@ -1,5 +1,6 @@ // Generated by ReScript, PLEASE EDIT WITH CARE +import * as Obj from "rescript/lib/es6/obj.js"; import * as React from "react"; import * as ImportHooks from "./ImportHooks.res.js"; import * as ImportHookDefault from "./ImportHookDefault.res.js"; @@ -126,7 +127,7 @@ let WithRef = { let testForwardRef = React.forwardRef((x, y) => makeWithRef(x.vehicle)(y)); let input = React.forwardRef((r, ref) => React.createElement("div", { - ref: ref + ref: Obj.magic(ref) }, r.x)); let ForwardRef = { diff --git a/jscomp/gentype_tests/typescript-react-example/src/Records.res.js b/jscomp/gentype_tests/typescript-react-example/src/Records.res.js index 8ad1df10ae..a399123fb1 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Records.res.js +++ b/jscomp/gentype_tests/typescript-react-example/src/Records.res.js @@ -3,7 +3,7 @@ import * as Belt_List from "rescript/lib/es6/belt_List.js"; import * as Belt_Array from "rescript/lib/es6/belt_Array.js"; import * as Belt_Option from "rescript/lib/es6/belt_Option.js"; -import * as Caml_option from "rescript/lib/es6/caml_option.js"; +import * as Primitive_option from "rescript/lib/es6/primitive_option.js"; function computeArea(param) { return Math.imul(Math.imul(param.x, param.y), Belt_Option.mapWithDefault(param.z, 1, n => n)); @@ -63,7 +63,7 @@ function getPayloadRecordPlusOne(param) { } function findAddress2(business) { - return Belt_Option.mapWithDefault(Caml_option.nullable_to_opt(business.address2), /* [] */0, a => ({ + return Belt_Option.mapWithDefault(Primitive_option.fromNullable(business.address2), /* [] */0, a => ({ hd: a, tl: /* [] */0 })); @@ -80,7 +80,7 @@ let someBusiness2 = { }; function computeArea3(o) { - return Math.imul(Math.imul(o.x, o.y), Belt_Option.mapWithDefault(Caml_option.nullable_to_opt(o.z), 1, n => n)); + return Math.imul(Math.imul(o.x, o.y), Belt_Option.mapWithDefault(Primitive_option.fromNullable(o.z), 1, n => n)); } function computeArea4(o) { diff --git a/jscomp/gentype_tests/typescript-react-example/src/TestPromise.res.js b/jscomp/gentype_tests/typescript-react-example/src/TestPromise.res.js index 153c834adc..27c2b0b8b7 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/TestPromise.res.js +++ b/jscomp/gentype_tests/typescript-react-example/src/TestPromise.res.js @@ -1,8 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as Caml_obj from "rescript/lib/es6/caml_obj.js"; import * as Js_promise from "rescript/lib/es6/js_promise.js"; -import * as Caml_option from "rescript/lib/es6/caml_option.js"; +import * as Primitive_object from "rescript/lib/es6/primitive_object.js"; function convert(p) { return Js_promise.then_(param => Promise.resolve({ @@ -11,8 +10,8 @@ function convert(p) { } function barx(xOpt, param) { - let x = xOpt !== undefined ? Caml_option.valFromOption(xOpt) : Promise.resolve("a"); - return Caml_obj.equal(x, x); + let x = xOpt !== undefined ? xOpt : Promise.resolve("a"); + return Primitive_object.equal(x, x); } export { diff --git a/jscomp/gentype_tests/typescript-react-example/src/Uncurried.res b/jscomp/gentype_tests/typescript-react-example/src/Uncurried.res index f7bf1b94fa..ac78dcff15 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Uncurried.res +++ b/jscomp/gentype_tests/typescript-react-example/src/Uncurried.res @@ -8,15 +8,15 @@ @genType let uncurried0 = (. ()) => "" -@genType let uncurried1 = (. x) => x |> string_of_int +@genType let uncurried1 = (. x) => x->Belt.Int.toString -@genType let uncurried2 = (. x, y) => (x |> string_of_int) ++ y +@genType let uncurried2 = (. x, y) => (x->Belt.Int.toString) ++ y -@genType let uncurried3 = (. x, y, z) => (x |> string_of_int) ++ (y ++ (z |> string_of_int)) +@genType let uncurried3 = (. x, y, z) => (x->Belt.Int.toString) ++ (y ++ (z->Belt.Int.toString)) -@genType let curried3 = (x, y, z) => (x |> string_of_int) ++ (y ++ (z |> string_of_int)) +@genType let curried3 = (x, y, z) => (x->Belt.Int.toString) ++ (y ++ (z->Belt.Int.toString)) -@genType let callback = cb => cb() |> string_of_int +@genType let callback = cb => cb()->Belt.Int.toString type auth = {login: unit => string} type authU = {loginU: (. unit) => string} diff --git a/jscomp/gentype_tests/typescript-react-example/src/VariantsWithPayload.res b/jscomp/gentype_tests/typescript-react-example/src/VariantsWithPayload.res index 0fc87dc5b6..13831c803c 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/VariantsWithPayload.res +++ b/jscomp/gentype_tests/typescript-react-example/src/VariantsWithPayload.res @@ -64,21 +64,21 @@ type variantWithPayloads = let printVariantWithPayloads = x => switch x { | A => Js.log2("printVariantWithPayloads", "A") - | B(x) => Js.log2("printVariantWithPayloads", "B(" ++ (string_of_int(x) ++ ")")) + | B(x) => Js.log2("printVariantWithPayloads", "B(" ++ (Belt.Int.toString(x) ++ ")")) | C(x, y) => Js.log2( "printVariantWithPayloads", - "C(" ++ (string_of_int(x) ++ (", " ++ (string_of_int(y) ++ ")"))), + "C(" ++ (Belt.Int.toString(x) ++ (", " ++ (Belt.Int.toString(y) ++ ")"))), ) | D((x, y)) => Js.log2( "printVariantWithPayloads", - "D((" ++ (string_of_int(x) ++ (", " ++ (string_of_int(y) ++ "))"))), + "D((" ++ (Belt.Int.toString(x) ++ (", " ++ (Belt.Int.toString(y) ++ "))"))), ) | E(x, s, y) => Js.log2( "printVariantWithPayloads", - "E(" ++ (string_of_int(x) ++ (", " ++ (s ++ (", " ++ (string_of_int(y) ++ ")"))))), + "E(" ++ (Belt.Int.toString(x) ++ (", " ++ (s ++ (", " ++ (Belt.Int.toString(y) ++ ")"))))), ) } diff --git a/jscomp/gentype_tests/typescript-react-example/src/index.tsx b/jscomp/gentype_tests/typescript-react-example/src/index.tsx index 5984d48e6b..1bdb73f6c2 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/index.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/index.tsx @@ -23,7 +23,7 @@ import * as TestPromise from "./TestPromise.gen"; const consoleLog = console.log; -const intList = Types.map(x => x + 1, Types.someIntList); +const intList = Types.map(Types.someIntList, x => x + 1); const businesses = [ { diff --git a/jscomp/gentype_tests/typescript-react-example/src/nested/Types.gen.tsx b/jscomp/gentype_tests/typescript-react-example/src/nested/Types.gen.tsx index f31439c426..d497835c0e 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/nested/Types.gen.tsx +++ b/jscomp/gentype_tests/typescript-react-example/src/nested/Types.gen.tsx @@ -7,6 +7,8 @@ import * as TypesJS from './Types.res.js'; import type {Json_t as Js_Json_t} from '../../src/shims/Js.shim'; +import type {List_t as Belt_List_t} from '../../src/shims/Belt.shim'; + import type {M_t__ as TypeNameSanitize_M_t__} from '../../src/TypeNameSanitize.gen'; import type {list} from '../../src/shims/RescriptPervasives.shim'; @@ -74,17 +76,13 @@ export type Vector = vector; export type date = Date; -export type i64A = [number, number]; - -export type i64B = [number, number]; - export type ObjectId_t = number; export type tPrimed = [TypeNameSanitize_t_, TypeNameSanitize_M_t__]; export const someIntList: list = TypesJS.someIntList as any; -export const map: (_1:((_1:T1) => T2), _2:list) => list = TypesJS.map as any; +export const map: (_1:Belt_List_t, _2:((_1:T1) => T2)) => Belt_List_t = TypesJS.map as any; export const swap: (tree:tree) => tree = TypesJS.swap as any; @@ -114,6 +112,4 @@ export const testInstantiateTypeParameter: (x:instantiateTypeParameter) => insta export const currentTime: Date = TypesJS.currentTime as any; -export const i64Const: i64B = TypesJS.i64Const as any; - export const optFunction: (undefined | (() => number)) = TypesJS.optFunction as any; diff --git a/jscomp/gentype_tests/typescript-react-example/src/nested/Types.res b/jscomp/gentype_tests/typescript-react-example/src/nested/Types.res index 189f4064bf..4ca499ed6e 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/nested/Types.res +++ b/jscomp/gentype_tests/typescript-react-example/src/nested/Types.res @@ -4,7 +4,7 @@ @genType let someIntList = list{1, 2, 3} -@genType let map = List.map +@genType let map = Belt.List.map @genType type typeWithVars<'x, 'y, 'z> = @@ -126,12 +126,6 @@ type vector<'a> = ('a, 'a) @genType let currentTime = Js.Date.make() -@genType type i64A = Int64.t - -@genType type i64B = int64 - -@genType let i64Const: i64B = 34L - @genType let optFunction = Some(() => 3) module ObjectId: { diff --git a/jscomp/gentype_tests/typescript-react-example/src/nested/Types.res.js b/jscomp/gentype_tests/typescript-react-example/src/nested/Types.res.js index 11917c6506..0fcd610585 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/nested/Types.res.js +++ b/jscomp/gentype_tests/typescript-react-example/src/nested/Types.res.js @@ -1,6 +1,6 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as List from "rescript/lib/es6/list.js"; +import * as Belt_List from "rescript/lib/es6/belt_List.js"; import * as Belt_Option from "rescript/lib/es6/belt_Option.js"; function swap(tree) { @@ -72,7 +72,7 @@ let someIntList = { } }; -let map = List.map; +let map = Belt_List.map; let stringT = "a"; @@ -80,11 +80,6 @@ let jsStringT = "a"; let jsString2T = "a"; -let i64Const = [ - 0, - 34 -]; - export { someIntList, map, @@ -102,7 +97,6 @@ export { setMatch, testInstantiateTypeParameter, currentTime, - i64Const, optFunction, ObjectId, } diff --git a/jscomp/gentype_tests/typescript-react-example/src/shims/Belt.shim.ts b/jscomp/gentype_tests/typescript-react-example/src/shims/Belt.shim.ts new file mode 100644 index 0000000000..18897a9b0c --- /dev/null +++ b/jscomp/gentype_tests/typescript-react-example/src/shims/Belt.shim.ts @@ -0,0 +1,3 @@ +import type { list } from "./RescriptPervasives.shim"; + +export type List_t = list; diff --git a/jscomp/ml/ast_async.ml b/jscomp/ml/ast_async.ml index ad538c9270..a758ae29ba 100644 --- a/jscomp/ml/ast_async.ml +++ b/jscomp/ml/ast_async.ml @@ -6,7 +6,7 @@ let add_promise_type ?(loc = Location.none) ~async if async then let unsafe_async = Ast_helper.Exp.ident ~loc - {txt = Ldot (Lident Js_runtime_modules.promise, "unsafe_async"); loc} + {txt = Ldot (Lident Primitive_modules.promise, "unsafe_async"); loc} in Ast_helper.Exp.apply ~loc unsafe_async [(Nolabel, result)] else result diff --git a/jscomp/ml/ast_await.ml b/jscomp/ml/ast_await.ml index c5fc0c52ae..4cf7461979 100644 --- a/jscomp/ml/ast_await.ml +++ b/jscomp/ml/ast_await.ml @@ -5,7 +5,7 @@ let create_await_expression (e : Parsetree.expression) = let loc = {e.pexp_loc with loc_ghost = true} in let unsafe_await = Ast_helper.Exp.ident ~loc - {txt = Ldot (Lident Js_runtime_modules.promise, "unsafe_await"); loc} + {txt = Ldot (Lident Primitive_modules.promise, "unsafe_await"); loc} in Ast_helper.Exp.apply ~loc unsafe_await [(Nolabel, e)] @@ -24,7 +24,7 @@ let create_await_module_expression ~module_type_lid (e : Parsetree.module_expr) (Exp.apply ~loc:e.pmod_loc (Exp.ident ~loc:e.pmod_loc { - txt = Longident.Ldot (Lident Js_runtime_modules.promise, "import"); + txt = Longident.Ldot (Lident Primitive_modules.module_, "import"); loc = e.pmod_loc; }) [ diff --git a/jscomp/ml/ctype.ml b/jscomp/ml/ctype.ml index 950a1a598f..0337f008c4 100644 --- a/jscomp/ml/ctype.ml +++ b/jscomp/ml/ctype.ml @@ -1893,11 +1893,7 @@ let is_instantiable env p = (* PR#7113: -safe-string should be a global property *) -let compatible_paths p1 p2 = - let open Predef in - Path.same p1 p2 || - Path.same p1 path_bytes && Path.same p2 path_string || - Path.same p1 path_string && Path.same p2 path_bytes +let compatible_paths p1 p2 = Path.same p1 p2 (* Check for datatypes carefully; see PR#6348 *) let rec expands_to_datatype env ty = diff --git a/jscomp/ml/lambda.ml b/jscomp/ml/lambda.ml index 8b7489402f..8b3a777e9d 100644 --- a/jscomp/ml/lambda.ml +++ b/jscomp/ml/lambda.ml @@ -13,20 +13,6 @@ (* *) (**************************************************************************) - - - - -type compile_time_constant = - | Big_endian - | Word_size - | Int_size - | Max_wosize - | Ostype_unix - | Ostype_win32 - | Ostype_cygwin - | Backend_type - type loc_kind = | Loc_FILE | Loc_LINE @@ -185,16 +171,18 @@ type immediate_or_pointer = | Immediate | Pointer - - type is_safe = | Safe | Unsafe type primitive = | Pidentity - | Pbytes_to_string | Pignore + | Pdebugger + | Ptypeof + | Pnull + | Pundefined + | Pfn_arity | Prevapply | Pdirapply | Ploc of loc_kind @@ -204,9 +192,6 @@ type primitive = | Pmakeblock of tag_info | Pfield of int * field_dbg_info | Psetfield of int * set_field_dbg_info - - - | Pduprecord (* Force lazy values *) | Plazyforce @@ -214,71 +199,99 @@ type primitive = | Pccall of Primitive.description (* Exceptions *) | Praise of raise_kind + (* object operations *) + | Pobjcomp of comparison + | Pobjorder + | Pobjmin + | Pobjmax + | Pobjtag + | Pobjsize (* Boolean operations *) | Psequand | Psequor | Pnot + | Pboolcomp of comparison + | Pboolorder | Pboolmin | Pboolmax (* Integer operations *) | Pnegint | Paddint | Psubint | Pmulint | Pdivint of is_safe | Pmodint of is_safe | Pandint | Porint | Pxorint | Plslint | Plsrint | Pasrint | Pintcomp of comparison + | Pintorder | Pintmin | Pintmax | Poffsetint of int | Poffsetref of int (* Float operations *) | Pintoffloat | Pfloatofint - | Pnegfloat | Pabsfloat + | Pnegfloat | Pabsfloat | Pmodfloat | Paddfloat | Psubfloat | Pmulfloat | Pdivfloat | Pfloatcomp of comparison + | Pfloatorder | Pfloatmin | Pfloatmax (* BigInt operations *) | Pnegbigint | Paddbigint | Psubbigint | Ppowbigint | Pmulbigint | Pdivbigint | Pmodbigint | Pandbigint | Porbigint | Pxorbigint | Plslbigint | Pasrbigint | Pbigintcomp of comparison + | Pbigintorder | Pbigintmin | Pbigintmax (* String operations *) | Pstringlength | Pstringrefu | Pstringrefs - | Pbyteslength | Pbytesrefu | Pbytessetu | Pbytesrefs | Pbytessets + | Pstringcomp of comparison + | Pstringorder | Pstringmin | Pstringmax + | Pstringadd (* Array operations *) - | Pmakearray of Asttypes.mutable_flag - | Parraylength - | Parrayrefu - | Parraysetu - | Parrayrefs - | Parraysets + | Pmakearray of Asttypes.mutable_flag + | Parraylength + | Parrayrefu + | Parraysetu + | Parrayrefs + | Parraysets + (* List primitives *) + | Pmakelist of Asttypes.mutable_flag + (* dict primitives *) + | Pmakedict + (* promise *) + | Pawait + (* module *) + | Pimport + | Pinit_mod + | Pupdate_mod + (* hash *) + | Phash + | Phash_mixint + | Phash_mixstring + | Phash_finalmix (* Test if the argument is a block or an immediate integer *) | Pisint (* Test if the (integer) argument is outside an interval *) | Pisout - | Pbintofint of boxed_integer - | Pintofbint of boxed_integer - | Pcvtbint of boxed_integer (*source*) * boxed_integer (*destination*) - | Pnegbint of boxed_integer - | Paddbint of boxed_integer - | Psubbint of boxed_integer - | Pmulbint of boxed_integer - | Pdivbint of { size : boxed_integer; is_safe : is_safe } - | Pmodbint of { size : boxed_integer; is_safe : is_safe } - | Pandbint of boxed_integer - | Porbint of boxed_integer - | Pxorbint of boxed_integer - | Plslbint of boxed_integer - | Plsrbint of boxed_integer - | Pasrbint of boxed_integer - | Pbintcomp of boxed_integer * comparison - | Pctconst of compile_time_constant + (* Test if the argument is null or undefined *) + | Pisnullable + (* exn *) | Pcreate_extension of string + | Pextension_slot_eq + | Pwrap_exn + (* js *) + | Pcurry_apply of int + | Pjscomp of comparison + | Pundefined_to_opt + | Pnull_to_opt + | Pnullable_to_opt + | Pis_not_none + | Pval_from_option + | Pval_from_option_not_nest + | Pis_poly_var_block + | Pjs_raw_expr + | Pjs_raw_stmt + | Pjs_fn_make of int + | Pjs_fn_make_unit + | Pjs_fn_method + | Pjs_unsafe_downgrade + and comparison = Ceq | Cneq | Clt | Cgt | Cle | Cge and value_kind = Pgenval - - -and boxed_integer = Primitive.boxed_integer = - Pbigint | Pint32 | Pint64 - - and raise_kind = | Raise_regular | Raise_reraise diff --git a/jscomp/ml/lambda.mli b/jscomp/ml/lambda.mli index 87125870c5..8ec0d24459 100644 --- a/jscomp/ml/lambda.mli +++ b/jscomp/ml/lambda.mli @@ -17,16 +17,6 @@ open Asttypes -type compile_time_constant = - | Big_endian - | Word_size - | Int_size - | Max_wosize - | Ostype_unix - | Ostype_win32 - | Ostype_cygwin - | Backend_type - type loc_kind = | Loc_FILE | Loc_LINE @@ -160,15 +150,19 @@ type pointer_info = type primitive = | Pidentity - | Pbytes_to_string | Pignore + | Pdebugger + | Ptypeof + | Pnull + | Pundefined + | Pfn_arity | Prevapply | Pdirapply | Ploc of loc_kind (* Globals *) | Pgetglobal of Ident.t (* Operations on heap blocks *) - | Pmakeblock of tag_info + | Pmakeblock of tag_info | Pfield of int * field_dbg_info | Psetfield of int * set_field_dbg_info @@ -180,72 +174,99 @@ type primitive = | Pccall of Primitive.description (* Exceptions *) | Praise of raise_kind + (* object primitives *) + | Pobjcomp of comparison + | Pobjorder + | Pobjmin + | Pobjmax + | Pobjtag + | Pobjsize (* Boolean operations *) | Psequand | Psequor | Pnot + | Pboolcomp of comparison + | Pboolorder | Pboolmin | Pboolmax (* Integer operations *) | Pnegint | Paddint | Psubint | Pmulint | Pdivint of is_safe | Pmodint of is_safe | Pandint | Porint | Pxorint | Plslint | Plsrint | Pasrint | Pintcomp of comparison + | Pintorder | Pintmin | Pintmax | Poffsetint of int | Poffsetref of int (* Float operations *) | Pintoffloat | Pfloatofint - | Pnegfloat | Pabsfloat + | Pnegfloat | Pabsfloat | Pmodfloat | Paddfloat | Psubfloat | Pmulfloat | Pdivfloat | Pfloatcomp of comparison + | Pfloatorder | Pfloatmin | Pfloatmax (* BigInt operations *) | Pnegbigint | Paddbigint | Psubbigint | Ppowbigint | Pmulbigint | Pdivbigint | Pmodbigint | Pandbigint | Porbigint | Pxorbigint | Plslbigint | Pasrbigint | Pbigintcomp of comparison + | Pbigintorder | Pbigintmin | Pbigintmax (* String operations *) | Pstringlength | Pstringrefu | Pstringrefs - | Pbyteslength | Pbytesrefu | Pbytessetu | Pbytesrefs | Pbytessets + | Pstringcomp of comparison + | Pstringorder | Pstringmin | Pstringmax + | Pstringadd (* Array operations *) - | Pmakearray of mutable_flag + | Pmakearray of mutable_flag | Parraylength | Parrayrefu | Parraysetu | Parrayrefs | Parraysets + (* List primitives *) + | Pmakelist of Asttypes.mutable_flag + (* dict primitives *) + | Pmakedict + (* promise *) + | Pawait + (* modules *) + | Pimport + | Pinit_mod + | Pupdate_mod + (* hash *) + | Phash + | Phash_mixint + | Phash_mixstring + | Phash_finalmix (* Test if the argument is a block or an immediate integer *) | Pisint (* Test if the (integer) argument is outside an interval *) | Pisout - (* Operations on boxed integers (Nativeint.t, Int32.t, Int64.t) *) - | Pbintofint of boxed_integer - | Pintofbint of boxed_integer - | Pcvtbint of boxed_integer (*source*) * boxed_integer (*destination*) - | Pnegbint of boxed_integer - | Paddbint of boxed_integer - | Psubbint of boxed_integer - | Pmulbint of boxed_integer - | Pdivbint of { size : boxed_integer; is_safe : is_safe } - | Pmodbint of { size : boxed_integer; is_safe : is_safe } - | Pandbint of boxed_integer - | Porbint of boxed_integer - | Pxorbint of boxed_integer - | Plslbint of boxed_integer - | Plsrbint of boxed_integer - | Pasrbint of boxed_integer - | Pbintcomp of boxed_integer * comparison - | Pctconst of compile_time_constant + (* Test if the argument is null or undefined *) + | Pisnullable + (* exn *) | Pcreate_extension of string + | Pextension_slot_eq + | Pwrap_exn + (* js *) + | Pcurry_apply of int + | Pjscomp of comparison + | Pundefined_to_opt + | Pnull_to_opt + | Pnullable_to_opt + | Pis_not_none + | Pval_from_option + | Pval_from_option_not_nest + | Pis_poly_var_block + | Pjs_raw_expr + | Pjs_raw_stmt + | Pjs_fn_make of int + | Pjs_fn_make_unit + | Pjs_fn_method + | Pjs_unsafe_downgrade + and comparison = Ceq | Cneq | Clt | Cgt | Cle | Cge - and value_kind = Pgenval - -and boxed_integer = Primitive.boxed_integer = - Pbigint | Pint32 | Pint64 - - and raise_kind = | Raise_regular | Raise_reraise diff --git a/jscomp/ml/matching.ml b/jscomp/ml/matching.ml index d1fe30cc50..2544cdb072 100644 --- a/jscomp/ml/matching.ml +++ b/jscomp/ml/matching.ml @@ -1313,18 +1313,6 @@ let matcher_constr cstr = match cstr.cstr_arity with | Tpat_any -> Parmatch.omegas cstr.cstr_arity @ rem | _ -> raise NoMatch -let is_not_none_bs_primitve : Lambda.primitive = - Pccall - (Primitive.simple ~name:"#is_not_none" ~arity:1 ~alloc:false) - -let val_from_option_bs_primitive : Lambda.primitive = - Pccall - (Primitive.simple ~name:"#val_from_option" ~arity:1 ~alloc:true) - -let val_from_unnest_option_bs_primitive : Lambda.primitive = - Pccall - (Primitive.simple ~name:"#val_from_unnest_option" ~arity:1 ~alloc:true) - let make_constr_matching p def ctx = function [] -> fatal_error "Matching.make_constr_matching" | ((arg, _mut) :: argl) -> @@ -1345,8 +1333,8 @@ let make_constr_matching p def ctx = function pat_type ; pat_env } ]) when Typeopt.type_cannot_contain_undefined pat_type pat_env - -> val_from_unnest_option_bs_primitive - | _ -> val_from_option_bs_primitive in + -> Pval_from_option_not_nest + | _ -> Pval_from_option in (Lprim (from_option, [arg], p.pat_loc), Alias) :: argl end | Cstr_constant _ @@ -1498,7 +1486,7 @@ let get_mod_field modname field = let code_force = - get_mod_field "CamlinternalLazy" "force" + get_mod_field Primitive_modules.lazy_ "force" ;; (* inline_lazy_force inlines the beginning of the code of Lazy.force. When @@ -1678,18 +1666,6 @@ let divide_array ctx pm = let strings_test_threshold = 8 -let prim_string_notequal = - Pccall(Primitive.simple - ~name:"caml_string_notequal" - ~arity:2 - ~alloc:false) - -let prim_string_compare = - Pccall(Primitive.simple - ~name:"caml_string_compare" - ~arity:2 - ~alloc:false) - let bind_sw arg k = match arg with | Lvar _ -> k arg | _ -> @@ -1713,7 +1689,7 @@ let make_string_test_sequence loc arg sw d = (fun (s,lam) k -> Lifthenelse (Lprim - (prim_string_notequal, + (Pstringcomp Cneq, [arg; Lconst (Const_immstring s)], loc), k,lam)) sw d) @@ -1744,7 +1720,7 @@ let rec do_make_string_test_tree loc arg sw delta d = let lt,(s,act),gt = split len sw in bind_sw (Lprim - (prim_string_compare, + (Pstringcomp Ceq, [arg; Lconst (Const_immstring s)], loc)) (fun r -> tree_way_test loc r @@ -2225,16 +2201,8 @@ let combine_constant names loc arg cst partial ctx def fail (Pfloatcomp Cneq) (Pfloatcomp Clt) arg const_lambda_list - | Const_int32 _ -> - make_test_sequence loc - fail - (Pbintcomp(Pint32, Cneq)) (Pbintcomp(Pint32, Clt)) - arg const_lambda_list - | Const_int64 _ -> - make_test_sequence loc - fail - (Pbintcomp(Pint64, Cneq)) (Pbintcomp(Pint64, Clt)) - arg const_lambda_list + | Const_int32 _ -> assert false + | Const_int64 _ -> assert false | Const_bigint _ -> make_test_sequence loc fail @@ -2284,8 +2252,6 @@ let get_extension_cases tag_lambda_list = split_rec tag_lambda_list -let extension_slot_eq = - Pccall (Primitive.simple ~name:"#extension_slot_eq" ~arity:2 ~alloc:false) let combine_constructor sw_names loc arg ex_pat cstr partial ctx def (tag_lambda_list, total1, pats) = if cstr.cstr_consts < 0 then begin @@ -2310,7 +2276,7 @@ let combine_constructor sw_names loc arg ex_pat cstr partial ctx def List.fold_right (fun (path, act) rem -> let ext = transl_extension_path ex_pat.pat_env path in - Lifthenelse(Lprim(extension_slot_eq , [Lvar tag; ext], loc), + Lifthenelse(Lprim(Pextension_slot_eq, [Lvar tag; ext], loc), act, rem)) extension_cases default @@ -2344,7 +2310,7 @@ let combine_constructor sw_names loc arg ex_pat cstr partial ctx def case *) let arg = if Datarepr.constructor_has_optional_shape cstr then - Lprim(is_not_none_bs_primitve , [arg], loc) + Lprim(Pis_not_none, [arg], loc) else arg in Lifthenelse(arg, act2, act1) @@ -2440,7 +2406,7 @@ let combine_variant names loc row arg partial ctx def else num_constr := max_int; let test_int_or_block arg if_int if_block = - Lifthenelse(Lprim (Pccall(Primitive.simple ~name:"#is_poly_var_block" ~arity:1 ~alloc:false), [arg], loc), if_block, if_int) in + Lifthenelse(Lprim (Pis_poly_var_block, [arg], loc), if_block, if_int) in let sig_complete = List.length tag_lambda_list = !num_constr and one_action = same_actions tag_lambda_list in (* reduandant work under bs context *) let fail, local_jumps = diff --git a/jscomp/ml/predef.ml b/jscomp/ml/predef.ml index 4258d3ef2f..c1fcd5ad3d 100644 --- a/jscomp/ml/predef.ml +++ b/jscomp/ml/predef.ml @@ -31,7 +31,6 @@ let ident_create_predef_exn = wrap Ident.create_predef_exn let ident_int = ident_create "int" and ident_char = ident_create "char" -and ident_bytes = ident_create "bytes" and ident_float = ident_create "float" and ident_bool = ident_create "bool" and ident_unit = ident_create "unit" @@ -41,16 +40,11 @@ and ident_list = ident_create "list" and ident_option = ident_create "option" and ident_result = ident_create "result" and ident_dict = ident_create "dict" - -and ident_int64 = ident_create "int64" and ident_bigint = ident_create "bigint" and ident_lazy_t = ident_create "lazy_t" and ident_string = ident_create "string" and ident_extension_constructor = ident_create "extension_constructor" -and ident_floatarray = ident_create "floatarray" - and ident_unknown = ident_create "unknown" - and ident_promise = ident_create "promise" and ident_uncurried = ident_create "function$" @@ -59,23 +53,21 @@ type test = | For_sure_no | NA -let type_is_builtin_path_but_option (p : Path.t) : test = +let type_is_builtin_path_but_option (p : Path.t) : test = match p with - | Pident {stamp} -> - if - stamp >= ident_int.stamp - && stamp <= ident_floatarray.stamp - then - if (stamp = ident_option.stamp) - || (stamp = ident_unit.stamp) then - For_sure_no - else For_sure_yes - else NA + | Pident {stamp} + when stamp = ident_option.stamp + -> For_sure_no + | Pident {stamp} + when stamp = ident_unit.stamp + -> For_sure_no + | Pident {stamp} + when stamp >= ident_int.stamp && stamp <= ident_uncurried.stamp + -> For_sure_yes | _ -> NA let path_int = Pident ident_int and path_char = Pident ident_char -and path_bytes = Pident ident_bytes and path_float = Pident ident_float and path_bool = Pident ident_bool and path_unit = Pident ident_unit @@ -85,23 +77,16 @@ and path_list = Pident ident_list and path_option = Pident ident_option and path_result = Pident ident_result and path_dict = Pident ident_dict - - -and path_int64 = Pident ident_int64 and path_bigint = Pident ident_bigint and path_lazy_t = Pident ident_lazy_t and path_string = Pident ident_string - and path_unkonwn = Pident ident_unknown and path_extension_constructor = Pident ident_extension_constructor -and path_floatarray = Pident ident_floatarray - and path_promise = Pident ident_promise and path_uncurried = Pident ident_uncurried let type_int = newgenty (Tconstr(path_int, [], ref Mnil)) and type_char = newgenty (Tconstr(path_char, [], ref Mnil)) -and type_bytes = newgenty (Tconstr(path_bytes, [], ref Mnil)) and type_float = newgenty (Tconstr(path_float, [], ref Mnil)) and type_bool = newgenty (Tconstr(path_bool, [], ref Mnil)) and type_unit = newgenty (Tconstr(path_unit, [], ref Mnil)) @@ -112,7 +97,6 @@ and type_option t = newgenty (Tconstr(path_option, [t], ref Mnil)) and type_result t1 t2 = newgenty (Tconstr(path_result, [t1; t2], ref Mnil)) and type_dict t = newgenty (Tconstr(path_dict, [t], ref Mnil)) -and type_int64 = newgenty (Tconstr(path_int64, [], ref Mnil)) and type_bigint = newgenty (Tconstr(path_bigint, [], ref Mnil)) and type_lazy_t t = newgenty (Tconstr(path_lazy_t, [t], ref Mnil)) and type_string = newgenty (Tconstr(path_string, [], ref Mnil)) @@ -120,7 +104,6 @@ and type_string = newgenty (Tconstr(path_string, [], ref Mnil)) and type_unknown = newgenty (Tconstr(path_unkonwn, [], ref Mnil)) and type_extension_constructor = newgenty (Tconstr(path_extension_constructor, [], ref Mnil)) -and type_floatarray = newgenty (Tconstr(path_floatarray, [], ref Mnil)) let ident_match_failure = ident_create_predef_exn "Match_failure" @@ -301,7 +284,6 @@ let common_initial_env add_type add_extension empty_env = [newgenty (Ttuple[type_string; type_int; type_int])] ( add_exception ident_undefined_recursive_module [newgenty (Ttuple[type_string; type_int; type_int])] ( - add_type ident_int64 decl_abstr ( add_type ident_bigint decl_abstr ( add_type ident_lazy_t decl_lazy_t ( @@ -319,18 +301,16 @@ let common_initial_env add_type add_extension empty_env = add_type ident_string decl_abstr ( add_type ident_int decl_abstr_imm ( add_type ident_extension_constructor decl_abstr ( - add_type ident_floatarray decl_abstr ( add_type ident_promise decl_promise ( - empty_env)))))))))))))))))))))))))))) + empty_env)))))))))))))))))))))))))) let build_initial_env add_type add_exception empty_env = let common = common_initial_env add_type add_exception empty_env in - let res = add_type ident_bytes decl_abstr common in let decl_type_char = {decl_abstr with type_manifest = Some type_int; type_private = Private} in - add_type ident_char decl_type_char res + add_type ident_char decl_type_char common let builtin_values = diff --git a/jscomp/ml/predef.mli b/jscomp/ml/predef.mli index a8049b5325..8de1073fe1 100644 --- a/jscomp/ml/predef.mli +++ b/jscomp/ml/predef.mli @@ -20,7 +20,6 @@ open Types val type_int: type_expr val type_char: type_expr val type_string: type_expr -val type_bytes: type_expr val type_float: type_expr val type_bool: type_expr val type_unit: type_expr @@ -31,16 +30,13 @@ val type_option: type_expr -> type_expr val type_result: type_expr -> type_expr -> type_expr val type_dict: type_expr -> type_expr -val type_int64: type_expr val type_bigint: type_expr val type_lazy_t: type_expr -> type_expr val type_extension_constructor:type_expr -val type_floatarray:type_expr val path_int: Path.t val path_char: Path.t val path_string: Path.t -val path_bytes: Path.t val path_float: Path.t val path_bool: Path.t val path_unit: Path.t @@ -51,11 +47,9 @@ val path_option: Path.t val path_result: Path.t val path_dict: Path.t -val path_int64: Path.t val path_bigint: Path.t val path_lazy_t: Path.t val path_extension_constructor: Path.t -val path_floatarray: Path.t val path_promise: Path.t val path_uncurried: Path.t diff --git a/jscomp/ml/printlambda.ml b/jscomp/ml/printlambda.ml index 4dc4e7705e..05bd881465 100644 --- a/jscomp/ml/printlambda.ml +++ b/jscomp/ml/printlambda.ml @@ -46,10 +46,6 @@ let rec struct_const ppf = function | Const_false -> fprintf ppf "false" | Const_true -> fprintf ppf "true" -let boxed_integer_name = function - | Pbigint -> "bigint" - | Pint32 -> "int32" - | Pint64 -> "int64" let value_kind = function | Pgenval -> "" @@ -60,20 +56,6 @@ let value_kind = function | Pfloatval -> "float" | Pboxedintval bi -> boxed_integer_name bi *) -let print_boxed_integer_conversion ppf bi1 bi2 = - fprintf ppf "%s_of_%s" (boxed_integer_name bi2) (boxed_integer_name bi1) - -let boxed_integer_mark name = function - | Pbigint -> Printf.sprintf "BigInt.%s" name - | Pint32 -> Printf.sprintf "Int32.%s" name - | Pint64 -> Printf.sprintf "Int64.%s" name - -let print_boxed_integer name ppf bi = - fprintf ppf "%s" (boxed_integer_mark name bi);; - - - - let string_of_loc_kind = function | Loc_FILE -> "loc_FILE" | Loc_LINE -> "loc_LINE" @@ -122,8 +104,12 @@ let print_taginfo ppf = function let primitive ppf = function | Pidentity -> fprintf ppf "id" - | Pbytes_to_string -> fprintf ppf "bytes_to_string" | Pignore -> fprintf ppf "ignore" + | Pdebugger -> fprintf ppf "debugger" + | Ptypeof -> fprintf ppf "typeof" + | Pnull -> fprintf ppf "null" + | Pundefined -> fprintf ppf "undefined" + | Pfn_arity -> fprintf ppf "fn.length" | Prevapply -> fprintf ppf "revapply" | Pdirapply -> fprintf ppf "dirapply" | Ploc kind -> fprintf ppf "%s" (string_of_loc_kind kind) @@ -137,9 +123,29 @@ let primitive ppf = function | Plazyforce -> fprintf ppf "force" | Pccall p -> fprintf ppf "%s" p.prim_name | Praise k -> fprintf ppf "%s" (Lambda.raise_kind k) + | Pobjcomp(Ceq) -> fprintf ppf "==" + | Pobjcomp(Cneq) -> fprintf ppf "!=" + | Pobjcomp(Clt) -> fprintf ppf "<" + | Pobjcomp(Cle) -> fprintf ppf "<=" + | Pobjcomp(Cgt) -> fprintf ppf ">" + | Pobjcomp(Cge) -> fprintf ppf ">=" + | Pobjorder -> fprintf ppf "compare" + | Pobjmin -> fprintf ppf "min" + | Pobjmax -> fprintf ppf "max" + | Pobjtag -> fprintf ppf "tag" + | Pobjsize -> fprintf ppf "length" | Psequand -> fprintf ppf "&&" | Psequor -> fprintf ppf "||" | Pnot -> fprintf ppf "not" + | Pboolcomp(Ceq) -> fprintf ppf "==" + | Pboolcomp(Cneq) -> fprintf ppf "!=" + | Pboolcomp(Clt) -> fprintf ppf "<" + | Pboolcomp(Cle) -> fprintf ppf "<=" + | Pboolcomp(Cgt) -> fprintf ppf ">" + | Pboolcomp(Cge) -> fprintf ppf ">=" + | Pboolorder -> fprintf ppf "compare" + | Pboolmin -> fprintf ppf "min" + | Pboolmax -> fprintf ppf "max" | Pnegint -> fprintf ppf "~" | Paddint -> fprintf ppf "+" | Psubint -> fprintf ppf "-" @@ -160,6 +166,9 @@ let primitive ppf = function | Pintcomp(Cle) -> fprintf ppf "<=" | Pintcomp(Cgt) -> fprintf ppf ">" | Pintcomp(Cge) -> fprintf ppf ">=" + | Pintorder -> fprintf ppf "compare" + | Pintmin -> fprintf ppf "min" + | Pintmax -> fprintf ppf "max" | Poffsetint n -> fprintf ppf "%i+" n | Poffsetref n -> fprintf ppf "+:=%i"n | Pintoffloat -> fprintf ppf "int_of_float" @@ -170,12 +179,16 @@ let primitive ppf = function | Psubfloat -> fprintf ppf "-." | Pmulfloat -> fprintf ppf "*." | Pdivfloat -> fprintf ppf "/." + | Pmodfloat -> fprintf ppf "mod" | Pfloatcomp(Ceq) -> fprintf ppf "==." | Pfloatcomp(Cneq) -> fprintf ppf "!=." | Pfloatcomp(Clt) -> fprintf ppf "<." | Pfloatcomp(Cle) -> fprintf ppf "<=." | Pfloatcomp(Cgt) -> fprintf ppf ">." | Pfloatcomp(Cge) -> fprintf ppf ">=." + | Pfloatorder -> fprintf ppf "compare" + | Pfloatmin -> fprintf ppf "min" + | Pfloatmax -> fprintf ppf "max" | Pnegbigint -> fprintf ppf "~" | Paddbigint -> fprintf ppf "+" | Psubbigint -> fprintf ppf "-" @@ -194,15 +207,22 @@ let primitive ppf = function | Pbigintcomp(Cle) -> fprintf ppf "<=," | Pbigintcomp(Cgt) -> fprintf ppf ">," | Pbigintcomp(Cge) -> fprintf ppf ">=," + | Pbigintorder -> fprintf ppf "compare" + | Pbigintmin -> fprintf ppf "min" + | Pbigintmax -> fprintf ppf "max" | Pstringlength -> fprintf ppf "string.length" | Pstringrefu -> fprintf ppf "string.unsafe_get" | Pstringrefs -> fprintf ppf "string.get" - | Pbyteslength -> fprintf ppf "bytes.length" - | Pbytesrefu -> fprintf ppf "bytes.unsafe_get" - | Pbytessetu -> fprintf ppf "bytes.unsafe_set" - | Pbytesrefs -> fprintf ppf "bytes.get" - | Pbytessets -> fprintf ppf "bytes.set" - + | Pstringcomp(Ceq) -> fprintf ppf "==" + | Pstringcomp(Cneq) -> fprintf ppf "!=" + | Pstringcomp(Clt) -> fprintf ppf "<" + | Pstringcomp(Cle) -> fprintf ppf "<=" + | Pstringcomp(Cgt) -> fprintf ppf ">" + | Pstringcomp(Cge) -> fprintf ppf ">=" + | Pstringorder -> fprintf ppf "compare" + | Pstringmin -> fprintf ppf "min" + | Pstringmax -> fprintf ppf "max" + | Pstringadd -> fprintf ppf "string.concat" | Parraylength -> fprintf ppf "array.length" | Pmakearray Mutable -> fprintf ppf "makearray" | Pmakearray Immutable -> fprintf ppf "makearray_imm" @@ -210,136 +230,43 @@ let primitive ppf = function | Parraysetu -> fprintf ppf "array.unsafe_set" | Parrayrefs -> fprintf ppf "array.get" | Parraysets -> fprintf ppf "array.set" - | Pctconst c -> - let const_name = match c with - | Big_endian -> "big_endian" - | Word_size -> "word_size" - | Int_size -> "int_size" - | Max_wosize -> "max_wosize" - | Ostype_unix -> "ostype_unix" - | Ostype_win32 -> "ostype_win32" - | Ostype_cygwin -> "ostype_cygwin" - | Backend_type -> "backend_type" in - fprintf ppf "sys.constant_%s" const_name + | Pmakelist Mutable -> fprintf ppf "makelist" + | Pmakelist Immutable -> fprintf ppf "makelist_imm" + | Pmakedict -> fprintf ppf "makedict" | Pisint -> fprintf ppf "isint" | Pisout -> fprintf ppf "isout" - | Pbintofint bi -> print_boxed_integer "of_int" ppf bi - | Pintofbint bi -> print_boxed_integer "to_int" ppf bi - | Pcvtbint (bi1, bi2) -> print_boxed_integer_conversion ppf bi1 bi2 - | Pnegbint bi -> print_boxed_integer "neg" ppf bi - | Paddbint bi -> print_boxed_integer "add" ppf bi - | Psubbint bi -> print_boxed_integer "sub" ppf bi - | Pmulbint bi -> print_boxed_integer "mul" ppf bi - | Pdivbint { size = bi; is_safe = Safe } -> - print_boxed_integer "div" ppf bi - | Pdivbint { size = bi; is_safe = Unsafe } -> - print_boxed_integer "div_unsafe" ppf bi - | Pmodbint { size = bi; is_safe = Safe } -> - print_boxed_integer "mod" ppf bi - | Pmodbint { size = bi; is_safe = Unsafe } -> - print_boxed_integer "mod_unsafe" ppf bi - | Pandbint bi -> print_boxed_integer "and" ppf bi - | Porbint bi -> print_boxed_integer "or" ppf bi - | Pxorbint bi -> print_boxed_integer "xor" ppf bi - | Plslbint bi -> print_boxed_integer "lsl" ppf bi - | Plsrbint bi -> print_boxed_integer "lsr" ppf bi - | Pasrbint bi -> print_boxed_integer "asr" ppf bi - | Pbintcomp(bi, Ceq) -> print_boxed_integer "==" ppf bi - | Pbintcomp(bi, Cneq) -> print_boxed_integer "!=" ppf bi - | Pbintcomp(bi, Clt) -> print_boxed_integer "<" ppf bi - | Pbintcomp(bi, Cgt) -> print_boxed_integer ">" ppf bi - | Pbintcomp(bi, Cle) -> print_boxed_integer "<=" ppf bi - | Pbintcomp(bi, Cge) -> print_boxed_integer ">=" ppf bi - | Pcreate_extension s -> fprintf ppf "extension[%s]" s -let name_of_primitive = function - | Pidentity -> "Pidentity" - | Pbytes_to_string -> "Pbytes_to_string" - | Pignore -> "Pignore" - | Prevapply -> "Prevapply" - | Pdirapply -> "Pdirapply" - | Ploc _ -> "Ploc" - | Pgetglobal _ -> "Pgetglobal" - | Pmakeblock _ -> "Pmakeblock" - | Pfield _ -> "Pfield" - | Psetfield _ -> "Psetfield" - | Pduprecord -> "Pduprecord" - | Plazyforce -> "Plazyforce" - | Pccall _ -> "Pccall" - | Praise _ -> "Praise" - | Psequand -> "Psequand" - | Psequor -> "Psequor" - | Pnot -> "Pnot" - | Pnegint -> "Pnegint" - | Paddint -> "Paddint" - | Psubint -> "Psubint" - | Pmulint -> "Pmulint" - | Pdivint _ -> "Pdivint" - | Pmodint _ -> "Pmodint" - | Pandint -> "Pandint" - | Porint -> "Porint" - | Pxorint -> "Pxorint" - | Plslint -> "Plslint" - | Plsrint -> "Plsrint" - | Pasrint -> "Pasrint" - | Pintcomp _ -> "Pintcomp" - | Poffsetint _ -> "Poffsetint" - | Poffsetref _ -> "Poffsetref" - | Pintoffloat -> "Pintoffloat" - | Pfloatofint -> "Pfloatofint" - | Pnegfloat -> "Pnegfloat" - | Pabsfloat -> "Pabsfloat" - | Paddfloat -> "Paddfloat" - | Psubfloat -> "Psubfloat" - | Pmulfloat -> "Pmulfloat" - | Pdivfloat -> "Pdivfloat" - | Pfloatcomp _ -> "Pfloatcomp" - | Pnegbigint -> "Pnegbigint" - | Paddbigint -> "Paddbigint" - | Psubbigint -> "Psubbigint" - | Pmulbigint -> "Pmulbigint" - | Pdivbigint -> "Pdivbigint" - | Pmodbigint -> "Pmodbigint" - | Ppowbigint -> "Ppowbigint" - | Pandbigint -> "Pandbigint" - | Porbigint -> "Porbigint" - | Pxorbigint -> "Pxorbigint" - | Plslbigint -> "Plslbigint" - | Pasrbigint -> "Pasrbigint" - | Pbigintcomp _ -> "Pbigintcomp" - | Pstringlength -> "Pstringlength" - | Pstringrefu -> "Pstringrefu" - | Pstringrefs -> "Pstringrefs" - | Pbyteslength -> "Pbyteslength" - | Pbytesrefu -> "Pbytesrefu" - | Pbytessetu -> "Pbytessetu" - | Pbytesrefs -> "Pbytesrefs" - | Pbytessets -> "Pbytessets" - | Parraylength -> "Parraylength" - | Pmakearray _-> "Pmakearray" - | Parrayrefu -> "Parrayrefu" - | Parraysetu -> "Parraysetu" - | Parrayrefs -> "Parrayrefs" - | Parraysets -> "Parraysets" - | Pctconst _ -> "Pctconst" - | Pisint -> "Pisint" - | Pisout -> "Pisout" - | Pbintofint _ -> "Pbintofint" - | Pintofbint _ -> "Pintofbint" - | Pcvtbint _ -> "Pcvtbint" - | Pnegbint _ -> "Pnegbint" - | Paddbint _ -> "Paddbint" - | Psubbint _ -> "Psubbint" - | Pmulbint _ -> "Pmulbint" - | Pdivbint _ -> "Pdivbint" - | Pmodbint _ -> "Pmodbint" - | Pandbint _ -> "Pandbint" - | Porbint _ -> "Porbint" - | Pxorbint _ -> "Pxorbint" - | Plslbint _ -> "Plslbint" - | Plsrbint _ -> "Plsrbint" - | Pasrbint _ -> "Pasrbint" - | Pbintcomp _ -> "Pbintcomp" - | Pcreate_extension _ -> "Pcreate_extension" + | Pisnullable -> fprintf ppf "isnullable" + | Pcreate_extension s -> fprintf ppf "extension[%s]" s + | Pextension_slot_eq -> fprintf ppf "#extension_slot_eq" + | Pwrap_exn -> fprintf ppf "wrap_exn" + | Pawait -> fprintf ppf "await" + | Pimport -> fprintf ppf "import" + | Pinit_mod -> fprintf ppf "#init_mod" + | Pupdate_mod -> fprintf ppf "#update_mod" + | Phash -> fprintf ppf "hash" + | Phash_mixint -> fprintf ppf "hash_mix_int" + | Phash_mixstring -> fprintf ppf "hash_mix_string" + | Phash_finalmix -> fprintf ppf "hash_final_mix" + | Pcurry_apply i -> fprintf ppf "apply[%d]" i + | Pjscomp(Ceq) -> fprintf ppf "==" + | Pjscomp(Cneq) -> fprintf ppf "!=" + | Pjscomp(Clt) -> fprintf ppf "<" + | Pjscomp(Cle) -> fprintf ppf "<=" + | Pjscomp(Cgt) -> fprintf ppf ">" + | Pjscomp(Cge) -> fprintf ppf ">=" + | Pundefined_to_opt -> fprintf ppf "undefined_to_opt" + | Pnull_to_opt -> fprintf ppf "null_to_opt" + | Pnullable_to_opt -> fprintf ppf "nullable_to_opt" + | Pis_not_none -> fprintf ppf "#is_not_none" + | Pval_from_option -> fprintf ppf "#val_from_option" + | Pval_from_option_not_nest -> fprintf ppf "#val_from_option_not_nest" + | Pis_poly_var_block -> fprintf ppf "#is_poly_var_block" + | Pjs_raw_expr -> fprintf ppf "#raw_expr" + | Pjs_raw_stmt -> fprintf ppf "#raw_stmt" + | Pjs_fn_make arity -> fprintf ppf "#fn_mk(%d)" arity + | Pjs_fn_make_unit -> fprintf ppf "#fn_mk_unit" + | Pjs_fn_method -> fprintf ppf "#fn_method" + | Pjs_unsafe_downgrade -> fprintf ppf "#unsafe_downgrade" let function_attribute ppf { inline; is_a_functor; return_unit } = if is_a_functor then diff --git a/jscomp/ml/printlambda.mli b/jscomp/ml/printlambda.mli index d9d2420797..31e9657d96 100644 --- a/jscomp/ml/printlambda.mli +++ b/jscomp/ml/printlambda.mli @@ -19,7 +19,3 @@ open Format val structured_constant: formatter -> structured_constant -> unit val lambda: formatter -> lambda -> unit - -val primitive: formatter -> primitive -> unit -val name_of_primitive : primitive -> string -val value_kind : value_kind -> string diff --git a/jscomp/ml/rec_check.ml b/jscomp/ml/rec_check.ml index 6ec2ddde2f..bb2f981b3e 100644 --- a/jscomp/ml/rec_check.ml +++ b/jscomp/ml/rec_check.ml @@ -173,7 +173,7 @@ let build_unguarded_env : Ident.t list -> Env.env = let is_ref : Types.value_description -> bool = function | { Types.val_kind = - Types.Val_prim { Primitive.prim_name = "%makemutable"; prim_arity = 1 }; + Types.Val_prim { Primitive.prim_name = "%makeref"; prim_arity = 1 }; } -> true | _ -> false diff --git a/jscomp/ml/transl_recmodule.ml b/jscomp/ml/transl_recmodule.ml index cfef64ec74..0ec99a93b9 100644 --- a/jscomp/ml/transl_recmodule.ml +++ b/jscomp/ml/transl_recmodule.ml @@ -138,16 +138,6 @@ type t = Lambda.lambda (* Utilities for compiling "module rec" definitions *) -let bs_init_mod (args : t list) loc : t = - Lprim - (Pccall (Primitive.simple ~name:"#init_mod" ~arity:2 ~alloc:true), args, loc) - -let bs_update_mod (args : t list) loc : t = - Lprim - ( Pccall (Primitive.simple ~name:"#update_mod" ~arity:3 ~alloc:true), - args, - loc ) - type loc = t type shape = t @@ -164,7 +154,7 @@ let eval_rec_bindings_aux (bindings : binding list) (cont : t) : t = ( Strict, Pgenval, id, - bs_init_mod [ loc; shape ] Location.none, + Lprim (Pinit_mod, [ loc; shape ], Location.none), bind_inits rem acc ) in let rec bind_strict args acc = @@ -180,7 +170,7 @@ let eval_rec_bindings_aux (bindings : binding list) (cont : t) : t = | (_id, None, _rhs) :: rem -> patch_forwards rem | (id, Some (_loc, shape), rhs) :: rem -> Lsequence - ( bs_update_mod [ shape; Lvar id; rhs ] Location.none, + ( Lprim (Pupdate_mod, [ shape; Lvar id; rhs ], Location.none), patch_forwards rem ) in bind_inits bindings (bind_strict bindings (patch_forwards bindings)) diff --git a/jscomp/ml/translattribute.ml b/jscomp/ml/translattribute.ml index 5b2f896d8a..d286de95ef 100644 --- a/jscomp/ml/translattribute.ml +++ b/jscomp/ml/translattribute.ml @@ -72,7 +72,7 @@ let rec add_inline_attribute (expr : Lambda.lambda) loc attributes = Location.prerr_warning loc (Warnings.Duplicated_attribute "inline")); let attr = { attr with inline } in Lfunction { funct with attr } - | Lprim (Pccall {prim_name = "#fn_mk" | "#fn_mk_unit"} as p, [e], l), _ -> + | Lprim (Pjs_fn_make _ | Pjs_fn_make_unit as p, [e], l), _ -> Lambda.Lprim (p, [add_inline_attribute e loc attributes], l) | expr, (Always_inline) -> Location.prerr_warning loc (Warnings.Misplaced_attribute "inline1"); diff --git a/jscomp/ml/translcore.ml b/jscomp/ml/translcore.ml index 580ab01715..f9ea9c80e4 100644 --- a/jscomp/ml/translcore.ml +++ b/jscomp/ml/translcore.ml @@ -50,288 +50,205 @@ let transl_extension_constructor env path ext = (* Translation of primitives *) type specialized = { - gencomp : Lambda.primitive; + objcomp : Lambda.primitive; intcomp : Lambda.primitive; boolcomp : Lambda.primitive; floatcomp : Lambda.primitive; stringcomp : Lambda.primitive; - bytescomp : Lambda.primitive; - int64comp : Lambda.primitive; bigintcomp : Lambda.primitive; simplify_constant_constructor : bool; } -let arity2 name : Lambda.primitive = - Lambda.Pccall (Primitive.simple ~name ~arity:2 ~alloc:true) - let comparisons_table = - create_hashtable 11 - [ + create_hashtable + [| ( "%equal", { - gencomp = - Pccall (Primitive.simple ~name:"caml_equal" ~arity:2 ~alloc:true); + objcomp = Pobjcomp Ceq; intcomp = Pintcomp Ceq; - boolcomp = - Pccall - (Primitive.simple ~name:"caml_bool_equal" ~arity:2 ~alloc:false); + boolcomp = Pboolcomp Ceq; floatcomp = Pfloatcomp Ceq; - stringcomp = - Pccall - (Primitive.simple ~name:"caml_string_equal" ~arity:2 ~alloc:false); - bytescomp = - Pccall - (Primitive.simple ~name:"caml_bytes_equal" ~arity:2 ~alloc:false); - int64comp = Pbintcomp (Pint64, Ceq); + stringcomp = Pstringcomp Ceq; bigintcomp = Pbigintcomp Ceq; simplify_constant_constructor = true; } ); ( "%notequal", { - gencomp = - Pccall (Primitive.simple ~name:"caml_notequal" ~arity:2 ~alloc:true); + objcomp = Pobjcomp Cneq; intcomp = Pintcomp Cneq; - boolcomp = - Pccall - (Primitive.simple ~name:"caml_bool_notequal" ~arity:2 ~alloc:false); + boolcomp = Pboolcomp Cneq; floatcomp = Pfloatcomp Cneq; - stringcomp = - Pccall - (Primitive.simple ~name:"caml_string_notequal" ~arity:2 - ~alloc:false); - bytescomp = - Pccall - (Primitive.simple ~name:"caml_bytes_notequal" ~arity:2 - ~alloc:false); - int64comp = Pbintcomp (Pint64, Cneq); + stringcomp = Pstringcomp Cneq; bigintcomp = Pbigintcomp Cneq; simplify_constant_constructor = true; } ); ( "%lessthan", { - gencomp = - Pccall (Primitive.simple ~name:"caml_lessthan" ~arity:2 ~alloc:true); + objcomp = Pobjcomp Clt; intcomp = Pintcomp Clt; - boolcomp = - Pccall - (Primitive.simple ~name:"caml_bool_lessthan" ~arity:2 ~alloc:false); + boolcomp = Pboolcomp Clt; floatcomp = Pfloatcomp Clt; - stringcomp = - Pccall - (Primitive.simple ~name:"caml_string_lessthan" ~arity:2 - ~alloc:false); - bytescomp = - Pccall - (Primitive.simple ~name:"caml_bytes_lessthan" ~arity:2 - ~alloc:false); - int64comp = Pbintcomp (Pint64, Clt); + stringcomp = Pstringcomp Clt; bigintcomp = Pbigintcomp Clt; simplify_constant_constructor = false; } ); ( "%greaterthan", { - gencomp = - Pccall - (Primitive.simple ~name:"caml_greaterthan" ~arity:2 ~alloc:true); + objcomp = Pobjcomp Cgt; intcomp = Pintcomp Cgt; - boolcomp = - Pccall - (Primitive.simple ~name:"caml_bool_greaterthan" ~arity:2 - ~alloc:false); + boolcomp = Pboolcomp Cgt; floatcomp = Pfloatcomp Cgt; - stringcomp = - Pccall - (Primitive.simple ~name:"caml_string_greaterthan" ~arity:2 - ~alloc:false); - bytescomp = - Pccall - (Primitive.simple ~name:"caml_bytes_greaterthan" ~arity:2 - ~alloc:false); - int64comp = Pbintcomp (Pint64, Cgt); + stringcomp = Pstringcomp Cgt; bigintcomp = Pbigintcomp Cgt; simplify_constant_constructor = false; } ); ( "%lessequal", { - gencomp = - Pccall - (Primitive.simple ~name:"caml_lessequal" ~arity:2 ~alloc:true); + objcomp = Pobjcomp Cle; intcomp = Pintcomp Cle; - boolcomp = - Pccall - (Primitive.simple ~name:"caml_bool_lessequal" ~arity:2 - ~alloc:false); + boolcomp = Pboolcomp Cle; floatcomp = Pfloatcomp Cle; - stringcomp = - Pccall - (Primitive.simple ~name:"caml_string_lessequal" ~arity:2 - ~alloc:false); - bytescomp = - Pccall - (Primitive.simple ~name:"caml_bytes_lessequal" ~arity:2 - ~alloc:false); - int64comp = Pbintcomp (Pint64, Cle); + stringcomp = Pstringcomp Cle; bigintcomp = Pbigintcomp Cle; simplify_constant_constructor = false; } ); ( "%greaterequal", { - gencomp = - Pccall - (Primitive.simple ~name:"caml_greaterequal" ~arity:2 ~alloc:true); + objcomp = Pobjcomp Cge; intcomp = Pintcomp Cge; - boolcomp = - Pccall - (Primitive.simple ~name:"caml_bool_greaterequal" ~arity:2 - ~alloc:false); + boolcomp = Pboolcomp Cge; floatcomp = Pfloatcomp Cge; - stringcomp = - Pccall - (Primitive.simple ~name:"caml_string_greaterequal" ~arity:2 - ~alloc:false); - bytescomp = - Pccall - (Primitive.simple ~name:"caml_bytes_greaterequal" ~arity:2 - ~alloc:false); - int64comp = Pbintcomp (Pint64, Cge); + stringcomp = Pstringcomp Cge; bigintcomp = Pbigintcomp Cge; simplify_constant_constructor = false; } ); ( "%compare", { - gencomp = - Pccall (Primitive.simple ~name:"caml_compare" ~arity:2 ~alloc:true); - (* Not unboxed since the comparison is done directly on tagged int *) - intcomp = - Pccall - (Primitive.simple ~name:"caml_int_compare" ~arity:2 ~alloc:false); - boolcomp = - Pccall - (Primitive.simple ~name:"caml_bool_compare" ~arity:2 ~alloc:false); - floatcomp = - Pccall - (Primitive.simple ~name:"caml_float_compare" ~arity:2 ~alloc:false); - stringcomp = - Pccall - (Primitive.simple ~name:"caml_string_compare" ~arity:2 - ~alloc:false); - bytescomp = - Pccall - (Primitive.simple ~name:"caml_bytes_compare" ~arity:2 ~alloc:false); - int64comp = - Pccall - (Primitive.simple ~name:"caml_int64_compare" ~arity:2 ~alloc:false); - bigintcomp = - Pccall - (Primitive.simple ~name:"caml_bigint_compare" ~arity:2 ~alloc:false); + objcomp = Pobjorder; + intcomp = Pintorder; + boolcomp = Pboolorder; + floatcomp = Pfloatorder; + stringcomp = Pstringorder; + bigintcomp = Pbigintorder; simplify_constant_constructor = false; } ); - ( "%bs_max", + ( "%max", { - gencomp = arity2 "caml_max"; - bytescomp = arity2 "caml_max"; - (* FIXME bytescomp*) - intcomp = arity2 "caml_int_max"; - boolcomp = arity2 "caml_bool_max"; - floatcomp = arity2 "caml_float_max"; - stringcomp = arity2 "caml_string_max"; - int64comp = arity2 "caml_int64_max"; - bigintcomp = arity2 "caml_bigint_max"; + objcomp = Pobjmax; + intcomp = Pintmax; + boolcomp = Pboolmax; + floatcomp = Pboolmax; + stringcomp = Pstringmax; + bigintcomp = Pbigintmax; simplify_constant_constructor = false; } ); - ( "%bs_min", + ( "%min", { - gencomp = arity2 "caml_min"; - bytescomp = arity2 "caml_min"; - intcomp = arity2 "caml_int_min"; - boolcomp = arity2 "caml_bool_min"; - floatcomp = arity2 "caml_float_min"; - stringcomp = arity2 "caml_string_min"; - int64comp = arity2 "caml_int64_min"; - bigintcomp = arity2 "caml_bigint_min"; + objcomp = Pobjmin; + intcomp = Pintmin; + boolcomp = Pboolmin; + floatcomp = Pfloatmin; + stringcomp = Pstringmin; + bigintcomp = Pbigintmin; simplify_constant_constructor = false; } ); - ( "%bs_equal_null", + ( "%equal_null", { - gencomp = arity2 "caml_equal_null"; - bytescomp = arity2 "caml_equal_null"; - (* FIXME*) - intcomp = arity2 "caml_int_equal_null"; - boolcomp = arity2 "caml_bool_equal_null"; - floatcomp = arity2 "caml_float_equal_null"; - stringcomp = arity2 "caml_string_equal_null"; - int64comp = arity2 "caml_int64_equal_null"; - bigintcomp = arity2 "caml_bigint_equal_null"; - simplify_constant_constructor = true; + objcomp = Pobjcomp Ceq; + intcomp = Pintcomp Ceq; + boolcomp = Pboolcomp Ceq; + floatcomp = Pfloatcomp Ceq; + stringcomp = Pstringcomp Ceq; + bigintcomp = Pbigintcomp Ceq; + simplify_constant_constructor = false; } ); - ( "%bs_equal_undefined", + ( "%equal_undefined", { - gencomp = arity2 "caml_equal_undefined"; - bytescomp = arity2 "caml_equal_undefined"; - (* FIXME*) - intcomp = arity2 "caml_int_equal_undefined"; - boolcomp = arity2 "caml_bool_equal_undefined"; - floatcomp = arity2 "caml_float_equal_undefined"; - stringcomp = arity2 "caml_string_equal_undefined"; - int64comp = arity2 "caml_int64_equal_undefined"; - bigintcomp = arity2 "caml_bigint_equal_undefined"; - simplify_constant_constructor = true; + objcomp = Pobjcomp Ceq; + intcomp = Pintcomp Ceq; + boolcomp = Pboolcomp Ceq; + floatcomp = Pfloatcomp Ceq; + stringcomp = Pstringcomp Ceq; + bigintcomp = Pbigintcomp Ceq; + simplify_constant_constructor = false; } ); - ( "%bs_equal_nullable", + ( "%equal_nullable", { - gencomp = arity2 "caml_equal_nullable"; - bytescomp = arity2 "caml_equal_nullable"; - (* FIXME *) - intcomp = arity2 "caml_int_equal_nullable"; - boolcomp = arity2 "caml_bool_equal_nullable"; - floatcomp = arity2 "caml_float_equal_nullable"; - stringcomp = arity2 "caml_string_equal_nullable"; - int64comp = arity2 "caml_int64_equal_nullable"; - bigintcomp = arity2 "caml_bigint_equal_nullable"; - simplify_constant_constructor = true; + objcomp = Pobjcomp Ceq; + intcomp = Pintcomp Ceq; + boolcomp = Pboolcomp Ceq; + floatcomp = Pfloatcomp Ceq; + stringcomp = Pstringcomp Ceq; + bigintcomp = Pbigintcomp Ceq; + simplify_constant_constructor = false; + } ); + + (* FIXME: Core compatibility *) + ( "%bs_min", + { + objcomp = Pobjmax; + intcomp = Pintmax; + boolcomp = Pboolmax; + floatcomp = Pboolmax; + stringcomp = Pstringmax; + bigintcomp = Pbigintmax; + simplify_constant_constructor = false; + } ); + ( "%bs_max", + { + objcomp = Pobjmin; + intcomp = Pintmin; + boolcomp = Pboolmin; + floatcomp = Pfloatmin; + stringcomp = Pstringmin; + bigintcomp = Pbigintmin; + simplify_constant_constructor = false; } ); - ] + |] let primitives_table = - create_hashtable 57 - [ + create_hashtable + [| ("%identity", Pidentity); - ("%bytes_to_string", Pbytes_to_string); ("%ignore", Pignore); ("%revapply", Prevapply); ("%apply", Pdirapply); + ("%loc_LOC", Ploc Loc_LOC); ("%loc_FILE", Ploc Loc_FILE); ("%loc_LINE", Ploc Loc_LINE); ("%loc_POS", Ploc Loc_POS); ("%loc_MODULE", Ploc Loc_MODULE); + (* BEGIN Triples for ref data type *) - ("%bs_ref_setfield0", Psetfield (0, Lambda.ref_field_set_info)); - ("%bs_ref_field0", Pfield (0, Lambda.ref_field_info)); - ("%makemutable", Pmakeblock Lambda.ref_tag_info); + ("%makeref", Pmakeblock Lambda.ref_tag_info); + ("%refset", Psetfield (0, Lambda.ref_field_set_info)); + ("%refget", Pfield (0, Lambda.ref_field_info)); + ("%incr", Poffsetref 1); ("%decr", Poffsetref (-1)); + (* Finish Triples for ref data type *) ("%field0", Pfield (0, Fld_tuple)); ("%field1", Pfield (1, Fld_tuple)); ("%obj_dup", Pduprecord); - ("%obj_field", Parrayrefu); + ("%obj_tag", Pobjtag); + ("%obj_size", Pobjsize); + ("%obj_get_field", Parrayrefu); ("%obj_set_field", Parraysetu); - ("%obj_is_int", Pisint); + ("%raise", Praise Raise_regular); - ("%reraise", Praise Raise_reraise); - ("%raise_notrace", Praise Raise_notrace); + + (* bool primitives *) ("%sequand", Psequand); ("%sequor", Psequor); ("%boolnot", Pnot); - ("%big_endian", Pctconst Big_endian); - ("%backend_type", Pctconst Backend_type); - ("%word_size", Pctconst Word_size); - ("%int_size", Pctconst Int_size); - ("%max_wosize", Pctconst Max_wosize); - ("%ostype_unix", Pctconst Ostype_unix); - ("%ostype_win32", Pctconst Ostype_win32); - ("%ostype_cygwin", Pctconst Ostype_cygwin); + ("%boolorder", Pboolorder); + ("%boolmin", Pboolmin); + ("%boolmax", Pboolmax); + + (* int primitives *) + ("%obj_is_int", Pisint); ("%negint", Pnegint); ("%succint", Poffsetint 1); ("%predint", Poffsetint (-1)); @@ -346,31 +263,35 @@ let primitives_table = ("%lslint", Plslint); ("%lsrint", Plsrint); ("%asrint", Pasrint); - ("%andbigint", Pandbigint); - ("%orbigint", Porbigint); - ("%xorbigint", Pxorbigint); - ("%lslbigint", Plslbigint); - ("%asrbigint", Pasrbigint); ("%eq", Pintcomp Ceq); ("%noteq", Pintcomp Cneq); ("%ltint", Pintcomp Clt); ("%leint", Pintcomp Cle); ("%gtint", Pintcomp Cgt); ("%geint", Pintcomp Cge); - ("%intoffloat", Pintoffloat); - ("%floatofint", Pfloatofint); + ("%intorder", Pintorder); + ("%intmin", Pintmin); + ("%intmax", Pintmax); + + (* float primitives *) ("%negfloat", Pnegfloat); ("%absfloat", Pabsfloat); ("%addfloat", Paddfloat); ("%subfloat", Psubfloat); ("%mulfloat", Pmulfloat); ("%divfloat", Pdivfloat); + ("%modfloat", Pmodfloat); ("%eqfloat", Pfloatcomp Ceq); ("%noteqfloat", Pfloatcomp Cneq); ("%ltfloat", Pfloatcomp Clt); ("%lefloat", Pfloatcomp Cle); ("%gtfloat", Pfloatcomp Cgt); ("%gefloat", Pfloatcomp Cge); + ("%floatorder", Pfloatorder); + ("%floatmin", Pfloatmin); + ("%floatmax", Pfloatmax); + + (* bigint primitives *) ("%negbigint", Pnegbigint); ("%addbigint", Paddbigint); ("%subbigint", Psubbigint); @@ -384,51 +305,98 @@ let primitives_table = ("%lebigint", Pbigintcomp Cle); ("%gtbigint", Pbigintcomp Cgt); ("%gebigint", Pbigintcomp Cge); + ("%andbigint", Pandbigint); + ("%orbigint", Porbigint); + ("%xorbigint", Pxorbigint); + ("%lslbigint", Plslbigint); + ("%asrbigint", Pasrbigint); + ("%bigintorder", Pbigintorder); + ("%bigintmin", Pbigintmin); + ("%bigintmax", Pbigintmax); + + (* string primitives *) ("%string_length", Pstringlength); ("%string_safe_get", Pstringrefs); ("%string_unsafe_get", Pstringrefu); - ("%bytes_length", Pbyteslength); - ("%bytes_safe_get", Pbytesrefs); - ("%bytes_safe_set", Pbytessets); - ("%bytes_unsafe_get", Pbytesrefu); - ("%bytes_unsafe_set", Pbytessetu); + ("%stringorder", Pstringorder); + ("%stringmin", Pstringmin); + ("%stringmax", Pstringmax); + ("%string_concat", Pstringadd); + + (* array primitives *) ("%array_length", Parraylength); ("%array_safe_get", Parrayrefs); ("%array_safe_set", Parraysets); ("%array_unsafe_get", Parrayrefu); ("%array_unsafe_set", Parraysetu); - ("%floatarray_length", Parraylength); - ("%floatarray_safe_get", Parrayrefs); - ("%floatarray_safe_set", Parraysets); - ("%floatarray_unsafe_get", Parrayrefu); - ("%floatarray_unsafe_set", Parraysetu); - ("%lazy_force", Plazyforce); - ("%int64_of_int", Pbintofint Pint64); - ("%int64_to_int", Pintofbint Pint64); - ("%int64_neg", Pnegbint Pint64); - ("%int64_add", Paddbint Pint64); - ("%int64_sub", Psubbint Pint64); - ("%int64_mul", Pmulbint Pint64); - ("%int64_div", Pdivbint { size = Pint64; is_safe = Safe }); - ("%int64_mod", Pmodbint { size = Pint64; is_safe = Safe }); - ("%int64_and", Pandbint Pint64); - ("%int64_or", Porbint Pint64); - ("%int64_xor", Pxorbint Pint64); - ("%int64_lsl", Plslbint Pint64); - ("%int64_lsr", Plsrbint Pint64); - ("%int64_asr", Pasrbint Pint64); - ("%bigint_of_int32", Pcvtbint (Pint32, Pbigint)); - ("%bigint_to_int32", Pcvtbint (Pbigint, Pint32)); - ("%int64_of_int32", Pcvtbint (Pint32, Pint64)); - ("%int64_to_int32", Pcvtbint (Pint64, Pint32)); - ("%int64_of_bigint", Pcvtbint (Pbigint, Pint64)); - ("%int64_to_bigint", Pcvtbint (Pint64, Pbigint)); - ] + + (* dict primitives *) + ("%makedict", Pmakedict); + + (* promise *) + ("%await", Pawait); + + (* module *) + ("%import", Pimport); + + (* hash *) + ("%hash", Phash); + ("%hash_mix_int", Phash_mixint); + ("%hash_mix_string", Phash_mixstring); + ("%hash_final_mix", Phash_finalmix); + + (* etc *) + ("%typeof", Ptypeof); + ("%debugger", Pdebugger); + ("%intoffloat", Pintoffloat); + ("%floatofint", Pfloatofint); + ("%unsafe_eq", Pjscomp Ceq); + ("%unsafe_neq", Pjscomp Cneq); + ("%unsafe_lt", Pjscomp Clt); + ("%unsafe_le", Pjscomp Cle); + ("%unsafe_gt", Pjscomp Cgt); + ("%unsafe_ge", Pjscomp Cge); + ("%null", Pnull); + ("%undefined", Pundefined); + ("%is_nullable", Pisnullable); + ("%undefined_to_opt", Pundefined_to_opt); + ("%null_to_opt", Pnull_to_opt); + ("%nullable_to_opt", Pnullable_to_opt); + ("%function_arity", Pfn_arity); + ("%wrap_exn", Pwrap_exn); + ("%curry_apply1", Pcurry_apply 1); + ("%curry_apply2", Pcurry_apply 2); + ("%curry_apply3", Pcurry_apply 3); + ("%curry_apply4", Pcurry_apply 4); + ("%curry_apply5", Pcurry_apply 5); + ("%curry_apply6", Pcurry_apply 6); + ("%curry_apply7", Pcurry_apply 7); + ("%curry_apply8", Pcurry_apply 8); + ("%makemutablelist", Pmakelist Mutable); + ("%unsafe_to_method", Pjs_fn_method); + + (* Compiler internals, never expose to ReScript files *) + ("#raw_expr", Pjs_raw_expr); + ("#raw_stmt", Pjs_raw_stmt); + + (* FIXME: Core compatibility *) + ("#null", Pundefined); + ("#undefined", Pundefined); + ("#typeof", Ptypeof); + ("#is_nullable", Pisnullable); + ("#null_to_opt", Pnullable_to_opt); + ("#nullable_to_opt", Pnull_to_opt); + ("#undefined_to_opt", Pundefined_to_opt); + ("#makemutablelist", Pmakelist Mutable); + + (* FIXME: Deprecated *) + ("%obj_field", Parrayrefu); + |] let find_primitive prim_name = Hashtbl.find primitives_table prim_name let specialize_comparison - ({ gencomp; intcomp; floatcomp; stringcomp; bytescomp; int64comp; bigintcomp; boolcomp } : + ({ objcomp; intcomp; floatcomp; stringcomp; bigintcomp; boolcomp } : specialized) env ty = match () with | () @@ -438,11 +406,9 @@ let specialize_comparison intcomp | () when is_base_type env ty Predef.path_float -> floatcomp | () when is_base_type env ty Predef.path_string -> stringcomp - | () when is_base_type env ty Predef.path_bytes -> bytescomp - | () when is_base_type env ty Predef.path_int64 -> int64comp | () when is_base_type env ty Predef.path_bigint -> bigintcomp | () when is_base_type env ty Predef.path_bool -> boolcomp - | () -> gencomp + | () -> objcomp (* Specialize a primitive from available type information, raise Not_found if primitive is unknown *) @@ -452,7 +418,7 @@ let specialize_primitive p env ty (* ~has_constant_constructor *) = let table = Hashtbl.find comparisons_table p.prim_name in match is_function_type env ty with | Some (lhs, _rhs) -> specialize_comparison table env lhs - | None -> table.gencomp + | None -> table.objcomp with Not_found -> find_primitive p.prim_name (* Eta-expand a primitive *) @@ -842,19 +808,17 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.lambda = let loc = expr.exp_loc in let lambda = transl_exp expr in let arity = Ast_uncurried.uncurried_type_get_arity ~env:e.exp_env e.exp_type in - let arity_s = arity |> string_of_int in - let name = match (Ctype.expand_head expr.exp_env expr.exp_type).desc with - | Tarrow (Nolabel, t, _, _) -> ( - match (Ctype.expand_head expr.exp_env t).desc with - | Tconstr (Pident {name= "unit"}, [], _) -> "#fn_mk_unit" - | _ -> "#fn_mk" - ) - | _ -> "#fn_mk" in let prim = - Primitive.make ~name ~alloc:true ~native_name:arity_s ~arity:1 + match (Ctype.expand_head expr.exp_env expr.exp_type).desc with + | Tarrow (Nolabel, t, _, _) -> ( + match (Ctype.expand_head expr.exp_env t).desc with + | Tconstr (Pident {name= "unit"}, [], _) -> Pjs_fn_make_unit + | _ -> Pjs_fn_make arity + ) + | _ -> Pjs_fn_make arity in Lprim - ( Pccall prim + ( prim (* could be replaced with Opaque in the future except arity 0*), [ lambda ], loc ) @@ -1176,13 +1140,10 @@ and transl_record loc env fields repres opt_init_expr = let lambda = transl_exp expr in if lbl_name.[0] = 'I' then let arity_s = String.sub lbl_name 1 (String.length lbl_name - 1) in - let prim = - Primitive.make ~name:"#fn_mk" ~alloc:true ~native_name:arity_s - ~arity:1 - in + let arity = Int32.of_string arity_s |> Int32.to_int in Lprim - ( Pccall prim - (* could be replaced with Opaque in the future except arity 0*), + ( Pjs_fn_make arity, + (* could be replaced with Opaque in the future except arity 0*) [ lambda ], loc ) else lambda diff --git a/jscomp/ml/typecore.ml b/jscomp/ml/typecore.ml index 12644c172a..57895afe9b 100644 --- a/jscomp/ml/typecore.ml +++ b/jscomp/ml/typecore.ml @@ -237,7 +237,7 @@ let type_constant = function | Const_char _ -> instance_def Predef.type_char | Const_string _ -> instance_def Predef.type_string | Const_float _ -> instance_def Predef.type_float - | Const_int64 _ -> instance_def Predef.type_int64 + | Const_int64 _ -> assert false | Const_bigint _ -> instance_def Predef.type_bigint | Const_int32 _ -> assert false @@ -248,16 +248,6 @@ let constant : Parsetree.constant -> (Asttypes.constant, error) result = try Ok (Const_int (Misc.Int_literal_converter.int i)) with Failure _ -> Error (Literal_overflow "int") end - | Pconst_integer (i,Some 'l') -> - begin - try Ok (Const_int32 (Misc.Int_literal_converter.int32 i)) - with Failure _ -> Error (Literal_overflow "int32") - end - | Pconst_integer (i,Some 'L') -> - begin - try Ok (Const_int64 (Misc.Int_literal_converter.int64 i)) - with Failure _ -> Error (Literal_overflow "int64") - end | Pconst_integer (i,Some 'n') -> let sign, i = Bigint_utils.parse_bigint i in Ok (Const_bigint (sign, i)) diff --git a/jscomp/ml/typeopt.ml b/jscomp/ml/typeopt.ml index 565cc3b799..bd9f74d638 100644 --- a/jscomp/ml/typeopt.ml +++ b/jscomp/ml/typeopt.ml @@ -140,9 +140,7 @@ let classify env ty = if Path.same p Predef.path_float then Float else if Path.same p Predef.path_lazy_t then Lazy else if Path.same p Predef.path_string - || Path.same p Predef.path_bytes - || Path.same p Predef.path_array - || Path.same p Predef.path_int64 then Addr + || Path.same p Predef.path_array then Addr else begin try match (Env.find_type p env).type_kind with diff --git a/jscomp/others/belt_HashMapInt.res b/jscomp/others/belt_HashMapInt.res index e567b01a21..8cb478f59f 100644 --- a/jscomp/others/belt_HashMapInt.res +++ b/jscomp/others/belt_HashMapInt.res @@ -15,9 +15,9 @@ type key = int type seed = int -external caml_hash_mix_int: (seed, int) => seed = "?hash_mix_int" -external final_mix: seed => seed = "?hash_final_mix" -let hash = (s: key) => final_mix(caml_hash_mix_int(0, s)) +external hash_mix_int: (seed, int) => seed = "%hash_mix_int" +external hash_final_mix: seed => seed = "%hash_final_mix" +let hash = (s: key) => hash_final_mix(hash_mix_int(0, s)) module N = Belt_internalBuckets module C = Belt_internalBucketsType diff --git a/jscomp/others/belt_HashMapString.res b/jscomp/others/belt_HashMapString.res index ad7d223df5..5e36735e14 100644 --- a/jscomp/others/belt_HashMapString.res +++ b/jscomp/others/belt_HashMapString.res @@ -15,9 +15,9 @@ type key = string type seed = int -external caml_hash_mix_string: (seed, string) => seed = "?hash_mix_string" -external final_mix: seed => seed = "?hash_final_mix" -let hash = (s: key) => final_mix(caml_hash_mix_string(0, s)) +external hash_mix_string: (seed, string) => seed = "%hash_mix_string" +external hash_final_mix: seed => seed = "%hash_final_mix" +let hash = (s: key) => hash_final_mix(hash_mix_string(0, s)) module N = Belt_internalBuckets module C = Belt_internalBucketsType diff --git a/jscomp/others/belt_HashSetInt.res b/jscomp/others/belt_HashSetInt.res index fd159d0529..43668f800a 100644 --- a/jscomp/others/belt_HashSetInt.res +++ b/jscomp/others/belt_HashSetInt.res @@ -1,8 +1,8 @@ type key = int type seed = int -external caml_hash_mix_int: (seed, int) => seed = "?hash_mix_int" -external final_mix: seed => seed = "?hash_final_mix" -let hash = (s: key) => final_mix(caml_hash_mix_int(0, s)) +external hash_mix_int: (seed, int) => seed = "%hash_mix_int" +external hash_final_mix: seed => seed = "%hash_final_mix" +let hash = (s: key) => hash_final_mix(hash_mix_int(0, s)) module N = Belt_internalSetBuckets module C = Belt_internalBucketsType diff --git a/jscomp/others/belt_HashSetString.res b/jscomp/others/belt_HashSetString.res index 9ce5273cf5..6405d464b7 100644 --- a/jscomp/others/belt_HashSetString.res +++ b/jscomp/others/belt_HashSetString.res @@ -1,8 +1,8 @@ type key = string type seed = int -external caml_hash_mix_string: (seed, string) => seed = "?hash_mix_string" -external final_mix: seed => seed = "?hash_final_mix" -let hash = (s: key) => final_mix(caml_hash_mix_string(0, s)) +external hash_mix_string: (seed, string) => seed = "%hash_mix_string" +external hash_final_mix: seed => seed = "%hash_final_mix" +let hash = (s: key) => hash_final_mix(hash_mix_string(0, s)) module N = Belt_internalSetBuckets module C = Belt_internalBucketsType diff --git a/jscomp/others/belt_List.res b/jscomp/others/belt_List.res index 038d40253a..cf00c5611e 100644 --- a/jscomp/others/belt_List.res +++ b/jscomp/others/belt_List.res @@ -65,7 +65,7 @@ type t<'a> = list<'a> module A = Belt_Array -external mutableCell: ('a, t<'a>) => t<'a> = "#makemutablelist" +external mutableCell: ('a, t<'a>) => t<'a> = "%makemutablelist" /* `mutableCell x []` == `x` diff --git a/jscomp/others/belt_internalBucketsType.res b/jscomp/others/belt_internalBucketsType.res index d7d0c686a9..2cb648b3dc 100644 --- a/jscomp/others/belt_internalBucketsType.res +++ b/jscomp/others/belt_internalBucketsType.res @@ -31,7 +31,7 @@ type container<'hash, 'eq, 'c> = { } module A = Belt_Array -external toOpt: opt<'a> => option<'a> = "#undefined_to_opt" +external toOpt: opt<'a> => option<'a> = "%undefined_to_opt" external return: 'a => opt<'a> = "%identity" let emptyOpt = Js.undefined diff --git a/jscomp/others/belt_internalBucketsType.resi b/jscomp/others/belt_internalBucketsType.resi index cab76a7d98..d8eff6d858 100644 --- a/jscomp/others/belt_internalBucketsType.resi +++ b/jscomp/others/belt_internalBucketsType.resi @@ -30,7 +30,7 @@ type container<'hash, 'eq, 'c> = { eq: 'eq, } -external toOpt: opt<'a> => option<'a> = "#undefined_to_opt" +external toOpt: opt<'a> => option<'a> = "%undefined_to_opt" external return: 'a => opt<'a> = "%identity" let emptyOpt: Js.undefined<'a> diff --git a/jscomp/others/belt_internals.resi b/jscomp/others/belt_internals.resi deleted file mode 100644 index 2325c1e76a..0000000000 --- a/jscomp/others/belt_internals.resi +++ /dev/null @@ -1,68 +0,0 @@ -// Since [others] depend on this file, its public mli files **should not -// export types** introduced here, otherwise it would cause -// conflicts here. -// -// If the type exported here is also exported in modules from others, -// you will get a type not equivalent. -// -// Types defined here but should not export: -// - ref (make sure not exported in public others/*.mli) - -external \"^": (string, string) => string = "#string_append" -external \"=": ('a, 'a) => bool = "%equal" -external \"<>": ('a, 'a) => bool = "%notequal" -external \"==": ('a, 'a) => bool = "%eq" -external \"!=": ('a, 'a) => bool = "%noteq" -external \"<": ('a, 'a) => bool = "%lessthan" -external \">": ('a, 'a) => bool = "%greaterthan" -external \"<=": ('a, 'a) => bool = "%lessequal" -external \">=": ('a, 'a) => bool = "%greaterequal" -external \"+": (int, int) => int = "%addint" -external \"-": (int, int) => int = "%subint" -external \"~-": int => int = "%negint" -external \"*": (int, int) => int = "%mulint" -external \"/": (int, int) => int = "%divint" -external lsl: (int, int) => int = "%lslint" -external lor: (int, int) => int = "%orint" -external land: (int, int) => int = "%andint" -external mod: (int, int) => int = "%modint" -external lsr: (int, int) => int = "%lsrint" -external lxor: (int, int) => int = "%xorint" -external asr: (int, int) => int = "%asrint" -type ref<'a> = {mutable contents: 'a} -external ref: 'a => ref<'a> = "%makemutable" - -external \"||": (bool, bool) => bool = "%sequor" -external \"&&": (bool, bool) => bool = "%sequand" -external not: bool => bool = "%boolnot" - -external raise: exn => 'a = "%raise" -external ignore: 'a => unit = "%ignore" -external \"|>": ('a, 'a => 'b) => 'b = "%revapply" -external \"@@": ('a => 'b, 'a) => 'b = "%apply" - -@val @scope("Math") external \"**": (float, float) => float = "pow" -external \"~-.": float => float = "%negfloat" -external \"+.": (float, float) => float = "%addfloat" -external \"-.": (float, float) => float = "%subfloat" -external \"*.": (float, float) => float = "%mulfloat" -external \"/.": (float, float) => float = "%divfloat" - -module Obj: { - type t - external field: (t, int) => t = "%obj_field" - external set_field: (t, int, t) => unit = "%obj_set_field" - external tag: t => int = "?obj_tag" - external repr: 'a => t = "%identity" - external obj: t => 'a = "%identity" - external magic: 'a => 'b = "%identity" - external size: t => int = "#obj_length" -} - -module Pervasives: { - external compare: ('a, 'a) => int = "%compare" - external not: bool => bool = "%boolnot" - external min: ('a, 'a) => 'a = "%bs_min" - external max: ('a, 'a) => 'a = "%bs_max" - external \"=": ('a, 'a) => bool = "%equal" -} diff --git a/jscomp/others/js.res b/jscomp/others/js.res index cc6a9154ea..72c535cdb6 100644 --- a/jscomp/others/js.res +++ b/jscomp/others/js.res @@ -74,106 +74,6 @@ Js.log(Js.String.startsWith(\"Re\", \"ReScript\")) Prefer `Js.Array2` over `Js.Array`, `Js.String2` over `Js.String`, etc. The latters are old modules. */ -/** JS object type */ -type t<'a> = {..} as 'a - -/** JS global object reference */ -@val -external globalThis: t<'a> = "globalThis" - -/** - Nullable value of this type can be either null or 'a. This type is equivalent to Js.Null.t. -*/ -@unboxed -type null<+'a> = Value('a) | @as(null) Null - -/** - A value of this type can be either undefined or 'a. This type is equivalent to Js.Undefined.t. -*/ -type undefined<+'a> - -@unboxed type nullable<+'a> = Value('a) | @as(null) Null | @as(undefined) Undefined - -/*** - A value of this type can be undefined, null or 'a. This type is equivalent to Js.Null_undefined.t. -*/ - -type null_undefined<+'a> = nullable<'a> - -external toOption: nullable<'a> => option<'a> = "#nullable_to_opt" -external undefinedToOption: undefined<'a> => option<'a> = "#undefined_to_opt" -external nullToOption: null<'a> => option<'a> = "#null_to_opt" -external isNullable: nullable<'a> => bool = "#is_nullable" -external import: 'a => promise<'a> = "#import" - -/** The same as {!test} except that it is more permissive on the types of input */ -external testAny: 'a => bool = "#is_nullable" - -/** - The promise type, defined here for interoperation across packages. -*/ -type promise<+'a, +'e> - -/** - The same as empty in `Js.Null`. Compiles to `null`. -*/ -external null: null<'a> = "#null" - -/** - The same as empty `Js.Undefined`. Compiles to `undefined`. -*/ -external undefined: undefined<'a> = "#undefined" - -/** -`typeof x` will be compiled as `typeof x` in JS. Please consider functions in -`Js.Types` for a type safe way of reflection. -*/ -external typeof: 'a => string = "#typeof" - -@val @scope("console") /** Equivalent to console.log any value. */ -external log: 'a => unit = "log" - -@val @scope("console") external log2: ('a, 'b) => unit = "log" -@val @scope("console") external log3: ('a, 'b, 'c) => unit = "log" - -@val @scope("console") external log4: ('a, 'b, 'c, 'd) => unit = "log" - -@val @scope("console") @variadic /** A convenience function to console.log more than 4 arguments */ -external logMany: array<'a> => unit = "log" - -external eqNull: ('a, null<'a>) => bool = "%bs_equal_null" -external eqUndefined: ('a, undefined<'a>) => bool = "%bs_equal_undefined" -external eqNullable: ('a, nullable<'a>) => bool = "%bs_equal_nullable" - -/* ## Operators */ - -/** - `unsafe_lt(a, b)` will be compiled as `a < b`. - It is marked as unsafe, since it is impossible - to give a proper semantics for comparision which applies to any type -*/ -external unsafe_lt: ('a, 'a) => bool = "#unsafe_lt" - -/** - `unsafe_le(a, b)` will be compiled as `a <= b`. - See also `Js.unsafe_lt`. -*/ -external unsafe_le: ('a, 'a) => bool = "#unsafe_le" - -/** - `unsafe_gt(a, b)` will be compiled as `a > b`. - See also `Js.unsafe_lt`. -*/ -external unsafe_gt: ('a, 'a) => bool = "#unsafe_gt" - -/** - `unsafe_ge(a, b)` will be compiled as `a >= b`. - See also `Js.unsafe_lt`. -*/ -external unsafe_ge: ('a, 'a) => bool = "#unsafe_ge" - -/* ## Nested Modules */ - /** Provide utilities for `Js.null<'a>` */ module Null = Js_null @@ -271,3 +171,92 @@ module Map = Js_map /** Provides bindings for ES6 WeakMap */ module WeakMap = Js_weakmap + +/** JS object type */ +type t<'a> = {..} as 'a + +/** JS global object reference */ +@val +external globalThis: t<'a> = "globalThis" + +@unboxed +type null<+'a> = Js_null.t<'a> = Value('a) | @as(null) Null + +type undefined<+'a> = Js_undefined.t<'a> + +@unboxed +type nullable<+'a> = Js_null_undefined.t<'a> = Value('a) | @as(null) Null | @as(undefined) Undefined + +type null_undefined<+'a> = nullable<'a> + +external toOption: nullable<'a> => option<'a> = "%nullable_to_opt" +external undefinedToOption: undefined<'a> => option<'a> = "%undefined_to_opt" +external nullToOption: null<'a> => option<'a> = "%null_to_opt" +external isNullable: nullable<'a> => bool = "%is_nullable" +external import: 'a => promise<'a> = "%import" + +/** The same as {!test} except that it is more permissive on the types of input */ +external testAny: 'a => bool = "%is_nullable" + +/** + The promise type, defined here for interoperation across packages. +*/ +type promise<+'a, +'e> + +/** + The same as empty in `Js.Null`. Compiles to `null`. +*/ +external null: null<'a> = "%null" + +/** + The same as empty `Js.Undefined`. Compiles to `undefined`. +*/ +external undefined: undefined<'a> = "%undefined" + +/** +`typeof x` will be compiled as `typeof x` in JS. Please consider functions in +`Js.Types` for a type safe way of reflection. +*/ +external typeof: 'a => string = "%typeof" + +@val @scope("console") /** Equivalent to console.log any value. */ +external log: 'a => unit = "log" + +@val @scope("console") external log2: ('a, 'b) => unit = "log" +@val @scope("console") external log3: ('a, 'b, 'c) => unit = "log" + +@val @scope("console") external log4: ('a, 'b, 'c, 'd) => unit = "log" + +@val @scope("console") @variadic /** A convenience function to console.log more than 4 arguments */ +external logMany: array<'a> => unit = "log" + +external eqNull: ('a, null<'a>) => bool = "%equal_null" +external eqUndefined: ('a, undefined<'a>) => bool = "%equal_undefined" +external eqNullable: ('a, nullable<'a>) => bool = "%equal_nullable" + +/* ## Operators */ + +/** + `unsafe_lt(a, b)` will be compiled as `a < b`. + It is marked as unsafe, since it is impossible + to give a proper semantics for comparision which applies to any type +*/ +external unsafe_lt: ('a, 'a) => bool = "%unsafe_lt" + +/** + `unsafe_le(a, b)` will be compiled as `a <= b`. + See also `Js.unsafe_lt`. +*/ +external unsafe_le: ('a, 'a) => bool = "%unsafe_le" + +/** + `unsafe_gt(a, b)` will be compiled as `a > b`. + See also `Js.unsafe_lt`. +*/ +external unsafe_gt: ('a, 'a) => bool = "%unsafe_gt" + +/** + `unsafe_ge(a, b)` will be compiled as `a >= b`. + See also `Js.unsafe_lt`. +*/ +external unsafe_ge: ('a, 'a) => bool = "%unsafe_ge" diff --git a/jscomp/others/js_OO.res b/jscomp/others/js_OO.res index 033ab69b60..aba40deefa 100644 --- a/jscomp/others/js_OO.res +++ b/jscomp/others/js_OO.res @@ -24,7 +24,7 @@ @@config({flags: ["-unboxed-types"]}) -external unsafe_to_method: 'a => 'a = "#fn_method" +external unsafe_to_method: 'a => 'a = "%unsafe_to_method" module Callback = { type arity1<'a> = {@internal i1: 'a} diff --git a/jscomp/others/js_exn.res b/jscomp/others/js_exn.res index 9cd37bc19b..1a7f7da952 100644 --- a/jscomp/others/js_exn.res +++ b/jscomp/others/js_exn.res @@ -27,7 +27,11 @@ type t = unknown @@warning("-38") /* unused extension constructor */ exception Error = JsError -external asJsExn: exn => option = "?as_js_exn" +let asJsExn: exn => option = exn => + switch Obj.magic(exn) { + | Error(t) => Some(t) + | _ => None + } @get external stack: t => option = "stack" @get external message: t => option = "message" @@ -36,9 +40,8 @@ external asJsExn: exn => option = "?as_js_exn" type error @new external makeError: string => error = "Error" -external isCamlExceptionOrOpenVariant: 'a => bool = "?is_extension" -external anyToExnInternal: 'a => exn = "#wrap_exn" +external anyToExnInternal: 'a => exn = "%wrap_exn" let raiseError = str => raise((Obj.magic((makeError(str): error)): exn)) diff --git a/jscomp/others/js_exn.resi b/jscomp/others/js_exn.resi index 87ce8ca887..31e8751e5f 100644 --- a/jscomp/others/js_exn.resi +++ b/jscomp/others/js_exn.resi @@ -31,16 +31,13 @@ type t type exn += private Error(t) -external asJsExn: exn => option = "?as_js_exn" +let asJsExn: exn => option @get external stack: t => option = "stack" @get external message: t => option = "message" @get external name: t => option = "name" @get external fileName: t => option = "fileName" -/** internal use only */ -external isCamlExceptionOrOpenVariant: 'a => bool = "?is_extension" - /** `anyToExnInternal(obj)` will take any value `obj` and wrap it in a Js.Exn.Error if given value is not an exn already. If @@ -64,7 +61,7 @@ switch (Js.Exn.unsafeAnyToExn("test")) { } ``` */ -external anyToExnInternal: 'a => exn = "#wrap_exn" +external anyToExnInternal: 'a => exn = "%wrap_exn" /** Raise Js exception Error object with stacktrace */ let raiseError: string => 'a diff --git a/jscomp/others/js_extern.res b/jscomp/others/js_extern.res new file mode 100644 index 0000000000..f1e49974e4 --- /dev/null +++ b/jscomp/others/js_extern.res @@ -0,0 +1,7 @@ +external testAny: 'a => bool = "%is_nullable" + +external null: Primitive_js_extern.null<'a> = "%null" + +external undefined: Primitive_js_extern.null<'a> = "%undefined" + +external typeof: 'a => string = "%typeof" diff --git a/jscomp/others/js_json.res b/jscomp/others/js_json.res index 47ea235e60..7888b086df 100644 --- a/jscomp/others/js_json.res +++ b/jscomp/others/js_json.res @@ -30,7 +30,7 @@ type rec t = | @as(null) Null | String(string) | Number(float) - | Object(Js.Dict.t) + | Object(Js_dict.t) | Array(array) module Kind = { @@ -54,7 +54,7 @@ type tagged_t = | JSONArray(array) let classify = (x: t): tagged_t => { - let ty = Js.typeof(x) + let ty = Js_extern.typeof(x) if ty == "string" { JSONString(Obj.magic(x)) } else if ty == "number" { @@ -65,7 +65,7 @@ let classify = (x: t): tagged_t => { } else { JSONFalse } - } else if Obj.magic(x) === Js.null { + } else if Obj.magic(x) === Js_extern.null { JSONNull } else if Js_array2.isArray(x) { JSONArray(Obj.magic(x)) @@ -76,23 +76,24 @@ let classify = (x: t): tagged_t => { let test = (type a, x: 'a, v: Kind.t): bool => switch v { - | Kind.Number => Js.typeof(x) == "number" - | Kind.Boolean => Js.typeof(x) == "boolean" - | Kind.String => Js.typeof(x) == "string" - | Kind.Null => Obj.magic(x) === Js.null + | Kind.Number => Js_extern.typeof(x) == "number" + | Kind.Boolean => Js_extern.typeof(x) == "boolean" + | Kind.String => Js_extern.typeof(x) == "string" + | Kind.Null => Obj.magic(x) === Js_extern.null | Kind.Array => Js_array2.isArray(x) - | Kind.Object => Obj.magic(x) !== Js.null && (Js.typeof(x) == "object" && !Js_array2.isArray(x)) + | Kind.Object => + Obj.magic(x) !== Js_extern.null && (Js_extern.typeof(x) == "object" && !Js_array2.isArray(x)) } let decodeString = json => - if Js.typeof(json) == "string" { + if Js_extern.typeof(json) == "string" { Some((Obj.magic((json: t)): string)) } else { None } let decodeNumber = json => - if Js.typeof(json) == "number" { + if Js_extern.typeof(json) == "number" { Some((Obj.magic((json: t)): float)) } else { None @@ -100,9 +101,9 @@ let decodeNumber = json => let decodeObject = json => if ( - Js.typeof(json) == "object" && + Js_extern.typeof(json) == "object" && (!Js_array2.isArray(json) && - !((Obj.magic(json): Js.null<'a>) === Js.null)) + !((Obj.magic(json): Js_null.t<'a>) === Js_extern.null)) ) { Some((Obj.magic((json: t)): Js_dict.t)) } else { @@ -117,15 +118,15 @@ let decodeArray = json => } let decodeBoolean = (json: t) => - if Js.typeof(json) == "boolean" { + if Js_extern.typeof(json) == "boolean" { Some((Obj.magic((json: t)): bool)) } else { None } -let decodeNull = (json): option> => - if (Obj.magic(json): Js.null<'a>) === Js.null { - Some(Js.null) +let decodeNull = (json): option> => + if (Obj.magic(json): Js_null.t<'a>) === Js_extern.null { + Some(Js_extern.null) } else { None } diff --git a/jscomp/others/js_json.resi b/jscomp/others/js_json.resi index 218d5f5626..0043b1cbdd 100644 --- a/jscomp/others/js_json.resi +++ b/jscomp/others/js_json.resi @@ -36,7 +36,7 @@ type rec t = | @as(null) Null | String(string) | Number(float) - | Object(Js.Dict.t) + | Object(Js_dict.t) | Array(array) module Kind: { diff --git a/jscomp/others/js_null.res b/jscomp/others/js_null.res index 8c64aeeb2f..33f73888f2 100644 --- a/jscomp/others/js_null.res +++ b/jscomp/others/js_null.res @@ -25,15 +25,13 @@ /*** Provides functionality for dealing with the `'a Js.null` type */ @unboxed -type t<+'a> = Js.null<'a> = - | Value('a) - | @as(null) Null +type t<+'a> = Primitive_js_extern.null<'a> = Value('a) | @as(null) Null -external to_opt: t<'a> => option<'a> = "#null_to_opt" -external toOption: t<'a> => option<'a> = "#null_to_opt" +external to_opt: t<'a> => option<'a> = "%null_to_opt" +external toOption: t<'a> => option<'a> = "%null_to_opt" external return: 'a => t<'a> = "%identity" -let test: t<'a> => bool = x => x == Js.null -external empty: t<'a> = "#null" +let test: t<'a> => bool = x => x == Js_extern.null +external empty: t<'a> = "%null" external getUnsafe: t<'a> => 'a = "%identity" let getExn = f => diff --git a/jscomp/others/js_null.resi b/jscomp/others/js_null.resi index 6841f08e8f..cb521ea4fb 100644 --- a/jscomp/others/js_null.resi +++ b/jscomp/others/js_null.resi @@ -24,10 +24,8 @@ /*** Provides functionality for dealing with the `Js.null<'a>` type */ -@unboxed /** Local alias for `Js.null<'a>` */ -type t<+'a> = Js.null<'a> = - | Value('a) - | @as(null) Null +@unboxed +type t<+'a> = Primitive_js_extern.null<'a> = Value('a) | @as(null) Null /** Constructs a value of `Js.null<'a>` containing a value of `'a`. */ external return: 'a => t<'a> = "%identity" @@ -37,7 +35,7 @@ external return: 'a => t<'a> = "%identity" let test: t<'a> => bool /** The empty value, `null` */ -external empty: t<'a> = "#null" +external empty: t<'a> = "%null" external getUnsafe: t<'a> => 'a = "%identity" let getExn: t<'a> => 'a @@ -85,6 +83,6 @@ Maps `Js.null<'a>` to `option<'a>`. `a` => `Some(a)` `empty` => `None` */ -external toOption: t<'a> => option<'a> = "#null_to_opt" +external toOption: t<'a> => option<'a> = "%null_to_opt" -@deprecated("Use toOption instead") external to_opt: t<'a> => option<'a> = "#null_to_opt" +@deprecated("Use toOption instead") external to_opt: t<'a> => option<'a> = "%null_to_opt" diff --git a/jscomp/others/js_null_undefined.res b/jscomp/others/js_null_undefined.res index 9c98d0f04a..084106bea7 100644 --- a/jscomp/others/js_null_undefined.res +++ b/jscomp/others/js_null_undefined.res @@ -25,17 +25,15 @@ /*** Contains functionality for dealing with values that can be both `null` and `undefined` */ @unboxed -type t<+'a> = Js.nullable<'a> = - | Value('a) - | @as(null) Null - | @as(undefined) Undefined +type t<+'a> = Primitive_js_extern.nullable<'a> = + Value('a) | @as(null) Null | @as(undefined) Undefined -external toOption: t<'a> => option<'a> = "#nullable_to_opt" -external to_opt: t<'a> => option<'a> = "#nullable_to_opt" +external toOption: t<'a> => option<'a> = "%nullable_to_opt" +external to_opt: t<'a> => option<'a> = "%nullable_to_opt" external return: 'a => t<'a> = "%identity" -external isNullable: t<'a> => bool = "#is_nullable" -external null: t<'a> = "#null" -external undefined: t<'a> = "#undefined" +external isNullable: t<'a> => bool = "%is_nullable" +external null: t<'a> = "%null" +external undefined: t<'a> = "%undefined" let bind = (x, f) => switch to_opt(x) { diff --git a/jscomp/others/js_null_undefined.resi b/jscomp/others/js_null_undefined.resi index 55634f8dff..ba310cca5a 100644 --- a/jscomp/others/js_null_undefined.resi +++ b/jscomp/others/js_null_undefined.resi @@ -26,24 +26,21 @@ Contains functionality for dealing with values that can be both `null` and `undefined` */ -/** Local alias for `Js.null_undefined<'a>`. */ @unboxed -type t<+'a> = Js.nullable<'a> = - | Value('a) - | @as(null) Null - | @as(undefined) Undefined +type t<+'a> = Primitive_js_extern.nullable<'a> = + Value('a) | @as(null) Null | @as(undefined) Undefined /** Constructs a value of `Js.null_undefined<'a>` containing a value of `'a`. */ external return: 'a => t<'a> = "%identity" /** Returns `true` if the given value is null or undefined, `false` otherwise. */ -external isNullable: t<'a> => bool = "#is_nullable" +external isNullable: t<'a> => bool = "%is_nullable" /** The null value of type `Js.null_undefined<'a>`. */ -external null: t<'a> = "#null" +external null: t<'a> = "%null" /** The undefined value of type `Js.null_undefined<'a>`. */ -external undefined: t<'a> = "#undefined" +external undefined: t<'a> = "%undefined" /** Maps the contained value using the given function. @@ -89,6 +86,6 @@ Maps `Js.null_undefined<'a>` to `option<'a>`. `undefined` => `None` `null` => `None` */ -external toOption: t<'a> => option<'a> = "#nullable_to_opt" +external toOption: t<'a> => option<'a> = "%nullable_to_opt" -@deprecated("Use toOption instead") external to_opt: t<'a> => option<'a> = "#nullable_to_opt" +@deprecated("Use toOption instead") external to_opt: t<'a> => option<'a> = "%nullable_to_opt" diff --git a/jscomp/others/js_promise2.res b/jscomp/others/js_promise2.res index 5b99b9b9f4..8bdaae73fe 100644 --- a/jscomp/others/js_promise2.res +++ b/jscomp/others/js_promise2.res @@ -53,4 +53,4 @@ external all6: ( @val @scope("Promise") external race: array> => promise<'a> = "race" external unsafe_async: 'a => promise<'a> = "%identity" -external unsafe_await: promise<'a> => 'a = "?await" +external unsafe_await: promise<'a> => 'a = "%await" diff --git a/jscomp/others/js_re.res b/jscomp/others/js_re.res index 4f10383bce..05e46ec64a 100644 --- a/jscomp/others/js_re.res +++ b/jscomp/others/js_re.res @@ -40,7 +40,7 @@ type result An `array` of the match and captures, the first is the full match and the remaining are the substring captures. */ -external captures: result => array> = "%identity" +external captures: result => array> = "%identity" @deprecated("Use Js.Re.captures instead") external matches: result => array = "%identity" diff --git a/jscomp/others/js_typed_array2.res b/jscomp/others/js_typed_array2.res index 26fe53f2e5..47338d748f 100644 --- a/jscomp/others/js_typed_array2.res +++ b/jscomp/others/js_typed_array2.res @@ -129,8 +129,8 @@ module Int8Array = { @send external filter: (t, elt => bool) => t = "filter" @send external filteri: (t, (elt, int) => bool) => t = "filter" - @send external find: (t, elt => bool) => Js.undefined = "find" - @send external findi: (t, (elt, int) => bool) => Js.undefined = "find" + @send external find: (t, elt => bool) => Js_undefined.t = "find" + @send external findi: (t, (elt, int) => bool) => Js_undefined.t = "find" @send external findIndex: (t, elt => bool) => int = "findIndex" @send external findIndexi: (t, (elt, int) => bool) => int = "findIndex" @@ -250,8 +250,8 @@ module Uint8Array = { @send external filter: (t, elt => bool) => t = "filter" @send external filteri: (t, (elt, int) => bool) => t = "filter" - @send external find: (t, elt => bool) => Js.undefined = "find" - @send external findi: (t, (elt, int) => bool) => Js.undefined = "find" + @send external find: (t, elt => bool) => Js_undefined.t = "find" + @send external findi: (t, (elt, int) => bool) => Js_undefined.t = "find" @send external findIndex: (t, elt => bool) => int = "findIndex" @send external findIndexi: (t, (elt, int) => bool) => int = "findIndex" @@ -371,8 +371,8 @@ module Uint8ClampedArray = { @send external filter: (t, elt => bool) => t = "filter" @send external filteri: (t, (elt, int) => bool) => t = "filter" - @send external find: (t, elt => bool) => Js.undefined = "find" - @send external findi: (t, (elt, int) => bool) => Js.undefined = "find" + @send external find: (t, elt => bool) => Js_undefined.t = "find" + @send external findi: (t, (elt, int) => bool) => Js_undefined.t = "find" @send external findIndex: (t, elt => bool) => int = "findIndex" @send external findIndexi: (t, (elt, int) => bool) => int = "findIndex" @@ -492,8 +492,8 @@ module Int16Array = { @send external filter: (t, elt => bool) => t = "filter" @send external filteri: (t, (elt, int) => bool) => t = "filter" - @send external find: (t, elt => bool) => Js.undefined = "find" - @send external findi: (t, (elt, int) => bool) => Js.undefined = "find" + @send external find: (t, elt => bool) => Js_undefined.t = "find" + @send external findi: (t, (elt, int) => bool) => Js_undefined.t = "find" @send external findIndex: (t, elt => bool) => int = "findIndex" @send external findIndexi: (t, (elt, int) => bool) => int = "findIndex" @@ -613,8 +613,8 @@ module Uint16Array = { @send external filter: (t, elt => bool) => t = "filter" @send external filteri: (t, (elt, int) => bool) => t = "filter" - @send external find: (t, elt => bool) => Js.undefined = "find" - @send external findi: (t, (elt, int) => bool) => Js.undefined = "find" + @send external find: (t, elt => bool) => Js_undefined.t = "find" + @send external findi: (t, (elt, int) => bool) => Js_undefined.t = "find" @send external findIndex: (t, elt => bool) => int = "findIndex" @send external findIndexi: (t, (elt, int) => bool) => int = "findIndex" @@ -734,8 +734,8 @@ module Int32Array = { @send external filter: (t, elt => bool) => t = "filter" @send external filteri: (t, (elt, int) => bool) => t = "filter" - @send external find: (t, elt => bool) => Js.undefined = "find" - @send external findi: (t, (elt, int) => bool) => Js.undefined = "find" + @send external find: (t, elt => bool) => Js_undefined.t = "find" + @send external findi: (t, (elt, int) => bool) => Js_undefined.t = "find" @send external findIndex: (t, elt => bool) => int = "findIndex" @send external findIndexi: (t, (elt, int) => bool) => int = "findIndex" @@ -855,8 +855,8 @@ module Uint32Array = { @send external filter: (t, elt => bool) => t = "filter" @send external filteri: (t, (elt, int) => bool) => t = "filter" - @send external find: (t, elt => bool) => Js.undefined = "find" - @send external findi: (t, (elt, int) => bool) => Js.undefined = "find" + @send external find: (t, elt => bool) => Js_undefined.t = "find" + @send external findi: (t, (elt, int) => bool) => Js_undefined.t = "find" @send external findIndex: (t, elt => bool) => int = "findIndex" @send external findIndexi: (t, (elt, int) => bool) => int = "findIndex" @@ -979,8 +979,8 @@ module Float32Array = { @send external filter: (t, elt => bool) => t = "filter" @send external filteri: (t, (elt, int) => bool) => t = "filter" - @send external find: (t, elt => bool) => Js.undefined = "find" - @send external findi: (t, (elt, int) => bool) => Js.undefined = "find" + @send external find: (t, elt => bool) => Js_undefined.t = "find" + @send external findi: (t, (elt, int) => bool) => Js_undefined.t = "find" @send external findIndex: (t, elt => bool) => int = "findIndex" @send external findIndexi: (t, (elt, int) => bool) => int = "findIndex" @@ -1100,8 +1100,8 @@ module Float64Array = { @send external filter: (t, elt => bool) => t = "filter" @send external filteri: (t, (elt, int) => bool) => t = "filter" - @send external find: (t, elt => bool) => Js.undefined = "find" - @send external findi: (t, (elt, int) => bool) => Js.undefined = "find" + @send external find: (t, elt => bool) => Js_undefined.t = "find" + @send external findi: (t, (elt, int) => bool) => Js_undefined.t = "find" @send external findIndex: (t, elt => bool) => int = "findIndex" @send external findIndexi: (t, (elt, int) => bool) => int = "findIndex" diff --git a/jscomp/others/js_types.res b/jscomp/others/js_types.res index 7a385823b8..88bd6f6fbe 100644 --- a/jscomp/others/js_types.res +++ b/jscomp/others/js_types.res @@ -58,7 +58,7 @@ type tagged_t = | JSBigInt(bigint) let classify = (x: 'a): tagged_t => { - let ty = Js.typeof(x) + let ty = Js_extern.typeof(x) if ty == "undefined" { JSUndefined } else if x === Obj.magic(Js_null.empty) { @@ -86,13 +86,13 @@ let classify = (x: 'a): tagged_t => { let test = (type a, x: 'a, v: t): bool => switch v { - | Number => Js.typeof(x) == "number" - | Boolean => Js.typeof(x) == "boolean" - | Undefined => Js.typeof(x) == "undefined" + | Number => Js_extern.typeof(x) == "number" + | Boolean => Js_extern.typeof(x) == "boolean" + | Undefined => Js_extern.typeof(x) == "undefined" | Null => x === Obj.magic(Js_null.empty) - | String => Js.typeof(x) == "string" - | Function => Js.typeof(x) == "function" - | Object => Js.typeof(x) == "object" - | Symbol => Js.typeof(x) == "symbol" - | BigInt => Js.typeof(x) == "bigint" + | String => Js_extern.typeof(x) == "string" + | Function => Js_extern.typeof(x) == "function" + | Object => Js_extern.typeof(x) == "object" + | Symbol => Js_extern.typeof(x) == "symbol" + | BigInt => Js_extern.typeof(x) == "bigint" } diff --git a/jscomp/others/js_undefined.res b/jscomp/others/js_undefined.res index 91a45ef481..00924699ee 100644 --- a/jscomp/others/js_undefined.res +++ b/jscomp/others/js_undefined.res @@ -24,12 +24,13 @@ /*** Provides functionality for dealing with the `'a Js.undefined` type */ -type t<+'a> = Js.undefined<'a> -external to_opt: t<'a> => option<'a> = "#undefined_to_opt" -external toOption: t<'a> => option<'a> = "#undefined_to_opt" +type t<+'a> = Primitive_js_extern.undefined<'a> + +external to_opt: t<'a> => option<'a> = "%undefined_to_opt" +external toOption: t<'a> => option<'a> = "%undefined_to_opt" external return: 'a => t<'a> = "%identity" -external empty: t<'a> = "#undefined" +external empty: t<'a> = "%undefined" let test: t<'a> => bool = x => x == empty let testAny: 'a => bool = x => Obj.magic(x) == empty external getUnsafe: t<'a> => 'a = "%identity" diff --git a/jscomp/others/js_undefined.resi b/jscomp/others/js_undefined.resi index dffebc976f..6b379c62f2 100644 --- a/jscomp/others/js_undefined.resi +++ b/jscomp/others/js_undefined.resi @@ -25,7 +25,7 @@ /*** Provides functionality for dealing with the `Js.undefined<'a>` type */ /** Local alias for `Js.undefined<'a>` */ -type t<+'a> = Js.undefined<'a> +type t<+'a> = Primitive_js_extern.undefined<'a> /** Constructs a value of `Js.undefined<'a>` containing a value of `'a`. */ external return: 'a => t<'a> = "%identity" @@ -42,7 +42,7 @@ Returns `true` if the given value is empty (undefined). let testAny: 'a => bool /** The empty value, `undefined` */ -external empty: t<'a> = "#undefined" +external empty: t<'a> = "%undefined" external getUnsafe: t<'a> => 'a = "%identity" let getExn: t<'a> => 'a @@ -90,6 +90,6 @@ Maps `Js.undefined<'a>` to `option<'a>` `a` => `Some(a)` `empty` => `None` */ -external toOption: t<'a> => option<'a> = "#undefined_to_opt" +external toOption: t<'a> => option<'a> = "%undefined_to_opt" -@deprecated("use toOption instead") external to_opt: t<'a> => option<'a> = "#undefined_to_opt" +@deprecated("use toOption instead") external to_opt: t<'a> => option<'a> = "%undefined_to_opt" diff --git a/jscomp/others/release.ninja b/jscomp/others/release.ninja index bcb6f32fed..d3779d3f25 100644 --- a/jscomp/others/release.ninja +++ b/jscomp/others/release.ninja @@ -1,6 +1,5 @@ -bsc_primitive_flags = -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 -bsc_flags = $bsc_primitive_flags -open Belt_internals +bsc_flags = -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -make-runtime -unsafe -w +50 -warn-error A -I runtime rule cc command = $bsc -bs-cmi -bs-cmj $bsc_flags -I others $in @@ -9,148 +8,140 @@ rule cc_cmi command = $bsc -bs-read-cmi -bs-cmi -bs-cmj $bsc_flags -I others $in description = $in -> $out -o others/belt.cmj others/belt.cmi : cc others/belt.res | $bsc - bsc_flags = $bsc_primitive_flags -o others/js.cmj others/js.cmi : cc others/js.res | $bsc - bsc_flags = $bsc_primitive_flags -o others/belt_internals.cmi : cc others/belt_internals.resi | $bsc - bsc_flags = $bsc_primitive_flags -o others/js_OO.cmi others/js_OO.cmj : cc others/js_OO.res | others/belt_internals.cmi others/js.cmi $bsc -o others/js_array.cmi others/js_array.cmj : cc others/js_array.res | others/belt_internals.cmi others/js.cmi others/js_array2.cmj $bsc -o others/js_array2.cmi others/js_array2.cmj : cc others/js_array2.res | others/belt_internals.cmi others/js.cmi $bsc -o others/js_bigint.cmi others/js_bigint.cmj : cc others/js_bigint.res | others/belt_internals.cmi others/js.cmi $bsc -o others/js_blob.cmi others/js_blob.cmj : cc others/js_blob.res | others/belt_internals.cmi others/js.cmi $bsc -o others/js_cast.cmj : cc_cmi others/js_cast.res | others/belt_internals.cmi others/js.cmi others/js_cast.cmi $bsc -o others/js_cast.cmi : cc others/js_cast.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/js_console.cmi others/js_console.cmj : cc others/js_console.res | others/belt_internals.cmi others/js.cmi $bsc -o others/js_date.cmi others/js_date.cmj : cc others/js_date.res | others/belt_internals.cmi others/js.cmi $bsc -o others/js_dict.cmj : cc_cmi others/js_dict.res | others/belt_internals.cmi others/js.cmi others/js_array2.cmj others/js_dict.cmi $bsc -o others/js_dict.cmi : cc others/js_dict.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/js_exn.cmj : cc_cmi others/js_exn.res | others/belt_internals.cmi others/js.cmi others/js_exn.cmi $bsc -o others/js_exn.cmi : cc others/js_exn.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/js_file.cmi others/js_file.cmj : cc others/js_file.res | others/belt_internals.cmi others/js.cmi $bsc -o others/js_float.cmi others/js_float.cmj : cc others/js_float.res | others/belt_internals.cmi others/js.cmi $bsc -o others/js_global.cmi others/js_global.cmj : cc others/js_global.res | others/belt_internals.cmi others/js.cmi $bsc -o others/js_int.cmi others/js_int.cmj : cc others/js_int.res | others/belt_internals.cmi others/js.cmi $bsc -o others/js_json.cmj : cc_cmi others/js_json.res | others/belt_internals.cmi others/js.cmi others/js_array2.cmj others/js_dict.cmj others/js_json.cmi others/js_string.cmj others/js_types.cmj $bsc -o others/js_json.cmi : cc others/js_json.resi | others/belt_internals.cmi others/js.cmi others/js_dict.cmi others/js_null.cmi others/js_string.cmj others/js_types.cmi $bsc -o others/js_map.cmi others/js_map.cmj : cc others/js_map.res | others/belt_internals.cmi others/js.cmi $bsc -o others/js_math.cmi others/js_math.cmj : cc others/js_math.res | others/belt_internals.cmi others/js.cmi others/js_int.cmj $bsc -o others/js_null.cmj : cc_cmi others/js_null.res | others/belt_internals.cmi others/js.cmi others/js_exn.cmj others/js_null.cmi $bsc -o others/js_null.cmi : cc others/js_null.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/js_null_undefined.cmj : cc_cmi others/js_null_undefined.res | others/belt_internals.cmi others/js.cmi others/js_null_undefined.cmi $bsc -o others/js_null_undefined.cmi : cc others/js_null_undefined.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/js_obj.cmi others/js_obj.cmj : cc others/js_obj.res | others/belt_internals.cmi others/js.cmi $bsc -o others/js_option.cmj : cc_cmi others/js_option.res | others/belt_internals.cmi others/js.cmi others/js_exn.cmj others/js_option.cmi $bsc -o others/js_option.cmi : cc others/js_option.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/js_promise.cmi others/js_promise.cmj : cc others/js_promise.res | others/belt_internals.cmi others/js.cmi others/js_promise2.cmj $bsc -o others/js_promise2.cmi others/js_promise2.cmj : cc others/js_promise2.res | others/belt_internals.cmi others/js.cmi $bsc -o others/js_re.cmi others/js_re.cmj : cc others/js_re.res | others/belt_internals.cmi others/js.cmi $bsc -o others/js_result.cmj : cc_cmi others/js_result.res | others/belt_internals.cmi others/js.cmi others/js_result.cmi $bsc -o others/js_result.cmi : cc others/js_result.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/js_set.cmi others/js_set.cmj : cc others/js_set.res | others/belt_internals.cmi others/js.cmi $bsc -o others/js_string.cmi others/js_string.cmj : cc others/js_string.res | others/belt_internals.cmi others/js.cmi others/js_array2.cmj others/js_re.cmj $bsc -o others/js_string2.cmi others/js_string2.cmj : cc others/js_string2.res | others/belt_internals.cmi others/js.cmi others/js_array2.cmj others/js_re.cmj $bsc -o others/js_typed_array.cmi others/js_typed_array.cmj : cc others/js_typed_array.res | others/belt_internals.cmi others/js.cmi others/js_typed_array2.cmj $bsc -o others/js_typed_array2.cmi others/js_typed_array2.cmj : cc others/js_typed_array2.res | others/belt_internals.cmi others/js.cmi $bsc -o others/js_types.cmj : cc_cmi others/js_types.res | others/belt_internals.cmi others/js.cmi others/js_null.cmj others/js_types.cmi $bsc -o others/js_types.cmi : cc others/js_types.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/js_undefined.cmj : cc_cmi others/js_undefined.res | others/belt_internals.cmi others/js.cmi others/js_exn.cmj others/js_undefined.cmi $bsc -o others/js_undefined.cmi : cc others/js_undefined.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/js_weakmap.cmi others/js_weakmap.cmj : cc others/js_weakmap.res | others/belt_internals.cmi others/js.cmi $bsc -o others/js_weakset.cmi others/js_weakset.cmj : cc others/js_weakset.res | others/belt_internals.cmi others/js.cmi $bsc -o others/jsx.cmi others/jsx.cmj : cc others/jsx.res | others/belt_internals.cmi others/js.cmi $bsc -o others/jsxDOM.cmi others/jsxDOM.cmj : cc others/jsxDOM.res | others/belt_internals.cmi others/js.cmi others/jsx.cmj others/jsxDOMStyle.cmj others/jsxEvent.cmj $bsc -o others/jsxDOMStyle.cmi others/jsxDOMStyle.cmj : cc others/jsxDOMStyle.res | others/belt_internals.cmi others/js.cmi $bsc -o others/jsxEvent.cmi others/jsxEvent.cmj : cc others/jsxEvent.res | others/belt_internals.cmi others/js.cmi $bsc -o others/jsxPPXReactSupport.cmi others/jsxPPXReactSupport.cmj : cc others/jsxPPXReactSupport.res | others/belt_internals.cmi others/js.cmi others/jsx.cmj $bsc -o js_pkg : phony others/js_OO.cmi others/js_OO.cmj others/js_array.cmi others/js_array.cmj others/js_array2.cmi others/js_array2.cmj others/js_bigint.cmi others/js_bigint.cmj others/js_blob.cmi others/js_blob.cmj others/js_cast.cmi others/js_cast.cmj others/js_console.cmi others/js_console.cmj others/js_date.cmi others/js_date.cmj others/js_dict.cmi others/js_dict.cmj others/js_exn.cmi others/js_exn.cmj others/js_file.cmi others/js_file.cmj others/js_float.cmi others/js_float.cmj others/js_global.cmi others/js_global.cmj others/js_int.cmi others/js_int.cmj others/js_json.cmi others/js_json.cmj others/js_map.cmi others/js_map.cmj others/js_math.cmi others/js_math.cmj others/js_null.cmi others/js_null.cmj others/js_null_undefined.cmi others/js_null_undefined.cmj others/js_obj.cmi others/js_obj.cmj others/js_option.cmi others/js_option.cmj others/js_promise.cmi others/js_promise.cmj others/js_promise2.cmi others/js_promise2.cmj others/js_re.cmi others/js_re.cmj others/js_result.cmi others/js_result.cmj others/js_set.cmi others/js_set.cmj others/js_string.cmi others/js_string.cmj others/js_string2.cmi others/js_string2.cmj others/js_typed_array.cmi others/js_typed_array.cmj others/js_typed_array2.cmi others/js_typed_array2.cmj others/js_types.cmi others/js_types.cmj others/js_undefined.cmi others/js_undefined.cmj others/js_weakmap.cmi others/js_weakmap.cmj others/js_weakset.cmi others/js_weakset.cmj others/jsx.cmi others/jsx.cmj others/jsxDOM.cmi others/jsxDOM.cmj others/jsxDOMStyle.cmi others/jsxDOMStyle.cmj others/jsxEvent.cmi others/jsxEvent.cmj others/jsxPPXReactSupport.cmi others/jsxPPXReactSupport.cmj -o others/belt_Array.cmj : cc_cmi others/belt_Array.res | others/belt.cmi others/belt_Array.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_Array.cmi : cc others/belt_Array.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_Float.cmj : cc_cmi others/belt_Float.res | others/belt.cmi others/belt_Float.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_Float.cmi : cc others/belt_Float.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_HashMap.cmj : cc_cmi others/belt_HashMap.res | others/belt.cmi others/belt_Array.cmj others/belt_HashMap.cmi others/belt_HashMapInt.cmj others/belt_HashMapString.cmj others/belt_Id.cmj others/belt_internalBuckets.cmj others/belt_internalBucketsType.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_HashMap.cmi : cc others/belt_HashMap.resi | others/belt.cmi others/belt_HashMapInt.cmi others/belt_HashMapString.cmi others/belt_Id.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_HashMapInt.cmj : cc_cmi others/belt_HashMapInt.res | others/belt.cmi others/belt_Array.cmj others/belt_HashMapInt.cmi others/belt_internalBuckets.cmj others/belt_internalBucketsType.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_HashMapInt.cmi : cc others/belt_HashMapInt.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_HashMapString.cmj : cc_cmi others/belt_HashMapString.res | others/belt.cmi others/belt_Array.cmj others/belt_HashMapString.cmi others/belt_internalBuckets.cmj others/belt_internalBucketsType.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_HashMapString.cmi : cc others/belt_HashMapString.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_HashSet.cmj : cc_cmi others/belt_HashSet.res | others/belt.cmi others/belt_Array.cmj others/belt_HashSet.cmi others/belt_HashSetInt.cmj others/belt_HashSetString.cmj others/belt_Id.cmj others/belt_internalBucketsType.cmj others/belt_internalSetBuckets.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_HashSet.cmi : cc others/belt_HashSet.resi | others/belt.cmi others/belt_HashSetInt.cmi others/belt_HashSetString.cmi others/belt_Id.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_HashSetInt.cmj : cc_cmi others/belt_HashSetInt.res | others/belt.cmi others/belt_Array.cmj others/belt_HashSetInt.cmi others/belt_internalBucketsType.cmj others/belt_internalSetBuckets.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_HashSetInt.cmi : cc others/belt_HashSetInt.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_HashSetString.cmj : cc_cmi others/belt_HashSetString.res | others/belt.cmi others/belt_Array.cmj others/belt_HashSetString.cmi others/belt_internalBucketsType.cmj others/belt_internalSetBuckets.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_HashSetString.cmi : cc others/belt_HashSetString.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_Id.cmj : cc_cmi others/belt_Id.res | others/belt.cmi others/belt_Id.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_Id.cmi : cc others/belt_Id.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_Int.cmj : cc_cmi others/belt_Int.res | others/belt.cmi others/belt_Int.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_Int.cmi : cc others/belt_Int.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_List.cmj : cc_cmi others/belt_List.res | others/belt.cmi others/belt_Array.cmj others/belt_List.cmi others/belt_SortArray.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_List.cmi : cc others/belt_List.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_Map.cmj : cc_cmi others/belt_Map.res | others/belt.cmi others/belt_Id.cmj others/belt_Map.cmi others/belt_MapDict.cmj others/belt_MapInt.cmj others/belt_MapString.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_Map.cmi : cc others/belt_Map.resi | others/belt.cmi others/belt_Id.cmi others/belt_MapDict.cmi others/belt_MapInt.cmi others/belt_MapString.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_MapDict.cmj : cc_cmi others/belt_MapDict.res | others/belt.cmi others/belt_Array.cmj others/belt_Id.cmj others/belt_MapDict.cmi others/belt_internalAVLtree.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_MapDict.cmi : cc others/belt_MapDict.resi | others/belt.cmi others/belt_Id.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_MapInt.cmj : cc_cmi others/belt_MapInt.res | others/belt.cmi others/belt_Array.cmj others/belt_MapInt.cmi others/belt_internalAVLtree.cmj others/belt_internalMapInt.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_MapInt.cmi : cc others/belt_MapInt.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_MapString.cmj : cc_cmi others/belt_MapString.res | others/belt.cmi others/belt_Array.cmj others/belt_MapString.cmi others/belt_internalAVLtree.cmj others/belt_internalMapString.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_MapString.cmi : cc others/belt_MapString.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_MutableMap.cmj : cc_cmi others/belt_MutableMap.res | others/belt.cmi others/belt_Array.cmj others/belt_Id.cmj others/belt_MutableMap.cmi others/belt_MutableMapInt.cmj others/belt_MutableMapString.cmj others/belt_internalAVLtree.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_MutableMap.cmi : cc others/belt_MutableMap.resi | others/belt.cmi others/belt_Id.cmi others/belt_MutableMapInt.cmi others/belt_MutableMapString.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_MutableMapInt.cmj : cc_cmi others/belt_MutableMapInt.res | others/belt.cmi others/belt_Array.cmj others/belt_MutableMapInt.cmi others/belt_internalAVLtree.cmj others/belt_internalMapInt.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_MutableMapInt.cmi : cc others/belt_MutableMapInt.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_MutableMapString.cmj : cc_cmi others/belt_MutableMapString.res | others/belt.cmi others/belt_Array.cmj others/belt_MutableMapString.cmi others/belt_internalAVLtree.cmj others/belt_internalMapString.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_MutableMapString.cmi : cc others/belt_MutableMapString.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_MutableQueue.cmj : cc_cmi others/belt_MutableQueue.res | others/belt.cmi others/belt_Array.cmj others/belt_MutableQueue.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_MutableQueue.cmi : cc others/belt_MutableQueue.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_MutableSet.cmj : cc_cmi others/belt_MutableSet.res | others/belt.cmi others/belt_Array.cmj others/belt_Id.cmj others/belt_MutableSet.cmi others/belt_MutableSetInt.cmj others/belt_MutableSetString.cmj others/belt_SortArray.cmj others/belt_internalAVLset.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_MutableSet.cmi : cc others/belt_MutableSet.resi | others/belt.cmi others/belt_Id.cmi others/belt_MutableSetInt.cmi others/belt_MutableSetString.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_MutableSetInt.cmj : cc_cmi others/belt_MutableSetInt.res | others/belt.cmi others/belt_Array.cmj others/belt_MutableSetInt.cmi others/belt_SortArrayInt.cmj others/belt_internalAVLset.cmj others/belt_internalSetInt.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_MutableSetInt.cmi : cc others/belt_MutableSetInt.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_MutableSetString.cmj : cc_cmi others/belt_MutableSetString.res | others/belt.cmi others/belt_Array.cmj others/belt_MutableSetString.cmi others/belt_SortArrayString.cmj others/belt_internalAVLset.cmj others/belt_internalSetString.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_MutableSetString.cmi : cc others/belt_MutableSetString.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_MutableStack.cmj : cc_cmi others/belt_MutableStack.res | others/belt.cmi others/belt_MutableStack.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_MutableStack.cmi : cc others/belt_MutableStack.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_Option.cmj : cc_cmi others/belt_Option.res | others/belt.cmi others/belt_Option.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_Option.cmi : cc others/belt_Option.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_Range.cmj : cc_cmi others/belt_Range.res | others/belt.cmi others/belt_Range.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_Range.cmi : cc others/belt_Range.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_Result.cmj : cc_cmi others/belt_Result.res | others/belt.cmi others/belt_Result.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_Result.cmi : cc others/belt_Result.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_Set.cmj : cc_cmi others/belt_Set.res | others/belt.cmi others/belt_Id.cmj others/belt_Set.cmi others/belt_SetDict.cmj others/belt_SetInt.cmj others/belt_SetString.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_Set.cmi : cc others/belt_Set.resi | others/belt.cmi others/belt_Id.cmi others/belt_SetDict.cmi others/belt_SetInt.cmi others/belt_SetString.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_SetDict.cmj : cc_cmi others/belt_SetDict.res | others/belt.cmi others/belt_Array.cmj others/belt_Id.cmj others/belt_SetDict.cmi others/belt_internalAVLset.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_SetDict.cmi : cc others/belt_SetDict.resi | others/belt.cmi others/belt_Id.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_SetInt.cmj : cc_cmi others/belt_SetInt.res | others/belt.cmi others/belt_Array.cmj others/belt_SetInt.cmi others/belt_internalAVLset.cmj others/belt_internalSetInt.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_SetInt.cmi : cc others/belt_SetInt.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_SetString.cmj : cc_cmi others/belt_SetString.res | others/belt.cmi others/belt_Array.cmj others/belt_SetString.cmi others/belt_internalAVLset.cmj others/belt_internalSetString.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_SetString.cmi : cc others/belt_SetString.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_SortArray.cmj : cc_cmi others/belt_SortArray.res | others/belt.cmi others/belt_Array.cmj others/belt_SortArray.cmi others/belt_SortArrayInt.cmj others/belt_SortArrayString.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_SortArray.cmi : cc others/belt_SortArray.resi | others/belt.cmi others/belt_SortArrayInt.cmi others/belt_SortArrayString.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_SortArrayInt.cmj : cc_cmi others/belt_SortArrayInt.res | others/belt.cmi others/belt_Array.cmj others/belt_SortArrayInt.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_SortArrayInt.cmi : cc others/belt_SortArrayInt.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_SortArrayString.cmj : cc_cmi others/belt_SortArrayString.res | others/belt.cmi others/belt_Array.cmj others/belt_SortArrayString.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_SortArrayString.cmi : cc others/belt_SortArrayString.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_internalAVLset.cmj : cc_cmi others/belt_internalAVLset.res | others/belt.cmi others/belt_Array.cmj others/belt_Id.cmj others/belt_SortArray.cmj others/belt_internalAVLset.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_internalAVLset.cmi : cc others/belt_internalAVLset.resi | others/belt.cmi others/belt_Id.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_internalAVLtree.cmj : cc_cmi others/belt_internalAVLtree.res | others/belt.cmi others/belt_Array.cmj others/belt_Id.cmj others/belt_SortArray.cmj others/belt_internalAVLtree.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_internalAVLtree.cmi : cc others/belt_internalAVLtree.resi | others/belt.cmi others/belt_Id.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_internalBuckets.cmj : cc_cmi others/belt_internalBuckets.res | others/belt.cmi others/belt_Array.cmj others/belt_internalBuckets.cmi others/belt_internalBucketsType.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_internalBuckets.cmi : cc others/belt_internalBuckets.resi | others/belt.cmi others/belt_internalBucketsType.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_internalBucketsType.cmj : cc_cmi others/belt_internalBucketsType.res | others/belt.cmi others/belt_Array.cmj others/belt_internalBucketsType.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_internalBucketsType.cmi : cc others/belt_internalBucketsType.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/belt_internalMapInt.cmi others/belt_internalMapInt.cmj : cc others/belt_internalMapInt.res | others/belt.cmi others/belt_Array.cmj others/belt_SortArray.cmj others/belt_internalAVLtree.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_internalMapString.cmi others/belt_internalMapString.cmj : cc others/belt_internalMapString.res | others/belt.cmi others/belt_Array.cmj others/belt_SortArray.cmj others/belt_internalAVLtree.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_internalSetBuckets.cmj : cc_cmi others/belt_internalSetBuckets.res | others/belt.cmi others/belt_Array.cmj others/belt_internalBucketsType.cmj others/belt_internalSetBuckets.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_internalSetBuckets.cmi : cc others/belt_internalSetBuckets.resi | others/belt.cmi others/belt_internalBucketsType.cmi others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_internalSetInt.cmi others/belt_internalSetInt.cmj : cc others/belt_internalSetInt.res | others/belt.cmi others/belt_Array.cmj others/belt_SortArrayInt.cmj others/belt_internalAVLset.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/belt_internalSetString.cmi others/belt_internalSetString.cmj : cc others/belt_internalSetString.res | others/belt.cmi others/belt_Array.cmj others/belt_SortArrayString.cmj others/belt_internalAVLset.cmj others/belt_internals.cmi others/js.cmi $bsc js_pkg -o others/dom.cmi others/dom.cmj : cc others/dom.res | others/belt_internals.cmi others/dom_storage.cmj others/dom_storage2.cmj others/js.cmi $bsc js_pkg -o others/dom_storage.cmi others/dom_storage.cmj : cc others/dom_storage.res | others/belt_internals.cmi others/dom_storage2.cmj others/js.cmi $bsc js_pkg -o others/dom_storage2.cmi others/dom_storage2.cmj : cc others/dom_storage2.res | others/belt_internals.cmi others/js.cmi $bsc -o others/runtime_deriving.cmj : cc_cmi others/runtime_deriving.res | others/belt_internals.cmi others/js.cmi others/runtime_deriving.cmi $bsc js_pkg -o others/runtime_deriving.cmi : cc others/runtime_deriving.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/runtime_dict.cmj : cc_cmi others/runtime_dict.res | others/belt_internals.cmi others/js.cmi others/runtime_dict.cmi $bsc js_pkg -o others/runtime_dict.cmi : cc others/runtime_dict.resi | others/belt_internals.cmi others/js.cmi $bsc -o others/runtime_promise.cmi others/runtime_promise.cmj : cc others/runtime_promise.res | others/belt_internals.cmi others/js.cmi $bsc -o others : phony others/belt_Array.cmi others/belt_Array.cmj others/belt_Float.cmi others/belt_Float.cmj others/belt_HashMap.cmi others/belt_HashMap.cmj others/belt_HashMapInt.cmi others/belt_HashMapInt.cmj others/belt_HashMapString.cmi others/belt_HashMapString.cmj others/belt_HashSet.cmi others/belt_HashSet.cmj others/belt_HashSetInt.cmi others/belt_HashSetInt.cmj others/belt_HashSetString.cmi others/belt_HashSetString.cmj others/belt_Id.cmi others/belt_Id.cmj others/belt_Int.cmi others/belt_Int.cmj others/belt_List.cmi others/belt_List.cmj others/belt_Map.cmi others/belt_Map.cmj others/belt_MapDict.cmi others/belt_MapDict.cmj others/belt_MapInt.cmi others/belt_MapInt.cmj others/belt_MapString.cmi others/belt_MapString.cmj others/belt_MutableMap.cmi others/belt_MutableMap.cmj others/belt_MutableMapInt.cmi others/belt_MutableMapInt.cmj others/belt_MutableMapString.cmi others/belt_MutableMapString.cmj others/belt_MutableQueue.cmi others/belt_MutableQueue.cmj others/belt_MutableSet.cmi others/belt_MutableSet.cmj others/belt_MutableSetInt.cmi others/belt_MutableSetInt.cmj others/belt_MutableSetString.cmi others/belt_MutableSetString.cmj others/belt_MutableStack.cmi others/belt_MutableStack.cmj others/belt_Option.cmi others/belt_Option.cmj others/belt_Range.cmi others/belt_Range.cmj others/belt_Result.cmi others/belt_Result.cmj others/belt_Set.cmi others/belt_Set.cmj others/belt_SetDict.cmi others/belt_SetDict.cmj others/belt_SetInt.cmi others/belt_SetInt.cmj others/belt_SetString.cmi others/belt_SetString.cmj others/belt_SortArray.cmi others/belt_SortArray.cmj others/belt_SortArrayInt.cmi others/belt_SortArrayInt.cmj others/belt_SortArrayString.cmi others/belt_SortArrayString.cmj others/belt_internalAVLset.cmi others/belt_internalAVLset.cmj others/belt_internalAVLtree.cmi others/belt_internalAVLtree.cmj others/belt_internalBuckets.cmi others/belt_internalBuckets.cmj others/belt_internalBucketsType.cmi others/belt_internalBucketsType.cmj others/belt_internalMapInt.cmi others/belt_internalMapInt.cmj others/belt_internalMapString.cmi others/belt_internalMapString.cmj others/belt_internalSetBuckets.cmi others/belt_internalSetBuckets.cmj others/belt_internalSetInt.cmi others/belt_internalSetInt.cmj others/belt_internalSetString.cmi others/belt_internalSetString.cmj others/dom.cmi others/dom.cmj others/dom_storage.cmi others/dom_storage.cmj others/dom_storage2.cmi others/dom_storage2.cmj others/runtime_deriving.cmi others/runtime_deriving.cmj others/runtime_dict.cmi others/runtime_dict.cmj others/runtime_promise.cmi others/runtime_promise.cmj +o others/belt.cmj others/belt.cmi : cc others/belt.res | $bsc runtime +o others/js.cmi others/js.cmj : cc others/js.res | others/js_array.cmj others/js_array2.cmj others/js_bigint.cmj others/js_blob.cmj others/js_console.cmj others/js_date.cmj others/js_dict.cmj others/js_exn.cmj others/js_file.cmj others/js_float.cmj others/js_global.cmj others/js_int.cmj others/js_json.cmj others/js_map.cmj others/js_math.cmj others/js_null.cmj others/js_null_undefined.cmj others/js_obj.cmj others/js_option.cmj others/js_promise.cmj others/js_promise2.cmj others/js_re.cmj others/js_result.cmj others/js_set.cmj others/js_string.cmj others/js_string2.cmj others/js_typed_array.cmj others/js_typed_array2.cmj others/js_types.cmj others/js_undefined.cmj others/js_weakmap.cmj others/js_weakset.cmj $bsc runtime +o others/js_OO.cmi others/js_OO.cmj : cc others/js_OO.res | $bsc runtime +o others/js_array.cmi others/js_array.cmj : cc others/js_array.res | others/js_array2.cmj $bsc runtime +o others/js_array2.cmi others/js_array2.cmj : cc others/js_array2.res | $bsc runtime +o others/js_bigint.cmi others/js_bigint.cmj : cc others/js_bigint.res | $bsc runtime +o others/js_blob.cmi others/js_blob.cmj : cc others/js_blob.res | $bsc runtime +o others/js_cast.cmj : cc_cmi others/js_cast.res | others/js_cast.cmi $bsc runtime +o others/js_cast.cmi : cc others/js_cast.resi | $bsc runtime +o others/js_console.cmi others/js_console.cmj : cc others/js_console.res | $bsc runtime +o others/js_date.cmi others/js_date.cmj : cc others/js_date.res | $bsc runtime +o others/js_dict.cmj : cc_cmi others/js_dict.res | others/js_array2.cmj others/js_dict.cmi $bsc runtime +o others/js_dict.cmi : cc others/js_dict.resi | $bsc runtime +o others/js_exn.cmj : cc_cmi others/js_exn.res | others/js_exn.cmi $bsc runtime +o others/js_exn.cmi : cc others/js_exn.resi | $bsc runtime +o others/js_extern.cmi others/js_extern.cmj : cc others/js_extern.res | $bsc runtime +o others/js_file.cmi others/js_file.cmj : cc others/js_file.res | $bsc runtime +o others/js_float.cmi others/js_float.cmj : cc others/js_float.res | $bsc runtime +o others/js_global.cmi others/js_global.cmj : cc others/js_global.res | $bsc runtime +o others/js_int.cmi others/js_int.cmj : cc others/js_int.res | $bsc runtime +o others/js_json.cmj : cc_cmi others/js_json.res | others/js_array2.cmj others/js_dict.cmj others/js_extern.cmj others/js_json.cmi others/js_null.cmj others/js_string.cmj others/js_types.cmj $bsc runtime +o others/js_json.cmi : cc others/js_json.resi | others/js_dict.cmi others/js_null.cmi others/js_string.cmj others/js_types.cmi $bsc runtime +o others/js_map.cmi others/js_map.cmj : cc others/js_map.res | $bsc runtime +o others/js_math.cmi others/js_math.cmj : cc others/js_math.res | others/js_int.cmj $bsc runtime +o others/js_null.cmj : cc_cmi others/js_null.res | others/js_exn.cmj others/js_extern.cmj others/js_null.cmi $bsc runtime +o others/js_null.cmi : cc others/js_null.resi | $bsc runtime +o others/js_null_undefined.cmj : cc_cmi others/js_null_undefined.res | others/js_null_undefined.cmi $bsc runtime +o others/js_null_undefined.cmi : cc others/js_null_undefined.resi | $bsc runtime +o others/js_obj.cmi others/js_obj.cmj : cc others/js_obj.res | $bsc runtime +o others/js_option.cmj : cc_cmi others/js_option.res | others/js_exn.cmj others/js_option.cmi $bsc runtime +o others/js_option.cmi : cc others/js_option.resi | $bsc runtime +o others/js_promise.cmi others/js_promise.cmj : cc others/js_promise.res | others/js_promise2.cmj $bsc runtime +o others/js_promise2.cmi others/js_promise2.cmj : cc others/js_promise2.res | $bsc runtime +o others/js_re.cmi others/js_re.cmj : cc others/js_re.res | others/js_null_undefined.cmj $bsc runtime +o others/js_result.cmj : cc_cmi others/js_result.res | others/js_result.cmi $bsc runtime +o others/js_result.cmi : cc others/js_result.resi | $bsc runtime +o others/js_set.cmi others/js_set.cmj : cc others/js_set.res | $bsc runtime +o others/js_string.cmi others/js_string.cmj : cc others/js_string.res | others/js_array2.cmj others/js_re.cmj $bsc runtime +o others/js_string2.cmi others/js_string2.cmj : cc others/js_string2.res | others/js_array2.cmj others/js_re.cmj $bsc runtime +o others/js_typed_array.cmi others/js_typed_array.cmj : cc others/js_typed_array.res | others/js_typed_array2.cmj $bsc runtime +o others/js_typed_array2.cmi others/js_typed_array2.cmj : cc others/js_typed_array2.res | others/js_undefined.cmj $bsc runtime +o others/js_types.cmj : cc_cmi others/js_types.res | others/js_extern.cmj others/js_null.cmj others/js_types.cmi $bsc runtime +o others/js_types.cmi : cc others/js_types.resi | $bsc runtime +o others/js_undefined.cmj : cc_cmi others/js_undefined.res | others/js_exn.cmj others/js_undefined.cmi $bsc runtime +o others/js_undefined.cmi : cc others/js_undefined.resi | $bsc runtime +o others/js_weakmap.cmi others/js_weakmap.cmj : cc others/js_weakmap.res | $bsc runtime +o others/js_weakset.cmi others/js_weakset.cmj : cc others/js_weakset.res | $bsc runtime +o others/jsx.cmi others/jsx.cmj : cc others/jsx.res | $bsc runtime +o others/jsxDOM.cmi others/jsxDOM.cmj : cc others/jsxDOM.res | others/jsx.cmj others/jsxDOMStyle.cmj others/jsxEvent.cmj $bsc runtime +o others/jsxDOMStyle.cmi others/jsxDOMStyle.cmj : cc others/jsxDOMStyle.res | $bsc runtime +o others/jsxEvent.cmi others/jsxEvent.cmj : cc others/jsxEvent.res | $bsc runtime +o others/jsxPPXReactSupport.cmi others/jsxPPXReactSupport.cmj : cc others/jsxPPXReactSupport.res | others/jsx.cmj $bsc runtime +o js_pkg : phony others/js.cmi others/js.cmj others/js_OO.cmi others/js_OO.cmj others/js_array.cmi others/js_array.cmj others/js_array2.cmi others/js_array2.cmj others/js_bigint.cmi others/js_bigint.cmj others/js_blob.cmi others/js_blob.cmj others/js_cast.cmi others/js_cast.cmj others/js_console.cmi others/js_console.cmj others/js_date.cmi others/js_date.cmj others/js_dict.cmi others/js_dict.cmj others/js_exn.cmi others/js_exn.cmj others/js_extern.cmi others/js_extern.cmj others/js_file.cmi others/js_file.cmj others/js_float.cmi others/js_float.cmj others/js_global.cmi others/js_global.cmj others/js_int.cmi others/js_int.cmj others/js_json.cmi others/js_json.cmj others/js_map.cmi others/js_map.cmj others/js_math.cmi others/js_math.cmj others/js_null.cmi others/js_null.cmj others/js_null_undefined.cmi others/js_null_undefined.cmj others/js_obj.cmi others/js_obj.cmj others/js_option.cmi others/js_option.cmj others/js_promise.cmi others/js_promise.cmj others/js_promise2.cmi others/js_promise2.cmj others/js_re.cmi others/js_re.cmj others/js_result.cmi others/js_result.cmj others/js_set.cmi others/js_set.cmj others/js_string.cmi others/js_string.cmj others/js_string2.cmi others/js_string2.cmj others/js_typed_array.cmi others/js_typed_array.cmj others/js_typed_array2.cmi others/js_typed_array2.cmj others/js_types.cmi others/js_types.cmj others/js_undefined.cmi others/js_undefined.cmj others/js_weakmap.cmi others/js_weakmap.cmj others/js_weakset.cmi others/js_weakset.cmj others/jsx.cmi others/jsx.cmj others/jsxDOM.cmi others/jsxDOM.cmj others/jsxDOMStyle.cmi others/jsxDOMStyle.cmj others/jsxEvent.cmi others/jsxEvent.cmj others/jsxPPXReactSupport.cmi others/jsxPPXReactSupport.cmj +o others/belt_Array.cmj : cc_cmi others/belt_Array.res | others/belt.cmi others/belt_Array.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_Array.cmi : cc others/belt_Array.resi | others/js.cmi $bsc runtime +o others/belt_Float.cmj : cc_cmi others/belt_Float.res | others/belt.cmi others/belt_Float.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_Float.cmi : cc others/belt_Float.resi | others/js.cmi $bsc runtime +o others/belt_HashMap.cmj : cc_cmi others/belt_HashMap.res | others/belt.cmi others/belt_Array.cmj others/belt_HashMap.cmi others/belt_HashMapInt.cmj others/belt_HashMapString.cmj others/belt_Id.cmj others/belt_internalBuckets.cmj others/belt_internalBucketsType.cmj others/js.cmi $bsc js_pkg runtime +o others/belt_HashMap.cmi : cc others/belt_HashMap.resi | others/belt.cmi others/belt_HashMapInt.cmi others/belt_HashMapString.cmi others/belt_Id.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_HashMapInt.cmj : cc_cmi others/belt_HashMapInt.res | others/belt.cmi others/belt_Array.cmj others/belt_HashMapInt.cmi others/belt_internalBuckets.cmj others/belt_internalBucketsType.cmj others/js.cmi $bsc js_pkg runtime +o others/belt_HashMapInt.cmi : cc others/belt_HashMapInt.resi | others/js.cmi $bsc runtime +o others/belt_HashMapString.cmj : cc_cmi others/belt_HashMapString.res | others/belt.cmi others/belt_Array.cmj others/belt_HashMapString.cmi others/belt_internalBuckets.cmj others/belt_internalBucketsType.cmj others/js.cmi $bsc js_pkg runtime +o others/belt_HashMapString.cmi : cc others/belt_HashMapString.resi | others/js.cmi $bsc runtime +o others/belt_HashSet.cmj : cc_cmi others/belt_HashSet.res | others/belt.cmi others/belt_Array.cmj others/belt_HashSet.cmi others/belt_HashSetInt.cmj others/belt_HashSetString.cmj others/belt_Id.cmj others/belt_internalBucketsType.cmj others/belt_internalSetBuckets.cmj others/js.cmi $bsc js_pkg runtime +o others/belt_HashSet.cmi : cc others/belt_HashSet.resi | others/belt.cmi others/belt_HashSetInt.cmi others/belt_HashSetString.cmi others/belt_Id.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_HashSetInt.cmj : cc_cmi others/belt_HashSetInt.res | others/belt.cmi others/belt_Array.cmj others/belt_HashSetInt.cmi others/belt_internalBucketsType.cmj others/belt_internalSetBuckets.cmj others/js.cmi $bsc js_pkg runtime +o others/belt_HashSetInt.cmi : cc others/belt_HashSetInt.resi | others/js.cmi $bsc runtime +o others/belt_HashSetString.cmj : cc_cmi others/belt_HashSetString.res | others/belt.cmi others/belt_Array.cmj others/belt_HashSetString.cmi others/belt_internalBucketsType.cmj others/belt_internalSetBuckets.cmj others/js.cmi $bsc js_pkg runtime +o others/belt_HashSetString.cmi : cc others/belt_HashSetString.resi | others/js.cmi $bsc runtime +o others/belt_Id.cmj : cc_cmi others/belt_Id.res | others/belt.cmi others/belt_Id.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_Id.cmi : cc others/belt_Id.resi | others/js.cmi $bsc runtime +o others/belt_Int.cmj : cc_cmi others/belt_Int.res | others/belt.cmi others/belt_Int.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_Int.cmi : cc others/belt_Int.resi | others/js.cmi $bsc runtime +o others/belt_List.cmj : cc_cmi others/belt_List.res | others/belt.cmi others/belt_Array.cmj others/belt_List.cmi others/belt_SortArray.cmj others/js.cmi $bsc js_pkg runtime +o others/belt_List.cmi : cc others/belt_List.resi | others/js.cmi $bsc runtime +o others/belt_Map.cmj : cc_cmi others/belt_Map.res | others/belt.cmi others/belt_Id.cmj others/belt_Map.cmi others/belt_MapDict.cmj others/belt_MapInt.cmj others/belt_MapString.cmj others/js.cmi $bsc js_pkg runtime +o others/belt_Map.cmi : cc others/belt_Map.resi | others/belt.cmi others/belt_Id.cmi others/belt_MapDict.cmi others/belt_MapInt.cmi others/belt_MapString.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_MapDict.cmj : cc_cmi others/belt_MapDict.res | others/belt.cmi others/belt_Array.cmj others/belt_Id.cmj others/belt_MapDict.cmi others/belt_internalAVLtree.cmj others/js.cmi $bsc js_pkg runtime +o others/belt_MapDict.cmi : cc others/belt_MapDict.resi | others/belt.cmi others/belt_Id.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_MapInt.cmj : cc_cmi others/belt_MapInt.res | others/belt.cmi others/belt_Array.cmj others/belt_MapInt.cmi others/belt_internalAVLtree.cmj others/belt_internalMapInt.cmj others/js.cmi $bsc js_pkg runtime +o others/belt_MapInt.cmi : cc others/belt_MapInt.resi | others/js.cmi $bsc runtime +o others/belt_MapString.cmj : cc_cmi others/belt_MapString.res | others/belt.cmi others/belt_Array.cmj others/belt_MapString.cmi others/belt_internalAVLtree.cmj others/belt_internalMapString.cmj others/js.cmi $bsc js_pkg runtime +o others/belt_MapString.cmi : cc others/belt_MapString.resi | others/js.cmi $bsc runtime +o others/belt_MutableMap.cmj : cc_cmi others/belt_MutableMap.res | others/belt.cmi others/belt_Array.cmj others/belt_Id.cmj others/belt_MutableMap.cmi others/belt_MutableMapInt.cmj others/belt_MutableMapString.cmj others/belt_internalAVLtree.cmj others/js.cmi $bsc js_pkg runtime +o others/belt_MutableMap.cmi : cc others/belt_MutableMap.resi | others/belt.cmi others/belt_Id.cmi others/belt_MutableMapInt.cmi others/belt_MutableMapString.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_MutableMapInt.cmj : cc_cmi others/belt_MutableMapInt.res | others/belt.cmi others/belt_Array.cmj others/belt_MutableMapInt.cmi others/belt_internalAVLtree.cmj others/belt_internalMapInt.cmj others/js.cmi $bsc js_pkg runtime +o others/belt_MutableMapInt.cmi : cc others/belt_MutableMapInt.resi | others/js.cmi $bsc runtime +o others/belt_MutableMapString.cmj : cc_cmi others/belt_MutableMapString.res | others/belt.cmi others/belt_Array.cmj others/belt_MutableMapString.cmi others/belt_internalAVLtree.cmj others/belt_internalMapString.cmj others/js.cmi $bsc js_pkg runtime +o others/belt_MutableMapString.cmi : cc others/belt_MutableMapString.resi | others/js.cmi $bsc runtime +o others/belt_MutableQueue.cmj : cc_cmi others/belt_MutableQueue.res | others/belt.cmi others/belt_Array.cmj others/belt_MutableQueue.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_MutableQueue.cmi : cc others/belt_MutableQueue.resi | others/js.cmi $bsc runtime +o others/belt_MutableSet.cmj : cc_cmi others/belt_MutableSet.res | others/belt.cmi others/belt_Array.cmj others/belt_Id.cmj others/belt_MutableSet.cmi others/belt_MutableSetInt.cmj others/belt_MutableSetString.cmj others/belt_SortArray.cmj others/belt_internalAVLset.cmj others/js.cmi $bsc js_pkg runtime +o others/belt_MutableSet.cmi : cc others/belt_MutableSet.resi | others/belt.cmi others/belt_Id.cmi others/belt_MutableSetInt.cmi others/belt_MutableSetString.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_MutableSetInt.cmj : cc_cmi others/belt_MutableSetInt.res | others/belt.cmi others/belt_Array.cmj others/belt_MutableSetInt.cmi others/belt_SortArrayInt.cmj others/belt_internalAVLset.cmj others/belt_internalSetInt.cmj others/js.cmi $bsc js_pkg runtime +o others/belt_MutableSetInt.cmi : cc others/belt_MutableSetInt.resi | others/js.cmi $bsc runtime +o others/belt_MutableSetString.cmj : cc_cmi others/belt_MutableSetString.res | others/belt.cmi others/belt_Array.cmj others/belt_MutableSetString.cmi others/belt_SortArrayString.cmj others/belt_internalAVLset.cmj others/belt_internalSetString.cmj others/js.cmi $bsc js_pkg runtime +o others/belt_MutableSetString.cmi : cc others/belt_MutableSetString.resi | others/js.cmi $bsc runtime +o others/belt_MutableStack.cmj : cc_cmi others/belt_MutableStack.res | others/belt.cmi others/belt_MutableStack.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_MutableStack.cmi : cc others/belt_MutableStack.resi | others/js.cmi $bsc runtime +o others/belt_Option.cmj : cc_cmi others/belt_Option.res | others/belt.cmi others/belt_Option.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_Option.cmi : cc others/belt_Option.resi | others/js.cmi $bsc runtime +o others/belt_Range.cmj : cc_cmi others/belt_Range.res | others/belt.cmi others/belt_Range.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_Range.cmi : cc others/belt_Range.resi | others/js.cmi $bsc runtime +o others/belt_Result.cmj : cc_cmi others/belt_Result.res | others/belt.cmi others/belt_Result.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_Result.cmi : cc others/belt_Result.resi | others/js.cmi $bsc runtime +o others/belt_Set.cmj : cc_cmi others/belt_Set.res | others/belt.cmi others/belt_Id.cmj others/belt_Set.cmi others/belt_SetDict.cmj others/belt_SetInt.cmj others/belt_SetString.cmj others/js.cmi $bsc js_pkg runtime +o others/belt_Set.cmi : cc others/belt_Set.resi | others/belt.cmi others/belt_Id.cmi others/belt_SetDict.cmi others/belt_SetInt.cmi others/belt_SetString.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_SetDict.cmj : cc_cmi others/belt_SetDict.res | others/belt.cmi others/belt_Array.cmj others/belt_Id.cmj others/belt_SetDict.cmi others/belt_internalAVLset.cmj others/js.cmi $bsc js_pkg runtime +o others/belt_SetDict.cmi : cc others/belt_SetDict.resi | others/belt.cmi others/belt_Id.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_SetInt.cmj : cc_cmi others/belt_SetInt.res | others/belt.cmi others/belt_Array.cmj others/belt_SetInt.cmi others/belt_internalAVLset.cmj others/belt_internalSetInt.cmj others/js.cmi $bsc js_pkg runtime +o others/belt_SetInt.cmi : cc others/belt_SetInt.resi | others/js.cmi $bsc runtime +o others/belt_SetString.cmj : cc_cmi others/belt_SetString.res | others/belt.cmi others/belt_Array.cmj others/belt_SetString.cmi others/belt_internalAVLset.cmj others/belt_internalSetString.cmj others/js.cmi $bsc js_pkg runtime +o others/belt_SetString.cmi : cc others/belt_SetString.resi | others/js.cmi $bsc runtime +o others/belt_SortArray.cmj : cc_cmi others/belt_SortArray.res | others/belt.cmi others/belt_Array.cmj others/belt_SortArray.cmi others/belt_SortArrayInt.cmj others/belt_SortArrayString.cmj others/js.cmi $bsc js_pkg runtime +o others/belt_SortArray.cmi : cc others/belt_SortArray.resi | others/belt.cmi others/belt_SortArrayInt.cmi others/belt_SortArrayString.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_SortArrayInt.cmj : cc_cmi others/belt_SortArrayInt.res | others/belt.cmi others/belt_Array.cmj others/belt_SortArrayInt.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_SortArrayInt.cmi : cc others/belt_SortArrayInt.resi | others/js.cmi $bsc runtime +o others/belt_SortArrayString.cmj : cc_cmi others/belt_SortArrayString.res | others/belt.cmi others/belt_Array.cmj others/belt_SortArrayString.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_SortArrayString.cmi : cc others/belt_SortArrayString.resi | others/js.cmi $bsc runtime +o others/belt_internalAVLset.cmj : cc_cmi others/belt_internalAVLset.res | others/belt.cmi others/belt_Array.cmj others/belt_Id.cmj others/belt_SortArray.cmj others/belt_internalAVLset.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_internalAVLset.cmi : cc others/belt_internalAVLset.resi | others/belt.cmi others/belt_Id.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_internalAVLtree.cmj : cc_cmi others/belt_internalAVLtree.res | others/belt.cmi others/belt_Array.cmj others/belt_Id.cmj others/belt_SortArray.cmj others/belt_internalAVLtree.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_internalAVLtree.cmi : cc others/belt_internalAVLtree.resi | others/belt.cmi others/belt_Id.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_internalBuckets.cmj : cc_cmi others/belt_internalBuckets.res | others/belt.cmi others/belt_Array.cmj others/belt_internalBuckets.cmi others/belt_internalBucketsType.cmj others/js.cmi $bsc js_pkg runtime +o others/belt_internalBuckets.cmi : cc others/belt_internalBuckets.resi | others/belt.cmi others/belt_internalBucketsType.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_internalBucketsType.cmj : cc_cmi others/belt_internalBucketsType.res | others/belt.cmi others/belt_Array.cmj others/belt_internalBucketsType.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_internalBucketsType.cmi : cc others/belt_internalBucketsType.resi | others/js.cmi $bsc runtime +o others/belt_internalMapInt.cmi others/belt_internalMapInt.cmj : cc others/belt_internalMapInt.res | others/belt.cmi others/belt_Array.cmj others/belt_SortArray.cmj others/belt_internalAVLtree.cmj others/js.cmi $bsc js_pkg runtime +o others/belt_internalMapString.cmi others/belt_internalMapString.cmj : cc others/belt_internalMapString.res | others/belt.cmi others/belt_Array.cmj others/belt_SortArray.cmj others/belt_internalAVLtree.cmj others/js.cmi $bsc js_pkg runtime +o others/belt_internalSetBuckets.cmj : cc_cmi others/belt_internalSetBuckets.res | others/belt.cmi others/belt_Array.cmj others/belt_internalBucketsType.cmj others/belt_internalSetBuckets.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_internalSetBuckets.cmi : cc others/belt_internalSetBuckets.resi | others/belt.cmi others/belt_internalBucketsType.cmi others/js.cmi $bsc js_pkg runtime +o others/belt_internalSetInt.cmi others/belt_internalSetInt.cmj : cc others/belt_internalSetInt.res | others/belt.cmi others/belt_Array.cmj others/belt_SortArrayInt.cmj others/belt_internalAVLset.cmj others/js.cmi $bsc js_pkg runtime +o others/belt_internalSetString.cmi others/belt_internalSetString.cmj : cc others/belt_internalSetString.res | others/belt.cmi others/belt_Array.cmj others/belt_SortArrayString.cmj others/belt_internalAVLset.cmj others/js.cmi $bsc js_pkg runtime +o others/dom.cmi others/dom.cmj : cc others/dom.res | others/dom_storage.cmj others/dom_storage2.cmj others/js.cmi $bsc js_pkg runtime +o others/dom_storage.cmi others/dom_storage.cmj : cc others/dom_storage.res | others/dom_storage2.cmj others/js.cmi $bsc js_pkg runtime +o others/dom_storage2.cmi others/dom_storage2.cmj : cc others/dom_storage2.res | others/js.cmi $bsc runtime +o others : phony others/belt_Array.cmi others/belt_Array.cmj others/belt_Float.cmi others/belt_Float.cmj others/belt_HashMap.cmi others/belt_HashMap.cmj others/belt_HashMapInt.cmi others/belt_HashMapInt.cmj others/belt_HashMapString.cmi others/belt_HashMapString.cmj others/belt_HashSet.cmi others/belt_HashSet.cmj others/belt_HashSetInt.cmi others/belt_HashSetInt.cmj others/belt_HashSetString.cmi others/belt_HashSetString.cmj others/belt_Id.cmi others/belt_Id.cmj others/belt_Int.cmi others/belt_Int.cmj others/belt_List.cmi others/belt_List.cmj others/belt_Map.cmi others/belt_Map.cmj others/belt_MapDict.cmi others/belt_MapDict.cmj others/belt_MapInt.cmi others/belt_MapInt.cmj others/belt_MapString.cmi others/belt_MapString.cmj others/belt_MutableMap.cmi others/belt_MutableMap.cmj others/belt_MutableMapInt.cmi others/belt_MutableMapInt.cmj others/belt_MutableMapString.cmi others/belt_MutableMapString.cmj others/belt_MutableQueue.cmi others/belt_MutableQueue.cmj others/belt_MutableSet.cmi others/belt_MutableSet.cmj others/belt_MutableSetInt.cmi others/belt_MutableSetInt.cmj others/belt_MutableSetString.cmi others/belt_MutableSetString.cmj others/belt_MutableStack.cmi others/belt_MutableStack.cmj others/belt_Option.cmi others/belt_Option.cmj others/belt_Range.cmi others/belt_Range.cmj others/belt_Result.cmi others/belt_Result.cmj others/belt_Set.cmi others/belt_Set.cmj others/belt_SetDict.cmi others/belt_SetDict.cmj others/belt_SetInt.cmi others/belt_SetInt.cmj others/belt_SetString.cmi others/belt_SetString.cmj others/belt_SortArray.cmi others/belt_SortArray.cmj others/belt_SortArrayInt.cmi others/belt_SortArrayInt.cmj others/belt_SortArrayString.cmi others/belt_SortArrayString.cmj others/belt_internalAVLset.cmi others/belt_internalAVLset.cmj others/belt_internalAVLtree.cmi others/belt_internalAVLtree.cmj others/belt_internalBuckets.cmi others/belt_internalBuckets.cmj others/belt_internalBucketsType.cmi others/belt_internalBucketsType.cmj others/belt_internalMapInt.cmi others/belt_internalMapInt.cmj others/belt_internalMapString.cmi others/belt_internalMapString.cmj others/belt_internalSetBuckets.cmi others/belt_internalSetBuckets.cmj others/belt_internalSetInt.cmi others/belt_internalSetInt.cmj others/belt_internalSetString.cmi others/belt_internalSetString.cmj others/dom.cmi others/dom.cmj others/dom_storage.cmi others/dom_storage.cmj others/dom_storage2.cmi others/dom_storage2.cmj diff --git a/jscomp/others/runtime_deriving.res b/jscomp/others/runtime_deriving.res deleted file mode 100644 index 7aa535e41b..0000000000 --- a/jscomp/others/runtime_deriving.res +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (C) 2017 Hongbo Zhang, Authors of ReScript - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -let raiseWhenNotFound = x => - if Js.testAny(x) { - raise(Not_found) - } else { - x - } diff --git a/jscomp/others/runtime_deriving.resi b/jscomp/others/runtime_deriving.resi deleted file mode 100644 index fa5cdeb74d..0000000000 --- a/jscomp/others/runtime_deriving.resi +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 2017 Authors of ReScript - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -let raiseWhenNotFound: 'a => 'a diff --git a/jscomp/others/runtime_dict.res b/jscomp/others/runtime_dict.res deleted file mode 100644 index 7f40937dc5..0000000000 --- a/jscomp/others/runtime_dict.res +++ /dev/null @@ -1 +0,0 @@ -external unsafe_create: array<(string, 'a)> => dict<'a> = "?create_dict" diff --git a/jscomp/others/runtime_dict.resi b/jscomp/others/runtime_dict.resi deleted file mode 100644 index 7f40937dc5..0000000000 --- a/jscomp/others/runtime_dict.resi +++ /dev/null @@ -1 +0,0 @@ -external unsafe_create: array<(string, 'a)> => dict<'a> = "?create_dict" diff --git a/jscomp/others/runtime_promise.res b/jscomp/others/runtime_promise.res deleted file mode 100644 index e674a1c1cd..0000000000 --- a/jscomp/others/runtime_promise.res +++ /dev/null @@ -1,28 +0,0 @@ -/* Copyright (C) 2017 Hongbo Zhang, Authors of ReScript - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -external unsafe_async: 'a => promise<'a> = "%identity" -external unsafe_await: promise<'a> => 'a = "?await" - -external import: 'a => promise<'a> = "#import" diff --git a/jscomp/stdlib-406/array.res b/jscomp/runtime/array.res similarity index 76% rename from jscomp/stdlib-406/array.res rename to jscomp/runtime/array.res index 486217b151..6339770b3a 100644 --- a/jscomp/stdlib-406/array.res +++ b/jscomp/runtime/array.res @@ -1,79 +1,52 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/* Array operations */ +// FIXME: +// This exists for compatibility reason. +// Move this into Pervasives or Core -external length: array<'a> => int = "%array_length" +// Caution: `Array.get` is implicitly used by `array[idx]` syntax external get: (array<'a>, int) => 'a = "%array_safe_get" + +// Caution: `Array.set` is implicitly used by `array[idx]` syntax external set: (array<'a>, int, 'a) => unit = "%array_safe_set" + +// Below is all deprecated and should be removed in v13 + +external length: array<'a> => int = "%array_length" + external unsafe_get: (array<'a>, int) => 'a = "%array_unsafe_get" + external unsafe_set: (array<'a>, int, 'a) => unit = "%array_unsafe_set" -external make: (int, 'a) => array<'a> = "?make_vect" -external create: (int, 'a) => array<'a> = "?make_vect" -external unsafe_sub: (array<'a>, int, int) => array<'a> = "?array_sub" +let init: (int, int => 'a) => array<'a> = %raw(`(length, f) => Array.from({ length }, f)`) + +let make = (len, x) => init(len, _ => x) + +@send external slice: (array<'a>, int, int) => array<'a> = "slice" +let unsafe_sub = (array, offset, length) => array->slice(offset, offset + length) + +@send external concat: (array<'a>, array<'a>) => array<'a> = "concat" @send external append_prim: (array<'a>, array<'a>) => array<'a> = "concat" -external concat: list> => array<'a> = "?array_concat" -external unsafe_blit: (array<'a>, int, array<'a>, int, int) => unit = "?array_blit" -external create_float: int => array = "?make_float_vect" -let make_float = create_float - -module Floatarray = { - external create: int => floatarray = "?floatarray_create" - external length: floatarray => int = "%floatarray_length" - external get: (floatarray, int) => float = "%floatarray_safe_get" - external set: (floatarray, int, float) => unit = "%floatarray_safe_set" - external unsafe_get: (floatarray, int) => float = "%floatarray_unsafe_get" - external unsafe_set: (floatarray, int, float) => unit = "%floatarray_unsafe_set" +let concat = list => { + List.fold_left((arr1, arr2) => arr1->concat(arr2), [], list) } -let init = (l, f) => - if l == 0 { - [] - } else if l < 0 { - invalid_arg("Array.init") - } else { - /* See #6575. We could also check for maximum array size, but this depends - on whether we create a float array or a regular one... */ - - let res = create(l, f(0)) - for i in 1 to pred(l) { - unsafe_set(res, i, f(i)) - } - res +let unsafe_blit = (srcArray, srcOffset, destArray, destOffset, len) => { + for i in 0 to len - 1 { + destArray->unsafe_set(destOffset + i, srcArray->unsafe_get(srcOffset + i)) } +} + +let create_float = len => make(len, 0.0) let make_matrix = (sx, sy, init) => { - let res = create(sx, []) + let res = make(sx, []) for x in 0 to pred(sx) { - unsafe_set(res, x, create(sy, init)) + unsafe_set(res, x, make(sy, init)) } res } -let create_matrix = make_matrix - -let copy = a => { - let l = length(a) - if l == 0 { - [] - } else { - unsafe_sub(a, 0, l) - } -} +@send external copy: array<'a> => array<'a> = "slice" let append = (a1, a2) => { let l1 = length(a1) @@ -128,7 +101,7 @@ let map = (f, a) => { if l == 0 { [] } else { - let r = create(l, f(unsafe_get(a, 0))) + let r = make(l, f(unsafe_get(a, 0))) for i in 1 to l - 1 { unsafe_set(r, i, f(unsafe_get(a, i))) } @@ -144,7 +117,7 @@ let map2 = (f, a, b) => { } else if la == 0 { [] } else { - let r = create(la, f(unsafe_get(a, 0), unsafe_get(b, 0))) + let r = make(la, f(unsafe_get(a, 0), unsafe_get(b, 0))) for i in 1 to la - 1 { unsafe_set(r, i, f(unsafe_get(a, i), unsafe_get(b, i))) } @@ -162,7 +135,7 @@ let mapi = (f, a) => { if l == 0 { [] } else { - let r = create(l, f(0, unsafe_get(a, 0))) + let r = make(l, f(0, unsafe_get(a, 0))) for i in 1 to l - 1 { unsafe_set(r, i, f(i, unsafe_get(a, i))) } @@ -191,7 +164,7 @@ let of_list = param => switch param { | list{} => [] | list{hd, ...tl} as l => - let a = create(list_length(0, l), hd) + let a = make(list_length(0, l), hd) let rec fill = (i, param) => switch param { | list{} => a diff --git a/jscomp/stdlib-406/array.resi b/jscomp/runtime/array.resi similarity index 77% rename from jscomp/stdlib-406/array.resi rename to jscomp/runtime/array.resi index d16f7bb088..74a7c24724 100644 --- a/jscomp/stdlib-406/array.resi +++ b/jscomp/runtime/array.resi @@ -1,40 +1,19 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/* Array operations. */ +// FIXME: +// This exists for compatibility reason. +// Move this into Pervasives or Core -/** Return the length (number of elements) of the given array. */ -external length: array<'a> => int = "%array_length" - -/** [Array.get a n] returns the element number [n] of array [a]. - The first element has number 0. - The last element has number [Array.length a - 1]. - You can also write [a.(n)] instead of [Array.get a n]. - - Raise [Invalid_argument "index out of bounds"] - if [n] is outside the range 0 to [(Array.length a - 1)]. */ +// Caution: `Array.get` is implicitly used by `array[idx]` syntax external get: (array<'a>, int) => 'a = "%array_safe_get" -/** [Array.set a n x] modifies array [a] in place, replacing - element number [n] with [x]. - You can also write [a.(n) <- x] instead of [Array.set a n x]. - - Raise [Invalid_argument "index out of bounds"] - if [n] is outside the range 0 to [Array.length a - 1]. */ +// Caution: `Array.set` is implicitly used by `array[idx]` syntax external set: (array<'a>, int, 'a) => unit = "%array_safe_set" +// Below is all deprecated and should be removed in v13 + +/** Return the length (number of elements) of the given array. */ +@deprecated("Use Core instead. This will be removed in v13") +external length: array<'a> => int = "%array_length" + /** [Array.make n x] returns a fresh array of length [n], initialized with [x]. All the elements of this new array are initially @@ -46,20 +25,14 @@ external set: (array<'a>, int, 'a) => unit = "%array_safe_set" Raise [Invalid_argument] if [n < 0] or [n > Sys.max_array_length]. If the value of [x] is a floating-point number, then the maximum size is only [Sys.max_array_length / 2].*/ -external make: (int, 'a) => array<'a> = "?make_vect" - -@deprecated("Use Array.make instead.") -/** @deprecated [Array.create] is an alias for {!Array.make}. */ -external create: (int, 'a) => array<'a> = "?make_vect" +@deprecated("Use Core instead. This will be removed in v13") +let make: (int, 'a) => array<'a> /** [Array.create_float n] returns a fresh float array of length [n], with uninitialized data. @since 4.03 */ -external create_float: int => array = "?make_float_vect" - -@deprecated("Use Array.create_float instead.") -/** @deprecated [Array.make_float] is an alias for {!Array.create_float}. */ -let make_float: int => array +@deprecated("Use Core instead. This will be removed in v13") +let create_float: int => array /** [Array.init n f] returns a fresh array of length [n], with element number [i] initialized to the result of [f i]. @@ -69,6 +42,7 @@ let make_float: int => array Raise [Invalid_argument] if [n < 0] or [n > Sys.max_array_length]. If the return type of [f] is [float], then the maximum size is only [Sys.max_array_length / 2].*/ +@deprecated("Use Core instead. This will be removed in v13") let init: (int, int => 'a) => array<'a> /** [Array.make_matrix dimx dimy e] returns a two-dimensional array @@ -82,17 +56,16 @@ let init: (int, int => 'a) => array<'a> greater than {!Sys.max_array_length}. If the value of [e] is a floating-point number, then the maximum size is only [Sys.max_array_length / 2]. */ +@deprecated("Use Core instead. This will be removed in v13") let make_matrix: (int, int, 'a) => array> -@deprecated("Use Array.make_matrix instead.") -/** @deprecated [Array.create_matrix] is an alias for {!Array.make_matrix}. */ -let create_matrix: (int, int, 'a) => array> - /** [Array.append v1 v2] returns a fresh array containing the concatenation of the arrays [v1] and [v2]. */ +@deprecated("Use Core instead. This will be removed in v13") let append: (array<'a>, array<'a>) => array<'a> /** Same as {!Array.append}, but concatenates a list of arrays. */ +@deprecated("Use Core instead. This will be removed in v13") let concat: list> => array<'a> /** [Array.sub a start len] returns a fresh array of length [len], @@ -102,17 +75,21 @@ let concat: list> => array<'a> Raise [Invalid_argument "Array.sub"] if [start] and [len] do not designate a valid subarray of [a]; that is, if [start < 0], or [len < 0], or [start + len > Array.length a]. */ +@deprecated("Use Core instead. This will be removed in v13") let sub: (array<'a>, int, int) => array<'a> /** [Array.copy a] returns a copy of [a], that is, a fresh array containing the same elements as [a]. */ -let copy: array<'a> => array<'a> +@deprecated("Use Core instead. This will be removed in v13") +@send +external copy: array<'a> => array<'a> = "slice" /** [Array.fill a ofs len x] modifies the array [a] in place, storing [x] in elements number [ofs] to [ofs + len - 1]. Raise [Invalid_argument "Array.fill"] if [ofs] and [len] do not designate a valid subarray of [a]. */ +@deprecated("Use Core instead. This will be removed in v13") let fill: (array<'a>, int, int, 'a) => unit /** [Array.blit v1 o1 v2 o2 len] copies [len] elements @@ -124,13 +101,16 @@ let fill: (array<'a>, int, int, 'a) => unit Raise [Invalid_argument "Array.blit"] if [o1] and [len] do not designate a valid subarray of [v1], or if [o2] and [len] do not designate a valid subarray of [v2]. */ +@deprecated("Use Core instead. This will be removed in v13") let blit: (array<'a>, int, array<'a>, int, int) => unit /** [Array.to_list a] returns the list of all the elements of [a]. */ +@deprecated("Use Core instead. This will be removed in v13") let to_list: array<'a> => list<'a> /** [Array.of_list l] returns a fresh array containing the elements of [l]. */ +@deprecated("Use Core instead. This will be removed in v13") let of_list: list<'a> => array<'a> /* {1 Iterators} */ @@ -138,31 +118,37 @@ let of_list: list<'a> => array<'a> /** [Array.iter f a] applies function [f] in turn to all the elements of [a]. It is equivalent to [f a.(0); f a.(1); ...; f a.(Array.length a - 1); ()]. */ +@deprecated("Use Core instead. This will be removed in v13") let iter: ('a => unit, array<'a>) => unit /** Same as {!Array.iter}, but the function is applied with the index of the element as first argument, and the element itself as second argument. */ +@deprecated("Use Core instead. This will be removed in v13") let iteri: ((int, 'a) => unit, array<'a>) => unit /** [Array.map f a] applies function [f] to all the elements of [a], and builds an array with the results returned by [f]: [[| f a.(0); f a.(1); ...; f a.(Array.length a - 1) |]]. */ +@deprecated("Use Core instead. This will be removed in v13") let map: ('a => 'b, array<'a>) => array<'b> /** Same as {!Array.map}, but the function is applied to the index of the element as first argument, and the element itself as second argument. */ +@deprecated("Use Core instead. This will be removed in v13") let mapi: ((int, 'a) => 'b, array<'a>) => array<'b> /** [Array.fold_left f x a] computes [f (... (f (f x a.(0)) a.(1)) ...) a.(n-1)], where [n] is the length of the array [a]. */ +@deprecated("Use Core instead. This will be removed in v13") let fold_left: (('a, 'b) => 'a, 'a, array<'b>) => 'a /** [Array.fold_right f a x] computes [f a.(0) (f a.(1) ( ... (f a.(n-1) x) ...))], where [n] is the length of the array [a]. */ +@deprecated("Use Core instead. This will be removed in v13") let fold_right: (('b, 'a) => 'a, array<'b>, 'a) => 'a /* {1 Iterators on two arrays} */ @@ -171,6 +157,7 @@ let fold_right: (('b, 'a) => 'a, array<'b>, 'a) => 'a and [b]. Raise [Invalid_argument] if the arrays are not the same size. @since 4.03.0 */ +@deprecated("Use Core instead. This will be removed in v13") let iter2: (('a, 'b) => unit, array<'a>, array<'b>) => unit /** [Array.map2 f a b] applies function [f] to all the elements of [a] @@ -178,6 +165,7 @@ let iter2: (('a, 'b) => unit, array<'a>, array<'b>) => unit [[| f a.(0) b.(0); ...; f a.(Array.length a - 1) b.(Array.length b - 1)|]]. Raise [Invalid_argument] if the arrays are not the same size. @since 4.03.0 */ +@deprecated("Use Core instead. This will be removed in v13") let map2: (('a, 'b) => 'c, array<'a>, array<'b>) => array<'c> /* {1 Array scanning} */ @@ -186,22 +174,26 @@ let map2: (('a, 'b) => 'c, array<'a>, array<'b>) => array<'c> satisfy the predicate [p]. That is, it returns [(p a1) && (p a2) && ... && (p an)]. @since 4.03.0 */ +@deprecated("Use Core instead. This will be removed in v13") let for_all: ('a => bool, array<'a>) => bool /** [Array.exists p [|a1; ...; an|]] checks if at least one element of the array satisfies the predicate [p]. That is, it returns [(p a1) || (p a2) || ... || (p an)]. @since 4.03.0 */ +@deprecated("Use Core instead. This will be removed in v13") let exists: ('a => bool, array<'a>) => bool /** [mem a l] is true if and only if [a] is equal to an element of [l]. @since 4.03.0 */ +@deprecated("Use Core instead. This will be removed in v13") let mem: ('a, array<'a>) => bool /** Same as {!Array.mem}, but uses physical equality instead of structural equality to compare array elements. @since 4.03.0 */ +@deprecated("Use Core instead. This will be removed in v13") let memq: ('a, array<'a>) => bool /* {1 Sorting} */ @@ -230,6 +222,7 @@ let memq: ('a, array<'a>) => bool reordered in such a way that for all i and j valid indices of [a] : - [cmp a.(i) a.(j)] >= 0 if and only if i >= j */ +@deprecated("Use Core instead. This will be removed in v13") let sort: (('a, 'a) => int, array<'a>) => unit /** Same as {!Array.sort}, but the sorting algorithm is stable (i.e. @@ -240,25 +233,17 @@ let sort: (('a, 'a) => int, array<'a>) => unit words of heap space, where [n] is the length of the array. It is usually faster than the current implementation of {!Array.sort}. */ +@deprecated("Use Core instead. This will be removed in v13") let stable_sort: (('a, 'a) => int, array<'a>) => unit /** Same as {!Array.sort} or {!Array.stable_sort}, whichever is faster on typical input. */ +@deprecated("Use Core instead. This will be removed in v13") let fast_sort: (('a, 'a) => int, array<'a>) => unit -/* {1 Undocumented functions} */ - -/* The following is for system use only. Do not call directly. */ - +@deprecated("Use Core instead. This will be removed in v13") external unsafe_get: (array<'a>, int) => 'a = "%array_unsafe_get" -external unsafe_set: (array<'a>, int, 'a) => unit = "%array_unsafe_set" -module Floatarray: { - external create: int => floatarray = "?floatarray_create" - external length: floatarray => int = "%floatarray_length" - external get: (floatarray, int) => float = "%floatarray_safe_get" - external set: (floatarray, int, float) => unit = "%floatarray_safe_set" - external unsafe_get: (floatarray, int) => float = "%floatarray_unsafe_get" - external unsafe_set: (floatarray, int, float) => unit = "%floatarray_unsafe_set" -} +@deprecated("Use Core instead. This will be removed in v13") +external unsafe_set: (array<'a>, int, 'a) => unit = "%array_unsafe_set" diff --git a/jscomp/runtime/bs_stdlib_mini.resi b/jscomp/runtime/bs_stdlib_mini.resi deleted file mode 100644 index c7f6c29da2..0000000000 --- a/jscomp/runtime/bs_stdlib_mini.resi +++ /dev/null @@ -1,70 +0,0 @@ -/** - Since [others] depend on this file, its public mli files **should not - export types** introduced here, otherwise it would cause - conflicts here. - - If the type exported here is also exported in modules from others, - you will get a type not equivalent. - - - Types defined here but should not export: - - ref (make sure not exported in *.mli in others folder) -*/ -external \"^": (string, string) => string = "#string_append" -external \"=": ('a, 'a) => bool = "%equal" -external \"<>": ('a, 'a) => bool = "%notequal" -external \"==": ('a, 'a) => bool = "%eq" -external \"!=": ('a, 'a) => bool = "%noteq" -external \"<": ('a, 'a) => bool = "%lessthan" -external \">": ('a, 'a) => bool = "%greaterthan" -external \"<=": ('a, 'a) => bool = "%lessequal" -external \">=": ('a, 'a) => bool = "%greaterequal" -external \"+": (int, int) => int = "%addint" -external \"-": (int, int) => int = "%subint" -external \"~-": int => int = "%negint" -external \"*": (int, int) => int = "%mulint" -external \"/": (int, int) => int = "%divint" -external lsl: (int, int) => int = "%lslint" -external lor: (int, int) => int = "%orint" -external land: (int, int) => int = "%andint" -external mod: (int, int) => int = "%modint" -external lsr: (int, int) => int = "%lsrint" -external lxor: (int, int) => int = "%xorint" -external asr: (int, int) => int = "%asrint" -type ref<'a> = {mutable contents: 'a} -external ref: 'a => ref<'a> = "%makemutable" - -external \"||": (bool, bool) => bool = "%sequor" -external \"&&": (bool, bool) => bool = "%sequand" -external not: bool => bool = "%boolnot" - -external raise: exn => 'a = "%raise" -external ignore: 'a => unit = "%ignore" -external \"|>": ('a, 'a => 'b) => 'b = "%revapply" -external \"@@": ('a => 'b, 'a) => 'b = "%apply" - -@val @scope("Math") external \"**": (float, float) => float = "pow" -external \"~-.": float => float = "%negfloat" -external \"+.": (float, float) => float = "%addfloat" -external \"-.": (float, float) => float = "%subfloat" -external \"*.": (float, float) => float = "%mulfloat" -external \"/.": (float, float) => float = "%divfloat" - -module Obj: { - type t - external field: (t, int) => t = "%obj_field" - external set_field: (t, int, t) => unit = "%obj_set_field" - external tag: t => int = "?obj_tag" - external repr: 'a => t = "%identity" - external obj: t => 'a = "%identity" - external magic: 'a => 'b = "%identity" - external size: t => int = "#obj_length" -} - -module Pervasives: { - external compare: ('a, 'a) => int = "%compare" - external not: bool => bool = "%boolnot" - external min: ('a, 'a) => 'a = "%bs_min" - external max: ('a, 'a) => 'a = "%bs_max" - external \"=": ('a, 'a) => bool = "%equal" -} diff --git a/jscomp/runtime/caml.res b/jscomp/runtime/caml.res deleted file mode 100644 index 15a70573b7..0000000000 --- a/jscomp/runtime/caml.res +++ /dev/null @@ -1,162 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -let int_compare = (x: int, y: int): int => - if x < y { - -1 - } else if x == y { - 0 - } else { - 1 - } -let bool_compare = (x: bool, y: bool): int => - switch (x, y) { - | (true, true) | (false, false) => 0 - | (true, false) => 1 - | (false, true) => -1 - } - -let float_compare = (x: float, y: float) => - if x == y { - 0 - } else if x < y { - -1 - } else if x > y { - 1 - } else if x == x { - 1 - } else if y == y { - -1 - } else { - 0 - } - -let bigint_compare = (x: bigint, y: bigint) => - if x < y { - -1 - } else if x == y { - 0 - } else { - 1 - } - -/* Lexical order */ -let string_compare = (s1: string, s2: string): int => - if s1 == s2 { - 0 - } else if s1 < s2 { - -1 - } else { - 1 - } - -type selector<'a> = ('a, 'a) => 'a - -/* could be replaced by [Math.min], but it seems those built-ins are slower */ -let bool_min = (x: bool, y): bool => - if x { - y - } else { - x - } -let int_min = (x: int, y: int): int => - if x < y { - x - } else { - y - } -let float_min = (x: float, y) => - if x < y { - x - } else { - y - } -let string_min = (x: string, y) => - if x < y { - x - } else { - y - } - -let bool_max = (x: bool, y): bool => - if x { - x - } else { - y - } -let int_max = (x: int, y: int): int => - if x > y { - x - } else { - y - } -let float_max = (x: float, y) => - if x > y { - x - } else { - y - } -let string_max = (x: string, y) => - if x > y { - x - } else { - y - } -type i64 = Caml_int64_extern.t -let i64_eq = (x: i64, y: i64) => x.lo == y.lo && x.hi == y.hi - -let i64_ge = ({hi, lo}: i64, {hi: other_hi, lo: other_lo}: i64): bool => - if hi > other_hi { - true - } else if hi < other_hi { - false - } else { - lo >= other_lo - } - -let i64_neq = (x, y) => Pervasives.not(i64_eq(x, y)) -let i64_lt = (x, y) => Pervasives.not(i64_ge(x, y)) -let i64_gt = (x: i64, y: i64) => - if x.hi > y.hi { - true - } else if x.hi < y.hi { - false - } else { - x.lo > y.lo - } - -let i64_le = (x, y) => Pervasives.not(i64_gt(x, y)) - -let i64_min = (x, y) => - if i64_lt(x, y) { - x - } else { - y - } -let i64_max = (x, y) => - if i64_gt(x, y) { - x - } else { - y - } diff --git a/jscomp/runtime/caml.resi b/jscomp/runtime/caml.resi deleted file mode 100644 index fe4d629b3c..0000000000 --- a/jscomp/runtime/caml.resi +++ /dev/null @@ -1,51 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -type selector<'a> = ('a, 'a) => 'a - -let int_compare: (int, int) => int -let bool_compare: (bool, bool) => int -let float_compare: (float, float) => int -let bigint_compare: (bigint, bigint) => int -let string_compare: (string, string) => int - -let bool_min: selector -let int_min: selector -let float_min: selector -let string_min: selector - -let bool_max: selector -let int_max: selector -let float_max: selector -let string_max: selector - -let i64_eq: (Caml_int64_extern.t, Caml_int64_extern.t) => bool -let i64_neq: (Caml_int64_extern.t, Caml_int64_extern.t) => bool -let i64_lt: (Caml_int64_extern.t, Caml_int64_extern.t) => bool -let i64_gt: (Caml_int64_extern.t, Caml_int64_extern.t) => bool -let i64_le: (Caml_int64_extern.t, Caml_int64_extern.t) => bool -let i64_ge: (Caml_int64_extern.t, Caml_int64_extern.t) => bool - -let i64_min: (Caml_int64_extern.t, Caml_int64_extern.t) => Caml_int64_extern.t -let i64_max: (Caml_int64_extern.t, Caml_int64_extern.t) => Caml_int64_extern.t diff --git a/jscomp/runtime/caml_array.res b/jscomp/runtime/caml_array.res deleted file mode 100644 index bcd996ae31..0000000000 --- a/jscomp/runtime/caml_array.res +++ /dev/null @@ -1,107 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -@send external dup: (array<'a>, @as(0) _) => array<'a> = "slice" - -%%private(let {unsafe_get, unsafe_set} = module(Caml_array_extern)) - -let sub = (x: array<'a>, offset: int, len: int) => { - let result = Caml_array_extern.new_uninitialized(len) - let j = {contents: 0} and i = {contents: offset} - while j.contents < len { - result->unsafe_set(j.contents, x->unsafe_get(i.contents)) - j.contents = j.contents + 1 - i.contents = i.contents + 1 - } - result -} - -let rec len = (acc, l) => - switch l { - | list{} => acc - | list{x, ...xs} => len(Caml_array_extern.length(x) + acc, xs) - } - -let rec fill = (arr, i, l) => - switch l { - | list{} => () - | list{x, ...xs} => - let l = Caml_array_extern.length(x) - let k = {contents: i} - let j = {contents: 0} - while j.contents < l { - arr->unsafe_set(k.contents, x->unsafe_get(j.contents)) - k.contents = k.contents + 1 - j.contents = j.contents + 1 - } - fill(arr, k.contents, xs) - } - -let concat = (l: list>): array<'a> => { - let v = len(0, l) - let result = Caml_array_extern.new_uninitialized(v) - fill(result, 0, l) - result -} - -let set = (xs, index, newval) => - if index < 0 || index >= Caml_array_extern.length(xs) { - raise(Invalid_argument("index out of bounds")) - } else { - xs->unsafe_set(index, newval) - } - -let get = (xs, index) => - if index < 0 || index >= Caml_array_extern.length(xs) { - raise(Invalid_argument("index out of bounds")) - } else { - xs->unsafe_get(index) - } - -let make = (len, init) => { - let b = Caml_array_extern.new_uninitialized(len) - for i in 0 to len - 1 { - b->unsafe_set(i, init) - } - b -} - -let make_float = len => { - let b = Caml_array_extern.new_uninitialized(len) - for i in 0 to len - 1 { - b->unsafe_set(i, 0.) - } - b -} - -let blit = (a1, i1, a2, i2, len) => - if i2 <= i1 { - for j in 0 to len - 1 { - a2->unsafe_set(j + i2, a1->unsafe_get(j + i1)) - } - } else { - for j in len - 1 downto 0 { - a2->unsafe_set(j + i2, a1->unsafe_get(j + i1)) - } - } diff --git a/jscomp/runtime/caml_array.resi b/jscomp/runtime/caml_array.resi deleted file mode 100644 index af94891e64..0000000000 --- a/jscomp/runtime/caml_array.resi +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -let dup: array<'a> => array<'a> - -let sub: (array<'a>, int, int) => array<'a> - -let concat: list> => array<'a> - -let make: (int, 'a) => array<'a> - -let make_float: int => array - -let blit: (array<'a>, int, array<'a>, int, int) => unit - -let get: (array<'a>, int) => 'a - -let set: (array<'a>, int, 'a) => unit diff --git a/jscomp/runtime/caml_array_extern.res b/jscomp/runtime/caml_array_extern.res deleted file mode 100644 index 84b2ac3406..0000000000 --- a/jscomp/runtime/caml_array_extern.res +++ /dev/null @@ -1,11 +0,0 @@ -@new external new_uninitialized: int => array<'a> = "Array" -@send external append: (array<'a>, array<'a>) => array<'a> = "concat" -external unsafe_get: (array<'a>, int) => 'a = "%array_unsafe_get" -external unsafe_set: (array<'a>, int, 'a) => unit = "%array_unsafe_set" -external length: array<'a> => int = "%array_length" - -/* - Could be replaced by {!Caml_array.caml_make_vect} - Leave here temporarily since we have marked it side effect free internally -*/ -external make: (int, 'a) => array<'a> = "?make_vect" diff --git a/jscomp/runtime/caml_bigint.res b/jscomp/runtime/caml_bigint.res deleted file mode 100644 index bf78dcef84..0000000000 --- a/jscomp/runtime/caml_bigint.res +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -let div = (x: bigint, y: bigint) => - if y == 0n { - raise(Division_by_zero) - } else { - Caml_bigint_extern.div(x, y) - } - -let mod_ = (x: bigint, y: bigint) => - if y == 0n { - raise(Division_by_zero) - } else { - Caml_bigint_extern.rem(x, y) - } diff --git a/jscomp/runtime/caml_bigint.resi b/jscomp/runtime/caml_bigint.resi deleted file mode 100644 index 386a1ab992..0000000000 --- a/jscomp/runtime/caml_bigint.resi +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -let div: (bigint, bigint) => bigint - -let mod_: (bigint, bigint) => bigint diff --git a/jscomp/runtime/caml_bigint_extern.res b/jscomp/runtime/caml_bigint_extern.res deleted file mode 100644 index 33f0c432d2..0000000000 --- a/jscomp/runtime/caml_bigint_extern.res +++ /dev/null @@ -1,2 +0,0 @@ -external div: (bigint, bigint) => bigint = "?bigint_div" -external rem: (bigint, bigint) => bigint = "?bigint_mod" diff --git a/jscomp/runtime/caml_bytes.res b/jscomp/runtime/caml_bytes.res deleted file mode 100644 index afab0966dd..0000000000 Binary files a/jscomp/runtime/caml_bytes.res and /dev/null differ diff --git a/jscomp/runtime/caml_bytes.resi b/jscomp/runtime/caml_bytes.resi deleted file mode 100644 index a76db5d5f8..0000000000 --- a/jscomp/runtime/caml_bytes.resi +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -let create: int => bytes - -let get: (bytes, int) => char -let set: (bytes, int, char) => unit - -let bytes_compare: (bytes, bytes) => int - -let bytes_greaterthan: (bytes, bytes) => bool - -let bytes_greaterequal: (bytes, bytes) => bool - -let bytes_lessthan: (bytes, bytes) => bool - -let bytes_lessequal: (bytes, bytes) => bool - -let bytes_equal: (bytes, bytes) => bool diff --git a/jscomp/runtime/caml_exceptions.resi b/jscomp/runtime/caml_exceptions.resi deleted file mode 100644 index da55d4d07b..0000000000 --- a/jscomp/runtime/caml_exceptions.resi +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -type t = {@as("RE_EXN_ID") id: string} - -let create: string => string - -let is_extension: 'a => bool - -let exn_slot_name: t => string diff --git a/jscomp/runtime/caml_float.res b/jscomp/runtime/caml_float.res deleted file mode 100644 index 95ac08b3a9..0000000000 --- a/jscomp/runtime/caml_float.res +++ /dev/null @@ -1,157 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -/* borrowed from others/js_math.ml */ -@val external _LOG2E: float = "Math.LOG2E" -@val external _LOG10E: float = "Math.LOG10E" -@val external abs_float: float => float = "Math.abs" -@val external floor: float => float = "Math.floor" -@val @scope("Math") external exp: float => float = "exp" -@val external log: float => float = "Math.log" -@val @scope("Math") external sqrt: float => float = "sqrt" -@val external pow_float: (~base: float, ~exp: float) => float = "Math.pow" -external int_of_float: float => int = "%intoffloat" -external float_of_int: int => float = "%floatofint" - -let int_float_of_bits: int => float = %raw(`function(x){ - return new Float32Array(new Int32Array([x]).buffer)[0] - }`) -/* let int = Int32_array.make [| x |] in - let float32 = Float32_array.fromBuffer ( Int32_array.buffer int) in - Float32_array.unsafe_get float32 0 */ - -let int_bits_of_float: float => int = %raw(`function(x){ - return new Int32Array(new Float32Array([x]).buffer)[0] -}`) -/* let float32 = Float32_array.make [|x|] in - Int32_array.unsafe_get (Int32_array.fromBuffer (Float32_array.buffer float32)) 0 */ - -let modf_float = (x: float): (float, float) => - if Caml_float_extern.isFinite(x) { - let neg = 1. /. x < 0. - let x = abs_float(x) - let i = floor(x) - let f = x -. i - if neg { - (-.f, -.i) - } else { - (f, i) - } - } else if Caml_float_extern.isNaN(x) { - (Caml_float_extern._NaN, Caml_float_extern._NaN) - } else { - (1. /. x, x) - } - -let ldexp_float = (x: float, exp: int): float => { - let (x', exp') = (ref(x), ref(float_of_int(exp))) - if exp'.contents > 1023. { - exp'.contents = exp'.contents -. 1023. - x'.contents = x'.contents *. pow_float(~base=2., ~exp=1023.) - if exp'.contents > 1023. { - /* in case x is subnormal */ - exp'.contents = exp'.contents -. 1023. - x'.contents = x'.contents *. pow_float(~base=2., ~exp=1023.) - } - } else if exp'.contents < -1023. { - exp'.contents = exp'.contents +. 1023. - x'.contents = x'.contents *. pow_float(~base=2., ~exp=-1023.) - } - x'.contents *. pow_float(~base=2., ~exp=exp'.contents) -} - -let frexp_float = (x: float): (float, int) => - if x == 0. || !Caml_float_extern.isFinite(x) { - (x, 0) - } else { - let neg = x < 0. - let x' = ref(abs_float(x)) - let exp = ref(floor(_LOG2E *. log(x'.contents)) +. 1.) - - x'.contents = x'.contents *. pow_float(~base=2., ~exp=-.exp.contents) - if x'.contents < 0.5 { - x'.contents = x'.contents *. 2. - exp.contents = exp.contents -. 1. - } - if neg { - x'.contents = -.x'.contents - } - (x'.contents, int_of_float(exp.contents)) - } - -let copysign_float = (x: float, y: float): float => { - let x = abs_float(x) - let y = if y == 0. { - 1. /. y - } else { - y - } - if y < 0. { - -.x - } else { - x - } -} - -/* http://www.johndcook.com/blog/cpp_expm1/ */ -let expm1_float: float => float = x => - switch x { - | x => - let y = exp(x) - let z = y -. 1. - if abs_float(x) > 1. { - z - } else if z == 0. { - x - } else { - x *. z /. log(y) - } - } - -/* -(* http://blog.csdn.net/liyuanbhu/article/details/8544644 *) -let log1p_float : float -> float = function x -> - let y = 1. +. x in - let z = y -. 1. in - if z = 0. then x else x *. log y /. z */ - -let hypot_float = (x: float, y: float): float => { - let (x0, y0) = (abs_float(x), abs_float(y)) - let a = Pervasives.max(x0, y0) - let b = - Pervasives.min(x0, y0) /. if a != 0. { - a - } else { - 1. - } - a *. sqrt(1. +. b *. b) -} - -/* -let caml_cosh_float x = exp x +. exp (-. x) /. 2. -let caml_sin_float x = exp x -. exp (-. x) /. 2. -let caml_tan_float x = - let y = exp x in - let z = exp (-. x) in - (y +. z) /. (y -. z ) */ diff --git a/jscomp/runtime/caml_float.resi b/jscomp/runtime/caml_float.resi deleted file mode 100644 index 4cb4559b65..0000000000 --- a/jscomp/runtime/caml_float.resi +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -@val external floor: float => float = "Math.floor" -external int_of_float: float => int = "%intoffloat" -external float_of_int: int => float = "%floatofint" -let int_float_of_bits: int => float -let int_bits_of_float: float => int - -let modf_float: float => (float, float) - -let ldexp_float: (float, int) => float -let frexp_float: float => (float, int) - -let copysign_float: (float, float) => float -let expm1_float: float => float - -let hypot_float: (float, float) => float diff --git a/jscomp/runtime/caml_float_extern.res b/jscomp/runtime/caml_float_extern.res deleted file mode 100644 index 065c5a5aea..0000000000 --- a/jscomp/runtime/caml_float_extern.res +++ /dev/null @@ -1,7 +0,0 @@ -@val external _NaN: float = "NaN" -@val external isNaN: float => bool = "isNaN" -@val external isFinite: float => bool = "isFinite" -@send external toExponentialWithPrecision: (float, ~digits: int) => string = "toExponential" -@send external toFixed: float => string = "toFixed" -@send external toFixedWithPrecision: (float, ~digits: int) => string = "toFixed" -@val external fromString: string => float = "Number" diff --git a/jscomp/runtime/caml_format.res b/jscomp/runtime/caml_format.res deleted file mode 100644 index 9705f3a482..0000000000 --- a/jscomp/runtime/caml_format.res +++ /dev/null @@ -1,724 +0,0 @@ -/* - * Js_of_ocaml runtime support - * http://www.ocsigen.org/js_of_ocaml/ - * Copyright (C) 2010 Jérôme Vouillon - * Laboratoire PPS - CNRS Université Paris Diderot - * Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published * by - * the Free Software Foundation, with linking exception; - * either version 2.1 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -external \".![]": (string, int) => int = "%string_unsafe_get" -external \".!()": (string, int) => char = "%string_unsafe_get" - -let code_0 = 48 // '0' -let code_a = 97 // 'a' -let code_A = 65 // 'A' - -module Caml_char = { - external code: char => int = "%identity" - external unsafe_chr: int => char = "%identity" -} - -let failwith = s => raise(Failure(s)) -/* let invalid_argument s= raise (Invalid_argument s ) */ - -let \">>>" = Caml_nativeint_extern.shift_right_logical - -let \"+~" = Caml_nativeint_extern.add -let \"*~" = Caml_nativeint_extern.mul - -let parse_digit = c => - switch c { - | '0' .. '9' => Caml_char.code(c) - code_0 - | 'A' .. 'Z' => Caml_char.code(c) - (code_A - 10) - | 'a' .. 'z' => Caml_char.code(c) - (code_a - 10) - | _ => -1 - } - -type of_string_base = - | Oct - | Hex - | Dec - | Bin - -let int_of_string_base = x => - switch x { - | Oct => 8 - | Hex => 16 - | Dec => 10 - | Bin => 2 - } - -let parse_sign_and_base = (s: string) => { - let sign = ref(1) - let base = ref(Dec) - let i = ref(0) - switch \".!()"(s, i.contents) { - | '-' => - sign.contents = -1 - i.contents = i.contents + 1 - | '+' => i.contents = i.contents + 1 - | _ => () - } - if \".!()"(s, i.contents) == '0' { - switch \".!()"(s, i.contents + 1) { - | 'x' | 'X' => - base.contents = Hex - i.contents = i.contents + 2 - | 'o' | 'O' => - base.contents = Oct - i.contents = i.contents + 2 - | 'b' | 'B' => - base.contents = Bin - i.contents = i.contents + 2 - | 'u' | 'U' => i.contents = i.contents + 2 - | _ => () - } - } - (i.contents, sign.contents, base.contents) -} - -let int_of_string = (s: string): int => { - let (i, sign, hbase) = parse_sign_and_base(s) - let base = int_of_string_base(hbase) - let threshold = \">>>"(-1, 0) - let len = Caml_string_extern.length(s) - let c = if i < len { - \".!()"(s, i) - } else { - '\000' - } - let d = parse_digit(c) - let () = if d < 0 || d >= base { - failwith("int_of_string") - } - /* let () = [%debugger] in */ - let rec aux = (acc, k) => - if k == len { - acc - } else { - let a = \".!()"(s, k) - if a == '_' { - aux(acc, k + 1) - } else { - let v = parse_digit(a) - if v < 0 || v >= base { - failwith("int_of_string") - } else { - let acc = \"+~"(\"*~"(base, acc), v) - if acc > threshold { - failwith("int_of_string") - } else { - aux(acc, k + 1) - } - } - } - } - - let res = \"*~"(sign, aux(d, i + 1)) - let or_res = lor(res, 0) - if base == 10 && res != or_res { - failwith("int_of_string") - } - or_res -} - -let (hex_threshold, dec_threshold, oct_threshold, bin_threshold) = ( - 1152921504606846975L, - 1844674407370955161L, - 2305843009213693951L, - 9223372036854775807L, -) - -let int64_of_string = s => { - let (i, sign, hbase) = parse_sign_and_base(s) - let base = Caml_int64_extern.of_int(int_of_string_base(hbase)) - let sign = Caml_int64_extern.of_int(sign) - let threshold = switch hbase { - | Hex => /* 2 ^ 64 - 1 / 16 */ - hex_threshold - | Dec => dec_threshold - | Oct => oct_threshold - | Bin => bin_threshold - } - - let len = Caml_string_extern.length(s) - let c = if i < len { - \".!()"(s, i) - } else { - '\000' - } - let d = Caml_int64_extern.of_int(parse_digit(c)) - let () = if d < 0L || d >= base { - failwith("int64_of_string") - } - let \"+~" = Caml_int64_extern.add - let \"*~" = Caml_int64_extern.mul - - let rec aux = (acc, k) => - if k == len { - acc - } else { - let a = \".!()"(s, k) - if a == '_' { - aux(acc, k + 1) - } else { - let v = Caml_int64_extern.of_int(parse_digit(a)) - if v < 0L || (v >= base || acc > threshold) { - failwith("int64_of_string") - } else { - let acc = \"+~"(\"*~"(base, acc), v) - aux(acc, k + 1) - } - } - } - - let res = \"*~"(sign, aux(d, i + 1)) - let or_res = Caml_int64_extern.logor(res, 0L) - if base == 10L && res != or_res { - failwith("int64_of_string") - } - or_res -} - -type base = Oct | Hex | Dec -let int_of_base = x => - switch x { - | Oct => 8 - | Hex => 16 - | Dec => 10 - } - -type fmt = { - mutable justify: string, - mutable signstyle: string, - mutable filter: string, - mutable alternate: bool, - mutable base: base, - mutable signedconv: bool, - mutable width: int, - mutable uppercase: bool, - mutable sign: int, - mutable prec: int, - mutable conv: string, -} - -let lowercase = (c: char): char => - if (c >= 'A' && c <= 'Z') || ((c >= '\192' && c <= '\214') || c >= '\216' && c <= '\222') { - Caml_char.unsafe_chr(Caml_char.code(c) + 32) - } else { - c - } - -let parse_format = fmt => { - module String = Caml_string_extern - let len = Caml_string_extern.length(fmt) - if len > 31 { - raise(Invalid_argument("format_int: format too long")) - } - let rec aux = (f: fmt, i): fmt => - if i >= len { - f - } else { - let c = String.get(fmt, i) - switch c { - | '-' => - f.justify = "-" - aux(f, i + 1) - | '+' | ' ' => - f.signstyle = Caml_string_extern.of_char(c) - aux(f, i + 1) - | '#' => - f.alternate = true - aux(f, i + 1) - | '0' => - f.filter = "0" - aux(f, i + 1) - | '1' .. '9' => - f.width = 0 - let j = ref(i) - - while { - let w = \".![]"(fmt, j.contents) - code_0 - w >= 0 && w <= 9 - } { - f.width = f.width * 10 + \".![]"(fmt, j.contents) - code_0 - j.contents = j.contents + 1 - } - aux(f, j.contents) - | '.' => - f.prec = 0 - let j = ref(i + 1) - while { - let w = \".![]"(fmt, j.contents) - code_0 - w >= 0 && w <= 9 - } { - f.prec = f.prec * 10 + \".![]"(fmt, j.contents) - code_0 - j.contents = j.contents + 1 - } - aux(f, j.contents) - | 'd' - | 'i' => - f.signedconv = true - f.base = Dec - aux(f, i + 1) - | 'u' => - f.base = Dec - aux(f, i + 1) - | 'x' => - f.base = Hex - aux(f, i + 1) - | 'X' => - f.base = Hex - f.uppercase = true - aux(f, i + 1) - | 'o' => - f.base = Oct - aux(f, i + 1) - /* | 'O' -> base .contents<- 8; uppercase .contents<- true no uppercase for oct */ - | 'e' | 'f' | 'g' => - f.signedconv = true - f.conv = Caml_string_extern.of_char(c) - aux(f, i + 1) - | 'E' | 'F' | 'G' => - f.signedconv = true - f.uppercase = true - f.conv = Caml_string_extern.of_char(lowercase(c)) - aux(f, i + 1) - | _ => aux(f, i + 1) - } - } - - aux( - { - justify: "+", - signstyle: "-", - filter: " ", - alternate: false, - base: Dec, - signedconv: false, - width: 0, - uppercase: false, - sign: 1, - prec: -1, - conv: "f", - }, - 0, - ) -} - -let finish_formatting = (config: fmt, rawbuffer) => { - let { - justify, - signstyle, - filter, - alternate, - base, - signedconv, - width, - uppercase, - sign, - prec: _, - conv: _, - } = config - let len = ref(Caml_string_extern.length(rawbuffer)) - if signedconv && (sign < 0 || signstyle != "-") { - len.contents = len.contents + 1 - } - if alternate { - if base == Oct { - len.contents = len.contents + 1 - } else if base == Hex { - len.contents = len.contents + 2 - } else { - () - } - } - let buffer = ref("") - - /* let (+=) buffer s = buffer .contents<- buffer.contents ^ s in - FIXME: should get inlined - */ - /* let (+:) s = buffer .contents<- buffer.contents ^ s in */ - if justify == "+" && filter == " " { - for _ in len.contents to width - 1 { - buffer.contents = buffer.contents ++ filter - } - } - if signedconv { - if sign < 0 { - buffer.contents = buffer.contents ++ "-" - } else if signstyle != "-" { - buffer.contents = buffer.contents ++ signstyle - } else { - () - } - } - if alternate && base == Oct { - buffer.contents = buffer.contents ++ "0" - } - if alternate && base === Hex { - buffer.contents = buffer.contents ++ "0x" - } - - if justify == "+" && filter == "0" { - for _ in len.contents to width - 1 { - buffer.contents = buffer.contents ++ filter - } - } - if uppercase { - buffer.contents = buffer.contents ++ Caml_string_extern.toUpperCase(rawbuffer) - } else { - buffer.contents = buffer.contents ++ rawbuffer - } - if justify == "-" { - for _ in len.contents to width - 1 { - buffer.contents = buffer.contents ++ " " - } - } - buffer.contents -} - -let aux = (f, i: int): string => { - let i = if i < 0 { - if f.signedconv { - f.sign = -1 - \">>>"(-i, 0) - /* when i is min_int, [-i] could overflow */ - } else { - \">>>"(i, 0) - } - } else { - i - } - let s = ref(Caml_string_extern.of_int(i, ~base=int_of_base(f.base))) - if f.prec >= 0 { - f.filter = " " - let n = f.prec - Caml_string_extern.length(s.contents) - if n > 0 { - s.contents = Caml_string_extern.repeat("0", n) ++ s.contents - } - } - finish_formatting(f, s.contents) -} - -let format_int = (fmt, i) => - if fmt == "%d" { - Caml_nativeint_extern.to_string(i) - } else { - let f = parse_format(fmt) - aux(f, i) - } - -/* This can handle unsigned integer (-1L) and print it as "%Lu" which - will overflow signed integer in general -*/ -let dec_of_pos_int64 = x => - if x < 0L { - let wbase = 10L - let cvtbl = "0123456789" - let y = Caml_int64.discard_sign(x) - /* 2 ^ 63 + y `div_mod` 10 */ - - let quotient_l = 922337203685477580L /* 2 ^ 63 / 10 */ - /* {lo = -858993460n; hi = 214748364n} */ - /* TODO: int64 constant folding so that we can do idiomatic code - 2 ^ 63 / 10 */ - let modulus_l = 8L - /* let c, d = Caml_int64.div_mod (Caml_int64.add y modulus_l) wbase in - we can not do the code above, it can overflow when y is really large - */ - let (c, d) = Caml_int64.div_mod(y, wbase) - let (e, f) = Caml_int64.div_mod(Caml_int64_extern.add(modulus_l, d), wbase) - let quotient = Caml_int64_extern.add(Caml_int64_extern.add(quotient_l, c), e) - Caml_int64.to_string(quotient) ++ - Caml_string_extern.get_string_unsafe(cvtbl, Caml_int64_extern.to_int(f)) - } else { - Caml_int64.to_string(x) - } - -let oct_of_int64 = x => { - let s = ref("") - let wbase = 8L - let cvtbl = "01234567" - if x < 0L { - let y = Caml_int64.discard_sign(x) - /* 2 ^ 63 + y `div_mod` 8 */ - let quotient_l = 1152921504606846976L - /* {lo = 0n; hi = 268435456n } */ /* 2 ^ 31 / 8 */ - - /* let c, d = Caml_int64.div_mod (Caml_int64.add y modulus_l) wbase in - we can not do the code above, it can overflow when y is really large - */ - let (c, d) = Caml_int64.div_mod(y, wbase) - - let quotient = ref(Caml_int64_extern.add(quotient_l, c)) - let modulus = ref(d) - s.contents = - Caml_string_extern.get_string_unsafe(cvtbl, Caml_int64_extern.to_int(modulus.contents)) ++ - s.contents - - while quotient.contents != 0L { - let (a, b) = Caml_int64.div_mod(quotient.contents, wbase) - quotient.contents = a - modulus.contents = b - s.contents = - Caml_string_extern.get_string_unsafe(cvtbl, Caml_int64_extern.to_int(modulus.contents)) ++ - s.contents - } - } else { - let (a, b) = Caml_int64.div_mod(x, wbase) - let quotient = ref(a) - let modulus = ref(b) - s.contents = - Caml_string_extern.get_string_unsafe(cvtbl, Caml_int64_extern.to_int(modulus.contents)) ++ - s.contents - - while quotient.contents != 0L { - let (a, b) = Caml_int64.div_mod(quotient.contents, wbase) - quotient.contents = a - modulus.contents = b - s.contents = - Caml_string_extern.get_string_unsafe(cvtbl, Caml_int64_extern.to_int(modulus.contents)) ++ - s.contents - } - } - s.contents -} - -/* FIXME: improve codegen for such cases - let div_mod (x : int64) (y : int64) : int64 * int64 = - let a, b = Caml_int64.(div_mod (unsafe_of_int64 x) (unsafe_of_int64 y)) in - Caml_int64.unsafe_to_int64 a , Caml_int64.unsafe_to_int64 b -*/ -let int64_format = (fmt, x) => - if fmt == "%d" { - Caml_int64.to_string(x) - } else { - let f = parse_format(fmt) - let x = if f.signedconv && x < 0L { - f.sign = -1 - Caml_int64_extern.neg(x) - } else { - x - } - let s = switch f.base { - | Hex => Caml_int64.to_hex(x) - | Oct => oct_of_int64(x) - | Dec => dec_of_pos_int64(x) - } - let fill_s = if f.prec >= 0 { - f.filter = " " - let n = f.prec - Caml_string_extern.length(s) - if n > 0 { - "0"->Caml_string_extern.repeat(n) ++ s - } else { - s - } - } else { - s - } - - finish_formatting(f, fill_s) - } - -let format_float = (fmt, x) => { - module String = Caml_string_extern - let f = parse_format(fmt) - let prec = if f.prec < 0 { - 6 - } else { - f.prec - } - let x = if x < 0. { - f.sign = -1 - -.x - } else { - x - } - let s = ref("") - if Caml_float_extern.isNaN(x) { - s.contents = "nan" - f.filter = " " - } else if !Caml_float_extern.isFinite(x) { - s.contents = "inf" - f.filter = " " - } else { - switch f.conv { - | "e" => - s.contents = Caml_float_extern.toExponentialWithPrecision(x, ~digits=prec) - /* exponent should be at least two digits - {[ - (3.3).toExponential() - "3.3e+0" - 3.3e+00 - ]} - */ - let i = Caml_string_extern.length(s.contents) - if String.get(s.contents, i - 3) == 'e' { - s.contents = - Caml_string_extern.slice(s.contents, 0, i - 1) ++ - ("0" ++ - Caml_string_extern.slice_rest(s.contents, i - 1)) - } - | "f" => - /* this will not work large numbers */ - /* ("%3.10f", 3e+56, "300000000000000005792779041490073052596128503513888063488.0000000000") */ - s.contents = Caml_float_extern.toFixedWithPrecision(x, ~digits=prec) - | "g" => - let prec = if prec != 0 { - prec - } else { - 1 - } - s.contents = Caml_float_extern.toExponentialWithPrecision(x, ~digits=prec - 1) - let j = Caml_string_extern.index_of(s.contents, "e") - let exp = Caml_float.int_of_float( - Caml_float_extern.fromString(Caml_string_extern.slice_rest(s.contents, j + 1)), - ) - if exp < -4 || (x >= 1e21 || Caml_string_extern.length(Caml_float_extern.toFixed(x)) > prec) { - let i = ref(j - 1) - while String.get(s.contents, i.contents) == '0' { - i.contents = i.contents - 1 - } - if String.get(s.contents, i.contents) == '.' { - i.contents = i.contents - 1 - } - s.contents = - Caml_string_extern.slice(s.contents, 0, i.contents + 1) ++ - Caml_string_extern.slice_rest(s.contents, j) - let i = Caml_string_extern.length(s.contents) - if String.get(s.contents, i - 3) == 'e' { - s.contents = - Caml_string_extern.slice(s.contents, 0, i - 1) ++ - ("0" ++ - Caml_string_extern.slice_rest(s.contents, i - 1)) - } else { - () - } - } else { - let p = ref(prec) - if exp < 0 { - p.contents = p.contents - (exp + 1) - s.contents = Caml_float_extern.toFixedWithPrecision(x, ~digits=p.contents) - } else { - while { - s.contents = Caml_float_extern.toFixedWithPrecision(x, ~digits=p.contents) - Caml_string_extern.length(s.contents) > prec + 1 - } { - p.contents = p.contents - 1 - } - } - if p.contents != 0 { - let k = ref(Caml_string_extern.length(s.contents) - 1) - while String.get(s.contents, k.contents) == '0' { - k.contents = k.contents - 1 - } - if String.get(s.contents, k.contents) == '.' { - k.contents = k.contents - 1 - } - s.contents = Caml_string_extern.slice(s.contents, 0, k.contents + 1) - } - } - - | _ => () - } - } - finish_formatting(f, s.contents) -} - -let hexstring_of_float: (float, int, char) => string = %raw(`function(x,prec,style){ - if (!isFinite(x)) { - if (isNaN(x)) return "nan"; - return x > 0 ? "infinity":"-infinity"; - } - var sign = (x==0 && 1/x == -Infinity)?1:(x>=0)?0:1; - if(sign) x = -x; - var exp = 0; - if (x == 0) { } - else if (x < 1) { - while (x < 1 && exp > -1022) { x *= 2; exp-- } - } else { - while (x >= 2) { x /= 2; exp++ } - } - var exp_sign = exp < 0 ? '' : '+'; - var sign_str = ''; - if (sign) sign_str = '-' - else { - switch(style){ - case 43 /* '+' */: sign_str = '+'; break; - case 32 /* ' ' */: sign_str = ' '; break; - default: break; - } - } - if (prec >= 0 && prec < 13) { - /* If a precision is given, and is small, round mantissa accordingly */ - var cst = Math.pow(2,prec * 4); - x = Math.round(x * cst) / cst; - } - var x_str = x.toString(16); - if(prec >= 0){ - var idx = x_str.indexOf('.'); - if(idx<0) { - x_str += '.' + '0'.repeat(prec); - } - else { - var size = idx+1+prec; - if(x_str.length < size) - x_str += '0'.repeat(size - x_str.length); - else - x_str = x_str.substr(0,size); - } - } - return (sign_str + '0x' + x_str + 'p' + exp_sign + exp.toString(10)); -}`) - -let float_of_string: (string, exn) => float = %raw(`function(s,exn){ - - var res = +s; - if ((s.length > 0) && (res === res)) - return res; - s = s.replace(/_/g, ""); - res = +s; - if (((s.length > 0) && (res === res)) || /^[+-]?nan$/i.test(s)) { - return res; - }; - var m = /^ *([+-]?)0x([0-9a-f]+)\.?([0-9a-f]*)p([+-]?[0-9]+)/i.exec(s); - // 1 2 3 4 - if(m){ - var m3 = m[3].replace(/0+$/,''); - var mantissa = parseInt(m[1] + m[2] + m3, 16); - var exponent = (m[4]|0) - 4*m3.length; - res = mantissa * Math.pow(2, exponent); - return res; - } - if (/^\+?inf(inity)?$/i.test(s)) - return Infinity; - if (/^-inf(inity)?$/i.test(s)) - return -Infinity; - throw exn; -} -`) - -/** - Pervasives.float_of_string : string -> float = \"?float_of_string\" - Semantics is slightly different from javascript : - console.assert(float_of_string('infinity')===Infinity) - console.assert(float_of_string('Infinity')===Infinity - parseFloat('Infinity') === Infinity - parseFloat('infinity') === Nan -*/ -let float_of_string = (s: string): float => float_of_string(s, Failure("float_of_string")) diff --git a/jscomp/runtime/caml_hash.resi b/jscomp/runtime/caml_hash.resi deleted file mode 100644 index da8fd9e1b6..0000000000 --- a/jscomp/runtime/caml_hash.resi +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -let hash: (int, 'a, int, Obj.t) => int diff --git a/jscomp/runtime/caml_hash_primitive.res b/jscomp/runtime/caml_hash_primitive.res deleted file mode 100644 index 281b623168..0000000000 --- a/jscomp/runtime/caml_hash_primitive.res +++ /dev/null @@ -1,78 +0,0 @@ -/* Copyright (C) 2018 Hongbo Zhang, Authors of ReScript - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -let rotl32 = (x: int, n) => lor(lsl(x, n), lsr(x, 32 - n)) - -@send external charCodeAt: (string, int) => int = "charCodeAt" - -let hash_mix_int = (h, d) => { - let d = ref(d) - d.contents = d.contents * 0xcc9e2d51 - d.contents = rotl32(d.contents, 15) - d.contents = d.contents * 0x1b873593 - let h = ref(lxor(h, d.contents)) - h.contents = rotl32(h.contents, 13) - h.contents + lsl(h.contents, 2) + 0xe6546b64 -} - -let hash_final_mix = h => { - let h = ref(lxor(h, lsr(h, 16))) - h.contents = h.contents * 0x85ebca6b - h.contents = lxor(h.contents, lsr(h.contents, 13)) - h.contents = h.contents * 0xc2b2ae35 - lxor(h.contents, lsr(h.contents, 16)) -} -/* Caml_nativeint_extern.logand (h.contents ^ (h.contents >>> 16)) 0x3FFFFFFFn */ - -let hash_mix_string = (h, s) => { - let len = Caml_string_extern.length(s) - let block = len / 4 - 1 - let hash = ref(h) - for i in 0 to block { - let j = 4 * i - let w = lor( - lor(lor(s->charCodeAt(j), lsl(s->charCodeAt(j + 1), 8)), lsl(s->charCodeAt(j + 2), 16)), - lsl(s->charCodeAt(j + 3), 24), - ) - - hash.contents = hash_mix_int(hash.contents, w) - } - let modulo = land(len, 0b11) - if modulo != 0 { - let w = if modulo == 3 { - lor( - lor(lsl(s->charCodeAt(len - 1), 16), lsl(s->charCodeAt(len - 2), 8)), - s->charCodeAt(len - 3), - ) - } else if modulo == 2 { - lor(lsl(s->charCodeAt(len - 1), 8), s->charCodeAt(len - 2)) - } else { - s->charCodeAt(len - 1) - } - - hash.contents = hash_mix_int(hash.contents, w) - } - hash.contents = lxor(hash.contents, len) - hash.contents -} diff --git a/jscomp/runtime/caml_int32.res b/jscomp/runtime/caml_int32.res deleted file mode 100644 index bba66cf586..0000000000 --- a/jscomp/runtime/caml_int32.res +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -let div = (x: int, y: int) => - if y == 0 { - raise(Division_by_zero) - } else { - Caml_nativeint_extern.div(x, y) - } - -let mod_ = (x: int, y: int) => - if y == 0 { - raise(Division_by_zero) - } else { - Caml_nativeint_extern.rem(x, y) - } diff --git a/jscomp/runtime/caml_int32.resi b/jscomp/runtime/caml_int32.resi deleted file mode 100644 index 56ef48535e..0000000000 --- a/jscomp/runtime/caml_int32.resi +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -let div: (int, int) => int - -let mod_: (int, int) => int diff --git a/jscomp/runtime/caml_int64.res b/jscomp/runtime/caml_int64.res deleted file mode 100644 index d079cdc4af..0000000000 --- a/jscomp/runtime/caml_int64.res +++ /dev/null @@ -1,564 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -/* This module would only work with js backend, since it requires - [int] behaves as js numbers -*/ - -/* TODO: see GPR#333 - the encoding of int is platform dependent */ - -%%private( - let {shift_right_logical: \">>>~", add: \"+~", mul: \"*~"} = module(Caml_nativeint_extern) -) - -let {i64_eq: eq, i64_ge: ge, i64_gt: gt} = module(Caml) - -let lognot = x => lxor(x, -1) - -/* [hi] is signed - [lo] is unsigned - - signedness does not matter when they are doing int32 bits operation - however, they are different when doing comparison -*/ -type t = Caml_int64_extern.t = {@as("0") hi: int, @as("1") lo: int} - -external unsafe_to_int64: t => int64 = "%identity" -external unsafe_of_int64: int64 => t = "%identity" - -@inline let mk = (~lo, ~hi) => {lo: \">>>~"(lo, 0), hi} -let min_int = mk(~lo=0, ~hi=0x80000000) -/* The high bits are signed 0x80000000 |~ 0 */ - -let max_int = mk(~lo=0xffff_ffff, ~hi=0x7fff_ffff) - -let one = mk(~lo=1, ~hi=0) -let zero = mk(~lo=0, ~hi=0) -let neg_one = mk(~lo=-1, ~hi=-1) - -let neg_signed = x => land(x, 0x8000_0000) != 0 -let non_neg_signed = x => land(x, 0x8000_0000) == 0 -let succ_aux = (~x_lo, ~x_hi) => { - let lo = lor(\"+~"(x_lo, 1), 0) - mk( - ~lo, - ~hi=lor( - \"+~"( - x_hi, - if lo == 0 { - 1 - } else { - 0 - }, - ), - 0, - ), - ) -} -let succ = ({lo: x_lo, hi: x_hi}: t) => succ_aux(~x_lo, ~x_hi) - -let neg = ({lo, hi}) => { - let other_lo = lor(\"+~"(lognot(lo), 1), 0) - mk( - ~lo=other_lo, - ~hi=lor( - \"+~"( - lognot(hi), - if other_lo == 0 { - 1 - } else { - 0 - }, - ), - 0, - ), - ) -} - -let add_aux = ({lo: x_lo, hi: x_hi}: t, ~y_lo, ~y_hi) => { - let lo = lor(\"+~"(x_lo, y_lo), 0) - let overflow = if ( - (neg_signed(x_lo) && (neg_signed(y_lo) || non_neg_signed(lo))) || - (neg_signed(y_lo) && non_neg_signed(lo)) - ) { - /* we can make it symmetric by adding (neg_signed x_lo) but it will make it - verbose and slow - a (b+c) + b (a+c) - --> bc + ac + ab - --> a (b+c) + bc - */ - 1 - } else { - 0 - } - - mk(~lo, ~hi=lor(\"+~"(\"+~"(x_hi, y_hi), overflow), 0)) -} - -let add = (self: t, {lo: y_lo, hi: y_hi}: t) => add_aux(self, ~y_lo, ~y_hi) - -/* let not ( {lo; hi }) = mk ~lo:(lognot lo) ~hi:(lognot hi) */ - -let equal = (x, y) => x.lo == y.lo && x.hi == y.hi -let equal_null = (x, y) => - switch Js.nullToOption(y) { - | None => false - | Some(y) => eq(x, y) - } -let equal_undefined = (x, y) => - switch Js.undefinedToOption(y) { - | None => false - | Some(y) => eq(x, y) - } -let equal_nullable = (x, y) => - switch Js.toOption(y) { - | None => false - | Some(y) => eq(x, y) - } - -/* when [lo] is unsigned integer, [lognot lo] is still an unsigned integer */ -let sub_aux = (x, ~lo, ~hi) => { - let y_lo = \">>>~"(\"+~"(lognot(lo), 1), 0) - let y_hi = lor( - \"+~"( - lognot(hi), - if y_lo == 0 { - 1 - } else { - 0 - }, - ), - 0, - ) - add_aux(x, ~y_lo, ~y_hi) -} - -let sub = (self, {lo, hi}) => sub_aux(self, ~lo, ~hi) - -let lsl_ = ({lo, hi} as x, numBits) => - if numBits == 0 { - x - } else if numBits >= 32 { - mk(~lo=0, ~hi=lsl(lo, numBits - 32)) - } else { - mk(~lo=lsl(lo, numBits), ~hi=lor(\">>>~"(lo, 32 - numBits), lsl(hi, numBits))) - } - -let lsr_ = ({lo, hi} as x, numBits) => - if numBits == 0 { - x - } else { - let offset = numBits - 32 - if offset == 0 { - mk(~lo=hi, ~hi=0) - } else if offset > 0 { - mk(~lo=\">>>~"(hi, offset), ~hi=0) - } else { - mk(~hi=\">>>~"(hi, numBits), ~lo=lor(lsl(hi, -offset), \">>>~"(lo, numBits))) - } - } - -let asr_ = ({lo, hi} as x, numBits) => - if numBits == 0 { - x - } else if numBits < 32 { - mk( - ~hi=asr(hi, numBits), - ~lo=/* zero filled */ - lor(lsl(hi, 32 - numBits), \">>>~"(lo, numBits)), - ) - } else { - mk( - ~hi=if hi >= 0 { - 0 - } else { - -1 - }, - ~lo=asr(hi, numBits - 32), - ) - } - -let is_zero = x => - switch x { - | {lo: 0, hi: 0} => true - | _ => false - } - -let rec mul = (this, other) => - switch (this, other) { - | ({lo: 0, hi: 0}, _) - | (_, {lo: 0, hi: 0}) => zero - | ({lo: 0, hi: -0x80000000}, {lo, _}) - | ({lo, _}, {lo: 0, hi: -0x80000000}) => - if land(lo, 0x1) == 0 { - zero - } else { - min_int - } - | ({lo: this_lo, hi: this_hi}, {lo: other_lo, hi: other_hi}) => - if this_hi < 0 { - if other_hi < 0 { - mul(neg(this), neg(other)) - } else { - neg(mul(neg(this), other)) - } - } else if other_hi < 0 { - neg(mul(this, neg(other))) - } else { - /* TODO: when both are small, use float multiplication */ - let a48 = \">>>~"(this_hi, 16) - let a32 = land(this_hi, 0xffff) - let a16 = \">>>~"(this_lo, 16) - let a00 = land(this_lo, 0xffff) - - let b48 = \">>>~"(other_hi, 16) - let b32 = land(other_hi, 0xffff) - let b16 = \">>>~"(other_lo, 16) - let b00 = land(other_lo, 0xffff) - - let c48 = ref(0) - let c32 = ref(0) - let c16 = ref(0) - - let c00 = \"*~"(a00, b00) - c16.contents = \"+~"(\">>>~"(c00, 16), \"*~"(a16, b00)) - c32.contents = \">>>~"(c16.contents, 16) - c16.contents = \"+~"(land(c16.contents, 0xffff), \"*~"(a00, b16)) - c32.contents = \"+~"(\"+~"(c32.contents, \">>>~"(c16.contents, 16)), \"*~"(a32, b00)) - c48.contents = \">>>~"(c32.contents, 16) - c32.contents = \"+~"(land(c32.contents, 0xffff), \"*~"(a16, b16)) - c48.contents = \"+~"(c48.contents, \">>>~"(c32.contents, 16)) - c32.contents = \"+~"(land(c32.contents, 0xffff), \"*~"(a00, b32)) - c48.contents = \"+~"(c48.contents, \">>>~"(c32.contents, 16)) - c32.contents = land(c32.contents, 0xffff) - c48.contents = land( - \"+~"( - c48.contents, - \"+~"(\"+~"(\"+~"(\"*~"(a48, b00), \"*~"(a32, b16)), \"*~"(a16, b32)), \"*~"(a00, b48)), - ), - 0xffff, - ) - mk( - ~lo=lor(land(c00, 0xffff), lsl(land(c16.contents, 0xffff), 16)), - ~hi=lor(c32.contents, lsl(c48.contents, 16)), - ) - } - } - -/* Dispatched by the compiler, idea: should we do maximum sharing - */ -let xor = ({lo: this_lo, hi: this_hi}, {lo: other_lo, hi: other_hi}) => - mk(~lo=lxor(this_lo, other_lo), ~hi=lxor(this_hi, other_hi)) - -let or_ = ({lo: this_lo, hi: this_hi}, {lo: other_lo, hi: other_hi}) => - mk(~lo=lor(this_lo, other_lo), ~hi=lor(this_hi, other_hi)) - -let and_ = ({lo: this_lo, hi: this_hi}, {lo: other_lo, hi: other_hi}) => - mk(~lo=land(this_lo, other_lo), ~hi=land(this_hi, other_hi)) - -/* TODO: if we encode lo int32 bit as unsigned then - this is not necessary, - however (x>>>0 >>>0) is not that bad -*/ - -let to_float = ({hi, lo}: t) => - Caml_nativeint_extern.to_float(\"+~"(\"*~"(hi, %raw(`0x100000000`)), lo)) - -/** sign: Positive - -FIXME: hex notation -*/ -let two_ptr_32_dbl = 4294967296. /* 2. ** 32 */ -let two_ptr_63_dbl = 9.22337203685477581e+18 /* 2. ** 63. */ -let neg_two_ptr_63 = -9.22337203685477581e+18 /* -. (2. ** 63.) */ - -external mod_float: (float, float) => float = "?fmod_float" -/* note that we make sure the const number can acutally be represented - {[ - (2. ** 63. -. 1. = 2. ** 63.) ;; - ]} -*/ - -let rec of_float = (x: float): t => - if Caml_float_extern.isNaN(x) || Pervasives.not(Caml_float_extern.isFinite(x)) { - zero - } else if x <= neg_two_ptr_63 { - min_int - } else if x +. 1. >= two_ptr_63_dbl { - max_int /* Undefined behavior */ - } else if x < 0. { - neg(of_float(-.x)) - } else { - mk( - ~lo=Caml_nativeint_extern.of_float(mod_float(x, two_ptr_32_dbl)), - ~hi=Caml_nativeint_extern.of_float(x /. two_ptr_32_dbl), - ) - } - -@val @scope("Math") external log2: float = "LN2" -@val @scope("Math") external log: float => float = "log" -@val @scope("Math") external ceil: float => float = "ceil" -@val @scope("Math") external floor: float => float = "floor" -/* external maxFloat : float -> float -> float = "Math.max" [@@val] */ - -/* either top 11 bits are all 0 or all 1 - when it is all 1, we need exclude -2^53 -*/ -let isSafeInteger = ({hi, lo}) => { - let top11Bits = asr(hi, 21) - top11Bits == 0 || (top11Bits == -1 && Pervasives.not(lo == 0 && hi == 0xff_e0_00_00)) -} - -@val external string_of_float: float => string = "String" -let rec to_string = (self: int64) => { - let {hi: self_hi, _} as self = unsafe_of_int64(self) - if isSafeInteger(self) { - string_of_float(to_float(self)) - } else if self_hi < 0 { - if eq(self, min_int) { - "-9223372036854775808" - } else { - "-" ++ to_string(unsafe_to_int64(neg(self))) - } - } else { - /* large positive number */ - let {lo, hi} as approx_div1 = of_float(floor(to_float(self) /. 10.)) - let {lo: rem_lo, hi: rem_hi} = - /* rem should be a pretty small number */ - self - ->sub_aux(~lo=lsl(lo, 3), ~hi=lor(\">>>~"(lo, 29), lsl(hi, 3))) - ->sub_aux(~lo=lsl(lo, 1), ~hi=lor(\">>>~"(lo, 31), lsl(hi, 1))) - - if rem_lo == 0 && rem_hi == 0 { - to_string(unsafe_to_int64(approx_div1)) ++ "0" - } else if rem_hi < 0 { - /* let ( {lo = rem_lo}) = neg rem in */ - let rem_lo = \">>>~"(\"+~"(lognot(rem_lo), 1), 0)->Caml_nativeint_extern.to_float - let delta = ceil(rem_lo /. 10.) - let remainder = 10. *. delta -. rem_lo - approx_div1 - ->sub_aux(~lo=Caml_nativeint_extern.of_float(delta), ~hi=0) - ->unsafe_to_int64 - ->to_string ++ Caml_nativeint_extern.to_string(Caml_nativeint_extern.of_float(remainder)) - } else { - let rem_lo = Caml_nativeint_extern.to_float(rem_lo) - let delta = floor(rem_lo /. 10.) - let remainder = rem_lo -. 10. *. delta - approx_div1 - ->add_aux(~y_lo=Caml_nativeint_extern.of_float(delta), ~y_hi=0) - ->unsafe_to_int64 - ->to_string ++ Caml_nativeint_extern.to_string(Caml_nativeint_extern.of_float(remainder)) - } - } -} - -@inline -let float_max = (a: float, b) => - if a > b { - a - } else { - b - } -let rec div = (self, other) => - switch (self, other) { - | (_, {lo: 0, hi: 0}) => raise(Division_by_zero) - | ({lo: 0, hi: 0}, _) => zero - | ({lo: 0, hi: -0x8000_0000}, _) => - if eq(other, one) || eq(other, neg_one) { - self - } else if eq(other, min_int) { - one - } else { - let {hi: other_hi, _} = other - /* now |other| >= 2, so |this/other| < |MIN_VALUE| */ - let half_this = asr_(self, 1) - let approx = lsl_(div(half_this, other), 1) - switch approx { - | {lo: 0, hi: 0} => - if other_hi < 0 { - one - } else { - neg(one) - } - | _ => - let rem = sub(self, mul(other, approx)) - add(approx, div(rem, other)) - } - } - | (_, {lo: 0, hi: -0x8000_0000}) => zero - | ({lo: _, hi: self_hi}, {lo: _, hi: other_hi}) => - if self_hi < 0 { - if other_hi < 0 { - div(neg(self), neg(other)) - } else { - neg(div(neg(self), other)) - } - } else if other_hi < 0 { - neg(div(self, neg(other))) - } else { - let res = ref(zero) - let rem = ref(self) - /* assert false */ - while ge(rem.contents, other) { - let approx = ref(float_max(1., Caml_float.floor(to_float(rem.contents) /. to_float(other)))) - let log2 = ceil(log(approx.contents) /. log2) - let delta = if log2 <= 48. { - 1. - } else { - 2. ** (log2 -. 48.) - } - let approxRes = ref(of_float(approx.contents)) - let approxRem = ref(mul(approxRes.contents, other)) - while ( - switch approxRem.contents { - | {hi, _} => hi - } < 0 || gt(approxRem.contents, rem.contents) - ) { - approx.contents = approx.contents -. delta - approxRes.contents = of_float(approx.contents) - approxRem.contents = mul(approxRes.contents, other) - } - if is_zero(approxRes.contents) { - approxRes.contents = one - } - res.contents = add(res.contents, approxRes.contents) - rem.contents = sub(rem.contents, approxRem.contents) - } - res.contents - } - } - -let mod_ = (self, other) => sub(self, mul(div(self, other), other)) - -let div_mod = (self: int64, other: int64): (int64, int64) => { - let quotient = div(unsafe_of_int64(self), unsafe_of_int64(other)) - ( - unsafe_to_int64(quotient), - unsafe_to_int64(sub(unsafe_of_int64(self), mul(quotient, unsafe_of_int64(other)))), - ) -} - -/** Note this function is unasfe here, but when combined it is actually safe - In theory, we need do an uint_compare for [lo] components - The thing is [uint_compare] and [int_compare] are specialised - to the same code when translted into js -*/ -@inline -let int_compare = (x: int, y) => - if x < y { - -1 - } else if x == y { - 0 - } else { - 1 - } - -let compare = (self, other) => { - let v = int_compare(self.hi, other.hi) - if v == 0 { - int_compare(self.lo, other.lo) - } else { - v - } -} - -let of_int32 = (lo: int) => - mk( - ~lo, - ~hi=if lo < 0 { - -1 - } else { - 0 - }, - ) - -let to_int32 = x => lor(x.lo, 0) /* signed integer */ - -/* width does matter, will it be relevant to endian order? */ - -let to_hex = (x: int64) => { - let {hi: x_hi, lo: x_lo} = unsafe_of_int64(x) - let aux = (v): string => - Caml_string_extern.of_int(Caml_nativeint_extern.shift_right_logical(v, 0), ~base=16) - - switch (x_hi, x_lo) { - | (0, 0) => "0" - | (_, 0) => aux(x_hi) ++ "00000000" - | (0, _) => aux(x_lo) - | (_, _) => - let lo = aux(x_lo) - let pad = 8 - Caml_string_extern.length(lo) - if pad <= 0 { - aux(x_hi) ++ lo - } else { - aux(x_hi) ++ (Caml_string_extern.repeat("0", pad) ++ lo) - } - } -} - -let discard_sign = (x: int64): int64 => { - let v = unsafe_of_int64(x) - unsafe_to_int64( - switch v { - | v => {...v, hi: land(0x7fff_ffff, v.hi)} - }, - ) -} - -/* >>> 0 does not change its bit representation - it simply makes sure it is an unsigned integer - -1 >>> 0 -> 4294967295 - Which is still (-1) if you interpret it as a signed integer - When we do the call (new Int32Array(x[1], x[0]), it will - convert x[0] from an unsigned integer to signed integer - {[ - new Int32Array([-1 >>> 0]) - Int32Array(1)[-1] - ]} -*/ - -let float_of_bits = (x: t): float => - ( - %raw(`function(lo,hi){ return (new Float64Array(new Int32Array([lo,hi]).buffer))[0]}`): ( - _, - _, - ) => _ - )(x.lo, x.hi) - -/* let to_int32 (x : nativeint) = x |> Caml_nativeint_extern.to_int32 - in - (*TODO: - This should get inlined, we should apply a simple inliner in the js layer, - the thing is its lambda representation is complex but after js layer, - it's qutie simple - *) - let int32 = Int32_array.make [| to_int32 x.lo; to_int32 x.hi |] in - Float64_array.unsafe_get (Float64_array.fromBuffer (Int32_array.buffer int32)) 0 */ - -let bits_of_float: float => t = x => { - let (lo, hi) = (%raw(`function(x){return new Int32Array(new Float64Array([x]).buffer)}`): _ => _)( - x, - ) - mk(~lo, ~hi) -} diff --git a/jscomp/runtime/caml_int64.resi b/jscomp/runtime/caml_int64.resi deleted file mode 100644 index 63f054a175..0000000000 --- a/jscomp/runtime/caml_int64.resi +++ /dev/null @@ -1,73 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -type t -let mk: (~lo: int, ~hi: int) => t -let succ: t => t -let min_int: t -let max_int: t -let one: t -let zero: t -let neg_one: t -/* val not : t -> t */ -let of_int32: int => t -let to_int32: t => int - -let add: (t, t) => t -let neg: t => t -let sub: (t, t) => t -let lsl_: (t, int) => t -let lsr_: (t, int) => t -let asr_: (t, int) => t -let is_zero: t => bool -let mul: (t, t) => t -let xor: (t, t) => t -let or_: (t, t) => t -let and_: (t, t) => t - -let equal: (t, t) => bool -let equal_null: (t, Js.null) => bool -let equal_undefined: (t, Js.undefined) => bool -let equal_nullable: (t, Js.nullable) => bool - -let to_float: t => float -let of_float: float => t -let div: (t, t) => t -let mod_: (t, t) => t - -let compare: (t, t) => int - -let float_of_bits: t => float - -/** [bits_of_float fl] it is undefined behaivor when [f] is NaN*/ -let bits_of_float: float => t - -/* val get64 : string -> int -> t */ - -external unsafe_to_int64: t => int64 = "%identity" -external unsafe_of_int64: int64 => t = "%identity" -let div_mod: (int64, int64) => (int64, int64) -let to_hex: int64 => string -let discard_sign: int64 => int64 -let to_string: int64 => string diff --git a/jscomp/runtime/caml_int64_extern.res b/jscomp/runtime/caml_int64_extern.res deleted file mode 100644 index 0dbe54e868..0000000000 --- a/jscomp/runtime/caml_int64_extern.res +++ /dev/null @@ -1,10 +0,0 @@ -external of_int: int => int64 = "%int64_of_int" -external add: (int64, int64) => int64 = "%int64_add" -external sub: (int64, int64) => int64 = "%int64_sub" -external mul: (int64, int64) => int64 = "%int64_mul" -external div: (int64, int64) => int64 = "%int64_div" -external logor: (int64, int64) => int64 = "%int64_or" -external neg: int64 => int64 = "%int64_neg" -external to_int: int64 => int = "%int64_to_int" - -type t = {@as("0") hi: int, @as("1") lo: int} diff --git a/jscomp/runtime/caml_js_exceptions.res b/jscomp/runtime/caml_js_exceptions.res deleted file mode 100644 index 6ef72df7c5..0000000000 --- a/jscomp/runtime/caml_js_exceptions.res +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright (C) 2015- Hongbo Zhang, Authors of ReScript - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -exception Error = JsError -type js_error = {cause: exn} -/** - This function has to be in this module Since - [Error] is defined here -*/ -let internalToOCamlException = (e: unknown) => - if Caml_exceptions.is_extension(e) { - (Obj.magic(e): exn) - } else { - JsError(e) - } - -let as_js_exn = exn => - switch exn { - | Error(t) => Some(t) - | _ => None - } diff --git a/jscomp/runtime/caml_lexer.res b/jscomp/runtime/caml_lexer.res deleted file mode 100644 index 69f228b58e..0000000000 --- a/jscomp/runtime/caml_lexer.res +++ /dev/null @@ -1,335 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -type lex_tables -type lexbuf - -/* caml_lex_array("abcd") */ -/* [25185, 25699] */ -/* @param s */ -/* @returns {any[]} */ - -%%raw(` - -/***********************************************************************/ -/* */ -/* Objective Caml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 Institut National de Recherche en Informatique et */ -/* en Automatique. All rights reserved. This file is distributed */ -/* under the terms of the GNU Library General Public License, with */ -/* the special exception on linking described in file ../LICENSE. */ -/* */ -/***********************************************************************/ - -/* $Id: lexing.c 6045 2004-01-01 16:42:43Z doligez $ */ - -/* The table-driven automaton for lexers generated by camllex. */ - -function caml_lex_array(s) { - var l = s.length / 2; - var a = new Array(l); - // when s.charCodeAt(2 * i + 1 ) > 128 (0x80) - // a[i] < 0 - // for(var i = 0 ; i <= 0xffff; ++i) { if (i << 16 >> 16 !==i){console.log(i<<16>>16, 'vs',i)}} - // - for (var i = 0; i < l; i++) - a[i] = (s.charCodeAt(2 * i) | (s.charCodeAt(2 * i + 1) << 8)) << 16 >> 16; - return a; -} -`) - -/* - * external c_engine : lex_tables -> int -> lexbuf -> int - * lexing.ml - * type lex_tables = { - * lex_base : string; - * lex_backtrk : string; - * lex_default : string; - * lex_trans : string; - * lex_check : string; - * lex_base_code : string; - * lex_backtrk_code : string; - * lex_default_code : string; - * lex_trans_code : string; - * lex_check_code : string; - * lex_code : string; - * } - * - * type lexbuf = { - * refill_buff : lexbuf -> unit ; - * mutable lex_buffer : bytes; - * mutable lex_buffer_len : int; - * mutable lex_abs_pos : int; - * mutable lex_start_pos : int; - * mutable lex_curr_pos : int; - * mutable lex_last_pos : int; - * mutable lex_last_action : int; - * mutable lex_eof_reached : bool; - * mutable lex_mem : int array; - * mutable lex_start_p : position; - * mutable lex_curr_p; - * } - * @param tbl - * @param start_state - * @param lexbuf - * @returns {any} - */ - -let caml_lex_engine_aux: ( - lex_tables, - int, - lexbuf, - exn, -) => int = %raw(`function (tbl, start_state, lexbuf, exn){ - - if (!Array.isArray(tbl.lex_default)) { - tbl.lex_base = caml_lex_array(tbl.lex_base); - tbl.lex_backtrk = caml_lex_array(tbl.lex_backtrk); - tbl.lex_check = caml_lex_array(tbl.lex_check); - tbl.lex_trans = caml_lex_array(tbl.lex_trans); - tbl.lex_default = caml_lex_array(tbl.lex_default); - } - var c; - var state = start_state; - //var buffer = bytes_of_string(lexbuf.lex_buffer); - var buffer = lexbuf.lex_buffer; - if (state >= 0) { - /* First entry */ - lexbuf.lex_last_pos = lexbuf.lex_start_pos = lexbuf.lex_curr_pos; - lexbuf.lex_last_action = -1; - } - else { - /* Reentry after refill */ - state = -state - 1; - } - for (;;) { - /* Lookup base address or action number for current state */ - var base = tbl.lex_base[state]; - if (base < 0) - return -base - 1; - /* See if it's a backtrack point */ - var backtrk = tbl.lex_backtrk[state]; - if (backtrk >= 0) { - lexbuf.lex_last_pos = lexbuf.lex_curr_pos; - lexbuf.lex_last_action = backtrk; - } - /* See if we need a refill */ - if (lexbuf.lex_curr_pos >= lexbuf.lex_buffer_len) { - if (lexbuf.lex_eof_reached === 0) - return -state - 1; - else - c = 256; - } - else { - /* Read next input char */ - c = buffer[lexbuf.lex_curr_pos]; - lexbuf.lex_curr_pos++; - } - /* Determine next state */ - if (tbl.lex_check[base + c] === state) { - state = tbl.lex_trans[base + c]; - } - else { - state = tbl.lex_default[state]; - } - /* If no transition on this char, return to last backtrack point */ - if (state < 0) { - lexbuf.lex_curr_pos = lexbuf.lex_last_pos; - if (lexbuf.lex_last_action == -1) - throw exn - else - return lexbuf.lex_last_action; - } - else { - /* Erase the EOF condition only if the EOF pseudo-character was - consumed by the automaton (i.e. there was no backtrack above) - */ - if (c == 256) - lexbuf.lex_eof_reached = 0; - } - } -} -`) - -let empty_token_lit = "lexing: empty token" - -let lex_engine: (lex_tables, int, lexbuf) => int = (tbls, i, buf) => - caml_lex_engine_aux(tbls, i, buf, Failure(empty_token_lit)) - -%%raw(` - - -/***********************************************/ -/* New lexer engine, with memory of positions */ -/***********************************************/ - -/** - * s -> Lexing.lex_tables.lex_code - * mem -> Lexing.lexbuf.lex_mem (* int array *) - */ - -function caml_lex_run_mem(s, i, mem, curr_pos) { - for (;;) { - var dst = s.charCodeAt(i); - i++; - if (dst == 0xff) - return; - var src = s.charCodeAt(i); - i++; - if (src == 0xff) - mem[dst] = curr_pos; - else - mem[dst] = mem[src]; - } -} - - -/** - * s -> Lexing.lex_tables.lex_code - * mem -> Lexing.lexbuf.lex_mem (* int array *) - */ - -function caml_lex_run_tag(s, i, mem) { - for (;;) { - var dst = s.charCodeAt(i); - i++; - if (dst == 0xff) - return; - var src = s.charCodeAt(i); - i++; - if (src == 0xff) - mem[dst] = -1; - else - mem[dst] = mem[src]; - } -} -`) - -/* - * external c_new_engine : lex_tables -> int -> lexbuf -> int = "?new_lex_engine" - * @param tbl - * @param start_state - * @param lexbuf - * @returns {any} - */ - -let caml_new_lex_engine_aux: ( - lex_tables, - int, - lexbuf, - exn, -) => int = %raw(`function (tbl, start_state, lexbuf, exn) { - - if (!Array.isArray(tbl.lex_default)) { - tbl.lex_base = caml_lex_array(tbl.lex_base); - tbl.lex_backtrk = caml_lex_array(tbl.lex_backtrk); - tbl.lex_check = caml_lex_array(tbl.lex_check); - tbl.lex_trans = caml_lex_array(tbl.lex_trans); - tbl.lex_default = caml_lex_array(tbl.lex_default); - } - if(!Array.isArray(tbl.lex_default_code)){ - tbl.lex_base_code = caml_lex_array(tbl.lex_base_code); - tbl.lex_backtrk_code = caml_lex_array(tbl.lex_backtrk_code); - tbl.lex_check_code = caml_lex_array(tbl.lex_check_code); - tbl.lex_trans_code = caml_lex_array(tbl.lex_trans_code); - tbl.lex_default_code = caml_lex_array(tbl.lex_default_code); - } - var c, state = start_state; - //var buffer = caml_bytes_of_string(lexbuf.lex_buffer); - var buffer = lexbuf.lex_buffer; - if (state >= 0) { - /* First entry */ - lexbuf.lex_last_pos = lexbuf.lex_start_pos = lexbuf.lex_curr_pos; - lexbuf.lex_last_action = -1; - } - else { - /* Reentry after refill */ - state = -state - 1; - } - for (;;) { - /* Lookup base address or action number for current state */ - var base = tbl.lex_base[state]; - if (base < 0) { - var pc_off = tbl.lex_base_code[state]; - caml_lex_run_tag(tbl.lex_code, pc_off, lexbuf.lex_mem); - return -base - 1; - } - /* See if it's a backtrack point */ - var backtrk = tbl.lex_backtrk[state]; - if (backtrk >= 0) { - var pc_off = tbl.lex_backtrk_code[state]; - caml_lex_run_tag(tbl.lex_code, pc_off, lexbuf.lex_mem); - lexbuf.lex_last_pos = lexbuf.lex_curr_pos; - lexbuf.lex_last_action = backtrk; - } - /* See if we need a refill */ - if (lexbuf.lex_curr_pos >= lexbuf.lex_buffer_len) { - if (lexbuf.lex_eof_reached == 0) - return -state - 1; - else - c = 256; - } - else { - /* Read next input char */ - c = buffer[lexbuf.lex_curr_pos]; - lexbuf.lex_curr_pos++; - } - /* Determine next state */ - var pstate = state; - if (tbl.lex_check[base + c] == state) - state = tbl.lex_trans[base + c]; - else - state = tbl.lex_default[state]; - /* If no transition on this char, return to last backtrack point */ - if (state < 0) { - lexbuf.lex_curr_pos = lexbuf.lex_last_pos; - if (lexbuf.lex_last_action == -1) - throw exn; - else - return lexbuf.lex_last_action; - } - else { - /* If some transition, get and perform memory moves */ - var base_code = tbl.lex_base_code[pstate], pc_off; - if (tbl.lex_check_code[base_code + c] == pstate) - pc_off = tbl.lex_trans_code[base_code + c]; - else - pc_off = tbl.lex_default_code[pstate]; - if (pc_off > 0) - caml_lex_run_mem(tbl.lex_code, pc_off, lexbuf.lex_mem, lexbuf.lex_curr_pos); - /* Erase the EOF condition only if the EOF pseudo-character was - consumed by the automaton (i.e. there was no backtrack above) - */ - if (c == 256) - lexbuf.lex_eof_reached = 0; - } - } - } -`) - -let new_lex_engine: (lex_tables, int, lexbuf) => int = (tbl, i, buf) => - caml_new_lex_engine_aux(tbl, i, buf, Failure(empty_token_lit)) diff --git a/jscomp/runtime/caml_lexer.resi b/jscomp/runtime/caml_lexer.resi deleted file mode 100644 index cd01e892f1..0000000000 --- a/jscomp/runtime/caml_lexer.resi +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -/* the same as Lexing */ -type lex_tables -type lexbuf - -let lex_engine: (lex_tables, int, lexbuf) => int - -let new_lex_engine: (lex_tables, int, lexbuf) => int diff --git a/jscomp/runtime/caml_md5.res b/jscomp/runtime/caml_md5.res deleted file mode 100644 index b6b22d6205..0000000000 --- a/jscomp/runtime/caml_md5.res +++ /dev/null @@ -1,201 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -let lognot = n => lxor(n, -1l) -let cmn = (q, a, b, x, s, t) => { - let a = a + q + x + t - lor(lsl(a, s), lsr(a, 32 - s)) + b -} - -let f = (a, b, c, d, x, s, t) => cmn(lor(land(b, c), land(lognot(b), d)), a, b, x, s, t) - -let g = (a, b, c, d, x, s, t) => cmn(lor(land(b, d), land(c, lognot(d))), a, b, x, s, t) - -let h = (a, b, c, d, x, s, t) => cmn(lxor(lxor(b, c), d), a, b, x, s, t) - -let i = (a, b, c, d, x, s, t) => cmn(lxor(c, lor(b, lognot(d))), a, b, x, s, t) - -let {unsafe_get, unsafe_set} = module(Caml_array_extern) - -let cycle = (x: array, k: array) => { - let a = ref(x->unsafe_get(0)) - let b = ref(x->unsafe_get(1)) - let c = ref(x->unsafe_get(2)) - let d = ref(x->unsafe_get(3)) - - a.contents = f(a.contents, b.contents, c.contents, d.contents, k->unsafe_get(0), 7, 0xd76aa478l) - d.contents = f(d.contents, a.contents, b.contents, c.contents, k->unsafe_get(1), 12, 0xe8c7b756l) - c.contents = f(c.contents, d.contents, a.contents, b.contents, k->unsafe_get(2), 17, 0x242070dbl) - b.contents = f(b.contents, c.contents, d.contents, a.contents, k->unsafe_get(3), 22, 0xc1bdceeel) - - a.contents = f(a.contents, b.contents, c.contents, d.contents, k->unsafe_get(4), 7, 0xf57c0fafl) - d.contents = f(d.contents, a.contents, b.contents, c.contents, k->unsafe_get(5), 12, 0x4787c62al) - c.contents = f(c.contents, d.contents, a.contents, b.contents, k->unsafe_get(6), 17, 0xa8304613l) - b.contents = f(b.contents, c.contents, d.contents, a.contents, k->unsafe_get(7), 22, 0xfd469501l) - - a.contents = f(a.contents, b.contents, c.contents, d.contents, k->unsafe_get(8), 7, 0x698098d8l) - d.contents = f(d.contents, a.contents, b.contents, c.contents, k->unsafe_get(9), 12, 0x8b44f7afl) - c.contents = f(c.contents, d.contents, a.contents, b.contents, k->unsafe_get(10), 17, 0xffff5bb1l) - b.contents = f(b.contents, c.contents, d.contents, a.contents, k->unsafe_get(11), 22, 0x895cd7bel) - a.contents = f(a.contents, b.contents, c.contents, d.contents, k->unsafe_get(12), 7, 0x6b901122l) - d.contents = f(d.contents, a.contents, b.contents, c.contents, k->unsafe_get(13), 12, 0xfd987193l) - c.contents = f(c.contents, d.contents, a.contents, b.contents, k->unsafe_get(14), 17, 0xa679438el) - b.contents = f(b.contents, c.contents, d.contents, a.contents, k->unsafe_get(15), 22, 0x49b40821l) - - a.contents = g(a.contents, b.contents, c.contents, d.contents, k->unsafe_get(1), 5, 0xf61e2562l) - d.contents = g(d.contents, a.contents, b.contents, c.contents, k->unsafe_get(6), 9, 0xc040b340l) - c.contents = g(c.contents, d.contents, a.contents, b.contents, k->unsafe_get(11), 14, 0x265e5a51l) - b.contents = g(b.contents, c.contents, d.contents, a.contents, k->unsafe_get(0), 20, 0xe9b6c7aal) - a.contents = g(a.contents, b.contents, c.contents, d.contents, k->unsafe_get(5), 5, 0xd62f105dl) - d.contents = g(d.contents, a.contents, b.contents, c.contents, k->unsafe_get(10), 9, 0x2441453l) - c.contents = g(c.contents, d.contents, a.contents, b.contents, k->unsafe_get(15), 14, 0xd8a1e681l) - b.contents = g(b.contents, c.contents, d.contents, a.contents, k->unsafe_get(4), 20, 0xe7d3fbc8l) - a.contents = g(a.contents, b.contents, c.contents, d.contents, k->unsafe_get(9), 5, 0x21e1cde6l) - d.contents = g(d.contents, a.contents, b.contents, c.contents, k->unsafe_get(14), 9, 0xc33707d6l) - c.contents = g(c.contents, d.contents, a.contents, b.contents, k->unsafe_get(3), 14, 0xf4d50d87l) - b.contents = g(b.contents, c.contents, d.contents, a.contents, k->unsafe_get(8), 20, 0x455a14edl) - a.contents = g(a.contents, b.contents, c.contents, d.contents, k->unsafe_get(13), 5, 0xa9e3e905l) - d.contents = g(d.contents, a.contents, b.contents, c.contents, k->unsafe_get(2), 9, 0xfcefa3f8l) - c.contents = g(c.contents, d.contents, a.contents, b.contents, k->unsafe_get(7), 14, 0x676f02d9l) - b.contents = g(b.contents, c.contents, d.contents, a.contents, k->unsafe_get(12), 20, 0x8d2a4c8al) - - a.contents = h(a.contents, b.contents, c.contents, d.contents, k->unsafe_get(5), 4, 0xfffa3942l) - d.contents = h(d.contents, a.contents, b.contents, c.contents, k->unsafe_get(8), 11, 0x8771f681l) - c.contents = h(c.contents, d.contents, a.contents, b.contents, k->unsafe_get(11), 16, 0x6d9d6122l) - b.contents = h(b.contents, c.contents, d.contents, a.contents, k->unsafe_get(14), 23, 0xfde5380cl) - a.contents = h(a.contents, b.contents, c.contents, d.contents, k->unsafe_get(1), 4, 0xa4beea44l) - d.contents = h(d.contents, a.contents, b.contents, c.contents, k->unsafe_get(4), 11, 0x4bdecfa9l) - c.contents = h(c.contents, d.contents, a.contents, b.contents, k->unsafe_get(7), 16, 0xf6bb4b60l) - b.contents = h(b.contents, c.contents, d.contents, a.contents, k->unsafe_get(10), 23, 0xbebfbc70l) - a.contents = h(a.contents, b.contents, c.contents, d.contents, k->unsafe_get(13), 4, 0x289b7ec6l) - d.contents = h(d.contents, a.contents, b.contents, c.contents, k->unsafe_get(0), 11, 0xeaa127fal) - c.contents = h(c.contents, d.contents, a.contents, b.contents, k->unsafe_get(3), 16, 0xd4ef3085l) - b.contents = h(b.contents, c.contents, d.contents, a.contents, k->unsafe_get(6), 23, 0x4881d05l) - a.contents = h(a.contents, b.contents, c.contents, d.contents, k->unsafe_get(9), 4, 0xd9d4d039l) - d.contents = h(d.contents, a.contents, b.contents, c.contents, k->unsafe_get(12), 11, 0xe6db99e5l) - c.contents = h(c.contents, d.contents, a.contents, b.contents, k->unsafe_get(15), 16, 0x1fa27cf8l) - b.contents = h(b.contents, c.contents, d.contents, a.contents, k->unsafe_get(2), 23, 0xc4ac5665l) - - a.contents = i(a.contents, b.contents, c.contents, d.contents, k->unsafe_get(0), 6, 0xf4292244l) - d.contents = i(d.contents, a.contents, b.contents, c.contents, k->unsafe_get(7), 10, 0x432aff97l) - c.contents = i(c.contents, d.contents, a.contents, b.contents, k->unsafe_get(14), 15, 0xab9423a7l) - b.contents = i(b.contents, c.contents, d.contents, a.contents, k->unsafe_get(5), 21, 0xfc93a039l) - a.contents = i(a.contents, b.contents, c.contents, d.contents, k->unsafe_get(12), 6, 0x655b59c3l) - d.contents = i(d.contents, a.contents, b.contents, c.contents, k->unsafe_get(3), 10, 0x8f0ccc92l) - c.contents = i(c.contents, d.contents, a.contents, b.contents, k->unsafe_get(10), 15, 0xffeff47dl) - b.contents = i(b.contents, c.contents, d.contents, a.contents, k->unsafe_get(1), 21, 0x85845dd1l) - a.contents = i(a.contents, b.contents, c.contents, d.contents, k->unsafe_get(8), 6, 0x6fa87e4fl) - d.contents = i(d.contents, a.contents, b.contents, c.contents, k->unsafe_get(15), 10, 0xfe2ce6e0l) - c.contents = i(c.contents, d.contents, a.contents, b.contents, k->unsafe_get(6), 15, 0xa3014314l) - b.contents = i(b.contents, c.contents, d.contents, a.contents, k->unsafe_get(13), 21, 0x4e0811a1l) - a.contents = i(a.contents, b.contents, c.contents, d.contents, k->unsafe_get(4), 6, 0xf7537e82l) - d.contents = i(d.contents, a.contents, b.contents, c.contents, k->unsafe_get(11), 10, 0xbd3af235l) - c.contents = i(c.contents, d.contents, a.contents, b.contents, k->unsafe_get(2), 15, 0x2ad7d2bbl) - b.contents = i(b.contents, c.contents, d.contents, a.contents, k->unsafe_get(9), 21, 0xeb86d391l) - - unsafe_set(x, 0, a.contents + x->unsafe_get(0)) - unsafe_set(x, 1, b.contents + x->unsafe_get(1)) - unsafe_set(x, 2, c.contents + x->unsafe_get(2)) - unsafe_set(x, 3, d.contents + x->unsafe_get(3)) -} - -let seed_a = 0x67452301l -let seed_b = 0xefcdab89l -let seed_c = 0x98badcfel -let seed_d = 0x10325476l - -let state = [seed_a, seed_b, seed_c, seed_d] - -let md5blk = [0l, 0l, 0l, 0l, 0l, 0l, 0l, 0l, 0l, 0l, 0l, 0l, 0l, 0l, 0l, 0l] - -@send external charCodeAt: (string, int) => int = "charCodeAt" - -let md5_string = (s: string, start: int, len: int): string => { - let s = Caml_string_extern.slice(s, start, len) - let n = Caml_string_extern.length(s) - let () = { - state->unsafe_set(0, seed_a) - state->unsafe_set(1, seed_b) - state->unsafe_set(2, seed_c) - state->unsafe_set(3, seed_d) - for i in 0 to 15 { - md5blk->unsafe_set(i, 0l) - } - } - - let i_end = n / 64 - for i in 1 to i_end { - for j in 0 to 16 - 1 { - let k = i * 64 - 64 + j * 4 - md5blk->unsafe_set( - j, - charCodeAt(s, k) + - lsl(s->charCodeAt(k + 1), 8) + - lsl(s->charCodeAt(k + 2), 16) + - lsl(s->charCodeAt(k + 3), 24), - ) - } - cycle(state, md5blk) - } - - let s_tail = Caml_string_extern.slice_rest(s, i_end * 64) - for kk in 0 to 15 { - md5blk->unsafe_set(kk, 0l) - } - let i_end = Caml_string_extern.length(s_tail) - 1 - for i in 0 to i_end { - md5blk->unsafe_set( - i / 4, - lor(unsafe_get(md5blk, i / 4), lsl(charCodeAt(s_tail, i), lsl(mod(i, 4), 3))), - ) - } - let i = i_end + 1 - md5blk->unsafe_set(i / 4, lor(unsafe_get(md5blk, i / 4), lsl(0x80l, lsl(mod(i, 4), 3)))) - if i > 55 { - cycle(state, md5blk) - for i in 0 to 15 { - md5blk->unsafe_set(i, 0) - } - } - unsafe_set(md5blk, 14, n * 8) - cycle(state, md5blk) - Caml_string_extern.of_small_int32_array([ - land(state->unsafe_get(0), 0xff), - land(asr(state->unsafe_get(0), 8), 0xff), - land(asr(state->unsafe_get(0), 16), 0xff), - land(asr(state->unsafe_get(0), 24), 0xff), - land(state->unsafe_get(1), 0xff), - land(asr(state->unsafe_get(1), 8), 0xff), - land(asr(state->unsafe_get(1), 16), 0xff), - land(asr(state->unsafe_get(1), 24), 0xff), - land(state->unsafe_get(2), 0xff), - land(asr(state->unsafe_get(2), 8), 0xff), - land(asr(state->unsafe_get(2), 16), 0xff), - land(asr(state->unsafe_get(2), 24), 0xff), - land(state->unsafe_get(3), 0xff), - land(asr(state->unsafe_get(3), 8), 0xff), - land(asr(state->unsafe_get(3), 16), 0xff), - land(asr(state->unsafe_get(3), 24), 0xff), - ]) -} diff --git a/jscomp/runtime/caml_md5.resi b/jscomp/runtime/caml_md5.resi deleted file mode 100644 index c7bb429ff5..0000000000 --- a/jscomp/runtime/caml_md5.resi +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -let md5_string: (string, int, int) => string diff --git a/jscomp/runtime/caml_module.res b/jscomp/runtime/caml_module.res deleted file mode 100644 index 8b645038c3..0000000000 --- a/jscomp/runtime/caml_module.res +++ /dev/null @@ -1,111 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -/*** This module replaced camlinternalMod completely. - Note we can replace {!CamlinternalMod} completely, but it is not replaced - due to we believe this is an even low level dependency -*/ - -@@warning("-37") /* `Function` may be used in runtime */ - -type rec shape = - | Function - | Lazy - | Class - | Module(array<(shape, string)>) - | Value(Obj.t) -/* ATTENTION: check across versions */ -module Array = Caml_array_extern - -@set_index external set_field: (Obj.t, string, Obj.t) => unit = "" - -@get_index external get_field: (Obj.t, string) => Obj.t = "" - -module type Empty = {} - -/** Note that we have to provide a drop in replacement, since compiler internally will - spit out ("CamlinternalMod".[init_mod|update_mod] unless we intercept it - in the lambda layer -*/ -let init_mod = (loc: (string, int, int), shape: shape) => { - let undef_module = _ => raise(Undefined_recursive_module(loc)) - let rec loop = (shape: shape, struct_: Obj.t, idx) => - switch shape { - | Function => set_field(struct_, idx, Obj.magic(undef_module)) - | Lazy => set_field(struct_, idx, Obj.magic(undef_module)) - | Class => - set_field( - struct_, - idx, - Obj.magic /* ref {!CamlinternalOO.dummy_class loc} */(( - undef_module, - undef_module, - undef_module, - 0, - )), - /* depends on dummy class representation */ - ) - | Module(comps) => - let v = Obj.repr(module({}: Empty)) - set_field(struct_, idx, v) - let len = Array.length(comps) - for i in 0 to len - 1 { - let (shape, name) = Caml_array_extern.unsafe_get(comps, i) - loop(shape, v, name) - } - | Value(v) => set_field(struct_, idx, v) - } - let res = Obj.repr(module({}: Empty)) - let dummy_name = "dummy" - loop(shape, res, dummy_name) - get_field(res, dummy_name) -} - -/* Note the [shape] passed between [init_mod] and [update_mod] is always the same - and we assume [module] is encoded as an array -*/ -let update_mod = (shape: shape, o: Obj.t, n: Obj.t): unit => { - let rec aux = (shape: shape, o, n, parent, i) => - switch shape { - | Function => set_field(parent, i, n) - - | Lazy - | Class => - Caml_obj.update_dummy(o, n) - | Module(comps) => - for i in 0 to Array.length(comps) - 1 { - let (shape, name) = Caml_array_extern.unsafe_get(comps, i) - aux(shape, get_field(o, name), get_field(n, name), o, name) - } - | Value(_) => () - } - switch shape { - | Module(comps) => - for i in 0 to Array.length(comps) - 1 { - let (shape, name) = Caml_array_extern.unsafe_get(comps, i) - aux(shape, get_field(o, name), get_field(n, name), o, name) - } - | _ => assert(false) - } -} diff --git a/jscomp/runtime/caml_module.resi b/jscomp/runtime/caml_module.resi deleted file mode 100644 index 9cb284e722..0000000000 --- a/jscomp/runtime/caml_module.resi +++ /dev/null @@ -1,5 +0,0 @@ -type shape - -let init_mod: ((string, int, int), shape) => Obj.t - -let update_mod: (shape, Obj.t, Obj.t) => unit diff --git a/jscomp/runtime/caml_nativeint_extern.res b/jscomp/runtime/caml_nativeint_extern.res deleted file mode 100644 index ca19ae8622..0000000000 --- a/jscomp/runtime/caml_nativeint_extern.res +++ /dev/null @@ -1,10 +0,0 @@ -external add: (int, int) => int = "?nativeint_add" -external div: (int, int) => int = "?nativeint_div" -external rem: (int, int) => int = "?nativeint_mod" -external shift_right_logical: (int, int) => int = "?nativeint_lsr" -external mul: (int, int) => int = "?nativeint_mul" - -external to_float: int => float = "%identity" -external of_float: float => int = "?int_of_float" -/* TODO: this could be promoted to `#int_of_float` */ -@val external to_string: int => string = "String" diff --git a/jscomp/runtime/caml_parser.res b/jscomp/runtime/caml_parser.res deleted file mode 100644 index 82add8c00e..0000000000 --- a/jscomp/runtime/caml_parser.res +++ /dev/null @@ -1,390 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -%%raw(` - -/***********************************************************************/ -/* */ -/* Objective Caml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 Institut National de Recherche en Informatique et */ -/* en Automatique. All rights reserved. This file is distributed */ -/* under the terms of the GNU Library General Public License, with */ -/* the special exception on linking described in file ../LICENSE. */ -/* */ -/***********************************************************************/ - -/* $Id: parsing.c 8983 2008-08-06 09:38:25Z xleroy $ */ - -/* The PDA automaton for parsers generated by camlyacc */ - -/* The pushdown automata */ - -/** - * caml_lex_array("abcd") - * [25185, 25699] - * @param s - * @returns {any[]} - * TODO: duplicated with module {!Caml_lex} - */ -function caml_lex_array(s) { - var l = s.length / 2; - var a = new Array(l); - for (var i = 0; i < l; i++) - a[i] = (s.charCodeAt(2 * i) | (s.charCodeAt(2 * i + 1) << 8)) << 16 >> 16; - return a; -} -/** - * Note that TS enum is not friendly to Closure compiler - * @enum{number} - */ -var Automata = { - START: 0, - LOOP: 6, - TOKEN_READ: 1, - TEST_SHIFT: 7, - ERROR_DETECTED: 5, - SHIFT: 8, - SHIFT_RECOVER: 9, - STACK_GROWN_1: 2, - REDUCE: 10, - STACK_GROWN_2: 3, - SEMANTIC_ACTION_COMPUTED: 4 -}; -/** - * @enum{number} - */ -var Result = { - READ_TOKEN: 0, - RAISE_PARSE_ERROR: 1, - GROW_STACKS_1: 2, - GROW_STACKS_2: 3, - COMPUTE_SEMANTIC_ACTION: 4, - CALL_ERROR_FUNCTION: 5 -}; -var PARSER_TRACE = false; -`) - -/* - * external parse_engine : parse_tables -> parser_env -> parser_input -> Obj.t -> parser_output - * parsing.ml - * - * type parse_tables = { - * actions : (parser_env -> Obj.t) array - * transl_const : int array; - * transl_block : int array; - * lhs : string; - * len : string; - * defred : string; - * dgoto : string; - * sindex : string; - * rindex : string; - * gindex : string; - * tablesize : int; - * table : string; - * check : string; - * error_function : string -> unit; - * names_const : string; - * names_block : string - * } - * - * type parser_env = - * { mutable s_stack : int array; (* States *) - * mutable v_stack : Obj.t array; (* Semantic attributes *) - * mutable symb_start_stack : position array; (* Start positions *) - * mutable symb_end_stack : position array; (* End positions *) - * mutable stacksize : int; (* Size of the stacks *) - * mutable stackbase : int; (* Base sp for current parse *) - * mutable curr_char : int; (* Last token read *) - * mutable lval : Obj.t; (* Its semantic attribute *) - * mutable symb_start : position; (* Start pos. of the current symbol*) - * mutable symb_end : position; (* End pos. of the current symbol *) - * mutable asp : int; (* The stack pointer for attributes *) - * mutable rule_len : int; (* Number of rhs items in the rule *) - * mutable rule_number : int; (* Rule number to reduce by *) - * mutable sp : int; (* Saved sp for parse_engine *) - * mutable state : int; (* Saved state for parse_engine *) - * mutable errflag : int } (* Saved error flag for parse_engine *) - * - * type parser_input = - * | Start - * | Token_read - * | Stacks_grown_1 - * | Stacks_grown_2 - * | Semantic_action_computed - * | Error_detected - - * @param tables - * @param env - * @param cmd - * @param arg - * @returns {number} -*/ - -type parse_tables -type parser_env - -let parse_engine: ( - parse_tables, - parser_env, - /* Parsing.parser_input */ Obj.t, - Obj.t, -) => Obj.t = %raw(`function (tables /* parser_table */, env /* parser_env */, cmd /* parser_input*/, arg /* Obj.t*/) { - var ERRCODE = 256; - //var START = 0; - //var TOKEN_READ = 1; - //var STACKS_GROWN_1 = 2; - //var STACKS_GROWN_2 = 3; - //var SEMANTIC_ACTION_COMPUTED = 4; - //var ERROR_DETECTED = 5; - //var loop = 6; - //var testshift = 7; - //var shift = 8; - //var shift_recover = 9; - //var reduce = 10; - // Parsing.parser_env - var env_s_stack = 's_stack'; // array - var env_v_stack = 'v_stack'; // array - var env_symb_start_stack = 'symb_start_stack'; // array - var env_symb_end_stack = 'symb_end_stack'; // array - var env_stacksize = 'stacksize'; - var env_stackbase = 'stackbase'; - var env_curr_char = 'curr_char'; - var env_lval = 'lval'; // Obj.t - var env_symb_start = 'symb_start'; // position - var env_symb_end = 'symb_end'; // position - var env_asp = 'asp'; - var env_rule_len = 'rule_len'; - var env_rule_number = 'rule_number'; - var env_sp = 'sp'; - var env_state = 'state'; - var env_errflag = 'errflag'; - // Parsing.parse_tables - // var _tbl_actions = 1; - var tbl_transl_const = 'transl_const'; // array - var tbl_transl_block = 'transl_block'; // array - var tbl_lhs = 'lhs'; - var tbl_len = 'len'; - var tbl_defred = 'defred'; - var tbl_dgoto = 'dgoto'; - var tbl_sindex = 'sindex'; - var tbl_rindex = 'rindex'; - var tbl_gindex = 'gindex'; - var tbl_tablesize = 'tablesize'; - var tbl_table = 'table'; - var tbl_check = 'check'; - // var _tbl_error_function = 14; - // var _tbl_names_const = 15; - // var _tbl_names_block = 16; - if (!tables.preprocessed) { - tables.defred = caml_lex_array(tables[tbl_defred]); - tables.sindex = caml_lex_array(tables[tbl_sindex]); - tables.check = caml_lex_array(tables[tbl_check]); - tables.rindex = caml_lex_array(tables[tbl_rindex]); - tables.table = caml_lex_array(tables[tbl_table]); - tables.len = caml_lex_array(tables[tbl_len]); - tables.lhs = caml_lex_array(tables[tbl_lhs]); - tables.gindex = caml_lex_array(tables[tbl_gindex]); - tables.dgoto = caml_lex_array(tables[tbl_dgoto]); - tables.preprocessed = true; - } - var res; - var n, n1, n2, state1; - // RESTORE - var sp = env[env_sp]; - var state = env[env_state]; - var errflag = env[env_errflag]; - exit: for (;;) { - //console.error("State", Automata[cmd]); - switch (cmd) { - case Automata.START: - state = 0; - errflag = 0; - // Fall through - case Automata.LOOP: - n = tables.defred[state]; - if (n != 0) { - cmd = Automata.REDUCE; - break; - } - if (env[env_curr_char] >= 0) { - cmd = Automata.TEST_SHIFT; - break; - } - res = Result.READ_TOKEN; - break exit; - /* The ML code calls the lexer and updates */ - /* symb_start and symb_end */ - case Automata.TOKEN_READ: - if (typeof arg !== 'number') { - env[env_curr_char] = tables[tbl_transl_block][arg.TAG | 0 /* + 1 */]; - env[env_lval] = arg._0; // token carries payload - } - else { - env[env_curr_char] = tables[tbl_transl_const][arg /* + 1 */]; - env[env_lval] = 0; // const token - } - if (PARSER_TRACE) { - console.error("State %d, read token", state, arg); - } - // Fall through - case Automata.TEST_SHIFT: - n1 = tables.sindex[state]; - n2 = n1 + env[env_curr_char]; - if (n1 != 0 && n2 >= 0 && n2 <= tables[tbl_tablesize] && - tables.check[n2] == env[env_curr_char]) { - cmd = Automata.SHIFT; - break; - } - n1 = tables.rindex[state]; - n2 = n1 + env[env_curr_char]; - if (n1 != 0 && n2 >= 0 && n2 <= tables[tbl_tablesize] && - tables.check[n2] == env[env_curr_char]) { - n = tables.table[n2]; - cmd = Automata.REDUCE; - break; - } - if (errflag <= 0) { - res = Result.CALL_ERROR_FUNCTION; - break exit; - } - // Fall through - /* The ML code calls the error function */ - case Automata.ERROR_DETECTED: - if (errflag < 3) { - errflag = 3; - for (;;) { - state1 = env[env_s_stack][sp /* + 1*/]; - n1 = tables.sindex[state1]; - n2 = n1 + ERRCODE; - if (n1 != 0 && n2 >= 0 && n2 <= tables[tbl_tablesize] && - tables.check[n2] == ERRCODE) { - cmd = Automata.SHIFT_RECOVER; - break; - } - else { - if (sp <= env[env_stackbase]) - return Result.RAISE_PARSE_ERROR; - /* The ML code raises Parse_error */ - sp--; - } - } - } - else { - if (env[env_curr_char] == 0) - return Result.RAISE_PARSE_ERROR; - /* The ML code raises Parse_error */ - env[env_curr_char] = -1; - cmd = Automata.LOOP; - break; - } - // Fall through - case Automata.SHIFT: - env[env_curr_char] = -1; - if (errflag > 0) - errflag--; - // Fall through - case Automata.SHIFT_RECOVER: - if (PARSER_TRACE) { - console.error("State %d: shift to state %d", state, tables.table[n2]); - } - state = tables.table[n2]; - sp++; - if (sp >= env[env_stacksize]) { - res = Result.GROW_STACKS_1; - break exit; - } - // Fall through - /* The ML code resizes the stacks */ - case Automata.STACK_GROWN_1: - env[env_s_stack][sp /* + 1 */] = state; - env[env_v_stack][sp /* + 1 */] = env[env_lval]; - env[env_symb_start_stack][sp /* + 1 */] = env[env_symb_start]; - env[env_symb_end_stack][sp /* + 1 */] = env[env_symb_end]; - cmd = Automata.LOOP; - break; - case Automata.REDUCE: - if (PARSER_TRACE) { - console.error("State %d : reduce by rule %d", state, n); - } - var m = tables.len[n]; - env[env_asp] = sp; - env[env_rule_number] = n; - env[env_rule_len] = m; - sp = sp - m + 1; - m = tables.lhs[n]; - state1 = env[env_s_stack][sp - 1]; // - n1 = tables.gindex[m]; - n2 = n1 + state1; - if (n1 != 0 && n2 >= 0 && n2 <= tables[tbl_tablesize] && - tables.check[n2] == state1) - state = tables.table[n2]; - else - state = tables.dgoto[m]; - if (sp >= env[env_stacksize]) { - res = Result.GROW_STACKS_2; - break exit; - } - // Fall through - /* The ML code resizes the stacks */ - case Automata.STACK_GROWN_2: - res = Result.COMPUTE_SEMANTIC_ACTION; - break exit; - /* The ML code calls the semantic action */ - case Automata.SEMANTIC_ACTION_COMPUTED: - env[env_s_stack][sp /* + 1 */] = state; - env[env_v_stack][sp /* + 1*/] = arg; - var asp = env[env_asp]; - env[env_symb_end_stack][sp /* + 1*/] = env[env_symb_end_stack][asp /* + 1*/]; - if (sp > asp) { - /* This is an epsilon production. Take symb_start equal to symb_end. */ - env[env_symb_start_stack][sp /* + 1*/] = env[env_symb_end_stack][asp /*+ 1*/]; - } - cmd = Automata.LOOP; - break; - /* Should not happen */ - default: - return Result.RAISE_PARSE_ERROR; - } - } - // SAVE - env[env_sp] = sp; - env[env_state] = state; - env[env_errflag] = errflag; - return res; -}`) - -/** - * external set_trace: bool -> bool = "?set_parser_trace" - * parsing.ml - * @param {boolean} - * @returns {boolean} - */ -let set_parser_trace: bool => bool = %raw(`function (v) { - var old = PARSER_TRACE; - PARSER_TRACE = v; - return old; -}`) diff --git a/jscomp/runtime/caml_parser.resi b/jscomp/runtime/caml_parser.resi deleted file mode 100644 index 57d493c04e..0000000000 --- a/jscomp/runtime/caml_parser.resi +++ /dev/null @@ -1,35 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -type parse_tables -type parser_env - -let parse_engine: ( - parse_tables, - parser_env, - Obj.t /* Parsing.parser_input */, - Obj.t, -) => /* parser_output */ Obj.t - -let set_parser_trace: bool => bool diff --git a/jscomp/runtime/caml_string.res b/jscomp/runtime/caml_string.res deleted file mode 100644 index c70e95cf1f..0000000000 --- a/jscomp/runtime/caml_string.res +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -/* ********************* */ -/* replaced primitives */ -/* Note that we explicitly define [unsafe_set] instead of - using {!Bytes.unsafe_set} since for some standard libraries, - it might point to ["%string_unsafe_set"] -*/ - -let get = (s, i) => - if i >= Caml_string_extern.length(s) || i < 0 { - raise(Invalid_argument("index out of bounds")) - } else { - Caml_string_extern.unsafe_get(s, i) - } - -let make = (n, ch: char): string => Caml_string_extern.of_char(ch)->Caml_string_extern.repeat(n) diff --git a/jscomp/runtime/caml_string.resi b/jscomp/runtime/caml_string.resi deleted file mode 100644 index 162eab1887..0000000000 --- a/jscomp/runtime/caml_string.resi +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -let get: (string, int) => char - -let make: (int, char) => string diff --git a/jscomp/runtime/caml_string_extern.res b/jscomp/runtime/caml_string_extern.res deleted file mode 100644 index 6bfafc88f7..0000000000 --- a/jscomp/runtime/caml_string_extern.res +++ /dev/null @@ -1,55 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -/*** TODO: check with {!String.of_char} - it's quite common that we have - {[ Caml_string_extern.of_char x.[0] ]} - It would be nice to generate code as below - {[ x[0] - ]} -*/ - -/* ATT: this relies on we encode `char' as int */ -@val external of_char: char => string = "String.fromCharCode" -@get_index external get_string_unsafe: (string, int) => string = "" - -@send external toUpperCase: string => string = "toUpperCase" -@send external of_int: (int, ~base: int) => string = "toString" -@send external slice: (string, int, int) => string = "slice" -@send external slice_rest: (string, int) => string = "slice" -@send external index_of: (string, string) => int = "indexOf" - -@val -external of_small_int_array: (@as(json`null`) _, array) => string = "String.fromCharCode.apply" - -@val @variadic external of_small_int32_array: array => string = "String.fromCharCode" - -@send external lastIndexOf: (string, string) => int = "lastIndexOf" /* used in {!Caml_io} */ - -external length: string => int = "%string_length" -external unsafe_get: (string, int) => char = "%string_unsafe_get" -external unsafe_set: (bytes, int, char) => unit = "%bytes_unsafe_set" -external get: (string, int) => char = "%string_unsafe_get" - -@send external repeat: (string, int) => string = "repeat" diff --git a/jscomp/runtime/caml_sys.res b/jscomp/runtime/caml_sys.res deleted file mode 100644 index 11a84c6220..0000000000 --- a/jscomp/runtime/caml_sys.res +++ /dev/null @@ -1,111 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -@get_index external getEnv: ('a, string) => option = "" -let sys_getenv = s => - if ( - Js.typeof(%raw(`process`)) == "undefined" || %raw(`process.env`) == Caml_undefined_extern.empty - ) { - raise(Not_found) - } else { - switch getEnv(%raw(`process.env`), s) { - | None => raise(Not_found) - | Some(x) => x - } - } - -/* https://nodejs.org/dist/latest-v12.x/docs/api/os.html#os_os_platform - The value is set at compile time. Possible values are 'aix', 'darwin','freebsd', 'linux', 'openbsd', 'sunos', and 'win32'. - The return value is equivalent to process.platform. - NodeJS does not support Cygwin very well -*/ -let os_type: unit => string = %raw(`function(_){ - if(typeof process !== 'undefined' && process.platform === 'win32'){ - return "Win32" - } - else { - return "Unix" - } -}`) -/* TODO: improve [js_pass_scope] to avoid remove unused n here */ - -/* let initial_time = now () *. 0.001 */ - -type process -@send external uptime: (process, unit) => float = "uptime" -@send external exit: (process, int) => 'a = "exit" - -let sys_time = () => - if ( - Js.typeof(%raw(`process`)) == "undefined" || - %raw(`process.uptime`) == Caml_undefined_extern.empty - ) { - -1. - } else { - uptime(%raw(`process`), ()) - } - -/* -type spawnResult -external spawnSync : string -> spawnResult = "spawnSync" [@@module "child_process"] - -external readAs : spawnResult -> - < - status : int Js.null; - > Js.t = - "%identity" -*/ - -let sys_getcwd: unit => string = %raw(`function(param){ - if (typeof process === "undefined" || process.cwd === undefined){ - return "/" - } - return process.cwd() - }`) - -/* Called by {!Sys} in the toplevel, should never fail */ -let sys_get_argv = (): (string, array) => - if Js.typeof(%raw(`process`)) == "undefined" { - ("", [""]) - } else { - let argv = %raw(`process.argv`) - if Js.testAny(argv) { - ("", [""]) - } else { - (Caml_array_extern.unsafe_get(argv, 0), argv) - } - } - -/** {!Pervasives.sys_exit} */ -let sys_exit: int => 'a = exit_code => - if Js.typeof(%raw(`process`)) != "undefined" { - exit(%raw(`process`), exit_code) - } - -let sys_is_directory = _s => raise(Failure("sys_is_directory not implemented")) - -/** Need polyfill to make cmdliner work - {!Sys.is_directory} or {!Sys.file_exists} {!Sys.command} -*/ -let sys_file_exists = _s => raise(Failure("sys_file_exists not implemented")) diff --git a/jscomp/runtime/caml_sys.resi b/jscomp/runtime/caml_sys.resi deleted file mode 100644 index 8ebc0c158a..0000000000 --- a/jscomp/runtime/caml_sys.resi +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -let sys_getenv: string => string - -let sys_time: unit => float - -let os_type: unit => string - -let sys_getcwd: unit => string - -let sys_get_argv: unit => (string, array) - -let sys_exit: int => unit - -let sys_is_directory: string => bool -let sys_file_exists: string => bool diff --git a/jscomp/runtime/caml_undefined_extern.res b/jscomp/runtime/caml_undefined_extern.res deleted file mode 100644 index a34355edb1..0000000000 --- a/jscomp/runtime/caml_undefined_extern.res +++ /dev/null @@ -1,4 +0,0 @@ -type t<+'a> -external empty: t<'a> = "#undefined" -external return: 'a => t<'a> = "%identity" -external toOption: t<'a> => option<'a> = "#undefined_to_opt" diff --git a/jscomp/runtime/char.res b/jscomp/runtime/char.res new file mode 100644 index 0000000000..a80fc11663 --- /dev/null +++ b/jscomp/runtime/char.res @@ -0,0 +1,59 @@ +// FIXME: +// This exists for compatibility reason. +// Move this into Pervasives or Core + +// Below is all deprecated and should be removed in v13 + +type t = char + +external code: t => int = "%identity" + +external unsafe_chr: int => t = "%identity" + +let chr = unsafe_chr + +external bytes_create: int => array = "Array" + +let bytes_unsafe_set = Primitive_array_extern.setUnsafe + +@scope("String") @variadic +external unsafe_to_string: array => string = "fromCodePoint" + +let escaped = param => + switch param { + | '\'' => "\\'" + | '\\' => "\\\\" + | '\n' => "\\n" + | '\t' => "\\t" + | '\r' => "\\r" + | '\b' => "\\b" + | ' ' .. '~' as c => + let s = bytes_create(1) + bytes_unsafe_set(s, 0, c) + unsafe_to_string(s) + | c => + let n = code(c) + let s = bytes_create(4) + bytes_unsafe_set(s, 0, '\\') + bytes_unsafe_set(s, 1, unsafe_chr(48 + n / 100)) + bytes_unsafe_set(s, 2, unsafe_chr(48 + mod(n / 10, 10))) + bytes_unsafe_set(s, 3, unsafe_chr(48 + mod(n, 10))) + unsafe_to_string(s) + } + +let lowercase_ascii = c => + if c >= 'A' && c <= 'Z' { + unsafe_chr(code(c) + 32) + } else { + c + } + +let uppercase_ascii = c => + if c >= 'a' && c <= 'z' { + unsafe_chr(code(c) - 32) + } else { + c + } + +let compare = (c1, c2) => code(c1) - code(c2) +let equal = (c1: t, c2: t) => compare(c1, c2) == 0 diff --git a/jscomp/stdlib-406/char.resi b/jscomp/runtime/char.resi similarity index 55% rename from jscomp/stdlib-406/char.resi rename to jscomp/runtime/char.resi index 78e07aa735..97320d7118 100644 --- a/jscomp/stdlib-406/char.resi +++ b/jscomp/runtime/char.resi @@ -1,26 +1,15 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/*** Character operations. */ +// FIXME: +// This exists for compatibility reason. +// Move this into Pervasives or Core /** Return the ASCII code of the argument. */ +@deprecated("Use Core instead. This will be removed in v13") external code: char => int = "%identity" /** Return the character with the given ASCII code. Raise [Invalid_argument "Char.chr"] if the argument is outside the range 0--255. */ +@deprecated("Use Core instead. This will be removed in v13") let chr: int => char /** Return a string representing the given character, @@ -28,43 +17,38 @@ let chr: int => char of OCaml. All characters outside the ASCII printable range (32..126) are escaped, as well as backslash, double-quote, and single-quote. */ +@deprecated("Use Core instead. This will be removed in v13") let escaped: char => string -@deprecated("Use Char.lowercase_ascii instead.") -/** Convert the given character to its equivalent lowercase character, - using the ISO Latin-1 (8859-1) character set. - @deprecated Functions operating on Latin-1 character set are deprecated. */ -let lowercase: char => char - -@deprecated("Use Char.uppercase_ascii instead.") -/** Convert the given character to its equivalent uppercase character, - using the ISO Latin-1 (8859-1) character set. - @deprecated Functions operating on Latin-1 character set are deprecated. */ -let uppercase: char => char - /** Convert the given character to its equivalent lowercase character, using the US-ASCII character set. @since 4.03.0 */ +@deprecated("Use Core instead. This will be removed in v13") let lowercase_ascii: char => char /** Convert the given character to its equivalent uppercase character, using the US-ASCII character set. @since 4.03.0 */ +@deprecated("Use Core instead. This will be removed in v13") let uppercase_ascii: char => char /** An alias for the type of characters. */ +@deprecated("Use `char` instead. This will be removed in v13") type t = char /** The comparison function for characters, with the same specification as {!Pervasives.compare}. Along with the type [t], this function [compare] allows the module [Char] to be passed as argument to the functors {!Set.Make} and {!Map.Make}. */ +@deprecated("Use Core instead. This will be removed in v13") let compare: (t, t) => int /** The equal function for chars. @since 4.03.0 */ +@deprecated("Use Core instead. This will be removed in v13") let equal: (t, t) => bool /* The following is for system use only. Do not call directly. */ +@deprecated("Use Core instead. This will be removed in v13") external unsafe_chr: int => char = "%identity" diff --git a/jscomp/runtime/curry.res b/jscomp/runtime/curry.res deleted file mode 100644 index 97147be508..0000000000 --- a/jscomp/runtime/curry.res +++ /dev/null @@ -1,391 +0,0 @@ -/* Copyright (C) 2015 - Hongbo Zhang, Authors of ReScript - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -@@uncurried - -/* Generated by scripts/curry_gen.ml */ -external function_length: 'a => int = "#function_length" -external apply_args: ('a => 'b, array<_>) => 'b = "#apply" - -let _ = Caml_array.sub /* make the build dependency on Caml_array explicit */ -%%private(let sub = Caml_array.sub) -/* Public */ -let rec app = (f, args) => { - let init_arity = function_length(f) - let arity = if init_arity == 0 { - 1 - } else { - init_arity - } /* arity fixing */ - let len = Caml_array_extern.length(args) - let d = arity - len - if d == 0 { - apply_args(f, args) /* f.apply (null,args) */ - } else if d < 0 { - /* TODO: could avoid copy by tracking the index */ - app(Obj.magic(apply_args(f, sub(args, 0, arity))), sub(args, arity, -d)) - } else { - Obj.magic(x => app(f, Caml_array_extern.append(args, [x]))) - } -} - -/* Internal use */ -external apply1: ('a0 => 'a1, 'a0) => 'a1 = "#apply1" -/* Internal use */ -external apply2: (('a0, 'a1) => 'a2, 'a0, 'a1) => 'a2 = "#apply2" -/* Internal use */ -external apply3: (('a0, 'a1, 'a2) => 'a3, 'a0, 'a1, 'a2) => 'a3 = "#apply3" -/* Internal use */ -external apply4: (('a0, 'a1, 'a2, 'a3) => 'a4, 'a0, 'a1, 'a2, 'a3) => 'a4 = "#apply4" -/* Internal use */ -external apply5: (('a0, 'a1, 'a2, 'a3, 'a4) => 'a5, 'a0, 'a1, 'a2, 'a3, 'a4) => 'a5 = "#apply5" -/* Internal use */ -external apply6: (('a0, 'a1, 'a2, 'a3, 'a4, 'a5) => 'a6, 'a0, 'a1, 'a2, 'a3, 'a4, 'a5) => 'a6 = - "#apply6" -/* Internal use */ -external apply7: ( - ('a0, 'a1, 'a2, 'a3, 'a4, 'a5, 'a6) => 'a7, - 'a0, - 'a1, - 'a2, - 'a3, - 'a4, - 'a5, - 'a6, -) => 'a7 = "#apply7" -/* Internal use */ -external apply8: ( - ('a0, 'a1, 'a2, 'a3, 'a4, 'a5, 'a6, 'a7) => 'a8, - 'a0, - 'a1, - 'a2, - 'a3, - 'a4, - 'a5, - 'a6, - 'a7, -) => 'a8 = "#apply8" - -%%private( - let curry_1 = (o, a0, arity) => - switch arity { - | 1 => apply1(Obj.magic(o), a0) - | 2 => param => apply2(Obj.magic(o), a0, param) - | 3 => Obj.magic((param, \"param$1") => apply3(Obj.magic(o), a0, param, \"param$1")) - | 4 => - Obj.magic((param, \"param$1", \"param$2") => - apply4(Obj.magic(o), a0, param, \"param$1", \"param$2") - ) - | 5 => - Obj.magic((param, \"param$1", \"param$2", \"param$3") => - apply5(Obj.magic(o), a0, param, \"param$1", \"param$2", \"param$3") - ) - | 6 => - Obj.magic((param, \"param$1", \"param$2", \"param$3", \"param$4") => - apply6(Obj.magic(o), a0, param, \"param$1", \"param$2", \"param$3", \"param$4") - ) - | 7 => - Obj.magic((param, \"param$1", \"param$2", \"param$3", \"param$4", \"param$5") => - apply7(Obj.magic(o), a0, param, \"param$1", \"param$2", \"param$3", \"param$4", \"param$5") - ) - | _ => Obj.magic(app(o, [a0])) - } -) - -/* Public */ -let _1 = (o, a0) => { - let arity = function_length(o) - if arity == 1 { - apply1(o, a0) - } else { - curry_1(o, a0, arity) - } -} - -/* Public */ -let __1 = o => { - let arity = function_length(o) - if arity == 1 { - o - } else { - a0 => _1(o, a0) - } -} - -%%private( - let curry_2 = (o, a0, a1, arity) => - switch arity { - | 1 => app(apply1(Obj.magic(o), a0), [a1]) - | 2 => apply2(Obj.magic(o), a0, a1) - | 3 => param => apply3(Obj.magic(o), a0, a1, param) - | 4 => Obj.magic((param, \"param$1") => apply4(Obj.magic(o), a0, a1, param, \"param$1")) - | 5 => - Obj.magic((param, \"param$1", \"param$2") => - apply5(Obj.magic(o), a0, a1, param, \"param$1", \"param$2") - ) - | 6 => - Obj.magic((param, \"param$1", \"param$2", \"param$3") => - apply6(Obj.magic(o), a0, a1, param, \"param$1", \"param$2", \"param$3") - ) - | 7 => - Obj.magic((param, \"param$1", \"param$2", \"param$3", \"param$4") => - apply7(Obj.magic(o), a0, a1, param, \"param$1", \"param$2", \"param$3", \"param$4") - ) - | _ => Obj.magic(app(o, [a0, a1])) - } -) - -/* Public */ -let _2 = (o, a0, a1) => { - let arity = function_length(o) - if arity == 2 { - apply2(o, a0, a1) - } else { - curry_2(Obj.magic(o), a0, a1, arity) - } -} - -/* Public */ -let __2 = o => { - let arity = function_length(o) - if arity == 2 { - o - } else { - (a0, a1) => _2(o, a0, a1) - } -} - -%%private( - let curry_3 = (o, a0, a1, a2, arity) => - switch arity { - | 1 => app(apply1(Obj.magic(o), a0), [a1, a2]) - | 2 => app(apply2(Obj.magic(o), a0, a1), [a2]) - | 3 => apply3(Obj.magic(o), a0, a1, a2) - | 4 => param => apply4(Obj.magic(o), a0, a1, a2, param) - | 5 => Obj.magic((param, \"param$1") => apply5(Obj.magic(o), a0, a1, a2, param, \"param$1")) - | 6 => - Obj.magic((param, \"param$1", \"param$2") => - apply6(Obj.magic(o), a0, a1, a2, param, \"param$1", \"param$2") - ) - | 7 => - Obj.magic((param, \"param$1", \"param$2", \"param$3") => - apply7(Obj.magic(o), a0, a1, a2, param, \"param$1", \"param$2", \"param$3") - ) - | _ => Obj.magic(app(o, [a0, a1, a2])) - } -) - -/* Public */ -let _3 = (o, a0, a1, a2) => { - let arity = function_length(o) - if arity == 3 { - apply3(o, a0, a1, a2) - } else { - curry_3(Obj.magic(o), a0, a1, a2, arity) - } -} - -/* Public */ -let __3 = o => { - let arity = function_length(o) - if arity == 3 { - o - } else { - (a0, a1, a2) => _3(o, a0, a1, a2) - } -} - -%%private( - let curry_4 = (o, a0, a1, a2, a3, arity) => - switch arity { - | 1 => app(apply1(Obj.magic(o), a0), [a1, a2, a3]) - | 2 => app(apply2(Obj.magic(o), a0, a1), [a2, a3]) - | 3 => app(apply3(Obj.magic(o), a0, a1, a2), [a3]) - | 4 => apply4(Obj.magic(o), a0, a1, a2, a3) - | 5 => param => apply5(Obj.magic(o), a0, a1, a2, a3, param) - | 6 => Obj.magic((param, \"param$1") => apply6(Obj.magic(o), a0, a1, a2, a3, param, \"param$1")) - | 7 => - Obj.magic((param, \"param$1", \"param$2") => - apply7(Obj.magic(o), a0, a1, a2, a3, param, \"param$1", \"param$2") - ) - | _ => Obj.magic(app(o, [a0, a1, a2, a3])) - } -) - -/* Public */ -let _4 = (o, a0, a1, a2, a3) => { - let arity = function_length(o) - if arity == 4 { - apply4(o, a0, a1, a2, a3) - } else { - curry_4(Obj.magic(o), a0, a1, a2, a3, arity) - } -} - -/* Public */ -let __4 = o => { - let arity = function_length(o) - if arity == 4 { - o - } else { - (a0, a1, a2, a3) => _4(o, a0, a1, a2, a3) - } -} - -%%private( - let curry_5 = (o, a0, a1, a2, a3, a4, arity) => - switch arity { - | 1 => app(apply1(Obj.magic(o), a0), [a1, a2, a3, a4]) - | 2 => app(apply2(Obj.magic(o), a0, a1), [a2, a3, a4]) - | 3 => app(apply3(Obj.magic(o), a0, a1, a2), [a3, a4]) - | 4 => app(apply4(Obj.magic(o), a0, a1, a2, a3), [a4]) - | 5 => apply5(Obj.magic(o), a0, a1, a2, a3, a4) - | 6 => param => apply6(Obj.magic(o), a0, a1, a2, a3, a4, param) - | 7 => - Obj.magic((param, \"param$1") => apply7(Obj.magic(o), a0, a1, a2, a3, a4, param, \"param$1")) - | _ => Obj.magic(app(o, [a0, a1, a2, a3, a4])) - } -) - -/* Public */ -let _5 = (o, a0, a1, a2, a3, a4) => { - let arity = function_length(o) - if arity == 5 { - apply5(o, a0, a1, a2, a3, a4) - } else { - curry_5(Obj.magic(o), a0, a1, a2, a3, a4, arity) - } -} - -/* Public */ -let __5 = o => { - let arity = function_length(o) - if arity == 5 { - o - } else { - (a0, a1, a2, a3, a4) => _5(o, a0, a1, a2, a3, a4) - } -} - -%%private( - let curry_6 = (o, a0, a1, a2, a3, a4, a5, arity) => - switch arity { - | 1 => app(apply1(Obj.magic(o), a0), [a1, a2, a3, a4, a5]) - | 2 => app(apply2(Obj.magic(o), a0, a1), [a2, a3, a4, a5]) - | 3 => app(apply3(Obj.magic(o), a0, a1, a2), [a3, a4, a5]) - | 4 => app(apply4(Obj.magic(o), a0, a1, a2, a3), [a4, a5]) - | 5 => app(apply5(Obj.magic(o), a0, a1, a2, a3, a4), [a5]) - | 6 => apply6(Obj.magic(o), a0, a1, a2, a3, a4, a5) - | 7 => param => apply7(Obj.magic(o), a0, a1, a2, a3, a4, a5, param) - | _ => Obj.magic(app(o, [a0, a1, a2, a3, a4, a5])) - } -) - -/* Public */ -let _6 = (o, a0, a1, a2, a3, a4, a5) => { - let arity = function_length(o) - if arity == 6 { - apply6(o, a0, a1, a2, a3, a4, a5) - } else { - curry_6(Obj.magic(o), a0, a1, a2, a3, a4, a5, arity) - } -} - -/* Public */ -let __6 = o => { - let arity = function_length(o) - if arity == 6 { - o - } else { - (a0, a1, a2, a3, a4, a5) => _6(o, a0, a1, a2, a3, a4, a5) - } -} - -%%private( - let curry_7 = (o, a0, a1, a2, a3, a4, a5, a6, arity) => - switch arity { - | 1 => app(apply1(Obj.magic(o), a0), [a1, a2, a3, a4, a5, a6]) - | 2 => app(apply2(Obj.magic(o), a0, a1), [a2, a3, a4, a5, a6]) - | 3 => app(apply3(Obj.magic(o), a0, a1, a2), [a3, a4, a5, a6]) - | 4 => app(apply4(Obj.magic(o), a0, a1, a2, a3), [a4, a5, a6]) - | 5 => app(apply5(Obj.magic(o), a0, a1, a2, a3, a4), [a5, a6]) - | 6 => app(apply6(Obj.magic(o), a0, a1, a2, a3, a4, a5), [a6]) - | 7 => apply7(Obj.magic(o), a0, a1, a2, a3, a4, a5, a6) - | _ => Obj.magic(app(o, [a0, a1, a2, a3, a4, a5, a6])) - } -) - -/* Public */ -let _7 = (o, a0, a1, a2, a3, a4, a5, a6) => { - let arity = function_length(o) - if arity == 7 { - apply7(o, a0, a1, a2, a3, a4, a5, a6) - } else { - curry_7(Obj.magic(o), a0, a1, a2, a3, a4, a5, a6, arity) - } -} - -/* Public */ -let __7 = o => { - let arity = function_length(o) - if arity == 7 { - o - } else { - (a0, a1, a2, a3, a4, a5, a6) => _7(o, a0, a1, a2, a3, a4, a5, a6) - } -} - -%%private( - let curry_8 = (o, a0, a1, a2, a3, a4, a5, a6, a7, arity) => - switch arity { - | 1 => app(apply1(Obj.magic(o), a0), [a1, a2, a3, a4, a5, a6, a7]) - | 2 => app(apply2(Obj.magic(o), a0, a1), [a2, a3, a4, a5, a6, a7]) - | 3 => app(apply3(Obj.magic(o), a0, a1, a2), [a3, a4, a5, a6, a7]) - | 4 => app(apply4(Obj.magic(o), a0, a1, a2, a3), [a4, a5, a6, a7]) - | 5 => app(apply5(Obj.magic(o), a0, a1, a2, a3, a4), [a5, a6, a7]) - | 6 => app(apply6(Obj.magic(o), a0, a1, a2, a3, a4, a5), [a6, a7]) - | 7 => app(apply7(Obj.magic(o), a0, a1, a2, a3, a4, a5, a6), [a7]) - | _ => Obj.magic(app(o, [a0, a1, a2, a3, a4, a5, a6, a7])) - } -) - -/* Public */ -let _8 = (o, a0, a1, a2, a3, a4, a5, a6, a7) => { - let arity = function_length(o) - if arity == 8 { - apply8(o, a0, a1, a2, a3, a4, a5, a6, a7) - } else { - curry_8(Obj.magic(o), a0, a1, a2, a3, a4, a5, a6, a7, arity) - } -} - -/* Public */ -let __8 = o => { - let arity = function_length(o) - if arity == 8 { - o - } else { - (a0, a1, a2, a3, a4, a5, a6, a7) => _8(o, a0, a1, a2, a3, a4, a5, a6, a7) - } -} diff --git a/jscomp/runtime/hashtbl.res b/jscomp/runtime/hashtbl.res new file mode 100644 index 0000000000..b581705f85 --- /dev/null +++ b/jscomp/runtime/hashtbl.res @@ -0,0 +1,10 @@ +// FIXME: +// This exists for compatibility reason. +// Move this into Pervasives or Core + +// Below is all deprecated and should be removed in v13 + +@noalloc external seeded_hash_param: (int, int, int, 'a) => int = "%hash" + +@deprecated("Use an alternative library. This will be removed in v13") +let hash = x => seeded_hash_param(10, 100, 0, x) diff --git a/jscomp/runtime/hashtbl.resi b/jscomp/runtime/hashtbl.resi new file mode 100644 index 0000000000..411fe9b6f0 --- /dev/null +++ b/jscomp/runtime/hashtbl.resi @@ -0,0 +1,2 @@ +@deprecated("Use an alternative library. This will be removed in v13") +let hash: 'a => int diff --git a/jscomp/runtime/js.res b/jscomp/runtime/js.res deleted file mode 100644 index 0780d88919..0000000000 --- a/jscomp/runtime/js.res +++ /dev/null @@ -1,273 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -@@config({flags: ["-unboxed-types", "-w", "-49"]}) - -/* DESIGN: - - It does not have any code, all its code will be inlined so that - there will never be - {[ require('js')]} - - Its interface should be minimal -*/ - -/*** -The Js module mostly contains ReScript bindings to _standard JavaScript APIs_ -like [console.log](https://developer.mozilla.org/en-US/docs/Web/API/Console/log), -or the JavaScript -[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), -[Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date), and -[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) -classes. - -It is meant as a zero-abstraction interop layer and directly exposes JavaScript functions as they are. If you can find your API in this module, prefer this over an equivalent Belt helper. For example, prefer [Js.Array2](js/array2) over [Belt.Array](belt/array) - -## Argument Order - -For historical reasons, some APIs in the Js namespace (e.g. [Js.String](js/string)) are -using the data-last argument order whereas others (e.g. [Js.Date](js/date)) are using data-first. - -For more information about these argument orders and the trade-offs between them, see -[this blog post](https://www.javierchavarri.com/data-first-and-data-last-a-comparison/). - -_Eventually, all modules in the Js namespace are going to be migrated to data-first though._ - -In the meantime, there are several options for dealing with the data-last APIs: - -## Examples - -```rescript -/* Js.String (data-last API used with pipe last operator) */ -Js.log("2019-11-10" |> Js.String.split("-")) -Js.log("ReScript" |> Js.String.startsWith("Re")) - -/* Js.String (data-last API used with pipe first operator) */ -Js.log("2019-11-10"->Js.String.split("-", _)) -Js.log("ReScript"->Js.String.startsWith("Re", _)) - -/* Js.String (data-last API used without any piping) */ -Js.log(Js.String.split("-", "2019-11-10")) -Js.log(Js.String.startsWith("Re", "ReScript")) -``` -## Js.Xxx2 Modules - -Prefer `Js.Array2` over `Js.Array`, `Js.String2` over `Js.String`, etc. The latters are old modules. - */ - -/** JS object type */ -type t<'a> = {..} as 'a - -/** JS global object reference */ -@val -external globalThis: t<'a> = "globalThis" - -/** - Nullable value of this type can be either null or 'a. This type is equivalent to Js.Null.t. -*/ -@unboxed -type null<+'a> = Value('a) | @as(null) Null - -/** - A value of this type can be either undefined or 'a. This type is equivalent to Js.Undefined.t. -*/ -type undefined<+'a> - -@unboxed type nullable<+'a> = Value('a) | @as(null) Null | @as(undefined) Undefined - -/*** - A value of this type can be undefined, null or 'a. This type is equivalent to Js.Null_undefined.t. -*/ - -type null_undefined<+'a> = nullable<'a> - -external toOption: nullable<'a> => option<'a> = "#nullable_to_opt" -external undefinedToOption: undefined<'a> => option<'a> = "#undefined_to_opt" -external nullToOption: null<'a> => option<'a> = "#null_to_opt" -external isNullable: nullable<'a> => bool = "#is_nullable" -external import: 'a => promise<'a> = "#import" - -/** The same as {!test} except that it is more permissive on the types of input */ -external testAny: 'a => bool = "#is_nullable" - -/** - The promise type, defined here for interoperation across packages. -*/ -type promise<+'a, +'e> - -/** - The same as empty in `Js.Null`. Compiles to `null`. -*/ -external null: null<'a> = "#null" - -/** - The same as empty `Js.Undefined`. Compiles to `undefined`. -*/ -external undefined: undefined<'a> = "#undefined" - -/** -`typeof x` will be compiled as `typeof x` in JS. Please consider functions in -`Js.Types` for a type safe way of reflection. -*/ -external typeof: 'a => string = "#typeof" - -@val @scope("console") /** Equivalent to console.log any value. */ -external log: 'a => unit = "log" - -@val @scope("console") external log2: ('a, 'b) => unit = "log" -@val @scope("console") external log3: ('a, 'b, 'c) => unit = "log" - -@val @scope("console") external log4: ('a, 'b, 'c, 'd) => unit = "log" - -@val @scope("console") @variadic /** A convenience function to console.log more than 4 arguments */ -external logMany: array<'a> => unit = "log" - -external eqNull: ('a, null<'a>) => bool = "%bs_equal_null" -external eqUndefined: ('a, undefined<'a>) => bool = "%bs_equal_undefined" -external eqNullable: ('a, nullable<'a>) => bool = "%bs_equal_nullable" - -/* ## Operators */ - -/** - `unsafe_lt(a, b)` will be compiled as `a < b`. - It is marked as unsafe, since it is impossible - to give a proper semantics for comparision which applies to any type -*/ -external unsafe_lt: ('a, 'a) => bool = "#unsafe_lt" - -/** - `unsafe_le(a, b)` will be compiled as `a <= b`. - See also `Js.unsafe_lt`. -*/ -external unsafe_le: ('a, 'a) => bool = "#unsafe_le" - -/** - `unsafe_gt(a, b)` will be compiled as `a > b`. - See also `Js.unsafe_lt`. -*/ -external unsafe_gt: ('a, 'a) => bool = "#unsafe_gt" - -/** - `unsafe_ge(a, b)` will be compiled as `a >= b`. - See also `Js.unsafe_lt`. -*/ -external unsafe_ge: ('a, 'a) => bool = "#unsafe_ge" - -/* ## Nested Modules */ - -/** Provide utilities for `Js.null<'a>` */ -module Null = Js_null - -/** Provide utilities for `Js.undefined<'a>` */ -module Undefined = Js_undefined - -/** Provide utilities for `Js.null_undefined` */ -module Nullable = Js_null_undefined - -module Null_undefined = Js_null_undefined - -/** Provide utilities for dealing with Js exceptions */ -module Exn = Js_exn - -/** Provide bindings to JS array*/ -module Array = Js_array - -/** Provide bindings to JS array*/ -module Array2 = Js_array2 - -/** Provide bindings to JS string */ -module String = Js_string - -/** Provide bindings to JS string */ -module String2 = Js_string2 - -/** Provide bindings to JS regex expression */ -module Re = Js_re - -/** Provide bindings to JS Promise */ -module Promise = Js_promise - -/** Provide bindings to JS Promise */ -module Promise2 = Js_promise2 - -/** Provide bindings for JS Date */ -module Date = Js_date - -/** Provide utilities for JS dictionary object */ -module Dict = Js_dict - -/** Provide bindings to JS global functions in global namespace*/ -module Global = Js_global - -/** Provide utilities for json */ -module Json = Js_json - -/** Provide bindings for JS `Math` object */ -module Math = Js_math - -/** Provide utilities for `Js.t` */ -module Obj = Js_obj - -/** Provide bindings for JS typed array */ -module Typed_array = Js_typed_array - -/** Provide bindings for JS typed array */ -module TypedArray2 = Js_typed_array2 - -/** Provide utilities for manipulating JS types */ -module Types = Js_types - -/** Provide utilities for JS float */ -module Float = Js_float - -/** Provide utilities for int */ -module Int = Js_int - -/** Provide utilities for bigint */ -module BigInt = Js_bigint - -/** Provide utilities for File */ -module File = Js_file - -/** Provide utilities for Blob */ -module Blob = Js_blob - -/** Provide utilities for option */ -module Option = Js_option - -/** Define the interface for result */ -module Result = Js_result - -/** Provides bindings for console */ -module Console = Js_console - -/** Provides bindings for ES6 Set */ -module Set = Js_set - -/** Provides bindings for ES6 WeakSet */ -module WeakSet = Js_weakset - -/** Provides bindings for ES6 Map */ -module Map = Js_map - -/** Provides bindings for ES6 WeakMap */ -module WeakMap = Js_weakmap diff --git a/jscomp/runtime/lazy.res b/jscomp/runtime/lazy.res new file mode 100644 index 0000000000..7cefd00f12 --- /dev/null +++ b/jscomp/runtime/lazy.res @@ -0,0 +1,17 @@ +// FIXME: +// This exists for compatibility reason. +// Move this into Pervasives or Core + +type t<'a> = lazy_t<'a> + +exception Undefined = Primitive_lazy.Undefined + +let force = Primitive_lazy.force + +let force_val = Primitive_lazy.force_val + +let from_fun = Primitive_lazy.from_fun + +let from_val = Primitive_lazy.from_val + +let is_val = Primitive_lazy.is_val diff --git a/jscomp/runtime/lazy.resi b/jscomp/runtime/lazy.resi new file mode 100644 index 0000000000..90e6a7e3bb --- /dev/null +++ b/jscomp/runtime/lazy.resi @@ -0,0 +1,41 @@ +type t<'a> = lazy_t<'a> + +exception Undefined + +/** [force x] forces the suspension [x] and returns its result. + If [x] has already been forced, [Lazy.force x] returns the + same value again without recomputing it. If it raised an exception, + the same exception is raised again. + Raise {!Undefined} if the forcing of [x] tries to force [x] itself + recursively. +*/ +let force: t<'a> => 'a + +/** [force_val x] forces the suspension [x] and returns its + result. If [x] has already been forced, [force_val x] + returns the same value again without recomputing it. + Raise {!Undefined} if the forcing of [x] tries to force [x] itself + recursively. + If the computation of [x] raises an exception, it is unspecified + whether [force_val x] raises the same exception or {!Undefined}. +*/ +let force_val: t<'a> => 'a + +/** [from_fun f] is the same as [lazy (f ())] but slightly more efficient. + + [from_fun] should only be used if the function [f] is already defined. + In particular it is always less efficient to write + [from_fun (fun () => expr)] than [lazy expr]. +*/ +let from_fun: (unit => 'a) => t<'a> + +/** [from_val v] returns an already-forced suspension of [v]. + This is for special purposes only and should not be confused with + [lazy (v)]. +*/ +let from_val: 'a => t<'a> + +/** [is_val x] returns [true] if [x] has already been forced and + did not raise an exception. +*/ +let is_val: t<'a> => bool diff --git a/jscomp/stdlib-406/list.res b/jscomp/runtime/list.res similarity index 96% rename from jscomp/stdlib-406/list.res rename to jscomp/runtime/list.res index 4aa190c89f..334b2f8937 100644 --- a/jscomp/stdlib-406/list.res +++ b/jscomp/runtime/list.res @@ -1,19 +1,10 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/* List operations */ +// FIXME: +// This exists for compatibility reason. +// Move this into Pervasives or Core + +// Below is all deprecated and should be removed in v13 + +type t<'a> = list<'a> let rec length_aux = (len, param) => switch param { diff --git a/jscomp/stdlib-406/list.resi b/jscomp/runtime/list.resi similarity index 77% rename from jscomp/stdlib-406/list.resi rename to jscomp/runtime/list.resi index 27e82bbdf8..1fdfd31f0c 100644 --- a/jscomp/stdlib-406/list.resi +++ b/jscomp/runtime/list.resi @@ -1,32 +1,14 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/*** List operations. - - Some functions are flagged as not tail-recursive. A tail-recursive - function uses constant stack space, while a non-tail-recursive function - uses stack space proportional to the length of its list argument, which - can be a problem with very long lists. When the function takes several - list arguments, an approximate formula giving stack usage (in some - unspecified constant unit) is shown in parentheses. - - The above considerations can usually be ignored if your lists are not - longer than about 10000 elements. -*/ +// FIXME: +// This exists for compatibility reason. +// Move this into Pervasives or Core + +// Below is all deprecated and should be removed in v13 + +@deprecated("Use Core instead. This will be removed in v13") +type t<'a> = list<'a> /** Return the length (number of elements) of the given list. */ +@deprecated("Use Core instead. This will be removed in v13") let length: list<'a> => int /** Compare the lengths of two lists. [compare_lengths l1 l2] is @@ -34,6 +16,7 @@ let length: list<'a> => int the computation stops after itering on the shortest list. @since 4.05.0 */ +@deprecated("Use Core instead. This will be removed in v13") let compare_lengths: (list<'a>, list<'b>) => int /** Compare the length of a list to an integer. [compare_length_with l n] is @@ -41,25 +24,30 @@ let compare_lengths: (list<'a>, list<'b>) => int the computation stops after at most [n] iterations on the list. @since 4.05.0 */ +@deprecated("Use Core instead. This will be removed in v13") let compare_length_with: (list<'a>, int) => int /** [cons x xs] is [x :: xs] @since 4.03.0 */ +@deprecated("Use Core instead. This will be removed in v13") let cons: ('a, list<'a>) => list<'a> /** Return the first element of the given list. Raise [Failure "hd"] if the list is empty. */ +@deprecated("Use Core instead. This will be removed in v13") let hd: list<'a> => 'a /** Return the given list without its first element. Raise [Failure "tl"] if the list is empty. */ +@deprecated("Use Core instead. This will be removed in v13") let tl: list<'a> => list<'a> /** Return the [n]-th element of the given list. The first element (head of the list) is at position 0. Raise [Failure "nth"] if the list is too short. Raise [Invalid_argument "List.nth"] if [n] is negative. */ +@deprecated("Use Core instead. This will be removed in v13") let nth: (list<'a>, int) => 'a /** Return the [n]-th element of the given list. @@ -68,9 +56,11 @@ let nth: (list<'a>, int) => 'a Raise [Invalid_argument "List.nth"] if [n] is negative. @since 4.05 */ +@deprecated("Use Core instead. This will be removed in v13") let nth_opt: (list<'a>, int) => option<'a> /** List reversal. */ +@deprecated("Use Core instead. This will be removed in v13") let rev: list<'a> => list<'a> /** [List.init len f] is [f 0; f 1; ...; f (len-1)], evaluated left to right. @@ -78,24 +68,29 @@ let rev: list<'a> => list<'a> @raise Invalid_argument if len < 0. @since 4.06.0 */ +@deprecated("Use Core instead. This will be removed in v13") let init: (int, int => 'a) => list<'a> /** Concatenate two lists. Same as the infix operator [@]. Not tail-recursive (length of the first argument). */ +@deprecated("Use Core instead. This will be removed in v13") let append: (list<'a>, list<'a>) => list<'a> /** [List.rev_append l1 l2] reverses [l1] and concatenates it to [l2]. This is equivalent to {!List.rev}[ l1 @ l2], but [rev_append] is tail-recursive and more efficient. */ +@deprecated("Use Core instead. This will be removed in v13") let rev_append: (list<'a>, list<'a>) => list<'a> /** Concatenate a list of lists. The elements of the argument are all concatenated together (in the same order) to give the result. Not tail-recursive (length of the argument + length of the longest sub-list). */ +@deprecated("Use Core instead. This will be removed in v13") let concat: list> => list<'a> /** An alias for [concat]. */ +@deprecated("Use Core instead. This will be removed in v13") let flatten: list> => list<'a> /* {1 Iterators} */ @@ -103,6 +98,7 @@ let flatten: list> => list<'a> /** [List.iter f [a1; ...; an]] applies function [f] in turn to [a1; ...; an]. It is equivalent to [begin f a1; f a2; ...; f an; () end]. */ +@deprecated("Use Core instead. This will be removed in v13") let iter: ('a => unit, list<'a>) => unit /** Same as {!List.iter}, but the function is applied to the index of @@ -110,11 +106,13 @@ let iter: ('a => unit, list<'a>) => unit itself as second argument. @since 4.00.0 */ +@deprecated("Use Core instead. This will be removed in v13") let iteri: ((int, 'a) => unit, list<'a>) => unit /** [List.map f [a1; ...; an]] applies function [f] to [a1, ..., an], and builds the list [[f a1; ...; f an]] with the results returned by [f]. Not tail-recursive. */ +@deprecated("Use Core instead. This will be removed in v13") let map: ('a => 'b, list<'a>) => list<'b> /** Same as {!List.map}, but the function is applied to the index of @@ -122,19 +120,23 @@ let map: ('a => 'b, list<'a>) => list<'b> itself as second argument. Not tail-recursive. @since 4.00.0 */ +@deprecated("Use Core instead. This will be removed in v13") let mapi: ((int, 'a) => 'b, list<'a>) => list<'b> /** [List.rev_map f l] gives the same result as {!List.rev}[ (]{!List.map}[ f l)], but is tail-recursive and more efficient. */ +@deprecated("Use Core instead. This will be removed in v13") let rev_map: ('a => 'b, list<'a>) => list<'b> /** [List.fold_left f a [b1; ...; bn]] is [f (... (f (f a b1) b2) ...) bn]. */ +@deprecated("Use Core instead. This will be removed in v13") let fold_left: (('a, 'b) => 'a, 'a, list<'b>) => 'a /** [List.fold_right f [a1; ...; an] b] is [f a1 (f a2 (... (f an b) ...))]. Not tail-recursive. */ +@deprecated("Use Core instead. This will be removed in v13") let fold_right: (('a, 'b) => 'b, list<'a>, 'b) => 'b /* {1 Iterators on two lists} */ @@ -143,29 +145,34 @@ let fold_right: (('a, 'b) => 'b, list<'a>, 'b) => 'b [f a1 b1; ...; f an bn]. Raise [Invalid_argument] if the two lists are determined to have different lengths. */ +@deprecated("Use Core instead. This will be removed in v13") let iter2: (('a, 'b) => unit, list<'a>, list<'b>) => unit /** [List.map2 f [a1; ...; an] [b1; ...; bn]] is [[f a1 b1; ...; f an bn]]. Raise [Invalid_argument] if the two lists are determined to have different lengths. Not tail-recursive. */ +@deprecated("Use Core instead. This will be removed in v13") let map2: (('a, 'b) => 'c, list<'a>, list<'b>) => list<'c> /** [List.rev_map2 f l1 l2] gives the same result as {!List.rev}[ (]{!List.map2}[ f l1 l2)], but is tail-recursive and more efficient. */ +@deprecated("Use Core instead. This will be removed in v13") let rev_map2: (('a, 'b) => 'c, list<'a>, list<'b>) => list<'c> /** [List.fold_left2 f a [b1; ...; bn] [c1; ...; cn]] is [f (... (f (f a b1 c1) b2 c2) ...) bn cn]. Raise [Invalid_argument] if the two lists are determined to have different lengths. */ +@deprecated("Use Core instead. This will be removed in v13") let fold_left2: (('a, 'b, 'c) => 'a, 'a, list<'b>, list<'c>) => 'a /** [List.fold_right2 f [a1; ...; an] [b1; ...; bn] c] is [f a1 b1 (f a2 b2 (... (f an bn c) ...))]. Raise [Invalid_argument] if the two lists are determined to have different lengths. Not tail-recursive. */ +@deprecated("Use Core instead. This will be removed in v13") let fold_right2: (('a, 'b, 'c) => 'c, list<'a>, list<'b>, 'c) => 'c /* {1 List scanning} */ @@ -173,29 +180,35 @@ let fold_right2: (('a, 'b, 'c) => 'c, list<'a>, list<'b>, 'c) => 'c /** [for_all p [a1; ...; an]] checks if all elements of the list satisfy the predicate [p]. That is, it returns [(p a1) && (p a2) && ... && (p an)]. */ +@deprecated("Use Core instead. This will be removed in v13") let for_all: ('a => bool, list<'a>) => bool /** [exists p [a1; ...; an]] checks if at least one element of the list satisfies the predicate [p]. That is, it returns [(p a1) || (p a2) || ... || (p an)]. */ +@deprecated("Use Core instead. This will be removed in v13") let exists: ('a => bool, list<'a>) => bool /** Same as {!List.for_all}, but for a two-argument predicate. Raise [Invalid_argument] if the two lists are determined to have different lengths. */ +@deprecated("Use Core instead. This will be removed in v13") let for_all2: (('a, 'b) => bool, list<'a>, list<'b>) => bool /** Same as {!List.exists}, but for a two-argument predicate. Raise [Invalid_argument] if the two lists are determined to have different lengths. */ +@deprecated("Use Core instead. This will be removed in v13") let exists2: (('a, 'b) => bool, list<'a>, list<'b>) => bool /** [mem a l] is true if and only if [a] is equal to an element of [l]. */ +@deprecated("Use Core instead. This will be removed in v13") let mem: ('a, list<'a>) => bool /** Same as {!List.mem}, but uses physical equality instead of structural equality to compare list elements. */ +@deprecated("Use Core instead. This will be removed in v13") let memq: ('a, list<'a>) => bool /* {1 List searching} */ @@ -204,17 +217,20 @@ let memq: ('a, list<'a>) => bool that satisfies the predicate [p]. Raise [Not_found] if there is no value that satisfies [p] in the list [l]. */ +@deprecated("Use Core instead. This will be removed in v13") let find: ('a => bool, list<'a>) => 'a /** [find_opt p l] returns the first element of the list [l] that satisfies the predicate [p], or [None] if there is no value that satisfies [p] in the list [l]. @since 4.05 */ +@deprecated("Use Core instead. This will be removed in v13") let find_opt: ('a => bool, list<'a>) => option<'a> /** [filter p l] returns all the elements of the list [l] that satisfy the predicate [p]. The order of the elements in the input list is preserved. */ +@deprecated("Use Core instead. This will be removed in v13") let filter: ('a => bool, list<'a>) => list<'a> /** [find_all] is another name for {!List.filter}. */ @@ -225,6 +241,7 @@ let find_all: ('a => bool, list<'a>) => list<'a> satisfy the predicate [p], and [l2] is the list of all the elements of [l] that do not satisfy [p]. The order of the elements in the input list is preserved. */ +@deprecated("Use Core instead. This will be removed in v13") let partition: ('a => bool, list<'a>) => (list<'a>, list<'a>) /* {1 Association lists} */ @@ -235,6 +252,7 @@ let partition: ('a => bool, list<'a>) => (list<'a>, list<'a>) if [(a,b)] is the leftmost binding of [a] in list [l]. Raise [Not_found] if there is no value associated with [a] in the list [l]. */ +@deprecated("Use Core instead. This will be removed in v13") let assoc: ('a, list<('a, 'b)>) => 'b /** [assoc_opt a l] returns the value associated with key [a] in the list of @@ -244,32 +262,39 @@ let assoc: ('a, list<('a, 'b)>) => 'b Returns [None] if there is no value associated with [a] in the list [l]. @since 4.05 */ +@deprecated("Use Core instead. This will be removed in v13") let assoc_opt: ('a, list<('a, 'b)>) => option<'b> /** Same as {!List.assoc}, but uses physical equality instead of structural equality to compare keys. */ +@deprecated("Use Core instead. This will be removed in v13") let assq: ('a, list<('a, 'b)>) => 'b /** Same as {!List.assoc_opt}, but uses physical equality instead of structural equality to compare keys. @since 4.05 */ +@deprecated("Use Core instead. This will be removed in v13") let assq_opt: ('a, list<('a, 'b)>) => option<'b> /** Same as {!List.assoc}, but simply return true if a binding exists, and false if no bindings exist for the given key. */ +@deprecated("Use Core instead. This will be removed in v13") let mem_assoc: ('a, list<('a, 'b)>) => bool /** Same as {!List.mem_assoc}, but uses physical equality instead of structural equality to compare keys. */ +@deprecated("Use Core instead. This will be removed in v13") let mem_assq: ('a, list<('a, 'b)>) => bool /** [remove_assoc a l] returns the list of pairs [l] without the first pair with key [a], if any. Not tail-recursive. */ +@deprecated("Use Core instead. This will be removed in v13") let remove_assoc: ('a, list<('a, 'b)>) => list<('a, 'b)> /** Same as {!List.remove_assoc}, but uses physical equality instead of structural equality to compare keys. Not tail-recursive. */ +@deprecated("Use Core instead. This will be removed in v13") let remove_assq: ('a, list<('a, 'b)>) => list<('a, 'b)> /* {1 Lists of pairs} */ @@ -278,6 +303,7 @@ let remove_assq: ('a, list<('a, 'b)>) => list<('a, 'b)> [split [(a1,b1); ...; (an,bn)]] is [([a1; ...; an], [b1; ...; bn])]. Not tail-recursive. */ +@deprecated("Use Core instead. This will be removed in v13") let split: list<('a, 'b)> => (list<'a>, list<'b>) /** Transform a pair of lists into a list of pairs: @@ -285,6 +311,7 @@ let split: list<('a, 'b)> => (list<'a>, list<'b>) [[(a1,b1); ...; (an,bn)]]. Raise [Invalid_argument] if the two lists have different lengths. Not tail-recursive. */ +@deprecated("Use Core instead. This will be removed in v13") let combine: (list<'a>, list<'b>) => list<('a, 'b)> /* {1 Sorting} */ @@ -303,6 +330,7 @@ let combine: (list<'a>, list<'b>) => list<('a, 'b)> The current implementation uses Merge Sort. It runs in constant heap space and logarithmic stack space. */ +@deprecated("Use Core instead. This will be removed in v13") let sort: (('a, 'a) => int, list<'a>) => list<'a> /** Same as {!List.sort}, but the sorting algorithm is guaranteed to @@ -312,14 +340,17 @@ let sort: (('a, 'a) => int, list<'a>) => list<'a> The current implementation uses Merge Sort. It runs in constant heap space and logarithmic stack space. */ +@deprecated("Use Core instead. This will be removed in v13") let stable_sort: (('a, 'a) => int, list<'a>) => list<'a> /** Same as {!List.sort} or {!List.stable_sort}, whichever is faster on typical input. */ +@deprecated("Use Core instead. This will be removed in v13") let fast_sort: (('a, 'a) => int, list<'a>) => list<'a> /** Same as {!List.sort}, but also remove duplicates. @since 4.02.0 */ +@deprecated("Use Core instead. This will be removed in v13") let sort_uniq: (('a, 'a) => int, list<'a>) => list<'a> /** Merge two lists: @@ -330,4 +361,5 @@ let sort_uniq: (('a, 'a) => int, list<'a>) => list<'a> before the elements of [l2]. Not tail-recursive (sum of the lengths of the arguments). */ +@deprecated("Use Core instead. This will be removed in v13") let merge: (('a, 'a) => int, list<'a>, list<'a>) => list<'a> diff --git a/jscomp/runtime/map.res b/jscomp/runtime/map.res new file mode 100644 index 0000000000..b547fe31de --- /dev/null +++ b/jscomp/runtime/map.res @@ -0,0 +1,4 @@ +// FIXME: +// This exists for compatibility reason. +// Move this into Pervasives or Core + diff --git a/jscomp/runtime/obj.res b/jscomp/runtime/obj.res new file mode 100644 index 0000000000..d794096fad --- /dev/null +++ b/jscomp/runtime/obj.res @@ -0,0 +1,31 @@ +// FIXME: +// This exists for compatibility reason. +// Move this into Pervasives or Core + +type t = Primitive_object_extern.t + +let magic = Primitive_object_extern.magic + +@deprecated("Do not use directly. This will be removed in v13") +let repr = Primitive_object_extern.repr + +@deprecated("Do not use directly. This will be removed in v13") +let obj = Primitive_object_extern.obj + +@deprecated("Do not use directly. This will be removed in v13") +let tag = Primitive_object_extern.tag + +@deprecated("Do not use directly. This will be removed in v13") +let size = Primitive_object_extern.size + +@deprecated("Do not use directly. This will be removed in v13") +let field = Primitive_object_extern.getField + +@deprecated("Do not use directly. This will be removed in v13") +let set_field = Primitive_object_extern.setField + +@deprecated("Do not use directly. This will be removed in v13") +let dup = Primitive_object_extern.dup + +@deprecated("Do not use directly. This will be removed in v13") +let update_dummy = Primitive_object_extern.updateDummy diff --git a/jscomp/runtime/pervasives.res b/jscomp/runtime/pervasives.res new file mode 100644 index 0000000000..603d2d811a --- /dev/null +++ b/jscomp/runtime/pervasives.res @@ -0,0 +1,318 @@ +/** + Since [others] depend on this file, its public mli files **should not + export types** introduced here, otherwise it would cause + conflicts here. + + If the type exported here is also exported in modules from others, + you will get a type not equivalent. +*/ +module Pervasives = { + /* Internal */ + @deprecated("Do not use. This will be removed in v13") + external __unsafe_cast: 'a => 'b = "%identity" + + /* Exceptions */ + + external raise: exn => 'a = "%raise" + + @deprecated("Use custom exception instead") + let failwith = s => raise(Failure(s)) + + @deprecated("Use custom exception instead") + let invalid_arg = s => raise(Invalid_argument(s)) + + @deprecated("Use custom exception instead") exception Exit + + /* Composition operators */ + + external \"|>": ('a, 'a => 'b) => 'b = "%revapply" + external \"@@": ('a => 'b, 'a) => 'b = "%apply" + + /* Debugging */ + + external __LOC__: string = "%loc_LOC" + external __FILE__: string = "%loc_FILE" + external __LINE__: int = "%loc_LINE" + external __MODULE__: string = "%loc_MODULE" + external __POS__: (string, int, int, int) = "%loc_POS" + + external __LOC_OF__: 'a => (string, 'a) = "%loc_LOC" + external __LINE_OF__: 'a => (int, 'a) = "%loc_LINE" + external __POS_OF__: 'a => ((string, int, int, int), 'a) = "%loc_POS" + + /* Comparisons */ + + external \"=": ('a, 'a) => bool = "%equal" + external \"<>": ('a, 'a) => bool = "%notequal" + external \"<": ('a, 'a) => bool = "%lessthan" + external \">": ('a, 'a) => bool = "%greaterthan" + external \"<=": ('a, 'a) => bool = "%lessequal" + external \">=": ('a, 'a) => bool = "%greaterequal" + external compare: ('a, 'a) => int = "%compare" + external min: ('a, 'a) => 'a = "%min" + external max: ('a, 'a) => 'a = "%max" + external \"==": ('a, 'a) => bool = "%eq" + external \"!=": ('a, 'a) => bool = "%noteq" + + /* Boolean operations */ + + external not: bool => bool = "%boolnot" + + external \"&&": (bool, bool) => bool = "%sequand" + + external \"||": (bool, bool) => bool = "%sequor" + + /* Integer operations */ + + external \"~-": int => int = "%negint" + external \"~+": int => int = "%identity" + external succ: int => int = "%succint" + external pred: int => int = "%predint" + external \"+": (int, int) => int = "%addint" + external \"-": (int, int) => int = "%subint" + external \"*": (int, int) => int = "%mulint" + external \"/": (int, int) => int = "%divint" + external mod: (int, int) => int = "%modint" + + @deprecated("Use Core instead. This will be removed in v13") + let abs = x => + if x >= 0 { + x + } else { + -x + } + + external land: (int, int) => int = "%andint" + external lor: (int, int) => int = "%orint" + external lxor: (int, int) => int = "%xorint" + + let lnot = x => lxor(x, -1) + + external lsl: (int, int) => int = "%lslint" + external lsr: (int, int) => int = "%lsrint" + external asr: (int, int) => int = "%asrint" + + @deprecated("Use Core instead. This will be removed in v13") + let max_int = lsr(-1, 1) + + @deprecated("Use Core instead. This will be removed in v13") + let min_int = + max_int + 1 + + /* Floating-point operations */ + + external \"~-.": float => float = "%negfloat" + external \"~+.": float => float = "%identity" + external \"+.": (float, float) => float = "%addfloat" + external \"-.": (float, float) => float = "%subfloat" + external \"*.": (float, float) => float = "%mulfloat" + external \"/.": (float, float) => float = "%divfloat" + + @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") + external \"**": (float, float) => float = "pow" + + @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") + external exp: float => float = "exp" + + @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") + external acos: float => float = "acos" + + @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") + external asin: float => float = "asin" + + @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") + external atan: float => float = "atan" + + @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") + external atan2: (float, float) => float = "atan2" + + @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") + external cos: float => float = "cos" + + @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") + external cosh: float => float = "cosh" + + @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") + external log: float => float = "log" + + @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") + external log10: float => float = "log10" + + @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") + external log1p: float => float = "log1p" + + @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") + external sin: float => float = "sin" + + @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") + external sinh: float => float = "sinh" + + @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") + external sqrt: float => float = "sqrt" + + @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") + external tan: float => float = "tan" + + @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") + external tanh: float => float = "tanh" + + @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") + external ceil: float => float = "ceil" + + @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") + external floor: float => float = "floor" + + @deprecated("Use Core instead. This will be removed in v13") @val @scope("Math") + external abs_float: float => float = "abs" + + @deprecated("Use Core instead. This will be removed in v13") + external mod_float: float => float = "%modfloat" + + @deprecated("Use Core instead. This will be removed in v13") + external float: int => float = "%floatofint" + + @deprecated("Use Core instead. This will be removed in v13") + external float_of_int: int => float = "%floatofint" + + @deprecated("Use Core instead. This will be removed in v13") + external truncate: float => int = "%intoffloat" + + @deprecated("Use Core instead. This will be removed in v13") + external int_of_float: float => int = "%intoffloat" + + @deprecated("Use Core instead. This will be removed in v13") + let infinity = 0x1p2047 + + @deprecated("Use Core instead. This will be removed in v13") + let neg_infinity = -0x1p2047 + + @deprecated("Use Core instead. This will be removed in v13") @val @scope("Number") + external nan: float = "NaN" + + @deprecated("Use Core instead. This will be removed in v13") + let max_float = 1.79769313486231571e+308 /* 0x1.ffff_ffff_ffff_fp+1023 */ + + @deprecated("Use Core instead. This will be removed in v13") + let min_float = 2.22507385850720138e-308 /* 0x1p-1022 */ + + @deprecated("Use Core instead. This will be removed in v13") + let epsilon_float = 2.22044604925031308e-16 /* 0x1p-52 */ + + @deprecated("Do not use. This will be removed in v13") + type fpclass = + | FP_normal + | FP_subnormal + | FP_zero + | FP_infinite + | FP_nan + + @deprecated("Do not use. This will be removed in v13") + let classify_float = (x: float): fpclass => + if (%raw(`isFinite`): _ => _)(x) { + if abs_float(x) >= /* 0x1p-1022 */ /* 2.22507385850720138e-308 */ min_float { + FP_normal + } else if x != 0. { + FP_subnormal + } else { + FP_zero + } + } else if (%raw(`isNaN`): _ => _)(x) { + FP_nan + } else { + FP_infinite + } + + /* String and byte sequence operations -- more in modules String and Bytes */ + + external \"^": (string, string) => string = "%string_concat" + + /* Character operations -- more in module Char */ + + @deprecated("Use Core instead. This will be removed in v13") + external int_of_char: char => int = "%identity" + + @deprecated("Use Core instead. This will be removed in v13") + external unsafe_char_of_int: int => char = "%identity" + + @deprecated("Use Core instead. This will be removed in v13") + let char_of_int = n => + if n < 0 || n > 255 { + invalid_arg("char_of_int") + } else { + unsafe_char_of_int(n) + } + + /* Unit operations */ + + external ignore: 'a => unit = "%ignore" + + /* Pair operations */ + + external fst: (('a, 'b)) => 'a = "%field0" + external snd: (('a, 'b)) => 'b = "%field1" + + /* References */ + + type ref<'a> = {mutable contents: 'a} + external ref: 'a => ref<'a> = "%makeref" + external \"!": ref<'a> => 'a = "%refget" + external \":=": (ref<'a>, 'a) => unit = "%refset" + external incr: ref => unit = "%incr" + external decr: ref => unit = "%decr" + + /* String conversion functions */ + + @deprecated("Use Core instead. This will be removed in v13") + let string_of_bool = b => + if b { + "true" + } else { + "false" + } + + @deprecated("Use Core instead. This will be removed in v13") + let bool_of_string = param => + switch param { + | "true" => true + | "false" => false + | _ => invalid_arg("bool_of_string") + } + + @deprecated("Use Core instead. This will be removed in v13") + let bool_of_string_opt = param => + switch param { + | "true" => Some(true) + | "false" => Some(false) + | _ => None + } + + @deprecated("Use Core instead. This will be removed in v13") + external string_of_int: int => string = "String" + + @deprecated("Use Core instead. This will be removed in v13") @scope("Number") + external int_of_string: string => int = "parseInt" + + let int_of_string_opt = s => + switch int_of_string(s) { + | n if n == %raw("NaN") => None + | n => Some(n) + } + + @deprecated("Use Core instead. This will be removed in v13") + external string_get: (string, int) => char = "%string_safe_get" + + /* List operations -- more in module List */ + + @deprecated("Use Core instead. This will be removed in v13") + let rec \"@" = (l1, l2) => + switch l1 { + | list{} => l2 + | list{hd, ...tl} => list{hd, ...\"@"(tl, l2)} + } + + /* Miscellaneous */ + + type int32 = int +} + +include Pervasives diff --git a/jscomp/runtime/primitive_array.res b/jscomp/runtime/primitive_array.res new file mode 100644 index 0000000000..b521bd1e4c --- /dev/null +++ b/jscomp/runtime/primitive_array.res @@ -0,0 +1,15 @@ +let length = Primitive_array_extern.length + +let get = (xs, index) => + if index < 0 || index >= length(xs) { + raise(Invalid_argument("index out of bounds")) + } else { + xs->Primitive_array_extern.getUnsafe(index) + } + +let set = (xs, index, newval) => + if index < 0 || index >= length(xs) { + raise(Invalid_argument("index out of bounds")) + } else { + xs->Primitive_array_extern.setUnsafe(index, newval) + } diff --git a/jscomp/runtime/primitive_array_extern.res b/jscomp/runtime/primitive_array_extern.res new file mode 100644 index 0000000000..67ab859918 --- /dev/null +++ b/jscomp/runtime/primitive_array_extern.res @@ -0,0 +1,6 @@ +external length: array<'a> => int = "%array_length" +external getUnsafe: (array<'a>, int) => 'a = "%array_unsafe_get" +external setUnsafe: (array<'a>, int, 'a) => unit = "%array_unsafe_set" + +@send external slice: (array<'a>, int, int) => array<'a> = "slice" +@send external concat: (array<'a>, array<'a>) => array<'a> = "concat" diff --git a/jscomp/runtime/primitive_bigint.res b/jscomp/runtime/primitive_bigint.res new file mode 100644 index 0000000000..cb576a9357 --- /dev/null +++ b/jscomp/runtime/primitive_bigint.res @@ -0,0 +1,40 @@ +let compare = (x: bigint, y: bigint): int => + if x < y { + -1 + } else if x == y { + 0 + } else { + 1 + } + +let min = (x: bigint, y: bigint): bigint => + if x < y { + x + } else { + y + } + +let max = (x: bigint, y: bigint): bigint => + if x > y { + x + } else { + y + } + +external div: (bigint, bigint) => bigint = "%divbigint" + +let div = (x: bigint, y: bigint) => + if y == 0n { + raise(Division_by_zero) + } else { + div(x, y) + } + +external mod_: (bigint, bigint) => bigint = "%modbigint" + +let mod_ = (x: bigint, y: bigint) => + if y == 0n { + raise(Division_by_zero) + } else { + mod_(x, y) + } diff --git a/jscomp/runtime/primitive_bool.res b/jscomp/runtime/primitive_bool.res new file mode 100644 index 0000000000..9a0b51a8a2 --- /dev/null +++ b/jscomp/runtime/primitive_bool.res @@ -0,0 +1,20 @@ +let compare = (x: bool, y: bool): int => + switch (x, y) { + | (true, true) | (false, false) => 0 + | (true, false) => 1 + | (false, true) => -1 + } + +let min = (x: bool, y: bool): bool => + if x { + y + } else { + x + } + +let max = (x: bool, y: bool): bool => + if x { + x + } else { + y + } diff --git a/jscomp/runtime/primitive_char_extern.res b/jscomp/runtime/primitive_char_extern.res new file mode 100644 index 0000000000..d78e84ba2f --- /dev/null +++ b/jscomp/runtime/primitive_char_extern.res @@ -0,0 +1,2 @@ +external code: char => int = "%identity" +external unsafe_chr: int => char = "%identity" diff --git a/jscomp/runtime/primitive_curry.res b/jscomp/runtime/primitive_curry.res new file mode 100644 index 0000000000..2f1dfc7e51 --- /dev/null +++ b/jscomp/runtime/primitive_curry.res @@ -0,0 +1,355 @@ +/* Copyright (C) 2015 - Hongbo Zhang, Authors of ReScript + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * In addition to the permissions granted to you by the LGPL, you may combine + * or link a "work that uses the Library" with a publicly distributed version + * of this file to produce a combined library or application, then distribute + * that combined work under the terms of your choosing, with no requirement + * to comply with the obligations normally placed on you by section 4 of the + * LGPL version 3 (or the corresponding section of a later version of the LGPL + * should you choose to use a later version). + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +module Array = Primitive_array_extern +module Obj = Primitive_object_extern +module Js = Primitive_js_extern + +@@uncurried + +external function_arity: 'a => int = "%function_arity" + +@send external apply_args: ('a => 'b, Js.null<_>, array<_>) => 'b = "apply" +let apply_args = (f, args) => apply_args(f, Js.null, args) + +/* Public */ +let rec app = (f, args) => { + let init_arity = function_arity(f) + let arity = if init_arity == 0 { + 1 + } else { + init_arity + } /* arity fixing */ + let len = Array.length(args) + let d = arity - len + if d == 0 { + apply_args(f, args) /* f.apply (null,args) */ + } else if d < 0 { + /* TODO: could avoid copy by tracking the index */ + app(Obj.magic(apply_args(f, Array.slice(args, 0, arity))), Array.slice(args, arity, len)) + } else { + Obj.magic(x => app(f, Array.concat(args, [x]))) + } +} + +external apply1: ('a0 => 'a1, 'a0) => 'a1 = "%curry_apply1" +external apply2: (('a0, 'a1) => 'a2, 'a0, 'a1) => 'a2 = "%curry_apply2" +external apply3: (('a0, 'a1, 'a2) => 'a3, 'a0, 'a1, 'a2) => 'a3 = "%curry_apply3" +external apply4: (('a0, 'a1, 'a2, 'a3) => 'a4, 'a0, 'a1, 'a2, 'a3) => 'a4 = "%curry_apply4" +external apply5: (('a0, 'a1, 'a2, 'a3, 'a4) => 'a5, 'a0, 'a1, 'a2, 'a3, 'a4) => 'a5 = + "%curry_apply5" +external apply6: (('a0, 'a1, 'a2, 'a3, 'a4, 'a5) => 'a6, 'a0, 'a1, 'a2, 'a3, 'a4, 'a5) => 'a6 = + "%curry_apply6" +external apply7: ( + ('a0, 'a1, 'a2, 'a3, 'a4, 'a5, 'a6) => 'a7, + 'a0, + 'a1, + 'a2, + 'a3, + 'a4, + 'a5, + 'a6, +) => 'a7 = "%curry_apply7" +external apply8: ( + ('a0, 'a1, 'a2, 'a3, 'a4, 'a5, 'a6, 'a7) => 'a8, + 'a0, + 'a1, + 'a2, + 'a3, + 'a4, + 'a5, + 'a6, + 'a7, +) => 'a8 = "%curry_apply8" + +let curry_1 = (o, a0, arity) => + switch arity { + | 1 => apply1(Obj.magic(o), a0) + | 2 => param => apply2(Obj.magic(o), a0, param) + | 3 => Obj.magic((param, \"param$1") => apply3(Obj.magic(o), a0, param, \"param$1")) + | 4 => + Obj.magic((param, \"param$1", \"param$2") => + apply4(Obj.magic(o), a0, param, \"param$1", \"param$2") + ) + | 5 => + Obj.magic((param, \"param$1", \"param$2", \"param$3") => + apply5(Obj.magic(o), a0, param, \"param$1", \"param$2", \"param$3") + ) + | 6 => + Obj.magic((param, \"param$1", \"param$2", \"param$3", \"param$4") => + apply6(Obj.magic(o), a0, param, \"param$1", \"param$2", \"param$3", \"param$4") + ) + | 7 => + Obj.magic((param, \"param$1", \"param$2", \"param$3", \"param$4", \"param$5") => + apply7(Obj.magic(o), a0, param, \"param$1", \"param$2", \"param$3", \"param$4", \"param$5") + ) + | _ => Obj.magic(app(o, [a0])) + } + +let _1 = (o, a0) => { + let arity = function_arity(o) + if arity == 1 { + apply1(o, a0) + } else { + curry_1(o, a0, arity) + } +} + +let __1 = o => { + let arity = function_arity(o) + if arity == 1 { + o + } else { + a0 => _1(o, a0) + } +} + +let curry_2 = (o, a0, a1, arity) => + switch arity { + | 1 => app(apply1(Obj.magic(o), a0), [a1]) + | 2 => apply2(Obj.magic(o), a0, a1) + | 3 => param => apply3(Obj.magic(o), a0, a1, param) + | 4 => Obj.magic((param, \"param$1") => apply4(Obj.magic(o), a0, a1, param, \"param$1")) + | 5 => + Obj.magic((param, \"param$1", \"param$2") => + apply5(Obj.magic(o), a0, a1, param, \"param$1", \"param$2") + ) + | 6 => + Obj.magic((param, \"param$1", \"param$2", \"param$3") => + apply6(Obj.magic(o), a0, a1, param, \"param$1", \"param$2", \"param$3") + ) + | 7 => + Obj.magic((param, \"param$1", \"param$2", \"param$3", \"param$4") => + apply7(Obj.magic(o), a0, a1, param, \"param$1", \"param$2", \"param$3", \"param$4") + ) + | _ => Obj.magic(app(o, [a0, a1])) + } + +let _2 = (o, a0, a1) => { + let arity = function_arity(o) + if arity == 2 { + apply2(o, a0, a1) + } else { + curry_2(Obj.magic(o), a0, a1, arity) + } +} + +let __2 = o => { + let arity = function_arity(o) + if arity == 2 { + o + } else { + (a0, a1) => _2(o, a0, a1) + } +} + +let curry_3 = (o, a0, a1, a2, arity) => + switch arity { + | 1 => app(apply1(Obj.magic(o), a0), [a1, a2]) + | 2 => app(apply2(Obj.magic(o), a0, a1), [a2]) + | 3 => apply3(Obj.magic(o), a0, a1, a2) + | 4 => param => apply4(Obj.magic(o), a0, a1, a2, param) + | 5 => Obj.magic((param, \"param$1") => apply5(Obj.magic(o), a0, a1, a2, param, \"param$1")) + | 6 => + Obj.magic((param, \"param$1", \"param$2") => + apply6(Obj.magic(o), a0, a1, a2, param, \"param$1", \"param$2") + ) + | 7 => + Obj.magic((param, \"param$1", \"param$2", \"param$3") => + apply7(Obj.magic(o), a0, a1, a2, param, \"param$1", \"param$2", \"param$3") + ) + | _ => Obj.magic(app(o, [a0, a1, a2])) + } + +let _3 = (o, a0, a1, a2) => { + let arity = function_arity(o) + if arity == 3 { + apply3(o, a0, a1, a2) + } else { + curry_3(Obj.magic(o), a0, a1, a2, arity) + } +} + +let __3 = o => { + let arity = function_arity(o) + if arity == 3 { + o + } else { + (a0, a1, a2) => _3(o, a0, a1, a2) + } +} + +let curry_4 = (o, a0, a1, a2, a3, arity) => + switch arity { + | 1 => app(apply1(Obj.magic(o), a0), [a1, a2, a3]) + | 2 => app(apply2(Obj.magic(o), a0, a1), [a2, a3]) + | 3 => app(apply3(Obj.magic(o), a0, a1, a2), [a3]) + | 4 => apply4(Obj.magic(o), a0, a1, a2, a3) + | 5 => param => apply5(Obj.magic(o), a0, a1, a2, a3, param) + | 6 => Obj.magic((param, \"param$1") => apply6(Obj.magic(o), a0, a1, a2, a3, param, \"param$1")) + | 7 => + Obj.magic((param, \"param$1", \"param$2") => + apply7(Obj.magic(o), a0, a1, a2, a3, param, \"param$1", \"param$2") + ) + | _ => Obj.magic(app(o, [a0, a1, a2, a3])) + } + +let _4 = (o, a0, a1, a2, a3) => { + let arity = function_arity(o) + if arity == 4 { + apply4(o, a0, a1, a2, a3) + } else { + curry_4(Obj.magic(o), a0, a1, a2, a3, arity) + } +} + +let __4 = o => { + let arity = function_arity(o) + if arity == 4 { + o + } else { + (a0, a1, a2, a3) => _4(o, a0, a1, a2, a3) + } +} + +let curry_5 = (o, a0, a1, a2, a3, a4, arity) => + switch arity { + | 1 => app(apply1(Obj.magic(o), a0), [a1, a2, a3, a4]) + | 2 => app(apply2(Obj.magic(o), a0, a1), [a2, a3, a4]) + | 3 => app(apply3(Obj.magic(o), a0, a1, a2), [a3, a4]) + | 4 => app(apply4(Obj.magic(o), a0, a1, a2, a3), [a4]) + | 5 => apply5(Obj.magic(o), a0, a1, a2, a3, a4) + | 6 => param => apply6(Obj.magic(o), a0, a1, a2, a3, a4, param) + | 7 => + Obj.magic((param, \"param$1") => apply7(Obj.magic(o), a0, a1, a2, a3, a4, param, \"param$1")) + | _ => Obj.magic(app(o, [a0, a1, a2, a3, a4])) + } + +let _5 = (o, a0, a1, a2, a3, a4) => { + let arity = function_arity(o) + if arity == 5 { + apply5(o, a0, a1, a2, a3, a4) + } else { + curry_5(Obj.magic(o), a0, a1, a2, a3, a4, arity) + } +} + +let __5 = o => { + let arity = function_arity(o) + if arity == 5 { + o + } else { + (a0, a1, a2, a3, a4) => _5(o, a0, a1, a2, a3, a4) + } +} + +let curry_6 = (o, a0, a1, a2, a3, a4, a5, arity) => + switch arity { + | 1 => app(apply1(Obj.magic(o), a0), [a1, a2, a3, a4, a5]) + | 2 => app(apply2(Obj.magic(o), a0, a1), [a2, a3, a4, a5]) + | 3 => app(apply3(Obj.magic(o), a0, a1, a2), [a3, a4, a5]) + | 4 => app(apply4(Obj.magic(o), a0, a1, a2, a3), [a4, a5]) + | 5 => app(apply5(Obj.magic(o), a0, a1, a2, a3, a4), [a5]) + | 6 => apply6(Obj.magic(o), a0, a1, a2, a3, a4, a5) + | 7 => param => apply7(Obj.magic(o), a0, a1, a2, a3, a4, a5, param) + | _ => Obj.magic(app(o, [a0, a1, a2, a3, a4, a5])) + } + +let _6 = (o, a0, a1, a2, a3, a4, a5) => { + let arity = function_arity(o) + if arity == 6 { + apply6(o, a0, a1, a2, a3, a4, a5) + } else { + curry_6(Obj.magic(o), a0, a1, a2, a3, a4, a5, arity) + } +} + +let __6 = o => { + let arity = function_arity(o) + if arity == 6 { + o + } else { + (a0, a1, a2, a3, a4, a5) => _6(o, a0, a1, a2, a3, a4, a5) + } +} + +let curry_7 = (o, a0, a1, a2, a3, a4, a5, a6, arity) => + switch arity { + | 1 => app(apply1(Obj.magic(o), a0), [a1, a2, a3, a4, a5, a6]) + | 2 => app(apply2(Obj.magic(o), a0, a1), [a2, a3, a4, a5, a6]) + | 3 => app(apply3(Obj.magic(o), a0, a1, a2), [a3, a4, a5, a6]) + | 4 => app(apply4(Obj.magic(o), a0, a1, a2, a3), [a4, a5, a6]) + | 5 => app(apply5(Obj.magic(o), a0, a1, a2, a3, a4), [a5, a6]) + | 6 => app(apply6(Obj.magic(o), a0, a1, a2, a3, a4, a5), [a6]) + | 7 => apply7(Obj.magic(o), a0, a1, a2, a3, a4, a5, a6) + | _ => Obj.magic(app(o, [a0, a1, a2, a3, a4, a5, a6])) + } + +let _7 = (o, a0, a1, a2, a3, a4, a5, a6) => { + let arity = function_arity(o) + if arity == 7 { + apply7(o, a0, a1, a2, a3, a4, a5, a6) + } else { + curry_7(Obj.magic(o), a0, a1, a2, a3, a4, a5, a6, arity) + } +} + +let __7 = o => { + let arity = function_arity(o) + if arity == 7 { + o + } else { + (a0, a1, a2, a3, a4, a5, a6) => _7(o, a0, a1, a2, a3, a4, a5, a6) + } +} + +let curry_8 = (o, a0, a1, a2, a3, a4, a5, a6, a7, arity) => + switch arity { + | 1 => app(apply1(Obj.magic(o), a0), [a1, a2, a3, a4, a5, a6, a7]) + | 2 => app(apply2(Obj.magic(o), a0, a1), [a2, a3, a4, a5, a6, a7]) + | 3 => app(apply3(Obj.magic(o), a0, a1, a2), [a3, a4, a5, a6, a7]) + | 4 => app(apply4(Obj.magic(o), a0, a1, a2, a3), [a4, a5, a6, a7]) + | 5 => app(apply5(Obj.magic(o), a0, a1, a2, a3, a4), [a5, a6, a7]) + | 6 => app(apply6(Obj.magic(o), a0, a1, a2, a3, a4, a5), [a6, a7]) + | 7 => app(apply7(Obj.magic(o), a0, a1, a2, a3, a4, a5, a6), [a7]) + | _ => Obj.magic(app(o, [a0, a1, a2, a3, a4, a5, a6, a7])) + } + +let _8 = (o, a0, a1, a2, a3, a4, a5, a6, a7) => { + let arity = function_arity(o) + if arity == 8 { + apply8(o, a0, a1, a2, a3, a4, a5, a6, a7) + } else { + curry_8(Obj.magic(o), a0, a1, a2, a3, a4, a5, a6, a7, arity) + } +} + +let __8 = o => { + let arity = function_arity(o) + if arity == 8 { + o + } else { + (a0, a1, a2, a3, a4, a5, a6, a7) => _8(o, a0, a1, a2, a3, a4, a5, a6, a7) + } +} diff --git a/jscomp/runtime/primitive_curry.resi b/jscomp/runtime/primitive_curry.resi new file mode 100644 index 0000000000..753d6bb398 --- /dev/null +++ b/jscomp/runtime/primitive_curry.resi @@ -0,0 +1,32 @@ +// let _1: ('a => 'b => 'c, 'a) => 'b => 'c +let __1: ('a => 'b => 'c) => 'a => 'b => 'c + +// let _2: (('a, 'a) => 'b => 'c, 'a, 'a) => 'b => 'c +let __2: (('a, 'a) => 'b => 'c) => ('a, 'a) => 'b => 'c + +// let _3: (('a, 'a, 'a) => 'b => 'c, 'a, 'a, 'a) => 'b => 'c +let __3: (('a, 'a, 'a) => 'b => 'c) => ('a, 'a, 'a) => 'b => 'c + +// let _4: (('a, 'a, 'a, 'a) => 'b => 'c, 'a, 'a, 'a, 'a) => 'b => 'c +let __4: (('a, 'a, 'a, 'a) => 'b => 'c) => ('a, 'a, 'a, 'a) => 'b => 'c + +// let _5: (('a, 'a, 'a, 'a, 'a) => 'b => 'c, 'a, 'a, 'a, 'a, 'a) => 'b => 'c +let __5: (('a, 'a, 'a, 'a, 'a) => 'b => 'c) => ('a, 'a, 'a, 'a, 'a) => 'b => 'c + +// let _6: (('a, 'a, 'a, 'a, 'a, 'a) => 'b => 'c, 'a, 'a, 'a, 'a, 'a, 'a) => 'b => 'c +let __6: (('a, 'a, 'a, 'a, 'a, 'a) => 'b => 'c) => ('a, 'a, 'a, 'a, 'a, 'a) => 'b => 'c + +// let _7: (('a, 'a, 'a, 'a, 'a, 'a, 'a) => 'b => 'c, 'a, 'a, 'a, 'a, 'a, 'a, 'a) => 'b => 'c +let __7: (('a, 'a, 'a, 'a, 'a, 'a, 'a) => 'b => 'c) => ('a, 'a, 'a, 'a, 'a, 'a, 'a) => 'b => 'c + +// let _8: (('a, 'a, 'a, 'a, 'a, 'a, 'a, 'a) => 'b => 'c, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a) => 'b => 'c +let __8: (('a, 'a, 'a, 'a, 'a, 'a, 'a, 'a) => 'b => 'c) => ( + 'a, + 'a, + 'a, + 'a, + 'a, + 'a, + 'a, + 'a, +) => 'b => 'c diff --git a/jscomp/runtime/primitive_dict.res b/jscomp/runtime/primitive_dict.res new file mode 100644 index 0000000000..6b9ee3f66a --- /dev/null +++ b/jscomp/runtime/primitive_dict.res @@ -0,0 +1,2 @@ +// Note: this is exposed to support syntax +external make: array<(string, 'a)> => dict<'a> = "%makedict" diff --git a/jscomp/runtime/caml_exceptions.res b/jscomp/runtime/primitive_exceptions.res similarity index 88% rename from jscomp/runtime/caml_exceptions.res rename to jscomp/runtime/primitive_exceptions.res index 0ca8fee7af..dae327dff3 100644 --- a/jscomp/runtime/caml_exceptions.res +++ b/jscomp/runtime/primitive_exceptions.res @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. +/* Copyright (C) 2015- Hongbo Zhang, Authors of ReScript * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -22,41 +22,13 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -type t = {@as("RE_EXN_ID") id: string} - -module Dict = { - @obj - external empty: unit => dict<'a> = "" - - @set_index - external set: (dict<'a>, string, 'a) => unit = "" - - @get_index - /** - It's the same as `Js.Dict.get` but it doesn't have runtime overhead to check if the key exists. - */ - external dangerouslyGetNonOption: (dict<'a>, string) => option<'a> = "" -} +module Obj = Primitive_object_extern +module Js = Primitive_js_extern -/** - Needs to have unique extension ids when used with functors. - See discussion in https://github.com/rescript-lang/rescript-compiler/pull/6570 -*/ -let idMap = Dict.empty() +type t = {@as("RE_EXN_ID") id: string} -let create = (str: string): string => { - switch idMap->Dict.dangerouslyGetNonOption(str) { - | Some(v) => { - let id = v + 1 - idMap->Dict.set(str, id) - str ++ ("/" ++ (Obj.magic((id: int)): string)) - } - | None => { - idMap->Dict.set(str, 1) - str - } - } -} +exception Error = JsError +type js_error = {cause: exn} /** This function should never throw @@ -89,12 +61,54 @@ let create = (str: string): string => { This is not a problem in `try .. with` since the logic above is not expressible, see more design in [destruct_exn.md] */ -let is_extension = (type a, e: a): bool => +let isExtension = (type a, e: a): bool => if Js.testAny(e) { false } else { Js.typeof((Obj.magic(e): t).id) == "string" } -/** FIXME: remove the trailing `/` */ -let exn_slot_name = (x: t): string => x.id +/** + This function has to be in this module Since + [Error] is defined here +*/ +let internalToException = (e: unknown) => + if isExtension(e) { + (Obj.magic(e): exn) + } else { + JsError(e) + } + +module Dict = { + @obj + external empty: unit => dict<'a> = "" + + @set_index + external set: (dict<'a>, string, 'a) => unit = "" + + @get_index + /** + It's the same as `Js.Dict.get` but it doesn't have runtime overhead to check if the key exists. + */ + external dangerouslyGetNonOption: (dict<'a>, string) => option<'a> = "" +} + +/** + Needs to have unique extension ids when used with functors. + See discussion in https://github.com/rescript-lang/rescript-compiler/pull/6570 +*/ +let idMap = Dict.empty() + +let create = (str: string): string => { + switch idMap->Dict.dangerouslyGetNonOption(str) { + | Some(v) => { + let id = v + 1 + idMap->Dict.set(str, id) + str ++ ("/" ++ (Obj.magic((id: int)): string)) + } + | None => { + idMap->Dict.set(str, 1) + str + } + } +} diff --git a/jscomp/runtime/primitive_exceptions.resi b/jscomp/runtime/primitive_exceptions.resi new file mode 100644 index 0000000000..9662bedfcf --- /dev/null +++ b/jscomp/runtime/primitive_exceptions.resi @@ -0,0 +1,7 @@ +exception Error = JsError +type js_error = {cause: exn} + +// TODO: remove legacy exn representation +type t = {@as("RE_EXN_ID") id: string} +let create: string => string +let internalToException: unknown => exn diff --git a/jscomp/runtime/primitive_float.res b/jscomp/runtime/primitive_float.res new file mode 100644 index 0000000000..088cc3e7aa --- /dev/null +++ b/jscomp/runtime/primitive_float.res @@ -0,0 +1,28 @@ +let compare = (x: float, y: float): int => + if x == y { + 0 + } else if x < y { + -1 + } else if x > y { + 1 + } else if x == x { + 1 + } else if y == y { + -1 + } else { + 0 + } + +let min = (x: float, y: float): float => + if x < y { + x + } else { + y + } + +let max = (x: float, y: float): float => + if x > y { + x + } else { + y + } diff --git a/jscomp/runtime/primitive_float_extern.res b/jscomp/runtime/primitive_float_extern.res new file mode 100644 index 0000000000..3a153d488a --- /dev/null +++ b/jscomp/runtime/primitive_float_extern.res @@ -0,0 +1 @@ +external toInt: float => int = "%intoffloat" diff --git a/jscomp/runtime/caml_hash.res b/jscomp/runtime/primitive_hash.res similarity index 69% rename from jscomp/runtime/caml_hash.res rename to jscomp/runtime/primitive_hash.res index ae675337a3..e195f2c947 100644 --- a/jscomp/runtime/caml_hash.res +++ b/jscomp/runtime/primitive_hash.res @@ -21,7 +21,14 @@ * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -@@config({flags: ["-bs-noassertfalse"]}) + +module Float = Primitive_float_extern +module Obj = Primitive_object_extern +module Js = Primitive_js_extern +module String = Primitive_string_extern + +@send external charCodeAt: (string, int) => int = "charCodeAt" + type rec cell<'a> = { content: 'a, mutable next: option>, @@ -74,12 +81,62 @@ let unsafe_pop = (q: t<'a>) => cell.content } -let {hash_mix_int, hash_final_mix, hash_mix_string} = module(Caml_hash_primitive) +let rotl32 = (x: int, n) => lor(lsl(x, n), lsr(x, 32 - n)) + +let hash_mix_int = (h, d) => { + let d = ref(d) + d.contents = d.contents * 0xcc9e2d51 + d.contents = rotl32(d.contents, 15) + d.contents = d.contents * 0x1b873593 + let h = ref(lxor(h, d.contents)) + h.contents = rotl32(h.contents, 13) + h.contents + lsl(h.contents, 2) + 0xe6546b64 +} + +let hash_final_mix = h => { + let h = ref(lxor(h, lsr(h, 16))) + h.contents = h.contents * 0x85ebca6b + h.contents = lxor(h.contents, lsr(h.contents, 13)) + h.contents = h.contents * 0xc2b2ae35 + lxor(h.contents, lsr(h.contents, 16)) +} + +let hash_mix_string = (h, s) => { + let len = String.length(s) + let block = len / 4 - 1 + let hash = ref(h) + for i in 0 to block { + let j = 4 * i + let w = lor( + lor(lor(s->charCodeAt(j), lsl(s->charCodeAt(j + 1), 8)), lsl(s->charCodeAt(j + 2), 16)), + lsl(s->charCodeAt(j + 3), 24), + ) + + hash.contents = hash_mix_int(hash.contents, w) + } + let modulo = land(len, 0b11) + if modulo != 0 { + let w = if modulo == 3 { + lor( + lor(lsl(s->charCodeAt(len - 1), 16), lsl(s->charCodeAt(len - 2), 8)), + s->charCodeAt(len - 3), + ) + } else if modulo == 2 { + lor(lsl(s->charCodeAt(len - 1), 8), s->charCodeAt(len - 2)) + } else { + s->charCodeAt(len - 1) + } + + hash.contents = hash_mix_int(hash.contents, w) + } + hash.contents = lxor(hash.contents, len) + hash.contents +} let hash = (count: int, _limit, seed: int, obj: Obj.t): int => { let s = ref(seed) if Js.typeof(obj) == "number" { - let u = Caml_nativeint_extern.of_float(Obj.magic(obj)) + let u = Float.toInt(Obj.magic(obj)) s.contents = hash_mix_int(s.contents, u + u + 1) hash_final_mix(s.contents) } else if Js.typeof(obj) == "string" { @@ -98,7 +155,7 @@ let hash = (count: int, _limit, seed: int, obj: Obj.t): int => { while !is_empty_queue(queue) && num.contents > 0 { let obj = unsafe_pop(queue) if Js.typeof(obj) == "number" { - let u = Caml_nativeint_extern.of_float(Obj.magic(obj)) + let u = Float.toInt(Obj.magic(obj)) s.contents = hash_mix_int(s.contents, u + u + 1) num.contents = num.contents - 1 } else if Js.typeof(obj) == "string" { @@ -118,7 +175,7 @@ let hash = (count: int, _limit, seed: int, obj: Obj.t): int => { let obj_tag = Obj.tag(obj) let tag = lor(lsl(size, 10), obj_tag) if obj_tag == 248 /* Obj.object_tag */ { - s.contents = hash_mix_int(s.contents, (Obj.obj(Obj.field(obj, 1)): int)) + s.contents = hash_mix_int(s.contents, (Obj.obj(Obj.getField(obj, 1)): int)) } else { s.contents = hash_mix_int(s.contents, tag) let block = { @@ -130,7 +187,7 @@ let hash = (count: int, _limit, seed: int, obj: Obj.t): int => { } } for i in 0 to block { - push_back(queue, Obj.field(obj, i)) + push_back(queue, Obj.getField(obj, i)) } } } else { diff --git a/jscomp/runtime/caml_hash_primitive.resi b/jscomp/runtime/primitive_hash.resi similarity index 96% rename from jscomp/runtime/caml_hash_primitive.resi rename to jscomp/runtime/primitive_hash.resi index 7066bf46f2..b2b66c3f01 100644 --- a/jscomp/runtime/caml_hash_primitive.resi +++ b/jscomp/runtime/primitive_hash.resi @@ -25,3 +25,4 @@ let hash_mix_int: (int, int) => int let hash_mix_string: (int, string) => int let hash_final_mix: int => int +let hash: (int, 'a, int, Primitive_object.t) => int diff --git a/jscomp/runtime/primitive_int.res b/jscomp/runtime/primitive_int.res new file mode 100644 index 0000000000..25afa896ee --- /dev/null +++ b/jscomp/runtime/primitive_int.res @@ -0,0 +1,36 @@ +let compare = (x: int, y: int): int => + if x < y { + -1 + } else if x == y { + 0 + } else { + 1 + } + +let min = (x: int, y: int): int => + if x < y { + x + } else { + y + } + +let max = (x: int, y: int): int => + if x > y { + x + } else { + y + } + +let div = (x: int, y: int) => + if y == 0 { + raise(Division_by_zero) + } else { + Primitive_int_extern.div(x, y) + } + +let mod_ = (x: int, y: int) => + if y == 0 { + raise(Division_by_zero) + } else { + Primitive_int_extern.mod_(x, y) + } diff --git a/jscomp/runtime/primitive_int_extern.res b/jscomp/runtime/primitive_int_extern.res new file mode 100644 index 0000000000..438e1b8e40 --- /dev/null +++ b/jscomp/runtime/primitive_int_extern.res @@ -0,0 +1,3 @@ +external div: (int, int) => int = "%divint" + +external mod_: (int, int) => int = "%modint" diff --git a/jscomp/runtime/primitive_js_extern.res b/jscomp/runtime/primitive_js_extern.res new file mode 100644 index 0000000000..2b9ea278b5 --- /dev/null +++ b/jscomp/runtime/primitive_js_extern.res @@ -0,0 +1,32 @@ +@unboxed +type null<+'a> = Value('a) | @as(null) Null + +type undefined<+'a> + +@unboxed type nullable<+'a> = Value('a) | @as(null) Null | @as(undefined) Undefined + +type null_undefined<+'a> = nullable<'a> + +external null: null<'a> = "%null" + +external undefined: undefined<'a> = "%undefined" + +external isNullable: nullable<'a> => bool = "%is_nullable" + +external testAny: 'a => bool = "%is_nullable" + +external typeof: 'a => string = "%typeof" + +external eqNull: ('a, null<'a>) => bool = "%equal_null" + +external eqUndefined: ('a, undefined<'a>) => bool = "%equal_undefined" + +external eqNullable: ('a, nullable<'a>) => bool = "%equal_nullable" + +external lt: ('a, 'a) => bool = "%unsafe_lt" + +external le: ('a, 'a) => bool = "%unsafe_le" + +external gt: ('a, 'a) => bool = "%unsafe_gt" + +external ge: ('a, 'a) => bool = "%unsafe_ge" diff --git a/jscomp/stdlib-406/camlinternalLazy.res b/jscomp/runtime/primitive_lazy.res similarity index 87% rename from jscomp/stdlib-406/camlinternalLazy.res rename to jscomp/runtime/primitive_lazy.res index f93ce9058a..9fb7a4f643 100644 --- a/jscomp/stdlib-406/camlinternalLazy.res +++ b/jscomp/runtime/primitive_lazy.res @@ -32,8 +32,8 @@ type t<'a> = { /* its type is ['a] or [unit -> 'a ] */ } -%%private(external fnToVal: ((. unit) => 'a) => 'a = "%identity") -%%private(external valToFn: 'a => (. unit) => 'a = "%identity") +%%private(external fnToVal: (unit => 'a) => 'a = "%identity") +%%private(external valToFn: 'a => unit => 'a = "%identity") %%private(external castToConcrete: lazy_t<'a> => t<'a> = "%identity") %%private(external castFromConcrete: t<'a> => lazy_t<'a> = "%identity") @@ -42,15 +42,15 @@ let is_val = (type a, l: lazy_t): bool => castToConcrete(l).tag exception Undefined %%private( - let forward_with_closure = (type a, blk: t, closure: (. unit) => a): a => { - let result = closure(.) + let forward_with_closure = (type a, blk: t, closure: unit => a): a => { + let result = closure() blk.value = result blk.tag = true result } ) -%%private(let raise_undefined = (. ()) => raise(Undefined)) +%%private(let raise_undefined = () => raise(Undefined)) /* Assume [blk] is a block with tag lazy */ %%private( @@ -59,7 +59,7 @@ exception Undefined blk.value = fnToVal(raise_undefined) try forward_with_closure(blk, closure) catch { | e => - blk.value = fnToVal((. ()) => raise(e)) + blk.value = fnToVal(() => raise(e)) raise(e) } } @@ -92,7 +92,7 @@ let force_val = (type a, lzv: lazy_t): a => { } } -let from_fun = (type a, closure: (. unit) => a): lazy_t => { +let from_fun = (type a, closure: unit => a): lazy_t => { let blk = { tag: false, value: fnToVal(closure), @@ -103,7 +103,7 @@ let from_fun = (type a, closure: (. unit) => a): lazy_t => { let from_val = (type a, value: a): lazy_t => { let blk = { tag: true, - value: value, + value, } castFromConcrete(blk) } diff --git a/jscomp/runtime/primitive_lazy.resi b/jscomp/runtime/primitive_lazy.resi new file mode 100644 index 0000000000..bfcd2fa211 --- /dev/null +++ b/jscomp/runtime/primitive_lazy.resi @@ -0,0 +1,39 @@ +exception Undefined + +/** [force x] forces the suspension [x] and returns its result. + If [x] has already been forced, [Lazy.force x] returns the + same value again without recomputing it. If it raised an exception, + the same exception is raised again. + Raise {!Undefined} if the forcing of [x] tries to force [x] itself + recursively. +*/ +let force: lazy_t<'a> => 'a + +/** [force_val x] forces the suspension [x] and returns its + result. If [x] has already been forced, [force_val x] + returns the same value again without recomputing it. + Raise {!Undefined} if the forcing of [x] tries to force [x] itself + recursively. + If the computation of [x] raises an exception, it is unspecified + whether [force_val x] raises the same exception or {!Undefined}. +*/ +let force_val: lazy_t<'a> => 'a + +/** [from_fun f] is the same as [lazy (f ())] but slightly more efficient. + + [from_fun] should only be used if the function [f] is already defined. + In particular it is always less efficient to write + [from_fun (fun () => expr)] than [lazy expr]. +*/ +let from_fun: (unit => 'a) => lazy_t<'a> + +/** [from_val v] returns an already-forced suspension of [v]. + This is for special purposes only and should not be confused with + [lazy (v)]. +*/ +let from_val: 'a => lazy_t<'a> + +/** [is_val x] returns [true] if [x] has already been forced and + did not raise an exception. +*/ +let is_val: lazy_t<'a> => bool diff --git a/jscomp/runtime/primitive_module.res b/jscomp/runtime/primitive_module.res new file mode 100644 index 0000000000..c71f1c6ab8 --- /dev/null +++ b/jscomp/runtime/primitive_module.res @@ -0,0 +1,70 @@ +module Array = Primitive_array_extern +module Obj = Primitive_object_extern + +external import: 'a => promise<'a> = "%import" + +@@warning("-37") /* `Function` may be used in runtime */ + +type rec shape = + | Function + | Lazy + | Class + | Module(array<(shape, string)>) + | Value(Obj.t) + +module type Empty = {} + +/** Note that we have to provide a drop in replacement, since compiler internally will + spit out ("CamlinternalMod".[init_mod|update_mod] unless we intercept it + in the lambda layer +*/ +let init = (loc: (string, int, int), shape: shape) => { + let undef_module = _ => raise(Undefined_recursive_module(loc)) + let rec loop = (shape: shape, struct_: Obj.t, idx) => + switch shape { + | Function => Obj.setField(struct_, idx, Obj.magic(undef_module)) + | Lazy => Obj.setField(struct_, idx, Obj.magic(undef_module)) + | Class => Obj.setField(struct_, idx, Obj.magic((undef_module, undef_module, undef_module, 0))) + | Module(comps) => + let v = Obj.repr(module({}: Empty)) + Obj.setField(struct_, idx, v) + let len = Array.length(comps) + for i in 0 to len - 1 { + let (shape, name) = Array.getUnsafe(comps, i) + loop(shape, v, name) + } + | Value(v) => Obj.setField(struct_, idx, v) + } + let res = Obj.repr(module({}: Empty)) + let dummy_name = "dummy" + loop(shape, res, dummy_name) + Obj.getField(res, dummy_name) +} + +/* Note the [shape] passed between [init_mod] and [update_mod] is always the same + and we assume [module] is encoded as an array +*/ +let update = (shape: shape, o: Obj.t, n: Obj.t): unit => { + let rec aux = (shape: shape, o, n, parent, i) => + switch shape { + | Function => Obj.setField(parent, i, n) + + | Lazy + | Class => + Obj.updateDummy(o, n) + | Module(comps) => + for i in 0 to Array.length(comps) - 1 { + let (shape, name) = Array.getUnsafe(comps, i) + aux(shape, Obj.getField(o, name), Obj.getField(n, name), o, name) + } + | Value(_) => () + } + switch shape { + | Module(comps) => + for i in 0 to Array.length(comps) - 1 { + let (shape, name) = Array.getUnsafe(comps, i) + aux(shape, Obj.getField(o, name), Obj.getField(n, name), o, name) + } + | _ => assert(false) + } +} diff --git a/jscomp/runtime/primitive_module.resi b/jscomp/runtime/primitive_module.resi new file mode 100644 index 0000000000..8ccc47557e --- /dev/null +++ b/jscomp/runtime/primitive_module.resi @@ -0,0 +1,7 @@ +external import: 'a => promise<'a> = "%import" + +type shape + +let init: ((string, int, int), shape) => Primitive_object.t + +let update: (shape, Primitive_object.t, Primitive_object.t) => unit diff --git a/jscomp/runtime/caml_obj.res b/jscomp/runtime/primitive_object.res similarity index 69% rename from jscomp/runtime/caml_obj.res rename to jscomp/runtime/primitive_object.res index f26a251a2a..3324543da4 100644 --- a/jscomp/runtime/caml_obj.res +++ b/jscomp/runtime/primitive_object.res @@ -22,12 +22,21 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -type t = Obj.t +module Array = Primitive_array_extern +module Js = Primitive_js_extern + +type t = Primitive_object_extern.t + +let repr = Primitive_object_extern.repr +let magic = Primitive_object_extern.magic +let tag = Primitive_object_extern.tag +let field = Primitive_object_extern.getField +let size = Primitive_object_extern.size module O = { @val external isArray: 'a => bool = "Array.isArray" type key = string - let for_in: (Obj.t, key => unit) => unit = %raw(`function(o,foo){ + let for_in: (t, key => unit) => unit = %raw(`function(o,foo){ for (var x in o) { foo(x) }} `) @@ -42,33 +51,10 @@ module O = { */ external hasOwnProperty: (t, key) => bool = "call" - @get_index external get_value: (Obj.t, key) => Obj.t = "" + @get_index external get_value: (t, key) => t = "" } -/** - For the empty dummy object, whether it's - [[]] or [{}] depends on how - runtime encoding works, and will affect - js polymorphic comparison(Js.(=)) (fine with caml polymoprhic comparison (Pervasives.equal)) - In most cases, rec value comes from record/modules, - whose tag is 0, we optimize that case -*/ -let update_dummy: (_, _) => unit = %raw(`function(x,y){ - var k - if(Array.isArray(y)){ - for(k = 0; k < y.length ; ++k){ - x[k] = y[k] - } - if(y.TAG !== undefined){ - x.TAG = y.TAG - } - } else { - for (var k in y){ - x[k] = y[k] - } - } -} -`) +let updateDummy = Primitive_object_extern.updateDummy /** TODO: investigate total [compare x y] returns [0] if [x] is equal to [y], @@ -87,7 +73,7 @@ let update_dummy: (_, _) => unit = %raw(`function(x,y){ The compare function can be used as the comparison function required by the [Set.Make] and [Map.Make] functors, as well as the [List.sort] and [Array.sort] functions. */ -let rec compare = (a: Obj.t, b: Obj.t): int => +let rec compare = (a: t, b: t): int => if a === b { 0 } else { @@ -100,11 +86,11 @@ let rec compare = (a: Obj.t, b: Obj.t): int => /* [a] is of type string, b can not be None, [a] could be (Some (Some x)) in that case [b] could be [Some None] or [null] so [b] has to be of type string or null */ - | ("string", "string") => Pervasives.compare((Obj.magic(a): string), Obj.magic(b)) + | ("string", "string") => Pervasives.compare((magic(a): string), magic(b)) | ("string", _) => /* [b] could be [Some None] or [null] */ 1 | (_, "string") => -1 - | ("boolean", "boolean") => Pervasives.compare((Obj.magic(a): bool), Obj.magic(b)) + | ("boolean", "boolean") => Pervasives.compare((magic(a): bool), magic(b)) | ("boolean", _) => 1 | (_, "boolean") => -1 | ("function", "function") => raise(Invalid_argument("compare: functional value")) @@ -112,30 +98,30 @@ let rec compare = (a: Obj.t, b: Obj.t): int => | (_, "function") => -1 | ("bigint", "bigint") | ("number", "number") => - Pervasives.compare((Obj.magic(a): float), (Obj.magic(b): float)) + Pervasives.compare((magic(a): float), (magic(b): float)) | ("number", _) => - if b === Obj.repr(Js.null) || Caml_option.isNested(b) { + if b === repr(Js.null) || Primitive_option.isNested(b) { 1 } else { /* Some (Some ..) < x */ -1 } /* Integer < Block in OCaml runtime GPR #1195, except Some.. */ | (_, "number") => - if a === Obj.repr(Js.null) || Caml_option.isNested(a) { + if a === repr(Js.null) || Primitive_option.isNested(a) { -1 } else { 1 } | _ => - if a === Obj.repr(Js.null) { + if a === repr(Js.null) { /* [b] could not be null otherwise would equal */ - if Caml_option.isNested(b) { + if Primitive_option.isNested(b) { 1 } else { -1 } - } else if b === Obj.repr(Js.null) { - if Caml_option.isNested(a) { + } else if b === repr(Js.null) { + if Primitive_option.isNested(a) { -1 } else { 1 @@ -143,22 +129,22 @@ let rec compare = (a: Obj.t, b: Obj.t): int => } else if ( /* double_array_tag: 254 */ - Caml_option.isNested(a) + Primitive_option.isNested(a) ) { - if Caml_option.isNested(b) { + if Primitive_option.isNested(b) { aux_obj_compare(a, b) } else { - /* Some None < Some (Some None)) */ + /* Some (None) < Some (Some (None)) */ /* b could not be undefined/None */ - /* Some None < Some .. */ + /* Some (None) < Some (...) */ -1 } } else { - let tag_a = Obj.tag(a) - let tag_b = Obj.tag(b) + let tag_a = tag(a) + let tag_b = tag(b) if tag_a == 248 /* object/exception */ { - Pervasives.compare((Obj.magic(Obj.field(a, 1)): int), Obj.magic(Obj.field(b, 1))) + Pervasives.compare((magic(field(a, 1)): int), magic(field(b, 1))) } else if tag_a == 251 /* abstract_tag */ { raise(Invalid_argument("equal: abstract value")) } else if tag_a != tag_b { @@ -168,11 +154,11 @@ let rec compare = (a: Obj.t, b: Obj.t): int => 1 } } else { - let len_a = Obj.size(a) - let len_b = Obj.size(b) + let len_a = size(a) + let len_b = size(b) if len_a == len_b { if O.isArray(a) { - aux_same_length((Obj.magic(a): array), (Obj.magic(b): array), 0, len_a) + aux_same_length((magic(a): array), (magic(b): array), 0, len_a) } else if %raw(`a instanceof Date && b instanceof Date`) { %raw(`a - b`) } else { @@ -180,20 +166,20 @@ let rec compare = (a: Obj.t, b: Obj.t): int => } } else if len_a < len_b { /* at least one is not zero, so it is an array block */ - aux_length_a_short((Obj.magic(a): array), (Obj.magic(b): array), 0, len_a) + aux_length_a_short((magic(a): array), (magic(b): array), 0, len_a) } else { - aux_length_b_short((Obj.magic(a): array), (Obj.magic(b): array), 0, len_b) + aux_length_b_short((magic(a): array), (magic(b): array), 0, len_b) } } } } } -and aux_same_length = (a: array, b: array, i, same_length) => +and aux_same_length = (a: array, b: array, i, same_length) => if i == same_length { 0 } else { - let res = compare(Caml_array_extern.unsafe_get(a, i), Caml_array_extern.unsafe_get(b, i)) + let res = compare(Array.getUnsafe(a, i), Array.getUnsafe(b, i)) if res != 0 { res @@ -202,11 +188,11 @@ and aux_same_length = (a: array, b: array, i, same_length) => } } -and aux_length_a_short = (a: array, b: array, i, short_length) => +and aux_length_a_short = (a: array, b: array, i, short_length) => if i == short_length { -1 } else { - let res = compare(Caml_array_extern.unsafe_get(a, i), Caml_array_extern.unsafe_get(b, i)) + let res = compare(Array.getUnsafe(a, i), Array.getUnsafe(b, i)) if res != 0 { res @@ -215,11 +201,11 @@ and aux_length_a_short = (a: array, b: array, i, short_length) => } } -and aux_length_b_short = (a: array, b: array, i, short_length) => +and aux_length_b_short = (a: array, b: array, i, short_length) => if i == short_length { 1 } else { - let res = compare(Caml_array_extern.unsafe_get(a, i), Caml_array_extern.unsafe_get(b, i)) + let res = compare(Array.getUnsafe(a, i), Array.getUnsafe(b, i)) if res != 0 { res @@ -228,7 +214,7 @@ and aux_length_b_short = (a: array, b: array, i, short_length) => } } -and aux_obj_compare = (a: Obj.t, b: Obj.t) => { +and aux_obj_compare = (a: t, b: t) => { let min_key_lhs = ref(None) let min_key_rhs = ref(None) let do_key = ((a, b, min_key), key) => @@ -256,12 +242,12 @@ and aux_obj_compare = (a: Obj.t, b: Obj.t) => { res } -type eq = (Obj.t, Obj.t) => bool +type eq = (t, t) => bool /** It is easier to do equality check than comparision, since as long as its basic type is not the same, it will not equal */ -let rec equal = (a: Obj.t, b: Obj.t): bool => +let rec equal = (a: t, b: t): bool => /* front and formoest, we do not compare function values */ if a === b { true @@ -287,22 +273,22 @@ let rec equal = (a: Obj.t, b: Obj.t): bool => false } else { /* [a] [b] could not be null, so it can not raise */ - let tag_a = Obj.tag(a) - let tag_b = Obj.tag(b) + let tag_a = tag(a) + let tag_b = tag(b) if tag_a == 248 /* object/exception */ { - Obj.magic(Obj.field(a, 1)) === Obj.magic(Obj.field(b, 1)) + magic(field(a, 1)) === magic(field(b, 1)) } else if tag_a == 251 /* abstract_tag */ { raise(Invalid_argument("equal: abstract value")) } else if tag_a != tag_b { false } else { - let len_a = Obj.size(a) - let len_b = Obj.size(b) + let len_a = size(a) + let len_b = size(b) if len_a == len_b { if O.isArray(a) { - aux_equal_length((Obj.magic(a): array), (Obj.magic(b): array), 0, len_a) + aux_equal_length((magic(a): array), (magic(b): array), 0, len_a) } else if %raw(`a instanceof Date && b instanceof Date`) { - !(Js.unsafe_gt(a, b) || Js.unsafe_lt(a, b)) + !(Js.gt(a, b) || Js.lt(a, b)) } else { aux_obj_equal(a, b) } @@ -314,15 +300,15 @@ let rec equal = (a: Obj.t, b: Obj.t): bool => } } -and aux_equal_length = (a: array, b: array, i, same_length) => +and aux_equal_length = (a: array, b: array, i, same_length) => if i == same_length { true } else { - equal(Caml_array_extern.unsafe_get(a, i), Caml_array_extern.unsafe_get(b, i)) && + equal(Array.getUnsafe(a, i), Array.getUnsafe(b, i)) && aux_equal_length(a, b, i + 1, same_length) } -and aux_obj_equal = (a: Obj.t, b: Obj.t) => { +and aux_obj_equal = (a: t, b: t) => { let result = ref(true) let do_key_a = key => if !O.hasOwnProperty(b, key) { @@ -341,24 +327,6 @@ and aux_obj_equal = (a: Obj.t, b: Obj.t) => { result.contents } -let equal_null = (x: Obj.t, y: Js.null) => - switch Js.nullToOption(y) { - | None => x === Obj.magic(y) - | Some(y) => equal(x, y) - } - -let equal_undefined = (x: Obj.t, y: Js.undefined) => - switch Js.undefinedToOption(y) { - | None => x === Obj.magic(y) - | Some(y) => equal(x, y) - } - -let equal_nullable = (x: Obj.t, y: Js.nullable) => - switch Js.toOption(y) { - | None => x === Obj.magic(y) - | Some(y) => equal(x, y) - } - @inline let isNumberOrBigInt = a => Js.typeof(a) == "number" || Js.typeof(a) == "bigint" @@ -367,47 +335,47 @@ let canNumericCompare = (a, b) => isNumberOrBigInt(a) && isNumberOrBigInt(b) let notequal = (a, b) => if canNumericCompare(a, b) { - (Obj.magic(a): float) != (Obj.magic(b): float) + (magic(a): float) != (magic(b): float) } else { !equal(a, b) } let greaterequal = (a, b) => if canNumericCompare(a, b) { - (Obj.magic(a): float) >= (Obj.magic(b): float) + (magic(a): float) >= (magic(b): float) } else { compare(a, b) >= 0 } let greaterthan = (a, b) => if canNumericCompare(a, b) { - (Obj.magic(a): float) > (Obj.magic(b): float) + (magic(a): float) > (magic(b): float) } else { compare(a, b) > 0 } let lessequal = (a, b) => if canNumericCompare(a, b) { - (Obj.magic(a): float) <= (Obj.magic(b): float) + (magic(a): float) <= (magic(b): float) } else { compare(a, b) <= 0 } let lessthan = (a, b) => if canNumericCompare(a, b) { - (Obj.magic(a): float) < (Obj.magic(b): float) + (magic(a): float) < (magic(b): float) } else { compare(a, b) < 0 } -let min = (x: Obj.t, y) => +let min = (x: t, y) => if compare(x, y) <= 0 { x } else { y } -let max = (x: Obj.t, y) => +let max = (x: t, y) => if compare(x, y) >= 0 { x } else { diff --git a/jscomp/runtime/caml_obj.resi b/jscomp/runtime/primitive_object.resi similarity index 83% rename from jscomp/runtime/caml_obj.resi rename to jscomp/runtime/primitive_object.resi index 7694d3791e..a7f4ea8d53 100644 --- a/jscomp/runtime/caml_obj.resi +++ b/jscomp/runtime/primitive_object.resi @@ -22,20 +22,14 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -type t = Obj.t +type t = Primitive_object_extern.t -let update_dummy: (Obj.t, Obj.t) => unit +let updateDummy: (t, t) => unit -let compare: (Obj.t, Obj.t) => int - -type eq = (Obj.t, Obj.t) => bool +let compare: (t, t) => int +type eq = (t, t) => bool let equal: eq - -let equal_null: (Obj.t, Js.null) => bool -let equal_undefined: (Obj.t, Js.undefined) => bool -let equal_nullable: (Obj.t, Js.nullable) => bool - let notequal: eq let greaterequal: eq let greaterthan: eq diff --git a/jscomp/runtime/primitive_object_extern.res b/jscomp/runtime/primitive_object_extern.res new file mode 100644 index 0000000000..de0a8c2395 --- /dev/null +++ b/jscomp/runtime/primitive_object_extern.res @@ -0,0 +1,14 @@ +type t + +external repr: 'a => t = "%identity" +external obj: t => 'a = "%identity" +external magic: 'a => 'b = "%identity" + +external tag: t => int = "%obj_tag" +external size: t => int = "%obj_size" +external getField: (t, 'a) => t = "%obj_get_field" +external setField: (t, 'a, t) => unit = "%obj_set_field" +external dup: t => t = "%obj_dup" + +@scope("Object") +external updateDummy: (t, t) => unit = "assign" diff --git a/jscomp/runtime/caml_option.res b/jscomp/runtime/primitive_option.res similarity index 84% rename from jscomp/runtime/caml_option.res rename to jscomp/runtime/primitive_option.res index 346205611f..4850d7638b 100644 --- a/jscomp/runtime/caml_option.res +++ b/jscomp/runtime/primitive_option.res @@ -22,10 +22,15 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +module Obj = Primitive_object_extern +module Js = Primitive_js_extern + type nested = {@as("BS_PRIVATE_NESTED_SOME_NONE") depth: int} /* INPUT: [x] should not be nullable */ -let isNested = (x: Obj.t): bool => Obj.repr((Obj.magic(x): nested).depth) !== Obj.repr(Js.undefined) +let isNested = (x: Obj.t): bool => { + Obj.repr((Obj.magic(x): nested).depth) !== Obj.repr(Js.undefined) +} let some = (x: Obj.t): Obj.t => if Obj.magic(x) == None { @@ -37,21 +42,21 @@ let some = (x: Obj.t): Obj.t => x } -let nullable_to_opt = (type t, x: Js.nullable): option => +let fromNullable = (type t, x: Js.nullable): option => if Js.isNullable(x) { None } else { Obj.magic(some((Obj.magic(x): 'a))) } -let undefined_to_opt = (type t, x: Js.undefined): option => +let fromUndefined = (type t, x: Js.undefined): option => if Obj.magic(x) === Js.undefined { None } else { Obj.magic(some((Obj.magic(x): 'a))) } -let null_to_opt = (type t, x: Js.null): option => +let fromNull = (type t, x: Js.null): option => if Obj.magic(x) === Js.null { None } else { @@ -75,20 +80,17 @@ let valFromOption = (x: Obj.t): Obj.t => Obj.magic(x) } -let option_get = (x: option<'a>) => +let toUndefined = (x: option<'a>) => if x == None { - Caml_undefined_extern.empty + Js.undefined } else { Obj.magic(valFromOption(Obj.repr(x))) } -type poly = { - @as("HASH") hash: int /* Literals.polyvar_hash */, - @as("VAL") value: Obj.t, -} +type poly = {@as("VAL") value: Obj.t} /** [input] is optional polymorphic variant */ -let option_unwrap = (x: option) => +let unwrapPolyVar = (x: option) => switch x { | None => Obj.repr(x) | Some(x) => x.value diff --git a/jscomp/runtime/caml_option.resi b/jscomp/runtime/primitive_option.resi similarity index 68% rename from jscomp/runtime/caml_option.resi rename to jscomp/runtime/primitive_option.resi index 8755bf77f2..0aaf2bd076 100644 --- a/jscomp/runtime/caml_option.resi +++ b/jscomp/runtime/primitive_option.resi @@ -24,23 +24,25 @@ type nested = {@as("BS_PRIVATE_NESTED_SOME_NONE") depth: int} -let nullable_to_opt: Js.null_undefined<'a> => option<'a> +let fromNullable: Primitive_js_extern.null_undefined<'a> => option<'a> -let undefined_to_opt: Js.undefined<'a> => option<'a> +let fromUndefined: Primitive_js_extern.undefined<'a> => option<'a> -let null_to_opt: Js.null<'a> => option<'a> +let fromNull: Primitive_js_extern.null<'a> => option<'a> -let valFromOption: Obj.t => Obj.t +let valFromOption: Primitive_object_extern.t => Primitive_object_extern.t -let some: Obj.t => Obj.t +let some: Primitive_object_extern.t => Primitive_object_extern.t -let isNested: Obj.t => bool +let isNested: Primitive_object_extern.t => bool -let option_get: option => Caml_undefined_extern.t +let toUndefined: option => Primitive_js_extern.undefined< + Primitive_object_extern.t, +> type poly -/** When it is None, return none - When it is (Some (`a 3)) return 3 +/** When it is None, return None + When it is Some (#a(3)) return 3 */ -let option_unwrap: option => Obj.t +let unwrapPolyVar: option => Primitive_object_extern.t diff --git a/jscomp/runtime/primitive_promise.res b/jscomp/runtime/primitive_promise.res new file mode 100644 index 0000000000..4024cd62f2 --- /dev/null +++ b/jscomp/runtime/primitive_promise.res @@ -0,0 +1,2 @@ +external unsafe_async: 'a => promise<'a> = "%identity" +external unsafe_await: promise<'a> => 'a = "%await" diff --git a/jscomp/runtime/primitive_string.res b/jscomp/runtime/primitive_string.res new file mode 100644 index 0000000000..fe6c2b127b --- /dev/null +++ b/jscomp/runtime/primitive_string.res @@ -0,0 +1,33 @@ +let compare = (s1: string, s2: string): int => + if s1 == s2 { + 0 + } else if s1 < s2 { + -1 + } else { + 1 + } + +let min = (x: string, y: string): string => + if x < y { + x + } else { + y + } + +let max = (x: string, y: string): string => + if x > y { + x + } else { + y + } + +let getChar = (s, i) => + if i >= Primitive_string_extern.length(s) || i < 0 { + raise(Invalid_argument("index out of bounds")) + } else { + Primitive_string_extern.getChar(s, i) + } + +// TODO: delete +let make = (n, ch: char): string => + Primitive_string_extern.fromChar(ch)->Primitive_string_extern.repeat(n) diff --git a/jscomp/runtime/caml_format.resi b/jscomp/runtime/primitive_string_extern.res similarity index 80% rename from jscomp/runtime/caml_format.resi rename to jscomp/runtime/primitive_string_extern.res index 8d45eeb501..4428679d9e 100644 --- a/jscomp/runtime/caml_format.resi +++ b/jscomp/runtime/primitive_string_extern.res @@ -22,14 +22,13 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -let format_float: (string, float) => string +external length: string => int = "%string_length" -let hexstring_of_float: (float, int, char) => string +@send external getChar: (string, int) => option = "codePointAt" -let format_int: (string, int) => string +@send external getCharUnsafe: (string, int) => char = "codePointAt" -let float_of_string: string => float -let int64_format: (string, int64) => string -let int_of_string: string => int +@scope("String") +external fromChar: char => string = "fromCodePoint" -let int64_of_string: string => int64 +@send external repeat: (string, int) => string = "repeat" diff --git a/jscomp/runtime/primitive_util.res b/jscomp/runtime/primitive_util.res new file mode 100644 index 0000000000..1b4cb015b9 --- /dev/null +++ b/jscomp/runtime/primitive_util.res @@ -0,0 +1,8 @@ +module Js = Primitive_js_extern + +let raiseWhenNotFound = x => + if Js.testAny(x) { + raise(Not_found) + } else { + x + } diff --git a/jscomp/runtime/release.ninja b/jscomp/runtime/release.ninja index 528c515610..b3ecd1eb7c 100644 --- a/jscomp/runtime/release.ninja +++ b/jscomp/runtime/release.ninja @@ -1,6 +1,5 @@ -bsc_no_open_flags = -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 -bsc_flags = $bsc_no_open_flags -open Bs_stdlib_mini +bsc_flags = -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -make-runtime -unsafe -w -3+50 -warn-error A rule cc command = $bsc -bs-cmi -bs-cmj $bsc_flags -I runtime $in @@ -9,55 +8,51 @@ rule cc_cmi command = $bsc -bs-read-cmi -bs-cmi -bs-cmj $bsc_flags -I runtime $in description = $in -> $out -o runtime/bs_stdlib_mini.cmi : cc runtime/bs_stdlib_mini.resi - bsc_flags = -nostdlib -nopervasives -o runtime/js.cmj runtime/js.cmi : cc runtime/js.res - bsc_flags = $bsc_no_open_flags -o runtime/caml.cmj : cc_cmi runtime/caml.res | runtime/caml.cmi runtime/caml_int64_extern.cmj -o runtime/caml.cmi : cc runtime/caml.resi | runtime/bs_stdlib_mini.cmi runtime/caml_int64_extern.cmj runtime/js.cmi runtime/js.cmj -o runtime/caml_array.cmj : cc_cmi runtime/caml_array.res | runtime/caml_array.cmi runtime/caml_array_extern.cmj -o runtime/caml_array.cmi : cc runtime/caml_array.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_bigint.cmj : cc_cmi runtime/caml_bigint.res | runtime/caml_bigint.cmi runtime/caml_bigint_extern.cmj -o runtime/caml_bigint.cmi : cc runtime/caml_bigint.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_bytes.cmj : cc_cmi runtime/caml_bytes.res | runtime/caml_bytes.cmi -o runtime/caml_bytes.cmi : cc runtime/caml_bytes.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_exceptions.cmj : cc_cmi runtime/caml_exceptions.res | runtime/caml_exceptions.cmi -o runtime/caml_exceptions.cmi : cc runtime/caml_exceptions.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_float.cmj : cc_cmi runtime/caml_float.res | runtime/caml_float.cmi runtime/caml_float_extern.cmj -o runtime/caml_float.cmi : cc runtime/caml_float.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_format.cmj : cc_cmi runtime/caml_format.res | runtime/caml.cmj runtime/caml_float.cmj runtime/caml_float_extern.cmj runtime/caml_format.cmi runtime/caml_int64.cmj runtime/caml_int64_extern.cmj runtime/caml_nativeint_extern.cmj runtime/caml_string_extern.cmj -o runtime/caml_format.cmi : cc runtime/caml_format.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_hash.cmj : cc_cmi runtime/caml_hash.res | runtime/caml_hash.cmi runtime/caml_hash_primitive.cmj runtime/caml_nativeint_extern.cmj -o runtime/caml_hash.cmi : cc runtime/caml_hash.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_hash_primitive.cmj : cc_cmi runtime/caml_hash_primitive.res | runtime/caml_hash_primitive.cmi runtime/caml_string_extern.cmj -o runtime/caml_hash_primitive.cmi : cc runtime/caml_hash_primitive.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_int32.cmj : cc_cmi runtime/caml_int32.res | runtime/caml_int32.cmi runtime/caml_nativeint_extern.cmj -o runtime/caml_int32.cmi : cc runtime/caml_int32.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_int64.cmj : cc_cmi runtime/caml_int64.res | runtime/caml.cmj runtime/caml_float.cmj runtime/caml_float_extern.cmj runtime/caml_int64.cmi runtime/caml_int64_extern.cmj runtime/caml_nativeint_extern.cmj runtime/caml_string_extern.cmj -o runtime/caml_int64.cmi : cc runtime/caml_int64.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_lexer.cmj : cc_cmi runtime/caml_lexer.res | runtime/caml_lexer.cmi -o runtime/caml_lexer.cmi : cc runtime/caml_lexer.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_md5.cmj : cc_cmi runtime/caml_md5.res | runtime/caml_array_extern.cmj runtime/caml_md5.cmi runtime/caml_string_extern.cmj -o runtime/caml_md5.cmi : cc runtime/caml_md5.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_module.cmj : cc_cmi runtime/caml_module.res | runtime/caml_array_extern.cmj runtime/caml_module.cmi runtime/caml_obj.cmj -o runtime/caml_module.cmi : cc runtime/caml_module.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_obj.cmj : cc_cmi runtime/caml_obj.res | runtime/caml.cmj runtime/caml_array_extern.cmj runtime/caml_obj.cmi runtime/caml_option.cmj -o runtime/caml_obj.cmi : cc runtime/caml_obj.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_option.cmj : cc_cmi runtime/caml_option.res | runtime/caml_option.cmi runtime/caml_undefined_extern.cmj -o runtime/caml_option.cmi : cc runtime/caml_option.resi | runtime/bs_stdlib_mini.cmi runtime/caml_undefined_extern.cmj runtime/js.cmi runtime/js.cmj -o runtime/caml_parser.cmj : cc_cmi runtime/caml_parser.res | runtime/caml_parser.cmi -o runtime/caml_parser.cmi : cc runtime/caml_parser.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_string.cmj : cc_cmi runtime/caml_string.res | runtime/caml_string.cmi runtime/caml_string_extern.cmj -o runtime/caml_string.cmi : cc runtime/caml_string.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_sys.cmj : cc_cmi runtime/caml_sys.res | runtime/caml_array_extern.cmj runtime/caml_sys.cmi runtime/caml_undefined_extern.cmj -o runtime/caml_sys.cmi : cc runtime/caml_sys.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_array_extern.cmi runtime/caml_array_extern.cmj : cc runtime/caml_array_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_bigint_extern.cmi runtime/caml_bigint_extern.cmj : cc runtime/caml_bigint_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_float_extern.cmi runtime/caml_float_extern.cmj : cc runtime/caml_float_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_int64_extern.cmi runtime/caml_int64_extern.cmj : cc runtime/caml_int64_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj : cc runtime/caml_js_exceptions.res | runtime/bs_stdlib_mini.cmi runtime/caml_exceptions.cmj runtime/caml_option.cmj runtime/js.cmi runtime/js.cmj -o runtime/caml_nativeint_extern.cmi runtime/caml_nativeint_extern.cmj : cc runtime/caml_nativeint_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_string_extern.cmi runtime/caml_string_extern.cmj : cc runtime/caml_string_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/caml_undefined_extern.cmi runtime/caml_undefined_extern.cmj : cc runtime/caml_undefined_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj -o runtime/curry.cmi runtime/curry.cmj : cc runtime/curry.res | runtime/bs_stdlib_mini.cmi runtime/caml_array.cmj runtime/caml_array_extern.cmj runtime/js.cmi runtime/js.cmj -o runtime : phony runtime/bs_stdlib_mini.cmi runtime/js.cmj runtime/js.cmi runtime/caml.cmi runtime/caml.cmj runtime/caml_array.cmi runtime/caml_array.cmj runtime/caml_bigint.cmi runtime/caml_bigint.cmj runtime/caml_bytes.cmi runtime/caml_bytes.cmj runtime/caml_exceptions.cmi runtime/caml_exceptions.cmj runtime/caml_float.cmi runtime/caml_float.cmj runtime/caml_format.cmi runtime/caml_format.cmj runtime/caml_hash.cmi runtime/caml_hash.cmj runtime/caml_hash_primitive.cmi runtime/caml_hash_primitive.cmj runtime/caml_int32.cmi runtime/caml_int32.cmj runtime/caml_int64.cmi runtime/caml_int64.cmj runtime/caml_lexer.cmi runtime/caml_lexer.cmj runtime/caml_md5.cmi runtime/caml_md5.cmj runtime/caml_module.cmi runtime/caml_module.cmj runtime/caml_obj.cmi runtime/caml_obj.cmj runtime/caml_option.cmi runtime/caml_option.cmj runtime/caml_parser.cmi runtime/caml_parser.cmj runtime/caml_string.cmi runtime/caml_string.cmj runtime/caml_sys.cmi runtime/caml_sys.cmj runtime/caml_array_extern.cmi runtime/caml_array_extern.cmj runtime/caml_bigint_extern.cmi runtime/caml_bigint_extern.cmj runtime/caml_float_extern.cmi runtime/caml_float_extern.cmj runtime/caml_int64_extern.cmi runtime/caml_int64_extern.cmj runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj runtime/caml_nativeint_extern.cmi runtime/caml_nativeint_extern.cmj runtime/caml_string_extern.cmi runtime/caml_string_extern.cmj runtime/caml_undefined_extern.cmi runtime/caml_undefined_extern.cmj runtime/curry.cmi runtime/curry.cmj +o runtime/pervasives.cmj runtime/pervasives.cmi : cc runtime/pervasives.res + bsc_flags = $bsc_flags -nopervasives +o runtime/array.cmj : cc_cmi runtime/array.res | runtime/array.cmi runtime/list.cmj runtime/primitive_array.cmj runtime/primitive_exceptions.cmj +o runtime/array.cmi : cc runtime/array.resi | runtime/pervasives.cmi runtime/pervasives.cmj +o runtime/char.cmj : cc_cmi runtime/char.res | runtime/char.cmi runtime/primitive_array_extern.cmj +o runtime/char.cmi : cc runtime/char.resi | runtime/pervasives.cmi runtime/pervasives.cmj +o runtime/hashtbl.cmj : cc_cmi runtime/hashtbl.res | runtime/hashtbl.cmi runtime/primitive_hash.cmj +o runtime/hashtbl.cmi : cc runtime/hashtbl.resi | runtime/pervasives.cmi runtime/pervasives.cmj +o runtime/lazy.cmj : cc_cmi runtime/lazy.res | runtime/lazy.cmi runtime/primitive_lazy.cmj +o runtime/lazy.cmi : cc runtime/lazy.resi | runtime/pervasives.cmi runtime/pervasives.cmj +o runtime/list.cmj : cc_cmi runtime/list.res | runtime/list.cmi runtime/pervasives.cmj runtime/primitive_option.cmj +o runtime/list.cmi : cc runtime/list.resi | runtime/pervasives.cmi runtime/pervasives.cmj +o runtime/primitive_curry.cmj : cc_cmi runtime/primitive_curry.res | runtime/array.cmj runtime/obj.cmj runtime/primitive_array_extern.cmj runtime/primitive_curry.cmi runtime/primitive_js_extern.cmj runtime/primitive_object_extern.cmj +o runtime/primitive_curry.cmi : cc runtime/primitive_curry.resi | runtime/pervasives.cmi runtime/pervasives.cmj +o runtime/primitive_exceptions.cmj : cc_cmi runtime/primitive_exceptions.res | runtime/obj.cmj runtime/primitive_exceptions.cmi runtime/primitive_js_extern.cmj runtime/primitive_object_extern.cmj +o runtime/primitive_exceptions.cmi : cc runtime/primitive_exceptions.resi | runtime/pervasives.cmi runtime/pervasives.cmj +o runtime/primitive_hash.cmj : cc_cmi runtime/primitive_hash.res | runtime/obj.cmj runtime/primitive_float_extern.cmj runtime/primitive_hash.cmi runtime/primitive_js_extern.cmj runtime/primitive_object_extern.cmj runtime/primitive_string_extern.cmj runtime/string.cmj +o runtime/primitive_hash.cmi : cc runtime/primitive_hash.resi | runtime/pervasives.cmi runtime/pervasives.cmj runtime/primitive_object.cmi +o runtime/primitive_lazy.cmj : cc_cmi runtime/primitive_lazy.res | runtime/primitive_exceptions.cmj runtime/primitive_lazy.cmi +o runtime/primitive_lazy.cmi : cc runtime/primitive_lazy.resi | runtime/pervasives.cmi runtime/pervasives.cmj +o runtime/primitive_module.cmj : cc_cmi runtime/primitive_module.res | runtime/array.cmj runtime/lazy.cmj runtime/obj.cmj runtime/primitive_array_extern.cmj runtime/primitive_module.cmi runtime/primitive_object_extern.cmj +o runtime/primitive_module.cmi : cc runtime/primitive_module.resi | runtime/pervasives.cmi runtime/pervasives.cmj runtime/primitive_object.cmi +o runtime/primitive_object.cmj : cc_cmi runtime/primitive_object.res | runtime/array.cmj runtime/primitive_array_extern.cmj runtime/primitive_bool.cmj runtime/primitive_float.cmj runtime/primitive_int.cmj runtime/primitive_js_extern.cmj runtime/primitive_object.cmi runtime/primitive_object_extern.cmj runtime/primitive_option.cmj runtime/primitive_string.cmj +o runtime/primitive_object.cmi : cc runtime/primitive_object.resi | runtime/pervasives.cmi runtime/pervasives.cmj runtime/primitive_object_extern.cmj +o runtime/primitive_option.cmj : cc_cmi runtime/primitive_option.res | runtime/primitive_js_extern.cmj runtime/primitive_object_extern.cmj runtime/primitive_option.cmi +o runtime/primitive_option.cmi : cc runtime/primitive_option.resi | runtime/pervasives.cmi runtime/pervasives.cmj runtime/primitive_js_extern.cmj runtime/primitive_object_extern.cmj +o runtime/string.cmj : cc_cmi runtime/string.res | runtime/array.cmj runtime/char.cmj runtime/primitive_exceptions.cmj runtime/primitive_string_extern.cmj runtime/string.cmi +o runtime/string.cmi : cc runtime/string.resi | runtime/pervasives.cmi runtime/pervasives.cmj +o runtime/map.cmi runtime/map.cmj : cc runtime/map.res | runtime/pervasives.cmi runtime/pervasives.cmj +o runtime/obj.cmi runtime/obj.cmj : cc runtime/obj.res | runtime/pervasives.cmi runtime/pervasives.cmj runtime/primitive_object_extern.cmj +o runtime/primitive_array.cmi runtime/primitive_array.cmj : cc runtime/primitive_array.res | runtime/pervasives.cmi runtime/pervasives.cmj runtime/primitive_array_extern.cmj +o runtime/primitive_array_extern.cmi runtime/primitive_array_extern.cmj : cc runtime/primitive_array_extern.res | runtime/pervasives.cmi runtime/pervasives.cmj +o runtime/primitive_bigint.cmi runtime/primitive_bigint.cmj : cc runtime/primitive_bigint.res | runtime/pervasives.cmi runtime/pervasives.cmj +o runtime/primitive_bool.cmi runtime/primitive_bool.cmj : cc runtime/primitive_bool.res | runtime/pervasives.cmi runtime/pervasives.cmj +o runtime/primitive_char_extern.cmi runtime/primitive_char_extern.cmj : cc runtime/primitive_char_extern.res | runtime/pervasives.cmi runtime/pervasives.cmj +o runtime/primitive_dict.cmi runtime/primitive_dict.cmj : cc runtime/primitive_dict.res | runtime/pervasives.cmi runtime/pervasives.cmj +o runtime/primitive_float.cmi runtime/primitive_float.cmj : cc runtime/primitive_float.res | runtime/pervasives.cmi runtime/pervasives.cmj +o runtime/primitive_float_extern.cmi runtime/primitive_float_extern.cmj : cc runtime/primitive_float_extern.res | runtime/pervasives.cmi runtime/pervasives.cmj +o runtime/primitive_int.cmi runtime/primitive_int.cmj : cc runtime/primitive_int.res | runtime/pervasives.cmi runtime/pervasives.cmj runtime/primitive_int_extern.cmj +o runtime/primitive_int_extern.cmi runtime/primitive_int_extern.cmj : cc runtime/primitive_int_extern.res | runtime/pervasives.cmi runtime/pervasives.cmj +o runtime/primitive_js_extern.cmi runtime/primitive_js_extern.cmj : cc runtime/primitive_js_extern.res | runtime/pervasives.cmi runtime/pervasives.cmj +o runtime/primitive_object_extern.cmi runtime/primitive_object_extern.cmj : cc runtime/primitive_object_extern.res | runtime/pervasives.cmi runtime/pervasives.cmj +o runtime/primitive_promise.cmi runtime/primitive_promise.cmj : cc runtime/primitive_promise.res | runtime/pervasives.cmi runtime/pervasives.cmj +o runtime/primitive_string.cmi runtime/primitive_string.cmj : cc runtime/primitive_string.res | runtime/pervasives.cmi runtime/pervasives.cmj runtime/primitive_string_extern.cmj +o runtime/primitive_string_extern.cmi runtime/primitive_string_extern.cmj : cc runtime/primitive_string_extern.res | runtime/pervasives.cmi runtime/pervasives.cmj +o runtime/primitive_util.cmi runtime/primitive_util.cmj : cc runtime/primitive_util.res | runtime/pervasives.cmi runtime/pervasives.cmj runtime/primitive_js_extern.cmj +o runtime/set.cmi runtime/set.cmj : cc runtime/set.res | runtime/pervasives.cmi runtime/pervasives.cmj +o runtime : phony runtime/pervasives.cmj runtime/pervasives.cmi runtime/array.cmi runtime/array.cmj runtime/char.cmi runtime/char.cmj runtime/hashtbl.cmi runtime/hashtbl.cmj runtime/lazy.cmi runtime/lazy.cmj runtime/list.cmi runtime/list.cmj runtime/primitive_curry.cmi runtime/primitive_curry.cmj runtime/primitive_exceptions.cmi runtime/primitive_exceptions.cmj runtime/primitive_hash.cmi runtime/primitive_hash.cmj runtime/primitive_lazy.cmi runtime/primitive_lazy.cmj runtime/primitive_module.cmi runtime/primitive_module.cmj runtime/primitive_object.cmi runtime/primitive_object.cmj runtime/primitive_option.cmi runtime/primitive_option.cmj runtime/string.cmi runtime/string.cmj runtime/map.cmi runtime/map.cmj runtime/obj.cmi runtime/obj.cmj runtime/primitive_array.cmi runtime/primitive_array.cmj runtime/primitive_array_extern.cmi runtime/primitive_array_extern.cmj runtime/primitive_bigint.cmi runtime/primitive_bigint.cmj runtime/primitive_bool.cmi runtime/primitive_bool.cmj runtime/primitive_char_extern.cmi runtime/primitive_char_extern.cmj runtime/primitive_dict.cmi runtime/primitive_dict.cmj runtime/primitive_float.cmi runtime/primitive_float.cmj runtime/primitive_float_extern.cmi runtime/primitive_float_extern.cmj runtime/primitive_int.cmi runtime/primitive_int.cmj runtime/primitive_int_extern.cmi runtime/primitive_int_extern.cmj runtime/primitive_js_extern.cmi runtime/primitive_js_extern.cmj runtime/primitive_object_extern.cmi runtime/primitive_object_extern.cmj runtime/primitive_promise.cmi runtime/primitive_promise.cmj runtime/primitive_string.cmi runtime/primitive_string.cmj runtime/primitive_string_extern.cmi runtime/primitive_string_extern.cmj runtime/primitive_util.cmi runtime/primitive_util.cmj runtime/set.cmi runtime/set.cmj diff --git a/jscomp/runtime/set.res b/jscomp/runtime/set.res new file mode 100644 index 0000000000..b547fe31de --- /dev/null +++ b/jscomp/runtime/set.res @@ -0,0 +1,4 @@ +// FIXME: +// This exists for compatibility reason. +// Move this into Pervasives or Core + diff --git a/jscomp/stdlib-406/string.res b/jscomp/runtime/string.res similarity index 66% rename from jscomp/stdlib-406/string.res rename to jscomp/runtime/string.res index a038bfdaf8..11fa4877f1 100644 --- a/jscomp/stdlib-406/string.res +++ b/jscomp/runtime/string.res @@ -1,52 +1,62 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Damien Doligez, projet Gallium, INRIA Rocquencourt */ -/* */ -/* Copyright 2014 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. */ -/* */ -/* ************************************************************************ */ - -/* String operations, based on byte sequence operations */ - -/* WARNING: Some functions in this file are duplicated in bytes.ml for - efficiency reasons. When you modify the one in this file you need to - modify its duplicate in bytes.ml. - These functions have a "duplicated" comment above their definition. -*/ - -external length: string => int = "%string_length" -external get: (string, int) => char = "%string_safe_get" -external unsafe_get: (string, int) => char = "%string_unsafe_get" - -module B = Bytes - -let bts = B.unsafe_to_string -let bos = B.unsafe_of_string - -external make: (int, char) => string = "?string_repeat" - -let init = (n, f) => bts(B.init(n, f)) -let sub = (s, ofs, len) => bts(B.sub(bos(s), ofs, len)) -let blit = B.blit_string +// FIXME: +// This exists for compatibility reason. +// Move this into Pervasives or Core + +// Below is all deprecated and should be removed in v13 + +type t = string + +module B = { + include Array -%%private(@send external join: (array, string) => string = "join") + let uppercase_ascii = bytes => map(Char.uppercase_ascii, bytes) + let lowercase_ascii = bytes => map(Char.lowercase_ascii, bytes) + + let apply1 = (f, bytes) => + if length(bytes) == 0 { + bytes + } else { + let r = copy(bytes) + unsafe_set(r, 0, f(unsafe_get(bytes, 0))) + r + } + let capitalize_ascii = bytes => apply1(Char.uppercase_ascii, bytes) + let uncapitalize_ascii = bytes => apply1(Char.lowercase_ascii, bytes) + + let escaped = bytes => map(Char.escaped, bytes) +} + +@send external join: (array, string) => string = "join" let concat = (sep: string, xs: list) => xs->Array.of_list->join(sep) -/* duplicated in bytes.ml */ +let length = Primitive_string_extern.length + +let get = Primitive_string_extern.getCharUnsafe + +let unsafe_get = Primitive_string_extern.getCharUnsafe + +@scope("Array") external bos: string => array = "from" +let bos = str => B.map(str => str->unsafe_get(0), str->bos) + +@scope("String") @variadic +external bts: array => string = "fromCodePoint" + +let make = (len, ch) => Primitive_string_extern.fromChar(ch)->Primitive_string_extern.repeat(len) + +let init = (len, f) => Array.init(len, i => Primitive_string_extern.fromChar(f(i)))->join("") + +let sub = (s, ofs, len) => bts(B.sub(bos(s), ofs, len)) + +external compare: (t, t) => int = "%compare" + +external equal: (t, t) => bool = "%equal" + let iter = (f, s) => for i in 0 to length(s) - 1 { f(unsafe_get(s, i)) } -/* duplicated in bytes.ml */ let iteri = (f, s) => for i in 0 to length(s) - 1 { f(i, unsafe_get(s, i)) @@ -55,24 +65,7 @@ let iteri = (f, s) => let map = (f, s) => bts(B.map(f, bos(s))) let mapi = (f, s) => bts(B.mapi(f, bos(s))) -/* Beware: we cannot use B.trim or B.escape because they always make a - copy, but String.mli spells out some cases where we are not allowed - to make a copy. */ - -let is_space = param => - switch param { - | ' ' | ' ' | '\n' | '\r' | '\t' => true - | _ => false - } - -let trim = s => - if s == "" { - s - } else if is_space(unsafe_get(s, 0)) || is_space(unsafe_get(s, length(s) - 1)) { - bts(B.trim(bos(s))) - } else { - s - } +@send external trim: string => string = "trim" let escaped = s => { let rec needs_escape = i => @@ -87,7 +80,7 @@ let escaped = s => { } if needs_escape(0) { - bts(B.escaped(bos(s))) + join(B.escaped(bos(s)), "") } else { s } @@ -217,11 +210,6 @@ let lowercase_ascii = s => bts(B.lowercase_ascii(bos(s))) let capitalize_ascii = s => bts(B.capitalize_ascii(bos(s))) let uncapitalize_ascii = s => bts(B.uncapitalize_ascii(bos(s))) -type t = string - -let compare = (x: t, y: t) => Pervasives.compare(x, y) -let equal: (string, string) => bool = (a, b) => a == b - let split_on_char = (sep, s) => { let r = ref(list{}) let j = ref(length(s)) diff --git a/jscomp/stdlib-406/string.resi b/jscomp/runtime/string.resi similarity index 72% rename from jscomp/stdlib-406/string.resi rename to jscomp/runtime/string.resi index 319e089ae4..8ef4fbbc7d 100644 --- a/jscomp/stdlib-406/string.resi +++ b/jscomp/runtime/string.resi @@ -1,75 +1,30 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/*** String operations. - - A string is an immutable data structure that contains a - fixed-length sequence of (single-byte) characters. Each character - can be accessed in constant time through its index. - - Given a string [s] of length [l], we can access each of the [l] - characters of [s] via its index in the sequence. Indexes start at - [0], and we will call an index valid in [s] if it falls within the - range [[0...l-1]] (inclusive). A position is the point between two - characters or at the beginning or end of the string. We call a - position valid in [s] if it falls within the range [[0...l]] - (inclusive). Note that the character at index [n] is between - positions [n] and [n+1]. - - Two parameters [start] and [len] are said to designate a valid - substring of [s] if [len >= 0] and [start] and [start+len] are - valid positions in [s]. - - OCaml strings used to be modifiable in place, for instance via the - {!String.set} and {!String.blit} functions described below. This - usage is deprecated and only possible when the compiler is put in - "unsafe-string" mode by giving the [-unsafe-string] command-line - option (which is currently the default for reasons of backward - compatibility). This is done by making the types [string] and - [bytes] (see module {!Bytes}) interchangeable so that functions - expecting byte sequences can also accept strings as arguments and - modify them. - - All new code should avoid this feature and be compiled with the - [-safe-string] command-line option to enforce the separation between - the types [string] and [bytes]. -*/ +// FIXME: +// This exists for compatibility reason. +// Move this into Pervasives or Core + +// Below is all deprecated and should be removed in v13 /** Return the length (number of characters) of the given string. */ -external length: string => int = "%string_length" +@deprecated("Use Core instead. This will be removed in v13") +let length: string => int /** [String.get s n] returns the character at index [n] in string [s]. You can also write [s.[n]] instead of [String.get s n]. Raise [Invalid_argument] if [n] not a valid index in [s]. */ -external get: (string, int) => char = "%string_safe_get" +@deprecated("Use Core instead. This will be removed in v13") +let get: (string, int) => char /** [String.make n c] returns a fresh string of length [n], - filled with the character [c]. - - Raise [Invalid_argument] if [n < 0] or [n > ]{!Sys.max_string_length}. */ + filled with the character [c]. */ +@deprecated("Use Core instead. This will be removed in v13") let make: (int, char) => string /** [String.init n f] returns a string of length [n], with character [i] initialized to the result of [f i] (called in increasing index order). - - Raise [Invalid_argument] if [n < 0] or [n > ]{!Sys.max_string_length}. - - @since 4.02.0 */ +@deprecated("Use Core instead. This will be removed in v13") let init: (int, int => char) => string /** [String.sub s start len] returns a fresh string of length [len], @@ -78,39 +33,42 @@ let init: (int, int => char) => string Raise [Invalid_argument] if [start] and [len] do not designate a valid substring of [s]. */ +@deprecated("Use Core instead. This will be removed in v13") let sub: (string, int, int) => string -/** Same as {!Bytes.blit_string}. */ -let blit: (string, int, bytes, int, int) => unit - /** [String.concat sep sl] concatenates the list of strings [sl], inserting the separator string [sep] between each. Raise [Invalid_argument] if the result is longer than {!Sys.max_string_length} bytes. */ +@deprecated("Use Core instead. This will be removed in v13") let concat: (string, list) => string /** [String.iter f s] applies function [f] in turn to all the characters of [s]. It is equivalent to [f s.[0]; f s.[1]; ...; f s.[String.length s - 1]; ()]. */ +@deprecated("Use Core instead. This will be removed in v13") let iter: (char => unit, string) => unit /** Same as {!String.iter}, but the function is applied to the index of the element as first argument (counting from 0), and the character itself as second argument. @since 4.00.0 */ +@deprecated("Use Core instead. This will be removed in v13") let iteri: ((int, char) => unit, string) => unit /** [String.map f s] applies function [f] in turn to all the characters of [s] (in increasing index order) and stores the results in a new string that is returned. @since 4.00.0 */ +@deprecated("Use Core instead. This will be removed in v13") let map: (char => char, string) => string /** [String.mapi f s] calls [f] with each character of [s] and its index (in increasing index order) and stores the results in a new string that is returned. @since 4.02.0 */ +@deprecated("Use Core instead. This will be removed in v13") let mapi: ((int, char) => char, string) => string /** Return a copy of the argument, without leading and trailing @@ -119,7 +77,9 @@ let mapi: ((int, char) => char, string) => string trailing whitespace character in the argument, return the original string itself, not a copy. @since 4.00.0 */ -let trim: string => string +@deprecated("Use Core instead. This will be removed in v13") +@send +external trim: string => string = "trim" /** Return a copy of the argument, with special characters represented by escape sequences, following the lexical @@ -129,37 +89,36 @@ let trim: string => string If there is no special character in the argument that needs escaping, return the original string itself, not a copy. - - Raise [Invalid_argument] if the result is longer than - {!Sys.max_string_length} bytes. - - The function {!Scanf.unescaped} is a left inverse of [escaped], - i.e. [Scanf.unescaped (escaped s) = s] for any string [s] (unless - [escape s] fails). */ + */ +@deprecated("Use Core instead. This will be removed in v13") let escaped: string => string /** [String.index s c] returns the index of the first occurrence of character [c] in string [s]. Raise [Not_found] if [c] does not occur in [s]. */ +@deprecated("Use Core instead. This will be removed in v13") let index: (string, char) => int /** [String.index_opt s c] returns the index of the first occurrence of character [c] in string [s], or [None] if [c] does not occur in [s]. @since 4.05 */ +@deprecated("Use Core instead. This will be removed in v13") let index_opt: (string, char) => option /** [String.rindex s c] returns the index of the last occurrence of character [c] in string [s]. Raise [Not_found] if [c] does not occur in [s]. */ +@deprecated("Use Core instead. This will be removed in v13") let rindex: (string, char) => int /** [String.rindex_opt s c] returns the index of the last occurrence of character [c] in string [s], or [None] if [c] does not occur in [s]. @since 4.05 */ +@deprecated("Use Core instead. This will be removed in v13") let rindex_opt: (string, char) => option /** [String.index_from s i c] returns the index of the @@ -168,6 +127,7 @@ let rindex_opt: (string, char) => option Raise [Invalid_argument] if [i] is not a valid position in [s]. Raise [Not_found] if [c] does not occur in [s] after position [i]. */ +@deprecated("Use Core instead. This will be removed in v13") let index_from: (string, int, char) => int /** [String.index_from_opt s i c] returns the index of the @@ -179,6 +139,7 @@ let index_from: (string, int, char) => int @since 4.05 */ +@deprecated("Use Core instead. This will be removed in v13") let index_from_opt: (string, int, char) => option /** [String.rindex_from s i c] returns the index of the @@ -188,6 +149,7 @@ let index_from_opt: (string, int, char) => option Raise [Invalid_argument] if [i+1] is not a valid position in [s]. Raise [Not_found] if [c] does not occur in [s] before position [i+1]. */ +@deprecated("Use Core instead. This will be removed in v13") let rindex_from: (string, int, char) => int /** [String.rindex_from_opt s i c] returns the index of the @@ -201,10 +163,12 @@ let rindex_from: (string, int, char) => int @since 4.05 */ +@deprecated("Use Core instead. This will be removed in v13") let rindex_from_opt: (string, int, char) => option /** [String.contains s c] tests if character [c] appears in the string [s]. */ +@deprecated("Use Core instead. This will be removed in v13") let contains: (string, char) => bool /** [String.contains_from s start c] tests if character [c] @@ -213,6 +177,7 @@ let contains: (string, char) => bool [String.contains_from s 0 c]. Raise [Invalid_argument] if [start] is not a valid position in [s]. */ +@deprecated("Use Core instead. This will be removed in v13") let contains_from: (string, int, char) => bool /** [String.rcontains_from s stop c] tests if character [c] @@ -220,40 +185,48 @@ let contains_from: (string, int, char) => bool Raise [Invalid_argument] if [stop < 0] or [stop+1] is not a valid position in [s]. */ +@deprecated("Use Core instead. This will be removed in v13") let rcontains_from: (string, int, char) => bool /** Return a copy of the argument, with all lowercase letters translated to uppercase, using the US-ASCII character set. @since 4.03.0 */ +@deprecated("Use Core instead. This will be removed in v13") let uppercase_ascii: string => string /** Return a copy of the argument, with all uppercase letters translated to lowercase, using the US-ASCII character set. @since 4.03.0 */ +@deprecated("Use Core instead. This will be removed in v13") let lowercase_ascii: string => string /** Return a copy of the argument, with the first character set to uppercase, using the US-ASCII character set. @since 4.03.0 */ +@deprecated("Use Core instead. This will be removed in v13") let capitalize_ascii: string => string /** Return a copy of the argument, with the first character set to lowercase, using the US-ASCII character set. @since 4.03.0 */ +@deprecated("Use Core instead. This will be removed in v13") let uncapitalize_ascii: string => string /** An alias for the type of strings. */ +@deprecated("Use `string` instead. This will be removed in v13") type t = string /** The comparison function for strings, with the same specification as {!Pervasives.compare}. Along with the type [t], this function [compare] allows the module [String] to be passed as argument to the functors {!Set.Make} and {!Map.Make}. */ -let compare: (t, t) => int +@deprecated("Use Core instead. This will be removed in v13") +external compare: (t, t) => int = "%compare" /** The equal function for strings. @since 4.03.0 */ -let equal: (t, t) => bool +@deprecated("Use Core instead. This will be removed in v13") +external equal: (t, t) => bool = "%equal" /** [String.split_on_char sep s] returns the list of all (possibly empty) substrings of [s] that are delimited by the [sep] character. @@ -268,8 +241,9 @@ let equal: (t, t) => bool @since 4.04.0 */ +@deprecated("Use Core instead. This will be removed in v13") let split_on_char: (char, string) => list /* The following is for system use only. Do not call directly. */ - -external unsafe_get: (string, int) => char = "%string_unsafe_get" +@deprecated("Use Core instead. This will be removed in v13") +let unsafe_get: (string, int) => char diff --git a/jscomp/stdlib-406/arg.res b/jscomp/stdlib-406/arg.res deleted file mode 100644 index 0ac5da3a18..0000000000 --- a/jscomp/stdlib-406/arg.res +++ /dev/null @@ -1,427 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Damien Doligez, projet Para, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -type key = string -type doc = string -type usage_msg = string -type anon_fun = string => unit - -type rec spec = - | Unit(unit => unit) /* Call the function with unit argument */ - | Bool(bool => unit) /* Call the function with a bool argument */ - | Set(ref) /* Set the reference to true */ - | Clear(ref) /* Set the reference to false */ - | String(string => unit) /* Call the function with a string argument */ - | Set_string(ref) /* Set the reference to the string argument */ - | Int(int => unit) /* Call the function with an int argument */ - | Set_int(ref) /* Set the reference to the int argument */ - | Float(float => unit) /* Call the function with a float argument */ - | Set_float(ref) /* Set the reference to the float argument */ - | Tuple(list) /* Take several arguments according to the - spec list */ - - | Symbol(list, string => unit) - /* Take one of the symbols as argument and - call the function with the symbol. */ - | Rest(string => unit) /* Stop interpreting keywords and call the - function with each remaining argument */ - - | Expand( - string => array, - ) /* If the remaining arguments to process - are of the form - [["-foo"; "arg"] @ rest] where "foo" is - registered as [Expand f], then the - arguments [f "arg" @ rest] are - processed. Only allowed in - [parse_and_expand_argv_dynamic]. */ - -exception Bad(string) -exception Help(string) - -type error = - | Unknown(string) - | Wrong(string, string, string) /* option, actual, expected */ - | Missing(string) - | Message(string) - -exception Stop(error) /* used internally */ - -let rec assoc3 = (x, l) => - switch l { - | list{} => raise(Not_found) - | list{(y1, y2, _), ..._} if y1 == x => y2 - | list{_, ...t} => assoc3(x, t) - } - -let split = s => { - let i = String.index(s, '=') - let len = String.length(s) - (String.sub(s, 0, i), String.sub(s, i + 1, len - (i + 1))) -} - -let make_symlist = (prefix, sep, suffix, l) => - switch l { - | list{} => "" - | list{h, ...t} => List.fold_left((x, y) => x ++ (sep ++ y), prefix ++ h, t) ++ suffix - } - -let print_spec = (buf, (key, spec, doc)) => - if String.length(doc) > 0 { - switch spec { - | Symbol(l, _) => - let sym = make_symlist("{", "|", "}", l) - Buffer.add_string(buf, ` ${key} ${sym}${doc}\n`) - | _ => Buffer.add_string(buf, ` ${key} ${doc}\n`) - } - } - -let help_action = () => raise(Stop(Unknown("-help"))) - -let add_help = speclist => { - let add1 = try { - ignore(assoc3("-help", speclist)) - list{} - } catch { - | Not_found => list{("-help", Unit(help_action), " Display this list of options")} - } - and add2 = try { - ignore(assoc3("--help", speclist)) - list{} - } catch { - | Not_found => list{("--help", Unit(help_action), " Display this list of options")} - } - - \"@"(speclist, \"@"(add1, add2)) -} - -let usage_b = (buf, speclist, errmsg) => { - Buffer.add_string(buf, `${errmsg}\n`) - List.iter(x => print_spec(buf, x), add_help(speclist)) -} - -let usage_string = (speclist, errmsg) => { - let b = Buffer.create(200) - usage_b(b, speclist, errmsg) - Buffer.contents(b) -} - -let usage = (speclist, errmsg) => Js.log(usage_string(speclist, errmsg)) - -let current = ref(0) - -let bool_of_string_opt = x => - try Some(bool_of_string(x)) catch { - | Invalid_argument(_) => None - } - -let int_of_string_opt = x => - try Some(int_of_string(x)) catch { - | Failure(_) => None - } - -let float_of_string_opt = x => - try Some(float_of_string(x)) catch { - | Failure(_) => None - } - -let parse_and_expand_argv_dynamic_aux = ( - allow_expand, - current, - argv, - speclist, - anonfun, - errmsg, -) => { - let initpos = current.contents - let convert_error = error => { - /* convert an internal error to a Bad/Help exception - *or* add the program name as a prefix and the usage message as a suffix - to an user-raised Bad exception. - */ - let b = Buffer.create(200) - let progname = if initpos < Array.length(argv.contents) { - argv.contents[initpos] - } else { - "(?)" - } - switch error { - | Unknown("-help") => () - | Unknown("--help") => () - | Unknown(s) => Buffer.add_string(b, `${progname}: unknown option '${s}'.\n`) - | Missing(s) => Buffer.add_string(b, `${progname}: option '${s}' needs an argument.\n`) - | Wrong(opt, arg, expected) => - Buffer.add_string( - b, - `${progname}: wrong argument '${arg}'; option '${opt}' expects ${expected}.\n`, - ) - | Message(s) => - /* user error message */ - Buffer.add_string(b, `${progname}: ${s}.\n`) - } - usage_b(b, speclist.contents, errmsg) - if error == Unknown("-help") || error == Unknown("--help") { - Help(Buffer.contents(b)) - } else { - Bad(Buffer.contents(b)) - } - } - - incr(current) - while current.contents < Array.length(argv.contents) { - try { - let s = argv.contents[current.contents] - if String.length(s) >= 1 && String.get(s, 0) == '-' { - let (action, follow) = try (assoc3(s, speclist.contents), None) catch { - | Not_found => - try { - let (keyword, arg) = split(s) - (assoc3(keyword, speclist.contents), Some(arg)) - } catch { - | Not_found => raise(Stop(Unknown(s))) - } - } - - let no_arg = () => - switch follow { - | None => () - | Some(arg) => raise(Stop(Wrong(s, arg, "no argument"))) - } - let get_arg = () => - switch follow { - | None => - if current.contents + 1 < Array.length(argv.contents) { - argv.contents[current.contents + 1] - } else { - raise(Stop(Missing(s))) - } - | Some(arg) => arg - } - - let consume_arg = () => - switch follow { - | None => incr(current) - | Some(_) => () - } - - let rec treat_action = f => - switch f { - | Unit(f) => f() - | Bool(f) => - let arg = get_arg() - switch bool_of_string_opt(arg) { - | None => raise(Stop(Wrong(s, arg, "a boolean"))) - | Some(s) => f(s) - } - consume_arg() - | Set(r) => - no_arg() - r := true - | Clear(r) => - no_arg() - r := false - | String(f) => - let arg = get_arg() - f(arg) - consume_arg() - | Symbol(symb, f) => - let arg = get_arg() - if List.mem(arg, symb) { - f(arg) - consume_arg() - } else { - raise(Stop(Wrong(s, arg, "one of: " ++ make_symlist("", " ", "", symb)))) - } - | Set_string(r) => - r := get_arg() - consume_arg() - | Int(f) => - let arg = get_arg() - switch int_of_string_opt(arg) { - | None => raise(Stop(Wrong(s, arg, "an integer"))) - | Some(x) => f(x) - } - consume_arg() - | Set_int(r) => - let arg = get_arg() - switch int_of_string_opt(arg) { - | None => raise(Stop(Wrong(s, arg, "an integer"))) - | Some(x) => r := x - } - consume_arg() - | Float(f) => - let arg = get_arg() - switch float_of_string_opt(arg) { - | None => raise(Stop(Wrong(s, arg, "a float"))) - | Some(x) => f(x) - } - consume_arg() - | Set_float(r) => - let arg = get_arg() - switch float_of_string_opt(arg) { - | None => raise(Stop(Wrong(s, arg, "a float"))) - | Some(x) => r := x - } - consume_arg() - | Tuple(specs) => List.iter(treat_action, specs) - | Rest(f) => - while current.contents < Array.length(argv.contents) - 1 { - f(argv.contents[current.contents + 1]) - consume_arg() - } - | Expand(f) => - if !allow_expand { - raise( - Invalid_argument( - "Arg.Expand is is only allowed with Arg.parse_and_expand_argv_dynamic", - ), - ) - } - let arg = get_arg() - let newarg = f(arg) - consume_arg() - let before = Array.sub(argv.contents, 0, current.contents + 1) - and after = Array.sub( - argv.contents, - current.contents + 1, - Array.length(argv.contents) - current.contents - 1, - ) - argv := Array.concat(list{before, newarg, after}) - } - - treat_action(action) - } else { - anonfun(s) - } - } catch { - | Bad(m) => raise(convert_error(Message(m))) - | Stop(e) => raise(convert_error(e)) - } - incr(current) - } -} - -let parse_and_expand_argv_dynamic = (current, argv, speclist, anonfun, errmsg) => - parse_and_expand_argv_dynamic_aux(true, current, argv, speclist, anonfun, errmsg) - -let parse_argv_dynamic = (~current=current, argv, speclist, anonfun, errmsg) => - parse_and_expand_argv_dynamic_aux(false, current, ref(argv), speclist, anonfun, errmsg) - -let parse_argv = (~current=current, argv, speclist, anonfun, errmsg) => - parse_argv_dynamic(~current, argv, ref(speclist), anonfun, errmsg) - -let parse = (l, f, msg) => - try parse_argv(Sys.argv, l, f, msg) catch { - | Bad(msg) => - Js.log(msg) - exit(2) - | Help(msg) => - Js.log(msg) - exit(0) - } - -let parse_dynamic = (l, f, msg) => - try parse_argv_dynamic(Sys.argv, l, f, msg) catch { - | Bad(msg) => - Js.log(msg) - exit(2) - | Help(msg) => - Js.log(msg) - exit(0) - } - -let parse_expand = (l, f, msg) => - try { - let argv = ref(Sys.argv) - let spec = ref(l) - let current = ref(current.contents) - parse_and_expand_argv_dynamic(current, argv, spec, f, msg) - } catch { - | Bad(msg) => - Js.log(msg) - exit(2) - | Help(msg) => - Js.log(msg) - exit(0) - } - -let second_word = s => { - let len = String.length(s) - let rec loop = n => - if n >= len { - len - } else if String.get(s, n) == ' ' { - loop(n + 1) - } else { - n - } - - switch String.index(s, '\t') { - | n => loop(n + 1) - | exception Not_found => - switch String.index(s, ' ') { - | n => loop(n + 1) - | exception Not_found => len - } - } -} - -let max_arg_len = (cur, (kwd, spec, doc)) => - switch spec { - | Symbol(_) => max(cur, String.length(kwd)) - | _ => max(cur, String.length(kwd) + second_word(doc)) - } - -let replace_leading_tab = s => { - let seen = ref(false) - String.map(c => - switch c { - | '\t' if !seen.contents => - seen := true - ' ' - | c => c - } - , s) -} - -let add_padding = (len, ksd) => - switch ksd { - | (_, _, "") => /* Do not pad undocumented options, so that they still don't show up when - * run through [usage] or [parse]. */ - ksd - | (kwd, Symbol(_) as spec, msg) => - let cutcol = second_word(msg) - let spaces = String.make(max(0, len - cutcol) + 3, ' ') - (kwd, spec, "\n" ++ (spaces ++ replace_leading_tab(msg))) - | (kwd, spec, msg) => - let cutcol = second_word(msg) - let kwd_len = String.length(kwd) - let diff = len - kwd_len - cutcol - if diff <= 0 { - (kwd, spec, replace_leading_tab(msg)) - } else { - let spaces = String.make(diff, ' ') - let prefix = String.sub(replace_leading_tab(msg), 0, cutcol) - let suffix = String.sub(msg, cutcol, String.length(msg) - cutcol) - (kwd, spec, prefix ++ (spaces ++ suffix)) - } - } - -let align = (~limit=max_int, speclist) => { - let completed = add_help(speclist) - let len = List.fold_left(max_arg_len, 0, completed) - let len = min(len, limit) - List.map(x => add_padding(len, x), completed) -} diff --git a/jscomp/stdlib-406/arg.resi b/jscomp/stdlib-406/arg.resi deleted file mode 100644 index e5b69162a1..0000000000 --- a/jscomp/stdlib-406/arg.resi +++ /dev/null @@ -1,186 +0,0 @@ -/*** Parsing of command line arguments. - - This module provides a general mechanism for extracting options and - arguments from the command line to the program. - - Syntax of command lines: - A keyword is a character string starting with a [-]. - An option is a keyword alone or followed by an argument. - The types of keywords are: [Unit], [Bool], [Set], [Clear], - [String], [Set_string], [Int], [Set_int], [Float], [Set_float], - [Tuple], [Symbol], and [Rest]. - [Unit], [Set] and [Clear] keywords take no argument. A [Rest] - keyword takes the remaining of the command line as arguments. - Every other keyword takes the following word on the command line - as argument. For compatibility with GNU getopt_long, [keyword=arg] - is also allowed. - Arguments not preceded by a keyword are called anonymous arguments. - - Examples ([cmd] is assumed to be the command name): -- [cmd -flag ](a unit option) -- [cmd -int 1 ](an int option with argument [1]) -- [cmd -string foobar ](a string option with argument ["foobar"]) -- [cmd -float 12.34 ](a float option with argument [12.34]) -- [cmd a b c ](three anonymous arguments: ["a"], ["b"], and ["c"]) -- [cmd a b -- c d ](two anonymous arguments and a rest option with - two arguments) -*/ - -/** The concrete type describing the behavior associated - with a keyword. */ -type rec spec = - | /** Call the function with unit argument */ Unit(unit => unit) - | /** Call the function with a bool argument */ Bool(bool => unit) - | /** Set the reference to true */ Set(ref) - | /** Set the reference to false */ Clear(ref) - | /** Call the function with a string argument */ String(string => unit) - | /** Set the reference to the string argument */ Set_string(ref) - | /** Call the function with an int argument */ Int(int => unit) - | /** Set the reference to the int argument */ Set_int(ref) - | /** Call the function with a float argument */ Float(float => unit) - | /** Set the reference to the float argument */ Set_float(ref) - | /** Take several arguments according to the - spec list */ - Tuple(list) - - | /** Take one of the symbols as argument and - call the function with the symbol */ - Symbol(list, string => unit) - - | /** Stop interpreting keywords and call the - function with each remaining argument */ - Rest(string => unit) - - | /** If the remaining arguments to process - are of the form - [["-foo"; "arg"] @ rest] where "foo" is - registered as [Expand f], then the - arguments [f "arg" @ rest] are - processed. Only allowed in - [parse_and_expand_argv_dynamic]. */ - Expand(string => array) - -type key = string -type doc = string -type usage_msg = string -type anon_fun = string => unit - -/** [Arg.parse speclist anon_fun usage_msg] parses the command line. - [speclist] is a list of triples [(key, spec, doc)]. - [key] is the option keyword, it must start with a ['-'] character. - [spec] gives the option type and the function to call when this option - is found on the command line. - [doc] is a one-line description of this option. - [anon_fun] is called on anonymous arguments. - The functions in [spec] and [anon_fun] are called in the same order - as their arguments appear on the command line. - - If an error occurs, [Arg.parse] exits the program, after printing - to standard error an error message as follows: -- The reason for the error: unknown option, invalid or missing argument, etc. -- [usage_msg] -- The list of options, each followed by the corresponding [doc] string. - Beware: options that have an empty [doc] string will not be included in the - list. - - For the user to be able to specify anonymous arguments starting with a - [-], include for example [("-", String anon_fun, doc)] in [speclist]. - - By default, [parse] recognizes two unit options, [-help] and [--help], - which will print to standard output [usage_msg] and the list of - options, and exit the program. You can override this behaviour - by specifying your own [-help] and [--help] options in [speclist]. -*/ -let parse: (list<(key, spec, doc)>, anon_fun, usage_msg) => unit - -/** Same as {!Arg.parse}, except that the [speclist] argument is a reference - and may be updated during the parsing. A typical use for this feature - is to parse command lines of the form: -- command subcommand [options] - where the list of options depends on the value of the subcommand argument. - @since 4.01.0 -*/ -let parse_dynamic: (ref>, anon_fun, usage_msg) => unit - -/** [Arg.parse_argv ~current args speclist anon_fun usage_msg] parses - the array [args] as if it were the command line. It uses and updates - the value of [~current] (if given), or {!Arg.current}. You must set - it before calling [parse_argv]. The initial value of [current] - is the index of the program name (argument 0) in the array. - If an error occurs, [Arg.parse_argv] raises {!Arg.Bad} with - the error message as argument. If option [-help] or [--help] is - given, [Arg.parse_argv] raises {!Arg.Help} with the help message - as argument. -*/ -let parse_argv: ( - ~current: ref=?, - array, - list<(key, spec, doc)>, - anon_fun, - usage_msg, -) => unit - -/** Same as {!Arg.parse_argv}, except that the [speclist] argument is a - reference and may be updated during the parsing. - See {!Arg.parse_dynamic}. - @since 4.01.0 -*/ -let parse_argv_dynamic: ( - ~current: ref=?, - array, - ref>, - anon_fun, - string, -) => unit - -/** Same as {!Arg.parse_argv_dynamic}, except that the [argv] argument is a - reference and may be updated during the parsing of [Expand] arguments. - See {!Arg.parse_argv_dynamic}. - @since 4.05.0 -*/ -let parse_and_expand_argv_dynamic: ( - ref, - ref>, - ref>, - anon_fun, - string, -) => unit - -/** Same as {!Arg.parse}, except that the [Expand] arguments are allowed and - the {!current} reference is not updated. - @since 4.05.0 -*/ -let parse_expand: (list<(key, spec, doc)>, anon_fun, usage_msg) => unit - -/** Raised by [Arg.parse_argv] when the user asks for help. */ exception Help(string) - -/** Functions in [spec] or [anon_fun] can raise [Arg.Bad] with an error - message to reject invalid arguments. - [Arg.Bad] is also raised by {!Arg.parse_argv} in case of an error. */ -exception Bad(string) - -/** [Arg.usage speclist usage_msg] prints to standard error - an error message that includes the list of valid options. This is - the same message that {!Arg.parse} prints in case of error. - [speclist] and [usage_msg] are the same as for {!Arg.parse}. */ -let usage: (list<(key, spec, doc)>, usage_msg) => unit - -/** Returns the message that would have been printed by {!Arg.usage}, - if provided with the same parameters. */ -let usage_string: (list<(key, spec, doc)>, usage_msg) => string - -/** Align the documentation strings by inserting spaces at the first alignment - separator (tab or, if tab is not found, space), according to the length of - the keyword. Use a alignment separator as the first character in a doc - string if you want to align the whole string. The doc strings corresponding - to [Symbol] arguments are aligned on the next line. - @param limit options with keyword and message longer than [limit] will not - be used to compute the alignment. */ -let align: (~limit: int=?, list<(key, spec, doc)>) => list<(key, spec, doc)> - -/** Position (in {!Sys.argv}) of the argument being processed. You can - change this value, e.g. to force {!Arg.parse} to skip some arguments. - {!Arg.parse} uses the initial value of {!Arg.current} as the index of - argument 0 (the program name) and starts parsing arguments - at the next element. */ -let current: ref diff --git a/jscomp/stdlib-406/arrayLabels.res b/jscomp/stdlib-406/arrayLabels.res deleted file mode 100644 index e67752553b..0000000000 --- a/jscomp/stdlib-406/arrayLabels.res +++ /dev/null @@ -1,410 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/* Array operations */ - -external length: array<'a> => int = "%array_length" -external get: (array<'a>, int) => 'a = "%array_safe_get" -external set: (array<'a>, int, 'a) => unit = "%array_safe_set" -external unsafe_get: (array<'a>, int) => 'a = "%array_unsafe_get" -external unsafe_set: (array<'a>, int, 'a) => unit = "%array_unsafe_set" -external make: (int, 'a) => array<'a> = "?make_vect" -external create: (int, 'a) => array<'a> = "?make_vect" -external unsafe_sub: (array<'a>, int, int) => array<'a> = "?array_sub" - -@send external append_prim: (array<'a>, array<'a>) => array<'a> = "concat" - -external concat: list> => array<'a> = "?array_concat" -external unsafe_blit: (array<'a>, int, array<'a>, int, int) => unit = "?array_blit" -external create_float: int => array = "?make_float_vect" -let make_float = create_float - -module Floatarray = { - external create: int => floatarray = "?floatarray_create" - external length: floatarray => int = "%floatarray_length" - external get: (floatarray, int) => float = "%floatarray_safe_get" - external set: (floatarray, int, float) => unit = "%floatarray_safe_set" - external unsafe_get: (floatarray, int) => float = "%floatarray_unsafe_get" - external unsafe_set: (floatarray, int, float) => unit = "%floatarray_unsafe_set" -} - -let init = (l, ~f) => - if l == 0 { - [] - } else if l < 0 { - invalid_arg("Array.init") - } else { - /* See #6575. We could also check for maximum array size, but this depends - on whether we create a float array or a regular one... */ - - let res = create(l, f(0)) - for i in 1 to pred(l) { - unsafe_set(res, i, f(i)) - } - res - } - -let make_matrix = (~dimx as sx, ~dimy as sy, init) => { - let res = create(sx, []) - for x in 0 to pred(sx) { - unsafe_set(res, x, create(sy, init)) - } - res -} - -let create_matrix = make_matrix - -let copy = a => { - let l = length(a) - if l == 0 { - [] - } else { - unsafe_sub(a, 0, l) - } -} - -let append = (a1, a2) => { - let l1 = length(a1) - if l1 == 0 { - copy(a2) - } else if length(a2) == 0 { - unsafe_sub(a1, 0, l1) - } else { - append_prim(a1, a2) - } -} - -let sub = (a, ~pos as ofs, ~len) => - if ofs < 0 || (len < 0 || ofs > length(a) - len) { - invalid_arg("Array.sub") - } else { - unsafe_sub(a, ofs, len) - } - -let fill = (a, ~pos as ofs, ~len, v) => - if ofs < 0 || (len < 0 || ofs > length(a) - len) { - invalid_arg("Array.fill") - } else { - for i in ofs to ofs + len - 1 { - unsafe_set(a, i, v) - } - } - -let blit = (~src as a1, ~src_pos as ofs1, ~dst as a2, ~dst_pos as ofs2, ~len) => - if len < 0 || (ofs1 < 0 || (ofs1 > length(a1) - len || (ofs2 < 0 || ofs2 > length(a2) - len))) { - invalid_arg("Array.blit") - } else { - unsafe_blit(a1, ofs1, a2, ofs2, len) - } - -let iter = (~f, a) => - for i in 0 to length(a) - 1 { - f(unsafe_get(a, i)) - } - -let iter2 = (~f, a, b) => - if length(a) != length(b) { - invalid_arg("Array.iter2: arrays must have the same length") - } else { - for i in 0 to length(a) - 1 { - f(unsafe_get(a, i), unsafe_get(b, i)) - } - } - -let map = (~f, a) => { - let l = length(a) - if l == 0 { - [] - } else { - let r = create(l, f(unsafe_get(a, 0))) - for i in 1 to l - 1 { - unsafe_set(r, i, f(unsafe_get(a, i))) - } - r - } -} - -let map2 = (~f, a, b) => { - let la = length(a) - let lb = length(b) - if la != lb { - invalid_arg("Array.map2: arrays must have the same length") - } else if la == 0 { - [] - } else { - let r = create(la, f(unsafe_get(a, 0), unsafe_get(b, 0))) - for i in 1 to la - 1 { - unsafe_set(r, i, f(unsafe_get(a, i), unsafe_get(b, i))) - } - r - } -} - -let iteri = (~f, a) => - for i in 0 to length(a) - 1 { - f(i, unsafe_get(a, i)) - } - -let mapi = (~f, a) => { - let l = length(a) - if l == 0 { - [] - } else { - let r = create(l, f(0, unsafe_get(a, 0))) - for i in 1 to l - 1 { - unsafe_set(r, i, f(i, unsafe_get(a, i))) - } - r - } -} - -let to_list = a => { - let rec tolist = (i, res) => - if i < 0 { - res - } else { - tolist(i - 1, list{unsafe_get(a, i), ...res}) - } - tolist(length(a) - 1, list{}) -} - -/* Cannot use List.length here because the List module depends on Array. */ -let rec list_length = (accu, param) => - switch param { - | list{} => accu - | list{_, ...t} => list_length(succ(accu), t) - } - -let of_list = param => - switch param { - | list{} => [] - | list{hd, ...tl} as l => - let a = create(list_length(0, l), hd) - let rec fill = (i, param) => - switch param { - | list{} => a - | list{hd, ...tl} => - unsafe_set(a, i, hd) - fill(i + 1, tl) - } - fill(1, tl) - } - -let fold_left = (~f, ~init as x, a) => { - let r = ref(x) - for i in 0 to length(a) - 1 { - r := f(r.contents, unsafe_get(a, i)) - } - r.contents -} - -let fold_right = (~f, a, ~init as x) => { - let r = ref(x) - for i in length(a) - 1 downto 0 { - r := f(unsafe_get(a, i), r.contents) - } - r.contents -} - -let exists = (~f as p, a) => { - let n = length(a) - let rec loop = i => - if i == n { - false - } else if p(unsafe_get(a, i)) { - true - } else { - loop(succ(i)) - } - loop(0) -} - -let for_all = (~f as p, a) => { - let n = length(a) - let rec loop = i => - if i == n { - true - } else if p(unsafe_get(a, i)) { - loop(succ(i)) - } else { - false - } - loop(0) -} - -let mem = (x, ~set as a) => { - let n = length(a) - let rec loop = i => - if i == n { - false - } else if compare(unsafe_get(a, i), x) == 0 { - true - } else { - loop(succ(i)) - } - loop(0) -} - -let memq = (x, ~set as a) => { - let n = length(a) - let rec loop = i => - if i == n { - false - } else if x === unsafe_get(a, i) { - true - } else { - loop(succ(i)) - } - loop(0) -} - -exception Bottom(int) -let sort = (~cmp, a) => { - let maxson = (l, i) => { - let i31 = i + i + i + 1 - let x = ref(i31) - if i31 + 2 < l { - if cmp(get(a, i31), get(a, i31 + 1)) < 0 { - x := i31 + 1 - } - if cmp(get(a, x.contents), get(a, i31 + 2)) < 0 { - x := i31 + 2 - } - x.contents - } else if i31 + 1 < l && cmp(get(a, i31), get(a, i31 + 1)) < 0 { - i31 + 1 - } else if i31 < l { - i31 - } else { - raise(Bottom(i)) - } - } - - let rec trickledown = (l, i, e) => { - let j = maxson(l, i) - if cmp(get(a, j), e) > 0 { - set(a, i, get(a, j)) - trickledown(l, j, e) - } else { - set(a, i, e) - } - } - - let trickle = (l, i, e) => - try trickledown(l, i, e) catch { - | Bottom(i) => set(a, i, e) - } - let rec bubbledown = (l, i) => { - let j = maxson(l, i) - set(a, i, get(a, j)) - bubbledown(l, j) - } - - let bubble = (l, i) => - try bubbledown(l, i) catch { - | Bottom(i) => i - } - let rec trickleup = (i, e) => { - let father = (i - 1) / 3 - assert(i != father) - if cmp(get(a, father), e) < 0 { - set(a, i, get(a, father)) - if father > 0 { - trickleup(father, e) - } else { - set(a, 0, e) - } - } else { - set(a, i, e) - } - } - - let l = length(a) - for i in (l + 1) / 3 - 1 downto 0 { - trickle(l, i, get(a, i)) - } - for i in l - 1 downto 2 { - let e = get(a, i) - set(a, i, get(a, 0)) - trickleup(bubble(i, 0), e) - } - if l > 1 { - let e = get(a, 1) - set(a, 1, get(a, 0)) - set(a, 0, e) - } -} - -let cutoff = 5 -let stable_sort = (~cmp, a) => { - let merge = (src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs) => { - let src1r = src1ofs + src1len and src2r = src2ofs + src2len - let rec loop = (i1, s1, i2, s2, d) => - if cmp(s1, s2) <= 0 { - set(dst, d, s1) - let i1 = i1 + 1 - if i1 < src1r { - loop(i1, get(a, i1), i2, s2, d + 1) - } else { - blit(~src=src2, ~src_pos=i2, ~dst, ~dst_pos=d + 1, ~len=src2r - i2) - } - } else { - set(dst, d, s2) - let i2 = i2 + 1 - if i2 < src2r { - loop(i1, s1, i2, get(src2, i2), d + 1) - } else { - blit(~src=a, ~src_pos=i1, ~dst, ~dst_pos=d + 1, ~len=src1r - i1) - } - } - loop(src1ofs, get(a, src1ofs), src2ofs, get(src2, src2ofs), dstofs) - } - - let isortto = (srcofs, dst, dstofs, len) => - for i in 0 to len - 1 { - let e = get(a, srcofs + i) - let j = ref(dstofs + i - 1) - while j.contents >= dstofs && cmp(get(dst, j.contents), e) > 0 { - set(dst, j.contents + 1, get(dst, j.contents)) - decr(j) - } - set(dst, j.contents + 1, e) - } - - let rec sortto = (srcofs, dst, dstofs, len) => - if len <= cutoff { - isortto(srcofs, dst, dstofs, len) - } else { - let l1 = len / 2 - let l2 = len - l1 - sortto(srcofs + l1, dst, dstofs + l1, l2) - sortto(srcofs, a, srcofs + l2, l1) - merge(srcofs + l2, l1, dst, dstofs + l1, l2, dst, dstofs) - } - - let l = length(a) - if l <= cutoff { - isortto(0, a, 0, l) - } else { - let l1 = l / 2 - let l2 = l - l1 - let t = make(l2, get(a, 0)) - sortto(l1, t, 0, l2) - sortto(0, a, l2, l1) - merge(l2, l1, t, 0, l2, a, 0) - } -} - -let fast_sort = stable_sort diff --git a/jscomp/stdlib-406/arrayLabels.resi b/jscomp/stdlib-406/arrayLabels.resi deleted file mode 100644 index 1a211691d3..0000000000 --- a/jscomp/stdlib-406/arrayLabels.resi +++ /dev/null @@ -1,264 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/*** Array operations. */ - -/** Return the length (number of elements) of the given array. */ -external length: array<'a> => int = "%array_length" - -/** [Array.get a n] returns the element number [n] of array [a]. - The first element has number 0. - The last element has number [Array.length a - 1]. - You can also write [a.(n)] instead of [Array.get a n]. - - Raise [Invalid_argument "index out of bounds"] - if [n] is outside the range 0 to [(Array.length a - 1)]. */ -external get: (array<'a>, int) => 'a = "%array_safe_get" - -/** [Array.set a n x] modifies array [a] in place, replacing - element number [n] with [x]. - You can also write [a.(n) <- x] instead of [Array.set a n x]. - - Raise [Invalid_argument "index out of bounds"] - if [n] is outside the range 0 to [Array.length a - 1]. */ -external set: (array<'a>, int, 'a) => unit = "%array_safe_set" - -/** [Array.make n x] returns a fresh array of length [n], - initialized with [x]. - All the elements of this new array are initially - physically equal to [x] (in the sense of the [==] predicate). - Consequently, if [x] is mutable, it is shared among all elements - of the array, and modifying [x] through one of the array entries - will modify all other entries at the same time. - - Raise [Invalid_argument] if [n < 0] or [n > Sys.max_array_length]. - If the value of [x] is a floating-point number, then the maximum - size is only [Sys.max_array_length / 2].*/ -external make: (int, 'a) => array<'a> = "?make_vect" - -@deprecated("Use Array.make instead.") -/** @deprecated [Array.create] is an alias for {!Array.make}. */ -external create: (int, 'a) => array<'a> = "?make_vect" - -/** [Array.init n f] returns a fresh array of length [n], - with element number [i] initialized to the result of [f i]. - In other terms, [Array.init n f] tabulates the results of [f] - applied to the integers [0] to [n-1]. - - Raise [Invalid_argument] if [n < 0] or [n > Sys.max_array_length]. - If the return type of [f] is [float], then the maximum - size is only [Sys.max_array_length / 2].*/ -let init: (int, ~f: int => 'a) => array<'a> - -/** [Array.make_matrix dimx dimy e] returns a two-dimensional array - (an array of arrays) with first dimension [dimx] and - second dimension [dimy]. All the elements of this new matrix - are initially physically equal to [e]. - The element ([x,y]) of a matrix [m] is accessed - with the notation [m.(x).(y)]. - - Raise [Invalid_argument] if [dimx] or [dimy] is negative or - greater than {!Sys.max_array_length}. - If the value of [e] is a floating-point number, then the maximum - size is only [Sys.max_array_length / 2]. */ -let make_matrix: (~dimx: int, ~dimy: int, 'a) => array> - -@deprecated("Use Array.make_matrix instead.") -/** @deprecated [Array.create_matrix] is an alias for - {!Array.make_matrix}. */ -let create_matrix: (~dimx: int, ~dimy: int, 'a) => array> - -/** [Array.append v1 v2] returns a fresh array containing the - concatenation of the arrays [v1] and [v2]. */ -let append: (array<'a>, array<'a>) => array<'a> - -/** Same as {!Array.append}, but concatenates a list of arrays. */ -let concat: list> => array<'a> - -/** [Array.sub a start len] returns a fresh array of length [len], - containing the elements number [start] to [start + len - 1] - of array [a]. - - Raise [Invalid_argument "Array.sub"] if [start] and [len] do not - designate a valid subarray of [a]; that is, if - [start < 0], or [len < 0], or [start + len > Array.length a]. */ -let sub: (array<'a>, ~pos: int, ~len: int) => array<'a> - -/** [Array.copy a] returns a copy of [a], that is, a fresh array - containing the same elements as [a]. */ -let copy: array<'a> => array<'a> - -/** [Array.fill a ofs len x] modifies the array [a] in place, - storing [x] in elements number [ofs] to [ofs + len - 1]. - - Raise [Invalid_argument "Array.fill"] if [ofs] and [len] do not - designate a valid subarray of [a]. */ -let fill: (array<'a>, ~pos: int, ~len: int, 'a) => unit - -/** [Array.blit v1 o1 v2 o2 len] copies [len] elements - from array [v1], starting at element number [o1], to array [v2], - starting at element number [o2]. It works correctly even if - [v1] and [v2] are the same array, and the source and - destination chunks overlap. - - Raise [Invalid_argument "Array.blit"] if [o1] and [len] do not - designate a valid subarray of [v1], or if [o2] and [len] do not - designate a valid subarray of [v2]. */ -let blit: (~src: array<'a>, ~src_pos: int, ~dst: array<'a>, ~dst_pos: int, ~len: int) => unit - -/** [Array.to_list a] returns the list of all the elements of [a]. */ -let to_list: array<'a> => list<'a> - -/** [Array.of_list l] returns a fresh array containing the elements - of [l]. */ -let of_list: list<'a> => array<'a> - -/** [Array.iter f a] applies function [f] in turn to all - the elements of [a]. It is equivalent to - [f a.(0); f a.(1); ...; f a.(Array.length a - 1); ()]. */ -let iter: (~f: 'a => unit, array<'a>) => unit - -/** [Array.map f a] applies function [f] to all the elements of [a], - and builds an array with the results returned by [f]: - [[| f a.(0); f a.(1); ...; f a.(Array.length a - 1) |]]. */ -let map: (~f: 'a => 'b, array<'a>) => array<'b> - -/** Same as {!Array.iter}, but the - function is applied to the index of the element as first argument, - and the element itself as second argument. */ -let iteri: (~f: (int, 'a) => unit, array<'a>) => unit - -/** Same as {!Array.map}, but the - function is applied to the index of the element as first argument, - and the element itself as second argument. */ -let mapi: (~f: (int, 'a) => 'b, array<'a>) => array<'b> - -/** [Array.fold_left f x a] computes - [f (... (f (f x a.(0)) a.(1)) ...) a.(n-1)], - where [n] is the length of the array [a]. */ -let fold_left: (~f: ('a, 'b) => 'a, ~init: 'a, array<'b>) => 'a - -/** [Array.fold_right f a x] computes - [f a.(0) (f a.(1) ( ... (f a.(n-1) x) ...))], - where [n] is the length of the array [a]. */ -let fold_right: (~f: ('b, 'a) => 'a, array<'b>, ~init: 'a) => 'a - -/* {6 Iterators on two arrays} */ - -/** [Array.iter2 f a b] applies function [f] to all the elements of [a] - and [b]. - Raise [Invalid_argument] if the arrays are not the same size. - @since 4.05.0 */ -let iter2: (~f: ('a, 'b) => unit, array<'a>, array<'b>) => unit - -/** [Array.map2 f a b] applies function [f] to all the elements of [a] - and [b], and builds an array with the results returned by [f]: - [[| f a.(0) b.(0); ...; f a.(Array.length a - 1) b.(Array.length b - 1)|]]. - Raise [Invalid_argument] if the arrays are not the same size. - @since 4.05.0 */ -let map2: (~f: ('a, 'b) => 'c, array<'a>, array<'b>) => array<'c> - -/* {6 Array scanning} */ - -/** [Array.exists p [|a1; ...; an|]] checks if at least one element of - the array satisfies the predicate [p]. That is, it returns - [(p a1) || (p a2) || ... || (p an)]. - @since 4.03.0 */ -let exists: (~f: 'a => bool, array<'a>) => bool - -/** [Array.for_all p [|a1; ...; an|]] checks if all elements of the array - satisfy the predicate [p]. That is, it returns - [(p a1) && (p a2) && ... && (p an)]. - @since 4.03.0 */ -let for_all: (~f: 'a => bool, array<'a>) => bool - -/** [mem x a] is true if and only if [x] is equal - to an element of [a]. - @since 4.03.0 */ -let mem: ('a, ~set: array<'a>) => bool - -/** Same as {!Array.mem}, but uses physical equality instead of structural - equality to compare list elements. - @since 4.03.0 */ -let memq: ('a, ~set: array<'a>) => bool - -/** [Array.create_float n] returns a fresh float array of length [n], - with uninitialized data. - @since 4.03 */ -external create_float: int => array = "?make_float_vect" - -@deprecated("Use Array.create_float instead.") -/** @deprecated [Array.make_float] is an alias for - {!Array.create_float}. */ -let make_float: int => array - -/* {1 Sorting} */ - -/** Sort an array in increasing order according to a comparison - function. The comparison function must return 0 if its arguments - compare as equal, a positive integer if the first is greater, - and a negative integer if the first is smaller (see below for a - complete specification). For example, {!Pervasives.compare} is - a suitable comparison function, provided there are no floating-point - NaN values in the data. After calling [Array.sort], the - array is sorted in place in increasing order. - [Array.sort] is guaranteed to run in constant heap space - and (at most) logarithmic stack space. - - The current implementation uses Heap Sort. It runs in constant - stack space. - - Specification of the comparison function: - Let [a] be the array and [cmp] the comparison function. The following - must be true for all x, y, z in a : -- [cmp x y] > 0 if and only if [cmp y x] < 0 -- if [cmp x y] >= 0 and [cmp y z] >= 0 then [cmp x z] >= 0 - - When [Array.sort] returns, [a] contains the same elements as before, - reordered in such a way that for all i and j valid indices of [a] : -- [cmp a.(i) a.(j)] >= 0 if and only if i >= j -*/ -let sort: (~cmp: ('a, 'a) => int, array<'a>) => unit - -/** Same as {!Array.sort}, but the sorting algorithm is stable (i.e. - elements that compare equal are kept in their original order) and - not guaranteed to run in constant heap space. - - The current implementation uses Merge Sort. It uses [n/2] - words of heap space, where [n] is the length of the array. - It is usually faster than the current implementation of {!Array.sort}. -*/ -let stable_sort: (~cmp: ('a, 'a) => int, array<'a>) => unit - -/** Same as {!Array.sort} or {!Array.stable_sort}, whichever is - faster on typical input. -*/ -let fast_sort: (~cmp: ('a, 'a) => int, array<'a>) => unit - -/* {1 Undocumented functions} */ - -/* The following is for system use only. Do not call directly. */ - -external unsafe_get: (array<'a>, int) => 'a = "%array_unsafe_get" -external unsafe_set: (array<'a>, int, 'a) => unit = "%array_unsafe_set" - -module Floatarray: { - external create: int => floatarray = "?floatarray_create" - external length: floatarray => int = "%floatarray_length" - external get: (floatarray, int) => float = "%floatarray_safe_get" - external set: (floatarray, int, float) => unit = "%floatarray_safe_set" - external unsafe_get: (floatarray, int) => float = "%floatarray_unsafe_get" - external unsafe_set: (floatarray, int, float) => unit = "%floatarray_unsafe_set" -} diff --git a/jscomp/stdlib-406/buffer.res b/jscomp/stdlib-406/buffer.res deleted file mode 100644 index 6d9db8c24d..0000000000 --- a/jscomp/stdlib-406/buffer.res +++ /dev/null @@ -1,307 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Pierre Weis and Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1999 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. */ -/* */ -/* ************************************************************************ */ - -/* Extensible buffers */ - -type t = { - mutable buffer: bytes, - mutable position: int, - mutable length: int, - initial_buffer: bytes, -} - -let create = n => { - let n = if n < 1 { - 1 - } else { - n - } - let s = Bytes.create(n) - {buffer: s, position: 0, length: n, initial_buffer: s} -} - -let contents = b => Bytes.sub_string(b.buffer, 0, b.position) -let to_bytes = b => Bytes.sub(b.buffer, 0, b.position) - -let sub = (b, ofs, len) => - if ofs < 0 || (len < 0 || ofs > b.position - len) { - invalid_arg("Buffer.sub") - } else { - Bytes.sub_string(b.buffer, ofs, len) - } - -let blit = (src, srcoff, dst, dstoff, len) => - if ( - len < 0 || - (srcoff < 0 || - (srcoff > src.position - len || (dstoff < 0 || dstoff > Bytes.length(dst) - len))) - ) { - invalid_arg("Buffer.blit") - } else { - Bytes.blit(src.buffer, srcoff, dst, dstoff, len) - } - -let nth = (b, ofs) => - if ofs < 0 || ofs >= b.position { - invalid_arg("Buffer.nth") - } else { - Bytes.unsafe_get(b.buffer, ofs) - } - -let length = b => b.position - -let clear = b => b.position = 0 - -let reset = b => { - b.position = 0 - b.buffer = b.initial_buffer - b.length = Bytes.length(b.buffer) -} - -let resize = (b, more) => { - let len = b.length - let new_len = ref(len) - while b.position + more > new_len.contents { - new_len := 2 * new_len.contents - } - let new_buffer = Bytes.create(new_len.contents) - /* PR#6148: let's keep using [blit] rather than [unsafe_blit] in - this tricky function that is slow anyway. */ - Bytes.blit(b.buffer, 0, new_buffer, 0, b.position) - b.buffer = new_buffer - b.length = new_len.contents -} - -let add_char = (b, c) => { - let pos = b.position - if pos >= b.length { - resize(b, 1) - } - Bytes.unsafe_set(b.buffer, pos, c) - b.position = pos + 1 -} - -let add_utf_8_uchar = (b, u) => - switch Uchar.to_int(u) { - | u if u < 0 => assert(false) - | u if u <= 0x007F => add_char(b, Char.unsafe_chr(u)) - | u if u <= 0x07FF => - let pos = b.position - if pos + 2 > b.length { - resize(b, 2) - } - Bytes.unsafe_set(b.buffer, pos, Char.unsafe_chr(lor(0xC0, lsr(u, 6)))) - Bytes.unsafe_set(b.buffer, pos + 1, Char.unsafe_chr(lor(0x80, land(u, 0x3F)))) - b.position = pos + 2 - | u if u <= 0xFFFF => - let pos = b.position - if pos + 3 > b.length { - resize(b, 3) - } - Bytes.unsafe_set(b.buffer, pos, Char.unsafe_chr(lor(0xE0, lsr(u, 12)))) - Bytes.unsafe_set(b.buffer, pos + 1, Char.unsafe_chr(lor(0x80, land(lsr(u, 6), 0x3F)))) - Bytes.unsafe_set(b.buffer, pos + 2, Char.unsafe_chr(lor(0x80, land(u, 0x3F)))) - b.position = pos + 3 - | u if u <= 0x10FFFF => - let pos = b.position - if pos + 4 > b.length { - resize(b, 4) - } - Bytes.unsafe_set(b.buffer, pos, Char.unsafe_chr(lor(0xF0, lsr(u, 18)))) - Bytes.unsafe_set(b.buffer, pos + 1, Char.unsafe_chr(lor(0x80, land(lsr(u, 12), 0x3F)))) - Bytes.unsafe_set(b.buffer, pos + 2, Char.unsafe_chr(lor(0x80, land(lsr(u, 6), 0x3F)))) - Bytes.unsafe_set(b.buffer, pos + 3, Char.unsafe_chr(lor(0x80, land(u, 0x3F)))) - b.position = pos + 4 - | _ => assert(false) - } - -let add_utf_16be_uchar = (b, u) => - switch Uchar.to_int(u) { - | u if u < 0 => assert(false) - | u if u <= 0xFFFF => - let pos = b.position - if pos + 2 > b.length { - resize(b, 2) - } - Bytes.unsafe_set(b.buffer, pos, Char.unsafe_chr(lsr(u, 8))) - Bytes.unsafe_set(b.buffer, pos + 1, Char.unsafe_chr(land(u, 0xFF))) - b.position = pos + 2 - | u if u <= 0x10FFFF => - let u' = u - 0x10000 - let hi = lor(0xD800, lsr(u', 10)) - let lo = lor(0xDC00, land(u', 0x3FF)) - let pos = b.position - if pos + 4 > b.length { - resize(b, 4) - } - Bytes.unsafe_set(b.buffer, pos, Char.unsafe_chr(lsr(hi, 8))) - Bytes.unsafe_set(b.buffer, pos + 1, Char.unsafe_chr(land(hi, 0xFF))) - Bytes.unsafe_set(b.buffer, pos + 2, Char.unsafe_chr(lsr(lo, 8))) - Bytes.unsafe_set(b.buffer, pos + 3, Char.unsafe_chr(land(lo, 0xFF))) - b.position = pos + 4 - | _ => assert(false) - } - -let add_utf_16le_uchar = (b, u) => - switch Uchar.to_int(u) { - | u if u < 0 => assert(false) - | u if u <= 0xFFFF => - let pos = b.position - if pos + 2 > b.length { - resize(b, 2) - } - Bytes.unsafe_set(b.buffer, pos, Char.unsafe_chr(land(u, 0xFF))) - Bytes.unsafe_set(b.buffer, pos + 1, Char.unsafe_chr(lsr(u, 8))) - b.position = pos + 2 - | u if u <= 0x10FFFF => - let u' = u - 0x10000 - let hi = lor(0xD800, lsr(u', 10)) - let lo = lor(0xDC00, land(u', 0x3FF)) - let pos = b.position - if pos + 4 > b.length { - resize(b, 4) - } - Bytes.unsafe_set(b.buffer, pos, Char.unsafe_chr(land(hi, 0xFF))) - Bytes.unsafe_set(b.buffer, pos + 1, Char.unsafe_chr(lsr(hi, 8))) - Bytes.unsafe_set(b.buffer, pos + 2, Char.unsafe_chr(land(lo, 0xFF))) - Bytes.unsafe_set(b.buffer, pos + 3, Char.unsafe_chr(lsr(lo, 8))) - b.position = pos + 4 - | _ => assert(false) - } - -let add_substring = (b, s, offset, len) => { - if offset < 0 || (len < 0 || offset > String.length(s) - len) { - invalid_arg("Buffer.add_substring/add_subbytes") - } - let new_position = b.position + len - if new_position > b.length { - resize(b, len) - } - Bytes.blit_string(s, offset, b.buffer, b.position, len) - b.position = new_position -} - -let add_subbytes = (b, s, offset, len) => add_substring(b, Bytes.unsafe_to_string(s), offset, len) - -let add_string = (b, s) => { - let len = String.length(s) - let new_position = b.position + len - if new_position > b.length { - resize(b, len) - } - Bytes.blit_string(s, 0, b.buffer, b.position, len) - b.position = new_position -} - -let add_bytes = (b, s) => add_string(b, Bytes.unsafe_to_string(s)) - -let add_buffer = (b, bs) => add_subbytes(b, bs.buffer, 0, bs.position) - -let closing = param => - switch param { - | '(' => ')' - | '{' => '}' - | _ => assert(false) - } - -/* opening and closing: open and close characters, typically ( and ) - k: balance of opening and closing chars - s: the string where we are searching - start: the index where we start the search. */ -let advance_to_closing = (opening, closing, k, s, start) => { - let rec advance = (k, i, lim) => - if i >= lim { - raise(Not_found) - } else if String.get(s, i) == opening { - advance(k + 1, i + 1, lim) - } else if String.get(s, i) == closing { - if k == 0 { - i - } else { - advance(k - 1, i + 1, lim) - } - } else { - advance(k, i + 1, lim) - } - advance(k, start, String.length(s)) -} - -let advance_to_non_alpha = (s, start) => { - let rec advance = (i, lim) => - if i >= lim { - lim - } else { - switch String.get(s, i) { - | 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_' => advance(i + 1, lim) - | _ => i - } - } - advance(start, String.length(s)) -} - -/* We are just at the beginning of an ident in s, starting at start. */ -let find_ident = (s, start, lim) => - if start >= lim { - raise(Not_found) - } else { - switch String.get(s, start) { - /* Parenthesized ident ? */ - | ('(' | '{') as c => - let new_start = start + 1 - let stop = advance_to_closing(c, closing(c), 0, s, new_start) - (String.sub(s, new_start, stop - start - 1), stop + 1) - /* Regular ident */ - | _ => - let stop = advance_to_non_alpha(s, start + 1) - (String.sub(s, start, stop - start), stop) - } - } - -/* Substitute $ident, $(ident), or ${ident} in s, - according to the function mapping f. */ -let add_substitute = (b, f, s) => { - let lim = String.length(s) - let rec subst = (previous, i) => - if i < lim { - switch String.get(s, i) { - | '$' as current if previous == '\\' => - add_char(b, current) - subst(' ', i + 1) - | '$' => - let j = i + 1 - let (ident, next_i) = find_ident(s, j, lim) - add_string(b, f(ident)) - subst(' ', next_i) - | current if previous === '\\' => - add_char(b, '\\') - add_char(b, current) - subst(' ', i + 1) - | '\\' as current => subst(current, i + 1) - | current => - add_char(b, current) - subst(current, i + 1) - } - } else if previous == '\\' { - add_char(b, previous) - } - subst(' ', 0) -} - -let truncate = (b, len) => - if len < 0 || len > length(b) { - invalid_arg("Buffer.truncate") - } else { - b.position = len - } diff --git a/jscomp/stdlib-406/buffer.resi b/jscomp/stdlib-406/buffer.resi deleted file mode 100644 index 9929a1d2ff..0000000000 --- a/jscomp/stdlib-406/buffer.resi +++ /dev/null @@ -1,148 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Pierre Weis and Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1999 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. */ -/* */ -/* ************************************************************************ */ - -/*** Extensible buffers. - - This module implements buffers that automatically expand - as necessary. It provides accumulative concatenation of strings - in quasi-linear time (instead of quadratic time when strings are - concatenated pairwise). -*/ - -/** The abstract type of buffers. */ -type t - -/** [create n] returns a fresh buffer, initially empty. - The [n] parameter is the initial size of the internal byte sequence - that holds the buffer contents. That byte sequence is automatically - reallocated when more than [n] characters are stored in the buffer, - but shrinks back to [n] characters when [reset] is called. - For best performance, [n] should be of the same order of magnitude - as the number of characters that are expected to be stored in - the buffer (for instance, 80 for a buffer that holds one output - line). Nothing bad will happen if the buffer grows beyond that - limit, however. In doubt, take [n = 16] for instance. - If [n] is not between 1 and {!Sys.max_string_length}, it will - be clipped to that interval. */ -let create: int => t - -/** Return a copy of the current contents of the buffer. - The buffer itself is unchanged. */ -let contents: t => string - -/** Return a copy of the current contents of the buffer. - The buffer itself is unchanged. - @since 4.02 */ -let to_bytes: t => bytes - -/** [Buffer.sub b off len] returns a copy of [len] bytes from the - current contents of the buffer [b], starting at offset [off]. - - Raise [Invalid_argument] if [srcoff] and [len] do not designate a valid - range of [b]. */ -let sub: (t, int, int) => string - -/** [Buffer.blit src srcoff dst dstoff len] copies [len] characters from - the current contents of the buffer [src], starting at offset [srcoff] - to [dst], starting at character [dstoff]. - - Raise [Invalid_argument] if [srcoff] and [len] do not designate a valid - range of [src], or if [dstoff] and [len] do not designate a valid - range of [dst]. - @since 3.11.2 -*/ -let blit: (t, int, bytes, int, int) => unit - -/** Get the n-th character of the buffer. Raise [Invalid_argument] if - index out of bounds */ -let nth: (t, int) => char - -/** Return the number of characters currently contained in the buffer. */ -let length: t => int - -/** Empty the buffer. */ -let clear: t => unit - -/** Empty the buffer and deallocate the internal byte sequence holding the - buffer contents, replacing it with the initial internal byte sequence - of length [n] that was allocated by {!Buffer.create} [n]. - For long-lived buffers that may have grown a lot, [reset] allows - faster reclamation of the space used by the buffer. */ -let reset: t => unit - -/** [add_char b c] appends the character [c] at the end of buffer [b]. */ -let add_char: (t, char) => unit - -/** [add_utf_8_uchar b u] appends the {{:https://tools.ietf.org/html/rfc3629} - UTF-8} encoding of [u] at the end of buffer [b]. - - @since 4.06.0 */ -let add_utf_8_uchar: (t, Uchar.t) => unit - -/** [add_utf_16le_uchar b u] appends the - {{:https://tools.ietf.org/html/rfc2781}UTF-16LE} encoding of [u] - at the end of buffer [b]. - - @since 4.06.0 */ -let add_utf_16le_uchar: (t, Uchar.t) => unit - -/** [add_utf_16be_uchar b u] appends the - {{:https://tools.ietf.org/html/rfc2781}UTF-16BE} encoding of [u] - at the end of buffer [b]. - - @since 4.06.0 */ -let add_utf_16be_uchar: (t, Uchar.t) => unit - -/** [add_string b s] appends the string [s] at the end of buffer [b]. */ -let add_string: (t, string) => unit - -/** [add_bytes b s] appends the byte sequence [s] at the end of buffer [b]. - @since 4.02 */ -let add_bytes: (t, bytes) => unit - -/** [add_substring b s ofs len] takes [len] characters from offset - [ofs] in string [s] and appends them at the end of buffer [b]. */ -let add_substring: (t, string, int, int) => unit - -/** [add_subbytes b s ofs len] takes [len] characters from offset - [ofs] in byte sequence [s] and appends them at the end of buffer [b]. - @since 4.02 */ -let add_subbytes: (t, bytes, int, int) => unit - -/** [add_substitute b f s] appends the string pattern [s] at the end - of buffer [b] with substitution. - The substitution process looks for variables into - the pattern and substitutes each variable name by its value, as - obtained by applying the mapping [f] to the variable name. Inside the - string pattern, a variable name immediately follows a non-escaped - [$] character and is one of the following: - - a non empty sequence of alphanumeric or [_] characters, - - an arbitrary sequence of characters enclosed by a pair of - matching parentheses or curly brackets. - An escaped [$] character is a [$] that immediately follows a backslash - character; it then stands for a plain [$]. - Raise [Not_found] if the closing character of a parenthesized variable - cannot be found. */ -let add_substitute: (t, string => string, string) => unit - -/** [add_buffer b1 b2] appends the current contents of buffer [b2] - at the end of buffer [b1]. [b2] is not modified. */ -let add_buffer: (t, t) => unit - -/** [truncate b len] truncates the length of [b] to [len] - Note: the internal byte sequence is not shortened. - Raise [Invalid_argument] if [len < 0] or [len > length b]. - @since 4.05.0 */ -let truncate: (t, int) => unit diff --git a/jscomp/stdlib-406/bytes.res b/jscomp/stdlib-406/bytes.res deleted file mode 100644 index d7f9c5cb7b..0000000000 Binary files a/jscomp/stdlib-406/bytes.res and /dev/null differ diff --git a/jscomp/stdlib-406/bytes.resi b/jscomp/stdlib-406/bytes.resi deleted file mode 100644 index 2b65cb4695..0000000000 --- a/jscomp/stdlib-406/bytes.resi +++ /dev/null @@ -1,427 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/*** Byte sequence operations. - - A byte sequence is a mutable data structure that contains a - fixed-length sequence of bytes. Each byte can be indexed in - constant time for reading or writing. - - Given a byte sequence [s] of length [l], we can access each of the - [l] bytes of [s] via its index in the sequence. Indexes start at - [0], and we will call an index valid in [s] if it falls within the - range [[0...l-1]] (inclusive). A position is the point between two - bytes or at the beginning or end of the sequence. We call a - position valid in [s] if it falls within the range [[0...l]] - (inclusive). Note that the byte at index [n] is between positions - [n] and [n+1]. - - Two parameters [start] and [len] are said to designate a valid - range of [s] if [len >= 0] and [start] and [start+len] are valid - positions in [s]. - - Byte sequences can be modified in place, for instance via the [set] - and [blit] functions described below. See also strings (module - {!String}), which are almost the same data structure, but cannot be - modified in place. - - Bytes are represented by the OCaml type [char]. - - @since 4.02.0 -*/ - -/** Return the length (number of bytes) of the argument. */ -external length: bytes => int = "%bytes_length" - -/** [get s n] returns the byte at index [n] in argument [s]. - - Raise [Invalid_argument] if [n] is not a valid index in [s]. */ -external get: (bytes, int) => char = "%bytes_safe_get" - -/** [set s n c] modifies [s] in place, replacing the byte at index [n] - with [c]. - - Raise [Invalid_argument] if [n] is not a valid index in [s]. */ -external set: (bytes, int, char) => unit = "%bytes_safe_set" - -/** [create n] returns a new byte sequence of length [n]. The - sequence is uninitialized and contains arbitrary bytes. - - Raise [Invalid_argument] if [n < 0] or [n > ]{!Sys.max_string_length}. */ -external create: int => bytes = "?create_bytes" - -/** [make n c] returns a new byte sequence of length [n], filled with - the byte [c]. - - Raise [Invalid_argument] if [n < 0] or [n > ]{!Sys.max_string_length}. */ -let make: (int, char) => bytes - -/** [Bytes.init n f] returns a fresh byte sequence of length [n], with - character [i] initialized to the result of [f i] (in increasing - index order). - - Raise [Invalid_argument] if [n < 0] or [n > ]{!Sys.max_string_length}. */ -let init: (int, int => char) => bytes - -/** A byte sequence of size 0. */ -let empty: bytes - -/** Return a new byte sequence that contains the same bytes as the - argument. */ -let copy: bytes => bytes - -/** Return a new byte sequence that contains the same bytes as the - given string. */ -let of_string: string => bytes - -/** Return a new string that contains the same bytes as the given byte - sequence. */ -let to_string: bytes => string - -/** [sub s start len] returns a new byte sequence of length [len], - containing the subsequence of [s] that starts at position [start] - and has length [len]. - - Raise [Invalid_argument] if [start] and [len] do not designate a - valid range of [s]. */ -let sub: (bytes, int, int) => bytes - -/** Same as [sub] but return a string instead of a byte sequence. */ -let sub_string: (bytes, int, int) => string - -/** [extend s left right] returns a new byte sequence that contains - the bytes of [s], with [left] uninitialized bytes prepended and - [right] uninitialized bytes appended to it. If [left] or [right] - is negative, then bytes are removed (instead of appended) from - the corresponding side of [s]. - - Raise [Invalid_argument] if the result length is negative or - longer than {!Sys.max_string_length} bytes. */ -let extend: (bytes, int, int) => bytes - -/** [fill s start len c] modifies [s] in place, replacing [len] - characters with [c], starting at [start]. - - Raise [Invalid_argument] if [start] and [len] do not designate a - valid range of [s]. */ -let fill: (bytes, int, int, char) => unit - -/** [blit src srcoff dst dstoff len] copies [len] bytes from sequence - [src], starting at index [srcoff], to sequence [dst], starting at - index [dstoff]. It works correctly even if [src] and [dst] are the - same byte sequence, and the source and destination intervals - overlap. - - Raise [Invalid_argument] if [srcoff] and [len] do not - designate a valid range of [src], or if [dstoff] and [len] - do not designate a valid range of [dst]. */ -let blit: (bytes, int, bytes, int, int) => unit - -/** [blit src srcoff dst dstoff len] copies [len] bytes from string - [src], starting at index [srcoff], to byte sequence [dst], - starting at index [dstoff]. - - Raise [Invalid_argument] if [srcoff] and [len] do not - designate a valid range of [src], or if [dstoff] and [len] - do not designate a valid range of [dst]. */ -let blit_string: (string, int, bytes, int, int) => unit - -/** [concat sep sl] concatenates the list of byte sequences [sl], - inserting the separator byte sequence [sep] between each, and - returns the result as a new byte sequence. - - Raise [Invalid_argument] if the result is longer than - {!Sys.max_string_length} bytes. */ -let concat: (bytes, list) => bytes - -/** [cat s1 s2] concatenates [s1] and [s2] and returns the result - as new byte sequence. - - Raise [Invalid_argument] if the result is longer than - {!Sys.max_string_length} bytes. */ -let cat: (bytes, bytes) => bytes - -/** [iter f s] applies function [f] in turn to all the bytes of [s]. - It is equivalent to [f (get s 0); f (get s 1); ...; f (get s - (length s - 1)); ()]. */ -let iter: (char => unit, bytes) => unit - -/** Same as {!Bytes.iter}, but the function is applied to the index of - the byte as first argument and the byte itself as second - argument. */ -let iteri: ((int, char) => unit, bytes) => unit - -/** [map f s] applies function [f] in turn to all the bytes of [s] - (in increasing index order) and stores the resulting bytes in - a new sequence that is returned as the result. */ -let map: (char => char, bytes) => bytes - -/** [mapi f s] calls [f] with each character of [s] and its - index (in increasing index order) and stores the resulting bytes - in a new sequence that is returned as the result. */ -let mapi: ((int, char) => char, bytes) => bytes - -/** Return a copy of the argument, without leading and trailing - whitespace. The bytes regarded as whitespace are the ASCII - characters [' '], ['\x0c'], ['\n'], ['\r'], and ['\t']. */ -let trim: bytes => bytes - -/** Return a copy of the argument, with special characters represented - by escape sequences, following the lexical conventions of OCaml. - All characters outside the ASCII printable range (32..126) are - escaped, as well as backslash and double-quote. - - Raise [Invalid_argument] if the result is longer than - {!Sys.max_string_length} bytes. */ -let escaped: bytes => bytes - -/** [index s c] returns the index of the first occurrence of byte [c] - in [s]. - - Raise [Not_found] if [c] does not occur in [s]. */ -let index: (bytes, char) => int - -/** [index_opt s c] returns the index of the first occurrence of byte [c] - in [s] or [None] if [c] does not occur in [s]. - @since 4.05 */ -let index_opt: (bytes, char) => option - -/** [rindex s c] returns the index of the last occurrence of byte [c] - in [s]. - - Raise [Not_found] if [c] does not occur in [s]. */ -let rindex: (bytes, char) => int - -/** [rindex_opt s c] returns the index of the last occurrence of byte [c] - in [s] or [None] if [c] does not occur in [s]. - @since 4.05 */ -let rindex_opt: (bytes, char) => option - -/** [index_from s i c] returns the index of the first occurrence of - byte [c] in [s] after position [i]. [Bytes.index s c] is - equivalent to [Bytes.index_from s 0 c]. - - Raise [Invalid_argument] if [i] is not a valid position in [s]. - Raise [Not_found] if [c] does not occur in [s] after position [i]. */ -let index_from: (bytes, int, char) => int - -/** [index_from _opts i c] returns the index of the first occurrence of - byte [c] in [s] after position [i] or [None] if [c] does not occur in [s] after position [i]. - [Bytes.index_opt s c] is equivalent to [Bytes.index_from_opt s 0 c]. - - Raise [Invalid_argument] if [i] is not a valid position in [s]. - @since 4.05 */ -let index_from_opt: (bytes, int, char) => option - -/** [rindex_from s i c] returns the index of the last occurrence of - byte [c] in [s] before position [i+1]. [rindex s c] is equivalent - to [rindex_from s (Bytes.length s - 1) c]. - - Raise [Invalid_argument] if [i+1] is not a valid position in [s]. - Raise [Not_found] if [c] does not occur in [s] before position [i+1]. */ -let rindex_from: (bytes, int, char) => int - -/** [rindex_from_opt s i c] returns the index of the last occurrence - of byte [c] in [s] before position [i+1] or [None] if [c] does not - occur in [s] before position [i+1]. [rindex_opt s c] is equivalent to - [rindex_from s (Bytes.length s - 1) c]. - - Raise [Invalid_argument] if [i+1] is not a valid position in [s]. - @since 4.05 */ -let rindex_from_opt: (bytes, int, char) => option - -/** [contains s c] tests if byte [c] appears in [s]. */ -let contains: (bytes, char) => bool - -/** [contains_from s start c] tests if byte [c] appears in [s] after - position [start]. [contains s c] is equivalent to [contains_from - s 0 c]. - - Raise [Invalid_argument] if [start] is not a valid position in [s]. */ -let contains_from: (bytes, int, char) => bool - -/** [rcontains_from s stop c] tests if byte [c] appears in [s] before - position [stop+1]. - - Raise [Invalid_argument] if [stop < 0] or [stop+1] is not a valid - position in [s]. */ -let rcontains_from: (bytes, int, char) => bool - -/** Return a copy of the argument, with all lowercase letters - translated to uppercase, using the US-ASCII character set. - @since 4.03.0 */ -let uppercase_ascii: bytes => bytes - -/** Return a copy of the argument, with all uppercase letters - translated to lowercase, using the US-ASCII character set. - @since 4.03.0 */ -let lowercase_ascii: bytes => bytes - -/** Return a copy of the argument, with the first character set to uppercase, - using the US-ASCII character set. - @since 4.03.0 */ -let capitalize_ascii: bytes => bytes - -/** Return a copy of the argument, with the first character set to lowercase, - using the US-ASCII character set. - @since 4.03.0 */ -let uncapitalize_ascii: bytes => bytes - -/** An alias for the type of byte sequences. */ -type t = bytes - -/** The comparison function for byte sequences, with the same - specification as {!Pervasives.compare}. Along with the type [t], - this function [compare] allows the module [Bytes] to be passed as - argument to the functors {!Set.Make} and {!Map.Make}. */ -let compare: (t, t) => int - -/** The equality function for byte sequences. - @since 4.03.0 */ -let equal: (t, t) => bool - -/* {3 Unsafe conversions (for advanced users)} - - This section describes unsafe, low-level conversion functions - between [bytes] and [string]. They do not copy the internal data; - used improperly, they can break the immutability invariant on - strings provided by the [-safe-string] option. They are available for - expert library authors, but for most purposes you should use the - always-correct {!Bytes.to_string} and {!Bytes.of_string} instead. -*/ - -/** Unsafely convert a byte sequence into a string. - - To reason about the use of [unsafe_to_string], it is convenient to - consider an "ownership" discipline. A piece of code that - manipulates some data "owns" it; there are several disjoint ownership - modes, including: - - Unique ownership: the data may be accessed and mutated - - Shared ownership: the data has several owners, that may only - access it, not mutate it. - - Unique ownership is linear: passing the data to another piece of - code means giving up ownership (we cannot write the - data again). A unique owner may decide to make the data shared - (giving up mutation rights on it), but shared data may not become - uniquely-owned again. - - [unsafe_to_string s] can only be used when the caller owns the byte - sequence [s] -- either uniquely or as shared immutable data. The - caller gives up ownership of [s], and gains ownership of the - returned string. - - There are two valid use-cases that respect this ownership - discipline: - - 1. Creating a string by initializing and mutating a byte sequence - that is never changed after initialization is performed. - - {[ -let string_init len f : string = - let s = Bytes.create len in - for i = 0 to len - 1 do Bytes.set s i (f i) done; - Bytes.unsafe_to_string s - ]} - - This function is safe because the byte sequence [s] will never be - accessed or mutated after [unsafe_to_string] is called. The - [string_init] code gives up ownership of [s], and returns the - ownership of the resulting string to its caller. - - Note that it would be unsafe if [s] was passed as an additional - parameter to the function [f] as it could escape this way and be - mutated in the future -- [string_init] would give up ownership of - [s] to pass it to [f], and could not call [unsafe_to_string] - safely. - - We have provided the {!String.init}, {!String.map} and - {!String.mapi} functions to cover most cases of building - new strings. You should prefer those over [to_string] or - [unsafe_to_string] whenever applicable. - - 2. Temporarily giving ownership of a byte sequence to a function - that expects a uniquely owned string and returns ownership back, so - that we can mutate the sequence again after the call ended. - - {[ -let bytes_length (s : bytes) = - String.length (Bytes.unsafe_to_string s) - ]} - - In this use-case, we do not promise that [s] will never be mutated - after the call to [bytes_length s]. The {!String.length} function - temporarily borrows unique ownership of the byte sequence - (and sees it as a [string]), but returns this ownership back to - the caller, which may assume that [s] is still a valid byte - sequence after the call. Note that this is only correct because we - know that {!String.length} does not capture its argument -- it could - escape by a side-channel such as a memoization combinator. - - The caller may not mutate [s] while the string is borrowed (it has - temporarily given up ownership). This affects concurrent programs, - but also higher-order functions: if {!String.length} returned - a closure to be called later, [s] should not be mutated until this - closure is fully applied and returns ownership. -*/ -let unsafe_to_string: bytes => string - -/** Unsafely convert a shared string to a byte sequence that should - not be mutated. - - The same ownership discipline that makes [unsafe_to_string] - correct applies to [unsafe_of_string]: you may use it if you were - the owner of the [string] value, and you will own the return - [bytes] in the same mode. - - In practice, unique ownership of string values is extremely - difficult to reason about correctly. You should always assume - strings are shared, never uniquely owned. - - For example, string literals are implicitly shared by the - compiler, so you never uniquely own them. - - {[ -let incorrect = Bytes.unsafe_of_string "hello" -let s = Bytes.of_string "hello" - ]} - - The first declaration is incorrect, because the string literal - ["hello"] could be shared by the compiler with other parts of the - program, and mutating [incorrect] is a bug. You must always use - the second version, which performs a copy and is thus correct. - - Assuming unique ownership of strings that are not string - literals, but are (partly) built from string literals, is also - incorrect. For example, mutating [unsafe_of_string ("foo" ^ s)] - could mutate the shared string ["foo"] -- assuming a rope-like - representation of strings. More generally, functions operating on - strings will assume shared ownership, they do not preserve unique - ownership. It is thus incorrect to assume unique ownership of the - result of [unsafe_of_string]. - - The only case we have reasonable confidence is safe is if the - produced [bytes] is shared -- used as an immutable byte - sequence. This is possibly useful for incremental migration of - low-level programs that manipulate immutable sequences of bytes - (for example {!Marshal.from_bytes}) and previously used the - [string] type for this purpose. -*/ -let unsafe_of_string: string => bytes - -/* The following is for system use only. Do not call directly. */ - -external unsafe_get: (bytes, int) => char = "%bytes_unsafe_get" -external unsafe_set: (bytes, int, char) => unit = "%bytes_unsafe_set" diff --git a/jscomp/stdlib-406/bytesLabels.res b/jscomp/stdlib-406/bytesLabels.res deleted file mode 100644 index 527d76a20a..0000000000 Binary files a/jscomp/stdlib-406/bytesLabels.res and /dev/null differ diff --git a/jscomp/stdlib-406/bytesLabels.resi b/jscomp/stdlib-406/bytesLabels.resi deleted file mode 100644 index 411f939e20..0000000000 --- a/jscomp/stdlib-406/bytesLabels.resi +++ /dev/null @@ -1,269 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/*** Byte sequence operations. - @since 4.02.0 -*/ - -/** Return the length (number of bytes) of the argument. */ -external length: bytes => int = "%bytes_length" - -/** [get s n] returns the byte at index [n] in argument [s]. - - Raise [Invalid_argument] if [n] is not a valid index in [s]. */ -external get: (bytes, int) => char = "%bytes_safe_get" - -/** [set s n c] modifies [s] in place, replacing the byte at index [n] - with [c]. - - Raise [Invalid_argument] if [n] is not a valid index in [s]. */ -external set: (bytes, int, char) => unit = "%bytes_safe_set" - -/** [create n] returns a new byte sequence of length [n]. The - sequence is uninitialized and contains arbitrary bytes. - - Raise [Invalid_argument] if [n < 0] or [n > ]{!Sys.max_string_length}. */ -external create: int => bytes = "?create_bytes" - -/** [make n c] returns a new byte sequence of length [n], filled with - the byte [c]. - - Raise [Invalid_argument] if [n < 0] or [n > ]{!Sys.max_string_length}. */ -let make: (int, char) => bytes - -/** [init n f] returns a fresh byte sequence of length [n], - with character [i] initialized to the result of [f i]. - - Raise [Invalid_argument] if [n < 0] or [n > ]{!Sys.max_string_length}. */ -let init: (int, ~f: int => char) => bytes - -/** A byte sequence of size 0. */ -let empty: bytes - -/** Return a new byte sequence that contains the same bytes as the - argument. */ -let copy: bytes => bytes - -/** Return a new byte sequence that contains the same bytes as the - given string. */ -let of_string: string => bytes - -/** Return a new string that contains the same bytes as the given byte - sequence. */ -let to_string: bytes => string - -/** [sub s start len] returns a new byte sequence of length [len], - containing the subsequence of [s] that starts at position [start] - and has length [len]. - - Raise [Invalid_argument] if [start] and [len] do not designate a - valid range of [s]. */ -let sub: (bytes, ~pos: int, ~len: int) => bytes - -/** Same as [sub] but return a string instead of a byte sequence. */ -let sub_string: (bytes, ~pos: int, ~len: int) => string - -/** [extend s left right] returns a new byte sequence that contains - the bytes of [s], with [left] uninitialized bytes prepended and - [right] uninitialized bytes appended to it. If [left] or [right] - is negative, then bytes are removed (instead of appended) from - the corresponding side of [s]. - - Raise [Invalid_argument] if the result length is negative or - longer than {!Sys.max_string_length} bytes. - @since 4.05.0 */ -let extend: (bytes, ~left: int, ~right: int) => bytes - -/** [fill s start len c] modifies [s] in place, replacing [len] - characters with [c], starting at [start]. - - Raise [Invalid_argument] if [start] and [len] do not designate a - valid range of [s]. */ -let fill: (bytes, ~pos: int, ~len: int, char) => unit - -/** [blit src srcoff dst dstoff len] copies [len] bytes from sequence - [src], starting at index [srcoff], to sequence [dst], starting at - index [dstoff]. It works correctly even if [src] and [dst] are the - same byte sequence, and the source and destination intervals - overlap. - - Raise [Invalid_argument] if [srcoff] and [len] do not - designate a valid range of [src], or if [dstoff] and [len] - do not designate a valid range of [dst]. */ -let blit: (~src: bytes, ~src_pos: int, ~dst: bytes, ~dst_pos: int, ~len: int) => unit - -/** [blit src srcoff dst dstoff len] copies [len] bytes from string - [src], starting at index [srcoff], to byte sequence [dst], - starting at index [dstoff]. - - Raise [Invalid_argument] if [srcoff] and [len] do not - designate a valid range of [src], or if [dstoff] and [len] - do not designate a valid range of [dst]. - @since 4.05.0 */ -let blit_string: (~src: string, ~src_pos: int, ~dst: bytes, ~dst_pos: int, ~len: int) => unit - -/** [concat sep sl] concatenates the list of byte sequences [sl], - inserting the separator byte sequence [sep] between each, and - returns the result as a new byte sequence. */ -let concat: (~sep: bytes, list) => bytes - -/** [cat s1 s2] concatenates [s1] and [s2] and returns the result - as new byte sequence. - - Raise [Invalid_argument] if the result is longer than - {!Sys.max_string_length} bytes. - @since 4.05.0 */ -let cat: (bytes, bytes) => bytes - -/** [iter f s] applies function [f] in turn to all the bytes of [s]. - It is equivalent to [f (get s 0); f (get s 1); ...; f (get s - (length s - 1)); ()]. */ -let iter: (~f: char => unit, bytes) => unit - -/** Same as {!Bytes.iter}, but the function is applied to the index of - the byte as first argument and the byte itself as second - argument. */ -let iteri: (~f: (int, char) => unit, bytes) => unit - -/** [map f s] applies function [f] in turn to all the bytes of [s] and - stores the resulting bytes in a new sequence that is returned as - the result. */ -let map: (~f: char => char, bytes) => bytes - -/** [mapi f s] calls [f] with each character of [s] and its - index (in increasing index order) and stores the resulting bytes - in a new sequence that is returned as the result. */ -let mapi: (~f: (int, char) => char, bytes) => bytes - -/** Return a copy of the argument, without leading and trailing - whitespace. The bytes regarded as whitespace are the ASCII - characters [' '], ['\x0c'], ['\n'], ['\r'], and ['\t']. */ -let trim: bytes => bytes - -/** Return a copy of the argument, with special characters represented - by escape sequences, following the lexical conventions of OCaml. */ -let escaped: bytes => bytes - -/** [index s c] returns the index of the first occurrence of byte [c] - in [s]. - - Raise [Not_found] if [c] does not occur in [s]. */ -let index: (bytes, char) => int - -/** [index_opt s c] returns the index of the first occurrence of byte [c] - in [s] or [None] if [c] does not occur in [s]. - @since 4.05 */ -let index_opt: (bytes, char) => option - -/** [rindex s c] returns the index of the last occurrence of byte [c] - in [s]. - - Raise [Not_found] if [c] does not occur in [s]. */ -let rindex: (bytes, char) => int - -/** [rindex_opt s c] returns the index of the last occurrence of byte [c] - in [s] or [None] if [c] does not occur in [s]. - @since 4.05 */ -let rindex_opt: (bytes, char) => option - -/** [index_from s i c] returns the index of the first occurrence of - byte [c] in [s] after position [i]. [Bytes.index s c] is - equivalent to [Bytes.index_from s 0 c]. - - Raise [Invalid_argument] if [i] is not a valid position in [s]. - Raise [Not_found] if [c] does not occur in [s] after position [i]. */ -let index_from: (bytes, int, char) => int - -/** [index_from _opts i c] returns the index of the first occurrence of - byte [c] in [s] after position [i] or [None] if [c] does not occur in [s] after position [i]. - [Bytes.index_opt s c] is equivalent to [Bytes.index_from_opt s 0 c]. - - Raise [Invalid_argument] if [i] is not a valid position in [s]. - @since 4.05 */ -let index_from_opt: (bytes, int, char) => option - -/** [rindex_from s i c] returns the index of the last occurrence of - byte [c] in [s] before position [i+1]. [rindex s c] is equivalent - to [rindex_from s (Bytes.length s - 1) c]. - - Raise [Invalid_argument] if [i+1] is not a valid position in [s]. - Raise [Not_found] if [c] does not occur in [s] before position [i+1]. */ -let rindex_from: (bytes, int, char) => int - -/** [rindex_from_opt s i c] returns the index of the last occurrence - of byte [c] in [s] before position [i+1] or [None] if [c] does not - occur in [s] before position [i+1]. [rindex_opt s c] is equivalent to - [rindex_from s (Bytes.length s - 1) c]. - - Raise [Invalid_argument] if [i+1] is not a valid position in [s]. - @since 4.05 */ -let rindex_from_opt: (bytes, int, char) => option - -/** [contains s c] tests if byte [c] appears in [s]. */ -let contains: (bytes, char) => bool - -/** [contains_from s start c] tests if byte [c] appears in [s] after - position [start]. [contains s c] is equivalent to [contains_from - s 0 c]. - - Raise [Invalid_argument] if [start] is not a valid position in [s]. */ -let contains_from: (bytes, int, char) => bool - -/** [rcontains_from s stop c] tests if byte [c] appears in [s] before - position [stop+1]. - - Raise [Invalid_argument] if [stop < 0] or [stop+1] is not a valid - position in [s]. */ -let rcontains_from: (bytes, int, char) => bool - -/** Return a copy of the argument, with all lowercase letters - translated to uppercase, using the US-ASCII character set. - @since 4.05.0 */ -let uppercase_ascii: bytes => bytes - -/** Return a copy of the argument, with all uppercase letters - translated to lowercase, using the US-ASCII character set. - @since 4.05.0 */ -let lowercase_ascii: bytes => bytes - -/** Return a copy of the argument, with the first character set to uppercase, - using the US-ASCII character set. - @since 4.05.0 */ -let capitalize_ascii: bytes => bytes - -/** Return a copy of the argument, with the first character set to lowercase, - using the US-ASCII character set. - @since 4.05.0 */ -let uncapitalize_ascii: bytes => bytes - -/** An alias for the type of byte sequences. */ -type t = bytes - -/** The comparison function for byte sequences, with the same - specification as {!Pervasives.compare}. Along with the type [t], - this function [compare] allows the module [Bytes] to be passed as - argument to the functors {!Set.Make} and {!Map.Make}. */ -let compare: (t, t) => int - -/** The equality function for byte sequences. - @since 4.05.0 */ -let equal: (t, t) => bool - -/* The following is for system use only. Do not call directly. */ - -external unsafe_get: (bytes, int) => char = "%bytes_unsafe_get" -external unsafe_set: (bytes, int, char) => unit = "%bytes_unsafe_set" -let unsafe_to_string: bytes => string -let unsafe_of_string: string => bytes diff --git a/jscomp/stdlib-406/callback.res b/jscomp/stdlib-406/callback.res deleted file mode 100644 index 89d44b6368..0000000000 --- a/jscomp/stdlib-406/callback.res +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ -@@config({flags: ["-bs-no-cross-module-opt"]}) -/* Registering OCaml values with the C runtime for later callbacks */ - -let register = (_, _) => () -let register_exception = (_, _) => () diff --git a/jscomp/stdlib-406/callback.resi b/jscomp/stdlib-406/callback.resi deleted file mode 100644 index bff728306d..0000000000 --- a/jscomp/stdlib-406/callback.resi +++ /dev/null @@ -1,34 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/*** Registering OCaml values with the C runtime. - - This module allows OCaml values to be registered with the C runtime - under a symbolic name, so that C code can later call back registered - OCaml functions, or raise registered OCaml exceptions. -*/ - -/** [Callback.register n v] registers the value [v] under - the name [n]. C code can later retrieve a handle to [v] - by calling [caml_named_value(n)]. */ -let register: (string, 'a) => unit - -/** [Callback.register_exception n exn] registers the - exception contained in the exception value [exn] - under the name [n]. C code can later retrieve a handle to - the exception by calling [caml_named_value(n)]. The exception - value thus obtained is suitable for passing as first argument - to [raise_constant] or [raise_with_arg]. */ -let register_exception: (string, exn) => unit diff --git a/jscomp/stdlib-406/camlinternalLazy.resi b/jscomp/stdlib-406/camlinternalLazy.resi deleted file mode 100644 index 24582c4bc0..0000000000 --- a/jscomp/stdlib-406/camlinternalLazy.resi +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Damien Doligez, projet Para, INRIA Rocquencourt */ -/* */ -/* Copyright 1997 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. */ -/* */ -/* ************************************************************************ */ - -/*** Run-time support for lazy values. - All functions in this module are for system use only, not for the - casual user. */ - -exception Undefined - -let force: lazy_t<'a> => 'a -/* instrumented by {!Matching} */ - -let force_val: lazy_t<'a> => 'a - -let is_val: lazy_t<'a> => bool - -let from_fun: ((. unit) => 'a) => lazy_t<'a> - -let from_val: 'a => lazy_t<'a> diff --git a/jscomp/stdlib-406/camlinternalMod.res b/jscomp/stdlib-406/camlinternalMod.res deleted file mode 100644 index 3bf65c6b40..0000000000 --- a/jscomp/stdlib-406/camlinternalMod.res +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 2004 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. */ -/* */ -/* ************************************************************************ */ - -type rec shape = - | Function - | Lazy - | Class - | Module(array) - | Value(Obj.t) diff --git a/jscomp/stdlib-406/camlinternalMod.resi b/jscomp/stdlib-406/camlinternalMod.resi deleted file mode 100644 index e5529a4d5c..0000000000 --- a/jscomp/stdlib-406/camlinternalMod.resi +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 2004 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. */ -/* */ -/* ************************************************************************ */ - -/*** Run-time support for recursive modules. - All functions in this module are for system use only, not for the - casual user. */ - -type rec shape = - | Function - | Lazy - | Class - | Module(array) - | Value(Obj.t) diff --git a/jscomp/stdlib-406/char.res b/jscomp/stdlib-406/char.res deleted file mode 100644 index afc28ae3f1..0000000000 --- a/jscomp/stdlib-406/char.res +++ /dev/null @@ -1,85 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/* Character operations */ - -external code: char => int = "%identity" -external unsafe_chr: int => char = "%identity" - -let chr = n => - if n < 0 || n > 255 { - invalid_arg("Char.chr") - } else { - unsafe_chr(n) - } - -external bytes_create: int => bytes = "?create_bytes" -external bytes_unsafe_set: (bytes, int, char) => unit = "%bytes_unsafe_set" -external unsafe_to_string: bytes => string = "%bytes_to_string" - -let escaped = param => - switch param { - | '\'' => "\\'" - | '\\' => "\\\\" - | '\n' => "\\n" - | '\t' => "\\t" - | '\r' => "\\r" - | '\b' => "\\b" - | ' ' .. '~' as c => - let s = bytes_create(1) - bytes_unsafe_set(s, 0, c) - unsafe_to_string(s) - | c => - let n = code(c) - let s = bytes_create(4) - bytes_unsafe_set(s, 0, '\\') - bytes_unsafe_set(s, 1, unsafe_chr(48 + n / 100)) - bytes_unsafe_set(s, 2, unsafe_chr(48 + mod(n / 10, 10))) - bytes_unsafe_set(s, 3, unsafe_chr(48 + mod(n, 10))) - unsafe_to_string(s) - } - -let lowercase = c => - if (c >= 'A' && c <= 'Z') || ((c >= 'À' && c <= 'Ö') || c >= 'Ø' && c <= 'Þ') { - unsafe_chr(code(c) + 32) - } else { - c - } - -let uppercase = c => - if (c >= 'a' && c <= 'z') || ((c >= 'à' && c <= 'ö') || c >= 'ø' && c <= 'þ') { - unsafe_chr(code(c) - 32) - } else { - c - } - -let lowercase_ascii = c => - if c >= 'A' && c <= 'Z' { - unsafe_chr(code(c) + 32) - } else { - c - } - -let uppercase_ascii = c => - if c >= 'a' && c <= 'z' { - unsafe_chr(code(c) - 32) - } else { - c - } - -type t = char - -let compare = (c1, c2) => code(c1) - code(c2) -let equal = (c1: t, c2: t) => compare(c1, c2) == 0 diff --git a/jscomp/stdlib-406/complex.res b/jscomp/stdlib-406/complex.res deleted file mode 100644 index 4b0561011f..0000000000 --- a/jscomp/stdlib-406/complex.res +++ /dev/null @@ -1,112 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 2002 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. */ -/* */ -/* ************************************************************************ */ - -/* Complex numbers */ - -type t = {re: float, im: float} - -let zero = {re: 0.0, im: 0.0} -let one = {re: 1.0, im: 0.0} -let i = {re: 0.0, im: 1.0} - -let add = (x, y) => {re: x.re +. y.re, im: x.im +. y.im} - -let sub = (x, y) => {re: x.re -. y.re, im: x.im -. y.im} - -let neg = x => {re: -.x.re, im: -.x.im} - -let conj = x => {re: x.re, im: -.x.im} - -let mul = (x, y) => { - re: x.re *. y.re -. x.im *. y.im, - im: x.re *. y.im +. x.im *. y.re, -} - -let div = (x, y) => - if abs_float(y.re) >= abs_float(y.im) { - let r = y.im /. y.re - let d = y.re +. r *. y.im - { - re: (x.re +. r *. x.im) /. d, - im: (x.im -. r *. x.re) /. d, - } - } else { - let r = y.re /. y.im - let d = y.im +. r *. y.re - { - re: (r *. x.re +. x.im) /. d, - im: (r *. x.im -. x.re) /. d, - } - } - -let inv = x => div(one, x) - -let norm2 = x => x.re *. x.re +. x.im *. x.im - -let norm = x => { - /* Watch out for overflow in computing re^2 + im^2 */ - let r = abs_float(x.re) - and i = abs_float(x.im) - if r == 0.0 { - i - } else if i == 0.0 { - r - } else if r >= i { - let q = i /. r - r *. sqrt(1.0 +. q *. q) - } else { - let q = r /. i - i *. sqrt(1.0 +. q *. q) - } -} - -let arg = x => atan2(x.im, x.re) - -let polar = (n, a) => {re: cos(a) *. n, im: sin(a) *. n} - -let sqrt = x => - if x.re == 0.0 && x.im == 0.0 { - {re: 0.0, im: 0.0} - } else { - let r = abs_float(x.re) and i = abs_float(x.im) - let w = if r >= i { - let q = i /. r - sqrt(r) *. sqrt(0.5 *. (1.0 +. sqrt(1.0 +. q *. q))) - } else { - let q = r /. i - sqrt(i) *. sqrt(0.5 *. (q +. sqrt(1.0 +. q *. q))) - } - if x.re >= 0.0 { - {re: w, im: 0.5 *. x.im /. w} - } else { - { - re: 0.5 *. i /. w, - im: if x.im >= 0.0 { - w - } else { - -.w - }, - } - } - } - -let exp = x => { - let e = exp(x.re) - {re: e *. cos(x.im), im: e *. sin(x.im)} -} - -let log = x => {re: log(norm(x)), im: atan2(x.im, x.re)} - -let pow = (x, y) => exp(mul(y, log(x))) diff --git a/jscomp/stdlib-406/complex.resi b/jscomp/stdlib-406/complex.resi deleted file mode 100644 index bacdc477d5..0000000000 --- a/jscomp/stdlib-406/complex.resi +++ /dev/null @@ -1,86 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 2002 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. */ -/* */ -/* ************************************************************************ */ - -/*** Complex numbers. - - This module provides arithmetic operations on complex numbers. - Complex numbers are represented by their real and imaginary parts - (cartesian representation). Each part is represented by a - double-precision floating-point number (type [float]). */ - -/** The type of complex numbers. [re] is the real part and [im] the - imaginary part. */ -type t = {re: float, im: float} - -/** The complex number [0]. */ -let zero: t - -/** The complex number [1]. */ -let one: t - -/** The complex number [i]. */ -let i: t - -/** Unary negation. */ -let neg: t => t - -/** Conjugate: given the complex [x + i.y], returns [x - i.y]. */ -let conj: t => t - -/** Addition */ -let add: (t, t) => t - -/** Subtraction */ -let sub: (t, t) => t - -/** Multiplication */ -let mul: (t, t) => t - -/** Multiplicative inverse ([1/z]). */ -let inv: t => t - -/** Division */ -let div: (t, t) => t - -/** Square root. The result [x + i.y] is such that [x > 0] or - [x = 0] and [y >= 0]. - This function has a discontinuity along the negative real axis. */ -let sqrt: t => t - -/** Norm squared: given [x + i.y], returns [x^2 + y^2]. */ -let norm2: t => float - -/** Norm: given [x + i.y], returns [sqrt(x^2 + y^2)]. */ -let norm: t => float - -/** Argument. The argument of a complex number is the angle - in the complex plane between the positive real axis and a line - passing through zero and the number. This angle ranges from - [-pi] to [pi]. This function has a discontinuity along the - negative real axis. */ -let arg: t => float - -/** [polar norm arg] returns the complex having norm [norm] - and argument [arg]. */ -let polar: (float, float) => t - -/** Exponentiation. [exp z] returns [e] to the [z] power. */ -let exp: t => t - -/** Natural logarithm (in base [e]). */ -let log: t => t - -/** Power function. [pow z1 z2] returns [z1] to the [z2] power. */ -let pow: (t, t) => t diff --git a/jscomp/stdlib-406/digest.res b/jscomp/stdlib-406/digest.res deleted file mode 100644 index d922290395..0000000000 --- a/jscomp/stdlib-406/digest.res +++ /dev/null @@ -1,78 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/* Message digest (MD5) */ - -type t = string - -let compare = String.compare -let equal = String.equal - -external unsafe_string: (string, int, int) => t = "?md5_string" - -let string = str => unsafe_string(str, 0, String.length(str)) - -let bytes = b => string(Bytes.unsafe_to_string(b)) - -let substring = (str, ofs, len) => - if ofs < 0 || (len < 0 || ofs > String.length(str) - len) { - invalid_arg("Digest.substring") - } else { - unsafe_string(str, ofs, len) - } - -let subbytes = (b, ofs, len) => substring(Bytes.unsafe_to_string(b), ofs, len) - -let char_hex = n => - Char.unsafe_chr( - n + if n < 10 { - Char.code('0') - } else { - Char.code('a') - 10 - }, - ) - -let to_hex = d => { - if String.length(d) != 16 { - invalid_arg("Digest.to_hex") - } - let result = Bytes.create(32) - for i in 0 to 15 { - let x = Char.code(String.get(d, i)) - Bytes.unsafe_set(result, i * 2, char_hex(lsr(x, 4))) - Bytes.unsafe_set(result, i * 2 + 1, char_hex(land(x, 0x0f))) - } - Bytes.unsafe_to_string(result) -} - -let from_hex = s => { - if String.length(s) != 32 { - invalid_arg("Digest.from_hex") - } - let digit = c => - switch c { - | '0' .. '9' => Char.code(c) - Char.code('0') - | 'A' .. 'F' => Char.code(c) - Char.code('A') + 10 - | 'a' .. 'f' => Char.code(c) - Char.code('a') + 10 - | _ => raise(Invalid_argument("Digest.from_hex")) - } - - let byte = i => lsl(digit(String.get(s, i)), 4) + digit(String.get(s, i + 1)) - let result = Bytes.create(16) - for i in 0 to 15 { - Bytes.set(result, i, Char.chr(byte(2 * i))) - } - Bytes.unsafe_to_string(result) -} diff --git a/jscomp/stdlib-406/digest.resi b/jscomp/stdlib-406/digest.resi deleted file mode 100644 index bcedb527e5..0000000000 --- a/jscomp/stdlib-406/digest.resi +++ /dev/null @@ -1,67 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/*** MD5 message digest. - - This module provides functions to compute 128-bit 'digests' of - arbitrary-length strings or files. The digests are of cryptographic - quality: it is very hard, given a digest, to forge a string having - that digest. The algorithm used is MD5. This module should not be - used for secure and sensitive cryptographic applications. For these - kind of applications more recent and stronger cryptographic - primitives should be used instead. -*/ - -/** The type of digests: 16-character strings. */ -type t = string - -/** The comparison function for 16-character digest, with the same - specification as {!Pervasives.compare} and the implementation - shared with {!String.compare}. Along with the type [t], this - function [compare] allows the module [Digest] to be passed as - argument to the functors {!Set.Make} and {!Map.Make}. - @since 4.00.0 */ -let compare: (t, t) => int - -/** The equal function for 16-character digest. - @since 4.03.0 */ -let equal: (t, t) => bool - -/** Return the digest of the given string. */ -let string: string => t - -/** Return the digest of the given byte sequence. - @since 4.02.0 */ -let bytes: bytes => t - -/** [Digest.substring s ofs len] returns the digest of the substring - of [s] starting at index [ofs] and containing [len] characters. */ -let substring: (string, int, int) => t - -/** [Digest.subbytes s ofs len] returns the digest of the subsequence - of [s] starting at index [ofs] and containing [len] bytes. - @since 4.02.0 */ -let subbytes: (bytes, int, int) => t - -/** Return the printable hexadecimal representation of the given digest. - Raise [Invalid_argument] if the argument is not exactly 16 bytes. - */ -let to_hex: t => string - -/** Convert a hexadecimal representation back into the corresponding digest. - Raise [Invalid_argument] if the argument is not exactly 32 hexadecimal - characters. - @since 4.00.0 */ -let from_hex: string => t diff --git a/jscomp/stdlib-406/filename.res b/jscomp/stdlib-406/filename.res deleted file mode 100644 index 1ccdd3c3d5..0000000000 --- a/jscomp/stdlib-406/filename.res +++ /dev/null @@ -1,353 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy and Damien Doligez, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -let generic_quote = (quotequote, s) => { - let l = String.length(s) - let b = Buffer.create(l + 20) - Buffer.add_char(b, '\'') - for i in 0 to l - 1 { - if String.get(s, i) == '\'' { - Buffer.add_string(b, quotequote) - } else { - Buffer.add_char(b, String.get(s, i)) - } - } - Buffer.add_char(b, '\'') - Buffer.contents(b) -} - -/* This function implements the Open Group specification found here: - [[1]] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/basename.html - In step 1 of [[1]], we choose to return "." for empty input. - (for compatibility with previous versions of OCaml) - In step 2, we choose to process "//" normally. - Step 6 is not implemented: we consider that the [suffix] operand is - always absent. Suffixes are handled by [chop_suffix] and [chop_extension]. -*/ -let generic_basename = (is_dir_sep, current_dir_name, name) => { - let rec find_end = n => - if n < 0 { - String.sub(name, 0, 1) - } else if is_dir_sep(name, n) { - find_end(n - 1) - } else { - find_beg(n, n + 1) - } - and find_beg = (n, p) => - if n < 0 { - String.sub(name, 0, p) - } else if is_dir_sep(name, n) { - String.sub(name, n + 1, p - n - 1) - } else { - find_beg(n - 1, p) - } - - if name == "" { - current_dir_name - } else { - find_end(String.length(name) - 1) - } -} - -/* This function implements the Open Group specification found here: - [[2]] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/dirname.html - In step 6 of [[2]], we choose to process "//" normally. -*/ -let generic_dirname = (is_dir_sep, current_dir_name, name) => { - let rec trailing_sep = n => - if n < 0 { - String.sub(name, 0, 1) - } else if is_dir_sep(name, n) { - trailing_sep(n - 1) - } else { - base(n) - } - and base = n => - if n < 0 { - current_dir_name - } else if is_dir_sep(name, n) { - intermediate_sep(n) - } else { - base(n - 1) - } - and intermediate_sep = n => - if n < 0 { - String.sub(name, 0, 1) - } else if is_dir_sep(name, n) { - intermediate_sep(n - 1) - } else { - String.sub(name, 0, n + 1) - } - - if name == "" { - current_dir_name - } else { - trailing_sep(String.length(name) - 1) - } -} - -module Unix = { - let current_dir_name = "." - let parent_dir_name = ".." - let dir_sep = "/" - let is_dir_sep = (s, i) => String.get(s, i) == '/' - let is_relative = n => String.length(n) < 1 || String.get(n, 0) != '/' - let is_implicit = n => - is_relative(n) && - ((String.length(n) < 2 || String.sub(n, 0, 2) != "./") && - (String.length(n) < 3 || String.sub(n, 0, 3) != "../")) - let check_suffix = (name, suff) => - String.length(name) >= String.length(suff) && - String.sub(name, String.length(name) - String.length(suff), String.length(suff)) == suff - let temp_dir_name = try Sys.getenv("TMPDIR") catch { - | Not_found => "/tmp" - } - let quote = x => generic_quote("'\\''", x) - let basename = x => generic_basename(is_dir_sep, current_dir_name, x) - let dirname = x => generic_dirname(is_dir_sep, current_dir_name, x) -} - -module Win32 = { - let current_dir_name = "." - let parent_dir_name = ".." - let dir_sep = "\\" - let is_dir_sep = (s, i) => { - let c = String.get(s, i) - c == '/' || (c == '\\' || c == ':') - } - let is_relative = n => - (String.length(n) < 1 || String.get(n, 0) != '/') && - ((String.length(n) < 1 || String.get(n, 0) != '\\') && - (String.length(n) < 2 || String.get(n, 1) != ':')) - let is_implicit = n => - is_relative(n) && - ((String.length(n) < 2 || String.sub(n, 0, 2) != "./") && - ((String.length(n) < 2 || String.sub(n, 0, 2) != ".\\") && - ((String.length(n) < 3 || String.sub(n, 0, 3) != "../") && - (String.length(n) < 3 || String.sub(n, 0, 3) != "..\\")))) - let check_suffix = (name, suff) => - String.length(name) >= String.length(suff) && { - let s = String.sub(name, String.length(name) - String.length(suff), String.length(suff)) - String.lowercase_ascii(s) == String.lowercase_ascii(suff) - } - let temp_dir_name = try Sys.getenv("TEMP") catch { - | Not_found => "." - } - let quote = s => { - let l = String.length(s) - let b = Buffer.create(l + 20) - Buffer.add_char(b, '"') - let rec loop = i => - if i == l { - Buffer.add_char(b, '"') - } else { - switch String.get(s, i) { - | '"' => loop_bs(0, i) - | '\\' => loop_bs(0, i) - | c => - Buffer.add_char(b, c) - loop(i + 1) - } - } - and loop_bs = (n, i) => - if i == l { - Buffer.add_char(b, '"') - add_bs(n) - } else { - switch String.get(s, i) { - | '"' => - add_bs(2 * n + 1) - Buffer.add_char(b, '"') - loop(i + 1) - | '\\' => loop_bs(n + 1, i + 1) - | _ => - add_bs(n) - loop(i) - } - } - and add_bs = n => - for _j in 1 to n { - Buffer.add_char(b, '\\') - } - - loop(0) - Buffer.contents(b) - } - let has_drive = s => { - let is_letter = param => - switch param { - | 'A' .. 'Z' | 'a' .. 'z' => true - | _ => false - } - - String.length(s) >= 2 && (is_letter(String.get(s, 0)) && String.get(s, 1) == ':') - } - let drive_and_path = s => - if has_drive(s) { - (String.sub(s, 0, 2), String.sub(s, 2, String.length(s) - 2)) - } else { - ("", s) - } - let dirname = s => { - let (drive, path) = drive_and_path(s) - let dir = generic_dirname(is_dir_sep, current_dir_name, path) - drive ++ dir - } - let basename = s => { - let (_drive, path) = drive_and_path(s) - generic_basename(is_dir_sep, current_dir_name, path) - } -} - -module Cygwin = { - let current_dir_name = "." - let parent_dir_name = ".." - let dir_sep = "/" - let is_dir_sep = Win32.is_dir_sep - let is_relative = Win32.is_relative - let is_implicit = Win32.is_implicit - let check_suffix = Win32.check_suffix - let temp_dir_name = Unix.temp_dir_name - let quote = Unix.quote - let basename = x => generic_basename(is_dir_sep, current_dir_name, x) - let dirname = x => generic_dirname(is_dir_sep, current_dir_name, x) -} - -let ( - current_dir_name, - parent_dir_name, - dir_sep, - is_dir_sep, - is_relative, - is_implicit, - check_suffix, - temp_dir_name, - quote, - basename, - dirname, -) = switch Sys.os_type { -| "Win32" => ( - Win32.current_dir_name, - Win32.parent_dir_name, - Win32.dir_sep, - Win32.is_dir_sep, - Win32.is_relative, - Win32.is_implicit, - Win32.check_suffix, - Win32.temp_dir_name, - Win32.quote, - Win32.basename, - Win32.dirname, - ) -| "Cygwin" => ( - Cygwin.current_dir_name, - Cygwin.parent_dir_name, - Cygwin.dir_sep, - Cygwin.is_dir_sep, - Cygwin.is_relative, - Cygwin.is_implicit, - Cygwin.check_suffix, - Cygwin.temp_dir_name, - Cygwin.quote, - Cygwin.basename, - Cygwin.dirname, - ) -| _ => /* normally "Unix" */ - ( - Unix.current_dir_name, - Unix.parent_dir_name, - Unix.dir_sep, - Unix.is_dir_sep, - Unix.is_relative, - Unix.is_implicit, - Unix.check_suffix, - Unix.temp_dir_name, - Unix.quote, - Unix.basename, - Unix.dirname, - ) -} - -let concat = (dirname, filename) => { - let l = String.length(dirname) - if l == 0 || is_dir_sep(dirname, l - 1) { - dirname ++ filename - } else { - dirname ++ (dir_sep ++ filename) - } -} - -let chop_suffix = (name, suff) => { - let n = String.length(name) - String.length(suff) - if n < 0 { - invalid_arg("Filename.chop_suffix") - } else { - String.sub(name, 0, n) - } -} - -let extension_len = name => { - let rec check = (i0, i) => - if i < 0 || is_dir_sep(name, i) { - 0 - } else if String.get(name, i) == '.' { - check(i0, i - 1) - } else { - String.length(name) - i0 - } - - let rec search_dot = i => - if i < 0 || is_dir_sep(name, i) { - 0 - } else if String.get(name, i) == '.' { - check(i, i - 1) - } else { - search_dot(i - 1) - } - - search_dot(String.length(name) - 1) -} - -let extension = name => { - let l = extension_len(name) - if l == 0 { - "" - } else { - String.sub(name, String.length(name) - l, l) - } -} - -let chop_extension = name => { - let l = extension_len(name) - if l == 0 { - invalid_arg("Filename.chop_extension") - } else { - String.sub(name, 0, String.length(name) - l) - } -} - -let remove_extension = name => { - let l = extension_len(name) - if l == 0 { - name - } else { - String.sub(name, 0, String.length(name) - l) - } -} - -let current_temp_dir_name = ref(temp_dir_name) - -let set_temp_dir_name = s => current_temp_dir_name := s -let get_temp_dir_name = () => current_temp_dir_name.contents diff --git a/jscomp/stdlib-406/filename.resi b/jscomp/stdlib-406/filename.resi deleted file mode 100644 index e9da0f7634..0000000000 --- a/jscomp/stdlib-406/filename.resi +++ /dev/null @@ -1,132 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/* Operations on file names. */ - -/** The conventional name for the current directory (e.g. [.] in Unix). */ -let current_dir_name: string - -/** The conventional name for the parent of the current directory - (e.g. [..] in Unix). */ -let parent_dir_name: string - -/** The directory separator (e.g. [/] in Unix). @since 3.11.2 */ -let dir_sep: string - -/** [concat dir file] returns a file name that designates file - [file] in directory [dir]. */ -let concat: (string, string) => string - -/** Return [true] if the file name is relative to the current - directory, [false] if it is absolute (i.e. in Unix, starts - with [/]). */ -let is_relative: string => bool - -/** Return [true] if the file name is relative and does not start - with an explicit reference to the current directory ([./] or - [../] in Unix), [false] if it starts with an explicit reference - to the root directory or the current directory. */ -let is_implicit: string => bool - -/** [check_suffix name suff] returns [true] if the filename [name] - ends with the suffix [suff]. */ -let check_suffix: (string, string) => bool - -/** [chop_suffix name suff] removes the suffix [suff] from - the filename [name]. The behavior is undefined if [name] does not - end with the suffix [suff]. */ -let chop_suffix: (string, string) => string - -/** [extension name] is the shortest suffix [ext] of [name0] where: - - - [name0] is the longest suffix of [name] that does not - contain a directory separator; - - [ext] starts with a period; - - [ext] is preceded by at least one non-period character - in [name0]. - - If such a suffix does not exist, [extension name] is the empty - string. - - @since 4.04 -*/ -let extension: string => string - -/** Return the given file name without its extension, as defined - in {!Filename.extension}. If the extension is empty, the function - returns the given file name. - - The following invariant holds for any file name [s]: - - [remove_extension s ^ extension s = s] - - @since 4.04 -*/ -let remove_extension: string => string - -/** Same as {!Filename.remove_extension}, but raise [Invalid_argument] - if the given name has an empty extension. */ -let chop_extension: string => string - -/** Split a file name into directory name / base file name. - If [name] is a valid file name, then [concat (dirname name) (basename name)] - returns a file name which is equivalent to [name]. Moreover, - after setting the current directory to [dirname name] (with {!Sys.chdir}), - references to [basename name] (which is a relative file name) - designate the same file as [name] before the call to {!Sys.chdir}. - - This function conforms to the specification of POSIX.1-2008 for the - [basename] utility. */ -let basename: string => string - -/** See {!Filename.basename}. - This function conforms to the specification of POSIX.1-2008 for the - [dirname] utility. */ -let dirname: string => string - -/** The name of the temporary directory: - Under Unix, the value of the [TMPDIR] environment variable, or "/tmp" - if the variable is not set. - Under Windows, the value of the [TEMP] environment variable, or "." - if the variable is not set. - The temporary directory can be changed with {!Filename.set_temp_dir_name}. - @since 4.00.0 -*/ -let get_temp_dir_name: unit => string - -/** Change the temporary directory returned by {!Filename.get_temp_dir_name} - and used by {!Filename.temp_file} and {!Filename.open_temp_file}. - @since 4.00.0 -*/ -let set_temp_dir_name: string => unit - -@deprecated("Use Filename.get_temp_dir_name instead") -/** The name of the initial temporary directory: - Under Unix, the value of the [TMPDIR] environment variable, or "/tmp" - if the variable is not set. - Under Windows, the value of the [TEMP] environment variable, or "." - if the variable is not set. - @deprecated You should use {!Filename.get_temp_dir_name} instead. - @since 3.09.1 -*/ -let temp_dir_name: string - -/** Return a quoted version of a file name, suitable for use as - one argument in a command line, escaping all meta-characters. - Warning: under Windows, the output is only suitable for use - with programs that follow the standard Windows quoting - conventions. - */ -let quote: string => string diff --git a/jscomp/stdlib-406/genlex.res b/jscomp/stdlib-406/genlex.res deleted file mode 100644 index bb6ef2409a..0000000000 --- a/jscomp/stdlib-406/genlex.res +++ /dev/null @@ -1,353 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -type token = - | Kwd(string) - | Ident(string) - | Int(int) - | Float(float) - | String(string) - | Char(char) - -/* The string buffering machinery */ - -let initial_buffer = Bytes.create(32) - -let buffer = ref(initial_buffer) -let bufpos = ref(0) - -let reset_buffer = () => { - buffer := initial_buffer - bufpos := 0 -} - -let store = c => { - if bufpos.contents >= Bytes.length(buffer.contents) { - let newbuffer = Bytes.create(2 * bufpos.contents) - Bytes.blit(buffer.contents, 0, newbuffer, 0, bufpos.contents) - buffer := newbuffer - } - Bytes.set(buffer.contents, bufpos.contents, c) - incr(bufpos) -} - -let get_string = () => { - let s = Bytes.sub_string(buffer.contents, 0, bufpos.contents) - buffer := initial_buffer - s -} - -/* The lexer */ - -let make_lexer = keywords => { - let kwd_table = Hashtbl.create(17) - List.iter(s => Hashtbl.add(kwd_table, s, Kwd(s)), keywords) - let ident_or_keyword = id => - try Hashtbl.find(kwd_table, id) catch { - | Not_found => Ident(id) - } - and keyword_or_error = c => { - let s = String.make(1, c) - try Hashtbl.find(kwd_table, s) catch { - | Not_found => raise(Stream.Error("Illegal character " ++ s)) - } - } - - let rec next_token = (strm__: Stream.t<_>) => - switch Stream.peek(strm__) { - | Some(' ' | '\n' | '\r' | '\t' | '' | ' ') => - Stream.junk(strm__) - next_token(strm__) - | Some(('A' .. 'Z' | 'a' .. 'z' | '_' | 'À' .. 'ÿ') as c) => - Stream.junk(strm__) - let s = strm__ - reset_buffer() - store(c) - ident(s) - | Some( - ('!' - | '%' - | '&' - | '$' - | '#' - | '+' - | '/' - | ':' - | '<' - | '=' - | '>' - | '?' - | '@' - | '\\' - | '~' - | '^' - | '|' - | '*') as c, - ) => - Stream.junk(strm__) - let s = strm__ - reset_buffer() - store(c) - ident2(s) - | Some('0' .. '9' as c) => - Stream.junk(strm__) - let s = strm__ - reset_buffer() - store(c) - number(s) - | Some('\'') => - Stream.junk(strm__) - let c = try char(strm__) catch { - | Stream.Failure => raise(Stream.Error("")) - } - - switch Stream.peek(strm__) { - | Some('\'') => - Stream.junk(strm__) - Some(Char(c)) - | _ => raise(Stream.Error("")) - } - | Some('"') => - Stream.junk(strm__) - let s = strm__ - reset_buffer() - Some(String(string(s))) - | Some('-') => - Stream.junk(strm__) - neg_number(strm__) - | Some('(') => - Stream.junk(strm__) - maybe_comment(strm__) - | Some(c) => - Stream.junk(strm__) - Some(keyword_or_error(c)) - | _ => None - } - and ident = (strm__: Stream.t<_>) => - switch Stream.peek(strm__) { - | Some(('A' .. 'Z' | 'a' .. 'z' | 'À' .. 'ÿ' | '0' .. '9' | '_' | '\'') as c) => - Stream.junk(strm__) - let s = strm__ - store(c) - ident(s) - | _ => Some(ident_or_keyword(get_string())) - } - and ident2 = (strm__: Stream.t<_>) => - switch Stream.peek(strm__) { - | Some( - ('!' - | '%' - | '&' - | '$' - | '#' - | '+' - | '-' - | '/' - | ':' - | '<' - | '=' - | '>' - | '?' - | '@' - | '\\' - | '~' - | '^' - | '|' - | '*') as c, - ) => - Stream.junk(strm__) - let s = strm__ - store(c) - ident2(s) - | _ => Some(ident_or_keyword(get_string())) - } - and neg_number = (strm__: Stream.t<_>) => - switch Stream.peek(strm__) { - | Some('0' .. '9' as c) => - Stream.junk(strm__) - let s = strm__ - reset_buffer() - store('-') - store(c) - number(s) - | _ => - let s = strm__ - reset_buffer() - store('-') - ident2(s) - } - and number = (strm__: Stream.t<_>) => - switch Stream.peek(strm__) { - | Some('0' .. '9' as c) => - Stream.junk(strm__) - let s = strm__ - store(c) - number(s) - | Some('.') => - Stream.junk(strm__) - let s = strm__ - store('.') - decimal_part(s) - | Some('e' | 'E') => - Stream.junk(strm__) - let s = strm__ - store('E') - exponent_part(s) - | _ => Some(Int(int_of_string(get_string()))) - } - and decimal_part = (strm__: Stream.t<_>) => - switch Stream.peek(strm__) { - | Some('0' .. '9' as c) => - Stream.junk(strm__) - let s = strm__ - store(c) - decimal_part(s) - | Some('e' | 'E') => - Stream.junk(strm__) - let s = strm__ - store('E') - exponent_part(s) - | _ => Some(Float(float_of_string(get_string()))) - } - and exponent_part = (strm__: Stream.t<_>) => - switch Stream.peek(strm__) { - | Some(('+' | '-') as c) => - Stream.junk(strm__) - let s = strm__ - store(c) - end_exponent_part(s) - | _ => end_exponent_part(strm__) - } - and end_exponent_part = (strm__: Stream.t<_>) => - switch Stream.peek(strm__) { - | Some('0' .. '9' as c) => - Stream.junk(strm__) - let s = strm__ - store(c) - end_exponent_part(s) - | _ => Some(Float(float_of_string(get_string()))) - } - and string = (strm__: Stream.t<_>) => - switch Stream.peek(strm__) { - | Some('"') => - Stream.junk(strm__) - get_string() - | Some('\\') => - Stream.junk(strm__) - let c = try escape(strm__) catch { - | Stream.Failure => raise(Stream.Error("")) - } - - let s = strm__ - store(c) - string(s) - | Some(c) => - Stream.junk(strm__) - let s = strm__ - store(c) - string(s) - | _ => raise(Stream.Failure) - } - and char = (strm__: Stream.t<_>) => - switch Stream.peek(strm__) { - | Some('\\') => - Stream.junk(strm__) - try escape(strm__) catch { - | Stream.Failure => raise(Stream.Error("")) - } - | Some(c) => - Stream.junk(strm__) - c - | _ => raise(Stream.Failure) - } - and escape = (strm__: Stream.t<_>) => - switch Stream.peek(strm__) { - | Some('n') => - Stream.junk(strm__) - '\n' - | Some('r') => - Stream.junk(strm__) - '\r' - | Some('t') => - Stream.junk(strm__) - '\t' - | Some('0' .. '9' as c1) => - Stream.junk(strm__) - switch Stream.peek(strm__) { - | Some('0' .. '9' as c2) => - Stream.junk(strm__) - switch Stream.peek(strm__) { - | Some('0' .. '9' as c3) => - Stream.junk(strm__) - Char.chr((Char.code(c1) - 48) * 100 + (Char.code(c2) - 48) * 10 + (Char.code(c3) - 48)) - | _ => raise(Stream.Error("")) - } - | _ => raise(Stream.Error("")) - } - | Some(c) => - Stream.junk(strm__) - c - | _ => raise(Stream.Failure) - } - and maybe_comment = (strm__: Stream.t<_>) => - switch Stream.peek(strm__) { - | Some('*') => - Stream.junk(strm__) - let s = strm__ - comment(s) - next_token(s) - | _ => Some(keyword_or_error('(')) - } - and comment = (strm__: Stream.t<_>) => - switch Stream.peek(strm__) { - | Some('(') => - Stream.junk(strm__) - maybe_nested_comment(strm__) - | Some('*') => - Stream.junk(strm__) - maybe_end_comment(strm__) - | Some(_) => - Stream.junk(strm__) - comment(strm__) - | _ => raise(Stream.Failure) - } - and maybe_nested_comment = (strm__: Stream.t<_>) => - switch Stream.peek(strm__) { - | Some('*') => - Stream.junk(strm__) - let s = strm__ - comment(s) - comment(s) - | Some(_) => - Stream.junk(strm__) - comment(strm__) - | _ => raise(Stream.Failure) - } - and maybe_end_comment = (strm__: Stream.t<_>) => - switch Stream.peek(strm__) { - | Some(')') => - Stream.junk(strm__) - () - | Some('*') => - Stream.junk(strm__) - maybe_end_comment(strm__) - | Some(_) => - Stream.junk(strm__) - comment(strm__) - | _ => raise(Stream.Failure) - } - - input => Stream.from(_count => next_token(input)) -} diff --git a/jscomp/stdlib-406/genlex.resi b/jscomp/stdlib-406/genlex.resi deleted file mode 100644 index 1d3f661670..0000000000 --- a/jscomp/stdlib-406/genlex.resi +++ /dev/null @@ -1,73 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/*** A generic lexical analyzer. - - - This module implements a simple 'standard' lexical analyzer, presented - as a function from character streams to token streams. It implements - roughly the lexical conventions of OCaml, but is parameterized by the - set of keywords of your language. - - - Example: a lexer suitable for a desk calculator is obtained by - {[ let lexer = make_lexer ["+";"-";"*";"/";"let";"="; "("; ")"] ]} - - The associated parser would be a function from [token stream] - to, for instance, [int], and would have rules such as: - - {[ - let rec parse_expr = parser - | [< n1 = parse_atom; n2 = parse_remainder n1 >] -> n2 - and parse_atom = parser - | [< 'Int n >] -> n - | [< 'Kwd "("; n = parse_expr; 'Kwd ")" >] -> n - and parse_remainder n1 = parser - | [< 'Kwd "+"; n2 = parse_expr >] -> n1+n2 - | [< >] -> n1 - ]} - - One should notice that the use of the [parser] keyword and associated - notation for streams are only available through camlp4 extensions. This - means that one has to preprocess its sources {i e. g.} by using the - ["-pp"] command-line switch of the compilers. -*/ - -/** The type of tokens. The lexical classes are: [Int] and [Float] - for integer and floating-point numbers; [String] for - string literals, enclosed in double quotes; [Char] for - character literals, enclosed in single quotes; [Ident] for - identifiers (either sequences of letters, digits, underscores - and quotes, or sequences of 'operator characters' such as - [+], [*], etc); and [Kwd] for keywords (either identifiers or - single 'special characters' such as [(], [}], etc). */ -type token = - | Kwd(string) - | Ident(string) - | Int(int) - | Float(float) - | String(string) - | Char(char) - -/** Construct the lexer function. The first argument is the list of - keywords. An identifier [s] is returned as [Kwd s] if [s] - belongs to this list, and as [Ident s] otherwise. - A special character [s] is returned as [Kwd s] if [s] - belongs to this list, and cause a lexical error (exception - {!Stream.Error} with the offending lexeme as its parameter) otherwise. - Blanks and newlines are skipped. Comments delimited by [(*] and [*)] - are skipped as well, and can be nested. A {!Stream.Failure} exception - is raised if end of stream is unexpectedly reached.*/ -let make_lexer: list => (Stream.t => Stream.t) diff --git a/jscomp/stdlib-406/hashtbl.res b/jscomp/stdlib-406/hashtbl.res deleted file mode 100644 index 58c3ac9735..0000000000 --- a/jscomp/stdlib-406/hashtbl.res +++ /dev/null @@ -1,679 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/* Hash tables */ - -@noalloc external seeded_hash_param: (int, int, int, 'a) => int = "?hash" -/* external old_hash_param : - int -> int -> 'a -> int = "caml_hash_univ_param" [@@noalloc] */ - -let hash = x => seeded_hash_param(10, 100, 0, x) -let hash_param = (n1, n2, x) => seeded_hash_param(n1, n2, 0, x) -let seeded_hash = (seed, x) => seeded_hash_param(10, 100, seed, x) - -/* We do dynamic hashing, and resize the table and rehash the elements - when buckets become too long. */ - -type rec t<'a, 'b> = { - mutable size: int /* number of entries */, - mutable data: array> /* the buckets */, - mutable seed: int /* for randomization */, - mutable initial_size: int /* initial array size */, -} - -and bucketlist<'a, 'b> = - | Empty - | Cons({mutable key: 'a, mutable data: 'b, mutable next: bucketlist<'a, 'b>}) - -/* The sign of initial_size encodes the fact that a traversal is - ongoing or not. - - This disables the efficient in place implementation of resizing. -*/ - -let ongoing_traversal = h => h.initial_size < 0 - -let flip_ongoing_traversal = h => h.initial_size = -h.initial_size - -/* To pick random seeds if requested */ - -let randomized_default = false - -let randomized = ref(randomized_default) - -let randomize = () => randomized := true -let is_randomized = () => randomized.contents - -let prng = Lazy.from_fun(() => Random.State.make_self_init()) - -/* Creating a fresh, empty table */ - -let rec power_2_above = (x, n) => - if x >= n { - x - } else if x * 2 < x { - x /* overflow */ - } else { - power_2_above(x * 2, n) - } - -let create = (~random=randomized.contents, initial_size) => { - let s = power_2_above(16, initial_size) - let seed = if random { - Random.State.bits(Lazy.force(prng)) - } else { - 0 - } - {initial_size: s, size: 0, seed, data: Array.make(s, Empty)} -} - -let clear = h => { - h.size = 0 - let len = Array.length(h.data) - for i in 0 to len - 1 { - h.data[i] = Empty - } -} - -let reset = h => { - let len = Array.length(h.data) - if len == abs(h.initial_size) { - clear(h) - } else { - h.size = 0 - h.data = Array.make(abs(h.initial_size), Empty) - } -} - -let copy_bucketlist = param => - switch param { - | Empty => Empty - | Cons({key, data, next}) => - let rec loop = (prec, param) => - switch param { - | Empty => () - | Cons({key, data, next}) => - let r = Cons({key, data, next}) - switch prec { - | Empty => assert(false) - | Cons(prec) => prec.next = r - } - loop(r, next) - } - - let r = Cons({key, data, next}) - loop(r, next) - r - } - -let copy = h => {...h, data: Array.map(copy_bucketlist, h.data)} - -let length = h => h.size - -let resize = (indexfun, h) => { - let odata = h.data - let osize = Array.length(odata) - let nsize = osize * 2 - if nsize >= osize { - let ndata = Array.make(nsize, Empty) - let ndata_tail = Array.make(nsize, Empty) - let inplace = !ongoing_traversal(h) - h.data = ndata /* so that indexfun sees the new bucket count */ - let rec insert_bucket = param => - switch param { - | Empty => () - | Cons({key, data, next}) as cell => - let cell = if inplace { - cell - } else { - Cons({key, data, next: Empty}) - } - - let nidx = indexfun(h, key) - switch ndata_tail[nidx] { - | Empty => ndata[nidx] = cell - | Cons(tail) => tail.next = cell - } - ndata_tail[nidx] = cell - insert_bucket(next) - } - - for i in 0 to osize - 1 { - insert_bucket(odata[i]) - } - if inplace { - for i in 0 to nsize - 1 { - switch ndata_tail[i] { - | Empty => () - | Cons(tail) => tail.next = Empty - } - } - } - } -} - -let key_index = (h, key) => - /* compatibility with old hash tables */ - land(seeded_hash_param(10, 100, h.seed, key), Array.length(h.data) - 1) - -let add = (h, key, data) => { - let i = key_index(h, key) - let bucket = Cons({key, data, next: h.data[i]}) - h.data[i] = bucket - h.size = h.size + 1 - if h.size > lsl(Array.length(h.data), 1) { - resize(key_index, h) - } -} - -let rec remove_bucket = (h, i, key, prec, param) => - switch param { - | Empty => () - | Cons({key: k, next}) as c => - if compare(k, key) == 0 { - h.size = h.size - 1 - switch prec { - | Empty => h.data[i] = next - | Cons(c) => c.next = next - } - } else { - remove_bucket(h, i, key, c, next) - } - } - -let remove = (h, key) => { - let i = key_index(h, key) - remove_bucket(h, i, key, Empty, h.data[i]) -} - -let rec find_rec = (key, param) => - switch param { - | Empty => raise(Not_found) - | Cons({key: k, data, next}) => - if compare(key, k) == 0 { - data - } else { - find_rec(key, next) - } - } - -let find = (h, key) => - switch h.data[key_index(h, key)] { - | Empty => raise(Not_found) - | Cons({key: k1, data: d1, next: next1}) => - if compare(key, k1) == 0 { - d1 - } else { - switch next1 { - | Empty => raise(Not_found) - | Cons({key: k2, data: d2, next: next2}) => - if compare(key, k2) == 0 { - d2 - } else { - switch next2 { - | Empty => raise(Not_found) - | Cons({key: k3, data: d3, next: next3}) => - if compare(key, k3) == 0 { - d3 - } else { - find_rec(key, next3) - } - } - } - } - } - } - -let rec find_rec_opt = (key, param) => - switch param { - | Empty => None - | Cons({key: k, data, next}) => - if compare(key, k) == 0 { - Some(data) - } else { - find_rec_opt(key, next) - } - } - -let find_opt = (h, key) => - switch h.data[key_index(h, key)] { - | Empty => None - | Cons({key: k1, data: d1, next: next1}) => - if compare(key, k1) == 0 { - Some(d1) - } else { - switch next1 { - | Empty => None - | Cons({key: k2, data: d2, next: next2}) => - if compare(key, k2) == 0 { - Some(d2) - } else { - switch next2 { - | Empty => None - | Cons({key: k3, data: d3, next: next3}) => - if compare(key, k3) == 0 { - Some(d3) - } else { - find_rec_opt(key, next3) - } - } - } - } - } - } - -let find_all = (h, key) => { - let rec find_in_bucket = param => - switch param { - | Empty => list{} - | Cons({key: k, data, next}) => - if compare(k, key) == 0 { - list{data, ...find_in_bucket(next)} - } else { - find_in_bucket(next) - } - } - find_in_bucket(h.data[key_index(h, key)]) -} - -let rec replace_bucket = (key, data, param) => - switch param { - | Empty => true - | Cons({key: k, next} as slot) => - if compare(k, key) == 0 { - slot.key = key - slot.data = data - false - } else { - replace_bucket(key, data, next) - } - } - -let replace = (h, key, data) => { - let i = key_index(h, key) - let l = h.data[i] - if replace_bucket(key, data, l) { - h.data[i] = Cons({key, data, next: l}) - h.size = h.size + 1 - if h.size > lsl(Array.length(h.data), 1) { - resize(key_index, h) - } - } -} - -let mem = (h, key) => { - let rec mem_in_bucket = param => - switch param { - | Empty => false - | Cons({key: k, next}) => compare(k, key) == 0 || mem_in_bucket(next) - } - mem_in_bucket(h.data[key_index(h, key)]) -} - -let iter = (f, h) => { - let rec do_bucket = param => - switch param { - | Empty => () - | Cons({key, data, next}) => - f(key, data) - do_bucket(next) - } - let old_trav = ongoing_traversal(h) - if !old_trav { - flip_ongoing_traversal(h) - } - try { - let d = h.data - for i in 0 to Array.length(d) - 1 { - do_bucket(d[i]) - } - if !old_trav { - flip_ongoing_traversal(h) - } - } catch { - | exn if !old_trav => - flip_ongoing_traversal(h) - raise(exn) - } -} - -let rec filter_map_inplace_bucket = (f, h, i, prec, param) => - switch param { - | Empty => - switch prec { - | Empty => h.data[i] = Empty - | Cons(c) => c.next = Empty - } - | Cons({key, data, next} as c) as slot => - switch f(key, data) { - | None => - h.size = h.size - 1 - filter_map_inplace_bucket(f, h, i, prec, next) - | Some(data) => - switch prec { - | Empty => h.data[i] = slot - | Cons(c) => c.next = slot - } - c.data = data - filter_map_inplace_bucket(f, h, i, slot, next) - } - } - -let filter_map_inplace = (f, h) => { - let d = h.data - let old_trav = ongoing_traversal(h) - if !old_trav { - flip_ongoing_traversal(h) - } - try for i in 0 to Array.length(d) - 1 { - filter_map_inplace_bucket(f, h, i, Empty, h.data[i]) - } catch { - | exn if !old_trav => - flip_ongoing_traversal(h) - raise(exn) - } -} - -let fold = (f, h, init) => { - let rec do_bucket = (b, accu) => - switch b { - | Empty => accu - | Cons({key, data, next}) => do_bucket(next, f(key, data, accu)) - } - let old_trav = ongoing_traversal(h) - if !old_trav { - flip_ongoing_traversal(h) - } - try { - let d = h.data - let accu = ref(init) - for i in 0 to Array.length(d) - 1 { - accu := do_bucket(d[i], accu.contents) - } - if !old_trav { - flip_ongoing_traversal(h) - } - accu.contents - } catch { - | exn if !old_trav => - flip_ongoing_traversal(h) - raise(exn) - } -} - -type statistics = { - num_bindings: int, - num_buckets: int, - max_bucket_length: int, - bucket_histogram: array, -} - -let rec bucket_length = (accu, param) => - switch param { - | Empty => accu - | Cons({next}) => bucket_length(accu + 1, next) - } - -let stats = h => { - let mbl = Array.fold_left((m, b) => max(m, bucket_length(0, b)), 0, h.data) - let histo = Array.make(mbl + 1, 0) - Array.iter(b => { - let l = bucket_length(0, b) - histo[l] = histo[l] + 1 - }, h.data) - { - num_bindings: h.size, - num_buckets: Array.length(h.data), - max_bucket_length: mbl, - bucket_histogram: histo, - } -} - -/* Functorial interface */ - -module type HashedType = { - type t - let equal: (t, t) => bool - let hash: t => int -} - -module type SeededHashedType = { - type t - let equal: (t, t) => bool - let hash: (int, t) => int -} - -module type S = { - type key - type t<'a> - let create: int => t<'a> - let clear: t<'a> => unit - let reset: t<'a> => unit - let copy: t<'a> => t<'a> - let add: (t<'a>, key, 'a) => unit - let remove: (t<'a>, key) => unit - let find: (t<'a>, key) => 'a - let find_opt: (t<'a>, key) => option<'a> - let find_all: (t<'a>, key) => list<'a> - let replace: (t<'a>, key, 'a) => unit - let mem: (t<'a>, key) => bool - let iter: ((key, 'a) => unit, t<'a>) => unit - let filter_map_inplace: ((key, 'a) => option<'a>, t<'a>) => unit - let fold: ((key, 'a, 'b) => 'b, t<'a>, 'b) => 'b - let length: t<'a> => int - let stats: t<'a> => statistics -} - -module type SeededS = { - type key - type t<'a> - let create: (~random: bool=?, int) => t<'a> - let clear: t<'a> => unit - let reset: t<'a> => unit - let copy: t<'a> => t<'a> - let add: (t<'a>, key, 'a) => unit - let remove: (t<'a>, key) => unit - let find: (t<'a>, key) => 'a - let find_opt: (t<'a>, key) => option<'a> - let find_all: (t<'a>, key) => list<'a> - let replace: (t<'a>, key, 'a) => unit - let mem: (t<'a>, key) => bool - let iter: ((key, 'a) => unit, t<'a>) => unit - let filter_map_inplace: ((key, 'a) => option<'a>, t<'a>) => unit - let fold: ((key, 'a, 'b) => 'b, t<'a>, 'b) => 'b - let length: t<'a> => int - let stats: t<'a> => statistics -} - -module MakeSeeded = (H: SeededHashedType): (SeededS with type key = H.t) => { - type key = H.t - type hashtbl<'a> = t - type t<'a> = hashtbl<'a> - let create = create - let clear = clear - let reset = reset - let copy = copy - - let key_index = (h, key) => land(H.hash(h.seed, key), Array.length(h.data) - 1) - - let add = (h, key, data) => { - let i = key_index(h, key) - let bucket = Cons({key, data, next: h.data[i]}) - h.data[i] = bucket - h.size = h.size + 1 - if h.size > lsl(Array.length(h.data), 1) { - resize(key_index, h) - } - } - - let rec remove_bucket = (h, i, key, prec, param) => - switch param { - | Empty => () - | Cons({key: k, next}) as c => - if H.equal(k, key) { - h.size = h.size - 1 - switch prec { - | Empty => h.data[i] = next - | Cons(c) => c.next = next - } - } else { - remove_bucket(h, i, key, c, next) - } - } - - let remove = (h, key) => { - let i = key_index(h, key) - remove_bucket(h, i, key, Empty, h.data[i]) - } - - let rec find_rec = (key, param) => - switch param { - | Empty => raise(Not_found) - | Cons({key: k, data, next}) => - if H.equal(key, k) { - data - } else { - find_rec(key, next) - } - } - - let find = (h, key) => - switch h.data[key_index(h, key)] { - | Empty => raise(Not_found) - | Cons({key: k1, data: d1, next: next1}) => - if H.equal(key, k1) { - d1 - } else { - switch next1 { - | Empty => raise(Not_found) - | Cons({key: k2, data: d2, next: next2}) => - if H.equal(key, k2) { - d2 - } else { - switch next2 { - | Empty => raise(Not_found) - | Cons({key: k3, data: d3, next: next3}) => - if H.equal(key, k3) { - d3 - } else { - find_rec(key, next3) - } - } - } - } - } - } - - let rec find_rec_opt = (key, param) => - switch param { - | Empty => None - | Cons({key: k, data, next}) => - if H.equal(key, k) { - Some(data) - } else { - find_rec_opt(key, next) - } - } - - let find_opt = (h, key) => - switch h.data[key_index(h, key)] { - | Empty => None - | Cons({key: k1, data: d1, next: next1}) => - if H.equal(key, k1) { - Some(d1) - } else { - switch next1 { - | Empty => None - | Cons({key: k2, data: d2, next: next2}) => - if H.equal(key, k2) { - Some(d2) - } else { - switch next2 { - | Empty => None - | Cons({key: k3, data: d3, next: next3}) => - if H.equal(key, k3) { - Some(d3) - } else { - find_rec_opt(key, next3) - } - } - } - } - } - } - - let find_all = (h, key) => { - let rec find_in_bucket = param => - switch param { - | Empty => list{} - | Cons({key: k, data: d, next}) => - if H.equal(k, key) { - list{d, ...find_in_bucket(next)} - } else { - find_in_bucket(next) - } - } - find_in_bucket(h.data[key_index(h, key)]) - } - - let rec replace_bucket = (key, data, param) => - switch param { - | Empty => true - | Cons({key: k, next} as slot) => - if H.equal(k, key) { - slot.key = key - slot.data = data - false - } else { - replace_bucket(key, data, next) - } - } - - let replace = (h, key, data) => { - let i = key_index(h, key) - let l = h.data[i] - if replace_bucket(key, data, l) { - h.data[i] = Cons({key, data, next: l}) - h.size = h.size + 1 - if h.size > lsl(Array.length(h.data), 1) { - resize(key_index, h) - } - } - } - - let mem = (h, key) => { - let rec mem_in_bucket = param => - switch param { - | Empty => false - | Cons({key: k, next}) => H.equal(k, key) || mem_in_bucket(next) - } - mem_in_bucket(h.data[key_index(h, key)]) - } - - let iter = iter - let filter_map_inplace = filter_map_inplace - let fold = fold - let length = length - let stats = stats -} - -module Make = (H: HashedType): (S with type key = H.t) => { - include MakeSeeded({ - type t = H.t - let equal = H.equal - let hash = (_seed: int, x) => H.hash(x) - }) - let create = sz => create(~random=false, sz) -} diff --git a/jscomp/stdlib-406/hashtbl.resi b/jscomp/stdlib-406/hashtbl.resi deleted file mode 100644 index 5acfde280f..0000000000 --- a/jscomp/stdlib-406/hashtbl.resi +++ /dev/null @@ -1,406 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/*** Hash tables and hash functions. - - Hash tables are hashed association tables, with in-place modification. -*/ - -/* {1 Generic interface} */ - -/** The type of hash tables from type ['a] to type ['b]. */ -type t<'a, 'b> - -/** [Hashtbl.create n] creates a new, empty hash table, with - initial size [n]. For best results, [n] should be on the - order of the expected number of elements that will be in - the table. The table grows as needed, so [n] is just an - initial guess. - - The optional [random] parameter (a boolean) controls whether - the internal organization of the hash table is randomized at each - execution of [Hashtbl.create] or deterministic over all executions. - - A hash table that is created with [~random:false] uses a - fixed hash function ({!Hashtbl.hash}) to distribute keys among - buckets. As a consequence, collisions between keys happen - deterministically. In Web-facing applications or other - security-sensitive applications, the deterministic collision - patterns can be exploited by a malicious user to create a - denial-of-service attack: the attacker sends input crafted to - create many collisions in the table, slowing the application down. - - A hash table that is created with [~random:true] uses the seeded - hash function {!Hashtbl.seeded_hash} with a seed that is randomly - chosen at hash table creation time. In effect, the hash function - used is randomly selected among [2^{30}] different hash functions. - All these hash functions have different collision patterns, - rendering ineffective the denial-of-service attack described above. - However, because of randomization, enumerating all elements of the - hash table using {!Hashtbl.fold} or {!Hashtbl.iter} is no longer - deterministic: elements are enumerated in different orders at - different runs of the program. - - If no [~random] parameter is given, hash tables are created - in non-random mode by default. This default can be changed - either programmatically by calling {!Hashtbl.randomize} or by - setting the [R] flag in the [OCAMLRUNPARAM] environment variable. - - @before 4.00.0 the [random] parameter was not present and all - hash tables were created in non-randomized mode. */ -let create: (~random: bool=?, int) => t<'a, 'b> - -/** Empty a hash table. Use [reset] instead of [clear] to shrink the - size of the bucket table to its initial size. */ -let clear: t<'a, 'b> => unit - -/** Empty a hash table and shrink the size of the bucket table - to its initial size. - @since 4.00.0 */ -let reset: t<'a, 'b> => unit - -/** Return a copy of the given hashtable. */ -let copy: t<'a, 'b> => t<'a, 'b> - -/** [Hashtbl.add tbl x y] adds a binding of [x] to [y] in table [tbl]. - Previous bindings for [x] are not removed, but simply - hidden. That is, after performing {!Hashtbl.remove}[ tbl x], - the previous binding for [x], if any, is restored. - (Same behavior as with association lists.) */ -let add: (t<'a, 'b>, 'a, 'b) => unit - -/** [Hashtbl.find tbl x] returns the current binding of [x] in [tbl], - or raises [Not_found] if no such binding exists. */ -let find: (t<'a, 'b>, 'a) => 'b - -/** [Hashtbl.find_opt tbl x] returns the current binding of [x] in [tbl], - or [None] if no such binding exists. - @since 4.05 */ -let find_opt: (t<'a, 'b>, 'a) => option<'b> - -/** [Hashtbl.find_all tbl x] returns the list of all data - associated with [x] in [tbl]. - The current binding is returned first, then the previous - bindings, in reverse order of introduction in the table. */ -let find_all: (t<'a, 'b>, 'a) => list<'b> - -/** [Hashtbl.mem tbl x] checks if [x] is bound in [tbl]. */ -let mem: (t<'a, 'b>, 'a) => bool - -/** [Hashtbl.remove tbl x] removes the current binding of [x] in [tbl], - restoring the previous binding if it exists. - It does nothing if [x] is not bound in [tbl]. */ -let remove: (t<'a, 'b>, 'a) => unit - -/** [Hashtbl.replace tbl x y] replaces the current binding of [x] - in [tbl] by a binding of [x] to [y]. If [x] is unbound in [tbl], - a binding of [x] to [y] is added to [tbl]. - This is functionally equivalent to {!Hashtbl.remove}[ tbl x] - followed by {!Hashtbl.add}[ tbl x y]. */ -let replace: (t<'a, 'b>, 'a, 'b) => unit - -/** [Hashtbl.iter f tbl] applies [f] to all bindings in table [tbl]. - [f] receives the key as first argument, and the associated value - as second argument. Each binding is presented exactly once to [f]. - - The order in which the bindings are passed to [f] is unspecified. - However, if the table contains several bindings for the same key, - they are passed to [f] in reverse order of introduction, that is, - the most recent binding is passed first. - - If the hash table was created in non-randomized mode, the order - in which the bindings are enumerated is reproducible between - successive runs of the program, and even between minor versions - of OCaml. For randomized hash tables, the order of enumeration - is entirely random. - - The behavior is not defined if the hash table is modified - by [f] during the iteration. -*/ -let iter: (('a, 'b) => unit, t<'a, 'b>) => unit - -/** [Hashtbl.filter_map_inplace f tbl] applies [f] to all bindings in - table [tbl] and update each binding depending on the result of - [f]. If [f] returns [None], the binding is discarded. If it - returns [Some new_val], the binding is update to associate the key - to [new_val]. - - Other comments for {!Hashtbl.iter} apply as well. - @since 4.03.0 */ -let filter_map_inplace: (('a, 'b) => option<'b>, t<'a, 'b>) => unit - -/** [Hashtbl.fold f tbl init] computes - [(f kN dN ... (f k1 d1 init)...)], - where [k1 ... kN] are the keys of all bindings in [tbl], - and [d1 ... dN] are the associated values. - Each binding is presented exactly once to [f]. - - The order in which the bindings are passed to [f] is unspecified. - However, if the table contains several bindings for the same key, - they are passed to [f] in reverse order of introduction, that is, - the most recent binding is passed first. - - If the hash table was created in non-randomized mode, the order - in which the bindings are enumerated is reproducible between - successive runs of the program, and even between minor versions - of OCaml. For randomized hash tables, the order of enumeration - is entirely random. - - The behavior is not defined if the hash table is modified - by [f] during the iteration. -*/ -let fold: (('a, 'b, 'c) => 'c, t<'a, 'b>, 'c) => 'c - -/** [Hashtbl.length tbl] returns the number of bindings in [tbl]. - It takes constant time. Multiple bindings are counted once each, so - [Hashtbl.length] gives the number of times [Hashtbl.iter] calls its - first argument. */ -let length: t<'a, 'b> => int - -/** After a call to [Hashtbl.randomize()], hash tables are created in - randomized mode by default: {!Hashtbl.create} returns randomized - hash tables, unless the [~random:false] optional parameter is given. - The same effect can be achieved by setting the [R] parameter in - the [OCAMLRUNPARAM] environment variable. - - It is recommended that applications or Web frameworks that need to - protect themselves against the denial-of-service attack described - in {!Hashtbl.create} call [Hashtbl.randomize()] at initialization - time. - - Note that once [Hashtbl.randomize()] was called, there is no way - to revert to the non-randomized default behavior of {!Hashtbl.create}. - This is intentional. Non-randomized hash tables can still be - created using [Hashtbl.create ~random:false]. - - @since 4.00.0 */ -let randomize: unit => unit - -/** return if the tables are currently created in randomized mode by default - - @since 4.03.0 */ -let is_randomized: unit => bool - -/** @since 4.00.0 */ -type statistics = { - /** Number of bindings present in the table. - Same value as returned by {!Hashtbl.length}. */ - num_bindings: int, - /** Number of buckets in the table. */ - num_buckets: int, - /** Maximal number of bindings per bucket. */ - max_bucket_length: int, - /** Histogram of bucket sizes. This array [histo] has - length [max_bucket_length + 1]. The value of - [histo.(i)] is the number of buckets whose size is [i]. */ - bucket_histogram: array, -} - -/** [Hashtbl.stats tbl] returns statistics about the table [tbl]: - number of buckets, size of the biggest bucket, distribution of - buckets by size. - @since 4.00.0 */ -let stats: t<'a, 'b> => statistics - -/* {1 Functorial interface} - -The functorial interface allows the use of specific comparison - and hash functions, either for performance/security concerns, - or because keys are not hashable/comparable with the polymorphic builtins. - - For instance, one might want to specialize a table for integer keys: - {[ - module IntHash = - struct - type t = int - let equal i j = i=j - let hash i = i land max_int - end - - module IntHashtbl = Hashtbl.Make(IntHash) - - let h = IntHashtbl.create 17 in - IntHashtbl.add h 12 "hello" - ]} - - This creates a new module [IntHashtbl], with a new type ['a - IntHashtbl.t] of tables from [int] to ['a]. In this example, [h] - contains [string] values so its type is [string IntHashtbl.t]. - - Note that the new type ['a IntHashtbl.t] is not compatible with - the type [('a,'b) Hashtbl.t] of the generic interface. For - example, [Hashtbl.length h] would not type-check, you must use - [IntHashtbl.length]. -*/ - -/** The input signature of the functor {!Hashtbl.Make}. */ -module type HashedType = { - /** The type of the hashtable keys. */ - type t - - /** The equality predicate used to compare keys. */ - let equal: (t, t) => bool - - /** A hashing function on keys. It must be such that if two keys are - equal according to [equal], then they have identical hash values - as computed by [hash]. - Examples: suitable ([equal], [hash]) pairs for arbitrary key - types include -- ([(=)], {!Hashtbl.hash}) for comparing objects by structure - (provided objects do not contain floats) -- ([(fun x y -> compare x y = 0)], {!Hashtbl.hash}) - for comparing objects by structure - and handling {!Pervasives.nan} correctly -- ([(==)], {!Hashtbl.hash}) for comparing objects by physical - equality (e.g. for mutable or cyclic objects). */ - let hash: t => int -} - -/** The output signature of the functor {!Hashtbl.Make}. */ -module type S = { - type key - type t<'a> - let create: int => t<'a> - let clear: t<'a> => unit - /** @since 4.00.0 */ - let reset: t<'a> => unit - - let copy: t<'a> => t<'a> - let add: (t<'a>, key, 'a) => unit - let remove: (t<'a>, key) => unit - let find: (t<'a>, key) => 'a - /** @since 4.05.0 */ - let find_opt: (t<'a>, key) => option<'a> - - let find_all: (t<'a>, key) => list<'a> - let replace: (t<'a>, key, 'a) => unit - let mem: (t<'a>, key) => bool - let iter: ((key, 'a) => unit, t<'a>) => unit - /** @since 4.03.0 */ - let filter_map_inplace: ((key, 'a) => option<'a>, t<'a>) => unit - - let fold: ((key, 'a, 'b) => 'b, t<'a>, 'b) => 'b - let length: t<'a> => int - /** @since 4.00.0 */ - let stats: t<'a> => statistics -} - -/** Functor building an implementation of the hashtable structure. - The functor [Hashtbl.Make] returns a structure containing - a type [key] of keys and a type ['a t] of hash tables - associating data of type ['a] to keys of type [key]. - The operations perform similarly to those of the generic - interface, but use the hashing and equality functions - specified in the functor argument [H] instead of generic - equality and hashing. Since the hash function is not seeded, - the [create] operation of the result structure always returns - non-randomized hash tables. */ -module Make: (H: HashedType) => (S with type key = H.t) - -/** The input signature of the functor {!Hashtbl.MakeSeeded}. - @since 4.00.0 */ -module type SeededHashedType = { - /** The type of the hashtable keys. */ - type t - - /** The equality predicate used to compare keys. */ - let equal: (t, t) => bool - - /** A seeded hashing function on keys. The first argument is - the seed. It must be the case that if [equal x y] is true, - then [hash seed x = hash seed y] for any value of [seed]. - A suitable choice for [hash] is the function {!Hashtbl.seeded_hash} - below. */ - let hash: (int, t) => int -} - -/** The output signature of the functor {!Hashtbl.MakeSeeded}. - @since 4.00.0 */ -module type SeededS = { - type key - type t<'a> - let create: (~random: bool=?, int) => t<'a> - let clear: t<'a> => unit - let reset: t<'a> => unit - let copy: t<'a> => t<'a> - let add: (t<'a>, key, 'a) => unit - let remove: (t<'a>, key) => unit - let find: (t<'a>, key) => 'a - /** @since 4.05.0 */ - let find_opt: (t<'a>, key) => option<'a> - - let find_all: (t<'a>, key) => list<'a> - let replace: (t<'a>, key, 'a) => unit - let mem: (t<'a>, key) => bool - let iter: ((key, 'a) => unit, t<'a>) => unit - /** @since 4.03.0 */ - let filter_map_inplace: ((key, 'a) => option<'a>, t<'a>) => unit - - let fold: ((key, 'a, 'b) => 'b, t<'a>, 'b) => 'b - let length: t<'a> => int - let stats: t<'a> => statistics -} - -/** Functor building an implementation of the hashtable structure. - The functor [Hashtbl.MakeSeeded] returns a structure containing - a type [key] of keys and a type ['a t] of hash tables - associating data of type ['a] to keys of type [key]. - The operations perform similarly to those of the generic - interface, but use the seeded hashing and equality functions - specified in the functor argument [H] instead of generic - equality and hashing. The [create] operation of the - result structure supports the [~random] optional parameter - and returns randomized hash tables if [~random:true] is passed - or if randomization is globally on (see {!Hashtbl.randomize}). - @since 4.00.0 */ -module MakeSeeded: (H: SeededHashedType) => (SeededS with type key = H.t) - -/* {1 The polymorphic hash functions} */ - -/** [Hashtbl.hash x] associates a nonnegative integer to any value of - any type. It is guaranteed that - if [x = y] or [Pervasives.compare x y = 0], then [hash x = hash y]. - Moreover, [hash] always terminates, even on cyclic structures. */ -let hash: 'a => int - -/** A variant of {!Hashtbl.hash} that is further parameterized by - an integer seed. - @since 4.00.0 */ -let seeded_hash: (int, 'a) => int - -/** [Hashtbl.hash_param meaningful total x] computes a hash value for [x], - with the same properties as for [hash]. The two extra integer - parameters [meaningful] and [total] give more precise control over - hashing. Hashing performs a breadth-first, left-to-right traversal - of the structure [x], stopping after [meaningful] meaningful nodes - were encountered, or [total] nodes (meaningful or not) were - encountered. If [total] as specified by the user exceeds a certain - value, currently 256, then it is capped to that value. - Meaningful nodes are: integers; floating-point - numbers; strings; characters; booleans; and constant - constructors. Larger values of [meaningful] and [total] means that - more nodes are taken into account to compute the final hash value, - and therefore collisions are less likely to happen. However, - hashing takes longer. The parameters [meaningful] and [total] - govern the tradeoff between accuracy and speed. As default - choices, {!Hashtbl.hash} and {!Hashtbl.seeded_hash} take - [meaningful = 10] and [total = 100]. */ -let hash_param: (int, int, 'a) => int - -/** A variant of {!Hashtbl.hash_param} that is further parameterized by - an integer seed. Usage: - [Hashtbl.seeded_hash_param meaningful total seed x]. - @since 4.00.0 */ -let seeded_hash_param: (int, int, int, 'a) => int diff --git a/jscomp/stdlib-406/hashtblLabels.res b/jscomp/stdlib-406/hashtblLabels.res deleted file mode 100644 index e9fe63a1fa..0000000000 --- a/jscomp/stdlib-406/hashtblLabels.res +++ /dev/null @@ -1,129 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/* Hash tables */ - -type t<'a, 'b> = Hashtbl.t<'a, 'b> - -let { - create, - clear, - reset, - copy, - add, - find, - find_opt, - find_all, - mem, - remove, - replace, - iter, - filter_map_inplace, - fold, - length, - randomize, - is_randomized, - stats, - hash, - seeded_hash, - hash_param, - seeded_hash_param, -} = module(Hashtbl) - -let add = (tbl, ~key, ~data) => add(tbl, key, data) - -let replace = (tbl, ~key, ~data) => replace(tbl, key, data) - -let iter = (~f, tbl) => iter((key, data) => f(~key, ~data), tbl) - -let filter_map_inplace = (~f, tbl) => filter_map_inplace((key, data) => f(~key, ~data), tbl) - -let fold = (~f, tbl, ~init) => fold((key, data, acc) => f(~key, ~data, acc), tbl, init) - -type statistics = Hashtbl.statistics = { - num_bindings: int, - num_buckets: int, - max_bucket_length: int, - bucket_histogram: array, -} - -/* Functorial interface */ - -module type HashedType = Hashtbl.HashedType - -module type SeededHashedType = Hashtbl.SeededHashedType - -module type S = { - type rec key - and t<'a> - let create: int => t<'a> - let clear: t<'a> => unit - let reset: t<'a> => unit - let copy: t<'a> => t<'a> - let add: (t<'a>, ~key: key, ~data: 'a) => unit - let remove: (t<'a>, key) => unit - let find: (t<'a>, key) => 'a - let find_opt: (t<'a>, key) => option<'a> - let find_all: (t<'a>, key) => list<'a> - let replace: (t<'a>, ~key: key, ~data: 'a) => unit - let mem: (t<'a>, key) => bool - let iter: (~f: (~key: key, ~data: 'a) => unit, t<'a>) => unit - let filter_map_inplace: (~f: (~key: key, ~data: 'a) => option<'a>, t<'a>) => unit - let fold: (~f: (~key: key, ~data: 'a, 'b) => 'b, t<'a>, ~init: 'b) => 'b - let length: t<'a> => int - let stats: t<'a> => statistics -} - -module type SeededS = { - type rec key - and t<'a> - let create: (~random: bool=?, int) => t<'a> - let clear: t<'a> => unit - let reset: t<'a> => unit - let copy: t<'a> => t<'a> - let add: (t<'a>, ~key: key, ~data: 'a) => unit - let remove: (t<'a>, key) => unit - let find: (t<'a>, key) => 'a - let find_opt: (t<'a>, key) => option<'a> - let find_all: (t<'a>, key) => list<'a> - let replace: (t<'a>, ~key: key, ~data: 'a) => unit - let mem: (t<'a>, key) => bool - let iter: (~f: (~key: key, ~data: 'a) => unit, t<'a>) => unit - let filter_map_inplace: (~f: (~key: key, ~data: 'a) => option<'a>, t<'a>) => unit - let fold: (~f: (~key: key, ~data: 'a, 'b) => 'b, t<'a>, ~init: 'b) => 'b - let length: t<'a> => int - let stats: t<'a> => statistics -} - -module MakeSeeded = (H: SeededHashedType): (SeededS with type key = H.t) => { - include Hashtbl.MakeSeeded(H) - let add = (tbl, ~key, ~data) => add(tbl, key, data) - let replace = (tbl, ~key, ~data) => replace(tbl, key, data) - - let iter = (~f, tbl) => iter((key, data) => f(~key, ~data), tbl) - - let filter_map_inplace = (~f, tbl) => filter_map_inplace((key, data) => f(~key, ~data), tbl) - - let fold = (~f, tbl, ~init) => fold((key, data, acc) => f(~key, ~data, acc), tbl, init) -} - -module Make = (H: HashedType): (S with type key = H.t) => { - include MakeSeeded({ - type t = H.t - let equal = H.equal - let hash = (_seed: int, x) => H.hash(x) - }) - let create = sz => create(~random=false, sz) -} diff --git a/jscomp/stdlib-406/int32.res b/jscomp/stdlib-406/int32.res deleted file mode 100644 index d3a53dbbdf..0000000000 --- a/jscomp/stdlib-406/int32.res +++ /dev/null @@ -1,64 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ -type t = int -/* Module [t]: 32-bit integers */ - -external neg: t => t = "%negint" -external add: (t, t) => t = "%addint" -external sub: (t, t) => t = "%subint" -external mul: (t, t) => t = "%mulint" -external div: (t, t) => t = "%divint" -external rem: (t, t) => t = "%modint" -external logand: (t, t) => t = "%andint" -external logor: (t, t) => t = "%orint" -external logxor: (t, t) => t = "%xorint" -external shift_left: (t, int) => t = "%lslint" -external shift_right: (t, int) => t = "%asrint" -external shift_right_logical: (t, int) => t = "%lsrint" -external of_int: int => t = "%identity" -external to_int: t => int = "%identity" -external of_float: float => t = "?int_of_float" -external to_float: t => float = "?int_to_float" -external bits_of_float: float => t = "?int_bits_of_float" -external float_of_bits: t => float = "?int_float_of_bits" - -let zero = 0l -let one = 1l -let minus_one = -1l -let succ = n => add(n, 1l) -let pred = n => sub(n, 1l) -let abs = n => - if n >= 0l { - n - } else { - neg(n) - } -let min_int = 0x80000000l -let max_int = 0x7FFFFFFFl -let lognot = n => logxor(n, -1l) - -external format: (string, t) => string = "?format_int" -let to_string = n => format("%d", n) - -external of_string: string => t = "?int_of_string" - -let of_string_opt = s => - /* TODO: expose a non-raising primitive directly. */ - try Some(of_string(s)) catch { - | Failure(_) => None - } - -let compare = (x: t, y: t) => Pervasives.compare(x, y) -let equal = (x: t, y: t) => compare(x, y) == 0 diff --git a/jscomp/stdlib-406/int32.resi b/jscomp/stdlib-406/int32.resi deleted file mode 100644 index 174036f240..0000000000 --- a/jscomp/stdlib-406/int32.resi +++ /dev/null @@ -1,176 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/** 32-bit integers. - - This module provides operations on the type [t] - of signed 32-bit integers. Unlike the built-in [int] type, - the type [t] is guaranteed to be exactly 32-bit wide on all - platforms. All arithmetic operations over [t] are taken - modulo 2{^32}. - - Performance notice: values of type [t] occupy more memory - space than values of type [int], and arithmetic operations on - [t] are generally slower than those on [int]. Use [t] - only when the application requires exact 32-bit arithmetic. */ -/** An alias for the type of 32-bit integers. */ -type t = int - -/** The 32-bit integer 0. */ -let zero: t - -/** The 32-bit integer 1. */ -let one: t - -/** The 32-bit integer -1. */ -let minus_one: t - -/** Unary negation. */ -external neg: t => t = "%negint" - -/** Addition. */ -external add: (t, t) => t = "%addint" - -/** Subtraction. */ -external sub: (t, t) => t = "%subint" - -/** Multiplication. */ -external mul: (t, t) => t = "%mulint" - -/** Integer division. Raise [Division_by_zero] if the second - argument is zero. This division rounds the real quotient of - its arguments towards zero, as specified for {!Pervasives.(/)}. */ -external div: (t, t) => t = "%divint" - -/** Integer remainder. If [y] is not zero, the result - of [Int32.rem x y] satisfies the following property: - [x = Int32.add (Int32.mul (Int32.div x y) y) (Int32.rem x y)]. - If [y = 0], [Int32.rem x y] raises [Division_by_zero]. */ -external rem: (t, t) => t = "%modint" - -/** Successor. [Int32.succ x] is [Int32.add x Int32.one]. */ -let succ: t => t - -/** Predecessor. [Int32.pred x] is [Int32.sub x Int32.one]. */ -let pred: t => t - -/** Return the absolute value of its argument. */ -let abs: t => t - -/** The greatest representable 32-bit integer, 2{^31} - 1. */ -let max_int: t - -/** The smallest representable 32-bit integer, -2{^31}. */ -let min_int: t - -/** Bitwise logical and. */ -external logand: (t, t) => t = "%andint" - -/** Bitwise logical or. */ -external logor: (t, t) => t = "%orint" - -/** Bitwise logical exclusive or. */ -external logxor: (t, t) => t = "%xorint" - -/** Bitwise logical negation. */ -let lognot: t => t - -/** [Int32.shift_left x y] shifts [x] to the left by [y] bits. - The result is unspecified if [y < 0] or [y >= 32]. */ -external shift_left: (t, int) => t = "%lslint" - -/** [Int32.shift_right x y] shifts [x] to the right by [y] bits. - This is an arithmetic shift: the sign bit of [x] is replicated - and inserted in the vacated bits. - The result is unspecified if [y < 0] or [y >= 32]. */ -external shift_right: (t, int) => t = "%asrint" - -/** [Int32.shift_right_logical x y] shifts [x] to the right by [y] bits. - This is a logical shift: zeroes are inserted in the vacated bits - regardless of the sign of [x]. - The result is unspecified if [y < 0] or [y >= 32]. */ -external shift_right_logical: (t, int) => t = "%lsrint" - -/** Convert the given integer (type [int]) to a 32-bit integer - (type [t]). */ -external of_int: int => t = "%identity" - -/** Convert the given 32-bit integer (type [t]) to an - integer (type [int]). On 32-bit platforms, the 32-bit integer - is taken modulo 2{^31}, i.e. the high-order bit is lost - during the conversion. On 64-bit platforms, the conversion - is exact. */ -external to_int: t => int = "%identity" - -/** Convert the given floating-point number to a 32-bit integer, - discarding the fractional part (truncate towards 0). - The result of the conversion is undefined if, after truncation, - the number is outside the range \[{!Int32.min_int}, {!Int32.max_int}\]. */ -external of_float: float => t = "?int_of_float" - -/** Convert the given 32-bit integer to a floating-point number. */ -external to_float: t => float = "?int_to_float" - -/** Convert the given string to a 32-bit integer. - The string is read in decimal (by default, or if the string - begins with [0u]) or in hexadecimal, octal or binary if the - string begins with [0x], [0o] or [0b] respectively. - - The [0u] prefix reads the input as an unsigned integer in the range - [[0, 2*Int32.max_int+1]]. If the input exceeds {!Int32.max_int} - it is converted to the signed integer - [Int32.min_int + input - Int32.max_int - 1]. - - The [_] (underscore) character can appear anywhere in the string - and is ignored. - Raise [Failure "Int32.of_string"] if the given string is not - a valid representation of an integer, or if the integer represented - exceeds the range of integers representable in type [t]. */ -external of_string: string => t = "?int_of_string" - -/** Same as [of_string], but return [None] instead of raising. - @since 4.05 */ -let of_string_opt: string => option - -/** Return the string representation of its argument, in signed decimal. */ -let to_string: t => string - -/** Return the internal representation of the given float according - to the IEEE 754 floating-point 'single format' bit layout. - Bit 31 of the result represents the sign of the float; - bits 30 to 23 represent the (biased) exponent; bits 22 to 0 - represent the mantissa. */ -external bits_of_float: float => t = "?int_bits_of_float" - -/** Return the floating-point number whose internal representation, - according to the IEEE 754 floating-point 'single format' bit layout, - is the given [t]. */ -external float_of_bits: t => float = "?int_float_of_bits" - -/** The comparison function for 32-bit integers, with the same specification as - {!Pervasives.compare}. Along with the type [t], this function [compare] - allows the module [Int32] to be passed as argument to the functors - {!Set.Make} and {!Map.Make}. */ -let compare: (t, t) => int - -/** The equal function for int32s. - @since 4.03.0 */ -let equal: (t, t) => bool - -/* {1 Deprecated functions} */ - -/** Do not use this deprecated function. Instead, - used {!Printf.sprintf} with a [%l...] format. */ -external format: (string, t) => string = "?format_int" diff --git a/jscomp/stdlib-406/int64.res b/jscomp/stdlib-406/int64.res deleted file mode 100644 index 032a1c4aa4..0000000000 --- a/jscomp/stdlib-406/int64.res +++ /dev/null @@ -1,71 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/* Module [Int64]: 64-bit integers */ - -external neg: int64 => int64 = "%int64_neg" -external add: (int64, int64) => int64 = "%int64_add" -external sub: (int64, int64) => int64 = "%int64_sub" -external mul: (int64, int64) => int64 = "%int64_mul" -external div: (int64, int64) => int64 = "%int64_div" -external rem: (int64, int64) => int64 = "%int64_mod" -external logand: (int64, int64) => int64 = "%int64_and" -external logor: (int64, int64) => int64 = "%int64_or" -external logxor: (int64, int64) => int64 = "%int64_xor" -external shift_left: (int64, int) => int64 = "%int64_lsl" -external shift_right: (int64, int) => int64 = "%int64_asr" -external shift_right_logical: (int64, int) => int64 = "%int64_lsr" -external of_int: int => int64 = "%int64_of_int" -external to_int: int64 => int = "%int64_to_int" -external of_float: float => int64 = "?int64_of_float" -external to_float: int64 => float = "?int64_to_float" -external of_int32: int => int64 = "%int64_of_int32" -external to_int32: int64 => int = "%int64_to_int32" - -let zero = 0L -let one = 1L -let minus_one = -1L -/* let succ n = add n 1L */ -external succ: int64 => int64 = "?int64_succ" -let pred = n => sub(n, 1L) -let abs = n => - if n >= 0L { - n - } else { - neg(n) - } -let min_int = 0x8000000000000000L -let max_int = 0x7FFFFFFFFFFFFFFFL -let lognot = n => logxor(n, -1L) - -external format: (string, int64) => string = "?int64_format" -external to_string: int64 => string = "?int64_to_string" - -external of_string: string => int64 = "?int64_of_string" - -let of_string_opt = s => - /* TODO: expose a non-raising primitive directly. */ - try Some(of_string(s)) catch { - | Failure(_) => None - } - -external bits_of_float: float => int64 = "?int64_bits_of_float" - -external float_of_bits: int64 => float = "?int64_float_of_bits" - -type t = int64 - -let compare = (x: t, y: t) => Pervasives.compare(x, y) -let equal = (x: t, y: t) => compare(x, y) == 0 diff --git a/jscomp/stdlib-406/int64.resi b/jscomp/stdlib-406/int64.resi deleted file mode 100644 index aeb0588c0f..0000000000 --- a/jscomp/stdlib-406/int64.resi +++ /dev/null @@ -1,189 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/*** 64-bit integers. - - This module provides operations on the type [int64] of - signed 64-bit integers. Unlike the built-in [int] type, - the type [int64] is guaranteed to be exactly 64-bit wide on all - platforms. All arithmetic operations over [int64] are taken - modulo 2{^64} - - Performance notice: values of type [int64] occupy more memory - space than values of type [int], and arithmetic operations on - [int64] are generally slower than those on [int]. Use [int64] - only when the application requires exact 64-bit arithmetic. -*/ - -/** The 64-bit integer 0. */ -let zero: int64 - -/** The 64-bit integer 1. */ -let one: int64 - -/** The 64-bit integer -1. */ -let minus_one: int64 - -/** Unary negation. */ -external neg: int64 => int64 = "%int64_neg" - -/** Addition. */ -external add: (int64, int64) => int64 = "%int64_add" - -/** Subtraction. */ -external sub: (int64, int64) => int64 = "%int64_sub" - -/** Multiplication. */ -external mul: (int64, int64) => int64 = "%int64_mul" - -/** Integer division. Raise [Division_by_zero] if the second - argument is zero. This division rounds the real quotient of - its arguments towards zero, as specified for {!Pervasives.(/)}. */ -external div: (int64, int64) => int64 = "%int64_div" - -/** Integer remainder. If [y] is not zero, the result - of [Int64.rem x y] satisfies the following property: - [x = Int64.add (Int64.mul (Int64.div x y) y) (Int64.rem x y)]. - If [y = 0], [Int64.rem x y] raises [Division_by_zero]. */ -external rem: (int64, int64) => int64 = "%int64_mod" - -/** Successor. [Int64.succ x] is [Int64.add x Int64.one]. */ -let succ: int64 => int64 - -/** Predecessor. [Int64.pred x] is [Int64.sub x Int64.one]. */ -let pred: int64 => int64 - -/** Return the absolute value of its argument. */ -let abs: int64 => int64 - -/** The greatest representable 64-bit integer, 2{^63} - 1. */ -let max_int: int64 - -/** The smallest representable 64-bit integer, -2{^63}. */ -let min_int: int64 - -/** Bitwise logical and. */ -external logand: (int64, int64) => int64 = "%int64_and" - -/** Bitwise logical or. */ -external logor: (int64, int64) => int64 = "%int64_or" - -/** Bitwise logical exclusive or. */ -external logxor: (int64, int64) => int64 = "%int64_xor" - -/** Bitwise logical negation. */ -let lognot: int64 => int64 - -/** [Int64.shift_left x y] shifts [x] to the left by [y] bits. - The result is unspecified if [y < 0] or [y >= 64]. */ -external shift_left: (int64, int) => int64 = "%int64_lsl" - -/** [Int64.shift_right x y] shifts [x] to the right by [y] bits. - This is an arithmetic shift: the sign bit of [x] is replicated - and inserted in the vacated bits. - The result is unspecified if [y < 0] or [y >= 64]. */ -external shift_right: (int64, int) => int64 = "%int64_asr" - -/** [Int64.shift_right_logical x y] shifts [x] to the right by [y] bits. - This is a logical shift: zeroes are inserted in the vacated bits - regardless of the sign of [x]. - The result is unspecified if [y < 0] or [y >= 64]. */ -external shift_right_logical: (int64, int) => int64 = "%int64_lsr" - -/** Convert the given integer (type [int]) to a 64-bit integer - (type [int64]). */ -external of_int: int => int64 = "%int64_of_int" - -/** Convert the given 64-bit integer (type [int64]) to an - integer (type [int]). On 64-bit platforms, the 64-bit integer - is taken modulo 2{^63}, i.e. the high-order bit is lost - during the conversion. On 32-bit platforms, the 64-bit integer - is taken modulo 2{^31}, i.e. the top 33 bits are lost - during the conversion. */ -external to_int: int64 => int = "%int64_to_int" - -/** Convert the given floating-point number to a 64-bit integer, - discarding the fractional part (truncate towards 0). - The result of the conversion is undefined if, after truncation, - the number is outside the range \[{!Int64.min_int}, {!Int64.max_int}\]. */ -external of_float: float => int64 = "?int64_of_float" - -/** Convert the given 64-bit integer to a floating-point number. */ -external to_float: int64 => float = "?int64_to_float" - -/** Convert the given 32-bit integer (type [int]) - to a 64-bit integer (type [int64]). */ -external of_int32: int => int64 = "%int64_of_int32" - -/** Convert the given 64-bit integer (type [int64]) to a - 32-bit integer (type [int]). The 64-bit integer - is taken modulo 2{^32}, i.e. the top 32 bits are lost - during the conversion. */ -external to_int32: int64 => int = "%int64_to_int32" - -/** Convert the given string to a 64-bit integer. - The string is read in decimal (by default, or if the string - begins with [0u]) or in hexadecimal, octal or binary if the - string begins with [0x], [0o] or [0b] respectively. - - The [0u] prefix reads the input as an unsigned integer in the range - [[0, 2*Int64.max_int+1]]. If the input exceeds {!Int64.max_int} - it is converted to the signed integer - [Int64.min_int + input - Int64.max_int - 1]. - - The [_] (underscore) character can appear anywhere in the string - and is ignored. - Raise [Failure "Int64.of_string"] if the given string is not - a valid representation of an integer, or if the integer represented - exceeds the range of integers representable in type [int64]. */ -external of_string: string => int64 = "?int64_of_string" - -/** Same as [of_string], but return [None] instead of raising. - @since 4.05 */ -let of_string_opt: string => option - -/** Return the string representation of its argument, in decimal. */ -let to_string: int64 => string - -/** Return the internal representation of the given float according - to the IEEE 754 floating-point 'double format' bit layout. - Bit 63 of the result represents the sign of the float; - bits 62 to 52 represent the (biased) exponent; bits 51 to 0 - represent the mantissa. */ -external bits_of_float: float => int64 = "?int64_bits_of_float" - -/** Return the floating-point number whose internal representation, - according to the IEEE 754 floating-point 'double format' bit layout, - is the given [int64]. */ -external float_of_bits: int64 => float = "?int64_float_of_bits" - -/** An alias for the type of 64-bit integers. */ -type t = int64 - -/** The comparison function for 64-bit integers, with the same specification as - {!Pervasives.compare}. Along with the type [t], this function [compare] - allows the module [Int64] to be passed as argument to the functors - {!Set.Make} and {!Map.Make}. */ -let compare: (t, t) => int - -/** The equal function for int64s. - @since 4.03.0 */ -let equal: (t, t) => bool - -/* {1 Deprecated functions} */ - -/** Do not use this deprecated function. Instead, - used {!Printf.sprintf} with a [%L...] format. */ -external format: (string, int64) => string = "?int64_format" diff --git a/jscomp/stdlib-406/lazy.res b/jscomp/stdlib-406/lazy.res deleted file mode 100644 index a6a85521dd..0000000000 --- a/jscomp/stdlib-406/lazy.res +++ /dev/null @@ -1,68 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Damien Doligez, projet Para, INRIA Rocquencourt */ -/* */ -/* Copyright 1997 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. */ -/* */ -/* ************************************************************************ */ - -/* Module [Lazy]: deferred computations */ - -/* - WARNING: some purple magic is going on here. Do not take this file - as an example of how to program in OCaml. -*/ - -/* We make use of two special tags provided by the runtime: - [lazy_tag] and [forward_tag]. - - A value of type ['a Lazy.t] can be one of three things: - 1. A block of size 1 with tag [lazy_tag]. Its field is a closure of - type [unit -> 'a] that computes the value. - 2. A block of size 1 with tag [forward_tag]. Its field is the value - of type ['a] that was computed. - 3. Anything else except a float. This has type ['a] and is the value - that was computed. - Exceptions are stored in format (1). - The GC will magically change things from (2) to (3) according to its - fancy. - - If OCaml was configured with the -flat-float-array option (which is - currently the default), the following is also true: - We cannot use representation (3) for a [float Lazy.t] because - [caml_make_array] assumes that only a [float] value can have tag - [Double_tag]. - - We have to use the built-in type constructor [lazy_t] to - let the compiler implement the special typing and compilation - rules for the [lazy] keyword. -*/ - -type t<'a> = lazy_t<'a> - -exception Undefined = CamlinternalLazy.Undefined - -external force: t<'a> => 'a = "%lazy_force" - -/* let force = force */ - -let force_val = CamlinternalLazy.force_val - -let from_fun = f => CamlinternalLazy.from_fun((. ) => f()) - -let from_val = v => CamlinternalLazy.from_val(v) - -let is_val = CamlinternalLazy.is_val - -let lazy_from_fun = from_fun - -let lazy_from_val = from_val - -let lazy_is_val = is_val diff --git a/jscomp/stdlib-406/lazy.resi b/jscomp/stdlib-406/lazy.resi deleted file mode 100644 index fee1eefff9..0000000000 --- a/jscomp/stdlib-406/lazy.resi +++ /dev/null @@ -1,91 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Damien Doligez, projet Para, INRIA Rocquencourt */ -/* */ -/* Copyright 1997 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. */ -/* */ -/* ************************************************************************ */ - -/*** Deferred computations. */ - -/** A value of type ['a Lazy.t] is a deferred computation, called - a suspension, that has a result of type ['a]. The special - expression syntax [lazy (expr)] makes a suspension of the - computation of [expr], without computing [expr] itself yet. - "Forcing" the suspension will then compute [expr] and return its - result. - - Note: [lazy_t] is the built-in type constructor used by the compiler - for the [lazy] keyword. You should not use it directly. Always use - [Lazy.t] instead. - - Note: [Lazy.force] is not thread-safe. If you use this module in - a multi-threaded program, you will need to add some locks. - - Note: if the program is compiled with the [-rectypes] option, - ill-founded recursive definitions of the form [let rec x = lazy x] - or [let rec x = lazy(lazy(...(lazy x)))] are accepted by the type-checker - and lead, when forced, to ill-formed values that trigger infinite - loops in the garbage collector and other parts of the run-time system. - Without the [-rectypes] option, such ill-founded recursive definitions - are rejected by the type-checker. -*/ -type t<'a> = lazy_t<'a> - -exception Undefined - -/* val force : 'a t -> 'a */ -/** [force x] forces the suspension [x] and returns its result. - If [x] has already been forced, [Lazy.force x] returns the - same value again without recomputing it. If it raised an exception, - the same exception is raised again. - Raise {!Undefined} if the forcing of [x] tries to force [x] itself - recursively. -*/ -external force: t<'a> => 'a = "%lazy_force" - -/** [force_val x] forces the suspension [x] and returns its - result. If [x] has already been forced, [force_val x] - returns the same value again without recomputing it. - Raise {!Undefined} if the forcing of [x] tries to force [x] itself - recursively. - If the computation of [x] raises an exception, it is unspecified - whether [force_val x] raises the same exception or {!Undefined}. -*/ -let force_val: t<'a> => 'a - -/** [from_fun f] is the same as [lazy (f ())] but slightly more efficient. - - [from_fun] should only be used if the function [f] is already defined. - In particular it is always less efficient to write - [from_fun (fun () -> expr)] than [lazy expr]. - - @since 4.00.0 */ -let from_fun: (unit => 'a) => t<'a> - -/** [from_val v] returns an already-forced suspension of [v]. - This is for special purposes only and should not be confused with - [lazy (v)]. - @since 4.00.0 */ -let from_val: 'a => t<'a> - -/** [is_val x] returns [true] if [x] has already been forced and - did not raise an exception. - @since 4.00.0 */ -let is_val: t<'a> => bool - -@deprecated("Use Lazy.from_fun instead.") /** @deprecated synonym for [from_fun]. */ -let lazy_from_fun: (unit => 'a) => t<'a> - -@deprecated("Use Lazy.from_val instead.") /** @deprecated synonym for [from_val]. */ -let lazy_from_val: 'a => t<'a> - -@deprecated("Use Lazy.is_val instead.") /** @deprecated synonym for [is_val]. */ -let lazy_is_val: t<'a> => bool diff --git a/jscomp/stdlib-406/lexing.res b/jscomp/stdlib-406/lexing.res deleted file mode 100644 index 31cde12fcc..0000000000 --- a/jscomp/stdlib-406/lexing.res +++ /dev/null @@ -1,245 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/* The run-time library for lexers generated by camllex */ - -type position = { - pos_fname: string, - pos_lnum: int, - pos_bol: int, - pos_cnum: int, -} - -let dummy_pos = { - pos_fname: "", - pos_lnum: 0, - pos_bol: 0, - pos_cnum: -1, -} - -type rec lexbuf = { - refill_buff: lexbuf => unit, - mutable lex_buffer: bytes, - mutable lex_buffer_len: int, - mutable lex_abs_pos: int, - mutable lex_start_pos: int, - mutable lex_curr_pos: int, - mutable lex_last_pos: int, - mutable lex_last_action: int, - mutable lex_eof_reached: bool, - mutable lex_mem: array, - mutable lex_start_p: position, - mutable lex_curr_p: position, -} - -type lex_tables = { - lex_base: string, - lex_backtrk: string, - lex_default: string, - lex_trans: string, - lex_check: string, - lex_base_code: string, - lex_backtrk_code: string, - lex_default_code: string, - lex_trans_code: string, - lex_check_code: string, - lex_code: string, -} - -external c_engine: (lex_tables, int, lexbuf) => int = "?lex_engine" -external c_new_engine: (lex_tables, int, lexbuf) => int = "?new_lex_engine" - -let engine = (tbl, state, buf) => { - let result = c_engine(tbl, state, buf) - if result >= 0 { - buf.lex_start_p = buf.lex_curr_p - buf.lex_curr_p = { - ...buf.lex_curr_p, - pos_cnum: buf.lex_abs_pos + buf.lex_curr_pos, - } - } - result -} - -let new_engine = (tbl, state, buf) => { - let result = c_new_engine(tbl, state, buf) - if result >= 0 { - buf.lex_start_p = buf.lex_curr_p - buf.lex_curr_p = { - ...buf.lex_curr_p, - pos_cnum: buf.lex_abs_pos + buf.lex_curr_pos, - } - } - result -} - -let lex_refill = (read_fun, aux_buffer, lexbuf) => { - let read = read_fun(aux_buffer, Bytes.length(aux_buffer)) - let n = if read > 0 { - read - } else { - lexbuf.lex_eof_reached = true - 0 - } - - /* Current state of the buffer: - <-------|---------------------|-----------> - | junk | valid data | junk | - ^ ^ ^ ^ - 0 start_pos buffer_end Bytes.length buffer - */ - if lexbuf.lex_buffer_len + n > Bytes.length(lexbuf.lex_buffer) { - /* There is not enough space at the end of the buffer */ - if lexbuf.lex_buffer_len - lexbuf.lex_start_pos + n <= Bytes.length(lexbuf.lex_buffer) { - /* But there is enough space if we reclaim the junk at the beginning - of the buffer */ - Bytes.blit( - lexbuf.lex_buffer, - lexbuf.lex_start_pos, - lexbuf.lex_buffer, - 0, - lexbuf.lex_buffer_len - lexbuf.lex_start_pos, - ) - } else { - /* We must grow the buffer. Doubling its size will provide enough - space since n <= String.length aux_buffer <= String.length buffer. - Watch out for string length overflow, though. */ - let newlen = 2 * Bytes.length(lexbuf.lex_buffer) - - if lexbuf.lex_buffer_len - lexbuf.lex_start_pos + n > newlen { - failwith("Lexing.lex_refill: cannot grow buffer") - } - let newbuf = Bytes.create(newlen) - /* Copy the valid data to the beginning of the new buffer */ - Bytes.blit( - lexbuf.lex_buffer, - lexbuf.lex_start_pos, - newbuf, - 0, - lexbuf.lex_buffer_len - lexbuf.lex_start_pos, - ) - lexbuf.lex_buffer = newbuf - } - /* Reallocation or not, we have shifted the data left by - start_pos characters; update the positions */ - let s = lexbuf.lex_start_pos - lexbuf.lex_abs_pos = lexbuf.lex_abs_pos + s - lexbuf.lex_curr_pos = lexbuf.lex_curr_pos - s - lexbuf.lex_start_pos = 0 - lexbuf.lex_last_pos = lexbuf.lex_last_pos - s - lexbuf.lex_buffer_len = lexbuf.lex_buffer_len - s - let t = lexbuf.lex_mem - for i in 0 to Array.length(t) - 1 { - let v = t[i] - if v >= 0 { - t[i] = v - s - } - } - } - /* There is now enough space at the end of the buffer */ - Bytes.blit(aux_buffer, 0, lexbuf.lex_buffer, lexbuf.lex_buffer_len, n) - lexbuf.lex_buffer_len = lexbuf.lex_buffer_len + n -} - -let zero_pos = { - pos_fname: "", - pos_lnum: 1, - pos_bol: 0, - pos_cnum: 0, -} - -let from_function = f => { - refill_buff: x => lex_refill(f, Bytes.create(512), x), - lex_buffer: Bytes.create(1024), - lex_buffer_len: 0, - lex_abs_pos: 0, - lex_start_pos: 0, - lex_curr_pos: 0, - lex_last_pos: 0, - lex_last_action: 0, - lex_mem: [], - lex_eof_reached: false, - lex_start_p: zero_pos, - lex_curr_p: zero_pos, -} - -let from_string = s => { - refill_buff: lexbuf => lexbuf.lex_eof_reached = true, - lex_buffer: Bytes.of_string(s) /* have to make a copy for compatibility - with unsafe-string mode */, - lex_buffer_len: String.length(s), - lex_abs_pos: 0, - lex_start_pos: 0, - lex_curr_pos: 0, - lex_last_pos: 0, - lex_last_action: 0, - lex_mem: [], - lex_eof_reached: true, - lex_start_p: zero_pos, - lex_curr_p: zero_pos, -} - -let lexeme = lexbuf => { - let len = lexbuf.lex_curr_pos - lexbuf.lex_start_pos - Bytes.sub_string(lexbuf.lex_buffer, lexbuf.lex_start_pos, len) -} - -let sub_lexeme = (lexbuf, i1, i2) => { - let len = i2 - i1 - Bytes.sub_string(lexbuf.lex_buffer, i1, len) -} - -let sub_lexeme_opt = (lexbuf, i1, i2) => - if i1 >= 0 { - let len = i2 - i1 - Some(Bytes.sub_string(lexbuf.lex_buffer, i1, len)) - } else { - None - } - -let sub_lexeme_char = (lexbuf, i) => Bytes.get(lexbuf.lex_buffer, i) - -let sub_lexeme_char_opt = (lexbuf, i) => - if i >= 0 { - Some(Bytes.get(lexbuf.lex_buffer, i)) - } else { - None - } - -let lexeme_char = (lexbuf, i) => Bytes.get(lexbuf.lex_buffer, lexbuf.lex_start_pos + i) - -let lexeme_start = lexbuf => lexbuf.lex_start_p.pos_cnum -let lexeme_end = lexbuf => lexbuf.lex_curr_p.pos_cnum - -let lexeme_start_p = lexbuf => lexbuf.lex_start_p -let lexeme_end_p = lexbuf => lexbuf.lex_curr_p - -let new_line = lexbuf => { - let lcp = lexbuf.lex_curr_p - lexbuf.lex_curr_p = { - ...lcp, - pos_lnum: lcp.pos_lnum + 1, - pos_bol: lcp.pos_cnum, - } -} - -/* Discard data left in lexer buffer. */ - -let flush_input = lb => { - lb.lex_curr_pos = 0 - lb.lex_abs_pos = 0 - lb.lex_curr_p = {...lb.lex_curr_p, pos_cnum: 0} - lb.lex_buffer_len = 0 -} diff --git a/jscomp/stdlib-406/lexing.resi b/jscomp/stdlib-406/lexing.resi deleted file mode 100644 index 9a84781324..0000000000 --- a/jscomp/stdlib-406/lexing.resi +++ /dev/null @@ -1,164 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/*** The run-time library for lexers generated by [ocamllex]. */ - -/* {1 Positions} */ - -/** A value of type [position] describes a point in a source file. - [pos_fname] is the file name; [pos_lnum] is the line number; - [pos_bol] is the offset of the beginning of the line (number - of characters between the beginning of the lexbuf and the beginning - of the line); [pos_cnum] is the offset of the position (number of - characters between the beginning of the lexbuf and the position). - The difference between [pos_cnum] and [pos_bol] is the character - offset within the line (i.e. the column number, assuming each - character is one column wide). - - See the documentation of type [lexbuf] for information about - how the lexing engine will manage positions. - */ -type position = { - pos_fname: string, - pos_lnum: int, - pos_bol: int, - pos_cnum: int, -} - -/** A value of type [position], guaranteed to be different from any - valid position. - */ -let dummy_pos: position - -/* {1 Lexer buffers} */ - -/** The type of lexer buffers. A lexer buffer is the argument passed - to the scanning functions defined by the generated scanners. - The lexer buffer holds the current state of the scanner, plus - a function to refill the buffer from the input. - - At each token, the lexing engine will copy [lex_curr_p] to - [lex_start_p], then change the [pos_cnum] field - of [lex_curr_p] by updating it with the number of characters read - since the start of the [lexbuf]. The other fields are left - unchanged by the lexing engine. In order to keep them - accurate, they must be initialised before the first use of the - lexbuf, and updated by the relevant lexer actions (i.e. at each - end of line -- see also [new_line]). - */ -type rec lexbuf = { - refill_buff: lexbuf => unit, - mutable lex_buffer: bytes, - mutable lex_buffer_len: int, - mutable lex_abs_pos: int, - mutable lex_start_pos: int, - mutable lex_curr_pos: int, - mutable lex_last_pos: int, - mutable lex_last_action: int, - mutable lex_eof_reached: bool, - mutable lex_mem: array, - mutable lex_start_p: position, - mutable lex_curr_p: position, -} - -/** Create a lexer buffer which reads from - the given string. Reading starts from the first character in - the string. An end-of-input condition is generated when the - end of the string is reached. */ -let from_string: string => lexbuf - -/** Create a lexer buffer with the given function as its reading method. - When the scanner needs more characters, it will call the given - function, giving it a byte sequence [s] and a byte - count [n]. The function should put [n] bytes or fewer in [s], - starting at index 0, and return the number of bytes - provided. A return value of 0 means end of input. */ -let from_function: ((bytes, int) => int) => lexbuf - -/* {1 Functions for lexer semantic actions} */ - -/* The following functions can be called from the semantic actions - of lexer definitions (the ML code enclosed in braces that - computes the value returned by lexing functions). They give - access to the character string matched by the regular expression - associated with the semantic action. These functions must be - applied to the argument [lexbuf], which, in the code generated by - [ocamllex], is bound to the lexer buffer passed to the parsing - function. */ - -/** [Lexing.lexeme lexbuf] returns the string matched by - the regular expression. */ -let lexeme: lexbuf => string - -/** [Lexing.lexeme_char lexbuf i] returns character number [i] in - the matched string. */ -let lexeme_char: (lexbuf, int) => char - -/** [Lexing.lexeme_start lexbuf] returns the offset in the - input stream of the first character of the matched string. - The first character of the stream has offset 0. */ -let lexeme_start: lexbuf => int - -/** [Lexing.lexeme_end lexbuf] returns the offset in the input stream - of the character following the last character of the matched - string. The first character of the stream has offset 0. */ -let lexeme_end: lexbuf => int - -/** Like [lexeme_start], but return a complete [position] instead - of an offset. */ -let lexeme_start_p: lexbuf => position - -/** Like [lexeme_end], but return a complete [position] instead - of an offset. */ -let lexeme_end_p: lexbuf => position - -/** Update the [lex_curr_p] field of the lexbuf to reflect the start - of a new line. You can call this function in the semantic action - of the rule that matches the end-of-line character. - @since 3.11.0 -*/ -let new_line: lexbuf => unit - -/* {1 Miscellaneous functions} */ - -/** Discard the contents of the buffer and reset the current - position to 0. The next use of the lexbuf will trigger a - refill. */ -let flush_input: lexbuf => unit - -/* The following definitions are used by the generated scanners only. - They are not intended to be used directly by user programs. */ - -let sub_lexeme: (lexbuf, int, int) => string -let sub_lexeme_opt: (lexbuf, int, int) => option -let sub_lexeme_char: (lexbuf, int) => char -let sub_lexeme_char_opt: (lexbuf, int) => option - -type lex_tables = { - lex_base: string, - lex_backtrk: string, - lex_default: string, - lex_trans: string, - lex_check: string, - lex_base_code: string, - lex_backtrk_code: string, - lex_default_code: string, - lex_trans_code: string, - lex_check_code: string, - lex_code: string, -} - -let engine: (lex_tables, int, lexbuf) => int -let new_engine: (lex_tables, int, lexbuf) => int diff --git a/jscomp/stdlib-406/listLabels.res b/jscomp/stdlib-406/listLabels.res deleted file mode 100644 index d08db5ee32..0000000000 --- a/jscomp/stdlib-406/listLabels.res +++ /dev/null @@ -1,748 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/* List operations */ - -let rec length_aux = (len, param) => - switch param { - | list{} => len - | list{_, ...l} => length_aux(len + 1, l) - } - -let length = l => length_aux(0, l) - -let cons = (a, l) => list{a, ...l} - -let hd = param => - switch param { - | list{} => failwith("hd") - | list{a, ..._} => a - } - -let tl = param => - switch param { - | list{} => failwith("tl") - | list{_, ...l} => l - } - -let nth = (l, n) => - if n < 0 { - invalid_arg("List.nth") - } else { - let rec nth_aux = (l, n) => - switch l { - | list{} => failwith("nth") - | list{a, ...l} => - if n == 0 { - a - } else { - nth_aux(l, n - 1) - } - } - nth_aux(l, n) - } - -let nth_opt = (l, n) => - if n < 0 { - invalid_arg("List.nth") - } else { - let rec nth_aux = (l, n) => - switch l { - | list{} => None - | list{a, ...l} => - if n == 0 { - Some(a) - } else { - nth_aux(l, n - 1) - } - } - nth_aux(l, n) - } - -let append = \"@" - -let rec rev_append = (l1, l2) => - switch l1 { - | list{} => l2 - | list{a, ...l} => rev_append(l, list{a, ...l2}) - } - -let rev = l => rev_append(l, list{}) - -let rec init_tailrec_aux = (acc, i, n, f) => - if i >= n { - acc - } else { - init_tailrec_aux(list{f(i), ...acc}, i + 1, n, f) - } - -let rec init_aux = (i, n, f) => - if i >= n { - list{} - } else { - let r = f(i) - list{r, ...init_aux(i + 1, n, f)} - } - -let init = (~len, ~f) => - if len < 0 { - invalid_arg("List.init") - } else if len > 10_000 { - rev(init_tailrec_aux(list{}, 0, len, f)) - } else { - init_aux(0, len, f) - } - -let rec flatten = param => - switch param { - | list{} => list{} - | list{l, ...r} => \"@"(l, flatten(r)) - } - -let concat = flatten - -let rec map = (~f, param) => - switch param { - | list{} => list{} - | list{a, ...l} => - let r = f(a) - list{r, ...map(~f, l)} - } - -let rec mapi = (i, f, param) => - switch param { - | list{} => list{} - | list{a, ...l} => - let r = f(i, a) - list{r, ...mapi(i + 1, f, l)} - } - -let mapi = (~f, l) => mapi(0, f, l) - -let rev_map = (~f, l) => { - let rec rmap_f = (accu, param) => - switch param { - | list{} => accu - | list{a, ...l} => rmap_f(list{f(a), ...accu}, l) - } - - rmap_f(list{}, l) -} - -let rec iter = (~f, param) => - switch param { - | list{} => () - | list{a, ...l} => - f(a) - iter(~f, l) - } - -let rec iteri = (i, f, param) => - switch param { - | list{} => () - | list{a, ...l} => - f(i, a) - iteri(i + 1, f, l) - } - -let iteri = (~f, l) => iteri(0, f, l) - -let rec fold_left = (~f, ~init as accu, l) => - switch l { - | list{} => accu - | list{a, ...l} => fold_left(~f, ~init=f(accu, a), l) - } - -let rec fold_right = (~f, l, ~init as accu) => - switch l { - | list{} => accu - | list{a, ...l} => f(a, fold_right(~f, l, ~init=accu)) - } - -let rec map2 = (~f, l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => list{} - | (list{a1, ...l1}, list{a2, ...l2}) => - let r = f(a1, a2) - list{r, ...map2(~f, l1, l2)} - | (_, _) => invalid_arg("List.map2") - } - -let rev_map2 = (~f, l1, l2) => { - let rec rmap2_f = (accu, l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => accu - | (list{a1, ...l1}, list{a2, ...l2}) => rmap2_f(list{f(a1, a2), ...accu}, l1, l2) - | (_, _) => invalid_arg("List.rev_map2") - } - - rmap2_f(list{}, l1, l2) -} - -let rec iter2 = (~f, l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => () - | (list{a1, ...l1}, list{a2, ...l2}) => - f(a1, a2) - iter2(~f, l1, l2) - | (_, _) => invalid_arg("List.iter2") - } - -let rec fold_left2 = (~f, ~init as accu, l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => accu - | (list{a1, ...l1}, list{a2, ...l2}) => fold_left2(~f, ~init=f(accu, a1, a2), l1, l2) - | (_, _) => invalid_arg("List.fold_left2") - } - -let rec fold_right2 = (~f, l1, l2, ~init as accu) => - switch (l1, l2) { - | (list{}, list{}) => accu - | (list{a1, ...l1}, list{a2, ...l2}) => f(a1, a2, fold_right2(~f, l1, l2, ~init=accu)) - | (_, _) => invalid_arg("List.fold_right2") - } - -let rec for_all = (~f as p, param) => - switch param { - | list{} => true - | list{a, ...l} => p(a) && for_all(~f=p, l) - } - -let rec exists = (~f as p, param) => - switch param { - | list{} => false - | list{a, ...l} => p(a) || exists(~f=p, l) - } - -let rec for_all2 = (~f as p, l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => true - | (list{a1, ...l1}, list{a2, ...l2}) => p(a1, a2) && for_all2(~f=p, l1, l2) - | (_, _) => invalid_arg("List.for_all2") - } - -let rec exists2 = (~f as p, l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => false - | (list{a1, ...l1}, list{a2, ...l2}) => p(a1, a2) || exists2(~f=p, l1, l2) - | (_, _) => invalid_arg("List.exists2") - } - -let rec mem = (x, ~set) => - switch set { - | list{} => false - | list{a, ...l} => compare(a, x) == 0 || mem(x, ~set=l) - } - -let rec memq = (x, ~set) => - switch set { - | list{} => false - | list{a, ...l} => a === x || memq(x, ~set=l) - } - -let rec assoc = (x, param) => - switch param { - | list{} => raise(Not_found) - | list{(a, b), ...l} => - if compare(a, x) == 0 { - b - } else { - assoc(x, l) - } - } - -let rec assoc_opt = (x, param) => - switch param { - | list{} => None - | list{(a, b), ...l} => - if compare(a, x) == 0 { - Some(b) - } else { - assoc_opt(x, l) - } - } - -let rec assq = (x, param) => - switch param { - | list{} => raise(Not_found) - | list{(a, b), ...l} => - if a === x { - b - } else { - assq(x, l) - } - } - -let rec assq_opt = (x, param) => - switch param { - | list{} => None - | list{(a, b), ...l} => - if a === x { - Some(b) - } else { - assq_opt(x, l) - } - } - -let rec mem_assoc = (x, ~map) => - switch map { - | list{} => false - | list{(a, _), ...l} => compare(a, x) == 0 || mem_assoc(x, ~map=l) - } - -let rec mem_assq = (x, ~map) => - switch map { - | list{} => false - | list{(a, _), ...l} => a === x || mem_assq(x, ~map=l) - } - -let rec remove_assoc = (x, param) => - switch param { - | list{} => list{} - | list{(a, _) as pair, ...l} => - if compare(a, x) == 0 { - l - } else { - list{pair, ...remove_assoc(x, l)} - } - } - -let rec remove_assq = (x, param) => - switch param { - | list{} => list{} - | list{(a, _) as pair, ...l} => - if a === x { - l - } else { - list{pair, ...remove_assq(x, l)} - } - } - -let rec find = (~f as p, param) => - switch param { - | list{} => raise(Not_found) - | list{x, ...l} => - if p(x) { - x - } else { - find(~f=p, l) - } - } - -let rec find_opt = (~f as p, param) => - switch param { - | list{} => None - | list{x, ...l} => - if p(x) { - Some(x) - } else { - find_opt(~f=p, l) - } - } - -let find_all = (~f as p, l) => { - let rec find = (accu, param) => - switch param { - | list{} => rev(accu) - | list{x, ...l} => - if p(x) { - find(list{x, ...accu}, l) - } else { - find(accu, l) - } - } - find(list{}, l) -} - -let filter = find_all - -let partition = (~f as p, l) => { - let rec part = (yes, no, param) => - switch param { - | list{} => (rev(yes), rev(no)) - | list{x, ...l} => - if p(x) { - part(list{x, ...yes}, no, l) - } else { - part(yes, list{x, ...no}, l) - } - } - part(list{}, list{}, l) -} - -let rec split = param => - switch param { - | list{} => (list{}, list{}) - | list{(x, y), ...l} => - let (rx, ry) = split(l) - (list{x, ...rx}, list{y, ...ry}) - } - -let rec combine = (l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => list{} - | (list{a1, ...l1}, list{a2, ...l2}) => list{(a1, a2), ...combine(l1, l2)} - | (_, _) => invalid_arg("List.combine") - } - -/* sorting */ - -let rec merge = (~cmp, l1, l2) => - switch (l1, l2) { - | (list{}, l2) => l2 - | (l1, list{}) => l1 - | (list{h1, ...t1}, list{h2, ...t2}) => - if cmp(h1, h2) <= 0 { - list{h1, ...merge(~cmp, t1, l2)} - } else { - list{h2, ...merge(~cmp, l1, t2)} - } - } - -let rec chop = (k, l) => - if k == 0 { - l - } else { - switch l { - | list{_, ...t} => chop(k - 1, t) - | _ => assert(false) - } - } - -let stable_sort = (~cmp, l) => { - let rec rev_merge = (l1, l2, accu) => - switch (l1, l2) { - | (list{}, l2) => rev_append(l2, accu) - | (l1, list{}) => rev_append(l1, accu) - | (list{h1, ...t1}, list{h2, ...t2}) => - if cmp(h1, h2) <= 0 { - rev_merge(t1, l2, list{h1, ...accu}) - } else { - rev_merge(l1, t2, list{h2, ...accu}) - } - } - - let rec rev_merge_rev = (l1, l2, accu) => - switch (l1, l2) { - | (list{}, l2) => rev_append(l2, accu) - | (l1, list{}) => rev_append(l1, accu) - | (list{h1, ...t1}, list{h2, ...t2}) => - if cmp(h1, h2) > 0 { - rev_merge_rev(t1, l2, list{h1, ...accu}) - } else { - rev_merge_rev(l1, t2, list{h2, ...accu}) - } - } - - let rec sort = (n, l) => - switch (n, l) { - | (2, list{x1, x2, ..._}) => - if cmp(x1, x2) <= 0 { - list{x1, x2} - } else { - list{x2, x1} - } - | (3, list{x1, x2, x3, ..._}) => - if cmp(x1, x2) <= 0 { - if cmp(x2, x3) <= 0 { - list{x1, x2, x3} - } else if cmp(x1, x3) <= 0 { - list{x1, x3, x2} - } else { - list{x3, x1, x2} - } - } else if cmp(x1, x3) <= 0 { - list{x2, x1, x3} - } else if cmp(x2, x3) <= 0 { - list{x2, x3, x1} - } else { - list{x3, x2, x1} - } - | (n, l) => - let n1 = asr(n, 1) - let n2 = n - n1 - let l2 = chop(n1, l) - let s1 = rev_sort(n1, l) - let s2 = rev_sort(n2, l2) - rev_merge_rev(s1, s2, list{}) - } - and rev_sort = (n, l) => - switch (n, l) { - | (2, list{x1, x2, ..._}) => - if cmp(x1, x2) > 0 { - list{x1, x2} - } else { - list{x2, x1} - } - | (3, list{x1, x2, x3, ..._}) => - if cmp(x1, x2) > 0 { - if cmp(x2, x3) > 0 { - list{x1, x2, x3} - } else if cmp(x1, x3) > 0 { - list{x1, x3, x2} - } else { - list{x3, x1, x2} - } - } else if cmp(x1, x3) > 0 { - list{x2, x1, x3} - } else if cmp(x2, x3) > 0 { - list{x2, x3, x1} - } else { - list{x3, x2, x1} - } - | (n, l) => - let n1 = asr(n, 1) - let n2 = n - n1 - let l2 = chop(n1, l) - let s1 = sort(n1, l) - let s2 = sort(n2, l2) - rev_merge(s1, s2, list{}) - } - - let len = length(l) - if len < 2 { - l - } else { - sort(len, l) - } -} - -let sort = stable_sort -let fast_sort = stable_sort - -/* Note: on a list of length between about 100000 (depending on the minor - heap size and the type of the list) and Sys.max_array_size, it is - actually faster to use the following, but it might also use more memory - because the argument list cannot be deallocated incrementally. - - Also, there seems to be a bug in this code or in the - implementation of obj_truncate. - -external obj_truncate : 'a array -> int -> unit = "caml_obj_truncate" - -let array_to_list_in_place a = - let l = Array.length a in - let rec loop accu n p = - if p <= 0 then accu else begin - if p = n then begin - obj_truncate a p; - loop (a.(p-1) :: accu) (n-1000) (p-1) - end else begin - loop (a.(p-1) :: accu) n (p-1) - end - end - in - loop [] (l-1000) l - - -let stable_sort cmp l = - let a = Array.of_list l in - Array.stable_sort cmp a; - array_to_list_in_place a -*/ - -/* sorting + removing duplicates */ - -let sort_uniq = (~cmp, l) => { - let rec rev_merge = (l1, l2, accu) => - switch (l1, l2) { - | (list{}, l2) => rev_append(l2, accu) - | (l1, list{}) => rev_append(l1, accu) - | (list{h1, ...t1}, list{h2, ...t2}) => - let c = cmp(h1, h2) - if c == 0 { - rev_merge(t1, t2, list{h1, ...accu}) - } else if c < 0 { - rev_merge(t1, l2, list{h1, ...accu}) - } else { - rev_merge(l1, t2, list{h2, ...accu}) - } - } - - let rec rev_merge_rev = (l1, l2, accu) => - switch (l1, l2) { - | (list{}, l2) => rev_append(l2, accu) - | (l1, list{}) => rev_append(l1, accu) - | (list{h1, ...t1}, list{h2, ...t2}) => - let c = cmp(h1, h2) - if c == 0 { - rev_merge_rev(t1, t2, list{h1, ...accu}) - } else if c > 0 { - rev_merge_rev(t1, l2, list{h1, ...accu}) - } else { - rev_merge_rev(l1, t2, list{h2, ...accu}) - } - } - - let rec sort = (n, l) => - switch (n, l) { - | (2, list{x1, x2, ..._}) => - let c = cmp(x1, x2) - if c == 0 { - list{x1} - } else if c < 0 { - list{x1, x2} - } else { - list{x2, x1} - } - | (3, list{x1, x2, x3, ..._}) => - let c = cmp(x1, x2) - if c == 0 { - let c = cmp(x2, x3) - if c == 0 { - list{x2} - } else if c < 0 { - list{x2, x3} - } else { - list{x3, x2} - } - } else if c < 0 { - let c = cmp(x2, x3) - if c == 0 { - list{x1, x2} - } else if c < 0 { - list{x1, x2, x3} - } else { - let c = cmp(x1, x3) - if c == 0 { - list{x1, x2} - } else if c < 0 { - list{x1, x3, x2} - } else { - list{x3, x1, x2} - } - } - } else { - let c = cmp(x1, x3) - if c == 0 { - list{x2, x1} - } else if c < 0 { - list{x2, x1, x3} - } else { - let c = cmp(x2, x3) - if c == 0 { - list{x2, x1} - } else if c < 0 { - list{x2, x3, x1} - } else { - list{x3, x2, x1} - } - } - } - | (n, l) => - let n1 = asr(n, 1) - let n2 = n - n1 - let l2 = chop(n1, l) - let s1 = rev_sort(n1, l) - let s2 = rev_sort(n2, l2) - rev_merge_rev(s1, s2, list{}) - } - and rev_sort = (n, l) => - switch (n, l) { - | (2, list{x1, x2, ..._}) => - let c = cmp(x1, x2) - if c == 0 { - list{x1} - } else if c > 0 { - list{x1, x2} - } else { - list{x2, x1} - } - | (3, list{x1, x2, x3, ..._}) => - let c = cmp(x1, x2) - if c == 0 { - let c = cmp(x2, x3) - if c == 0 { - list{x2} - } else if c > 0 { - list{x2, x3} - } else { - list{x3, x2} - } - } else if c > 0 { - let c = cmp(x2, x3) - if c == 0 { - list{x1, x2} - } else if c > 0 { - list{x1, x2, x3} - } else { - let c = cmp(x1, x3) - if c == 0 { - list{x1, x2} - } else if c > 0 { - list{x1, x3, x2} - } else { - list{x3, x1, x2} - } - } - } else { - let c = cmp(x1, x3) - if c == 0 { - list{x2, x1} - } else if c > 0 { - list{x2, x1, x3} - } else { - let c = cmp(x2, x3) - if c == 0 { - list{x2, x1} - } else if c > 0 { - list{x2, x3, x1} - } else { - list{x3, x2, x1} - } - } - } - | (n, l) => - let n1 = asr(n, 1) - let n2 = n - n1 - let l2 = chop(n1, l) - let s1 = sort(n1, l) - let s2 = sort(n2, l2) - rev_merge(s1, s2, list{}) - } - - let len = length(l) - if len < 2 { - l - } else { - sort(len, l) - } -} - -let rec compare_lengths = (l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => 0 - | (list{}, _) => -1 - | (_, list{}) => 1 - | (list{_, ...l1}, list{_, ...l2}) => compare_lengths(l1, l2) - } - -let rec compare_length_with = (l, ~len as n) => - switch l { - | list{} => - if n == 0 { - 0 - } else if n > 0 { - -1 - } else { - 1 - } - | list{_, ...l} => - if n <= 0 { - 1 - } else { - compare_length_with(l, ~len=n - 1) - } - } diff --git a/jscomp/stdlib-406/listLabels.resi b/jscomp/stdlib-406/listLabels.resi deleted file mode 100644 index c48e830a47..0000000000 --- a/jscomp/stdlib-406/listLabels.resi +++ /dev/null @@ -1,337 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/*** List operations. - - Some functions are flagged as not tail-recursive. A tail-recursive - function uses constant stack space, while a non-tail-recursive function - uses stack space proportional to the length of its list argument, which - can be a problem with very long lists. When the function takes several - list arguments, an approximate formula giving stack usage (in some - unspecified constant unit) is shown in parentheses. - - The above considerations can usually be ignored if your lists are not - longer than about 10000 elements. -*/ - -/** Return the length (number of elements) of the given list. */ -let length: list<'a> => int - -/** Return the first element of the given list. Raise - [Failure "hd"] if the list is empty. */ -let hd: list<'a> => 'a - -/** Compare the lengths of two lists. [compare_lengths l1 l2] is - equivalent to [compare (length l1) (length l2)], except that - the computation stops after itering on the shortest list. - @since 4.05.0 - */ -let compare_lengths: (list<'a>, list<'b>) => int - -/** Compare the length of a list to an integer. [compare_length_with l n] is - equivalent to [compare (length l) n], except that - the computation stops after at most [n] iterations on the list. - @since 4.05.0 -*/ -let compare_length_with: (list<'a>, ~len: int) => int - -/** [cons x xs] is [x :: xs] - @since 4.05.0 -*/ -let cons: ('a, list<'a>) => list<'a> - -/** Return the given list without its first element. Raise - [Failure "tl"] if the list is empty. */ -let tl: list<'a> => list<'a> - -/** Return the [n]-th element of the given list. - The first element (head of the list) is at position 0. - Raise [Failure "nth"] if the list is too short. - Raise [Invalid_argument "List.nth"] if [n] is negative. */ -let nth: (list<'a>, int) => 'a - -/** Return the [n]-th element of the given list. - The first element (head of the list) is at position 0. - Return [None] if the list is too short. - Raise [Invalid_argument "List.nth"] if [n] is negative. - @since 4.05 -*/ -let nth_opt: (list<'a>, int) => option<'a> - -/** List reversal. */ -let rev: list<'a> => list<'a> - -/** [List.init len f] is [f 0; f 1; ...; f (len-1)], evaluated left to right. - - @raise Invalid_argument if [len < 0]. - @since 4.06.0 -*/ -let init: (~len: int, ~f: int => 'a) => list<'a> - -/** Catenate two lists. Same function as the infix operator [@]. - Not tail-recursive (length of the first argument). The [@] - operator is not tail-recursive either. */ -let append: (list<'a>, list<'a>) => list<'a> - -/** [List.rev_append l1 l2] reverses [l1] and concatenates it with [l2]. - This is equivalent to [(]{!List.rev}[ l1) @ l2], but [rev_append] is - tail-recursive and more efficient. */ -let rev_append: (list<'a>, list<'a>) => list<'a> - -/** Concatenate a list of lists. The elements of the argument are all - concatenated together (in the same order) to give the result. - Not tail-recursive - (length of the argument + length of the longest sub-list). */ -let concat: list> => list<'a> - -/** Same as [concat]. Not tail-recursive - (length of the argument + length of the longest sub-list). */ -let flatten: list> => list<'a> - -/* {1 Iterators} */ - -/** [List.iter f [a1; ...; an]] applies function [f] in turn to - [a1; ...; an]. It is equivalent to - [begin f a1; f a2; ...; f an; () end]. */ -let iter: (~f: 'a => unit, list<'a>) => unit - -/** Same as {!List.iter}, but the function is applied to the index of - the element as first argument (counting from 0), and the element - itself as second argument. - @since 4.00.0 -*/ -let iteri: (~f: (int, 'a) => unit, list<'a>) => unit - -/** [List.map f [a1; ...; an]] applies function [f] to [a1, ..., an], - and builds the list [[f a1; ...; f an]] - with the results returned by [f]. Not tail-recursive. */ -let map: (~f: 'a => 'b, list<'a>) => list<'b> - -/** Same as {!List.map}, but the function is applied to the index of - the element as first argument (counting from 0), and the element - itself as second argument. - @since 4.00.0 -*/ -let mapi: (~f: (int, 'a) => 'b, list<'a>) => list<'b> - -/** [List.rev_map f l] gives the same result as - {!List.rev}[ (]{!List.map}[ f l)], but is tail-recursive and - more efficient. */ -let rev_map: (~f: 'a => 'b, list<'a>) => list<'b> - -/** [List.fold_left f a [b1; ...; bn]] is - [f (... (f (f a b1) b2) ...) bn]. */ -let fold_left: (~f: ('a, 'b) => 'a, ~init: 'a, list<'b>) => 'a - -/** [List.fold_right f [a1; ...; an] b] is - [f a1 (f a2 (... (f an b) ...))]. Not tail-recursive. */ -let fold_right: (~f: ('a, 'b) => 'b, list<'a>, ~init: 'b) => 'b - -/* {1 Iterators on two lists} */ - -/** [List.iter2 f [a1; ...; an] [b1; ...; bn]] calls in turn - [f a1 b1; ...; f an bn]. - Raise [Invalid_argument] if the two lists are determined - to have different lengths. */ -let iter2: (~f: ('a, 'b) => unit, list<'a>, list<'b>) => unit - -/** [List.map2 f [a1; ...; an] [b1; ...; bn]] is - [[f a1 b1; ...; f an bn]]. - Raise [Invalid_argument] if the two lists are determined - to have different lengths. Not tail-recursive. */ -let map2: (~f: ('a, 'b) => 'c, list<'a>, list<'b>) => list<'c> - -/** [List.rev_map2 f l1 l2] gives the same result as - {!List.rev}[ (]{!List.map2}[ f l1 l2)], but is tail-recursive and - more efficient. */ -let rev_map2: (~f: ('a, 'b) => 'c, list<'a>, list<'b>) => list<'c> - -/** [List.fold_left2 f a [b1; ...; bn] [c1; ...; cn]] is - [f (... (f (f a b1 c1) b2 c2) ...) bn cn]. - Raise [Invalid_argument] if the two lists are determined - to have different lengths. */ -let fold_left2: (~f: ('a, 'b, 'c) => 'a, ~init: 'a, list<'b>, list<'c>) => 'a - -/** [List.fold_right2 f [a1; ...; an] [b1; ...; bn] c] is - [f a1 b1 (f a2 b2 (... (f an bn c) ...))]. - Raise [Invalid_argument] if the two lists are determined - to have different lengths. Not tail-recursive. */ -let fold_right2: (~f: ('a, 'b, 'c) => 'c, list<'a>, list<'b>, ~init: 'c) => 'c - -/* {1 List scanning} */ - -/** [for_all p [a1; ...; an]] checks if all elements of the list - satisfy the predicate [p]. That is, it returns - [(p a1) && (p a2) && ... && (p an)]. */ -let for_all: (~f: 'a => bool, list<'a>) => bool - -/** [exists p [a1; ...; an]] checks if at least one element of - the list satisfies the predicate [p]. That is, it returns - [(p a1) || (p a2) || ... || (p an)]. */ -let exists: (~f: 'a => bool, list<'a>) => bool - -/** Same as {!List.for_all}, but for a two-argument predicate. - Raise [Invalid_argument] if the two lists are determined - to have different lengths. */ -let for_all2: (~f: ('a, 'b) => bool, list<'a>, list<'b>) => bool - -/** Same as {!List.exists}, but for a two-argument predicate. - Raise [Invalid_argument] if the two lists are determined - to have different lengths. */ -let exists2: (~f: ('a, 'b) => bool, list<'a>, list<'b>) => bool - -/** [mem a l] is true if and only if [a] is equal - to an element of [l]. */ -let mem: ('a, ~set: list<'a>) => bool - -/** Same as {!List.mem}, but uses physical equality instead of structural - equality to compare list elements. */ -let memq: ('a, ~set: list<'a>) => bool - -/* {1 List searching} */ - -/** [find p l] returns the first element of the list [l] - that satisfies the predicate [p]. - Raise [Not_found] if there is no value that satisfies [p] in the - list [l]. */ -let find: (~f: 'a => bool, list<'a>) => 'a - -/** [find p l] returns the first element of the list [l] - that satisfies the predicate [p]. - Returns [None] if there is no value that satisfies [p] in the - list [l]. - @since 4.05 */ -let find_opt: (~f: 'a => bool, list<'a>) => option<'a> - -/** [filter p l] returns all the elements of the list [l] - that satisfy the predicate [p]. The order of the elements - in the input list is preserved. */ -let filter: (~f: 'a => bool, list<'a>) => list<'a> - -/** [find_all] is another name for {!List.filter}. */ -let find_all: (~f: 'a => bool, list<'a>) => list<'a> - -/** [partition p l] returns a pair of lists [(l1, l2)], where - [l1] is the list of all the elements of [l] that - satisfy the predicate [p], and [l2] is the list of all the - elements of [l] that do not satisfy [p]. - The order of the elements in the input list is preserved. */ -let partition: (~f: 'a => bool, list<'a>) => (list<'a>, list<'a>) - -/* {1 Association lists} */ - -/** [assoc a l] returns the value associated with key [a] in the list of - pairs [l]. That is, - [assoc a [ ...; (a,b); ...] = b] - if [(a,b)] is the leftmost binding of [a] in list [l]. - Raise [Not_found] if there is no value associated with [a] in the - list [l]. */ -let assoc: ('a, list<('a, 'b)>) => 'b - -/** [assoc_opt a l] returns the value associated with key [a] in the list of - pairs [l]. That is, - [assoc a [ ...; (a,b); ...] = b] - if [(a,b)] is the leftmost binding of [a] in list [l]. - Returns [None] if there is no value associated with [a] in the - list [l]. - @since 4.05 -*/ -let assoc_opt: ('a, list<('a, 'b)>) => option<'b> - -/** Same as {!List.assoc}, but uses physical equality instead of - structural equality to compare keys. */ -let assq: ('a, list<('a, 'b)>) => 'b - -/** Same as {!List.assoc_opt}, but uses physical equality instead of - structural equality to compare keys. - @since 4.05.0 */ -let assq_opt: ('a, list<('a, 'b)>) => option<'b> - -/** Same as {!List.assoc}, but simply return true if a binding exists, - and false if no bindings exist for the given key. */ -let mem_assoc: ('a, ~map: list<('a, 'b)>) => bool - -/** Same as {!List.mem_assoc}, but uses physical equality instead of - structural equality to compare keys. */ -let mem_assq: ('a, ~map: list<('a, 'b)>) => bool - -/** [remove_assoc a l] returns the list of - pairs [l] without the first pair with key [a], if any. - Not tail-recursive. */ -let remove_assoc: ('a, list<('a, 'b)>) => list<('a, 'b)> - -/** Same as {!List.remove_assoc}, but uses physical equality instead - of structural equality to compare keys. Not tail-recursive. */ -let remove_assq: ('a, list<('a, 'b)>) => list<('a, 'b)> - -/* {1 Lists of pairs} */ - -/** Transform a list of pairs into a pair of lists: - [split [(a1,b1); ...; (an,bn)]] is [([a1; ...; an], [b1; ...; bn])]. - Not tail-recursive. -*/ -let split: list<('a, 'b)> => (list<'a>, list<'b>) - -/** Transform a pair of lists into a list of pairs: - [combine [a1; ...; an] [b1; ...; bn]] is - [[(a1,b1); ...; (an,bn)]]. - Raise [Invalid_argument] if the two lists - have different lengths. Not tail-recursive. */ -let combine: (list<'a>, list<'b>) => list<('a, 'b)> - -/* {1 Sorting} */ - -/** Sort a list in increasing order according to a comparison - function. The comparison function must return 0 if its arguments - compare as equal, a positive integer if the first is greater, - and a negative integer if the first is smaller (see Array.sort for - a complete specification). For example, - {!Pervasives.compare} is a suitable comparison function. - The resulting list is sorted in increasing order. - [List.sort] is guaranteed to run in constant heap space - (in addition to the size of the result list) and logarithmic - stack space. - - The current implementation uses Merge Sort. It runs in constant - heap space and logarithmic stack space. -*/ -let sort: (~cmp: ('a, 'a) => int, list<'a>) => list<'a> - -/** Same as {!List.sort}, but the sorting algorithm is guaranteed to - be stable (i.e. elements that compare equal are kept in their - original order) . - - The current implementation uses Merge Sort. It runs in constant - heap space and logarithmic stack space. -*/ -let stable_sort: (~cmp: ('a, 'a) => int, list<'a>) => list<'a> - -/** Same as {!List.sort} or {!List.stable_sort}, whichever is - faster on typical input. */ -let fast_sort: (~cmp: ('a, 'a) => int, list<'a>) => list<'a> - -/** Same as {!List.sort}, but also remove duplicates. - @since 4.03.0 */ -let sort_uniq: (~cmp: ('a, 'a) => int, list<'a>) => list<'a> - -/** Merge two lists: - Assuming that [l1] and [l2] are sorted according to the - comparison function [cmp], [merge cmp l1 l2] will return a - sorted list containing all the elements of [l1] and [l2]. - If several elements compare equal, the elements of [l1] will be - before the elements of [l2]. - Not tail-recursive (sum of the lengths of the arguments). -*/ -let merge: (~cmp: ('a, 'a) => int, list<'a>, list<'a>) => list<'a> diff --git a/jscomp/stdlib-406/map.res b/jscomp/stdlib-406/map.res deleted file mode 100644 index f485f302e2..0000000000 --- a/jscomp/stdlib-406/map.res +++ /dev/null @@ -1,669 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -module type OrderedType = { - type t - let compare: (t, t) => int -} - -module type S = { - type key - type t<+'a> - let empty: t<'a> - let is_empty: t<'a> => bool - let mem: (key, t<'a>) => bool - let add: (key, 'a, t<'a>) => t<'a> - let update: (key, option<'a> => option<'a>, t<'a>) => t<'a> - let singleton: (key, 'a) => t<'a> - let remove: (key, t<'a>) => t<'a> - let merge: ((key, option<'a>, option<'b>) => option<'c>, t<'a>, t<'b>) => t<'c> - let union: ((key, 'a, 'a) => option<'a>, t<'a>, t<'a>) => t<'a> - let compare: (('a, 'a) => int, t<'a>, t<'a>) => int - let equal: (('a, 'a) => bool, t<'a>, t<'a>) => bool - let iter: ((key, 'a) => unit, t<'a>) => unit - let fold: ((key, 'a, 'b) => 'b, t<'a>, 'b) => 'b - let for_all: ((key, 'a) => bool, t<'a>) => bool - let exists: ((key, 'a) => bool, t<'a>) => bool - let filter: ((key, 'a) => bool, t<'a>) => t<'a> - let partition: ((key, 'a) => bool, t<'a>) => (t<'a>, t<'a>) - let cardinal: t<'a> => int - let bindings: t<'a> => list<(key, 'a)> - let min_binding: t<'a> => (key, 'a) - let min_binding_opt: t<'a> => option<(key, 'a)> - let max_binding: t<'a> => (key, 'a) - let max_binding_opt: t<'a> => option<(key, 'a)> - let choose: t<'a> => (key, 'a) - let choose_opt: t<'a> => option<(key, 'a)> - let split: (key, t<'a>) => (t<'a>, option<'a>, t<'a>) - let find: (key, t<'a>) => 'a - let find_opt: (key, t<'a>) => option<'a> - let find_first: (key => bool, t<'a>) => (key, 'a) - let find_first_opt: (key => bool, t<'a>) => option<(key, 'a)> - let find_last: (key => bool, t<'a>) => (key, 'a) - let find_last_opt: (key => bool, t<'a>) => option<(key, 'a)> - let map: ('a => 'b, t<'a>) => t<'b> - let mapi: ((key, 'a) => 'b, t<'a>) => t<'b> -} - -module Make = (Ord: OrderedType) => { - type key = Ord.t - - type rec t<'a> = - | Empty - | Node({l: t<'a>, v: key, d: 'a, r: t<'a>, h: int}) - - let height = param => - switch param { - | Empty => 0 - | Node({h}) => h - } - - let create = (l, x, d, r) => { - let hl = height(l) and hr = height(r) - Node({ - l, - v: x, - d, - r, - h: if hl >= hr { - hl + 1 - } else { - hr + 1 - }, - }) - } - - let singleton = (x, d) => Node({l: Empty, v: x, d, r: Empty, h: 1}) - - let bal = (l, x, d, r) => { - let hl = switch l { - | Empty => 0 - | Node({h}) => h - } - let hr = switch r { - | Empty => 0 - | Node({h}) => h - } - if hl > hr + 2 { - switch l { - | Empty => invalid_arg("Map.bal") - | Node({l: ll, v: lv, d: ld, r: lr}) => - if height(ll) >= height(lr) { - create(ll, lv, ld, create(lr, x, d, r)) - } else { - switch lr { - | Empty => invalid_arg("Map.bal") - | Node({l: lrl, v: lrv, d: lrd, r: lrr}) => - create(create(ll, lv, ld, lrl), lrv, lrd, create(lrr, x, d, r)) - } - } - } - } else if hr > hl + 2 { - switch r { - | Empty => invalid_arg("Map.bal") - | Node({l: rl, v: rv, d: rd, r: rr}) => - if height(rr) >= height(rl) { - create(create(l, x, d, rl), rv, rd, rr) - } else { - switch rl { - | Empty => invalid_arg("Map.bal") - | Node({l: rll, v: rlv, d: rld, r: rlr}) => - create(create(l, x, d, rll), rlv, rld, create(rlr, rv, rd, rr)) - } - } - } - } else { - Node({ - l, - v: x, - d, - r, - h: if hl >= hr { - hl + 1 - } else { - hr + 1 - }, - }) - } - } - - let empty = Empty - - let is_empty = param => - switch param { - | Empty => true - | _ => false - } - - let rec add = (x, data, param) => - switch param { - | Empty => Node({l: Empty, v: x, d: data, r: Empty, h: 1}) - | Node({l, v, d, r, h}) as m => - let c = Ord.compare(x, v) - if c == 0 { - if d === data { - m - } else { - Node({l, v: x, d: data, r, h}) - } - } else if c < 0 { - let ll = add(x, data, l) - if l === ll { - m - } else { - bal(ll, v, d, r) - } - } else { - let rr = add(x, data, r) - if r === rr { - m - } else { - bal(l, v, d, rr) - } - } - } - - let rec find = (x, param) => - switch param { - | Empty => raise(Not_found) - | Node({l, v, d, r}) => - let c = Ord.compare(x, v) - if c == 0 { - d - } else { - find( - x, - if c < 0 { - l - } else { - r - }, - ) - } - } - - let rec find_first_aux = (v0, d0, f, param) => - switch param { - | Empty => (v0, d0) - | Node({l, v, d, r}) => - if f(v) { - find_first_aux(v, d, f, l) - } else { - find_first_aux(v0, d0, f, r) - } - } - - let rec find_first = (f, param) => - switch param { - | Empty => raise(Not_found) - | Node({l, v, d, r}) => - if f(v) { - find_first_aux(v, d, f, l) - } else { - find_first(f, r) - } - } - - let rec find_first_opt_aux = (v0, d0, f, param) => - switch param { - | Empty => Some(v0, d0) - | Node({l, v, d, r}) => - if f(v) { - find_first_opt_aux(v, d, f, l) - } else { - find_first_opt_aux(v0, d0, f, r) - } - } - - let rec find_first_opt = (f, param) => - switch param { - | Empty => None - | Node({l, v, d, r}) => - if f(v) { - find_first_opt_aux(v, d, f, l) - } else { - find_first_opt(f, r) - } - } - - let rec find_last_aux = (v0, d0, f, param) => - switch param { - | Empty => (v0, d0) - | Node({l, v, d, r}) => - if f(v) { - find_last_aux(v, d, f, r) - } else { - find_last_aux(v0, d0, f, l) - } - } - - let rec find_last = (f, param) => - switch param { - | Empty => raise(Not_found) - | Node({l, v, d, r}) => - if f(v) { - find_last_aux(v, d, f, r) - } else { - find_last(f, l) - } - } - - let rec find_last_opt_aux = (v0, d0, f, param) => - switch param { - | Empty => Some(v0, d0) - | Node({l, v, d, r}) => - if f(v) { - find_last_opt_aux(v, d, f, r) - } else { - find_last_opt_aux(v0, d0, f, l) - } - } - - let rec find_last_opt = (f, param) => - switch param { - | Empty => None - | Node({l, v, d, r}) => - if f(v) { - find_last_opt_aux(v, d, f, r) - } else { - find_last_opt(f, l) - } - } - - let rec find_opt = (x, param) => - switch param { - | Empty => None - | Node({l, v, d, r}) => - let c = Ord.compare(x, v) - if c == 0 { - Some(d) - } else { - find_opt( - x, - if c < 0 { - l - } else { - r - }, - ) - } - } - - let rec mem = (x, param) => - switch param { - | Empty => false - | Node({l, v, r}) => - let c = Ord.compare(x, v) - c == 0 || - mem( - x, - if c < 0 { - l - } else { - r - }, - ) - } - - let rec min_binding = param => - switch param { - | Empty => raise(Not_found) - | Node({l: Empty, v, d}) => (v, d) - | Node({l}) => min_binding(l) - } - - let rec min_binding_opt = param => - switch param { - | Empty => None - | Node({l: Empty, v, d}) => Some(v, d) - | Node({l}) => min_binding_opt(l) - } - - let rec max_binding = param => - switch param { - | Empty => raise(Not_found) - | Node({v, d, r: Empty}) => (v, d) - | Node({r}) => max_binding(r) - } - - let rec max_binding_opt = param => - switch param { - | Empty => None - | Node({v, d, r: Empty}) => Some(v, d) - | Node({r}) => max_binding_opt(r) - } - - let rec remove_min_binding = param => - switch param { - | Empty => invalid_arg("Map.remove_min_elt") - | Node({l: Empty, r}) => r - | Node({l, v, d, r}) => bal(remove_min_binding(l), v, d, r) - } - - let merge = (t1, t2) => - switch (t1, t2) { - | (Empty, t) => t - | (t, Empty) => t - | (_, _) => - let (x, d) = min_binding(t2) - bal(t1, x, d, remove_min_binding(t2)) - } - - let rec remove = (x, param) => - switch param { - | Empty => Empty - | Node({l, v, d, r}) as m => - let c = Ord.compare(x, v) - if c == 0 { - merge(l, r) - } else if c < 0 { - let ll = remove(x, l) - if l === ll { - m - } else { - bal(ll, v, d, r) - } - } else { - let rr = remove(x, r) - if r === rr { - m - } else { - bal(l, v, d, rr) - } - } - } - - let rec update = (x, f, param) => - switch param { - | Empty => - switch f(None) { - | None => Empty - | Some(data) => Node({l: Empty, v: x, d: data, r: Empty, h: 1}) - } - | Node({l, v, d, r, h}) as m => - let c = Ord.compare(x, v) - if c == 0 { - switch f(Some(d)) { - | None => merge(l, r) - | Some(data) => - if d === data { - m - } else { - Node({l, v: x, d: data, r, h}) - } - } - } else if c < 0 { - let ll = update(x, f, l) - if l === ll { - m - } else { - bal(ll, v, d, r) - } - } else { - let rr = update(x, f, r) - if r === rr { - m - } else { - bal(l, v, d, rr) - } - } - } - - let rec iter = (f, param) => - switch param { - | Empty => () - | Node({l, v, d, r}) => - iter(f, l) - f(v, d) - iter(f, r) - } - - let rec map = (f, param) => - switch param { - | Empty => Empty - | Node({l, v, d, r, h}) => - let l' = map(f, l) - let d' = f(d) - let r' = map(f, r) - Node({l: l', v, d: d', r: r', h}) - } - - let rec mapi = (f, param) => - switch param { - | Empty => Empty - | Node({l, v, d, r, h}) => - let l' = mapi(f, l) - let d' = f(v, d) - let r' = mapi(f, r) - Node({l: l', v, d: d', r: r', h}) - } - - let rec fold = (f, m, accu) => - switch m { - | Empty => accu - | Node({l, v, d, r}) => fold(f, r, f(v, d, fold(f, l, accu))) - } - - let rec for_all = (p, param) => - switch param { - | Empty => true - | Node({l, v, d, r}) => p(v, d) && (for_all(p, l) && for_all(p, r)) - } - - let rec exists = (p, param) => - switch param { - | Empty => false - | Node({l, v, d, r}) => p(v, d) || (exists(p, l) || exists(p, r)) - } - - /* Beware: those two functions assume that the added k is *strictly* - smaller (or bigger) than all the present keys in the tree; it - does not test for equality with the current min (or max) key. - - Indeed, they are only used during the "join" operation which - respects this precondition. - */ - - let rec add_min_binding = (k, x, param) => - switch param { - | Empty => singleton(k, x) - | Node({l, v, d, r}) => bal(add_min_binding(k, x, l), v, d, r) - } - - let rec add_max_binding = (k, x, param) => - switch param { - | Empty => singleton(k, x) - | Node({l, v, d, r}) => bal(l, v, d, add_max_binding(k, x, r)) - } - - /* Same as create and bal, but no assumptions are made on the - relative heights of l and r. */ - - let rec join = (l, v, d, r) => - switch (l, r) { - | (Empty, _) => add_min_binding(v, d, r) - | (_, Empty) => add_max_binding(v, d, l) - | (Node({l: ll, v: lv, d: ld, r: lr, h: lh}), Node({l: rl, v: rv, d: rd, r: rr, h: rh})) => - if lh > rh + 2 { - bal(ll, lv, ld, join(lr, v, d, r)) - } else if rh > lh + 2 { - bal(join(l, v, d, rl), rv, rd, rr) - } else { - create(l, v, d, r) - } - } - - /* Merge two trees l and r into one. - All elements of l must precede the elements of r. - No assumption on the heights of l and r. */ - - let concat = (t1, t2) => - switch (t1, t2) { - | (Empty, t) => t - | (t, Empty) => t - | (_, _) => - let (x, d) = min_binding(t2) - join(t1, x, d, remove_min_binding(t2)) - } - - let concat_or_join = (t1, v, d, t2) => - switch d { - | Some(d) => join(t1, v, d, t2) - | None => concat(t1, t2) - } - - let rec split = (x, param) => - switch param { - | Empty => (Empty, None, Empty) - | Node({l, v, d, r}) => - let c = Ord.compare(x, v) - if c == 0 { - (l, Some(d), r) - } else if c < 0 { - let (ll, pres, rl) = split(x, l) - (ll, pres, join(rl, v, d, r)) - } else { - let (lr, pres, rr) = split(x, r) - (join(l, v, d, lr), pres, rr) - } - } - - let rec merge = (f, s1, s2) => - switch (s1, s2) { - | (Empty, Empty) => Empty - | (Node({l: l1, v: v1, d: d1, r: r1, h: h1}), _) if h1 >= height(s2) => - let (l2, d2, r2) = split(v1, s2) - concat_or_join(merge(f, l1, l2), v1, f(v1, Some(d1), d2), merge(f, r1, r2)) - | (_, Node({l: l2, v: v2, d: d2, r: r2})) => - let (l1, d1, r1) = split(v2, s1) - concat_or_join(merge(f, l1, l2), v2, f(v2, d1, Some(d2)), merge(f, r1, r2)) - | _ => assert(false) - } - - let rec union = (f, s1, s2) => - switch (s1, s2) { - | (Empty, s) | (s, Empty) => s - | (Node({l: l1, v: v1, d: d1, r: r1, h: h1}), Node({l: l2, v: v2, d: d2, r: r2, h: h2})) => - if h1 >= h2 { - let (l2, d2, r2) = split(v1, s2) - let l = union(f, l1, l2) and r = union(f, r1, r2) - switch d2 { - | None => join(l, v1, d1, r) - | Some(d2) => concat_or_join(l, v1, f(v1, d1, d2), r) - } - } else { - let (l1, d1, r1) = split(v2, s1) - let l = union(f, l1, l2) and r = union(f, r1, r2) - switch d1 { - | None => join(l, v2, d2, r) - | Some(d1) => concat_or_join(l, v2, f(v2, d1, d2), r) - } - } - } - - let rec filter = (p, param) => - switch param { - | Empty => Empty - | Node({l, v, d, r}) as m => - /* call [p] in the expected left-to-right order */ - let l' = filter(p, l) - let pvd = p(v, d) - let r' = filter(p, r) - if pvd { - if l === l' && r === r' { - m - } else { - join(l', v, d, r') - } - } else { - concat(l', r') - } - } - - let rec partition = (p, param) => - switch param { - | Empty => (Empty, Empty) - | Node({l, v, d, r}) => - /* call [p] in the expected left-to-right order */ - let (lt, lf) = partition(p, l) - let pvd = p(v, d) - let (rt, rf) = partition(p, r) - if pvd { - (join(lt, v, d, rt), concat(lf, rf)) - } else { - (concat(lt, rt), join(lf, v, d, rf)) - } - } - - type rec enumeration<'a> = End | More(key, 'a, t<'a>, enumeration<'a>) - - let rec cons_enum = (m, e) => - switch m { - | Empty => e - | Node({l, v, d, r}) => cons_enum(l, More(v, d, r, e)) - } - - let compare = (cmp, m1, m2) => { - let rec compare_aux = (e1, e2) => - switch (e1, e2) { - | (End, End) => 0 - | (End, _) => -1 - | (_, End) => 1 - | (More(v1, d1, r1, e1), More(v2, d2, r2, e2)) => - let c = Ord.compare(v1, v2) - if c != 0 { - c - } else { - let c = cmp(d1, d2) - if c != 0 { - c - } else { - compare_aux(cons_enum(r1, e1), cons_enum(r2, e2)) - } - } - } - compare_aux(cons_enum(m1, End), cons_enum(m2, End)) - } - - let equal = (cmp, m1, m2) => { - let rec equal_aux = (e1, e2) => - switch (e1, e2) { - | (End, End) => true - | (End, _) => false - | (_, End) => false - | (More(v1, d1, r1, e1), More(v2, d2, r2, e2)) => - Ord.compare(v1, v2) == 0 && (cmp(d1, d2) && equal_aux(cons_enum(r1, e1), cons_enum(r2, e2))) - } - equal_aux(cons_enum(m1, End), cons_enum(m2, End)) - } - - let rec cardinal = param => - switch param { - | Empty => 0 - | Node({l, r}) => cardinal(l) + 1 + cardinal(r) - } - - let rec bindings_aux = (accu, param) => - switch param { - | Empty => accu - | Node({l, v, d, r}) => bindings_aux(list{(v, d), ...bindings_aux(accu, r)}, l) - } - - let bindings = s => bindings_aux(list{}, s) - - let choose = min_binding - - let choose_opt = min_binding_opt -} diff --git a/jscomp/stdlib-406/map.resi b/jscomp/stdlib-406/map.resi deleted file mode 100644 index 11458cb69a..0000000000 --- a/jscomp/stdlib-406/map.resi +++ /dev/null @@ -1,310 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/*** Association tables over ordered types. - - This module implements applicative association tables, also known as - finite maps or dictionaries, given a total ordering function - over the keys. - All operations over maps are purely applicative (no side-effects). - The implementation uses balanced binary trees, and therefore searching - and insertion take time logarithmic in the size of the map. - - For instance: - {[ - module IntPairs = - struct - type t = int * int - let compare (x0,y0) (x1,y1) = - match Pervasives.compare x0 x1 with - 0 -> Pervasives.compare y0 y1 - | c -> c - end - - module PairsMap = Map.Make(IntPairs) - - let m = PairsMap.(empty |> add (0,1) \"hello\" |> add (1,0) \"world\") - ]} - - This creates a new module [PairsMap], with a new type ['a PairsMap.t] - of maps from [int * int] to ['a]. In this example, [m] contains [string] - values so its type is [string PairsMap.t]. -*/ - -/** Input signature of the functor {!Map.Make}. */ -module type OrderedType = { - /** The type of the map keys. */ - type t - - /** A total ordering function over the keys. - This is a two-argument function [f] such that - [f e1 e2] is zero if the keys [e1] and [e2] are equal, - [f e1 e2] is strictly negative if [e1] is smaller than [e2], - and [f e1 e2] is strictly positive if [e1] is greater than [e2]. - Example: a suitable ordering function is the generic structural - comparison function {!Pervasives.compare}. */ - let compare: (t, t) => int -} - -/** Output signature of the functor {!Map.Make}. */ -module type S = { - /** The type of the map keys. */ - type key - - /** The type of maps from type [key] to type ['a]. */ - type t<+'a> - - /** The empty map. */ - let empty: t<'a> - - /** Test whether a map is empty or not. */ - let is_empty: t<'a> => bool - - /** [mem x m] returns [true] if [m] contains a binding for [x], - and [false] otherwise. */ - let mem: (key, t<'a>) => bool - - /** [add x y m] returns a map containing the same bindings as - [m], plus a binding of [x] to [y]. If [x] was already bound - in [m] to a value that is physically equal to [y], - [m] is returned unchanged (the result of the function is - then physically equal to [m]). Otherwise, the previous binding - of [x] in [m] disappears. - @before 4.03 Physical equality was not ensured. */ - let add: (key, 'a, t<'a>) => t<'a> - - /** [update x f m] returns a map containing the same bindings as - [m], except for the binding of [x]. Depending on the value of - [y] where [y] is [f (find_opt x m)], the binding of [x] is - added, removed or updated. If [y] is [None], the binding is - removed if it exists; otherwise, if [y] is [Some z] then [x] - is associated to [z] in the resulting map. If [x] was already - bound in [m] to a value that is physically equal to [z], [m] - is returned unchanged (the result of the function is then - physically equal to [m]). - @since 4.06.0 - */ - let update: (key, option<'a> => option<'a>, t<'a>) => t<'a> - - /** [singleton x y] returns the one-element map that contains a binding [y] - for [x]. - @since 3.12.0 - */ - let singleton: (key, 'a) => t<'a> - - /** [remove x m] returns a map containing the same bindings as - [m], except for [x] which is unbound in the returned map. - If [x] was not in [m], [m] is returned unchanged - (the result of the function is then physically equal to [m]). - @before 4.03 Physical equality was not ensured. */ - let remove: (key, t<'a>) => t<'a> - - /** [merge f m1 m2] computes a map whose keys is a subset of keys of [m1] - and of [m2]. The presence of each such binding, and the corresponding - value, is determined with the function [f]. - In terms of the [find_opt] operation, we have - [find_opt x (merge f m1 m2) = f (find_opt x m1) (find_opt x m2)] - for any key [x], provided that [f None None = None]. - @since 3.12.0 - */ - let merge: ((key, option<'a>, option<'b>) => option<'c>, t<'a>, t<'b>) => t<'c> - - /** [union f m1 m2] computes a map whose keys is the union of keys - of [m1] and of [m2]. When the same binding is defined in both - arguments, the function [f] is used to combine them. - This is a special case of [merge]: [union f m1 m2] is equivalent - to [merge f' m1 m2], where - - [f' None None = None] - - [f' (Some v) None = Some v] - - [f' None (Some v) = Some v] - - [f' (Some v1) (Some v2) = f v1 v2] - - @since 4.03.0 - */ - let union: ((key, 'a, 'a) => option<'a>, t<'a>, t<'a>) => t<'a> - - /** Total ordering between maps. The first argument is a total ordering - used to compare data associated with equal keys in the two maps. */ - let compare: (('a, 'a) => int, t<'a>, t<'a>) => int - - /** [equal cmp m1 m2] tests whether the maps [m1] and [m2] are - equal, that is, contain equal keys and associate them with - equal data. [cmp] is the equality predicate used to compare - the data associated with the keys. */ - let equal: (('a, 'a) => bool, t<'a>, t<'a>) => bool - - /** [iter f m] applies [f] to all bindings in map [m]. - [f] receives the key as first argument, and the associated value - as second argument. The bindings are passed to [f] in increasing - order with respect to the ordering over the type of the keys. */ - let iter: ((key, 'a) => unit, t<'a>) => unit - - /** [fold f m a] computes [(f kN dN ... (f k1 d1 a)...)], - where [k1 ... kN] are the keys of all bindings in [m] - (in increasing order), and [d1 ... dN] are the associated data. */ - let fold: ((key, 'a, 'b) => 'b, t<'a>, 'b) => 'b - - /** [for_all p m] checks if all the bindings of the map - satisfy the predicate [p]. - @since 3.12.0 - */ - let for_all: ((key, 'a) => bool, t<'a>) => bool - - /** [exists p m] checks if at least one binding of the map - satisfies the predicate [p]. - @since 3.12.0 - */ - let exists: ((key, 'a) => bool, t<'a>) => bool - - /** [filter p m] returns the map with all the bindings in [m] - that satisfy predicate [p]. If [p] satisfies every binding in [m], - [m] is returned unchanged (the result of the function is then - physically equal to [m]) - @since 3.12.0 - @before 4.03 Physical equality was not ensured. - */ - let filter: ((key, 'a) => bool, t<'a>) => t<'a> - - /** [partition p m] returns a pair of maps [(m1, m2)], where - [m1] contains all the bindings of [s] that satisfy the - predicate [p], and [m2] is the map with all the bindings of - [s] that do not satisfy [p]. - @since 3.12.0 - */ - let partition: ((key, 'a) => bool, t<'a>) => (t<'a>, t<'a>) - - /** Return the number of bindings of a map. - @since 3.12.0 - */ - let cardinal: t<'a> => int - - /** Return the list of all bindings of the given map. - The returned list is sorted in increasing order with respect - to the ordering [Ord.compare], where [Ord] is the argument - given to {!Map.Make}. - @since 3.12.0 - */ - let bindings: t<'a> => list<(key, 'a)> - - /** Return the smallest binding of the given map - (with respect to the [Ord.compare] ordering), or raise - [Not_found] if the map is empty. - @since 3.12.0 - */ - let min_binding: t<'a> => (key, 'a) - - /** Return the smallest binding of the given map - (with respect to the [Ord.compare] ordering), or [None] - if the map is empty. - @since 4.05 - */ - let min_binding_opt: t<'a> => option<(key, 'a)> - - /** Same as {!Map.S.min_binding}, but returns the largest binding - of the given map. - @since 3.12.0 - */ - let max_binding: t<'a> => (key, 'a) - - /** Same as {!Map.S.min_binding_opt}, but returns the largest binding - of the given map. - @since 4.05 - */ - let max_binding_opt: t<'a> => option<(key, 'a)> - - /** Return one binding of the given map, or raise [Not_found] if - the map is empty. Which binding is chosen is unspecified, - but equal bindings will be chosen for equal maps. - @since 3.12.0 - */ - let choose: t<'a> => (key, 'a) - - /** Return one binding of the given map, or [None] if - the map is empty. Which binding is chosen is unspecified, - but equal bindings will be chosen for equal maps. - @since 4.05 - */ - let choose_opt: t<'a> => option<(key, 'a)> - - /** [split x m] returns a triple [(l, data, r)], where - [l] is the map with all the bindings of [m] whose key - is strictly less than [x]; - [r] is the map with all the bindings of [m] whose key - is strictly greater than [x]; - [data] is [None] if [m] contains no binding for [x], - or [Some v] if [m] binds [v] to [x]. - @since 3.12.0 - */ - let split: (key, t<'a>) => (t<'a>, option<'a>, t<'a>) - - /** [find x m] returns the current binding of [x] in [m], - or raises [Not_found] if no such binding exists. */ - let find: (key, t<'a>) => 'a - - /** [find_opt x m] returns [Some v] if the current binding of [x] - in [m] is [v], or [None] if no such binding exists. - @since 4.05 - */ - let find_opt: (key, t<'a>) => option<'a> - - /** [find_first f m], where [f] is a monotonically increasing function, - returns the binding of [m] with the lowest key [k] such that [f k], - or raises [Not_found] if no such key exists. - - For example, [find_first (fun k -> Ord.compare k x >= 0) m] will return - the first binding [k, v] of [m] where [Ord.compare k x >= 0] - (intuitively: [k >= x]), or raise [Not_found] if [x] is greater than any - element of [m]. - - @since 4.05 - */ - let find_first: (key => bool, t<'a>) => (key, 'a) - - /** [find_first_opt f m], where [f] is a monotonically increasing function, - returns an option containing the binding of [m] with the lowest key [k] - such that [f k], or [None] if no such key exists. - @since 4.05 - */ - let find_first_opt: (key => bool, t<'a>) => option<(key, 'a)> - - /** [find_last f m], where [f] is a monotonically decreasing function, - returns the binding of [m] with the highest key [k] such that [f k], - or raises [Not_found] if no such key exists. - @since 4.05 - */ - let find_last: (key => bool, t<'a>) => (key, 'a) - - /** [find_last_opt f m], where [f] is a monotonically decreasing function, - returns an option containing the binding of [m] with the highest key [k] - such that [f k], or [None] if no such key exists. - @since 4.05 - */ - let find_last_opt: (key => bool, t<'a>) => option<(key, 'a)> - - /** [map f m] returns a map with same domain as [m], where the - associated value [a] of all bindings of [m] has been - replaced by the result of the application of [f] to [a]. - The bindings are passed to [f] in increasing order - with respect to the ordering over the type of the keys. */ - let map: ('a => 'b, t<'a>) => t<'b> - - /** Same as {!Map.S.map}, but the function receives as arguments both the - key and the associated value for each binding of the map. */ - let mapi: ((key, 'a) => 'b, t<'a>) => t<'b> -} - -/** Functor building an implementation of the map structure - given a totally ordered type. */ -module Make: (Ord: OrderedType) => (S with type key = Ord.t) diff --git a/jscomp/stdlib-406/mapLabels.res b/jscomp/stdlib-406/mapLabels.res deleted file mode 100644 index 7a1a395075..0000000000 --- a/jscomp/stdlib-406/mapLabels.res +++ /dev/null @@ -1,669 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -module type OrderedType = { - type t - let compare: (t, t) => int -} - -module type S = { - type key - type t<+'a> - let empty: t<'a> - let is_empty: t<'a> => bool - let mem: (key, t<'a>) => bool - let add: (~key: key, ~data: 'a, t<'a>) => t<'a> - let update: (~key: key, ~f: option<'a> => option<'a>, t<'a>) => t<'a> - let singleton: (key, 'a) => t<'a> - let remove: (key, t<'a>) => t<'a> - let merge: (~f: (key, option<'a>, option<'b>) => option<'c>, t<'a>, t<'b>) => t<'c> - let union: (~f: (key, 'a, 'a) => option<'a>, t<'a>, t<'a>) => t<'a> - let compare: (~cmp: ('a, 'a) => int, t<'a>, t<'a>) => int - let equal: (~cmp: ('a, 'a) => bool, t<'a>, t<'a>) => bool - let iter: (~f: (~key: key, ~data: 'a) => unit, t<'a>) => unit - let fold: (~f: (~key: key, ~data: 'a, 'b) => 'b, t<'a>, ~init: 'b) => 'b - let for_all: (~f: (key, 'a) => bool, t<'a>) => bool - let exists: (~f: (key, 'a) => bool, t<'a>) => bool - let filter: (~f: (key, 'a) => bool, t<'a>) => t<'a> - let partition: (~f: (key, 'a) => bool, t<'a>) => (t<'a>, t<'a>) - let cardinal: t<'a> => int - let bindings: t<'a> => list<(key, 'a)> - let min_binding: t<'a> => (key, 'a) - let min_binding_opt: t<'a> => option<(key, 'a)> - let max_binding: t<'a> => (key, 'a) - let max_binding_opt: t<'a> => option<(key, 'a)> - let choose: t<'a> => (key, 'a) - let choose_opt: t<'a> => option<(key, 'a)> - let split: (key, t<'a>) => (t<'a>, option<'a>, t<'a>) - let find: (key, t<'a>) => 'a - let find_opt: (key, t<'a>) => option<'a> - let find_first: (~f: key => bool, t<'a>) => (key, 'a) - let find_first_opt: (~f: key => bool, t<'a>) => option<(key, 'a)> - let find_last: (~f: key => bool, t<'a>) => (key, 'a) - let find_last_opt: (~f: key => bool, t<'a>) => option<(key, 'a)> - let map: (~f: 'a => 'b, t<'a>) => t<'b> - let mapi: (~f: (key, 'a) => 'b, t<'a>) => t<'b> -} - -module Make = (Ord: OrderedType) => { - type key = Ord.t - - type rec t<'a> = - | Empty - | Node({l: t<'a>, v: key, d: 'a, r: t<'a>, h: int}) - - let height = param => - switch param { - | Empty => 0 - | Node({h}) => h - } - - let create = (l, x, d, r) => { - let hl = height(l) and hr = height(r) - Node({ - l, - v: x, - d, - r, - h: if hl >= hr { - hl + 1 - } else { - hr + 1 - }, - }) - } - - let singleton = (x, d) => Node({l: Empty, v: x, d, r: Empty, h: 1}) - - let bal = (l, x, d, r) => { - let hl = switch l { - | Empty => 0 - | Node({h}) => h - } - let hr = switch r { - | Empty => 0 - | Node({h}) => h - } - if hl > hr + 2 { - switch l { - | Empty => invalid_arg("Map.bal") - | Node({l: ll, v: lv, d: ld, r: lr}) => - if height(ll) >= height(lr) { - create(ll, lv, ld, create(lr, x, d, r)) - } else { - switch lr { - | Empty => invalid_arg("Map.bal") - | Node({l: lrl, v: lrv, d: lrd, r: lrr}) => - create(create(ll, lv, ld, lrl), lrv, lrd, create(lrr, x, d, r)) - } - } - } - } else if hr > hl + 2 { - switch r { - | Empty => invalid_arg("Map.bal") - | Node({l: rl, v: rv, d: rd, r: rr}) => - if height(rr) >= height(rl) { - create(create(l, x, d, rl), rv, rd, rr) - } else { - switch rl { - | Empty => invalid_arg("Map.bal") - | Node({l: rll, v: rlv, d: rld, r: rlr}) => - create(create(l, x, d, rll), rlv, rld, create(rlr, rv, rd, rr)) - } - } - } - } else { - Node({ - l, - v: x, - d, - r, - h: if hl >= hr { - hl + 1 - } else { - hr + 1 - }, - }) - } - } - - let empty = Empty - - let is_empty = param => - switch param { - | Empty => true - | _ => false - } - - let rec add = (~key as x, ~data, param) => - switch param { - | Empty => Node({l: Empty, v: x, d: data, r: Empty, h: 1}) - | Node({l, v, d, r, h}) as m => - let c = Ord.compare(x, v) - if c == 0 { - if d === data { - m - } else { - Node({l, v: x, d: data, r, h}) - } - } else if c < 0 { - let ll = add(~key=x, ~data, l) - if l === ll { - m - } else { - bal(ll, v, d, r) - } - } else { - let rr = add(~key=x, ~data, r) - if r === rr { - m - } else { - bal(l, v, d, rr) - } - } - } - - let rec find = (x, param) => - switch param { - | Empty => raise(Not_found) - | Node({l, v, d, r}) => - let c = Ord.compare(x, v) - if c == 0 { - d - } else { - find( - x, - if c < 0 { - l - } else { - r - }, - ) - } - } - - let rec find_first_aux = (v0, d0, f, param) => - switch param { - | Empty => (v0, d0) - | Node({l, v, d, r}) => - if f(v) { - find_first_aux(v, d, f, l) - } else { - find_first_aux(v0, d0, f, r) - } - } - - let rec find_first = (~f, param) => - switch param { - | Empty => raise(Not_found) - | Node({l, v, d, r}) => - if f(v) { - find_first_aux(v, d, f, l) - } else { - find_first(~f, r) - } - } - - let rec find_first_opt_aux = (v0, d0, f, param) => - switch param { - | Empty => Some(v0, d0) - | Node({l, v, d, r}) => - if f(v) { - find_first_opt_aux(v, d, f, l) - } else { - find_first_opt_aux(v0, d0, f, r) - } - } - - let rec find_first_opt = (~f, param) => - switch param { - | Empty => None - | Node({l, v, d, r}) => - if f(v) { - find_first_opt_aux(v, d, f, l) - } else { - find_first_opt(~f, r) - } - } - - let rec find_last_aux = (v0, d0, f, param) => - switch param { - | Empty => (v0, d0) - | Node({l, v, d, r}) => - if f(v) { - find_last_aux(v, d, f, r) - } else { - find_last_aux(v0, d0, f, l) - } - } - - let rec find_last = (~f, param) => - switch param { - | Empty => raise(Not_found) - | Node({l, v, d, r}) => - if f(v) { - find_last_aux(v, d, f, r) - } else { - find_last(~f, l) - } - } - - let rec find_last_opt_aux = (v0, d0, f, param) => - switch param { - | Empty => Some(v0, d0) - | Node({l, v, d, r}) => - if f(v) { - find_last_opt_aux(v, d, f, r) - } else { - find_last_opt_aux(v0, d0, f, l) - } - } - - let rec find_last_opt = (~f, param) => - switch param { - | Empty => None - | Node({l, v, d, r}) => - if f(v) { - find_last_opt_aux(v, d, f, r) - } else { - find_last_opt(~f, l) - } - } - - let rec find_opt = (x, param) => - switch param { - | Empty => None - | Node({l, v, d, r}) => - let c = Ord.compare(x, v) - if c == 0 { - Some(d) - } else { - find_opt( - x, - if c < 0 { - l - } else { - r - }, - ) - } - } - - let rec mem = (x, param) => - switch param { - | Empty => false - | Node({l, v, r}) => - let c = Ord.compare(x, v) - c == 0 || - mem( - x, - if c < 0 { - l - } else { - r - }, - ) - } - - let rec min_binding = param => - switch param { - | Empty => raise(Not_found) - | Node({l: Empty, v, d}) => (v, d) - | Node({l}) => min_binding(l) - } - - let rec min_binding_opt = param => - switch param { - | Empty => None - | Node({l: Empty, v, d}) => Some(v, d) - | Node({l}) => min_binding_opt(l) - } - - let rec max_binding = param => - switch param { - | Empty => raise(Not_found) - | Node({v, d, r: Empty}) => (v, d) - | Node({r}) => max_binding(r) - } - - let rec max_binding_opt = param => - switch param { - | Empty => None - | Node({v, d, r: Empty}) => Some(v, d) - | Node({r}) => max_binding_opt(r) - } - - let rec remove_min_binding = param => - switch param { - | Empty => invalid_arg("Map.remove_min_elt") - | Node({l: Empty, r}) => r - | Node({l, v, d, r}) => bal(remove_min_binding(l), v, d, r) - } - - let merge = (t1, t2) => - switch (t1, t2) { - | (Empty, t) => t - | (t, Empty) => t - | (_, _) => - let (x, d) = min_binding(t2) - bal(t1, x, d, remove_min_binding(t2)) - } - - let rec remove = (x, param) => - switch param { - | Empty => Empty - | Node({l, v, d, r}) as m => - let c = Ord.compare(x, v) - if c == 0 { - merge(l, r) - } else if c < 0 { - let ll = remove(x, l) - if l === ll { - m - } else { - bal(ll, v, d, r) - } - } else { - let rr = remove(x, r) - if r === rr { - m - } else { - bal(l, v, d, rr) - } - } - } - - let rec update = (~key as x, ~f, param) => - switch param { - | Empty => - switch f(None) { - | None => Empty - | Some(data) => Node({l: Empty, v: x, d: data, r: Empty, h: 1}) - } - | Node({l, v, d, r, h}) as m => - let c = Ord.compare(x, v) - if c == 0 { - switch f(Some(d)) { - | None => merge(l, r) - | Some(data) => - if d === data { - m - } else { - Node({l, v: x, d: data, r, h}) - } - } - } else if c < 0 { - let ll = update(~key=x, ~f, l) - if l === ll { - m - } else { - bal(ll, v, d, r) - } - } else { - let rr = update(~key=x, ~f, r) - if r === rr { - m - } else { - bal(l, v, d, rr) - } - } - } - - let rec iter = (~f, param) => - switch param { - | Empty => () - | Node({l, v, d, r}) => - iter(~f, l) - f(~key=v, ~data=d) - iter(~f, r) - } - - let rec map = (~f, param) => - switch param { - | Empty => Empty - | Node({l, v, d, r, h}) => - let l' = map(~f, l) - let d' = f(d) - let r' = map(~f, r) - Node({l: l', v, d: d', r: r', h}) - } - - let rec mapi = (~f, param) => - switch param { - | Empty => Empty - | Node({l, v, d, r, h}) => - let l' = mapi(~f, l) - let d' = f(v, d) - let r' = mapi(~f, r) - Node({l: l', v, d: d', r: r', h}) - } - - let rec fold = (~f, m, ~init as accu) => - switch m { - | Empty => accu - | Node({l, v, d, r}) => fold(~f, r, ~init=f(~key=v, ~data=d, fold(~f, l, ~init=accu))) - } - - let rec for_all = (~f as p, param) => - switch param { - | Empty => true - | Node({l, v, d, r}) => p(v, d) && (for_all(~f=p, l) && for_all(~f=p, r)) - } - - let rec exists = (~f as p, param) => - switch param { - | Empty => false - | Node({l, v, d, r}) => p(v, d) || (exists(~f=p, l) || exists(~f=p, r)) - } - - /* Beware: those two functions assume that the added k is *strictly* - smaller (or bigger) than all the present keys in the tree; it - does not test for equality with the current min (or max) key. - - Indeed, they are only used during the "join" operation which - respects this precondition. - */ - - let rec add_min_binding = (k, x, param) => - switch param { - | Empty => singleton(k, x) - | Node({l, v, d, r}) => bal(add_min_binding(k, x, l), v, d, r) - } - - let rec add_max_binding = (k, x, param) => - switch param { - | Empty => singleton(k, x) - | Node({l, v, d, r}) => bal(l, v, d, add_max_binding(k, x, r)) - } - - /* Same as create and bal, but no assumptions are made on the - relative heights of l and r. */ - - let rec join = (l, v, d, r) => - switch (l, r) { - | (Empty, _) => add_min_binding(v, d, r) - | (_, Empty) => add_max_binding(v, d, l) - | (Node({l: ll, v: lv, d: ld, r: lr, h: lh}), Node({l: rl, v: rv, d: rd, r: rr, h: rh})) => - if lh > rh + 2 { - bal(ll, lv, ld, join(lr, v, d, r)) - } else if rh > lh + 2 { - bal(join(l, v, d, rl), rv, rd, rr) - } else { - create(l, v, d, r) - } - } - - /* Merge two trees l and r into one. - All elements of l must precede the elements of r. - No assumption on the heights of l and r. */ - - let concat = (t1, t2) => - switch (t1, t2) { - | (Empty, t) => t - | (t, Empty) => t - | (_, _) => - let (x, d) = min_binding(t2) - join(t1, x, d, remove_min_binding(t2)) - } - - let concat_or_join = (t1, v, d, t2) => - switch d { - | Some(d) => join(t1, v, d, t2) - | None => concat(t1, t2) - } - - let rec split = (x, param) => - switch param { - | Empty => (Empty, None, Empty) - | Node({l, v, d, r}) => - let c = Ord.compare(x, v) - if c == 0 { - (l, Some(d), r) - } else if c < 0 { - let (ll, pres, rl) = split(x, l) - (ll, pres, join(rl, v, d, r)) - } else { - let (lr, pres, rr) = split(x, r) - (join(l, v, d, lr), pres, rr) - } - } - - let rec merge = (~f, s1, s2) => - switch (s1, s2) { - | (Empty, Empty) => Empty - | (Node({l: l1, v: v1, d: d1, r: r1, h: h1}), _) if h1 >= height(s2) => - let (l2, d2, r2) = split(v1, s2) - concat_or_join(merge(~f, l1, l2), v1, f(v1, Some(d1), d2), merge(~f, r1, r2)) - | (_, Node({l: l2, v: v2, d: d2, r: r2})) => - let (l1, d1, r1) = split(v2, s1) - concat_or_join(merge(~f, l1, l2), v2, f(v2, d1, Some(d2)), merge(~f, r1, r2)) - | _ => assert(false) - } - - let rec union = (~f, s1, s2) => - switch (s1, s2) { - | (Empty, s) | (s, Empty) => s - | (Node({l: l1, v: v1, d: d1, r: r1, h: h1}), Node({l: l2, v: v2, d: d2, r: r2, h: h2})) => - if h1 >= h2 { - let (l2, d2, r2) = split(v1, s2) - let l = union(~f, l1, l2) and r = union(~f, r1, r2) - switch d2 { - | None => join(l, v1, d1, r) - | Some(d2) => concat_or_join(l, v1, f(v1, d1, d2), r) - } - } else { - let (l1, d1, r1) = split(v2, s1) - let l = union(~f, l1, l2) and r = union(~f, r1, r2) - switch d1 { - | None => join(l, v2, d2, r) - | Some(d1) => concat_or_join(l, v2, f(v2, d1, d2), r) - } - } - } - - let rec filter = (~f as p, param) => - switch param { - | Empty => Empty - | Node({l, v, d, r}) as m => - /* call [p] in the expected left-to-right order */ - let l' = filter(~f=p, l) - let pvd = p(v, d) - let r' = filter(~f=p, r) - if pvd { - if l === l' && r === r' { - m - } else { - join(l', v, d, r') - } - } else { - concat(l', r') - } - } - - let rec partition = (~f as p, param) => - switch param { - | Empty => (Empty, Empty) - | Node({l, v, d, r}) => - /* call [p] in the expected left-to-right order */ - let (lt, lf) = partition(~f=p, l) - let pvd = p(v, d) - let (rt, rf) = partition(~f=p, r) - if pvd { - (join(lt, v, d, rt), concat(lf, rf)) - } else { - (concat(lt, rt), join(lf, v, d, rf)) - } - } - - type rec enumeration<'a> = End | More(key, 'a, t<'a>, enumeration<'a>) - - let rec cons_enum = (m, e) => - switch m { - | Empty => e - | Node({l, v, d, r}) => cons_enum(l, More(v, d, r, e)) - } - - let compare = (~cmp, m1, m2) => { - let rec compare_aux = (e1, e2) => - switch (e1, e2) { - | (End, End) => 0 - | (End, _) => -1 - | (_, End) => 1 - | (More(v1, d1, r1, e1), More(v2, d2, r2, e2)) => - let c = Ord.compare(v1, v2) - if c != 0 { - c - } else { - let c = cmp(d1, d2) - if c != 0 { - c - } else { - compare_aux(cons_enum(r1, e1), cons_enum(r2, e2)) - } - } - } - compare_aux(cons_enum(m1, End), cons_enum(m2, End)) - } - - let equal = (~cmp, m1, m2) => { - let rec equal_aux = (e1, e2) => - switch (e1, e2) { - | (End, End) => true - | (End, _) => false - | (_, End) => false - | (More(v1, d1, r1, e1), More(v2, d2, r2, e2)) => - Ord.compare(v1, v2) == 0 && (cmp(d1, d2) && equal_aux(cons_enum(r1, e1), cons_enum(r2, e2))) - } - equal_aux(cons_enum(m1, End), cons_enum(m2, End)) - } - - let rec cardinal = param => - switch param { - | Empty => 0 - | Node({l, r}) => cardinal(l) + 1 + cardinal(r) - } - - let rec bindings_aux = (accu, param) => - switch param { - | Empty => accu - | Node({l, v, d, r}) => bindings_aux(list{(v, d), ...bindings_aux(accu, r)}, l) - } - - let bindings = s => bindings_aux(list{}, s) - - let choose = min_binding - - let choose_opt = min_binding_opt -} diff --git a/jscomp/stdlib-406/moreLabels.res b/jscomp/stdlib-406/moreLabels.res deleted file mode 100644 index 2fb9e46e70..0000000000 --- a/jscomp/stdlib-406/moreLabels.res +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Jacques Garrigue, Kyoto University RIMS */ -/* */ -/* Copyright 2001 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. */ -/* */ -/* ************************************************************************ */ - -/* Module [MoreLabels]: meta-module for compatibility labelled libraries */ - -module Hashtbl = HashtblLabels - -module Map = MapLabels - -module Set = SetLabels diff --git a/jscomp/stdlib-406/moreLabels.resi b/jscomp/stdlib-406/moreLabels.resi deleted file mode 100644 index 397641d669..0000000000 --- a/jscomp/stdlib-406/moreLabels.resi +++ /dev/null @@ -1,182 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Jacques Garrigue, Kyoto University RIMS */ -/* */ -/* Copyright 2001 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. */ -/* */ -/* ************************************************************************ */ - -/*** Extra labeled libraries. - - This meta-module provides labelized version of the {!Hashtbl}, - {!Map} and {!Set} modules. - - They only differ by their labels. They are provided to help - porting from previous versions of OCaml. - The contents of this module are subject to change. -*/ - -module Hashtbl: { - type t<'a, 'b> = Hashtbl.t<'a, 'b> - let create: (~random: bool=?, int) => t<'a, 'b> - let clear: t<'a, 'b> => unit - let reset: t<'a, 'b> => unit - let copy: t<'a, 'b> => t<'a, 'b> - let add: (t<'a, 'b>, ~key: 'a, ~data: 'b) => unit - let find: (t<'a, 'b>, 'a) => 'b - let find_opt: (t<'a, 'b>, 'a) => option<'b> - let find_all: (t<'a, 'b>, 'a) => list<'b> - let mem: (t<'a, 'b>, 'a) => bool - let remove: (t<'a, 'b>, 'a) => unit - let replace: (t<'a, 'b>, ~key: 'a, ~data: 'b) => unit - let iter: (~f: (~key: 'a, ~data: 'b) => unit, t<'a, 'b>) => unit - let filter_map_inplace: (~f: (~key: 'a, ~data: 'b) => option<'b>, t<'a, 'b>) => unit - let fold: (~f: (~key: 'a, ~data: 'b, 'c) => 'c, t<'a, 'b>, ~init: 'c) => 'c - let length: t<'a, 'b> => int - let randomize: unit => unit - let is_randomized: unit => bool - type statistics = Hashtbl.statistics - let stats: t<'a, 'b> => statistics - module type HashedType = Hashtbl.HashedType - module type SeededHashedType = Hashtbl.SeededHashedType - module type S = { - type rec key - and t<'a> - let create: int => t<'a> - let clear: t<'a> => unit - let reset: t<'a> => unit - let copy: t<'a> => t<'a> - let add: (t<'a>, ~key: key, ~data: 'a) => unit - let remove: (t<'a>, key) => unit - let find: (t<'a>, key) => 'a - let find_opt: (t<'a>, key) => option<'a> - let find_all: (t<'a>, key) => list<'a> - let replace: (t<'a>, ~key: key, ~data: 'a) => unit - let mem: (t<'a>, key) => bool - let iter: (~f: (~key: key, ~data: 'a) => unit, t<'a>) => unit - let filter_map_inplace: (~f: (~key: key, ~data: 'a) => option<'a>, t<'a>) => unit - let fold: (~f: (~key: key, ~data: 'a, 'b) => 'b, t<'a>, ~init: 'b) => 'b - let length: t<'a> => int - let stats: t<'a> => statistics - } - module type SeededS = { - type rec key - and t<'a> - let create: (~random: bool=?, int) => t<'a> - let clear: t<'a> => unit - let reset: t<'a> => unit - let copy: t<'a> => t<'a> - let add: (t<'a>, ~key: key, ~data: 'a) => unit - let remove: (t<'a>, key) => unit - let find: (t<'a>, key) => 'a - let find_opt: (t<'a>, key) => option<'a> - let find_all: (t<'a>, key) => list<'a> - let replace: (t<'a>, ~key: key, ~data: 'a) => unit - let mem: (t<'a>, key) => bool - let iter: (~f: (~key: key, ~data: 'a) => unit, t<'a>) => unit - let filter_map_inplace: (~f: (~key: key, ~data: 'a) => option<'a>, t<'a>) => unit - let fold: (~f: (~key: key, ~data: 'a, 'b) => 'b, t<'a>, ~init: 'b) => 'b - let length: t<'a> => int - let stats: t<'a> => statistics - } - module Make: (H: HashedType) => (S with type key = H.t) - module MakeSeeded: (H: SeededHashedType) => (SeededS with type key = H.t) - let hash: 'a => int - let seeded_hash: (int, 'a) => int - let hash_param: (int, int, 'a) => int - let seeded_hash_param: (int, int, int, 'a) => int -} - -module Map: { - module type OrderedType = Map.OrderedType - module type S = { - type rec key - and t<+'a> - let empty: t<'a> - let is_empty: t<'a> => bool - let mem: (key, t<'a>) => bool - let add: (~key: key, ~data: 'a, t<'a>) => t<'a> - let update: (~key: key, ~f: option<'a> => option<'a>, t<'a>) => t<'a> - let singleton: (key, 'a) => t<'a> - let remove: (key, t<'a>) => t<'a> - let merge: (~f: (key, option<'a>, option<'b>) => option<'c>, t<'a>, t<'b>) => t<'c> - let union: (~f: (key, 'a, 'a) => option<'a>, t<'a>, t<'a>) => t<'a> - let compare: (~cmp: ('a, 'a) => int, t<'a>, t<'a>) => int - let equal: (~cmp: ('a, 'a) => bool, t<'a>, t<'a>) => bool - let iter: (~f: (~key: key, ~data: 'a) => unit, t<'a>) => unit - let fold: (~f: (~key: key, ~data: 'a, 'b) => 'b, t<'a>, ~init: 'b) => 'b - let for_all: (~f: (key, 'a) => bool, t<'a>) => bool - let exists: (~f: (key, 'a) => bool, t<'a>) => bool - let filter: (~f: (key, 'a) => bool, t<'a>) => t<'a> - let partition: (~f: (key, 'a) => bool, t<'a>) => (t<'a>, t<'a>) - let cardinal: t<'a> => int - let bindings: t<'a> => list<(key, 'a)> - let min_binding: t<'a> => (key, 'a) - let min_binding_opt: t<'a> => option<(key, 'a)> - let max_binding: t<'a> => (key, 'a) - let max_binding_opt: t<'a> => option<(key, 'a)> - let choose: t<'a> => (key, 'a) - let choose_opt: t<'a> => option<(key, 'a)> - let split: (key, t<'a>) => (t<'a>, option<'a>, t<'a>) - let find: (key, t<'a>) => 'a - let find_opt: (key, t<'a>) => option<'a> - let find_first: (~f: key => bool, t<'a>) => (key, 'a) - let find_first_opt: (~f: key => bool, t<'a>) => option<(key, 'a)> - let find_last: (~f: key => bool, t<'a>) => (key, 'a) - let find_last_opt: (~f: key => bool, t<'a>) => option<(key, 'a)> - let map: (~f: 'a => 'b, t<'a>) => t<'b> - let mapi: (~f: (key, 'a) => 'b, t<'a>) => t<'b> - } - module Make: (Ord: OrderedType) => (S with type key = Ord.t) -} - -module Set: { - module type OrderedType = Set.OrderedType - module type S = { - type rec elt - and t - let empty: t - let is_empty: t => bool - let mem: (elt, t) => bool - let add: (elt, t) => t - let singleton: elt => t - let remove: (elt, t) => t - let union: (t, t) => t - let inter: (t, t) => t - let diff: (t, t) => t - let compare: (t, t) => int - let equal: (t, t) => bool - let subset: (t, t) => bool - let iter: (~f: elt => unit, t) => unit - let map: (~f: elt => elt, t) => t - let fold: (~f: (elt, 'a) => 'a, t, ~init: 'a) => 'a - let for_all: (~f: elt => bool, t) => bool - let exists: (~f: elt => bool, t) => bool - let filter: (~f: elt => bool, t) => t - let partition: (~f: elt => bool, t) => (t, t) - let cardinal: t => int - let elements: t => list - let min_elt: t => elt - let min_elt_opt: t => option - let max_elt: t => elt - let max_elt_opt: t => option - let choose: t => elt - let choose_opt: t => option - let split: (elt, t) => (t, bool, t) - let find: (elt, t) => elt - let find_opt: (elt, t) => option - let find_first: (~f: elt => bool, t) => elt - let find_first_opt: (~f: elt => bool, t) => option - let find_last: (~f: elt => bool, t) => elt - let find_last_opt: (~f: elt => bool, t) => option - let of_list: list => t - } - module Make: (Ord: OrderedType) => (S with type elt = Ord.t) -} diff --git a/jscomp/stdlib-406/obj.res b/jscomp/stdlib-406/obj.res deleted file mode 100644 index e181ec8e15..0000000000 --- a/jscomp/stdlib-406/obj.res +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/* Operations on internal representations of values */ - -type t - -external repr: 'a => t = "%identity" -external obj: t => 'a = "%identity" -external magic: 'a => 'b = "%identity" -external is_int: t => bool = "%obj_is_int" -@inline(always) let is_block = a => !is_int(a) -external tag: t => int = "?obj_tag" -external size: t => int = "#obj_length" -external field: (t, int) => t = "%obj_field" -external set_field: (t, int, t) => unit = "%obj_set_field" -external dup: t => t = "%obj_dup" diff --git a/jscomp/stdlib-406/obj.resi b/jscomp/stdlib-406/obj.resi deleted file mode 100644 index 886586fb49..0000000000 --- a/jscomp/stdlib-406/obj.resi +++ /dev/null @@ -1,51 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/*** Operations on internal representations of values. - - Not for the casual user. -*/ - -type t - -external repr: 'a => t = "%identity" -external obj: t => 'a = "%identity" -external magic: 'a => 'b = "%identity" -@inline(always) let is_block: t => bool - -external tag: t => int = "?obj_tag" -/** - Computes the total size (in words, including the headers) of all - heap blocks accessible from the argument. Statically - allocated blocks are excluded. - - @Since 4.04 -*/ -external size: t => int = "#obj_length" - -external field: (t, int) => t = "%obj_field" - -/** When using flambda: - - [set_field] MUST NOT be called on immutable blocks. (Blocks allocated - in C stubs, or with [new_block] below, are always considered mutable.) - - For experts only: - [set_field] et al can be made safe by first wrapping the block in - {!Sys.opaque_identity}, so any information about its contents will not - be propagated. -*/ -external set_field: (t, int, t) => unit = "%obj_set_field" -external dup: t => t = "%obj_dup" diff --git a/jscomp/stdlib-406/parsing.res b/jscomp/stdlib-406/parsing.res deleted file mode 100644 index 6614e94357..0000000000 --- a/jscomp/stdlib-406/parsing.res +++ /dev/null @@ -1,232 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/* The parsing engine */ - -open Lexing - -/* Internal interface to the parsing engine */ - -type parser_env = { - mutable s_stack: array /* States */, - mutable v_stack: array /* Semantic attributes */, - mutable symb_start_stack: array /* Start positions */, - mutable symb_end_stack: array /* End positions */, - mutable stacksize: int /* Size of the stacks */, - mutable stackbase: int /* Base sp for current parse */, - mutable curr_char: int /* Last token read */, - mutable lval: Obj.t /* Its semantic attribute */, - mutable symb_start: position /* Start pos. of the current symbol */, - mutable symb_end: position /* End pos. of the current symbol */, - mutable asp: int /* The stack pointer for attributes */, - mutable rule_len: int /* Number of rhs items in the rule */, - mutable rule_number: int /* Rule number to reduce by */, - mutable sp: int /* Saved sp for parse_engine */, - mutable state: int /* Saved state for parse_engine */, - mutable errflag: int, -} /* Saved error flag for parse_engine */ - -type parse_tables = { - actions: array Obj.t>, - transl_const: array, - transl_block: array, - lhs: string, - len: string, - defred: string, - dgoto: string, - sindex: string, - rindex: string, - gindex: string, - tablesize: int, - table: string, - check: string, - error_function: string => unit, - names_const: string, - names_block: string, -} - -exception YYexit(Obj.t) -exception Parse_error - -type parser_input = - | Start - | Token_read - | Stacks_grown_1 - | Stacks_grown_2 - | Semantic_action_computed - | Error_detected - -type parser_output = - | Read_token - | Raise_parse_error - | Grow_stacks_1 - | Grow_stacks_2 - | Compute_semantic_action - | Call_error_function - -/* to avoid warnings */ -let _ = list{ - Read_token, - Raise_parse_error, - Grow_stacks_1, - Grow_stacks_2, - Compute_semantic_action, - Call_error_function, -} - -external parse_engine: (parse_tables, parser_env, parser_input, Obj.t) => parser_output = - "?parse_engine" - -external set_trace: bool => bool = "?set_parser_trace" - -let env = { - s_stack: Array.make(100, 0), - v_stack: Array.make(100, Obj.repr()), - symb_start_stack: Array.make(100, dummy_pos), - symb_end_stack: Array.make(100, dummy_pos), - stacksize: 100, - stackbase: 0, - curr_char: 0, - lval: Obj.repr(), - symb_start: dummy_pos, - symb_end: dummy_pos, - asp: 0, - rule_len: 0, - rule_number: 0, - sp: 0, - state: 0, - errflag: 0, -} - -let grow_stacks = () => { - let oldsize = env.stacksize - let newsize = oldsize * 2 - let new_s = Array.make(newsize, 0) - and new_v = Array.make(newsize, Obj.repr()) - and new_start = Array.make(newsize, dummy_pos) - and new_end = Array.make(newsize, dummy_pos) - Array.blit(env.s_stack, 0, new_s, 0, oldsize) - env.s_stack = new_s - Array.blit(env.v_stack, 0, new_v, 0, oldsize) - env.v_stack = new_v - Array.blit(env.symb_start_stack, 0, new_start, 0, oldsize) - env.symb_start_stack = new_start - Array.blit(env.symb_end_stack, 0, new_end, 0, oldsize) - env.symb_end_stack = new_end - env.stacksize = newsize -} - -let clear_parser = () => { - Array.fill(env.v_stack, 0, env.stacksize, Obj.repr()) - env.lval = Obj.repr() -} - -let current_lookahead_fun = ref((_: Obj.t) => false) - -let yyparse = (tables, start, lexer, lexbuf) => { - let rec loop = (cmd, arg) => - switch parse_engine(tables, env, cmd, arg) { - | Read_token => - let t = Obj.repr(lexer(lexbuf)) - env.symb_start = lexbuf.lex_start_p - env.symb_end = lexbuf.lex_curr_p - loop(Token_read, t) - | Raise_parse_error => raise(Parse_error) - | Compute_semantic_action => - let (action, value) = try ( - Semantic_action_computed, - tables.actions[env.rule_number](env), - ) catch { - | Parse_error => (Error_detected, Obj.repr()) - } - loop(action, value) - | Grow_stacks_1 => - grow_stacks() - loop(Stacks_grown_1, Obj.repr()) - | Grow_stacks_2 => - grow_stacks() - loop(Stacks_grown_2, Obj.repr()) - | Call_error_function => - tables.error_function("syntax error") - loop(Error_detected, Obj.repr()) - } - let init_asp = env.asp - and init_sp = env.sp - and init_stackbase = env.stackbase - and init_state = env.state - and init_curr_char = env.curr_char - and init_lval = env.lval - and init_errflag = env.errflag - env.stackbase = env.sp + 1 - env.curr_char = start - env.symb_end = lexbuf.lex_curr_p - try loop(Start, Obj.repr()) catch { - | exn => - let curr_char = env.curr_char - env.asp = init_asp - env.sp = init_sp - env.stackbase = init_stackbase - env.state = init_state - env.curr_char = init_curr_char - env.lval = init_lval - env.errflag = init_errflag - switch exn { - | YYexit(v) => Obj.magic(v) - | _ => - current_lookahead_fun := - ( - tok => - if Js.typeof(tok) != "number" { - tables.transl_block[Obj.tag(tok)] == curr_char - } else { - tables.transl_const[Obj.magic(tok)] == curr_char - } - ) - raise(exn) - } - } -} - -let peek_val = (env, n) => Obj.magic(env.v_stack[env.asp - n]) - -let symbol_start_pos = () => { - let rec loop = i => - if i <= 0 { - env.symb_end_stack[env.asp] - } else { - let st = env.symb_start_stack[env.asp - i + 1] - let en = env.symb_end_stack[env.asp - i + 1] - if st != en { - st - } else { - loop(i - 1) - } - } - - loop(env.rule_len) -} - -let symbol_end_pos = () => env.symb_end_stack[env.asp] -let rhs_start_pos = n => env.symb_start_stack[env.asp - (env.rule_len - n)] -let rhs_end_pos = n => env.symb_end_stack[env.asp - (env.rule_len - n)] - -let symbol_start = () => symbol_start_pos().pos_cnum -let symbol_end = () => symbol_end_pos().pos_cnum -let rhs_start = n => rhs_start_pos(n).pos_cnum -let rhs_end = n => rhs_end_pos(n).pos_cnum - -let is_current_lookahead = tok => current_lookahead_fun.contents(Obj.repr(tok)) - -let parse_error = (_: string) => () diff --git a/jscomp/stdlib-406/parsing.resi b/jscomp/stdlib-406/parsing.resi deleted file mode 100644 index f93fd0fcd1..0000000000 --- a/jscomp/stdlib-406/parsing.resi +++ /dev/null @@ -1,101 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/* The run-time library for parsers generated by [ocamlyacc]. */ - -/** [symbol_start] and {!Parsing.symbol_end} are to be called in the - action part of a grammar rule only. They return the offset of the - string that matches the left-hand side of the rule: [symbol_start()] - returns the offset of the first character; [symbol_end()] returns the - offset after the last character. The first character in a file is at - offset 0. */ -let symbol_start: unit => int - -/** See {!Parsing.symbol_start}. */ -let symbol_end: unit => int - -/** Same as {!Parsing.symbol_start} and {!Parsing.symbol_end}, but - return the offset of the string matching the [n]th item on the - right-hand side of the rule, where [n] is the integer parameter - to [rhs_start] and [rhs_end]. [n] is 1 for the leftmost item. */ -let rhs_start: int => int - -/** See {!Parsing.rhs_start}. */ -let rhs_end: int => int - -/** Same as [symbol_start], but return a [position] instead of an offset. */ -let symbol_start_pos: unit => Lexing.position - -/** Same as [symbol_end], but return a [position] instead of an offset. */ -let symbol_end_pos: unit => Lexing.position - -/** Same as [rhs_start], but return a [position] instead of an offset. */ -let rhs_start_pos: int => Lexing.position - -/** Same as [rhs_end], but return a [position] instead of an offset. */ -let rhs_end_pos: int => Lexing.position - -/** Empty the parser stack. Call it just after a parsing function - has returned, to remove all pointers from the parser stack - to structures that were built by semantic actions during parsing. - This is optional, but lowers the memory requirements of the - programs. */ -let clear_parser: unit => unit - -/** Raised when a parser encounters a syntax error. - Can also be raised from the action part of a grammar rule, - to initiate error recovery. */ -exception Parse_error - -/** Control debugging support for [ocamlyacc]-generated parsers. - After [Parsing.set_trace true], the pushdown automaton that - executes the parsers prints a trace of its actions (reading a token, - shifting a state, reducing by a rule) on standard output. - [Parsing.set_trace false] turns this debugging trace off. - The boolean returned is the previous state of the trace flag. - @since 3.11.0 -*/ -let set_trace: bool => bool - -/* The following definitions are used by the generated parsers only. - They are not intended to be used directly by user programs. */ - -type parser_env - -type parse_tables = { - actions: array Obj.t>, - transl_const: array, - transl_block: array, - lhs: string, - len: string, - defred: string, - dgoto: string, - sindex: string, - rindex: string, - gindex: string, - tablesize: int, - table: string, - check: string, - error_function: string => unit, - names_const: string, - names_block: string, -} - -exception YYexit(Obj.t) - -let yyparse: (parse_tables, int, Lexing.lexbuf => 'a, Lexing.lexbuf) => 'b -let peek_val: (parser_env, int) => 'a -let is_current_lookahead: 'a => bool -let parse_error: string => unit diff --git a/jscomp/stdlib-406/pervasives.res b/jscomp/stdlib-406/pervasives.res deleted file mode 100644 index 0cb4454052..0000000000 --- a/jscomp/stdlib-406/pervasives.res +++ /dev/null @@ -1,311 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/* Internal */ -external __unsafe_cast: 'a => 'b = "%identity" - -/* Exceptions */ - -external raise: exn => 'a = "%raise" -external raise_notrace: exn => 'a = "%raise_notrace" - -let failwith = s => raise(Failure(s)) -let invalid_arg = s => raise(Invalid_argument(s)) - -exception Exit - -/* Composition operators */ - -external \"|>": ('a, 'a => 'b) => 'b = "%revapply" -external \"@@": ('a => 'b, 'a) => 'b = "%apply" - -/* Debugging */ - -external __LOC__: string = "%loc_LOC" -external __FILE__: string = "%loc_FILE" -external __LINE__: int = "%loc_LINE" -external __MODULE__: string = "%loc_MODULE" -external __POS__: (string, int, int, int) = "%loc_POS" - -external __LOC_OF__: 'a => (string, 'a) = "%loc_LOC" -external __LINE_OF__: 'a => (int, 'a) = "%loc_LINE" -external __POS_OF__: 'a => ((string, int, int, int), 'a) = "%loc_POS" - -/* Comparisons */ - -external \"=": ('a, 'a) => bool = "%equal" -external \"<>": ('a, 'a) => bool = "%notequal" -external \"<": ('a, 'a) => bool = "%lessthan" -external \">": ('a, 'a) => bool = "%greaterthan" -external \"<=": ('a, 'a) => bool = "%lessequal" -external \">=": ('a, 'a) => bool = "%greaterequal" -external compare: ('a, 'a) => int = "%compare" -external min: ('a, 'a) => 'a = "%bs_min" -external max: ('a, 'a) => 'a = "%bs_max" -external \"==": ('a, 'a) => bool = "%eq" -external \"!=": ('a, 'a) => bool = "%noteq" - -/* Boolean operations */ - -external not: bool => bool = "%boolnot" - -external \"&&": (bool, bool) => bool = "%sequand" - -external \"||": (bool, bool) => bool = "%sequor" - -/* Integer operations */ - -external \"~-": int => int = "%negint" -external \"~+": int => int = "%identity" -external succ: int => int = "%succint" -external pred: int => int = "%predint" -external \"+": (int, int) => int = "%addint" -external \"-": (int, int) => int = "%subint" -external \"*": (int, int) => int = "%mulint" -external \"/": (int, int) => int = "%divint" -external mod: (int, int) => int = "%modint" - -let abs = x => - if x >= 0 { - x - } else { - -x - } - -external land: (int, int) => int = "%andint" -external lor: (int, int) => int = "%orint" -external lxor: (int, int) => int = "%xorint" - -let lnot = x => lxor(x, -1) - -external lsl: (int, int) => int = "%lslint" -external lsr: (int, int) => int = "%lsrint" -external asr: (int, int) => int = "%asrint" - -let max_int = lsr(-1, 1) -let min_int = max_int + 1 - -/* Floating-point operations */ - -external \"~-.": float => float = "%negfloat" -external \"~+.": float => float = "%identity" -external \"+.": (float, float) => float = "%addfloat" -external \"-.": (float, float) => float = "%subfloat" -external \"*.": (float, float) => float = "%mulfloat" -external \"/.": (float, float) => float = "%divfloat" - -@val @scope("Math") external \"**": (float, float) => float = "pow" -@val @scope("Math") external exp: float => float = "exp" -external expm1: float => float = "?expm1_float" - -@val @scope("Math") external acos: float => float = "acos" -@val @scope("Math") external asin: float => float = "asin" -@val @scope("Math") external atan: float => float = "atan" -@val @scope("Math") external atan2: (float, float) => float = "atan2" -external hypot: (float, float) => float = "?hypot_float" - -@val @scope("Math") external cos: float => float = "cos" -@val @scope("Math") external cosh: float => float = "cosh" -@val @scope("Math") external log: float => float = "log" -@val @scope("Math") external log10: float => float = "log10" -@val @scope("Math") external log1p: float => float = "log1p" -@val @scope("Math") external sin: float => float = "sin" -@val @scope("Math") external sinh: float => float = "sinh" -@val @scope("Math") external sqrt: float => float = "sqrt" -@val @scope("Math") external tan: float => float = "tan" -@val @scope("Math") external tanh: float => float = "tanh" -@val @scope("Math") external ceil: float => float = "ceil" -@val @scope("Math") external floor: float => float = "floor" -@val @scope("Math") external abs_float: float => float = "abs" -external copysign: (float, float) => float = "?copysign_float" -external mod_float: (float, float) => float = "?fmod_float" -external frexp: float => (float, int) = "?frexp_float" -external ldexp: (float, int) => float = "?ldexp_float" -external modf: float => (float, float) = "?modf_float" -external float: int => float = "%floatofint" -external float_of_int: int => float = "%floatofint" -external truncate: float => int = "%intoffloat" -external int_of_float: float => int = "%intoffloat" - -let infinity = 0x1p2047 -let neg_infinity = -0x1p2047 -@val @scope("Number") external nan: float = "NaN" -let max_float = 1.79769313486231571e+308 /* 0x1.ffff_ffff_ffff_fp+1023 */ -let min_float = 2.22507385850720138e-308 /* 0x1p-1022 */ -let epsilon_float = 2.22044604925031308e-16 /* 0x1p-52 */ - -type fpclass = - | FP_normal - | FP_subnormal - | FP_zero - | FP_infinite - | FP_nan - -let classify_float = (x: float): fpclass => - if (%raw(`isFinite`): (. _) => _)(. x) { - if abs_float(x) >= /* 0x1p-1022 */ /* 2.22507385850720138e-308 */ min_float { - FP_normal - } else if x != 0. { - FP_subnormal - } else { - FP_zero - } - } else if (%raw(`isNaN`): (. _) => _)(. x) { - FP_nan - } else { - FP_infinite - } - -/* String and byte sequence operations -- more in modules String and Bytes */ - -external string_length: string => int = "%string_length" - -external \"^": (string, string) => string = "#string_append" -/* Character operations -- more in module Char */ - -external int_of_char: char => int = "%identity" -external unsafe_char_of_int: int => char = "%identity" -let char_of_int = n => - if n < 0 || n > 255 { - invalid_arg("char_of_int") - } else { - unsafe_char_of_int(n) - } - -/* Unit operations */ - -external ignore: 'a => unit = "%ignore" - -/* Pair operations */ - -external fst: (('a, 'b)) => 'a = "%field0" -external snd: (('a, 'b)) => 'b = "%field1" - -/* References */ - -type ref<'a> = {mutable contents: 'a} -external ref: 'a => ref<'a> = "%makemutable" -external \"!": ref<'a> => 'a = "%bs_ref_field0" -external \":=": (ref<'a>, 'a) => unit = "%bs_ref_setfield0" -external incr: ref => unit = "%incr" -external decr: ref => unit = "%decr" - -/* String conversion functions */ -external format_float: (string, float) => string = "?format_float" - -let string_of_bool = b => - if b { - "true" - } else { - "false" - } -let bool_of_string = param => - switch param { - | "true" => true - | "false" => false - | _ => invalid_arg("bool_of_string") - } - -let bool_of_string_opt = param => - switch param { - | "true" => Some(true) - | "false" => Some(false) - | _ => None - } - -@val external string_of_int: int => string = "String" - -external int_of_string: string => int = "?int_of_string" - -let int_of_string_opt = s => - /* TODO: provide this directly as a non-raising primitive. */ - try Some(int_of_string(s)) catch { - | Failure(_) => None - } - -external string_get: (string, int) => char = "%string_safe_get" - -let valid_float_lexem = s => { - let l = string_length(s) - let rec loop = i => - if i >= l { - s ++ "." - } else { - switch string_get(s, i) { - | '0' .. '9' | '-' => loop(i + 1) - | _ => s - } - } - - loop(0) -} - -let string_of_float = f => valid_float_lexem(format_float("%.12g", f)) - -external float_of_string: string => float = "?float_of_string" - -let float_of_string_opt = s => - /* TODO: provide this directly as a non-raising primitive. */ - try Some(float_of_string(s)) catch { - | Failure(_) => None - } - -/* List operations -- more in module List */ - -let rec \"@" = (l1, l2) => - switch l1 { - | list{} => l2 - | list{hd, ...tl} => list{hd, ...\"@"(tl, l2)} - } - -/* Output functions on standard output */ - -@val @scope("console") external print_endline: string => unit = "log" -let print_newline = () => print_endline("") - -/* Output functions on standard error */ - -@val @scope("console") external prerr_endline: string => unit = "error" -let prerr_newline = () => prerr_endline("") - -let print_int = (i: int) => print_endline(string_of_int(i)) -let print_float = (i: float) => print_endline(string_of_float(i)) -let print_string = print_endline - -/* Miscellaneous */ - -external sys_exit: int => 'a = "?sys_exit" - -let exit_function = ref(ignore) - -let at_exit = f => { - let g = exit_function.contents - exit_function := - ( - () => { - f() - g() - } - ) -} - -let do_at_exit = () => exit_function.contents() - -let exit = retcode => { - do_at_exit() - sys_exit(retcode) -} - -type int32 = int diff --git a/jscomp/stdlib-406/pervasives.resi b/jscomp/stdlib-406/pervasives.resi deleted file mode 100644 index ecc6f5e13d..0000000000 --- a/jscomp/stdlib-406/pervasives.resi +++ /dev/null @@ -1,747 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/*** The initially opened module. - - This module provides the basic operations over the built-in types - (numbers, booleans, byte sequences, strings, exceptions, references, - lists, arrays, input-output channels, ...). - - This module is automatically opened at the beginning of each compilation. - All components of this module can therefore be referred by their short - name, without prefixing them by [Pervasives]. -*/ - -/* Internal */ -external __unsafe_cast: 'a => 'b = "%identity" -/* 1 Exceptions} */ - -/** Raise the given exception value */ -external raise: exn => 'a = "%raise" - -/** A faster version [raise] which does not record the backtrace. - @since 4.02.0 -*/ -external raise_notrace: exn => 'a = "%raise_notrace" - -/** Raise exception [Invalid_argument] with the given string. */ -let invalid_arg: string => 'a - -/** Raise exception [Failure] with the given string. */ -let failwith: string => 'a - -/** The [Exit] exception is not raised by any library function. It is - provided for use in your programs. */ -exception Exit - -/* {1 Comparisons} */ - -/** [e1 = e2] tests for structural equality of [e1] and [e2]. - Mutable structures (e.g. references and arrays) are equal - if and only if their current contents are structurally equal, - even if the two mutable objects are not the same physical object. - Equality between functional values raises [Invalid_argument]. - Equality between cyclic data structures may not terminate. - Left-associative operator at precedence level 4/11. */ -external \"=": ('a, 'a) => bool = "%equal" - -/** Negation of {!Pervasives.( = )}. - Left-associative operator at precedence level 4/11. */ -external \"<>": ('a, 'a) => bool = "%notequal" - -/** See {!Pervasives.( >= )}. - Left-associative operator at precedence level 4/11. */ -external \"<": ('a, 'a) => bool = "%lessthan" - -/** See {!Pervasives.( >= )}. - Left-associative operator at precedence level 4/11. */ -external \">": ('a, 'a) => bool = "%greaterthan" - -/** See {!Pervasives.( >= )}. - Left-associative operator at precedence level 4/11. */ -external \"<=": ('a, 'a) => bool = "%lessequal" - -/** Structural ordering functions. These functions coincide with - the usual orderings over integers, characters, strings, byte sequences - and floating-point numbers, and extend them to a - total ordering over all types. - The ordering is compatible with [( = )]. As in the case - of [( = )], mutable structures are compared by contents. - Comparison between functional values raises [Invalid_argument]. - Comparison between cyclic structures may not terminate. - Left-associative operator at precedence level 4/11. */ -external \">=": ('a, 'a) => bool = "%greaterequal" - -/** [compare x y] returns [0] if [x] is equal to [y], - a negative integer if [x] is less than [y], and a positive integer - if [x] is greater than [y]. The ordering implemented by [compare] - is compatible with the comparison predicates [=], [<] and [>] - defined above, with one difference on the treatment of the float value - {!Pervasives.nan}. Namely, the comparison predicates treat [nan] - as different from any other float value, including itself; - while [compare] treats [nan] as equal to itself and less than any - other float value. This treatment of [nan] ensures that [compare] - defines a total ordering relation. - - [compare] applied to functional values may raise [Invalid_argument]. - [compare] applied to cyclic structures may not terminate. - - The [compare] function can be used as the comparison function - required by the {!Set.Make} and {!Map.Make} functors, as well as - the {!List.sort} and {!Array.sort} functions. */ -external compare: ('a, 'a) => int = "%compare" - -/** Return the smaller of the two arguments. - The result is unspecified if one of the arguments contains - the float value [nan]. */ -external min: ('a, 'a) => 'a = "%bs_min" - -/** Return the greater of the two arguments. - The result is unspecified if one of the arguments contains - the float value [nan]. */ -external max: ('a, 'a) => 'a = "%bs_max" - -/** [e1 == e2] tests for physical equality of [e1] and [e2]. - On mutable types such as references, arrays, byte sequences, records with - mutable fields and objects with mutable instance variables, - [e1 == e2] is true if and only if physical modification of [e1] - also affects [e2]. - On non-mutable types, the behavior of [( == )] is - implementation-dependent; however, it is guaranteed that - [e1 == e2] implies [compare e1 e2 = 0]. - Left-associative operator at precedence level 4/11. */ -external \"==": ('a, 'a) => bool = "%eq" - -/** Negation of {!Pervasives.( == )}. - Left-associative operator at precedence level 4/11. */ -external \"!=": ('a, 'a) => bool = "%noteq" - -/* {1 Boolean operations} */ - -/** The boolean negation. */ -external not: bool => bool = "%boolnot" - -/** The boolean 'and'. Evaluation is sequential, left-to-right: - in [e1 && e2], [e1] is evaluated first, and if it returns [false], - [e2] is not evaluated at all. - Right-associative operator at precedence level 3/11. */ -external \"&&": (bool, bool) => bool = "%sequand" - -/** The boolean 'or'. Evaluation is sequential, left-to-right: - in [e1 || e2], [e1] is evaluated first, and if it returns [true], - [e2] is not evaluated at all. - Right-associative operator at precedence level 2/11. -*/ -external \"||": (bool, bool) => bool = "%sequor" - -/* {1 Debugging} */ - -/** [__LOC__] returns the location at which this expression appears in - the file currently being parsed by the compiler, with the standard - error format of OCaml: "File %S, line %d, characters %d-%d". - @since 4.02.0 -*/ -external __LOC__: string = "%loc_LOC" - -/** [__FILE__] returns the name of the file currently being - parsed by the compiler. - @since 4.02.0 -*/ -external __FILE__: string = "%loc_FILE" - -/** [__LINE__] returns the line number at which this expression - appears in the file currently being parsed by the compiler. - @since 4.02.0 -*/ -external __LINE__: int = "%loc_LINE" - -/** [__MODULE__] returns the module name of the file being - parsed by the compiler. - @since 4.02.0 -*/ -external __MODULE__: string = "%loc_MODULE" - -/** [__POS__] returns a tuple [(file,lnum,cnum,enum)], corresponding - to the location at which this expression appears in the file - currently being parsed by the compiler. [file] is the current - filename, [lnum] the line number, [cnum] the character position in - the line and [enum] the last character position in the line. - @since 4.02.0 - */ -external __POS__: (string, int, int, int) = "%loc_POS" - -/** [__LOC_OF__ expr] returns a pair [(loc, expr)] where [loc] is the - location of [expr] in the file currently being parsed by the - compiler, with the standard error format of OCaml: "File %S, line - %d, characters %d-%d". - @since 4.02.0 -*/ -external __LOC_OF__: 'a => (string, 'a) = "%loc_LOC" - -/** [__LINE__ expr] returns a pair [(line, expr)], where [line] is the - line number at which the expression [expr] appears in the file - currently being parsed by the compiler. - @since 4.02.0 - */ -external __LINE_OF__: 'a => (int, 'a) = "%loc_LINE" - -/** [__POS_OF__ expr] returns a pair [(loc,expr)], where [loc] is a - tuple [(file,lnum,cnum,enum)] corresponding to the location at - which the expression [expr] appears in the file currently being - parsed by the compiler. [file] is the current filename, [lnum] the - line number, [cnum] the character position in the line and [enum] - the last character position in the line. - @since 4.02.0 - */ -external __POS_OF__: 'a => ((string, int, int, int), 'a) = "%loc_POS" - -/* {1 Composition operators} */ - -/** Reverse-application operator: [x |> f |> g] is exactly equivalent - to [g (f (x))]. - Left-associative operator at precedence level 4/11. - @since 4.01 - */ -external \"|>": ('a, 'a => 'b) => 'b = "%revapply" - -/** Application operator: [g @@ f @@ x] is exactly equivalent to - [g (f (x))]. - Right-associative operator at precedence level 5/11. - @since 4.01 -*/ -external \"@@": ('a => 'b, 'a) => 'b = "%apply" - -/* {1 Integer arithmetic} */ - -/* Integers are 31 bits wide (or 63 bits on 64-bit processors). - All operations are taken modulo 2{^31} (or 2{^63}). - They do not fail on overflow. */ - -/** Unary negation. You can also write [- e] instead of [~- e]. - Unary operator at precedence level 9/11 for [- e] - and 11/11 for [~- e]. */ -external \"~-": int => int = "%negint" - -/** Unary addition. You can also write [+ e] instead of [~+ e]. - Unary operator at precedence level 9/11 for [+ e] - and 11/11 for [~+ e]. - @since 3.12.0 -*/ -external \"~+": int => int = "%identity" - -/** [succ x] is [x + 1]. */ -external succ: int => int = "%succint" - -/** [pred x] is [x - 1]. */ -external pred: int => int = "%predint" - -/** Integer addition. - Left-associative operator at precedence level 6/11. */ -external \"+": (int, int) => int = "%addint" - -/** Integer subtraction. - Left-associative operator at precedence level 6/11. */ -external \"-": (int, int) => int = "%subint" - -/** Integer multiplication. - Left-associative operator at precedence level 7/11. */ -external \"*": (int, int) => int = "%mulint" - -/** Integer division. - Raise [Division_by_zero] if the second argument is 0. - Integer division rounds the real quotient of its arguments towards zero. - More precisely, if [x >= 0] and [y > 0], [x / y] is the greatest integer - less than or equal to the real quotient of [x] by [y]. Moreover, - [(- x) / y = x / (- y) = - (x / y)]. - Left-associative operator at precedence level 7/11. */ -external \"/": (int, int) => int = "%divint" - -/** Integer remainder. If [y] is not zero, the result - of [x mod y] satisfies the following properties: - [x = (x / y) * y + x mod y] and - [abs(x mod y) <= abs(y) - 1]. - If [y = 0], [x mod y] raises [Division_by_zero]. - Note that [x mod y] is negative only if [x < 0]. - Raise [Division_by_zero] if [y] is zero. - Left-associative operator at precedence level 7/11. */ -external mod: (int, int) => int = "%modint" - -/** Return the absolute value of the argument. Note that this may be - negative if the argument is [min_int]. */ -let abs: int => int - -/** The greatest representable integer. */ -let max_int: int - -/** The smallest representable integer. */ -let min_int: int - -/* {2 Bitwise operations} */ - -/** Bitwise logical and. - Left-associative operator at precedence level 7/11. */ -external land: (int, int) => int = "%andint" - -/** Bitwise logical or. - Left-associative operator at precedence level 7/11. */ -external lor: (int, int) => int = "%orint" - -/** Bitwise logical exclusive or. - Left-associative operator at precedence level 7/11. */ -external lxor: (int, int) => int = "%xorint" - -/** Bitwise logical negation. */ -let lnot: int => int - -/** [n lsl m] shifts [n] to the left by [m] bits. - The result is unspecified if [m < 0] or [m >= bitsize], - where [bitsize] is [32] on a 32-bit platform and - [64] on a 64-bit platform. - Right-associative operator at precedence level 8/11. */ -external lsl: (int, int) => int = "%lslint" - -/** [n lsr m] shifts [n] to the right by [m] bits. - This is a logical shift: zeroes are inserted regardless of - the sign of [n]. - The result is unspecified if [m < 0] or [m >= bitsize]. - Right-associative operator at precedence level 8/11. */ -external lsr: (int, int) => int = "%lsrint" - -/** [n asr m] shifts [n] to the right by [m] bits. - This is an arithmetic shift: the sign bit of [n] is replicated. - The result is unspecified if [m < 0] or [m >= bitsize]. - Right-associative operator at precedence level 8/11. */ -external asr: (int, int) => int = "%asrint" - -/* {1 Floating-point arithmetic} - - OCaml's floating-point numbers follow the - IEEE 754 standard, using double precision (64 bits) numbers. - Floating-point operations never raise an exception on overflow, - underflow, division by zero, etc. Instead, special IEEE numbers - are returned as appropriate, such as [infinity] for [1.0 /. 0.0], - [neg_infinity] for [-1.0 /. 0.0], and [nan] ('not a number') - for [0.0 /. 0.0]. These special numbers then propagate through - floating-point computations as expected: for instance, - [1.0 /. infinity] is [0.0], and any arithmetic operation with [nan] - as argument returns [nan] as result. -*/ - -/** Unary negation. You can also write [-. e] instead of [~-. e]. - Unary operator at precedence level 9/11 for [-. e] - and 11/11 for [~-. e]. */ -external \"~-.": float => float = "%negfloat" - -/** Unary addition. You can also write [+. e] instead of [~+. e]. - Unary operator at precedence level 9/11 for [+. e] - and 11/11 for [~+. e]. - @since 3.12.0 -*/ -external \"~+.": float => float = "%identity" - -/** Floating-point addition. - Left-associative operator at precedence level 6/11. */ -external \"+.": (float, float) => float = "%addfloat" - -/** Floating-point subtraction. - Left-associative operator at precedence level 6/11. */ -external \"-.": (float, float) => float = "%subfloat" - -/** Floating-point multiplication. - Left-associative operator at precedence level 7/11. */ -external \"*.": (float, float) => float = "%mulfloat" - -/** Floating-point division. - Left-associative operator at precedence level 7/11. */ -external \"/.": (float, float) => float = "%divfloat" - -@val @scope("Math") /** Exponentiation. */ -external \"**": (float, float) => float = "pow" - -@val @scope("Math") /** Square root. */ -external sqrt: float => float = "sqrt" - -@val @scope("Math") /** Exponential. */ -external exp: float => float = "exp" - -@val @scope("Math") /** Natural logarithm. */ -external log: float => float = "log" - -@val @scope("Math") /** Base 10 logarithm. */ -external log10: float => float = "log10" - -/** [expm1 x] computes [exp x -. 1.0], giving numerically-accurate results - even if [x] is close to [0.0]. - @since 3.12.0 -*/ -external expm1: float => float = "?expm1_float" - -@val -@scope("Math") -/** [log1p x] computes [log(1.0 +. x)] (natural logarithm), - giving numerically-accurate results even if [x] is close to [0.0]. - @since 3.12.0 -*/ -external log1p: float => float = "log1p" - -@val @scope("Math") /** Cosine. Argument is in radians. */ -external cos: float => float = "cos" - -@val @scope("Math") /** Sine. Argument is in radians. */ -external sin: float => float = "sin" - -@val @scope("Math") /** Tangent. Argument is in radians. */ -external tan: float => float = "tan" - -@val -@scope("Math") -/** Arc cosine. The argument must fall within the range [[-1.0, 1.0]]. - Result is in radians and is between [0.0] and [pi]. */ -external acos: float => float = "acos" - -@val -@scope("Math") -/** Arc sine. The argument must fall within the range [[-1.0, 1.0]]. - Result is in radians and is between [-pi/2] and [pi/2]. */ -external asin: float => float = "asin" - -@val @scope("Math") /** Arc tangent. - Result is in radians and is between [-pi/2] and [pi/2]. */ -external atan: float => float = "atan" - -@val -@scope("Math") -/** [atan2 y x] returns the arc tangent of [y /. x]. The signs of [x] - and [y] are used to determine the quadrant of the result. - Result is in radians and is between [-pi] and [pi]. */ -external atan2: (float, float) => float = "atan2" - -/** [hypot x y] returns [sqrt(x *. x + y *. y)], that is, the length - of the hypotenuse of a right-angled triangle with sides of length - [x] and [y], or, equivalently, the distance of the point [(x,y)] - to origin. - @since 4.00.0 */ -external hypot: (float, float) => float = "?hypot_float" - -@val @scope("Math") /** Hyperbolic cosine. Argument is in radians. */ -external cosh: float => float = "cosh" - -@val @scope("Math") /** Hyperbolic sine. Argument is in radians. */ -external sinh: float => float = "sinh" - -@val @scope("Math") /** Hyperbolic tangent. Argument is in radians. */ -external tanh: float => float = "tanh" - -@val -@scope("Math") -/** Round above to an integer value. - [ceil f] returns the least integer value greater than or equal to [f]. - The result is returned as a float. */ -external ceil: float => float = "ceil" - -@val -@scope("Math") -/** Round below to an integer value. - [floor f] returns the greatest integer value less than or - equal to [f]. - The result is returned as a float. */ -external floor: float => float = "floor" - -@val @scope("Math") /** [abs_float f] returns the absolute value of [f]. */ -external abs_float: float => float = "abs" - -/** [copysign x y] returns a float whose absolute value is that of [x] - and whose sign is that of [y]. If [x] is [nan], returns [nan]. - If [y] is [nan], returns either [x] or [-. x], but it is not - specified which. - @since 4.00.0 */ -external copysign: (float, float) => float = "?copysign_float" - -/** [mod_float a b] returns the remainder of [a] with respect to - [b]. The returned value is [a -. n *. b], where [n] - is the quotient [a /. b] rounded towards zero to an integer. */ -external mod_float: (float, float) => float = "?fmod_float" - -/** [frexp f] returns the pair of the significant - and the exponent of [f]. When [f] is zero, the - significant [x] and the exponent [n] of [f] are equal to - zero. When [f] is non-zero, they are defined by - [f = x *. 2 ** n] and [0.5 <= x < 1.0]. */ -external frexp: float => (float, int) = "?frexp_float" - -/** [ldexp x n] returns [x *. 2 ** n]. */ -external ldexp: (float, int) => float = "?ldexp_float" - -/** [modf f] returns the pair of the fractional and integral - part of [f]. */ -external modf: float => (float, float) = "?modf_float" - -/** Same as {!Pervasives.float_of_int}. */ -external float: int => float = "%floatofint" - -/** Convert an integer to floating-point. */ -external float_of_int: int => float = "%floatofint" - -/** Same as {!Pervasives.int_of_float}. */ -external truncate: float => int = "%intoffloat" - -/** Truncate the given floating-point number to an integer. - The result is unspecified if the argument is [nan] or falls outside the - range of representable integers. */ -external int_of_float: float => int = "%intoffloat" - -/** Positive infinity. */ -let infinity: float - -/** Negative infinity. */ -let neg_infinity: float - -@val -@scope("Number") -/** A special floating-point value denoting the result of an - undefined operation such as [0.0 /. 0.0]. Stands for - 'not a number'. Any floating-point operation with [nan] as - argument returns [nan] as result. As for floating-point comparisons, - [=], [<], [<=], [>] and [>=] return [false] and [<>] returns [true] - if one or both of their arguments is [nan]. */ -external nan: float = "NaN" -/* we could also use [0. /. 0.] */ - -/** The largest positive finite value of type [float]. */ -let max_float: float - -/** The smallest positive, non-zero, non-denormalized value of type [float]. */ -let min_float: float - -/** The difference between [1.0] and the smallest exactly representable - floating-point number greater than [1.0]. */ -let epsilon_float: float - -/** The five classes of floating-point numbers, as determined by - the {!Pervasives.classify_float} function. */ -type fpclass = - | /** Normal number, none of the below */ FP_normal - | /** Number very close to 0.0, has reduced precision */ FP_subnormal - | /** Number is 0.0 or -0.0 */ FP_zero - | /** Number is positive or negative infinity */ FP_infinite - | /** Not a number: result of an undefined operation */ FP_nan - -/** Return the class of the given floating-point number: - normal, subnormal, zero, infinite, or not a number. */ -let classify_float: float => fpclass - -/** {1 String operations} - - More string operations are provided in module {!String}. -*/ -/** String concatenation. - Right-associative operator at precedence level 5/11. */ -external \"^": (string, string) => string = "#string_append" - -/* {1 Character operations} - - More character operations are provided in module {!Char}. -*/ - -/** Return the ASCII code of the argument. */ -external int_of_char: char => int = "%identity" - -/** Return the character with the given ASCII code. - Raise [Invalid_argument "char_of_int"] if the argument is - outside the range 0--255. */ -let char_of_int: int => char - -/* {1 Unit operations} */ - -/** Discard the value of its argument and return [()]. - For instance, [ignore(f x)] discards the result of - the side-effecting function [f]. It is equivalent to - [f x; ()], except that the latter may generate a - compiler warning; writing [ignore(f x)] instead - avoids the warning. */ -external ignore: 'a => unit = "%ignore" - -/* {1 String conversion functions} */ - -/** Return the string representation of a boolean. As the returned values - may be shared, the user should not modify them directly. -*/ -let string_of_bool: bool => string - -/** Convert the given string to a boolean. - Raise [Invalid_argument "bool_of_string"] if the string is not - ["true"] or ["false"]. */ -let bool_of_string: string => bool - -/** Convert the given string to a boolean. - Return [None] if the string is not - ["true"] or ["false"]. - @since 4.05 -*/ -let bool_of_string_opt: string => option - -@val /** Return the string representation of an integer, in decimal. */ -external string_of_int: int => string = "String" - -/** Convert the given string to an integer. - The string is read in decimal (by default, or if the string - begins with [0u]), in hexadecimal (if it begins with [0x] or - [0X]), in octal (if it begins with [0o] or [0O]), or in binary - (if it begins with [0b] or [0B]). - - The [0u] prefix reads the input as an unsigned integer in the range - [[0, 2*max_int+1]]. If the input exceeds {!max_int} - it is converted to the signed integer - [min_int + input - max_int - 1]. - - The [_] (underscore) character can appear anywhere in the string - and is ignored. - Raise [Failure "int_of_string"] if the given string is not - a valid representation of an integer, or if the integer represented - exceeds the range of integers representable in type [int]. */ -external int_of_string: string => int = "?int_of_string" - -/** Same as [int_of_string], but returns [None] instead of raising. - @since 4.05 -*/ -let int_of_string_opt: string => option - -@deprecated("Please use Js.Float.toString instead, string_of_float generates unparseable floats") -/** Return the string representation of a floating-point number. */ -let string_of_float: float => string - -/** Convert the given string to a float. The string is read in decimal - (by default) or in hexadecimal (marked by [0x] or [0X]). - The format of decimal floating-point numbers is - [ [-] dd.ddd (e|E) [+|-] dd ], where [d] stands for a decimal digit. - The format of hexadecimal floating-point numbers is - [ [-] 0(x|X) hh.hhh (p|P) [+|-] dd ], where [h] stands for an - hexadecimal digit and [d] for a decimal digit. - In both cases, at least one of the integer and fractional parts must be - given; the exponent part is optional. - The [_] (underscore) character can appear anywhere in the string - and is ignored. - Depending on the execution platforms, other representations of - floating-point numbers can be accepted, but should not be relied upon. - Raise [Failure "float_of_string"] if the given string is not a valid - representation of a float. */ -external float_of_string: string => float = "?float_of_string" - -/** Same as [float_of_string], but returns [None] instead of raising. - @since 4.05 -*/ -let float_of_string_opt: string => option - -/* {1 Pair operations} */ - -/** Return the first component of a pair. */ -external fst: (('a, 'b)) => 'a = "%field0" - -/** Return the second component of a pair. */ -external snd: (('a, 'b)) => 'b = "%field1" - -/* {1 List operations} - - More list operations are provided in module {!List}. -*/ - -@deprecated("Use Belt.List.concat instead") -/** List concatenation. Tail-recursive (length of the first argument). - Right-associative operator at precedence level 5/11. */ -let \"@": (list<'a>, list<'a>) => list<'a> - -type int32 = int - -/** Print a string on standard output. */ -let print_string: string => unit - -/** Print an integer, in decimal, on standard output. */ -let print_int: int => unit - -/** Print a floating-point number, in decimal, on standard output. */ -let print_float: float => unit - -/** Print a floating-point number, in decimal, on standard output. */ -@val -@scope("console") -/** Print a string, followed by a newline character, on - standard output and flush standard output. */ -external print_endline: string => unit = "log" - -/** Print a newline character on standard output, and flush - standard output. This can be used to simulate line - buffering of standard output. */ -let print_newline: unit => unit - -@val -@scope("console") -/** Print a string, followed by a newline character on standard - error and flush standard error. */ -external prerr_endline: string => unit = "error" - -/** Print a newline character on standard error, and flush - standard error. */ -let prerr_newline: unit => unit - -/* {1 References} */ - -/** The type of references (mutable indirection cells) containing - a value of type ['a]. */ -type ref<'a> = {mutable contents: 'a} - -/** Return a fresh reference containing the given value. */ -external ref: 'a => ref<'a> = "%makemutable" - -/** [!r] returns the current contents of reference [r]. - Equivalent to [fun r -> r.contents]. - Unary operator at precedence level 11/11.*/ -external \"!": ref<'a> => 'a = "%bs_ref_field0" - -/** [r := a] stores the value of [a] in reference [r]. - Equivalent to [fun r v -> r.contents <- v]. - Right-associative operator at precedence level 1/11. */ -external \":=": (ref<'a>, 'a) => unit = "%bs_ref_setfield0" - -/** Increment the integer contained in the given reference. - Equivalent to [fun r -> r := succ !r]. */ -external incr: ref => unit = "%incr" - -/** Decrement the integer contained in the given reference. - Equivalent to [fun r -> r := pred !r]. */ -external decr: ref => unit = "%decr" - -/* {1 Program termination} */ - -/** Terminate the process, returning the given status code - to the operating system: usually 0 to indicate no errors, - and a small positive integer to indicate failure. - All open output channels are flushed with [flush_all]. - An implicit [exit 0] is performed each time a program - terminates normally. An implicit [exit 2] is performed if the program - terminates early because of an uncaught exception. */ -let exit: int => 'a - -/** Register the given function to be called at program termination - time. The functions registered with [at_exit] will be called when - the program does any of the following: - - executes {!Pervasives.exit} - - terminates, either normally or because of an uncaught - exception - - executes the C function [caml_shutdown]. - The functions are called in 'last in, first out' order: the - function most recently added with [at_exit] is called first. */ -let at_exit: (unit => unit) => unit - -let valid_float_lexem: string => string diff --git a/jscomp/stdlib-406/queue.res b/jscomp/stdlib-406/queue.res deleted file mode 100644 index 89d9297229..0000000000 --- a/jscomp/stdlib-406/queue.res +++ /dev/null @@ -1,142 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Francois Pottier, projet Cristal, INRIA Rocquencourt */ -/* Jeremie Dimino, Jane Street Europe */ -/* */ -/* Copyright 2002 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. */ -/* */ -/* ************************************************************************ */ - -exception Empty - -type rec cell<'a> = - | Nil - | Cons({content: 'a, mutable next: cell<'a>}) - -type t<'a> = { - mutable length: int, - mutable first: cell<'a>, - mutable last: cell<'a>, -} - -let create = () => { - length: 0, - first: Nil, - last: Nil, -} - -let clear = q => { - q.length = 0 - q.first = Nil - q.last = Nil -} - -let add = (x, q) => { - let cell = Cons({ - content: x, - next: Nil, - }) - switch q.last { - | Nil => - q.length = 1 - q.first = cell - q.last = cell - | Cons(last) => - q.length = q.length + 1 - last.next = cell - q.last = cell - } -} - -let push = add - -let peek = q => - switch q.first { - | Nil => raise(Empty) - | Cons({content}) => content - } - -let top = peek - -let take = q => - switch q.first { - | Nil => raise(Empty) - | Cons({content, next: Nil}) => - clear(q) - content - | Cons({content, next}) => - q.length = q.length - 1 - q.first = next - content - } - -let pop = take - -let copy = { - let rec copy = (q_res, prev, cell) => - switch cell { - | Nil => - q_res.last = prev - q_res - | Cons({content, next}) => - let res = Cons({content, next: Nil}) - switch prev { - | Nil => q_res.first = res - | Cons(p) => p.next = res - } - copy(q_res, res, next) - } - - q => copy({length: q.length, first: Nil, last: Nil}, Nil, q.first) -} - -let is_empty = q => q.length == 0 - -let length = q => q.length - -let iter = { - let rec iter = (f, cell) => - switch cell { - | Nil => () - | Cons({content, next}) => - f(content) - iter(f, next) - } - - (f, q) => iter(f, q.first) -} - -let fold = { - let rec fold = (f, accu, cell) => - switch cell { - | Nil => accu - | Cons({content, next}) => - let accu = f(accu, content) - fold(f, accu, next) - } - - (f, accu, q) => fold(f, accu, q.first) -} - -let transfer = (q1, q2) => - if q1.length > 0 { - switch q2.last { - | Nil => - q2.length = q1.length - q2.first = q1.first - q2.last = q1.last - clear(q1) - | Cons(last) => - q2.length = q2.length + q1.length - last.next = q1.first - q2.last = q1.last - clear(q1) - } - } diff --git a/jscomp/stdlib-406/queue.resi b/jscomp/stdlib-406/queue.resi deleted file mode 100644 index c5ed5ae64b..0000000000 --- a/jscomp/stdlib-406/queue.resi +++ /dev/null @@ -1,79 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/*** First-in first-out queues. - - This module implements queues (FIFOs), with in-place modification. - - {b Warning} This module is not thread-safe: each {!Queue.t} value - must be protected from concurrent access (e.g. with a [Mutex.t]). - Failure to do so can lead to a crash. -*/ - -/** The type of queues containing elements of type ['a]. */ -type t<'a> - -/** Raised when {!Queue.take} or {!Queue.peek} is applied to an empty queue. */ exception Empty - -/** Return a new queue, initially empty. */ -let create: unit => t<'a> - -/** [add x q] adds the element [x] at the end of the queue [q]. */ -let add: ('a, t<'a>) => unit - -/** [push] is a synonym for [add]. */ -let push: ('a, t<'a>) => unit - -/** [take q] removes and returns the first element in queue [q], - or raises {!Empty} if the queue is empty. */ -let take: t<'a> => 'a - -/** [pop] is a synonym for [take]. */ -let pop: t<'a> => 'a - -/** [peek q] returns the first element in queue [q], without removing - it from the queue, or raises {!Empty} if the queue is empty. */ -let peek: t<'a> => 'a - -/** [top] is a synonym for [peek]. */ -let top: t<'a> => 'a - -/** Discard all elements from a queue. */ -let clear: t<'a> => unit - -/** Return a copy of the given queue. */ -let copy: t<'a> => t<'a> - -/** Return [true] if the given queue is empty, [false] otherwise. */ -let is_empty: t<'a> => bool - -/** Return the number of elements in a queue. */ -let length: t<'a> => int - -/** [iter f q] applies [f] in turn to all elements of [q], - from the least recently entered to the most recently entered. - The queue itself is unchanged. */ -let iter: ('a => unit, t<'a>) => unit - -/** [fold f accu q] is equivalent to [List.fold_left f accu l], - where [l] is the list of [q]'s elements. The queue remains - unchanged. */ -let fold: (('b, 'a) => 'b, 'b, t<'a>) => 'b - -/** [transfer q1 q2] adds all of [q1]'s elements at the end of - the queue [q2], then clears [q1]. It is equivalent to the - sequence [iter (fun x -> add x q2) q1; clear q1], but runs - in constant time. */ -let transfer: (t<'a>, t<'a>) => unit diff --git a/jscomp/stdlib-406/random.res b/jscomp/stdlib-406/random.res deleted file mode 100644 index 11b4e42f4d..0000000000 --- a/jscomp/stdlib-406/random.res +++ /dev/null @@ -1,336 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Damien Doligez, projet Para, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/* Pseudo-random number generator - This is a lagged-Fibonacci F(55, 24, +) with a modified addition - function to enhance the mixing of bits. - If we use normal addition, the low-order bit fails tests 1 and 7 - of the Diehard test suite, and bits 1 and 2 also fail test 7. - If we use multiplication as suggested by Marsaglia, it doesn't fare - much better. - By mixing the bits of one of the numbers before addition (XOR the - 5 high-order bits into the low-order bits), we get a generator that - passes all the Diehard tests. -*/ - -let random_seed: unit => array = _ => { - let seed: int = %raw("Math.floor(Math.random()*0x7fffffff)") - [seed] -} - -module State = { - type t = {st: array, mutable idx: int} - - let new_state = () => {st: Array.make(55, 0), idx: 0} - let assign = (st1, st2) => { - Array.blit(st2.st, 0, st1.st, 0, 55) - st1.idx = st2.idx - } - - let full_init = (s, seed) => { - let combine = (accu, x) => Digest.string(accu ++ string_of_int(x)) - let extract = d => - Char.code(String.get(d, 0)) + - lsl(Char.code(String.get(d, 1)), 8) + - lsl(Char.code(String.get(d, 2)), 16) + - lsl(Char.code(String.get(d, 3)), 24) - - let seed = if Array.length(seed) == 0 { - [0] - } else { - seed - } - let l = Array.length(seed) - for i in 0 to 54 { - s.st[i] = i - } - let accu = ref("x") - for i in 0 to 54 + max(55, l) { - let j = mod(i, 55) - let k = mod(i, l) - accu := combine(accu.contents, seed[k]) - s.st[j] = land(lxor(s.st[j], extract(accu.contents)), 0x3FFFFFFF) /* PR#5575 */ - } - s.idx = 0 - } - - let make = seed => { - let result = new_state() - full_init(result, seed) - result - } - - let make_self_init = () => make(random_seed()) - - let copy = s => { - let result = new_state() - assign(result, s) - result - } - - /* Returns 30 random bits as an integer 0 <= x < 1073741824 */ - let bits = s => { - s.idx = mod(s.idx + 1, 55) - let curval = s.st[s.idx] - let newval = s.st[mod(s.idx + 24, 55)] + lxor(curval, land(lsr(curval, 25), 0x1F)) - let newval30 = land(newval, 0x3FFFFFFF) /* PR#5575 */ - s.st[s.idx] = newval30 - newval30 - } - - let rec intaux = (s, n) => { - let r = bits(s) - let v = mod(r, n) - if r - v > 0x3FFFFFFF - n + 1 { - intaux(s, n) - } else { - v - } - } - - let int = (s, bound) => - if bound > 0x3FFFFFFF || bound <= 0 { - invalid_arg("Random.int") - } else { - intaux(s, bound) - } - - let rec int32aux = (s, n) => { - let b1 = Int32.of_int(bits(s)) - let b2 = Int32.shift_left(Int32.of_int(land(bits(s), 1)), 30) - let r = Int32.logor(b1, b2) - let v = Int32.rem(r, n) - if Int32.sub(r, v) > Int32.add(Int32.sub(Int32.max_int, n), 1l) { - int32aux(s, n) - } else { - v - } - } - - let int32 = (s, bound) => - if bound <= 0l { - invalid_arg("Random.int32") - } else { - int32aux(s, bound) - } - - let rec int64aux = (s, n) => { - let b1 = Int64.of_int(bits(s)) - let b2 = Int64.shift_left(Int64.of_int(bits(s)), 30) - let b3 = Int64.shift_left(Int64.of_int(land(bits(s), 7)), 60) - let r = Int64.logor(b1, Int64.logor(b2, b3)) - let v = Int64.rem(r, n) - if Int64.sub(r, v) > Int64.add(Int64.sub(Int64.max_int, n), 1L) { - int64aux(s, n) - } else { - v - } - } - - let int64 = (s, bound) => - if bound <= 0L { - invalid_arg("Random.int64") - } else { - int64aux(s, bound) - } - - /* Returns a float 0 <= x <= 1 with at most 60 bits of precision. */ - let rawfloat = s => { - let scale = 1073741824.0 /* 2^30 */ - and r1 = Pervasives.float(bits(s)) - and r2 = Pervasives.float(bits(s)) - (r1 /. scale +. r2) /. scale - } - - let float = (s, bound) => rawfloat(s) *. bound - - let bool = s => land(bits(s), 1) == 0 -} - -/* This is the state you get with [init 27182818] and then applying - the "land 0x3FFFFFFF" filter to them. See #5575, #5793, #5977. */ -let default = { - State.st: [ - 0x3ae2522b, - 0x1d8d4634, - 0x15b4fad0, - 0x18b14ace, - 0x12f8a3c4, - 0x3b086c47, - 0x16d467d6, - 0x101d91c7, - 0x321df177, - 0x0176c193, - 0x1ff72bf1, - 0x1e889109, - 0x0b464b18, - 0x2b86b97c, - 0x0891da48, - 0x03137463, - 0x085ac5a1, - 0x15d61f2f, - 0x3bced359, - 0x29c1c132, - 0x3a86766e, - 0x366d8c86, - 0x1f5b6222, - 0x3ce1b59f, - 0x2ebf78e1, - 0x27cd1b86, - 0x258f3dc3, - 0x389a8194, - 0x02e4c44c, - 0x18c43f7d, - 0x0f6e534f, - 0x1e7df359, - 0x055d0b7e, - 0x10e84e7e, - 0x126198e4, - 0x0e7722cb, - 0x1cbede28, - 0x3391b964, - 0x3d40e92a, - 0x0c59933d, - 0x0b8cd0b7, - 0x24efff1c, - 0x2803fdaa, - 0x08ebc72e, - 0x0f522e32, - 0x05398edc, - 0x2144a04c, - 0x0aef3cbd, - 0x01ad4719, - 0x35b93cd6, - 0x2a559d4f, - 0x1e6fd768, - 0x26e27f36, - 0x186f18c3, - 0x2fbf967a, - ], - State.idx: 0, -} - -let bits = () => State.bits(default) -let int = bound => State.int(default, bound) -let int32 = bound => State.int32(default, bound) - -let int64 = bound => State.int64(default, bound) -let float = scale => State.float(default, scale) -let bool = () => State.bool(default) - -let full_init = seed => State.full_init(default, seed) -let init = seed => State.full_init(default, [seed]) -let self_init = () => full_init(random_seed()) - -/* Manipulating the current state. */ - -let get_state = () => State.copy(default) -let set_state = s => State.assign(default, s) - -/* ******************* - -(* Test functions. Not included in the library. - The [chisquare] function should be called with n > 10r. - It returns a triple (low, actual, high). - If low <= actual <= high, the [g] function passed the test, - otherwise it failed. - - Some results: - -init 27182818; chisquare int 100000 1000 -init 27182818; chisquare int 100000 100 -init 27182818; chisquare int 100000 5000 -init 27182818; chisquare int 1000000 1000 -init 27182818; chisquare int 100000 1024 -init 299792643; chisquare int 100000 1024 -init 14142136; chisquare int 100000 1024 -init 27182818; init_diff 1024; chisquare diff 100000 1024 -init 27182818; init_diff 100; chisquare diff 100000 100 -init 27182818; init_diff2 1024; chisquare diff2 100000 1024 -init 27182818; init_diff2 100; chisquare diff2 100000 100 -init 14142136; init_diff2 100; chisquare diff2 100000 100 -init 299792643; init_diff2 100; chisquare diff2 100000 100 -- : float * float * float = (936.754446796632465, 997.5, 1063.24555320336754) -# - : float * float * float = (80., 89.7400000000052387, 120.) -# - : float * float * float = (4858.57864376269, 5045.5, 5141.42135623731) -# - : float * float * float = -(936.754446796632465, 944.805999999982305, 1063.24555320336754) -# - : float * float * float = (960., 1019.19744000000355, 1088.) -# - : float * float * float = (960., 1059.31776000000536, 1088.) -# - : float * float * float = (960., 1039.98463999999512, 1088.) -# - : float * float * float = (960., 1054.38207999999577, 1088.) -# - : float * float * float = (80., 90.096000000005, 120.) -# - : float * float * float = (960., 1076.78720000000612, 1088.) -# - : float * float * float = (80., 85.1760000000067521, 120.) -# - : float * float * float = (80., 85.2160000000003492, 120.) -# - : float * float * float = (80., 80.6220000000030268, 120.) - -*) - -(* Return the sum of the squares of v[i0,i1[ *) -let rec sumsq v i0 i1 = - if i0 >= i1 then 0.0 - else if i1 = i0 + 1 then Pervasives.float v.(i0) *. Pervasives.float v.(i0) - else sumsq v i0 ((i0+i1)/2) +. sumsq v ((i0+i1)/2) i1 - - -let chisquare g n r = - if n <= 10 * r then invalid_arg "chisquare"; - let f = Array.make r 0 in - for i = 1 to n do - let t = g r in - f.(t) <- f.(t) + 1 - done; - let t = sumsq f 0 r - and r = Pervasives.float r - and n = Pervasives.float n in - let sr = 2.0 *. sqrt r in - (r -. sr, (r *. t /. n) -. n, r +. sr) - - -(* This is to test for linear dependencies between successive random numbers. -*) -let st = ref 0 -let init_diff r = st := int r -let diff r = - let x1 = !st - and x2 = int r - in - st := x2; - if x1 >= x2 then - x1 - x2 - else - r + x1 - x2 - - -let st1 = ref 0 -and st2 = ref 0 - - -(* This is to test for quadratic dependencies between successive random - numbers. -*) -let init_diff2 r = st1 := int r; st2 := int r -let diff2 r = - let x1 = !st1 - and x2 = !st2 - and x3 = int r - in - st1 := x2; - st2 := x3; - (x3 - x2 - x2 + x1 + 2*r) mod r - - -********************/ diff --git a/jscomp/stdlib-406/random.resi b/jscomp/stdlib-406/random.resi deleted file mode 100644 index 05624c98eb..0000000000 --- a/jscomp/stdlib-406/random.resi +++ /dev/null @@ -1,100 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Damien Doligez, projet Para, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/*** Pseudo-random number generators (PRNG). */ - -/* {1 Basic functions} */ - -/** Initialize the generator, using the argument as a seed. - The same seed will always yield the same sequence of numbers. */ -let init: int => unit - -/** Same as {!Random.init} but takes more data as seed. */ -let full_init: array => unit - -/** Initialize the generator with a random seed chosen - in a system-dependent way. If [/dev/urandom] is available on - the host machine, it is used to provide a highly random initial - seed. Otherwise, a less random seed is computed from system - parameters (current time, process IDs). */ -let self_init: unit => unit - -/** Return 30 random bits in a nonnegative integer. - @before 3.12.0 used a different algorithm (affects all the following - functions) -*/ -let bits: unit => int - -/** [Random.int bound] returns a random integer between 0 (inclusive) - and [bound] (exclusive). [bound] must be greater than 0 and less - than 2{^30}. */ -let int: int => int - -/** [Random.int32 bound] returns a random integer between 0 (inclusive) - and [bound] (exclusive). [bound] must be greater than 0. */ -let int32: Int32.t => Int32.t - -/** [Random.int64 bound] returns a random integer between 0 (inclusive) - and [bound] (exclusive). [bound] must be greater than 0. */ -let int64: Int64.t => Int64.t - -/** [Random.float bound] returns a random floating-point number - between 0 and [bound] (inclusive). If [bound] is - negative, the result is negative or zero. If [bound] is 0, - the result is 0. */ -let float: float => float - -/** [Random.bool ()] returns [true] or [false] with probability 0.5 each. */ -let bool: unit => bool - -/* {1 Advanced functions} */ - -module State: { - /*** The functions from module {!State} manipulate the current state - of the random generator explicitly. - This allows using one or several deterministic PRNGs, - even in a multi-threaded program, without interference from - other parts of the program. - */ - - /** The type of PRNG states. */ - type t - - /** Create a new state and initialize it with the given seed. */ - let make: array => t - - /** Create a new state and initialize it with a system-dependent - low-entropy seed. */ - let make_self_init: unit => t - - /** Return a copy of the given state. */ - let copy: t => t - - let bits: t => int - let int: (t, int) => int - let int32: (t, Int32.t) => Int32.t - let int64: (t, Int64.t) => Int64.t - let float: (t, float) => float - /** These functions are the same as the basic functions, except that they - use (and update) the given PRNG state instead of the default one. - */ - let bool: t => bool -} - -/** Return the current state of the generator used by the basic functions. */ -let get_state: unit => State.t - -/** Set the state of the generator used by the basic functions. */ -let set_state: State.t => unit diff --git a/jscomp/stdlib-406/release.ninja b/jscomp/stdlib-406/release.ninja deleted file mode 100644 index fcf7b28038..0000000000 --- a/jscomp/stdlib-406/release.ninja +++ /dev/null @@ -1,90 +0,0 @@ - -bsc_flags = -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -make-runtime -w -9-3-106 -warn-error A -I others - -rule cc - command = $bsc -bs-cmi -bs-cmj $bsc_flags -I stdlib-406 $in - description = $in -> $out -rule cc_cmi - command = $bsc -bs-read-cmi -bs-cmi -bs-cmj $bsc_flags -I stdlib-406 $in - description = $in -> $out - -o stdlib-406/pervasives.cmj : cc_cmi stdlib-406/pervasives.res | stdlib-406/pervasives.cmi $bsc others - bsc_flags = $bsc_flags -nopervasives -o stdlib-406/pervasives.cmi : cc stdlib-406/pervasives.resi | $bsc others - bsc_flags = $bsc_flags -nopervasives -o stdlib-406/arg.cmj : cc_cmi stdlib-406/arg.res | stdlib-406/arg.cmi stdlib-406/array.cmj stdlib-406/buffer.cmj stdlib-406/list.cmj stdlib-406/set.cmj stdlib-406/string.cmj stdlib-406/sys.cmj $bsc others -o stdlib-406/arg.cmi : cc stdlib-406/arg.resi | stdlib-406/pervasives.cmj stdlib-406/set.cmi stdlib-406/string.cmi $bsc others -o stdlib-406/array.cmj : cc_cmi stdlib-406/array.res | stdlib-406/array.cmi $bsc others -o stdlib-406/array.cmi : cc stdlib-406/array.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/arrayLabels.cmj : cc_cmi stdlib-406/arrayLabels.res | stdlib-406/arrayLabels.cmi $bsc others -o stdlib-406/arrayLabels.cmi : cc stdlib-406/arrayLabels.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/buffer.cmj : cc_cmi stdlib-406/buffer.res | stdlib-406/buffer.cmi stdlib-406/bytes.cmj stdlib-406/char.cmj stdlib-406/string.cmj stdlib-406/uchar.cmj $bsc others -o stdlib-406/buffer.cmi : cc stdlib-406/buffer.resi | stdlib-406/pervasives.cmj stdlib-406/uchar.cmi $bsc others -o stdlib-406/bytes.cmj : cc_cmi stdlib-406/bytes.res | stdlib-406/bytes.cmi stdlib-406/char.cmj $bsc others -o stdlib-406/bytes.cmi : cc stdlib-406/bytes.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/bytesLabels.cmj : cc_cmi stdlib-406/bytesLabels.res | stdlib-406/bytesLabels.cmi stdlib-406/char.cmj $bsc others -o stdlib-406/bytesLabels.cmi : cc stdlib-406/bytesLabels.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/callback.cmj : cc_cmi stdlib-406/callback.res | stdlib-406/callback.cmi $bsc others -o stdlib-406/callback.cmi : cc stdlib-406/callback.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/camlinternalLazy.cmj : cc_cmi stdlib-406/camlinternalLazy.res | stdlib-406/camlinternalLazy.cmi $bsc others -o stdlib-406/camlinternalLazy.cmi : cc stdlib-406/camlinternalLazy.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/camlinternalMod.cmj : cc_cmi stdlib-406/camlinternalMod.res | stdlib-406/camlinternalMod.cmi stdlib-406/obj.cmj $bsc others -o stdlib-406/camlinternalMod.cmi : cc stdlib-406/camlinternalMod.resi | stdlib-406/obj.cmi stdlib-406/pervasives.cmj $bsc others -o stdlib-406/char.cmj : cc_cmi stdlib-406/char.res | stdlib-406/char.cmi $bsc others -o stdlib-406/char.cmi : cc stdlib-406/char.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/complex.cmj : cc_cmi stdlib-406/complex.res | stdlib-406/complex.cmi $bsc others -o stdlib-406/complex.cmi : cc stdlib-406/complex.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/digest.cmj : cc_cmi stdlib-406/digest.res | stdlib-406/bytes.cmj stdlib-406/char.cmj stdlib-406/digest.cmi stdlib-406/string.cmj $bsc others -o stdlib-406/digest.cmi : cc stdlib-406/digest.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/filename.cmj : cc_cmi stdlib-406/filename.res | stdlib-406/buffer.cmj stdlib-406/filename.cmi stdlib-406/string.cmj stdlib-406/sys.cmj $bsc others -o stdlib-406/filename.cmi : cc stdlib-406/filename.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/genlex.cmj : cc_cmi stdlib-406/genlex.res | stdlib-406/bytes.cmj stdlib-406/char.cmj stdlib-406/genlex.cmi stdlib-406/hashtbl.cmj stdlib-406/list.cmj stdlib-406/stream.cmj stdlib-406/string.cmj $bsc others -o stdlib-406/genlex.cmi : cc stdlib-406/genlex.resi | stdlib-406/char.cmi stdlib-406/pervasives.cmj stdlib-406/stream.cmi stdlib-406/string.cmi $bsc others -o stdlib-406/hashtbl.cmj : cc_cmi stdlib-406/hashtbl.res | stdlib-406/array.cmj stdlib-406/hashtbl.cmi stdlib-406/lazy.cmj stdlib-406/random.cmj $bsc others -o stdlib-406/hashtbl.cmi : cc stdlib-406/hashtbl.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/hashtblLabels.cmi stdlib-406/hashtblLabels.cmj : cc stdlib-406/hashtblLabels.res | stdlib-406/hashtbl.cmj stdlib-406/pervasives.cmj $bsc others -o stdlib-406/int32.cmj : cc_cmi stdlib-406/int32.res | stdlib-406/int32.cmi $bsc others -o stdlib-406/int32.cmi : cc stdlib-406/int32.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/int64.cmj : cc_cmi stdlib-406/int64.res | stdlib-406/int64.cmi $bsc others -o stdlib-406/int64.cmi : cc stdlib-406/int64.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/lazy.cmj : cc_cmi stdlib-406/lazy.res | stdlib-406/camlinternalLazy.cmj stdlib-406/lazy.cmi $bsc others -o stdlib-406/lazy.cmi : cc stdlib-406/lazy.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/lexing.cmj : cc_cmi stdlib-406/lexing.res | stdlib-406/array.cmj stdlib-406/bytes.cmj stdlib-406/lexing.cmi stdlib-406/string.cmj $bsc others -o stdlib-406/lexing.cmi : cc stdlib-406/lexing.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/list.cmj : cc_cmi stdlib-406/list.res | stdlib-406/list.cmi $bsc others -o stdlib-406/list.cmi : cc stdlib-406/list.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/listLabels.cmj : cc_cmi stdlib-406/listLabels.res | stdlib-406/listLabels.cmi $bsc others -o stdlib-406/listLabels.cmi : cc stdlib-406/listLabels.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/map.cmj : cc_cmi stdlib-406/map.res | stdlib-406/map.cmi $bsc others -o stdlib-406/map.cmi : cc stdlib-406/map.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/mapLabels.cmi stdlib-406/mapLabels.cmj : cc stdlib-406/mapLabels.res | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/moreLabels.cmj : cc_cmi stdlib-406/moreLabels.res | stdlib-406/hashtblLabels.cmj stdlib-406/mapLabels.cmj stdlib-406/moreLabels.cmi stdlib-406/setLabels.cmj $bsc others -o stdlib-406/moreLabels.cmi : cc stdlib-406/moreLabels.resi | stdlib-406/hashtbl.cmi stdlib-406/map.cmi stdlib-406/pervasives.cmj stdlib-406/set.cmi $bsc others -o stdlib-406/obj.cmj : cc_cmi stdlib-406/obj.res | stdlib-406/obj.cmi $bsc others -o stdlib-406/obj.cmi : cc stdlib-406/obj.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/parsing.cmj : cc_cmi stdlib-406/parsing.res | stdlib-406/array.cmj stdlib-406/lexing.cmj stdlib-406/obj.cmj stdlib-406/parsing.cmi $bsc others -o stdlib-406/parsing.cmi : cc stdlib-406/parsing.resi | stdlib-406/lexing.cmi stdlib-406/obj.cmi stdlib-406/pervasives.cmj $bsc others -o stdlib-406/queue.cmj : cc_cmi stdlib-406/queue.res | stdlib-406/queue.cmi $bsc others -o stdlib-406/queue.cmi : cc stdlib-406/queue.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/random.cmj : cc_cmi stdlib-406/random.res | stdlib-406/array.cmj stdlib-406/char.cmj stdlib-406/digest.cmj stdlib-406/int32.cmj stdlib-406/int64.cmj stdlib-406/random.cmi $bsc others -o stdlib-406/random.cmi : cc stdlib-406/random.resi | stdlib-406/int32.cmi stdlib-406/int64.cmi stdlib-406/pervasives.cmj $bsc others -o stdlib-406/set.cmj : cc_cmi stdlib-406/set.res | stdlib-406/list.cmj stdlib-406/set.cmi $bsc others -o stdlib-406/set.cmi : cc stdlib-406/set.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/setLabels.cmi stdlib-406/setLabels.cmj : cc stdlib-406/setLabels.res | stdlib-406/list.cmj stdlib-406/pervasives.cmj $bsc others -o stdlib-406/sort.cmj : cc_cmi stdlib-406/sort.res | stdlib-406/array.cmj stdlib-406/sort.cmi $bsc others -o stdlib-406/sort.cmi : cc stdlib-406/sort.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/stack.cmj : cc_cmi stdlib-406/stack.res | stdlib-406/list.cmj stdlib-406/stack.cmi $bsc others -o stdlib-406/stack.cmi : cc stdlib-406/stack.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/stdLabels.cmj : cc_cmi stdlib-406/stdLabels.res | stdlib-406/arrayLabels.cmj stdlib-406/bytesLabels.cmj stdlib-406/listLabels.cmj stdlib-406/stdLabels.cmi stdlib-406/stringLabels.cmj $bsc others -o stdlib-406/stdLabels.cmi : cc stdlib-406/stdLabels.resi | stdlib-406/arrayLabels.cmi stdlib-406/bytesLabels.cmi stdlib-406/listLabels.cmi stdlib-406/pervasives.cmj stdlib-406/stringLabels.cmi $bsc others -o stdlib-406/stream.cmj : cc_cmi stdlib-406/stream.res | stdlib-406/bytes.cmj stdlib-406/lazy.cmj stdlib-406/list.cmj stdlib-406/stream.cmi stdlib-406/string.cmj $bsc others -o stdlib-406/stream.cmi : cc stdlib-406/stream.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/string.cmj : cc_cmi stdlib-406/string.res | stdlib-406/array.cmj stdlib-406/bytes.cmj stdlib-406/string.cmi $bsc others -o stdlib-406/string.cmi : cc stdlib-406/string.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/stringLabels.cmj : cc_cmi stdlib-406/stringLabels.res | stdlib-406/array.cmj stdlib-406/bytes.cmj stdlib-406/stringLabels.cmi $bsc others -o stdlib-406/stringLabels.cmi : cc stdlib-406/stringLabels.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/sys.cmj : cc_cmi stdlib-406/sys.res | stdlib-406/sys.cmi $bsc others -o stdlib-406/sys.cmi : cc stdlib-406/sys.resi | stdlib-406/pervasives.cmj $bsc others -o stdlib-406/uchar.cmj : cc_cmi stdlib-406/uchar.res | stdlib-406/char.cmj stdlib-406/uchar.cmi $bsc others -o stdlib-406/uchar.cmi : cc stdlib-406/uchar.resi | stdlib-406/pervasives.cmj $bsc others -o $stdlib : phony stdlib-406/arg.cmi stdlib-406/arg.cmj stdlib-406/array.cmi stdlib-406/array.cmj stdlib-406/arrayLabels.cmi stdlib-406/arrayLabels.cmj stdlib-406/buffer.cmi stdlib-406/buffer.cmj stdlib-406/bytes.cmi stdlib-406/bytes.cmj stdlib-406/bytesLabels.cmi stdlib-406/bytesLabels.cmj stdlib-406/callback.cmi stdlib-406/callback.cmj stdlib-406/camlinternalLazy.cmi stdlib-406/camlinternalLazy.cmj stdlib-406/camlinternalMod.cmi stdlib-406/camlinternalMod.cmj stdlib-406/char.cmi stdlib-406/char.cmj stdlib-406/complex.cmi stdlib-406/complex.cmj stdlib-406/digest.cmi stdlib-406/digest.cmj stdlib-406/filename.cmi stdlib-406/filename.cmj stdlib-406/genlex.cmi stdlib-406/genlex.cmj stdlib-406/hashtbl.cmi stdlib-406/hashtbl.cmj stdlib-406/hashtblLabels.cmi stdlib-406/hashtblLabels.cmj stdlib-406/int32.cmi stdlib-406/int32.cmj stdlib-406/int64.cmi stdlib-406/int64.cmj stdlib-406/lazy.cmi stdlib-406/lazy.cmj stdlib-406/lexing.cmi stdlib-406/lexing.cmj stdlib-406/list.cmi stdlib-406/list.cmj stdlib-406/listLabels.cmi stdlib-406/listLabels.cmj stdlib-406/map.cmi stdlib-406/map.cmj stdlib-406/mapLabels.cmi stdlib-406/mapLabels.cmj stdlib-406/moreLabels.cmi stdlib-406/moreLabels.cmj stdlib-406/obj.cmi stdlib-406/obj.cmj stdlib-406/parsing.cmi stdlib-406/parsing.cmj stdlib-406/queue.cmi stdlib-406/queue.cmj stdlib-406/random.cmi stdlib-406/random.cmj stdlib-406/set.cmi stdlib-406/set.cmj stdlib-406/setLabels.cmi stdlib-406/setLabels.cmj stdlib-406/sort.cmi stdlib-406/sort.cmj stdlib-406/stack.cmi stdlib-406/stack.cmj stdlib-406/stdLabels.cmi stdlib-406/stdLabels.cmj stdlib-406/stream.cmi stdlib-406/stream.cmj stdlib-406/string.cmi stdlib-406/string.cmj stdlib-406/stringLabels.cmi stdlib-406/stringLabels.cmj stdlib-406/sys.cmi stdlib-406/sys.cmj stdlib-406/uchar.cmi stdlib-406/uchar.cmj diff --git a/jscomp/stdlib-406/set.res b/jscomp/stdlib-406/set.res deleted file mode 100644 index 49d30edd63..0000000000 --- a/jscomp/stdlib-406/set.res +++ /dev/null @@ -1,711 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/* Sets over ordered types */ - -module type OrderedType = { - type t - let compare: (t, t) => int -} - -module type S = { - type elt - type t - let empty: t - let is_empty: t => bool - let mem: (elt, t) => bool - let add: (elt, t) => t - let singleton: elt => t - let remove: (elt, t) => t - let union: (t, t) => t - let inter: (t, t) => t - let diff: (t, t) => t - let compare: (t, t) => int - let equal: (t, t) => bool - let subset: (t, t) => bool - let iter: (elt => unit, t) => unit - let map: (elt => elt, t) => t - let fold: ((elt, 'a) => 'a, t, 'a) => 'a - let for_all: (elt => bool, t) => bool - let exists: (elt => bool, t) => bool - let filter: (elt => bool, t) => t - let partition: (elt => bool, t) => (t, t) - let cardinal: t => int - let elements: t => list - let min_elt: t => elt - let min_elt_opt: t => option - let max_elt: t => elt - let max_elt_opt: t => option - let choose: t => elt - let choose_opt: t => option - let split: (elt, t) => (t, bool, t) - let find: (elt, t) => elt - let find_opt: (elt, t) => option - let find_first: (elt => bool, t) => elt - let find_first_opt: (elt => bool, t) => option - let find_last: (elt => bool, t) => elt - let find_last_opt: (elt => bool, t) => option - let of_list: list => t -} - -module Make = (Ord: OrderedType) => { - type elt = Ord.t - type rec t = Empty | Node({l: t, v: elt, r: t, h: int}) - - /* Sets are represented by balanced binary trees (the heights of the - children differ by at most 2 */ - - let height = param => - switch param { - | Empty => 0 - | Node({h}) => h - } - - /* Creates a new node with left son l, value v and right son r. - We must have all elements of l < v < all elements of r. - l and r must be balanced and | height l - height r | <= 2. - Inline expansion of height for better speed. */ - - let create = (l, v, r) => { - let hl = switch l { - | Empty => 0 - | Node({h}) => h - } - let hr = switch r { - | Empty => 0 - | Node({h}) => h - } - Node({ - l, - v, - r, - h: if hl >= hr { - hl + 1 - } else { - hr + 1 - }, - }) - } - - /* Same as create, but performs one step of rebalancing if necessary. - Assumes l and r balanced and | height l - height r | <= 3. - Inline expansion of create for better speed in the most frequent case - where no rebalancing is required. */ - - let bal = (l, v, r) => { - let hl = switch l { - | Empty => 0 - | Node({h}) => h - } - let hr = switch r { - | Empty => 0 - | Node({h}) => h - } - if hl > hr + 2 { - switch l { - | Empty => invalid_arg("Set.bal") - | Node({l: ll, v: lv, r: lr}) => - if height(ll) >= height(lr) { - create(ll, lv, create(lr, v, r)) - } else { - switch lr { - | Empty => invalid_arg("Set.bal") - | Node({l: lrl, v: lrv, r: lrr}) => create(create(ll, lv, lrl), lrv, create(lrr, v, r)) - } - } - } - } else if hr > hl + 2 { - switch r { - | Empty => invalid_arg("Set.bal") - | Node({l: rl, v: rv, r: rr}) => - if height(rr) >= height(rl) { - create(create(l, v, rl), rv, rr) - } else { - switch rl { - | Empty => invalid_arg("Set.bal") - | Node({l: rll, v: rlv, r: rlr}) => create(create(l, v, rll), rlv, create(rlr, rv, rr)) - } - } - } - } else { - Node({ - l, - v, - r, - h: if hl >= hr { - hl + 1 - } else { - hr + 1 - }, - }) - } - } - - /* Insertion of one element */ - - let rec add = (x, param) => - switch param { - | Empty => Node({l: Empty, v: x, r: Empty, h: 1}) - | Node({l, v, r}) as t => - let c = Ord.compare(x, v) - if c == 0 { - t - } else if c < 0 { - let ll = add(x, l) - if l === ll { - t - } else { - bal(ll, v, r) - } - } else { - let rr = add(x, r) - if r === rr { - t - } else { - bal(l, v, rr) - } - } - } - - let singleton = x => Node({l: Empty, v: x, r: Empty, h: 1}) - - /* Beware: those two functions assume that the added v is *strictly* - smaller (or bigger) than all the present elements in the tree; it - does not test for equality with the current min (or max) element. - Indeed, they are only used during the "join" operation which - respects this precondition. - */ - - let rec add_min_element = (x, param) => - switch param { - | Empty => singleton(x) - | Node({l, v, r}) => bal(add_min_element(x, l), v, r) - } - - let rec add_max_element = (x, param) => - switch param { - | Empty => singleton(x) - | Node({l, v, r}) => bal(l, v, add_max_element(x, r)) - } - - /* Same as create and bal, but no assumptions are made on the - relative heights of l and r. */ - - let rec join = (l, v, r) => - switch (l, r) { - | (Empty, _) => add_min_element(v, r) - | (_, Empty) => add_max_element(v, l) - | (Node({l: ll, v: lv, r: lr, h: lh}), Node({l: rl, v: rv, r: rr, h: rh})) => - if lh > rh + 2 { - bal(ll, lv, join(lr, v, r)) - } else if rh > lh + 2 { - bal(join(l, v, rl), rv, rr) - } else { - create(l, v, r) - } - } - - /* Smallest and greatest element of a set */ - - let rec min_elt = param => - switch param { - | Empty => raise(Not_found) - | Node({l: Empty, v}) => v - | Node({l}) => min_elt(l) - } - - let rec min_elt_opt = param => - switch param { - | Empty => None - | Node({l: Empty, v}) => Some(v) - | Node({l}) => min_elt_opt(l) - } - - let rec max_elt = param => - switch param { - | Empty => raise(Not_found) - | Node({v, r: Empty}) => v - | Node({r}) => max_elt(r) - } - - let rec max_elt_opt = param => - switch param { - | Empty => None - | Node({v, r: Empty}) => Some(v) - | Node({r}) => max_elt_opt(r) - } - - /* Remove the smallest element of the given set */ - - let rec remove_min_elt = param => - switch param { - | Empty => invalid_arg("Set.remove_min_elt") - | Node({l: Empty, r}) => r - | Node({l, v, r}) => bal(remove_min_elt(l), v, r) - } - - /* Merge two trees l and r into one. - All elements of l must precede the elements of r. - Assume | height l - height r | <= 2. */ - - let merge = (t1, t2) => - switch (t1, t2) { - | (Empty, t) => t - | (t, Empty) => t - | (_, _) => bal(t1, min_elt(t2), remove_min_elt(t2)) - } - - /* Merge two trees l and r into one. - All elements of l must precede the elements of r. - No assumption on the heights of l and r. */ - - let concat = (t1, t2) => - switch (t1, t2) { - | (Empty, t) => t - | (t, Empty) => t - | (_, _) => join(t1, min_elt(t2), remove_min_elt(t2)) - } - - /* Splitting. split x s returns a triple (l, present, r) where - - l is the set of elements of s that are < x - - r is the set of elements of s that are > x - - present is false if s contains no element equal to x, - or true if s contains an element equal to x. */ - - let rec split = (x, param) => - switch param { - | Empty => (Empty, false, Empty) - | Node({l, v, r}) => - let c = Ord.compare(x, v) - if c == 0 { - (l, true, r) - } else if c < 0 { - let (ll, pres, rl) = split(x, l) - (ll, pres, join(rl, v, r)) - } else { - let (lr, pres, rr) = split(x, r) - (join(l, v, lr), pres, rr) - } - } - - /* Implementation of the set operations */ - - let empty = Empty - - let is_empty = param => - switch param { - | Empty => true - | _ => false - } - - let rec mem = (x, param) => - switch param { - | Empty => false - | Node({l, v, r}) => - let c = Ord.compare(x, v) - c == 0 || - mem( - x, - if c < 0 { - l - } else { - r - }, - ) - } - - let rec remove = (x, param) => - switch param { - | Empty => Empty - | Node({l, v, r}) as t => - let c = Ord.compare(x, v) - if c == 0 { - merge(l, r) - } else if c < 0 { - let ll = remove(x, l) - if l === ll { - t - } else { - bal(ll, v, r) - } - } else { - let rr = remove(x, r) - if r === rr { - t - } else { - bal(l, v, rr) - } - } - } - - let rec union = (s1, s2) => - switch (s1, s2) { - | (Empty, t2) => t2 - | (t1, Empty) => t1 - | (Node({l: l1, v: v1, r: r1, h: h1}), Node({l: l2, v: v2, r: r2, h: h2})) => - if h1 >= h2 { - if h2 == 1 { - add(v2, s1) - } else { - let (l2, _, r2) = split(v1, s2) - join(union(l1, l2), v1, union(r1, r2)) - } - } else if h1 == 1 { - add(v1, s2) - } else { - let (l1, _, r1) = split(v2, s1) - join(union(l1, l2), v2, union(r1, r2)) - } - } - - let rec inter = (s1, s2) => - switch (s1, s2) { - | (Empty, _) => Empty - | (_, Empty) => Empty - | (Node({l: l1, v: v1, r: r1}), t2) => - switch split(v1, t2) { - | (l2, false, r2) => concat(inter(l1, l2), inter(r1, r2)) - | (l2, true, r2) => join(inter(l1, l2), v1, inter(r1, r2)) - } - } - - let rec diff = (s1, s2) => - switch (s1, s2) { - | (Empty, _) => Empty - | (t1, Empty) => t1 - | (Node({l: l1, v: v1, r: r1}), t2) => - switch split(v1, t2) { - | (l2, false, r2) => join(diff(l1, l2), v1, diff(r1, r2)) - | (l2, true, r2) => concat(diff(l1, l2), diff(r1, r2)) - } - } - - type rec enumeration = End | More(elt, t, enumeration) - - let rec cons_enum = (s, e) => - switch s { - | Empty => e - | Node({l, v, r}) => cons_enum(l, More(v, r, e)) - } - - let rec compare_aux = (e1, e2) => - switch (e1, e2) { - | (End, End) => 0 - | (End, _) => -1 - | (_, End) => 1 - | (More(v1, r1, e1), More(v2, r2, e2)) => - let c = Ord.compare(v1, v2) - if c != 0 { - c - } else { - compare_aux(cons_enum(r1, e1), cons_enum(r2, e2)) - } - } - - let compare = (s1, s2) => compare_aux(cons_enum(s1, End), cons_enum(s2, End)) - - let equal = (s1, s2) => compare(s1, s2) == 0 - - let rec subset = (s1, s2) => - switch (s1, s2) { - | (Empty, _) => true - | (_, Empty) => false - | (Node({l: l1, v: v1, r: r1}), Node({l: l2, v: v2, r: r2}) as t2) => - let c = Ord.compare(v1, v2) - if c == 0 { - subset(l1, l2) && subset(r1, r2) - } else if c < 0 { - subset(Node({l: l1, v: v1, r: Empty, h: 0}), l2) && subset(r1, t2) - } else { - subset(Node({l: Empty, v: v1, r: r1, h: 0}), r2) && subset(l1, t2) - } - } - - let rec iter = (f, param) => - switch param { - | Empty => () - | Node({l, v, r}) => - iter(f, l) - f(v) - iter(f, r) - } - - let rec fold = (f, s, accu) => - switch s { - | Empty => accu - | Node({l, v, r}) => fold(f, r, f(v, fold(f, l, accu))) - } - - let rec for_all = (p, param) => - switch param { - | Empty => true - | Node({l, v, r}) => p(v) && (for_all(p, l) && for_all(p, r)) - } - - let rec exists = (p, param) => - switch param { - | Empty => false - | Node({l, v, r}) => p(v) || (exists(p, l) || exists(p, r)) - } - - let rec filter = (p, param) => - switch param { - | Empty => Empty - | Node({l, v, r}) as t => - /* call [p] in the expected left-to-right order */ - let l' = filter(p, l) - let pv = p(v) - let r' = filter(p, r) - if pv { - if l === l' && r === r' { - t - } else { - join(l', v, r') - } - } else { - concat(l', r') - } - } - - let rec partition = (p, param) => - switch param { - | Empty => (Empty, Empty) - | Node({l, v, r}) => - /* call [p] in the expected left-to-right order */ - let (lt, lf) = partition(p, l) - let pv = p(v) - let (rt, rf) = partition(p, r) - if pv { - (join(lt, v, rt), concat(lf, rf)) - } else { - (concat(lt, rt), join(lf, v, rf)) - } - } - - let rec cardinal = param => - switch param { - | Empty => 0 - | Node({l, r}) => cardinal(l) + 1 + cardinal(r) - } - - let rec elements_aux = (accu, param) => - switch param { - | Empty => accu - | Node({l, v, r}) => elements_aux(list{v, ...elements_aux(accu, r)}, l) - } - - let elements = s => elements_aux(list{}, s) - - let choose = min_elt - - let choose_opt = min_elt_opt - - let rec find = (x, param) => - switch param { - | Empty => raise(Not_found) - | Node({l, v, r}) => - let c = Ord.compare(x, v) - if c == 0 { - v - } else { - find( - x, - if c < 0 { - l - } else { - r - }, - ) - } - } - - let rec find_first_aux = (v0, f, param) => - switch param { - | Empty => v0 - | Node({l, v, r}) => - if f(v) { - find_first_aux(v, f, l) - } else { - find_first_aux(v0, f, r) - } - } - - let rec find_first = (f, param) => - switch param { - | Empty => raise(Not_found) - | Node({l, v, r}) => - if f(v) { - find_first_aux(v, f, l) - } else { - find_first(f, r) - } - } - - let rec find_first_opt_aux = (v0, f, param) => - switch param { - | Empty => Some(v0) - | Node({l, v, r}) => - if f(v) { - find_first_opt_aux(v, f, l) - } else { - find_first_opt_aux(v0, f, r) - } - } - - let rec find_first_opt = (f, param) => - switch param { - | Empty => None - | Node({l, v, r}) => - if f(v) { - find_first_opt_aux(v, f, l) - } else { - find_first_opt(f, r) - } - } - - let rec find_last_aux = (v0, f, param) => - switch param { - | Empty => v0 - | Node({l, v, r}) => - if f(v) { - find_last_aux(v, f, r) - } else { - find_last_aux(v0, f, l) - } - } - - let rec find_last = (f, param) => - switch param { - | Empty => raise(Not_found) - | Node({l, v, r}) => - if f(v) { - find_last_aux(v, f, r) - } else { - find_last(f, l) - } - } - - let rec find_last_opt_aux = (v0, f, param) => - switch param { - | Empty => Some(v0) - | Node({l, v, r}) => - if f(v) { - find_last_opt_aux(v, f, r) - } else { - find_last_opt_aux(v0, f, l) - } - } - - let rec find_last_opt = (f, param) => - switch param { - | Empty => None - | Node({l, v, r}) => - if f(v) { - find_last_opt_aux(v, f, r) - } else { - find_last_opt(f, l) - } - } - - let rec find_opt = (x, param) => - switch param { - | Empty => None - | Node({l, v, r}) => - let c = Ord.compare(x, v) - if c == 0 { - Some(v) - } else { - find_opt( - x, - if c < 0 { - l - } else { - r - }, - ) - } - } - - let try_join = (l, v, r) => - /* [join l v r] can only be called when (elements of l < v < - elements of r); use [try_join l v r] when this property may - not hold, but you hope it does hold in the common case */ - if ( - (l == Empty || Ord.compare(max_elt(l), v) < 0) && - (r == Empty || Ord.compare(v, min_elt(r)) < 0) - ) { - join(l, v, r) - } else { - union(l, add(v, r)) - } - - let rec map = (f, param) => - switch param { - | Empty => Empty - | Node({l, v, r}) as t => - /* enforce left-to-right evaluation order */ - let l' = map(f, l) - let v' = f(v) - let r' = map(f, r) - if l === l' && (v === v' && r === r') { - t - } else { - try_join(l', v', r') - } - } - - let of_sorted_list = l => { - let rec sub = (n, l) => - switch (n, l) { - | (0, l) => (Empty, l) - | (1, list{x0, ...l}) => (Node({l: Empty, v: x0, r: Empty, h: 1}), l) - | (2, list{x0, x1, ...l}) => ( - Node({l: Node({l: Empty, v: x0, r: Empty, h: 1}), v: x1, r: Empty, h: 2}), - l, - ) - | (3, list{x0, x1, x2, ...l}) => ( - Node({ - l: Node({l: Empty, v: x0, r: Empty, h: 1}), - v: x1, - r: Node({l: Empty, v: x2, r: Empty, h: 1}), - h: 2, - }), - l, - ) - | (n, l) => - let nl = n / 2 - let (left, l) = sub(nl, l) - switch l { - | list{} => assert(false) - | list{mid, ...l} => - let (right, l) = sub(n - nl - 1, l) - (create(left, mid, right), l) - } - } - - fst(sub(List.length(l), l)) - } - - let of_list = l => - switch l { - | list{} => empty - | list{x0} => singleton(x0) - | list{x0, x1} => add(x1, singleton(x0)) - | list{x0, x1, x2} => add(x2, add(x1, singleton(x0))) - | list{x0, x1, x2, x3} => add(x3, add(x2, add(x1, singleton(x0)))) - | list{x0, x1, x2, x3, x4} => add(x4, add(x3, add(x2, add(x1, singleton(x0))))) - | _ => of_sorted_list(List.sort_uniq(Ord.compare, l)) - } -} diff --git a/jscomp/stdlib-406/set.resi b/jscomp/stdlib-406/set.resi deleted file mode 100644 index 7d68f7b7c6..0000000000 --- a/jscomp/stdlib-406/set.resi +++ /dev/null @@ -1,264 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/*** Sets over ordered types. - - This module implements the set data structure, given a total ordering - function over the set elements. All operations over sets - are purely applicative (no side-effects). - The implementation uses balanced binary trees, and is therefore - reasonably efficient: insertion and membership take time - logarithmic in the size of the set, for instance. - - The {!Make} functor constructs implementations for any type, given a - [compare] function. - For instance: - {[ - module IntPairs = - struct - type t = int * int - let compare (x0,y0) (x1,y1) = - match Pervasives.compare x0 x1 with - 0 -> Pervasives.compare y0 y1 - | c -> c - end - - module PairsSet = Set.Make(IntPairs) - - let m = PairsSet.(empty |> add (2,3) |> add (5,7) |> add (11,13)) - ]} - - This creates a new module [PairsSet], with a new type [PairsSet.t] - of sets of [int * int]. -*/ - -/** Input signature of the functor {!Set.Make}. */ -module type OrderedType = { - /** The type of the set elements. */ - type t - - /** A total ordering function over the set elements. - This is a two-argument function [f] such that - [f e1 e2] is zero if the elements [e1] and [e2] are equal, - [f e1 e2] is strictly negative if [e1] is smaller than [e2], - and [f e1 e2] is strictly positive if [e1] is greater than [e2]. - Example: a suitable ordering function is the generic structural - comparison function {!Pervasives.compare}. */ - let compare: (t, t) => int -} - -/** Output signature of the functor {!Set.Make}. */ -module type S = { - /** The type of the set elements. */ - type elt - - /** The type of sets. */ - type t - - /** The empty set. */ - let empty: t - - /** Test whether a set is empty or not. */ - let is_empty: t => bool - - /** [mem x s] tests whether [x] belongs to the set [s]. */ - let mem: (elt, t) => bool - - /** [add x s] returns a set containing all elements of [s], - plus [x]. If [x] was already in [s], [s] is returned unchanged - (the result of the function is then physically equal to [s]). - @before 4.03 Physical equality was not ensured. */ - let add: (elt, t) => t - - /** [singleton x] returns the one-element set containing only [x]. */ - let singleton: elt => t - - /** [remove x s] returns a set containing all elements of [s], - except [x]. If [x] was not in [s], [s] is returned unchanged - (the result of the function is then physically equal to [s]). - @before 4.03 Physical equality was not ensured. */ - let remove: (elt, t) => t - - /** Set union. */ - let union: (t, t) => t - - /** Set intersection. */ - let inter: (t, t) => t - - /** Set difference. */ - let diff: (t, t) => t - - /** Total ordering between sets. Can be used as the ordering function - for doing sets of sets. */ - let compare: (t, t) => int - - /** [equal s1 s2] tests whether the sets [s1] and [s2] are - equal, that is, contain equal elements. */ - let equal: (t, t) => bool - - /** [subset s1 s2] tests whether the set [s1] is a subset of - the set [s2]. */ - let subset: (t, t) => bool - - /** [iter f s] applies [f] in turn to all elements of [s]. - The elements of [s] are presented to [f] in increasing order - with respect to the ordering over the type of the elements. */ - let iter: (elt => unit, t) => unit - - /** [map f s] is the set whose elements are [f a0],[f a1]... [f - aN], where [a0],[a1]...[aN] are the elements of [s]. - - The elements are passed to [f] in increasing order - with respect to the ordering over the type of the elements. - - If no element of [s] is changed by [f], [s] is returned - unchanged. (If each output of [f] is physically equal to its - input, the returned set is physically equal to [s].) - @since 4.04.0 */ - let map: (elt => elt, t) => t - - /** [fold f s a] computes [(f xN ... (f x2 (f x1 a))...)], - where [x1 ... xN] are the elements of [s], in increasing order. */ - let fold: ((elt, 'a) => 'a, t, 'a) => 'a - - /** [for_all p s] checks if all elements of the set - satisfy the predicate [p]. */ - let for_all: (elt => bool, t) => bool - - /** [exists p s] checks if at least one element of - the set satisfies the predicate [p]. */ - let exists: (elt => bool, t) => bool - - /** [filter p s] returns the set of all elements in [s] - that satisfy predicate [p]. If [p] satisfies every element in [s], - [s] is returned unchanged (the result of the function is then - physically equal to [s]). - @before 4.03 Physical equality was not ensured.*/ - let filter: (elt => bool, t) => t - - /** [partition p s] returns a pair of sets [(s1, s2)], where - [s1] is the set of all the elements of [s] that satisfy the - predicate [p], and [s2] is the set of all the elements of - [s] that do not satisfy [p]. */ - let partition: (elt => bool, t) => (t, t) - - /** Return the number of elements of a set. */ - let cardinal: t => int - - /** Return the list of all elements of the given set. - The returned list is sorted in increasing order with respect - to the ordering [Ord.compare], where [Ord] is the argument - given to {!Set.Make}. */ - let elements: t => list - - /** Return the smallest element of the given set - (with respect to the [Ord.compare] ordering), or raise - [Not_found] if the set is empty. */ - let min_elt: t => elt - - /** Return the smallest element of the given set - (with respect to the [Ord.compare] ordering), or [None] - if the set is empty. - @since 4.05 - */ - let min_elt_opt: t => option - - /** Same as {!Set.S.min_elt}, but returns the largest element of the - given set. */ - let max_elt: t => elt - - /** Same as {!Set.S.min_elt_opt}, but returns the largest element of the - given set. - @since 4.05 - */ - let max_elt_opt: t => option - - /** Return one element of the given set, or raise [Not_found] if - the set is empty. Which element is chosen is unspecified, - but equal elements will be chosen for equal sets. */ - let choose: t => elt - - /** Return one element of the given set, or [None] if - the set is empty. Which element is chosen is unspecified, - but equal elements will be chosen for equal sets. - @since 4.05 - */ - let choose_opt: t => option - - /** [split x s] returns a triple [(l, present, r)], where - [l] is the set of elements of [s] that are - strictly less than [x]; - [r] is the set of elements of [s] that are - strictly greater than [x]; - [present] is [false] if [s] contains no element equal to [x], - or [true] if [s] contains an element equal to [x]. */ - let split: (elt, t) => (t, bool, t) - - /** [find x s] returns the element of [s] equal to [x] (according - to [Ord.compare]), or raise [Not_found] if no such element - exists. - @since 4.01.0 */ - let find: (elt, t) => elt - - /** [find_opt x s] returns the element of [s] equal to [x] (according - to [Ord.compare]), or [None] if no such element - exists. - @since 4.05 */ - let find_opt: (elt, t) => option - - /** [find_first f s], where [f] is a monotonically increasing function, - returns the lowest element [e] of [s] such that [f e], - or raises [Not_found] if no such element exists. - - For example, [find_first (fun e -> Ord.compare e x >= 0) s] will return - the first element [e] of [s] where [Ord.compare e x >= 0] (intuitively: - [e >= x]), or raise [Not_found] if [x] is greater than any element of - [s]. - - @since 4.05 - */ - let find_first: (elt => bool, t) => elt - - /** [find_first_opt f s], where [f] is a monotonically increasing function, - returns an option containing the lowest element [e] of [s] such that - [f e], or [None] if no such element exists. - @since 4.05 - */ - let find_first_opt: (elt => bool, t) => option - - /** [find_last f s], where [f] is a monotonically decreasing function, - returns the highest element [e] of [s] such that [f e], - or raises [Not_found] if no such element exists. - @since 4.05 - */ - let find_last: (elt => bool, t) => elt - - /** [find_last_opt f s], where [f] is a monotonically decreasing function, - returns an option containing the highest element [e] of [s] such that - [f e], or [None] if no such element exists. - @since 4.05 - */ - let find_last_opt: (elt => bool, t) => option - - /** [of_list l] creates a set from a list of elements. - This is usually more efficient than folding [add] over the list, - except perhaps for lists with many duplicated elements. - @since 4.02.0 */ - let of_list: list => t -} - -/** Functor building an implementation of the set structure - given a totally ordered type. */ -module Make: (Ord: OrderedType) => (S with type elt = Ord.t) diff --git a/jscomp/stdlib-406/setLabels.res b/jscomp/stdlib-406/setLabels.res deleted file mode 100644 index 4e0ed5e2c8..0000000000 --- a/jscomp/stdlib-406/setLabels.res +++ /dev/null @@ -1,711 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/* Sets over ordered types */ - -module type OrderedType = { - type t - let compare: (t, t) => int -} - -module type S = { - type elt - type t - let empty: t - let is_empty: t => bool - let mem: (elt, t) => bool - let add: (elt, t) => t - let singleton: elt => t - let remove: (elt, t) => t - let union: (t, t) => t - let inter: (t, t) => t - let diff: (t, t) => t - let compare: (t, t) => int - let equal: (t, t) => bool - let subset: (t, t) => bool - let iter: (~f: elt => unit, t) => unit - let map: (~f: elt => elt, t) => t - let fold: (~f: (elt, 'a) => 'a, t, ~init: 'a) => 'a - let for_all: (~f: elt => bool, t) => bool - let exists: (~f: elt => bool, t) => bool - let filter: (~f: elt => bool, t) => t - let partition: (~f: elt => bool, t) => (t, t) - let cardinal: t => int - let elements: t => list - let min_elt: t => elt - let min_elt_opt: t => option - let max_elt: t => elt - let max_elt_opt: t => option - let choose: t => elt - let choose_opt: t => option - let split: (elt, t) => (t, bool, t) - let find: (elt, t) => elt - let find_opt: (elt, t) => option - let find_first: (~f: elt => bool, t) => elt - let find_first_opt: (~f: elt => bool, t) => option - let find_last: (~f: elt => bool, t) => elt - let find_last_opt: (~f: elt => bool, t) => option - let of_list: list => t -} - -module Make = (Ord: OrderedType) => { - type elt = Ord.t - type rec t = Empty | Node({l: t, v: elt, r: t, h: int}) - - /* Sets are represented by balanced binary trees (the heights of the - children differ by at most 2 */ - - let height = param => - switch param { - | Empty => 0 - | Node({h}) => h - } - - /* Creates a new node with left son l, value v and right son r. - We must have all elements of l < v < all elements of r. - l and r must be balanced and | height l - height r | <= 2. - Inline expansion of height for better speed. */ - - let create = (l, v, r) => { - let hl = switch l { - | Empty => 0 - | Node({h}) => h - } - let hr = switch r { - | Empty => 0 - | Node({h}) => h - } - Node({ - l, - v, - r, - h: if hl >= hr { - hl + 1 - } else { - hr + 1 - }, - }) - } - - /* Same as create, but performs one step of rebalancing if necessary. - Assumes l and r balanced and | height l - height r | <= 3. - Inline expansion of create for better speed in the most frequent case - where no rebalancing is required. */ - - let bal = (l, v, r) => { - let hl = switch l { - | Empty => 0 - | Node({h}) => h - } - let hr = switch r { - | Empty => 0 - | Node({h}) => h - } - if hl > hr + 2 { - switch l { - | Empty => invalid_arg("Set.bal") - | Node({l: ll, v: lv, r: lr}) => - if height(ll) >= height(lr) { - create(ll, lv, create(lr, v, r)) - } else { - switch lr { - | Empty => invalid_arg("Set.bal") - | Node({l: lrl, v: lrv, r: lrr}) => create(create(ll, lv, lrl), lrv, create(lrr, v, r)) - } - } - } - } else if hr > hl + 2 { - switch r { - | Empty => invalid_arg("Set.bal") - | Node({l: rl, v: rv, r: rr}) => - if height(rr) >= height(rl) { - create(create(l, v, rl), rv, rr) - } else { - switch rl { - | Empty => invalid_arg("Set.bal") - | Node({l: rll, v: rlv, r: rlr}) => create(create(l, v, rll), rlv, create(rlr, rv, rr)) - } - } - } - } else { - Node({ - l, - v, - r, - h: if hl >= hr { - hl + 1 - } else { - hr + 1 - }, - }) - } - } - - /* Insertion of one element */ - - let rec add = (x, param) => - switch param { - | Empty => Node({l: Empty, v: x, r: Empty, h: 1}) - | Node({l, v, r}) as t => - let c = Ord.compare(x, v) - if c == 0 { - t - } else if c < 0 { - let ll = add(x, l) - if l === ll { - t - } else { - bal(ll, v, r) - } - } else { - let rr = add(x, r) - if r === rr { - t - } else { - bal(l, v, rr) - } - } - } - - let singleton = x => Node({l: Empty, v: x, r: Empty, h: 1}) - - /* Beware: those two functions assume that the added v is *strictly* - smaller (or bigger) than all the present elements in the tree; it - does not test for equality with the current min (or max) element. - Indeed, they are only used during the "join" operation which - respects this precondition. - */ - - let rec add_min_element = (x, param) => - switch param { - | Empty => singleton(x) - | Node({l, v, r}) => bal(add_min_element(x, l), v, r) - } - - let rec add_max_element = (x, param) => - switch param { - | Empty => singleton(x) - | Node({l, v, r}) => bal(l, v, add_max_element(x, r)) - } - - /* Same as create and bal, but no assumptions are made on the - relative heights of l and r. */ - - let rec join = (l, v, r) => - switch (l, r) { - | (Empty, _) => add_min_element(v, r) - | (_, Empty) => add_max_element(v, l) - | (Node({l: ll, v: lv, r: lr, h: lh}), Node({l: rl, v: rv, r: rr, h: rh})) => - if lh > rh + 2 { - bal(ll, lv, join(lr, v, r)) - } else if rh > lh + 2 { - bal(join(l, v, rl), rv, rr) - } else { - create(l, v, r) - } - } - - /* Smallest and greatest element of a set */ - - let rec min_elt = param => - switch param { - | Empty => raise(Not_found) - | Node({l: Empty, v}) => v - | Node({l}) => min_elt(l) - } - - let rec min_elt_opt = param => - switch param { - | Empty => None - | Node({l: Empty, v}) => Some(v) - | Node({l}) => min_elt_opt(l) - } - - let rec max_elt = param => - switch param { - | Empty => raise(Not_found) - | Node({v, r: Empty}) => v - | Node({r}) => max_elt(r) - } - - let rec max_elt_opt = param => - switch param { - | Empty => None - | Node({v, r: Empty}) => Some(v) - | Node({r}) => max_elt_opt(r) - } - - /* Remove the smallest element of the given set */ - - let rec remove_min_elt = param => - switch param { - | Empty => invalid_arg("Set.remove_min_elt") - | Node({l: Empty, r}) => r - | Node({l, v, r}) => bal(remove_min_elt(l), v, r) - } - - /* Merge two trees l and r into one. - All elements of l must precede the elements of r. - Assume | height l - height r | <= 2. */ - - let merge = (t1, t2) => - switch (t1, t2) { - | (Empty, t) => t - | (t, Empty) => t - | (_, _) => bal(t1, min_elt(t2), remove_min_elt(t2)) - } - - /* Merge two trees l and r into one. - All elements of l must precede the elements of r. - No assumption on the heights of l and r. */ - - let concat = (t1, t2) => - switch (t1, t2) { - | (Empty, t) => t - | (t, Empty) => t - | (_, _) => join(t1, min_elt(t2), remove_min_elt(t2)) - } - - /* Splitting. split x s returns a triple (l, present, r) where - - l is the set of elements of s that are < x - - r is the set of elements of s that are > x - - present is false if s contains no element equal to x, - or true if s contains an element equal to x. */ - - let rec split = (x, param) => - switch param { - | Empty => (Empty, false, Empty) - | Node({l, v, r}) => - let c = Ord.compare(x, v) - if c == 0 { - (l, true, r) - } else if c < 0 { - let (ll, pres, rl) = split(x, l) - (ll, pres, join(rl, v, r)) - } else { - let (lr, pres, rr) = split(x, r) - (join(l, v, lr), pres, rr) - } - } - - /* Implementation of the set operations */ - - let empty = Empty - - let is_empty = param => - switch param { - | Empty => true - | _ => false - } - - let rec mem = (x, param) => - switch param { - | Empty => false - | Node({l, v, r}) => - let c = Ord.compare(x, v) - c == 0 || - mem( - x, - if c < 0 { - l - } else { - r - }, - ) - } - - let rec remove = (x, param) => - switch param { - | Empty => Empty - | Node({l, v, r}) as t => - let c = Ord.compare(x, v) - if c == 0 { - merge(l, r) - } else if c < 0 { - let ll = remove(x, l) - if l === ll { - t - } else { - bal(ll, v, r) - } - } else { - let rr = remove(x, r) - if r === rr { - t - } else { - bal(l, v, rr) - } - } - } - - let rec union = (s1, s2) => - switch (s1, s2) { - | (Empty, t2) => t2 - | (t1, Empty) => t1 - | (Node({l: l1, v: v1, r: r1, h: h1}), Node({l: l2, v: v2, r: r2, h: h2})) => - if h1 >= h2 { - if h2 == 1 { - add(v2, s1) - } else { - let (l2, _, r2) = split(v1, s2) - join(union(l1, l2), v1, union(r1, r2)) - } - } else if h1 == 1 { - add(v1, s2) - } else { - let (l1, _, r1) = split(v2, s1) - join(union(l1, l2), v2, union(r1, r2)) - } - } - - let rec inter = (s1, s2) => - switch (s1, s2) { - | (Empty, _) => Empty - | (_, Empty) => Empty - | (Node({l: l1, v: v1, r: r1}), t2) => - switch split(v1, t2) { - | (l2, false, r2) => concat(inter(l1, l2), inter(r1, r2)) - | (l2, true, r2) => join(inter(l1, l2), v1, inter(r1, r2)) - } - } - - let rec diff = (s1, s2) => - switch (s1, s2) { - | (Empty, _) => Empty - | (t1, Empty) => t1 - | (Node({l: l1, v: v1, r: r1}), t2) => - switch split(v1, t2) { - | (l2, false, r2) => join(diff(l1, l2), v1, diff(r1, r2)) - | (l2, true, r2) => concat(diff(l1, l2), diff(r1, r2)) - } - } - - type rec enumeration = End | More(elt, t, enumeration) - - let rec cons_enum = (s, e) => - switch s { - | Empty => e - | Node({l, v, r}) => cons_enum(l, More(v, r, e)) - } - - let rec compare_aux = (e1, e2) => - switch (e1, e2) { - | (End, End) => 0 - | (End, _) => -1 - | (_, End) => 1 - | (More(v1, r1, e1), More(v2, r2, e2)) => - let c = Ord.compare(v1, v2) - if c != 0 { - c - } else { - compare_aux(cons_enum(r1, e1), cons_enum(r2, e2)) - } - } - - let compare = (s1, s2) => compare_aux(cons_enum(s1, End), cons_enum(s2, End)) - - let equal = (s1, s2) => compare(s1, s2) == 0 - - let rec subset = (s1, s2) => - switch (s1, s2) { - | (Empty, _) => true - | (_, Empty) => false - | (Node({l: l1, v: v1, r: r1}), Node({l: l2, v: v2, r: r2}) as t2) => - let c = Ord.compare(v1, v2) - if c == 0 { - subset(l1, l2) && subset(r1, r2) - } else if c < 0 { - subset(Node({l: l1, v: v1, r: Empty, h: 0}), l2) && subset(r1, t2) - } else { - subset(Node({l: Empty, v: v1, r: r1, h: 0}), r2) && subset(l1, t2) - } - } - - let rec iter = (~f, param) => - switch param { - | Empty => () - | Node({l, v, r}) => - iter(~f, l) - f(v) - iter(~f, r) - } - - let rec fold = (~f, s, ~init as accu) => - switch s { - | Empty => accu - | Node({l, v, r}) => fold(~f, r, ~init=f(v, fold(~f, l, ~init=accu))) - } - - let rec for_all = (~f as p, param) => - switch param { - | Empty => true - | Node({l, v, r}) => p(v) && (for_all(~f=p, l) && for_all(~f=p, r)) - } - - let rec exists = (~f as p, param) => - switch param { - | Empty => false - | Node({l, v, r}) => p(v) || (exists(~f=p, l) || exists(~f=p, r)) - } - - let rec filter = (~f as p, param) => - switch param { - | Empty => Empty - | Node({l, v, r}) as t => - /* call [p] in the expected left-to-right order */ - let l' = filter(~f=p, l) - let pv = p(v) - let r' = filter(~f=p, r) - if pv { - if l === l' && r === r' { - t - } else { - join(l', v, r') - } - } else { - concat(l', r') - } - } - - let rec partition = (~f as p, param) => - switch param { - | Empty => (Empty, Empty) - | Node({l, v, r}) => - /* call [p] in the expected left-to-right order */ - let (lt, lf) = partition(~f=p, l) - let pv = p(v) - let (rt, rf) = partition(~f=p, r) - if pv { - (join(lt, v, rt), concat(lf, rf)) - } else { - (concat(lt, rt), join(lf, v, rf)) - } - } - - let rec cardinal = param => - switch param { - | Empty => 0 - | Node({l, r}) => cardinal(l) + 1 + cardinal(r) - } - - let rec elements_aux = (accu, param) => - switch param { - | Empty => accu - | Node({l, v, r}) => elements_aux(list{v, ...elements_aux(accu, r)}, l) - } - - let elements = s => elements_aux(list{}, s) - - let choose = min_elt - - let choose_opt = min_elt_opt - - let rec find = (x, param) => - switch param { - | Empty => raise(Not_found) - | Node({l, v, r}) => - let c = Ord.compare(x, v) - if c == 0 { - v - } else { - find( - x, - if c < 0 { - l - } else { - r - }, - ) - } - } - - let rec find_first_aux = (v0, f, param) => - switch param { - | Empty => v0 - | Node({l, v, r}) => - if f(v) { - find_first_aux(v, f, l) - } else { - find_first_aux(v0, f, r) - } - } - - let rec find_first = (~f, param) => - switch param { - | Empty => raise(Not_found) - | Node({l, v, r}) => - if f(v) { - find_first_aux(v, f, l) - } else { - find_first(~f, r) - } - } - - let rec find_first_opt_aux = (v0, f, param) => - switch param { - | Empty => Some(v0) - | Node({l, v, r}) => - if f(v) { - find_first_opt_aux(v, f, l) - } else { - find_first_opt_aux(v0, f, r) - } - } - - let rec find_first_opt = (~f, param) => - switch param { - | Empty => None - | Node({l, v, r}) => - if f(v) { - find_first_opt_aux(v, f, l) - } else { - find_first_opt(~f, r) - } - } - - let rec find_last_aux = (v0, f, param) => - switch param { - | Empty => v0 - | Node({l, v, r}) => - if f(v) { - find_last_aux(v, f, r) - } else { - find_last_aux(v0, f, l) - } - } - - let rec find_last = (~f, param) => - switch param { - | Empty => raise(Not_found) - | Node({l, v, r}) => - if f(v) { - find_last_aux(v, f, r) - } else { - find_last(~f, l) - } - } - - let rec find_last_opt_aux = (v0, f, param) => - switch param { - | Empty => Some(v0) - | Node({l, v, r}) => - if f(v) { - find_last_opt_aux(v, f, r) - } else { - find_last_opt_aux(v0, f, l) - } - } - - let rec find_last_opt = (~f, param) => - switch param { - | Empty => None - | Node({l, v, r}) => - if f(v) { - find_last_opt_aux(v, f, r) - } else { - find_last_opt(~f, l) - } - } - - let rec find_opt = (x, param) => - switch param { - | Empty => None - | Node({l, v, r}) => - let c = Ord.compare(x, v) - if c == 0 { - Some(v) - } else { - find_opt( - x, - if c < 0 { - l - } else { - r - }, - ) - } - } - - let try_join = (l, v, r) => - /* [join l v r] can only be called when (elements of l < v < - elements of r); use [try_join l v r] when this property may - not hold, but you hope it does hold in the common case */ - if ( - (l == Empty || Ord.compare(max_elt(l), v) < 0) && - (r == Empty || Ord.compare(v, min_elt(r)) < 0) - ) { - join(l, v, r) - } else { - union(l, add(v, r)) - } - - let rec map = (~f, param) => - switch param { - | Empty => Empty - | Node({l, v, r}) as t => - /* enforce left-to-right evaluation order */ - let l' = map(~f, l) - let v' = f(v) - let r' = map(~f, r) - if l === l' && (v === v' && r === r') { - t - } else { - try_join(l', v', r') - } - } - - let of_sorted_list = l => { - let rec sub = (n, l) => - switch (n, l) { - | (0, l) => (Empty, l) - | (1, list{x0, ...l}) => (Node({l: Empty, v: x0, r: Empty, h: 1}), l) - | (2, list{x0, x1, ...l}) => ( - Node({l: Node({l: Empty, v: x0, r: Empty, h: 1}), v: x1, r: Empty, h: 2}), - l, - ) - | (3, list{x0, x1, x2, ...l}) => ( - Node({ - l: Node({l: Empty, v: x0, r: Empty, h: 1}), - v: x1, - r: Node({l: Empty, v: x2, r: Empty, h: 1}), - h: 2, - }), - l, - ) - | (n, l) => - let nl = n / 2 - let (left, l) = sub(nl, l) - switch l { - | list{} => assert(false) - | list{mid, ...l} => - let (right, l) = sub(n - nl - 1, l) - (create(left, mid, right), l) - } - } - - fst(sub(List.length(l), l)) - } - - let of_list = l => - switch l { - | list{} => empty - | list{x0} => singleton(x0) - | list{x0, x1} => add(x1, singleton(x0)) - | list{x0, x1, x2} => add(x2, add(x1, singleton(x0))) - | list{x0, x1, x2, x3} => add(x3, add(x2, add(x1, singleton(x0)))) - | list{x0, x1, x2, x3, x4} => add(x4, add(x3, add(x2, add(x1, singleton(x0))))) - | _ => of_sorted_list(List.sort_uniq(Ord.compare, l)) - } -} diff --git a/jscomp/stdlib-406/sort.res b/jscomp/stdlib-406/sort.res deleted file mode 100644 index ab1713a6ee..0000000000 --- a/jscomp/stdlib-406/sort.res +++ /dev/null @@ -1,134 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/* Merging and sorting */ - -open Array - -let rec merge = (order, l1, l2) => - switch l1 { - | list{} => l2 - | list{h1, ...t1} => - switch l2 { - | list{} => l1 - | list{h2, ...t2} => - if order(h1, h2) { - list{h1, ...merge(order, t1, l2)} - } else { - list{h2, ...merge(order, l1, t2)} - } - } - } - -let list = (order, l) => { - let rec initlist = param => - switch param { - | list{} => list{} - | list{e} => list{list{e}} - | list{e1, e2, ...rest} => - list{ - if order(e1, e2) { - list{e1, e2} - } else { - list{e2, e1} - }, - ...initlist(rest), - } - } - let rec merge2 = param => - switch param { - | list{l1, l2, ...rest} => list{merge(order, l1, l2), ...merge2(rest)} - | x => x - } - let rec mergeall = param => - switch param { - | list{} => list{} - | list{l} => l - | llist => mergeall(merge2(llist)) - } - mergeall(initlist(l)) -} - -let swap = (arr, i, j) => { - let tmp = unsafe_get(arr, i) - unsafe_set(arr, i, unsafe_get(arr, j)) - unsafe_set(arr, j, tmp) -} - -/* There is a known performance bug in the code below. If you find - it, don't bother reporting it. You're not supposed to use this - module anyway. */ -let array = (cmp, arr) => { - let rec qsort = (lo, hi) => - if hi - lo >= 6 { - let mid = lsr(lo + hi, 1) - - /* Select median value from among LO, MID, and HI. Rearrange - LO and HI so the three values are sorted. This lowers the - probability of picking a pathological pivot. It also - avoids extra comparisons on i and j in the two tight "while" - loops below. */ - if cmp(unsafe_get(arr, mid), unsafe_get(arr, lo)) { - swap(arr, mid, lo) - } - if cmp(unsafe_get(arr, hi), unsafe_get(arr, mid)) { - swap(arr, mid, hi) - if cmp(unsafe_get(arr, mid), unsafe_get(arr, lo)) { - swap(arr, mid, lo) - } - } - let pivot = unsafe_get(arr, mid) - let i = ref(lo + 1) and j = ref(hi - 1) - if !cmp(pivot, unsafe_get(arr, hi)) || !cmp(unsafe_get(arr, lo), pivot) { - raise(Invalid_argument("Sort.array")) - } - while i.contents < j.contents { - while !cmp(pivot, unsafe_get(arr, i.contents)) { - incr(i) - } - while !cmp(unsafe_get(arr, j.contents), pivot) { - decr(j) - } - if i.contents < j.contents { - swap(arr, i.contents, j.contents) - } - incr(i) - decr(j) - } - - /* Recursion on smaller half, tail-call on larger half */ - if j.contents - lo <= hi - i.contents { - qsort(lo, j.contents) - qsort(i.contents, hi) - } else { - qsort(i.contents, hi) - qsort(lo, j.contents) - } - } - qsort(0, Array.length(arr) - 1) - /* Finish sorting by insertion sort */ - for i in 1 to Array.length(arr) - 1 { - let val_i = unsafe_get(arr, i) - if !cmp(unsafe_get(arr, i - 1), val_i) { - unsafe_set(arr, i, unsafe_get(arr, i - 1)) - let j = ref(i - 1) - while j.contents >= 1 && !cmp(unsafe_get(arr, j.contents - 1), val_i) { - unsafe_set(arr, j.contents, unsafe_get(arr, j.contents - 1)) - decr(j) - } - unsafe_set(arr, j.contents, val_i) - } - } -} diff --git a/jscomp/stdlib-406/sort.resi b/jscomp/stdlib-406/sort.resi deleted file mode 100644 index b4de4f98f0..0000000000 --- a/jscomp/stdlib-406/sort.resi +++ /dev/null @@ -1,44 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/*** Sorting and merging lists. - - @deprecated This module is obsolete and exists only for backward - compatibility. - The sorting functions in {!Array} and {!List} should be used instead. - The new functions are faster and use less memory. -*/ - -@deprecated("Use List.sort instead.") -/** Sort a list in increasing order according to an ordering predicate. - The predicate should return [true] if its first argument is - less than or equal to its second argument. */ -let list: (('a, 'a) => bool, list<'a>) => list<'a> - -@deprecated("Use Array.sort instead.") -/** Sort an array in increasing order according to an - ordering predicate. - The predicate should return [true] if its first argument is - less than or equal to its second argument. - The array is sorted in place. */ -let array: (('a, 'a) => bool, array<'a>) => unit - -@deprecated("Use List.merge instead.") -/** Merge two lists according to the given predicate. - Assuming the two argument lists are sorted according to the - predicate, [merge] returns a sorted list containing the elements - from the two lists. The behavior is undefined if the two - argument lists were not sorted. */ -let merge: (('a, 'a) => bool, list<'a>, list<'a>) => list<'a> diff --git a/jscomp/stdlib-406/stack.res b/jscomp/stdlib-406/stack.res deleted file mode 100644 index ee13834b0f..0000000000 --- a/jscomp/stdlib-406/stack.res +++ /dev/null @@ -1,55 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -type t<'a> = {mutable c: list<'a>, mutable len: int} - -exception Empty - -let create = () => {c: list{}, len: 0} - -let clear = s => { - s.c = list{} - s.len = 0 -} - -let copy = s => {c: s.c, len: s.len} - -let push = (x, s) => { - s.c = list{x, ...s.c} - s.len = s.len + 1 -} - -let pop = s => - switch s.c { - | list{hd, ...tl} => - s.c = tl - s.len = s.len - 1 - hd - | list{} => raise(Empty) - } - -let top = s => - switch s.c { - | list{hd, ..._} => hd - | list{} => raise(Empty) - } - -let is_empty = s => s.c == list{} - -let length = s => s.len - -let iter = (f, s) => List.iter(f, s.c) - -let fold = (f, acc, s) => List.fold_left(f, acc, s.c) diff --git a/jscomp/stdlib-406/stack.resi b/jscomp/stdlib-406/stack.resi deleted file mode 100644 index 6acaaa7a03..0000000000 --- a/jscomp/stdlib-406/stack.resi +++ /dev/null @@ -1,61 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/*** Last-in first-out stacks. - - This module implements stacks (LIFOs), with in-place modification. -*/ - -/** The type of stacks containing elements of type ['a]. */ -type t<'a> - -/** Raised when {!Stack.pop} or {!Stack.top} is applied to an empty stack. */ exception Empty - -/** Return a new stack, initially empty. */ -let create: unit => t<'a> - -/** [push x s] adds the element [x] at the top of stack [s]. */ -let push: ('a, t<'a>) => unit - -/** [pop s] removes and returns the topmost element in stack [s], - or raises {!Empty} if the stack is empty. */ -let pop: t<'a> => 'a - -/** [top s] returns the topmost element in stack [s], - or raises {!Empty} if the stack is empty. */ -let top: t<'a> => 'a - -/** Discard all elements from a stack. */ -let clear: t<'a> => unit - -/** Return a copy of the given stack. */ -let copy: t<'a> => t<'a> - -/** Return [true] if the given stack is empty, [false] otherwise. */ -let is_empty: t<'a> => bool - -/** Return the number of elements in a stack. Time complexity O(1) */ -let length: t<'a> => int - -/** [iter f s] applies [f] in turn to all elements of [s], - from the element at the top of the stack to the element at the - bottom of the stack. The stack itself is unchanged. */ -let iter: ('a => unit, t<'a>) => unit - -/** [fold f accu s] is [(f (... (f (f accu x1) x2) ...) xn)] - where [x1] is the top of the stack, [x2] the second element, - and [xn] the bottom element. The stack is unchanged. - @since 4.03 */ -let fold: (('b, 'a) => 'b, 'b, t<'a>) => 'b diff --git a/jscomp/stdlib-406/stdLabels.res b/jscomp/stdlib-406/stdLabels.res deleted file mode 100644 index 8e35db9f80..0000000000 --- a/jscomp/stdlib-406/stdLabels.res +++ /dev/null @@ -1,24 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Jacques Garrigue, Kyoto University RIMS */ -/* */ -/* Copyright 2001 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. */ -/* */ -/* ************************************************************************ */ - -/* Module [StdLabels]: meta-module for labelled libraries */ - -module Array = ArrayLabels - -module List = ListLabels - -module String = StringLabels - -module Bytes = BytesLabels diff --git a/jscomp/stdlib-406/stdLabels.resi b/jscomp/stdlib-406/stdLabels.resi deleted file mode 100644 index a36e9d33a3..0000000000 --- a/jscomp/stdlib-406/stdLabels.resi +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Jacques Garrigue, Kyoto University RIMS */ -/* */ -/* Copyright 2001 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. */ -/* */ -/* ************************************************************************ */ - -/*** Standard labeled libraries. - - This meta-module provides labelized version of the {!Array}, - {!Bytes}, {!List} and {!String} modules. - - They only differ by their labels. Detailed interfaces can be found - in [arrayLabels.mli], [bytesLabels.mli], [listLabels.mli] - and [stringLabels.mli]. -*/ - -module Array = ArrayLabels -module Bytes = BytesLabels -module List = ListLabels -module String = StringLabels diff --git a/jscomp/stdlib-406/stream.res b/jscomp/stdlib-406/stream.res deleted file mode 100644 index 03bbd7240c..0000000000 --- a/jscomp/stdlib-406/stream.res +++ /dev/null @@ -1,260 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1997 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. */ -/* */ -/* ************************************************************************ */ - -type rec t<'a> = option> -and cell<'a> = {mutable count: int, mutable data: data<'a>} -and data<'a> = - | Sempty - | Scons('a, data<'a>) - | Sapp(data<'a>, data<'a>) - | Slazy(Lazy.t>) - | Sgen(gen<'a>) -and gen<'a> = {mutable curr: option>, func: int => option<'a>} - -exception Failure -exception Error(string) - -let count = param => - switch param { - | None => 0 - | Some({count}) => count - } -let data = param => - switch param { - | None => Sempty - | Some({data}) => data - } - -let rec get_data: - type v. (int, data) => data = - (count, d) => - switch d { - /* Returns either Sempty or Scons(a, _) even when d is a generator - or a buffer. In those cases, the item a is seen as extracted from - the generator/buffer. - The count parameter is used for calling `Sgen-functions'. */ - | Sempty | Scons(_, _) => d - | Sapp(d1, d2) => - switch get_data(count, d1) { - | Scons(a, d11) => Scons(a, Sapp(d11, d2)) - | Sempty => get_data(count, d2) - | _ => assert(false) - } - | Sgen({curr: Some(None)}) => Sempty - | Sgen({curr: Some(Some(a))} as g) => - g.curr = None - Scons(a, d) - | Sgen(g) => - switch g.func(count) { - | None => - g.curr = Some(None) - Sempty - | Some(a) => Scons(a, d) - /* Warning: anyone using g thinks that an item has been read */ - } - | Slazy(f) => get_data(count, Lazy.force(f)) - } - -let rec peek_data: - type v. cell => option = - s => - /* consult the first item of s */ - switch s.data { - | Sempty => None - | Scons(a, _) => Some(a) - | Sapp(_, _) => - switch get_data(s.count, s.data) { - | Scons(a, _) as d => - s.data = d - Some(a) - | Sempty => None - | _ => assert(false) - } - | Slazy(f) => - s.data = Lazy.force(f) - peek_data(s) - | Sgen({curr: Some(a)}) => a - | Sgen(g) => - let x = g.func(s.count) - g.curr = Some(x) - x - } - -let peek = param => - switch param { - | None => None - | Some(s) => peek_data(s) - } - -let rec junk_data: - type v. cell => unit = - s => - switch s.data { - | Scons(_, d) => - s.count = succ(s.count) - s.data = d - | Sgen({curr: Some(_)} as g) => - s.count = succ(s.count) - g.curr = None - | _ => - switch peek_data(s) { - | None => () - | Some(_) => junk_data(s) - } - } - -let junk = param => - switch param { - | None => () - | Some(data) => junk_data(data) - } - -let rec nget_data = (n, s) => - if n <= 0 { - (list{}, s.data, 0) - } else { - switch peek_data(s) { - | Some(a) => - junk_data(s) - let (al, d, k) = nget_data(pred(n), s) - (list{a, ...al}, Scons(a, d), succ(k)) - | None => (list{}, s.data, 0) - } - } - -let npeek_data = (n, s) => { - let (al, d, len) = nget_data(n, s) - s.count = s.count - len - s.data = d - al -} - -let npeek = (n, param) => - switch param { - | None => list{} - | Some(d) => npeek_data(n, d) - } - -let next = s => - switch peek(s) { - | Some(a) => - junk(s) - a - | None => raise(Failure) - } - -let empty = s => - switch peek(s) { - | Some(_) => raise(Failure) - | None => () - } - -let iter = (f, strm) => { - let rec do_rec = () => - switch peek(strm) { - | Some(a) => - junk(strm) - ignore(f(a)) - do_rec() - | None => () - } - - do_rec() -} - -/* Stream building functions */ - -let from = f => Some({count: 0, data: Sgen({curr: None, func: f})}) - -let of_list = l => Some({count: 0, data: List.fold_right((x, l) => Scons(x, l), l, Sempty)}) - -let of_string = s => { - let count = ref(0) - from(_ => { - /* We cannot use the index passed by the [from] function directly - because it returns the current stream count, with absolutely no - guarantee that it will start from 0. For example, in the case - of [Stream.icons 'c' (Stream.from_string "ab")], the first - access to the string will be made with count [1] already. - */ - let c = count.contents - if c < String.length(s) { - incr(count) - Some(String.get(s, c)) - } else { - None - } - }) -} - -let of_bytes = s => { - let count = ref(0) - from(_ => { - let c = count.contents - if c < Bytes.length(s) { - incr(count) - Some(Bytes.get(s, c)) - } else { - None - } - }) -} - -/* Stream expressions builders */ - -let iapp = (i, s) => Some({count: 0, data: Sapp(data(i), data(s))}) -let icons = (i, s) => Some({count: 0, data: Scons(i, data(s))}) -let ising = i => Some({count: 0, data: Scons(i, Sempty)}) - -let lapp = (f, s) => Some({count: 0, data: Slazy(Lazy.from_fun(() => Sapp(data(f()), data(s))))}) - -let lcons = (f, s) => Some({count: 0, data: Slazy(Lazy.from_fun(() => Scons(f(), data(s))))}) -let lsing = f => Some({count: 0, data: Slazy(Lazy.from_fun(() => Scons(f(), Sempty)))}) - -let sempty = None -let slazy = f => Some({count: 0, data: Slazy(Lazy.from_fun(() => data(f())))}) - -/* For debugging use */ - -let rec dump: - type v. (v => unit, t) => unit = - (f, s) => { - print_string("{count = ") - print_int(count(s)) - print_string("; data = ") - dump_data(f, data(s)) - print_string("}") - print_newline() - } -and dump_data: - type v. (v => unit, data) => unit = - (f, param) => - switch param { - | Sempty => print_string("Sempty") - | Scons(a, d) => - print_string("Scons (") - f(a) - print_string(", ") - dump_data(f, d) - print_string(")") - | Sapp(d1, d2) => - print_string("Sapp (") - dump_data(f, d1) - print_string(", ") - dump_data(f, d2) - print_string(")") - | Slazy(_) => print_string("Slazy") - | Sgen(_) => print_string("Sgen") - } diff --git a/jscomp/stdlib-406/stream.resi b/jscomp/stdlib-406/stream.resi deleted file mode 100644 index 952e6b9d4e..0000000000 --- a/jscomp/stdlib-406/stream.resi +++ /dev/null @@ -1,101 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1997 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. */ -/* */ -/* ************************************************************************ */ - -/*** Streams and parsers. */ - -/** The type of streams holding values of type ['a]. */ -type t<'a> - -/** Raised by parsers when none of the first components of the stream - patterns is accepted. */ -exception Failure - -/** Raised by parsers when the first component of a stream pattern is - accepted, but one of the following components is rejected. */ -exception Error(string) - -/*** {1 Stream builders} */ - -/** [Stream.from f] returns a stream built from the function [f]. - To create a new stream element, the function [f] is called with - the current stream count. The user function [f] must return either - [Some ] for a value or [None] to specify the end of the - stream. - - Do note that the indices passed to [f] may not start at [0] in the - general case. For example, [[< '0; '1; Stream.from f >]] would call - [f] the first time with count [2]. -*/ -let from: (int => option<'a>) => t<'a> - -/** Return the stream holding the elements of the list in the same - order. */ -let of_list: list<'a> => t<'a> - -/** Return the stream of the characters of the string parameter. */ -let of_string: string => t - -/** Return the stream of the characters of the bytes parameter. - @since 4.02.0 */ -let of_bytes: bytes => t - -/* {1 Stream iterator} */ - -/** [Stream.iter f s] scans the whole stream s, applying function [f] - in turn to each stream element encountered. */ -let iter: ('a => unit, t<'a>) => unit - -/* {1 Predefined parsers} */ - -/** Return the first element of the stream and remove it from the - stream. Raise {!Stream.Failure} if the stream is empty. */ -let next: t<'a> => 'a - -/** Return [()] if the stream is empty, else raise {!Stream.Failure}. */ -let empty: t<'a> => unit - -/* {1 Useful functions} */ - -/** Return [Some] of "the first element" of the stream, or [None] if - the stream is empty. */ -let peek: t<'a> => option<'a> - -/** Remove the first element of the stream, possibly unfreezing - it before. */ -let junk: t<'a> => unit - -/** Return the current count of the stream elements, i.e. the number - of the stream elements discarded. */ -let count: t<'a> => int - -/** [npeek n] returns the list of the [n] first elements of - the stream, or all its remaining elements if less than [n] - elements are available. */ -let npeek: (int, t<'a>) => list<'a> - -/* The following is for system use only. Do not call directly. */ - -let iapp: (t<'a>, t<'a>) => t<'a> -let icons: ('a, t<'a>) => t<'a> -let ising: 'a => t<'a> - -let lapp: (unit => t<'a>, t<'a>) => t<'a> -let lcons: (unit => 'a, t<'a>) => t<'a> -let lsing: (unit => 'a) => t<'a> - -let sempty: t<'a> -let slazy: (unit => t<'a>) => t<'a> - -let dump: ('a => unit, t<'a>) => unit diff --git a/jscomp/stdlib-406/stringLabels.res b/jscomp/stdlib-406/stringLabels.res deleted file mode 100644 index a9ea486d14..0000000000 --- a/jscomp/stdlib-406/stringLabels.res +++ /dev/null @@ -1,235 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Damien Doligez, projet Gallium, INRIA Rocquencourt */ -/* */ -/* Copyright 2014 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. */ -/* */ -/* ************************************************************************ */ - -/* String operations, based on byte sequence operations */ - -/* WARNING: Some functions in this file are duplicated in bytes.ml for - efficiency reasons. When you modify the one in this file you need to - modify its duplicate in bytes.ml. - These functions have a "duplicated" comment above their definition. -*/ - -external length: string => int = "%string_length" -external get: (string, int) => char = "%string_safe_get" -external unsafe_get: (string, int) => char = "%string_unsafe_get" - -module B = Bytes - -let bts = B.unsafe_to_string -let bos = B.unsafe_of_string - -external make: (int, char) => string = "?string_repeat" - -let init = (n, ~f) => bts(B.init(n, f)) -let sub = (s, ~pos as ofs, ~len) => bts(B.sub(bos(s), ofs, len)) -let blit = (~src, ~src_pos, ~dst, ~dst_pos, ~len) => B.blit_string(src, src_pos, dst, dst_pos, len) - -%%private(@send external join: (array, string) => string = "join") - -let concat = (~sep: string, xs: list) => xs->Array.of_list->join(sep) - -/* duplicated in bytes.ml */ -let iter = (~f, s) => - for i in 0 to length(s) - 1 { - f(unsafe_get(s, i)) - } - -/* duplicated in bytes.ml */ -let iteri = (~f, s) => - for i in 0 to length(s) - 1 { - f(i, unsafe_get(s, i)) - } - -let map = (~f, s) => bts(B.map(f, bos(s))) -let mapi = (~f, s) => bts(B.mapi(f, bos(s))) - -/* Beware: we cannot use B.trim or B.escape because they always make a - copy, but String.mli spells out some cases where we are not allowed - to make a copy. */ - -let is_space = param => - switch param { - | ' ' | ' ' | '\n' | '\r' | '\t' => true - | _ => false - } - -let trim = s => - if s == "" { - s - } else if is_space(unsafe_get(s, 0)) || is_space(unsafe_get(s, length(s) - 1)) { - bts(B.trim(bos(s))) - } else { - s - } - -let escaped = s => { - let rec needs_escape = i => - if i >= length(s) { - false - } else { - switch unsafe_get(s, i) { - | '"' | '\\' | '\n' | '\t' | '\r' | '\b' => true - | ' ' .. '~' => needs_escape(i + 1) - | _ => true - } - } - - if needs_escape(0) { - bts(B.escaped(bos(s))) - } else { - s - } -} - -/* duplicated in bytes.ml */ -let rec index_rec = (s, lim, i, c) => - if i >= lim { - raise(Not_found) - } else if unsafe_get(s, i) == c { - i - } else { - index_rec(s, lim, i + 1, c) - } - -/* duplicated in bytes.ml */ -let index = (s, c) => index_rec(s, length(s), 0, c) - -/* duplicated in bytes.ml */ -let rec index_rec_opt = (s, lim, i, c) => - if i >= lim { - None - } else if unsafe_get(s, i) == c { - Some(i) - } else { - index_rec_opt(s, lim, i + 1, c) - } - -/* duplicated in bytes.ml */ -let index_opt = (s, c) => index_rec_opt(s, length(s), 0, c) - -/* duplicated in bytes.ml */ -let index_from = (s, i, c) => { - let l = length(s) - if i < 0 || i > l { - invalid_arg("String.index_from / Bytes.index_from") - } else { - index_rec(s, l, i, c) - } -} - -/* duplicated in bytes.ml */ -let index_from_opt = (s, i, c) => { - let l = length(s) - if i < 0 || i > l { - invalid_arg("String.index_from_opt / Bytes.index_from_opt") - } else { - index_rec_opt(s, l, i, c) - } -} - -/* duplicated in bytes.ml */ -let rec rindex_rec = (s, i, c) => - if i < 0 { - raise(Not_found) - } else if unsafe_get(s, i) == c { - i - } else { - rindex_rec(s, i - 1, c) - } - -/* duplicated in bytes.ml */ -let rindex = (s, c) => rindex_rec(s, length(s) - 1, c) - -/* duplicated in bytes.ml */ -let rindex_from = (s, i, c) => - if i < -1 || i >= length(s) { - invalid_arg("String.rindex_from / Bytes.rindex_from") - } else { - rindex_rec(s, i, c) - } - -/* duplicated in bytes.ml */ -let rec rindex_rec_opt = (s, i, c) => - if i < 0 { - None - } else if unsafe_get(s, i) == c { - Some(i) - } else { - rindex_rec_opt(s, i - 1, c) - } - -/* duplicated in bytes.ml */ -let rindex_opt = (s, c) => rindex_rec_opt(s, length(s) - 1, c) - -/* duplicated in bytes.ml */ -let rindex_from_opt = (s, i, c) => - if i < -1 || i >= length(s) { - invalid_arg("String.rindex_from_opt / Bytes.rindex_from_opt") - } else { - rindex_rec_opt(s, i, c) - } - -/* duplicated in bytes.ml */ -let contains_from = (s, i, c) => { - let l = length(s) - if i < 0 || i > l { - invalid_arg("String.contains_from / Bytes.contains_from") - } else { - try { - ignore(index_rec(s, l, i, c)) - true - } catch { - | Not_found => false - } - } -} - -/* duplicated in bytes.ml */ -let contains = (s, c) => contains_from(s, 0, c) - -/* duplicated in bytes.ml */ -let rcontains_from = (s, i, c) => - if i < 0 || i >= length(s) { - invalid_arg("String.rcontains_from / Bytes.rcontains_from") - } else { - try { - ignore(rindex_rec(s, i, c)) - true - } catch { - | Not_found => false - } - } - -let uppercase_ascii = s => bts(B.uppercase_ascii(bos(s))) -let lowercase_ascii = s => bts(B.lowercase_ascii(bos(s))) -let capitalize_ascii = s => bts(B.capitalize_ascii(bos(s))) -let uncapitalize_ascii = s => bts(B.uncapitalize_ascii(bos(s))) - -type t = string - -let compare = (x: t, y: t) => Pervasives.compare(x, y) -let equal: (string, string) => bool = (a, b) => a == b - -let split_on_char = (~sep, s) => { - let r = ref(list{}) - let j = ref(length(s)) - for i in length(s) - 1 downto 0 { - if unsafe_get(s, i) == sep { - r := list{sub(s, ~pos=i + 1, ~len=j.contents - i - 1), ...r.contents} - j := i - } - } - list{sub(s, ~pos=0, ~len=j.contents), ...r.contents} -} diff --git a/jscomp/stdlib-406/stringLabels.resi b/jscomp/stdlib-406/stringLabels.resi deleted file mode 100644 index 2886ac2a44..0000000000 --- a/jscomp/stdlib-406/stringLabels.resi +++ /dev/null @@ -1,233 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/*** String operations. */ - -/** Return the length (number of characters) of the given string. */ -external length: string => int = "%string_length" - -/** [String.get s n] returns the character at index [n] in string [s]. - You can also write [s.[n]] instead of [String.get s n]. - - Raise [Invalid_argument] if [n] not a valid index in [s]. */ -external get: (string, int) => char = "%string_safe_get" - -/** [String.make n c] returns a fresh string of length [n], - filled with the character [c]. - - Raise [Invalid_argument] if [n < 0] or [n > ]{!Sys.max_string_length}. */ -let make: (int, char) => string - -/** [init n f] returns a string of length [n], - with character [i] initialized to the result of [f i]. - - Raise [Invalid_argument] if [n < 0] or [n > ]{!Sys.max_string_length}. - @since 4.02.0 */ -let init: (int, ~f: int => char) => string - -/** [String.sub s start len] returns a fresh string of length [len], - containing the substring of [s] that starts at position [start] and - has length [len]. - - Raise [Invalid_argument] if [start] and [len] do not - designate a valid substring of [s]. */ -let sub: (string, ~pos: int, ~len: int) => string - -/** [String.blit src srcoff dst dstoff len] copies [len] bytes - from the string [src], starting at index [srcoff], - to byte sequence [dst], starting at character number [dstoff]. - - Raise [Invalid_argument] if [srcoff] and [len] do not - designate a valid range of [src], or if [dstoff] and [len] - do not designate a valid range of [dst]. */ -let blit: (~src: string, ~src_pos: int, ~dst: bytes, ~dst_pos: int, ~len: int) => unit - -/** [String.concat sep sl] concatenates the list of strings [sl], - inserting the separator string [sep] between each. */ -let concat: (~sep: string, list) => string - -/** [String.iter f s] applies function [f] in turn to all - the characters of [s]. It is equivalent to - [f s.[0]; f s.[1]; ...; f s.[String.length s - 1]; ()]. */ -let iter: (~f: char => unit, string) => unit - -/** Same as {!String.iter}, but the - function is applied to the index of the element as first argument - (counting from 0), and the character itself as second argument. - @since 4.00.0 */ -let iteri: (~f: (int, char) => unit, string) => unit - -/** [String.map f s] applies function [f] in turn to all - the characters of [s] and stores the results in a new string that - is returned. - @since 4.00.0 */ -let map: (~f: char => char, string) => string - -/** [String.mapi f s] calls [f] with each character of [s] and its - index (in increasing index order) and stores the results in a new - string that is returned. - @since 4.02.0 */ -let mapi: (~f: (int, char) => char, string) => string - -/** Return a copy of the argument, without leading and trailing - whitespace. The characters regarded as whitespace are: [' '], - ['\x0c'], ['\n'], ['\r'], and ['\t']. If there is no leading nor - trailing whitespace character in the argument, return the original - string itself, not a copy. - @since 4.00.0 */ -let trim: string => string - -/** Return a copy of the argument, with special characters - represented by escape sequences, following the lexical - conventions of OCaml. If there is no special - character in the argument, return the original string itself, - not a copy. Its inverse function is Scanf.unescaped. */ -let escaped: string => string - -/** [String.index s c] returns the index of the first - occurrence of character [c] in string [s]. - - Raise [Not_found] if [c] does not occur in [s]. */ -let index: (string, char) => int - -/** [String.index_opt s c] returns the index of the first - occurrence of character [c] in string [s], or - [None] if [c] does not occur in [s]. - @since 4.05 */ -let index_opt: (string, char) => option - -/** [String.rindex s c] returns the index of the last - occurrence of character [c] in string [s]. - - Raise [Not_found] if [c] does not occur in [s]. */ -let rindex: (string, char) => int - -/** [String.rindex_opt s c] returns the index of the last occurrence - of character [c] in string [s], or [None] if [c] does not occur in - [s]. - @since 4.05 */ -let rindex_opt: (string, char) => option - -/** [String.index_from s i c] returns the index of the - first occurrence of character [c] in string [s] after position [i]. - [String.index s c] is equivalent to [String.index_from s 0 c]. - - Raise [Invalid_argument] if [i] is not a valid position in [s]. - Raise [Not_found] if [c] does not occur in [s] after position [i]. */ -let index_from: (string, int, char) => int - -/** [String.index_from_opt s i c] returns the index of the - first occurrence of character [c] in string [s] after position [i] - or [None] if [c] does not occur in [s] after position [i]. - - [String.index_opt s c] is equivalent to [String.index_from_opt s 0 c]. - Raise [Invalid_argument] if [i] is not a valid position in [s]. - - @since 4.05 -*/ -let index_from_opt: (string, int, char) => option - -/** [String.rindex_from s i c] returns the index of the - last occurrence of character [c] in string [s] before position [i+1]. - [String.rindex s c] is equivalent to - [String.rindex_from s (String.length s - 1) c]. - - Raise [Invalid_argument] if [i+1] is not a valid position in [s]. - Raise [Not_found] if [c] does not occur in [s] before position [i+1]. */ -let rindex_from: (string, int, char) => int - -/** [String.rindex_from_opt s i c] returns the index of the - last occurrence of character [c] in string [s] before position [i+1] - or [None] if [c] does not occur in [s] before position [i+1]. - - [String.rindex_opt s c] is equivalent to - [String.rindex_from_opt s (String.length s - 1) c]. - - Raise [Invalid_argument] if [i+1] is not a valid position in [s]. - - @since 4.05 -*/ -let rindex_from_opt: (string, int, char) => option - -/** [String.contains s c] tests if character [c] - appears in the string [s]. */ -let contains: (string, char) => bool - -/** [String.contains_from s start c] tests if character [c] - appears in [s] after position [start]. - [String.contains s c] is equivalent to - [String.contains_from s 0 c]. - - Raise [Invalid_argument] if [start] is not a valid position in [s]. */ -let contains_from: (string, int, char) => bool - -/** [String.rcontains_from s stop c] tests if character [c] - appears in [s] before position [stop+1]. - - Raise [Invalid_argument] if [stop < 0] or [stop+1] is not a valid - position in [s]. */ -let rcontains_from: (string, int, char) => bool - -/** Return a copy of the argument, with all lowercase letters - translated to uppercase, using the US-ASCII character set. - @since 4.05.0 */ -let uppercase_ascii: string => string - -/** Return a copy of the argument, with all uppercase letters - translated to lowercase, using the US-ASCII character set. - @since 4.05.0 */ -let lowercase_ascii: string => string - -/** Return a copy of the argument, with the first character set to uppercase, - using the US-ASCII character set. - @since 4.05.0 */ -let capitalize_ascii: string => string - -/** Return a copy of the argument, with the first character set to lowercase, - using the US-ASCII character set. - @since 4.05.0 */ -let uncapitalize_ascii: string => string - -/** An alias for the type of strings. */ -type t = string - -/** The comparison function for strings, with the same specification as - {!Pervasives.compare}. Along with the type [t], this function [compare] - allows the module [String] to be passed as argument to the functors - {!Set.Make} and {!Map.Make}. */ -let compare: (t, t) => int - -/** The equal function for strings. - @since 4.05.0 */ -let equal: (t, t) => bool - -/** [String.split_on_char sep s] returns the list of all (possibly empty) - substrings of [s] that are delimited by the [sep] character. - - The function's output is specified by the following invariants: - - - The list is not empty. - - Concatenating its elements using [sep] as a separator returns a - string equal to the input ([String.concat (String.make 1 sep) - (String.split_on_char sep s) = s]). - - No string in the result contains the [sep] character. - - @since 4.05.0 -*/ -let split_on_char: (~sep: char, string) => list - -/* The following is for system use only. Do not call directly. */ - -external unsafe_get: (string, int) => char = "%string_unsafe_get" diff --git a/jscomp/stdlib-406/sys.mlp b/jscomp/stdlib-406/sys.mlp deleted file mode 100644 index ca35841ee0..0000000000 --- a/jscomp/stdlib-406/sys.mlp +++ /dev/null @@ -1,131 +0,0 @@ -#2 "stdlib/sys.mlp" -(**************************************************************************) -(* *) -(* OCaml *) -(* *) -(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) -(* *) -(* Copyright 1996 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. *) -(* *) -(**************************************************************************) - -(* WARNING: sys.ml is generated from sys.mlp. DO NOT EDIT sys.ml or - your changes will be lost. -*) - -type backend_type = - | Native - | Bytecode - | Other of string -(* System interface *) - -external get_config: unit -> string * int * bool = "caml_sys_get_config" -external get_argv: unit -> string * string array = "?sys_get_argv" -external big_endian : unit -> bool = "%big_endian" -external word_size : unit -> int = "%word_size" -external int_size : unit -> int = "%int_size" -external max_wosize : unit -> int = "%max_wosize" -external unix : unit -> bool = "%ostype_unix" -external win32 : unit -> bool = "%ostype_win32" -external cygwin : unit -> bool = "%ostype_cygwin" -external get_backend_type : unit -> backend_type = "%backend_type" - -let (executable_name, argv) = get_argv() -let (os_type, _, _) = get_config() -let backend_type = get_backend_type () -let big_endian = big_endian () -let word_size = word_size () -let int_size = int_size () -let unix = unix () -let win32 = win32 () -let cygwin = cygwin () -let max_array_length = max_wosize () -let max_string_length = word_size / 8 * max_array_length - 1 -external runtime_variant : unit -> string = "?runtime_variant" -external runtime_parameters : unit -> string = "?runtime_parameters" - -external file_exists: string -> bool = "?sys_file_exists" -external is_directory : string -> bool = "?sys_is_directory" -external remove: string -> unit = "?sys_remove" -external rename : string -> string -> unit = "?sys_rename" -external getenv: string -> string = "?sys_getenv" - -let getenv_opt s = - (* TODO: expose a non-raising primitive directly. *) - try Some (getenv s) - with Not_found -> None - -external command: string -> int = "caml_sys_system_command" -external time: unit -> (float [@unboxed]) = - "caml_sys_time" "caml_sys_time_unboxed" [@@noalloc] -external chdir: string -> unit = "?sys_chdir" -external getcwd: unit -> string = "?sys_getcwd" -external readdir : string -> string array = "?sys_read_directory" - -let interactive = ref false - -type signal_behavior = - Signal_default - | Signal_ignore - | Signal_handle of (int -> unit) - -external signal : int -> signal_behavior -> signal_behavior - = "caml_install_signal_handler" - -let set_signal sig_num sig_beh = ignore(signal sig_num sig_beh) - -let sigabrt = -1 -let sigalrm = -2 -let sigfpe = -3 -let sighup = -4 -let sigill = -5 -let sigint = -6 -let sigkill = -7 -let sigpipe = -8 -let sigquit = -9 -let sigsegv = -10 -let sigterm = -11 -let sigusr1 = -12 -let sigusr2 = -13 -let sigchld = -14 -let sigcont = -15 -let sigstop = -16 -let sigtstp = -17 -let sigttin = -18 -let sigttou = -19 -let sigvtalrm = -20 -let sigprof = -21 -let sigbus = -22 -let sigpoll = -23 -let sigsys = -24 -let sigtrap = -25 -let sigurg = -26 -let sigxcpu = -27 -let sigxfsz = -28 - -exception Break - -let catch_break on = - if on then - set_signal sigint (Signal_handle(fun _ -> raise Break)) - else - set_signal sigint Signal_default - - -external enable_runtime_warnings: bool -> unit = - "caml_ml_enable_runtime_warnings" -external runtime_warnings_enabled: unit -> bool = - "caml_ml_runtime_warnings_enabled" - -(* The version string is found in file ../VERSION *) - -let ocaml_version = "%%VERSION%%" - -(* Optimization *) - -external opaque_identity : 'a -> 'a = "%opaque" diff --git a/jscomp/stdlib-406/sys.res b/jscomp/stdlib-406/sys.res deleted file mode 100644 index 1dc521f8a4..0000000000 --- a/jscomp/stdlib-406/sys.res +++ /dev/null @@ -1,127 +0,0 @@ -@@config({flags: ["-bs-no-cross-module-opt"]}) -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/* WARNING: sys.ml is generated from sys.mlp. DO NOT EDIT sys.ml or - your changes will be lost. -*/ - -type backend_type = - | Native - | Bytecode - | Other(string) -/* System interface */ - -external get_argv: unit => (string, array) = "?sys_get_argv" -external big_endian: unit => bool = "%big_endian" -external word_size: unit => int = "%word_size" -external int_size: unit => int = "%int_size" -/* external max_wosize : unit -> int = "%max_wosize" */ -external unix: unit => bool = "%ostype_unix" -external win32: unit => bool = "%ostype_win32" -external cygwin: unit => bool = "%ostype_cygwin" -external get_backend_type: unit => backend_type = "%backend_type" - -let (executable_name, argv) = get_argv() - -external get_os_type: unit => string = "#os_type" -let os_type = get_os_type() -let backend_type = get_backend_type() -let big_endian = big_endian() -let word_size = word_size() -let int_size = int_size() -let unix = unix() -let win32 = win32() -let cygwin = cygwin() - -let max_array_length = 2147483647 /* 2^ 31 - 1 */ -let max_string_length = 2147483647 - -external runtime_variant: unit => string = "?runtime_variant" -external runtime_parameters: unit => string = "?runtime_parameters" - -external file_exists: string => bool = "?sys_file_exists" -external is_directory: string => bool = "?sys_is_directory" -external remove: string => unit = "?sys_remove" -external rename: (string, string) => unit = "?sys_rename" -external getenv: string => string = "?sys_getenv" - -@get_index external getEnv: ('a, string) => option = "" -let getenv_opt = s => - switch %external(process) { - | None => None - | Some(x) => getEnv(x["env"], s) - } - -let command: string => int = _ => 127 -external time: unit => float = "?sys_time" -external chdir: string => unit = "?sys_chdir" -external getcwd: unit => string = "?sys_getcwd" -external readdir: string => array = "?sys_read_directory" - -let interactive = ref(false) - -type signal_behavior = - | Signal_default - | Signal_ignore - | Signal_handle(int => unit) - -let signal: (int, signal_behavior) => signal_behavior = (_, _) => Signal_default - -let set_signal = (sig_num, sig_beh) => ignore(signal(sig_num, sig_beh)) - -let sigabrt = -1 -let sigalrm = -2 -let sigfpe = -3 -let sighup = -4 -let sigill = -5 -let sigint = -6 -let sigkill = -7 -let sigpipe = -8 -let sigquit = -9 -let sigsegv = -10 -let sigterm = -11 -let sigusr1 = -12 -let sigusr2 = -13 -let sigchld = -14 -let sigcont = -15 -let sigstop = -16 -let sigtstp = -17 -let sigttin = -18 -let sigttou = -19 -let sigvtalrm = -20 -let sigprof = -21 -let sigbus = -22 -let sigpoll = -23 -let sigsys = -24 -let sigtrap = -25 -let sigurg = -26 -let sigxcpu = -27 -let sigxfsz = -28 - -exception Break - -let catch_break = on => - if on { - set_signal(sigint, Signal_handle(_ => raise(Break))) - } else { - set_signal(sigint, Signal_default) - } - -let enable_runtime_warnings: bool => unit = _ => () -let runtime_warnings_enabled: unit => bool = _ => false -/* The version string is found in file ../VERSION */ - -let ocaml_version = "4.06.2+BS" diff --git a/jscomp/stdlib-406/sys.resi b/jscomp/stdlib-406/sys.resi deleted file mode 100644 index 4de728e9a5..0000000000 --- a/jscomp/stdlib-406/sys.resi +++ /dev/null @@ -1,304 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 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. */ -/* */ -/* ************************************************************************ */ - -/*** System interface. - - Every function in this module raises [Sys_error] with an - informative message when the underlying system call signal - an error. -*/ - -/** The command line arguments given to the process. - The first element is the command name used to invoke the program. - The following elements are the command-line arguments - given to the program. */ -let argv: array - -/** The name of the file containing the executable currently running. */ -let executable_name: string - -/** Test if a file with the given name exists. */ -external file_exists: string => bool = "?sys_file_exists" - -/** Returns [true] if the given name refers to a directory, - [false] if it refers to another kind of file. - Raise [Sys_error] if no file exists with the given name. - @since 3.10.0 -*/ -external is_directory: string => bool = "?sys_is_directory" - -/** Remove the given file name from the file system. */ -external remove: string => unit = "?sys_remove" - -/** Rename a file. [rename oldpath newpath] renames the file - called [oldpath], giving it [newpath] as its new name, - moving it between directories if needed. If [newpath] already - exists, its contents will be replaced with those of [oldpath]. - Depending on the operating system, the metadata (permissions, - owner, etc) of [newpath] can either be preserved or be replaced by - those of [oldpath]. - @since 4.06 concerning the "replace existing file" behavior */ -external rename: (string, string) => unit = "?sys_rename" - -/** Return the value associated to a variable in the process - environment. Raise [Not_found] if the variable is unbound. */ -external getenv: string => string = "?sys_getenv" - -/** Return the value associated to a variable in the process - environment or [None] if the variable is unbound. - @since 4.05 -*/ -let getenv_opt: string => option - -/** Execute the given shell command and return its exit code. */ -let command: string => int - -/** Return the processor time, in seconds, used by the program - since the beginning of execution. */ -external time: unit => float = "?sys_time" - -/** Change the current working directory of the process. */ -external chdir: string => unit = "?sys_chdir" - -/** Return the current working directory of the process. */ -external getcwd: unit => string = "?sys_getcwd" - -/** Return the names of all files present in the given directory. - Names denoting the current directory and the parent directory - (["."] and [".."] in Unix) are not returned. Each string in the - result is a file name rather than a complete path. There is no - guarantee that the name strings in the resulting array will appear - in any specific order; they are not, in particular, guaranteed to - appear in alphabetical order. */ -external readdir: string => array = "?sys_read_directory" - -/** This reference is initially set to [false] in standalone - programs and to [true] if the code is being executed under - the interactive toplevel system [ocaml]. */ -let interactive: ref - -/** Operating system currently executing the OCaml program. One of -- ["Unix"] (for all Unix versions, including Linux and Mac OS X), -- ["Win32"] (for MS-Windows, OCaml compiled with MSVC++ or Mingw), -- ["Cygwin"] (for MS-Windows, OCaml compiled with Cygwin). */ -let os_type: string - -/** Currently, the official distribution only supports [Native] and - [Bytecode], but it can be other backends with alternative - compilers, for example, javascript. - - @since 4.04.0 -*/ -type backend_type = - | Native - | Bytecode - | Other(string) - -/** Backend type currently executing the OCaml program. - @since 4.04.0 - */ -let backend_type: backend_type - -/** True if [Sys.os_type = "Unix"]. - @since 4.01.0 */ -let unix: bool - -/** True if [Sys.os_type = "Win32"]. - @since 4.01.0 */ -let win32: bool - -/** True if [Sys.os_type = "Cygwin"]. - @since 4.01.0 */ -let cygwin: bool - -/** Size of one word on the machine currently executing the OCaml - program, in bits: 32 or 64. */ -let word_size: int - -/** Size of an int. It is 31 bits (resp. 63 bits) when using the - OCaml compiler on a 32 bits (resp. 64 bits) platform. It may - differ for other compilers, e.g. it is 32 bits when compiling to - JavaScript. - @since 4.03.0 */ -let int_size: int - -/** Whether the machine currently executing the Caml program is big-endian. - @since 4.00.0 */ -let big_endian: bool - -/** Maximum length of strings and byte sequences. */ -let max_string_length: int - -/** Maximum length of a normal array. The maximum length of a float - array is [max_array_length/2] on 32-bit machines and - [max_array_length] on 64-bit machines. */ -let max_array_length: int - -/** Return the name of the runtime variant the program is running on. - This is normally the argument given to [-runtime-variant] at compile - time, but for byte-code it can be changed after compilation. - @since 4.03.0 */ -external runtime_variant: unit => string = "?runtime_variant" - -/** Return the value of the runtime parameters, in the same format - as the contents of the [OCAMLRUNPARAM] environment variable. - @since 4.03.0 */ -external runtime_parameters: unit => string = "?runtime_parameters" - -/* {1 Signal handling} */ - -/** What to do when receiving a signal: - - [Signal_default]: take the default behavior - (usually: abort the program) - - [Signal_ignore]: ignore the signal - - [Signal_handle f]: call function [f], giving it the signal - number as argument. */ -type signal_behavior = - | Signal_default - | Signal_ignore - | /** */ Signal_handle(int => unit) - -/** Set the behavior of the system on receipt of a given signal. The - first argument is the signal number. Return the behavior - previously associated with the signal. If the signal number is - invalid (or not available on your system), an [Invalid_argument] - exception is raised. */ -let signal: (int, signal_behavior) => signal_behavior - -/** Same as {!Sys.signal} but return value is ignored. */ -let set_signal: (int, signal_behavior) => unit - -/* {2 Signal numbers for the standard POSIX signals.} */ - -/** Abnormal termination */ -let sigabrt: int - -/** Timeout */ -let sigalrm: int - -/** Arithmetic exception */ -let sigfpe: int - -/** Hangup on controlling terminal */ -let sighup: int - -/** Invalid hardware instruction */ -let sigill: int - -/** Interactive interrupt (ctrl-C) */ -let sigint: int - -/** Termination (cannot be ignored) */ -let sigkill: int - -/** Broken pipe */ -let sigpipe: int - -/** Interactive termination */ -let sigquit: int - -/** Invalid memory reference */ -let sigsegv: int - -/** Termination */ -let sigterm: int - -/** Application-defined signal 1 */ -let sigusr1: int - -/** Application-defined signal 2 */ -let sigusr2: int - -/** Child process terminated */ -let sigchld: int - -/** Continue */ -let sigcont: int - -/** Stop */ -let sigstop: int - -/** Interactive stop */ -let sigtstp: int - -/** Terminal read from background process */ -let sigttin: int - -/** Terminal write from background process */ -let sigttou: int - -/** Timeout in virtual time */ -let sigvtalrm: int - -/** Profiling interrupt */ -let sigprof: int - -/** Bus error - @since 4.03 */ -let sigbus: int - -/** Pollable event - @since 4.03 */ -let sigpoll: int - -/** Bad argument to routine - @since 4.03 */ -let sigsys: int - -/** Trace/breakpoint trap - @since 4.03 */ -let sigtrap: int - -/** Urgent condition on socket - @since 4.03 */ -let sigurg: int - -/** Timeout in cpu time - @since 4.03 */ -let sigxcpu: int - -/** File size limit exceeded - @since 4.03 */ -let sigxfsz: int - -/** Exception raised on interactive interrupt if {!Sys.catch_break} - is on. */ exception Break - -/** [catch_break] governs whether interactive interrupt (ctrl-C) - terminates the program or raises the [Break] exception. - Call [catch_break true] to enable raising [Break], - and [catch_break false] to let the system - terminate the program on user interrupt. */ -let catch_break: bool => unit - -/** [ocaml_version] is the version of OCaml. - It is a string of the form ["major.minor[.patchlevel][+additional-info]"], - where [major], [minor], and [patchlevel] are integers, and - [additional-info] is an arbitrary string. The [[.patchlevel]] and - [[+additional-info]] parts may be absent. */ -let ocaml_version: string - -/** Control whether the OCaml runtime system can emit warnings - on stderr. Currently, the only supported warning is triggered - when a channel created by [open_*] functions is finalized without - being closed. Runtime warnings are enabled by default. - - @since 4.03.0 */ -let enable_runtime_warnings: bool => unit - -/** Return whether runtime warnings are currently enabled. - - @since 4.03.0 */ -let runtime_warnings_enabled: unit => bool diff --git a/jscomp/stdlib-406/uchar.res b/jscomp/stdlib-406/uchar.res deleted file mode 100644 index de27d35e75..0000000000 --- a/jscomp/stdlib-406/uchar.res +++ /dev/null @@ -1,74 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Daniel C. Buenzli */ -/* */ -/* Copyright 2014 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. */ -/* */ -/* ************************************************************************ */ - -external format_int: (string, int) => string = "?format_int" - -let err_no_pred = "U+0000 has no predecessor" -let err_no_succ = "U+10FFFF has no successor" -let err_not_sv = i => format_int("%X", i) ++ " is not an Unicode scalar value" -let err_not_latin1 = u => "U+" ++ (format_int("%04X", u) ++ " is not a latin1 character") - -type t = int - -let min = 0x0000 -let max = 0x10FFFF -let lo_bound = 0xD7FF -let hi_bound = 0xE000 - -let bom = 0xFEFF -let rep = 0xFFFD - -let succ = u => - if u == lo_bound { - hi_bound - } else if u == max { - invalid_arg(err_no_succ) - } else { - u + 1 - } - -let pred = u => - if u == hi_bound { - lo_bound - } else if u == min { - invalid_arg(err_no_pred) - } else { - u - 1 - } - -let is_valid = i => (min <= i && i <= lo_bound) || (hi_bound <= i && i <= max) -let of_int = i => - if is_valid(i) { - i - } else { - invalid_arg(err_not_sv(i)) - } -external unsafe_of_int: int => t = "%identity" -external to_int: t => int = "%identity" - -let is_char = u => u < 256 -let of_char = c => Char.code(c) -let to_char = u => - if u > 255 { - invalid_arg(err_not_latin1(u)) - } else { - Char.unsafe_chr(u) - } - -let unsafe_to_char = Char.unsafe_chr - -let equal: (int, int) => bool = \"=" -let compare: (int, int) => int = Pervasives.compare -let hash = to_int diff --git a/jscomp/stdlib-406/uchar.resi b/jscomp/stdlib-406/uchar.resi deleted file mode 100644 index d837b86a19..0000000000 --- a/jscomp/stdlib-406/uchar.resi +++ /dev/null @@ -1,94 +0,0 @@ -/* ************************************************************************ */ -/* */ -/* OCaml */ -/* */ -/* Daniel C. Buenzli */ -/* */ -/* Copyright 2014 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. */ -/* */ -/* ************************************************************************ */ - -/*** Unicode characters. - - @since 4.03 */ - -/** The type for Unicode characters. - - A value of this type represents an Unicode - {{:http://unicode.org/glossary/#unicode_scalar_value}scalar - value} which is an integer in the ranges [0x0000]...[0xD7FF] or - [0xE000]...[0x10FFFF]. */ -type t - -/** [min] is U+0000. */ -let min: t - -/** [max] is U+10FFFF. */ -let max: t - -/** [bom] is U+FEFF, the - {{:http://unicode.org/glossary/#byte_order_mark}byte order mark} (BOM) - character. - - @since 4.06.0 */ -let bom: t - -/** [rep] is U+FFFD, the - {{:http://unicode.org/glossary/#replacement_character}replacement} - character. - - @since 4.06.0 */ -let rep: t - -/** [succ u] is the scalar value after [u] in the set of Unicode scalar - values. - - @raise Invalid_argument if [u] is {!max}. */ -let succ: t => t - -/** [pred u] is the scalar value before [u] in the set of Unicode scalar - values. - - @raise Invalid_argument if [u] is {!min}. */ -let pred: t => t - -/** [is_valid n] is [true] iff [n] is an Unicode scalar value - (i.e. in the ranges [0x0000]...[0xD7FF] or [0xE000]...[0x10FFFF]).*/ -let is_valid: int => bool - -/** [of_int i] is [i] as an Unicode character. - - @raise Invalid_argument if [i] does not satisfy {!is_valid}. */ -let of_int: int => t - -let unsafe_of_int: int => t - -/** [to_int u] is [u] as an integer. */ -let to_int: t => int - -/** [is_char u] is [true] iff [u] is a latin1 OCaml character. */ -let is_char: t => bool - -/** [of_char c] is [c] as an Unicode character. */ -let of_char: char => t - -/** [to_char u] is [u] as an OCaml latin1 character. - - @raise Invalid_argument if [u] does not satisfy {!is_char}. */ -let to_char: t => char - -let unsafe_to_char: t => char - -/** [equal u u'] is [u = u']. */ -let equal: (t, t) => bool - -/** [compare u u'] is [Pervasives.compare u u']. */ -let compare: (t, t) => int - -/** [hash u] associates a non-negative integer to [u]. */ -let hash: t => int diff --git a/jscomp/syntax/src/res_comments_table.ml b/jscomp/syntax/src/res_comments_table.ml index d334743b88..63d486de5e 100644 --- a/jscomp/syntax/src/res_comments_table.ml +++ b/jscomp/syntax/src/res_comments_table.ml @@ -1348,8 +1348,7 @@ and walk_expression expr t comments = | Pexp_apply ( { pexp_desc = - Pexp_ident - {txt = Longident.Ldot (Lident "Runtime_dict", "unsafe_create")}; + Pexp_ident {txt = Longident.Ldot (Lident "Primitive_dict", "make")}; }, [(Nolabel, key_values)] ) when Res_parsetree_viewer.is_tuple_array key_values -> diff --git a/jscomp/syntax/src/res_core.ml b/jscomp/syntax/src/res_core.ml index 8b6f7a1ce7..08910341c6 100644 --- a/jscomp/syntax/src/res_core.ml +++ b/jscomp/syntax/src/res_core.ml @@ -2020,6 +2020,13 @@ and parse_bracket_access p expr start_pos = Parser.leave_breadcrumb p ExprArrayMutation; Parser.next p; let rhs_expr = parse_expr p in + (* FIXME: Do not implicitly rely on specific module name, even primitive one + + This can be abused like + module Array = MyModule + + Find better mechanism to support it + *) let array_set = Location.mkloc (Longident.Ldot (Lident "Array", "set")) array_loc in @@ -3956,7 +3963,7 @@ and parse_dict_expr ~start_pos p = Ast_helper.Exp.apply ~loc (Ast_helper.Exp.ident ~loc (Location.mkloc - (Longident.Ldot (Longident.Lident "Runtime_dict", "unsafe_create")) + (Longident.Ldot (Longident.Lident Primitive_modules.dict, "make")) loc)) [(Asttypes.Nolabel, Ast_helper.Exp.array ~loc key_value_pairs)] diff --git a/jscomp/syntax/src/res_printer.ml b/jscomp/syntax/src/res_printer.ml index e60a9ddd31..507ed42034 100644 --- a/jscomp/syntax/src/res_printer.ml +++ b/jscomp/syntax/src/res_printer.ml @@ -4087,8 +4087,7 @@ and print_pexp_apply ~state expr cmt_tbl = | Pexp_apply ( { pexp_desc = - Pexp_ident - {txt = Longident.Ldot (Lident "Runtime_dict", "unsafe_create")}; + Pexp_ident {txt = Longident.Ldot (Lident "Primitive_dict", "make")}; }, [(Nolabel, key_values)] ) when Res_parsetree_viewer.is_tuple_array key_values -> diff --git a/jscomp/syntax/tests/parsing/grammar/expressions/expected/dict.res.txt b/jscomp/syntax/tests/parsing/grammar/expressions/expected/dict.res.txt index e289ca062b..f0e8bcb6ee 100644 --- a/jscomp/syntax/tests/parsing/grammar/expressions/expected/dict.res.txt +++ b/jscomp/syntax/tests/parsing/grammar/expressions/expected/dict.res.txt @@ -1,8 +1,7 @@ -let x = Runtime_dict.unsafe_create [||] -let x = Runtime_dict.unsafe_create [|("foo", {js|bar|js})|] -let x = - Runtime_dict.unsafe_create [|("foo", {js|bar|js});("bar", {js|baz|js})|] +let x = Primitive_dict.make [||] +let x = Primitive_dict.make [|("foo", {js|bar|js})|] +let x = Primitive_dict.make [|("foo", {js|bar|js});("bar", {js|baz|js})|] let baz = {js|foo|js} let x = - Runtime_dict.unsafe_create + Primitive_dict.make [|("foo", {js|bar|js});("bar", {js|baz|js});("baz", baz)|] \ No newline at end of file diff --git a/jscomp/syntax/tests/printer/structure/expected/valueBinding.res.txt b/jscomp/syntax/tests/printer/structure/expected/valueBinding.res.txt index 642afd5e9f..ea6d8bd149 100644 --- a/jscomp/syntax/tests/printer/structure/expected/valueBinding.res.txt +++ b/jscomp/syntax/tests/printer/structure/expected/valueBinding.res.txt @@ -22,7 +22,6 @@ let make = () =>
@react.recursiveComponent and otherMake = () =>
-@ocaml.doc(" {b See} {!length} ") -external size: array<'a> => int = "%array_length" +@ocaml.doc(" {b See} {!length} ") @get external size: array<'a> => int = "length" -@ocaml.doc(" {b See} {!length} ") external size: array<'a> => int = "%array_length" +@ocaml.doc(" {b See} {!length} ") @get external size: array<'a> => int = "length" diff --git a/jscomp/syntax/tests/printer/structure/valueBinding.res b/jscomp/syntax/tests/printer/structure/valueBinding.res index eab76aca58..cdda3d1328 100644 --- a/jscomp/syntax/tests/printer/structure/valueBinding.res +++ b/jscomp/syntax/tests/printer/structure/valueBinding.res @@ -24,6 +24,7 @@ let make = () =>
and otherMake = () =>
@ocaml.doc(" {b See} {!length} ") -external size: array<'a> => int = "%array_length" +@get external size: array<'a> => int = "length" -@ocaml.doc(" {b See} {!length} ") external size: array<'a> => int = "%array_length" +@ocaml.doc(" {b See} {!length} ") +@get external size: array<'a> => int = "length" diff --git a/jscomp/test/406_primitive_test.js b/jscomp/test/406_primitive_test.js deleted file mode 100644 index f094d9242d..0000000000 --- a/jscomp/test/406_primitive_test.js +++ /dev/null @@ -1,68 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); - -let suites = { - contents: /* [] */0 -}; - -let test_id = { - contents: 0 -}; - -function eq(loc, x, y) { - Mt.eq_suites(test_id, suites, loc, x, y); -} - -eq("File \"406_primitive_test.res\", line 13, characters 3-10", 32, 32); - -let backend_type = { - TAG: "Other", - _0: "BS" -}; - -eq("File \"406_primitive_test.res\", line 23, characters 3-10", backend_type, { - TAG: "Other", - _0: "BS" -}); - -function f() { - let A = /* @__PURE__ */Caml_exceptions.create("A"); - try { - for (let i = 0; i <= 200; ++i) { - if (i === 10) { - throw { - RE_EXN_ID: A, - _1: 0, - Error: new Error() - }; - } - - } - return; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === A) { - return; - } - throw exn; - } -} - -Mt.from_pair_suites("406_primitive_test", suites.contents); - -let v = 32; - -let max_array_length = /* Max_wosize */2147483647; - -exports.suites = suites; -exports.test_id = test_id; -exports.eq = eq; -exports.v = v; -exports.backend_type = backend_type; -exports.max_array_length = max_array_length; -exports.f = f; -/* Not a pure module */ diff --git a/jscomp/test/406_primitive_test.res b/jscomp/test/406_primitive_test.res deleted file mode 100644 index e2664f83f3..0000000000 --- a/jscomp/test/406_primitive_test.res +++ /dev/null @@ -1,36 +0,0 @@ -let suites: ref = ref(list{}) - -let test_id = ref(0) - -let eq = (loc, x, y): unit => Mt.eq_suites(~test_id, loc, ~suites, x, y) - -external int_size: unit => int = "%int_size" - -external max_wosize: unit => int = "%max_wosize" - -let v = int_size() /* 32 on JS */ - -eq(__LOC__, v, 32) -type backend_type = - | Native - | Bytecode - | Other(string) - -external get_backend_type: unit => backend_type = "%backend_type" -let backend_type = get_backend_type() - -let max_array_length = max_wosize() -eq(__LOC__, backend_type, Other("BS")) - -let f = () => { - exception A(int) - try for i in 0 to 200 { - if i == 10 { - raise(A(0)) - } - } catch { - | A(_) => () - } -} - -Mt.from_pair_suites(__MODULE__, suites.contents) diff --git a/jscomp/test/DictTests.js b/jscomp/test/DictTests.js index c05b1f0f5e..8228a11d00 100644 --- a/jscomp/test/DictTests.js +++ b/jscomp/test/DictTests.js @@ -23,4 +23,4 @@ exports.someString = someString; exports.createdDict = createdDict; exports.three = three; exports.intDict = intDict; -/* createdDict Not a pure module */ +/* No side effect */ diff --git a/jscomp/test/UncurriedExternals.js b/jscomp/test/UncurriedExternals.js index 16c435711e..c90461e203 100644 --- a/jscomp/test/UncurriedExternals.js +++ b/jscomp/test/UncurriedExternals.js @@ -18,8 +18,6 @@ let M = { let hh = M.sum(1.0, 2.0); -let mf = 3 % 4; - function tg(arr) { return arr[0]; } @@ -57,7 +55,6 @@ let StandardNotation = { h: h, M: M, hh: hh, - mf: mf, tg: tg, tc: tc, te: te, diff --git a/jscomp/test/UncurriedExternals.res b/jscomp/test/UncurriedExternals.res index 688c67b1dd..8de1186b81 100644 --- a/jscomp/test/UncurriedExternals.res +++ b/jscomp/test/UncurriedExternals.res @@ -12,9 +12,6 @@ module StandardNotation = { } let hh = M.sum(1.0, 2.0) - external mod_float: (float, float) => float = "?fmod_float" - let mf = mod_float(3., 4.) - @get_index external get: (array, int) => option<'a> = "" let tg = arr => arr->get(0) diff --git a/jscomp/test/UntaggedVariants.js b/jscomp/test/UntaggedVariants.js index 6dab75df61..90742769e6 100644 --- a/jscomp/test/UntaggedVariants.js +++ b/jscomp/test/UntaggedVariants.js @@ -3,8 +3,8 @@ let Js_dict = require("../../lib/js/js_dict.js"); let Belt_Array = require("../../lib/js/belt_Array.js"); -let Caml_array = require("../../lib/js/caml_array.js"); -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_array = require("../../lib/js/primitive_array.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); function classify(x) { if (x === "A" && typeof x !== "number") { @@ -290,7 +290,7 @@ let OverlapObject = { function classify$7(v) { if (Array.isArray(v)) { - return Caml_array.get(v, 0); + return Primitive_array.get(v, 0); } else { return v.x; } @@ -304,7 +304,7 @@ function classify$8(v) { if (typeof v === "object" && !Array.isArray(v)) { return v.x; } else { - return Caml_array.get(v, 0); + return Primitive_array.get(v, 0); } } @@ -317,11 +317,11 @@ function testHasNull(x) { } function testHasUndefined(x) { - return Caml_option.some(x); + return Primitive_option.some(x); } function untaggedWithOptionPayload(x) { - return Caml_option.some(x); + return Primitive_option.some(x); } function untaggedWithIntPayload(x) { @@ -333,11 +333,11 @@ function untaggedInlineNoOptions(x) { } function untaggedInlineUnaryWihtExplicitOption(x) { - return Caml_option.some(x); + return Primitive_option.some(x); } function untaggedInlineUnaryWihtImplicitOption(x) { - return Caml_option.some(x); + return Primitive_option.some(x); } function untaggedInlineMultinaryOption(x) { @@ -357,7 +357,7 @@ let OptionUnboxingHeuristic = { function classify$9(v) { if (Array.isArray(v)) { - return Caml_array.get(v, 0); + return Primitive_array.get(v, 0); } switch (typeof v) { case "object" : diff --git a/jscomp/test/a.js b/jscomp/test/a.js index d856702bfe..1eb4cada7a 100644 --- a/jscomp/test/a.js +++ b/jscomp/test/a.js @@ -1,2 +1,12 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ +'use strict'; + + +function Make(U) { + return { + v: U.compare + }; +} + +exports.Make = Make; +/* No side effect */ diff --git a/jscomp/test/a.res b/jscomp/test/a.res index dbfb1567f4..d6dfa0c868 100644 --- a/jscomp/test/a.res +++ b/jscomp/test/a.res @@ -1,3 +1,12 @@ +module type OrderedType = { + type t + let compare: (t, t) => int +} + +module Make = (U: OrderedType) => { + let v = U.compare +} + include ( { module M = ( @@ -11,20 +20,16 @@ include ( let add = (x, y) => x + y }) + open Belt + include List module N = List let v = N.length - module Make = (U: Set.OrderedType) => { - include U - let v = compare + module Make = (U: OrderedType) => { + let v = U.compare } - module X = Make(String) module U = Make(Test_order) - - include N - /* let v = "xhg" */ - /* let () = v.[0] <- 'a' */ }: {} ) diff --git a/jscomp/test/a_filename_test.js b/jscomp/test/a_filename_test.js deleted file mode 100644 index 1c8fda7a7e..0000000000 --- a/jscomp/test/a_filename_test.js +++ /dev/null @@ -1,128 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let $$Array = require("../../lib/js/array.js"); -let Ext_filename_test = require("./ext_filename_test.js"); - -let suites = { - contents: /* [] */0 -}; - -let test_id = { - contents: 0 -}; - -function eq(loc, x, y) { - test_id.contents = test_id.contents + 1 | 0; - suites.contents = { - hd: [ - loc + (" id " + String(test_id.contents)), - () => ({ - TAG: "Eq", - _0: x, - _1: y - }) - ], - tl: suites.contents - }; -} - -function test(x, y) { - return Ext_filename_test.node_relative_path(true, x, y); -} - -if (process.platform !== "win32") { - eq("File \"a_filename_test.res\", line 16, characters 4-11", [ - Ext_filename_test.combine("/tmp", "subdir/file.txt"), - Ext_filename_test.combine("/tmp", "/a/tmp.txt"), - Ext_filename_test.combine("/a/tmp.txt", "subdir/file.txt") - ], [ - "/tmp/subdir/file.txt", - "/a/tmp.txt", - "/a/tmp.txt/subdir/file.txt" - ]); - eq("File \"a_filename_test.res\", line 28, characters 5-12", Ext_filename_test.node_relative_path(true, { - NAME: "File", - VAL: "./a/b.c" - }, { - NAME: "File", - VAL: "./a/u/g.c" - }), "./u/g.c"); - eq("File \"a_filename_test.res\", line 31, characters 4-11", Ext_filename_test.node_relative_path(true, { - NAME: "File", - VAL: "./a/b.c" - }, { - NAME: "File", - VAL: "xxxghsoghos/ghsoghso/node_modules/buckle-stdlib/list.js" - }), "buckle-stdlib/list.js"); - eq("File \"a_filename_test.res\", line 37, characters 4-11", Ext_filename_test.node_relative_path(true, { - NAME: "File", - VAL: "./a/b.c" - }, { - NAME: "File", - VAL: "xxxghsoghos/ghsoghso/node_modules//buckle-stdlib/list.js" - }), "buckle-stdlib/list.js"); - eq("File \"a_filename_test.res\", line 43, characters 4-11", Ext_filename_test.node_relative_path(true, { - NAME: "File", - VAL: "./a/b.c" - }, { - NAME: "File", - VAL: "xxxghsoghos/ghsoghso/node_modules/./buckle-stdlib/list.js" - }), "buckle-stdlib/list.js"); - eq("File \"a_filename_test.res\", line 48, characters 5-12", Ext_filename_test.node_relative_path(true, { - NAME: "File", - VAL: "./a/c.js" - }, { - NAME: "File", - VAL: "./a/b" - }), "./b"); - eq("File \"a_filename_test.res\", line 49, characters 5-12", Ext_filename_test.node_relative_path(true, { - NAME: "File", - VAL: "./a/c" - }, { - NAME: "File", - VAL: "./a/b.js" - }), "./b.js"); - eq("File \"a_filename_test.res\", line 50, characters 5-12", Ext_filename_test.node_relative_path(true, { - NAME: "Dir", - VAL: "./a/" - }, { - NAME: "File", - VAL: "./a/b.js" - }), "./b.js"); - eq("File \"a_filename_test.res\", line 51, characters 5-12", Ext_filename_test.get_extension("a.txt"), ".txt"); - eq("File \"a_filename_test.res\", line 52, characters 5-12", Ext_filename_test.get_extension("a"), ""); - eq("File \"a_filename_test.res\", line 53, characters 5-12", Ext_filename_test.get_extension(".txt"), ".txt"); - eq("File \"a_filename_test.res\", line 56, characters 4-11", $$Array.map(Ext_filename_test.normalize_absolute_path, [ - "/gsho/./..", - "/a/b/../c../d/e/f", - "/a/b/../c/../d/e/f", - "/gsho/./../..", - "/a/b/c/d", - "/a/b/c/d/", - "/a/", - "/a", - "/a.txt/", - "/a.txt" - ]), [ - "/", - "/a/c../d/e/f", - "/a/d/e/f", - "/", - "/a/b/c/d", - "/a/b/c/d", - "/a", - "/a", - "/a.txt", - "/a.txt" - ]); -} - -Mt.from_pair_suites("A_filename_test", suites.contents); - -exports.suites = suites; -exports.test_id = test_id; -exports.eq = eq; -exports.test = test; -/* Not a pure module */ diff --git a/jscomp/test/a_filename_test.res b/jscomp/test/a_filename_test.res deleted file mode 100644 index d1d7452cc9..0000000000 --- a/jscomp/test/a_filename_test.res +++ /dev/null @@ -1,76 +0,0 @@ -@var @scope("process") -external platform: [#aix | #darwin | #freebsd | #linux | #openbsd | #sunos | #win32] = "platform" - -let suites: ref = ref(list{}) -let test_id = ref(0) -let eq = (loc, x, y) => { - incr(test_id) - suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} -} - -let test = (x, y) => Ext_filename_test.node_relative_path(true, x, y) -let () = /* TODO: adapt these tests to run on Windows. */ -if platform !== #win32 { - eq( - __LOC__, - { - let \"//" = Ext_filename_test.combine - ( - \"//"("/tmp", "subdir/file.txt"), - \"//"("/tmp", "/a/tmp.txt"), - \"//"("/a/tmp.txt", "subdir/file.txt"), - ) - }, - ("/tmp/subdir/file.txt", "/a/tmp.txt", "/a/tmp.txt/subdir/file.txt"), - ) - - eq(__LOC__, test(#File("./a/b.c"), #File("./a/u/g.c")), "./u/g.c") - - eq( - __LOC__, - test(#File("./a/b.c"), #File("xxxghsoghos/ghsoghso/node_modules/buckle-stdlib/list.js")), - "buckle-stdlib/list.js", - ) - - eq( - __LOC__, - test(#File("./a/b.c"), #File("xxxghsoghos/ghsoghso/node_modules//buckle-stdlib/list.js")), - "buckle-stdlib/list.js", - ) - - eq( - __LOC__, - test(#File("./a/b.c"), #File("xxxghsoghos/ghsoghso/node_modules/./buckle-stdlib/list.js")), - "buckle-stdlib/list.js", - ) - - eq(__LOC__, test(#File("./a/c.js"), #File("./a/b")), "./b") - eq(__LOC__, test(#File("./a/c"), #File("./a/b.js")), "./b.js") - eq(__LOC__, test(#Dir("./a/"), #File("./a/b.js")), "./b.js") - eq(__LOC__, Ext_filename_test.get_extension("a.txt"), ".txt") - eq(__LOC__, Ext_filename_test.get_extension("a"), "") - eq(__LOC__, Ext_filename_test.get_extension(".txt"), ".txt") - - eq( - __LOC__, - Array.map( - Ext_filename_test.normalize_absolute_path, - [ - "/gsho/./..", - "/a/b/../c../d/e/f", - "/a/b/../c/../d/e/f", - "/gsho/./../..", - "/a/b/c/d", - "/a/b/c/d/", - "/a/", - "/a", - "/a.txt/", - "/a.txt", - ], - ), - ["/", "/a/c../d/e/f", "/a/d/e/f", "/", "/a/b/c/d", "/a/b/c/d", "/a", "/a", "/a.txt", "/a.txt"], - ) -} - -Mt.from_pair_suites(__MODULE__, suites.contents) diff --git a/jscomp/test/a_list_test.js b/jscomp/test/a_list_test.js deleted file mode 100644 index 7bef3fdfe5..0000000000 --- a/jscomp/test/a_list_test.js +++ /dev/null @@ -1,109 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let Ext_list_test = require("./ext_list_test.js"); - -let suites_0 = [ - "drop", - param => ({ - TAG: "Eq", - _0: Ext_list_test.drop(3, { - hd: 0, - tl: { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - } - }), - _1: /* [] */0 - }) -]; - -let suites_1 = { - hd: [ - "drop1", - param => ({ - TAG: "Eq", - _0: Ext_list_test.drop(2, { - hd: 0, - tl: { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - } - }), - _1: { - hd: 2, - tl: /* [] */0 - } - }) - ], - tl: { - hd: [ - "flat_map", - param => ({ - TAG: "Eq", - _0: { - hd: 0, - tl: { - hd: 0, - tl: { - hd: 1, - tl: { - hd: 1, - tl: { - hd: 0, - tl: /* [] */0 - } - } - } - } - }, - _1: Ext_list_test.flat_map(x => { - if (x % 2 === 0) { - return { - hd: 0, - tl: /* [] */0 - }; - } else { - return { - hd: 1, - tl: { - hd: 1, - tl: /* [] */0 - } - }; - } - }, { - hd: 0, - tl: { - hd: 0, - tl: { - hd: 3, - tl: { - hd: 0, - tl: /* [] */0 - } - } - } - }) - }) - ], - tl: /* [] */0 - } -}; - -let suites = { - hd: suites_0, - tl: suites_1 -}; - -Mt.from_pair_suites("A_list_test", suites); - -exports.suites = suites; -/* Not a pure module */ diff --git a/jscomp/test/a_list_test.res b/jscomp/test/a_list_test.res deleted file mode 100644 index 91975a4198..0000000000 --- a/jscomp/test/a_list_test.res +++ /dev/null @@ -1,17 +0,0 @@ -let suites = { - open Mt - list{ - ("drop", _ => Eq(Ext_list_test.drop(3, list{0, 1, 2}), list{})), - ("drop1", _ => Eq(Ext_list_test.drop(2, list{0, 1, 2}), list{2})), - ("flat_map", _ => Eq(list{0, 0, 1, 1, 0}, Ext_list_test.flat_map(x => - if mod(x, 2) === 0 { - list{0} - } else { - list{1, 1} - } - , list{0, 0, 3, 0}))), - } -} - -open Mt -from_pair_suites(__MODULE__, suites) diff --git a/jscomp/test/a_scope_bug.js b/jscomp/test/a_scope_bug.js index 0a36a2d18c..0e43a28a04 100644 --- a/jscomp/test/a_scope_bug.js +++ b/jscomp/test/a_scope_bug.js @@ -7,7 +7,7 @@ function odd(_z) { let z = _z; let even = Math.imul(z, z); let a = (even + 4 | 0) + even | 0; - console.log(String(a)); + console.log(a.toString()); _z = 32; continue; }; diff --git a/jscomp/test/a_scope_bug.res b/jscomp/test/a_scope_bug.res index cc91c3201c..931f97c101 100644 --- a/jscomp/test/a_scope_bug.res +++ b/jscomp/test/a_scope_bug.res @@ -7,7 +7,7 @@ let rec odd = z => { let even = even * even even + 4 + even } - print_endline(string_of_int(a)) + a->Js.Int.toString->Js.log even(32) } and even = y => odd(y) diff --git a/jscomp/test/a_string_test.js b/jscomp/test/a_string_test.js deleted file mode 100644 index 904650af26..0000000000 --- a/jscomp/test/a_string_test.js +++ /dev/null @@ -1,115 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); -let Ext_string_test = require("./ext_string_test.js"); - -let suites_0 = [ - "split", - param => ({ - TAG: "Eq", - _0: Ext_string_test.split(true, "hihi", /* 'i' */105), - _1: { - hd: "h", - tl: { - hd: "h", - tl: { - hd: "", - tl: /* [] */0 - } - } - } - }) -]; - -let suites_1 = { - hd: [ - "split_non_empty", - param => ({ - TAG: "Eq", - _0: Ext_string_test.split(undefined, "hihi", /* 'i' */105), - _1: { - hd: "h", - tl: { - hd: "h", - tl: /* [] */0 - } - } - }) - ], - tl: { - hd: [ - "split_empty", - param => ({ - TAG: "Eq", - _0: Ext_string_test.split(true, "", /* 'i' */105), - _1: /* [] */0 - }) - ], - tl: { - hd: [ - "split_normal", - param => ({ - TAG: "Eq", - _0: Ext_string_test.split(true, "h i i", /* ' ' */32), - _1: { - hd: "h", - tl: { - hd: "i", - tl: { - hd: "i", - tl: /* [] */0 - } - } - } - }) - ], - tl: { - hd: [ - "split_by", - param => ({ - TAG: "Eq", - _0: List.filter(s => s !== "", Ext_string_test.split_by(undefined, x => { - if (x === /* ' ' */32) { - return true; - } else { - return x === /* '\t' */9; - } - }, "h hgso hgso \t hi")), - _1: { - hd: "h", - tl: { - hd: "hgso", - tl: { - hd: "hgso", - tl: { - hd: "hi", - tl: /* [] */0 - } - } - } - } - }) - ], - tl: /* [] */0 - } - } - } -}; - -let suites = { - hd: suites_0, - tl: suites_1 -}; - -Mt.from_pair_suites("A_string_test", suites); - -let split = Ext_string_test.split; - -let split_by = Ext_string_test.split_by; - -exports.split = split; -exports.split_by = split_by; -exports.suites = suites; -/* Not a pure module */ diff --git a/jscomp/test/a_string_test.res b/jscomp/test/a_string_test.res deleted file mode 100644 index 789f13b40c..0000000000 --- a/jscomp/test/a_string_test.res +++ /dev/null @@ -1,22 +0,0 @@ -let split = Ext_string_test.split - -let split_by = Ext_string_test.split_by - -let suites = { - open Mt - list{ - ("split", _ => Eq(split(~keep_empty=true, "hihi", 'i'), list{"h", "h", ""})), - ("split_non_empty", _ => Eq(split("hihi", 'i'), list{"h", "h"})), - ("split_empty", _ => Eq(split(~keep_empty=true, "", 'i'), list{})), - ("split_normal", _ => Eq(split(~keep_empty=true, "h i i", ' '), list{"h", "i", "i"})), - ( - "split_by", - _ => Eq( - List.filter(s => s != "", split_by(x => x == ' ' || x == '\t', "h hgso hgso \t hi")), - list{"h", "hgso", "hgso", "hi"}, - ), - ), - } -} - -Mt.from_pair_suites(__MODULE__, suites) diff --git a/jscomp/test/alias_test.js b/jscomp/test/alias_test.js index 6c1180a5fc..8ceff5cb6c 100644 --- a/jscomp/test/alias_test.js +++ b/jscomp/test/alias_test.js @@ -1,13 +1,12 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_string = require("../../lib/js/caml_string.js"); let a10 = "hello world"; let a20 = a10 + "not"; -let v = Caml_string.get(a20, 0) === /* 'h' */104 ? 1 : 2; +let v = a20.codePointAt(0) === /* 'h' */104 ? 1 : 2; let a21 = a20 + a20; @@ -29,4 +28,4 @@ exports.a21 = a21; exports.v = v; exports.a23 = a23; exports.ff = ff; -/* a23 Not a pure module */ +/* v Not a pure module */ diff --git a/jscomp/test/argv_test.js b/jscomp/test/argv_test.js deleted file mode 100644 index 727bfd8154..0000000000 --- a/jscomp/test/argv_test.js +++ /dev/null @@ -1,81 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Arg = require("../../lib/js/arg.js"); - -function anno_fun(arg) { - -} - -let usage_msg = "Usage:\n"; - -let compile = { - contents: false -}; - -let test = { - contents: true -}; - -let arg_spec_0 = [ - "-c", - { - TAG: "Set", - _0: compile - }, - " Compile" -]; - -let arg_spec_1 = { - hd: [ - "-d", - { - TAG: "Clear", - _0: test - }, - " Test" - ], - tl: /* [] */0 -}; - -let arg_spec = { - hd: arg_spec_0, - tl: arg_spec_1 -}; - -Arg.parse_argv(undefined, [ - "prog.exe", - "-c", - "-d" -], arg_spec, anno_fun, usage_msg); - -if (compile.contents !== true) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "argv_test.res", - 14, - 2 - ], - Error: new Error() - }; -} - -if (test.contents !== false) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "argv_test.res", - 15, - 2 - ], - Error: new Error() - }; -} - -exports.anno_fun = anno_fun; -exports.usage_msg = usage_msg; -exports.compile = compile; -exports.test = test; -exports.arg_spec = arg_spec; -/* Not a pure module */ diff --git a/jscomp/test/argv_test.res b/jscomp/test/argv_test.res deleted file mode 100644 index 37455729be..0000000000 --- a/jscomp/test/argv_test.res +++ /dev/null @@ -1,16 +0,0 @@ -let anno_fun = arg => () -/* Js.log arg */ -let usage_msg = "Usage:\n" -let compile = ref(false) -let test = ref(true) -let arg_spec = { - open Arg - list{("-c", Set(compile), " Compile"), ("-d", Clear(test), " Test")} -} - -Arg.parse_argv(["prog.exe", "-c", "-d"], arg_spec, anno_fun, usage_msg) - -{ - assert(compile.contents == true) - assert(test.contents == false) -} diff --git a/jscomp/test/arith_lexer.js b/jscomp/test/arith_lexer.js deleted file mode 100644 index 6d54073905..0000000000 --- a/jscomp/test/arith_lexer.js +++ /dev/null @@ -1,188 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Lexing = require("../../lib/js/lexing.js"); -let Pervasives = require("../../lib/js/pervasives.js"); -let Caml_format = require("../../lib/js/caml_format.js"); - -let __ocaml_lex_tables = { - lex_base: "\x00\x00\xf6\xff\xf7\xff\xf8\xff\xf9\xff\xfa\xff\xfb\xff\xfc\xff\ - \x3a\x00\x85\x00\xff\xff", - lex_backtrk: "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \x02\x00\x01\x00\xff\xff", - lex_default: "\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \xff\xff\xff\xff\x00\x00", - lex_trans: "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x0a\x00\x0a\x00\x00\x00\x00\x00\x0a\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x03\x00\x02\x00\x05\x00\x07\x00\x00\x00\x06\x00\x00\x00\x04\x00\ - \x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\ - \x09\x00\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x09\x00\x09\x00\x09\x00\ - \x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", - lex_check: "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\xff\xff\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x09\x00\x09\x00\x09\x00\ - \x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", - lex_base_code: "", - lex_backtrk_code: "", - lex_default_code: "", - lex_trans_code: "", - lex_check_code: "", - lex_code: "" -}; - -function __ocaml_lex_lexeme_rec(lexbuf, ___ocaml_lex_state) { - while (true) { - let __ocaml_lex_state = ___ocaml_lex_state; - let __ocaml_lex_state$1 = Lexing.engine(__ocaml_lex_tables, __ocaml_lex_state, lexbuf); - switch (__ocaml_lex_state$1) { - case 0 : - ___ocaml_lex_state = 0; - continue; - case 1 : - return { - TAG: "NUMERAL", - _0: Caml_format.int_of_string(Lexing.lexeme(lexbuf)) - }; - case 2 : - return { - TAG: "IDENT", - _0: Lexing.lexeme(lexbuf) - }; - case 3 : - return "PLUS"; - case 4 : - return "MINUS"; - case 5 : - return "TIMES"; - case 6 : - return "DIVIDE"; - case 7 : - return "LPAREN"; - case 8 : - return "RPAREN"; - case 9 : - return "EOF"; - default: - lexbuf.refill_buff(lexbuf); - ___ocaml_lex_state = __ocaml_lex_state$1; - continue; - } - }; -} - -function lexeme(lexbuf) { - return __ocaml_lex_lexeme_rec(lexbuf, 0); -} - -function str(e) { - switch (e.TAG) { - case "Numeral" : - return Pervasives.string_of_float(e._0); - case "Plus" : - return str(e._0) + ("+" + str(e._1)); - case "Minus" : - return str(e._0) + ("-" + str(e._1)); - case "Times" : - return str(e._0) + ("*" + str(e._1)); - case "Divide" : - return str(e._0) + ("/" + str(e._1)); - case "Negate" : - return "-" + str(e._0); - case "Variable" : - return e._0; - } -} - -exports.__ocaml_lex_tables = __ocaml_lex_tables; -exports.lexeme = lexeme; -exports.__ocaml_lex_lexeme_rec = __ocaml_lex_lexeme_rec; -exports.str = str; -/* No side effect */ diff --git a/jscomp/test/arith_lexer.res b/jscomp/test/arith_lexer.res deleted file mode 100644 index 12ccee33d6..0000000000 --- a/jscomp/test/arith_lexer.res +++ /dev/null @@ -1,155 +0,0 @@ -open Arith_parser - -let __ocaml_lex_tables = { - Lexing.lex_base: "\x00\x00\xf6\xff\xf7\xff\xf8\xff\xf9\xff\xfa\xff\xfb\xff\xfc\xff\ - \x3a\x00\x85\x00\xff\xff", - Lexing.lex_backtrk: "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \x02\x00\x01\x00\xff\xff", - Lexing.lex_default: "\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \xff\xff\xff\xff\x00\x00", - Lexing.lex_trans: "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x0a\x00\x0a\x00\x00\x00\x00\x00\x0a\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x03\x00\x02\x00\x05\x00\x07\x00\x00\x00\x06\x00\x00\x00\x04\x00\ - \x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\ - \x09\x00\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x09\x00\x09\x00\x09\x00\ - \x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", - Lexing.lex_check: "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\xff\xff\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x09\x00\x09\x00\x09\x00\ - \x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", - Lexing.lex_base_code: "", - Lexing.lex_backtrk_code: "", - Lexing.lex_default_code: "", - Lexing.lex_trans_code: "", - Lexing.lex_check_code: "", - Lexing.lex_code: "", -} - -let rec lexeme = lexbuf => __ocaml_lex_lexeme_rec(lexbuf, 0) -and __ocaml_lex_lexeme_rec = (lexbuf, __ocaml_lex_state) => - switch Lexing.engine(__ocaml_lex_tables, __ocaml_lex_state, lexbuf) { - | 0 => lexeme(lexbuf) - - | 1 => NUMERAL(float(int_of_string(Lexing.lexeme(lexbuf)))) - - | 2 => IDENT(Lexing.lexeme(lexbuf)) - - | 3 => PLUS - - | 4 => MINUS - - | 5 => TIMES - - | 6 => DIVIDE - - | 7 => LPAREN - - | 8 => RPAREN - - | 9 => EOF - - | __ocaml_lex_state => - lexbuf.Lexing.refill_buff(lexbuf) - __ocaml_lex_lexeme_rec(lexbuf, __ocaml_lex_state) - } -open Arith_syntax -let rec str = e => - switch e { - | Numeral(f) => string_of_float(f) - | Plus(a, b) => str(a) ++ ("+" ++ str(b)) - | Minus(a, b) => str(a) ++ ("-" ++ str(b)) - | Times(a, b) => str(a) ++ ("*" ++ str(b)) - | Divide(a, b) => str(a) ++ ("/" ++ str(b)) - | Negate(a) => "-" ++ str(a) - | Variable(s) => s - } - -/* let _ = Parsing.set_trace true;; */ diff --git a/jscomp/test/arith_parser.js b/jscomp/test/arith_parser.js deleted file mode 100644 index a7e951781d..0000000000 --- a/jscomp/test/arith_parser.js +++ /dev/null @@ -1,259 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Parsing = require("../../lib/js/parsing.js"); - -let yytransl_const = [ - 259, - 260, - 261, - 262, - 263, - 264, - 265, - 0, - 0 -]; - -let yytransl_block = [ - 257, - 258, - 0 -]; - -let yylhs = "\xff\xff\ -\x01\x00\x02\x00\x02\x00\x02\x00\x02\x00\x02\x00\x02\x00\x02\x00\ -\x02\x00\x00\x00"; - -let yylen = "\x02\x00\ -\x02\x00\x01\x00\x01\x00\x03\x00\x03\x00\x03\x00\x03\x00\x02\x00\ -\x03\x00\x02\x00"; - -let yydefred = "\x00\x00\ -\x00\x00\x00\x00\x02\x00\x03\x00\x00\x00\x00\x00\x0a\x00\x00\x00\ -\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x09\x00\ -\x00\x00\x00\x00\x06\x00\x07\x00"; - -let yydgoto = "\x02\x00\ -\x07\x00\x08\x00"; - -let yysindex = "\xff\xff\ -\x10\xff\x00\x00\x00\x00\x00\x00\x10\xff\x10\xff\x00\x00\x0a\x00\ -\x00\x00\x16\xff\x10\xff\x10\xff\x10\xff\x10\xff\x00\x00\x00\x00\ -\xff\xfe\xff\xfe\x00\x00\x00\x00"; - -let yyrindex = "\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x01\x00\x03\x00\x00\x00\x00\x00"; - -let yygindex = "\x00\x00\ -\x00\x00\x02\x00"; - -let yytable = "\x01\x00\ -\x04\x00\x00\x00\x05\x00\x0d\x00\x0e\x00\x00\x00\x09\x00\x0a\x00\ -\x00\x00\x0f\x00\x00\x00\x00\x00\x11\x00\x12\x00\x13\x00\x14\x00\ -\x03\x00\x04\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x06\x00\ -\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x00\x00\x00\x00\x10\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x04\x00\x04\x00\x05\x00\x05\x00\x00\x00\ -\x00\x00\x04\x00\x00\x00\x05\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00"; - -let yycheck = "\x01\x00\ -\x00\x00\xff\xff\x00\x00\x05\x01\x06\x01\xff\xff\x05\x00\x06\x00\ -\xff\xff\x00\x00\xff\xff\xff\xff\x0b\x00\x0c\x00\x0d\x00\x0e\x00\ -\x01\x01\x02\x01\xff\xff\x04\x01\xff\xff\xff\xff\xff\xff\x08\x01\ -\x03\x01\x04\x01\x05\x01\x06\x01\xff\xff\xff\xff\x09\x01\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\x03\x01\x04\x01\x03\x01\x04\x01\xff\xff\ -\xff\xff\x09\x01\xff\xff\x09\x01\x03\x01\x04\x01\x05\x01\x06\x01"; - -let yynames_const = "\ - PLUS\x00\ - MINUS\x00\ - TIMES\x00\ - DIVIDE\x00\ - UMINUS\x00\ - LPAREN\x00\ - RPAREN\x00\ - EOF\x00\ - "; - -let yynames_block = "\ - NUMERAL\x00\ - IDENT\x00\ - "; - -let yyact = [ - param => { - throw { - RE_EXN_ID: "Failure", - _1: "parser", - Error: new Error() - }; - }, - __caml_parser_env => Parsing.peek_val(__caml_parser_env, 1), - __caml_parser_env => { - let _1 = Parsing.peek_val(__caml_parser_env, 0); - return { - TAG: "Numeral", - _0: _1 - }; - }, - __caml_parser_env => { - let _1 = Parsing.peek_val(__caml_parser_env, 0); - return { - TAG: "Variable", - _0: _1 - }; - }, - __caml_parser_env => { - let _1 = Parsing.peek_val(__caml_parser_env, 2); - let _3 = Parsing.peek_val(__caml_parser_env, 0); - return { - TAG: "Plus", - _0: _1, - _1: _3 - }; - }, - __caml_parser_env => { - let _1 = Parsing.peek_val(__caml_parser_env, 2); - let _3 = Parsing.peek_val(__caml_parser_env, 0); - return { - TAG: "Minus", - _0: _1, - _1: _3 - }; - }, - __caml_parser_env => { - let _1 = Parsing.peek_val(__caml_parser_env, 2); - let _3 = Parsing.peek_val(__caml_parser_env, 0); - return { - TAG: "Times", - _0: _1, - _1: _3 - }; - }, - __caml_parser_env => { - let _1 = Parsing.peek_val(__caml_parser_env, 2); - let _3 = Parsing.peek_val(__caml_parser_env, 0); - return { - TAG: "Divide", - _0: _1, - _1: _3 - }; - }, - __caml_parser_env => { - let _2 = Parsing.peek_val(__caml_parser_env, 0); - return { - TAG: "Negate", - _0: _2 - }; - }, - __caml_parser_env => Parsing.peek_val(__caml_parser_env, 1), - __caml_parser_env => { - throw { - RE_EXN_ID: Parsing.YYexit, - _1: Parsing.peek_val(__caml_parser_env, 0), - Error: new Error() - }; - } -]; - -let yytables = { - actions: yyact, - transl_const: yytransl_const, - transl_block: yytransl_block, - lhs: yylhs, - len: yylen, - defred: yydefred, - dgoto: yydgoto, - sindex: yysindex, - rindex: yyrindex, - gindex: yygindex, - tablesize: 272, - table: yytable, - check: yycheck, - error_function: Parsing.parse_error, - names_const: yynames_const, - names_block: yynames_block -}; - -function toplevel(lexfun, lexbuf) { - return Parsing.yyparse(yytables, 1, lexfun, lexbuf); -} - -let yytablesize = 272; - -exports.yytransl_const = yytransl_const; -exports.yytransl_block = yytransl_block; -exports.yylhs = yylhs; -exports.yylen = yylen; -exports.yydefred = yydefred; -exports.yydgoto = yydgoto; -exports.yysindex = yysindex; -exports.yyrindex = yyrindex; -exports.yygindex = yygindex; -exports.yytablesize = yytablesize; -exports.yytable = yytable; -exports.yycheck = yycheck; -exports.yynames_const = yynames_const; -exports.yynames_block = yynames_block; -exports.yyact = yyact; -exports.yytables = yytables; -exports.toplevel = toplevel; -/* No side effect */ diff --git a/jscomp/test/arith_parser.res b/jscomp/test/arith_parser.res deleted file mode 100644 index 0e051be8aa..0000000000 --- a/jscomp/test/arith_parser.res +++ /dev/null @@ -1,213 +0,0 @@ -type token = - | NUMERAL(float) - | IDENT(string) - | PLUS - | MINUS - | TIMES - | DIVIDE - | UMINUS - | LPAREN - | RPAREN - | EOF - -open Parsing -let _ = parse_error -open Arith_syntax - -let yytransl_const = [ - 259 /* PLUS */, - 260 /* MINUS */, - 261 /* TIMES */, - 262 /* DIVIDE */, - 263 /* UMINUS */, - 264 /* LPAREN */, - 265 /* RPAREN */, - 0 /* EOF */, - 0, -] - -let yytransl_block = [257 /* NUMERAL */, 258 /* IDENT */, 0] - -let yylhs = "\xff\xff\ -\x01\x00\x02\x00\x02\x00\x02\x00\x02\x00\x02\x00\x02\x00\x02\x00\ -\x02\x00\x00\x00" - -let yylen = "\x02\x00\ -\x02\x00\x01\x00\x01\x00\x03\x00\x03\x00\x03\x00\x03\x00\x02\x00\ -\x03\x00\x02\x00" - -let yydefred = "\x00\x00\ -\x00\x00\x00\x00\x02\x00\x03\x00\x00\x00\x00\x00\x0a\x00\x00\x00\ -\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x09\x00\ -\x00\x00\x00\x00\x06\x00\x07\x00" - -let yydgoto = "\x02\x00\ -\x07\x00\x08\x00" - -let yysindex = "\xff\xff\ -\x10\xff\x00\x00\x00\x00\x00\x00\x10\xff\x10\xff\x00\x00\x0a\x00\ -\x00\x00\x16\xff\x10\xff\x10\xff\x10\xff\x10\xff\x00\x00\x00\x00\ -\xff\xfe\xff\xfe\x00\x00\x00\x00" - -let yyrindex = "\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x01\x00\x03\x00\x00\x00\x00\x00" - -let yygindex = "\x00\x00\ -\x00\x00\x02\x00" - -let yytablesize = 272 -let yytable = "\x01\x00\ -\x04\x00\x00\x00\x05\x00\x0d\x00\x0e\x00\x00\x00\x09\x00\x0a\x00\ -\x00\x00\x0f\x00\x00\x00\x00\x00\x11\x00\x12\x00\x13\x00\x14\x00\ -\x03\x00\x04\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x06\x00\ -\x0b\x00\x0c\x00\x0d\x00\x0e\x00\x00\x00\x00\x00\x10\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ -\x00\x00\x00\x00\x00\x00\x04\x00\x04\x00\x05\x00\x05\x00\x00\x00\ -\x00\x00\x04\x00\x00\x00\x05\x00\x0b\x00\x0c\x00\x0d\x00\x0e\x00" - -let yycheck = "\x01\x00\ -\x00\x00\xff\xff\x00\x00\x05\x01\x06\x01\xff\xff\x05\x00\x06\x00\ -\xff\xff\x00\x00\xff\xff\xff\xff\x0b\x00\x0c\x00\x0d\x00\x0e\x00\ -\x01\x01\x02\x01\xff\xff\x04\x01\xff\xff\xff\xff\xff\xff\x08\x01\ -\x03\x01\x04\x01\x05\x01\x06\x01\xff\xff\xff\xff\x09\x01\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ -\xff\xff\xff\xff\xff\xff\x03\x01\x04\x01\x03\x01\x04\x01\xff\xff\ -\xff\xff\x09\x01\xff\xff\x09\x01\x03\x01\x04\x01\x05\x01\x06\x01" - -let yynames_const = "\ - PLUS\x00\ - MINUS\x00\ - TIMES\x00\ - DIVIDE\x00\ - UMINUS\x00\ - LPAREN\x00\ - RPAREN\x00\ - EOF\x00\ - " - -let yynames_block = "\ - NUMERAL\x00\ - IDENT\x00\ - " - -let yyact = [ - _ => failwith("parser"), - __caml_parser_env => { - let _1: 'expression = Parsing.peek_val(__caml_parser_env, 1) - Obj.repr((_1: Arith_syntax.expression)) - }, - __caml_parser_env => { - let _1: float = Parsing.peek_val(__caml_parser_env, 0) - Obj.repr((Numeral(_1): 'expression)) - }, - __caml_parser_env => { - let _1: string = Parsing.peek_val(__caml_parser_env, 0) - Obj.repr((Variable(_1): 'expression)) - }, - __caml_parser_env => { - let _1: 'expression = Parsing.peek_val(__caml_parser_env, 2) - let _3: 'expression = Parsing.peek_val(__caml_parser_env, 0) - Obj.repr((Plus(_1, _3): 'expression)) - }, - __caml_parser_env => { - let _1: 'expression = Parsing.peek_val(__caml_parser_env, 2) - let _3: 'expression = Parsing.peek_val(__caml_parser_env, 0) - Obj.repr((Minus(_1, _3): 'expression)) - }, - __caml_parser_env => { - let _1: 'expression = Parsing.peek_val(__caml_parser_env, 2) - let _3: 'expression = Parsing.peek_val(__caml_parser_env, 0) - Obj.repr((Times(_1, _3): 'expression)) - }, - __caml_parser_env => { - let _1: 'expression = Parsing.peek_val(__caml_parser_env, 2) - let _3: 'expression = Parsing.peek_val(__caml_parser_env, 0) - Obj.repr((Divide(_1, _3): 'expression)) - }, - __caml_parser_env => { - let _2: 'expression = Parsing.peek_val(__caml_parser_env, 0) - Obj.repr((Negate(_2): 'expression)) - }, - __caml_parser_env => { - let _2: 'expression = Parsing.peek_val(__caml_parser_env, 1) - Obj.repr((_2: 'expression)) - }, - /* Entry toplevel */ - __caml_parser_env => raise(Parsing.YYexit(Parsing.peek_val(__caml_parser_env, 0))), -] -let yytables = { - Parsing.actions: yyact, - Parsing.transl_const: yytransl_const, - Parsing.transl_block: yytransl_block, - Parsing.lhs: yylhs, - Parsing.len: yylen, - Parsing.defred: yydefred, - Parsing.dgoto: yydgoto, - Parsing.sindex: yysindex, - Parsing.rindex: yyrindex, - Parsing.gindex: yygindex, - Parsing.tablesize: yytablesize, - Parsing.table: yytable, - Parsing.check: yycheck, - Parsing.error_function: parse_error, - Parsing.names_const: yynames_const, - Parsing.names_block: yynames_block, -} -let toplevel = (lexfun: Lexing.lexbuf => token, lexbuf: Lexing.lexbuf): Arith_syntax.expression => - Parsing.yyparse(yytables, 1, lexfun, lexbuf) diff --git a/jscomp/test/arith_syntax.js b/jscomp/test/arith_syntax.js index 250f53064e..64ed0baced 100644 --- a/jscomp/test/arith_syntax.js +++ b/jscomp/test/arith_syntax.js @@ -1,12 +1,11 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Pervasives = require("../../lib/js/pervasives.js"); function str(e) { switch (e.TAG) { case "Numeral" : - return Pervasives.string_of_float(e._0); + return e._0.toString(); case "Plus" : return str(e._0) + ("+" + str(e._1)); case "Minus" : diff --git a/jscomp/test/arith_syntax.res b/jscomp/test/arith_syntax.res index fbb77f3ea7..f47f4e8665 100644 --- a/jscomp/test/arith_syntax.res +++ b/jscomp/test/arith_syntax.res @@ -9,7 +9,7 @@ type rec expression = let rec str = e => switch e { - | Numeral(f) => string_of_float(f) + | Numeral(f) => f->Js.Float.toString | Plus(a, b) => str(a) ++ ("+" ++ str(b)) | Minus(a, b) => str(a) ++ ("-" ++ str(b)) | Times(a, b) => str(a) ++ ("*" ++ str(b)) diff --git a/jscomp/test/arity_deopt.js b/jscomp/test/arity_deopt.js index c742f2512d..2ee8396746 100644 --- a/jscomp/test/arity_deopt.js +++ b/jscomp/test/arity_deopt.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -42,13 +42,13 @@ function f3(x) { return (y, z) => (x + y | 0) + z | 0; } -eq("File \"arity_deopt.res\", line 47, characters 11-18", 6, 6); +eq("File \"arity_deopt.res\", line 50, characters 11-18", 6, 6); -eq("File \"arity_deopt.res\", line 48, characters 11-18", 6, 6); +eq("File \"arity_deopt.res\", line 51, characters 11-18", 6, 6); -eq("File \"arity_deopt.res\", line 49, characters 11-18", 6, 6); +eq("File \"arity_deopt.res\", line 52, characters 11-18", 6, 6); -eq("File \"arity_deopt.res\", line 50, characters 11-18", 6, 6); +eq("File \"arity_deopt.res\", line 53, characters 11-18", 6, 6); Mt.from_pair_suites("Arity_deopt", suites.contents); diff --git a/jscomp/test/arity_deopt.res b/jscomp/test/arity_deopt.res index c0f6dcb5ca..954ecef6c1 100644 --- a/jscomp/test/arity_deopt.res +++ b/jscomp/test/arity_deopt.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } /* let f = fun x y */ diff --git a/jscomp/test/array_safe_get.js b/jscomp/test/array_safe_get.js index 8a669d3822..0aea7466e0 100644 --- a/jscomp/test/array_safe_get.js +++ b/jscomp/test/array_safe_get.js @@ -1,8 +1,8 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_array = require("../../lib/js/caml_array.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); +let Primitive_array = require("../../lib/js/primitive_array.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); let x = [ 1, @@ -12,9 +12,9 @@ let x = [ let y; try { - y = Caml_array.get(x, 3); + y = Primitive_array.get(x, 3); } catch (raw_msg) { - let msg = Caml_js_exceptions.internalToOCamlException(raw_msg); + let msg = Primitive_exceptions.internalToException(raw_msg); if (msg.RE_EXN_ID === "Invalid_argument") { console.log(msg._1); y = 0; diff --git a/jscomp/test/array_safe_get.res b/jscomp/test/array_safe_get.res index 7c8501265e..436efebb50 100644 --- a/jscomp/test/array_safe_get.res +++ b/jscomp/test/array_safe_get.res @@ -1,6 +1,6 @@ let x = [1, 2] let y = try x[3] catch { | Invalid_argument(msg) => - print_endline(msg) + Js.log(msg) 0 } diff --git a/jscomp/test/array_subtle_test.js b/jscomp/test/array_subtle_test.js index 4233f2ef8d..551e03d747 100644 --- a/jscomp/test/array_subtle_test.js +++ b/jscomp/test/array_subtle_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_array = require("../../lib/js/caml_array.js"); +let Primitive_array = require("../../lib/js/primitive_array.js"); let suites = { contents: /* [] */0 @@ -18,7 +18,7 @@ function eq(loc, param) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -36,43 +36,43 @@ let v = [ 3 ]; -eq("File \"array_subtle_test.res\", line 11, characters 12-19", [ +eq("File \"array_subtle_test.res\", line 14, characters 12-19", [ 4, v.length ]); -eq("File \"array_subtle_test.res\", line 14, characters 5-12", [ +eq("File \"array_subtle_test.res\", line 17, characters 5-12", [ 5, v.push(3) ]); -eq("File \"array_subtle_test.res\", line 15, characters 5-12", [ +eq("File \"array_subtle_test.res\", line 18, characters 5-12", [ 5, v.length ]); -eq("File \"array_subtle_test.res\", line 16, characters 5-12", [ +eq("File \"array_subtle_test.res\", line 19, characters 5-12", [ 5, v.length ]); -eq("File \"array_subtle_test.res\", line 20, characters 5-12", [ +eq("File \"array_subtle_test.res\", line 23, characters 5-12", [ 3, - Caml_array.get(v, 2) + Primitive_array.get(v, 2) ]); -Caml_array.set(v, 2, 4); +Primitive_array.set(v, 2, 4); -eq("File \"array_subtle_test.res\", line 22, characters 5-12", [ +eq("File \"array_subtle_test.res\", line 25, characters 5-12", [ 4, - Caml_array.get(v, 2) + Primitive_array.get(v, 2) ]); while (v.length > 0) { v.pop(); }; -eq("File \"array_subtle_test.res\", line 29, characters 5-12", [ +eq("File \"array_subtle_test.res\", line 32, characters 5-12", [ 0, v.length ]); @@ -111,17 +111,17 @@ function fff4(x) { } } -eq("File \"array_subtle_test.res\", line 61, characters 3-10", [ +eq("File \"array_subtle_test.res\", line 64, characters 3-10", [ fff3([]), 1 ]); -eq("File \"array_subtle_test.res\", line 62, characters 3-10", [ +eq("File \"array_subtle_test.res\", line 65, characters 3-10", [ fff4([]), 2 ]); -eq("File \"array_subtle_test.res\", line 63, characters 3-10", [ +eq("File \"array_subtle_test.res\", line 66, characters 3-10", [ fff4([1]), 1 ]); diff --git a/jscomp/test/array_subtle_test.res b/jscomp/test/array_subtle_test.res index 59db33eded..a24b8a460e 100644 --- a/jscomp/test/array_subtle_test.res +++ b/jscomp/test/array_subtle_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, (x, y)) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let v = [1, 2, 3, 3] diff --git a/jscomp/test/array_test.js b/jscomp/test/array_test.js deleted file mode 100644 index 6a896b1c6b..0000000000 --- a/jscomp/test/array_test.js +++ /dev/null @@ -1,339 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let Caml = require("../../lib/js/caml.js"); -let List = require("../../lib/js/list.js"); -let $$Array = require("../../lib/js/array.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); -let Caml_array = require("../../lib/js/caml_array.js"); -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); - -function starts_with(xs, prefix, p) { - let H = /* @__PURE__ */Caml_exceptions.create("H"); - let len1 = xs.length; - let len2 = prefix.length; - if (len2 > len1) { - return false; - } - try { - for (let i = 0; i < len2; ++i) { - if (!p(Caml_array.get(xs, i), Caml_array.get(prefix, i))) { - throw { - RE_EXN_ID: H, - Error: new Error() - }; - } - - } - return true; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === H) { - return false; - } - throw exn; - } -} - -function is_sorted(x) { - let len = x.length; - let _i = 0; - while (true) { - let i = _i; - if (i >= (len - 1 | 0)) { - return true; - } - if (!Caml_obj.lessthan(Caml_array.get(x, i), Caml_array.get(x, i + 1 | 0))) { - return false; - } - _i = i + 1 | 0; - continue; - }; -} - -let array_suites_0 = [ - "init", - param => ({ - TAG: "Eq", - _0: $$Array.init(5, x => x), - _1: [ - 0, - 1, - 2, - 3, - 4 - ] - }) -]; - -let array_suites_1 = { - hd: [ - "toList", - param => { - let aux = xs => List.fold_left((acc, param) => ({ - hd: [ - $$Array.to_list(param[0]), - param[1] - ], - tl: acc - }), /* [] */0, xs); - let match = List.split(aux({ - hd: [ - [], - /* [] */0 - ], - tl: /* [] */0 - })); - return { - TAG: "Eq", - _0: match[0], - _1: match[1] - }; - } - ], - tl: { - hd: [ - "concat", - param => ({ - TAG: "Eq", - _0: [ - 0, - 1, - 2, - 3, - 4, - 5 - ], - _1: Caml_array.concat({ - hd: [ - 0, - 1, - 2 - ], - tl: { - hd: [ - 3, - 4 - ], - tl: { - hd: [], - tl: { - hd: [5], - tl: /* [] */0 - } - } - } - }) - }) - ], - tl: { - hd: [ - "make", - param => ({ - TAG: "Eq", - _0: [ - Caml_array.make(100, /* 'a' */97), - Caml_array.make_float(100) - ], - _1: [ - $$Array.init(100, param => /* 'a' */97), - $$Array.init(100, param => 0) - ] - }) - ], - tl: { - hd: [ - "sub", - param => ({ - TAG: "Eq", - _0: $$Array.sub([ - 0, - 1, - 2, - 3, - 4 - ], 2, 2), - _1: [ - 2, - 3 - ] - }) - ], - tl: { - hd: [ - "blit", - param => { - let u = [ - 100, - 0, - 0 - ]; - let v = $$Array.init(3, x => (x << 1)); - $$Array.blit(v, 1, u, 1, 2); - return { - TAG: "Eq", - _0: [ - [ - 0, - 2, - 4 - ], - [ - 100, - 2, - 4 - ] - ], - _1: [ - v, - u - ] - }; - } - ], - tl: { - hd: [ - "File \"array_test.res\", line 75, characters 8-15", - param => { - let a0 = $$Array.init(100, i => (i << 0)); - $$Array.blit(a0, 10, a0, 5, 20); - return { - TAG: "Eq", - _0: true, - _1: starts_with(a0, [ - 0, - 1, - 2, - 3, - 4, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20, - 21, - 22, - 23, - 24, - 25, - 26, - 27, - 28 - ], (prim0, prim1) => prim0 === prim1) - }; - } - ], - tl: { - hd: [ - "File \"array_test.res\", line 118, characters 8-15", - param => { - let a0 = $$Array.init(100, i => (i << 0)); - $$Array.blit(a0, 5, a0, 10, 20); - return { - TAG: "Eq", - _0: true, - _1: starts_with(a0, [ - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20 - ], (prim0, prim1) => prim0 === prim1) - }; - } - ], - tl: { - hd: [ - "make", - param => ({ - TAG: "Eq", - _0: Caml_array.make(2, 1), - _1: [ - 1, - 1 - ] - }) - ], - tl: { - hd: [ - "sort", - param => { - let u = [ - 3, - 0, - 1 - ]; - $$Array.sort(Caml.int_compare, u); - return { - TAG: "Eq", - _0: Caml_obj.equal([ - 0, - 1, - 3 - ], u), - _1: true - }; - } - ], - tl: { - hd: [ - "sort_large", - param => { - let v = $$Array.init(4, i => i % 17); - $$Array.sort(Caml.int_compare, v); - return { - TAG: "Eq", - _0: true, - _1: is_sorted(v) - }; - } - ], - tl: /* [] */0 - } - } - } - } - } - } - } - } - } -}; - -let array_suites = { - hd: array_suites_0, - tl: array_suites_1 -}; - -Mt.from_pair_suites("Array_test", array_suites); - -/* Not a pure module */ diff --git a/jscomp/test/array_test.res b/jscomp/test/array_test.res deleted file mode 100644 index a09f495ceb..0000000000 --- a/jscomp/test/array_test.res +++ /dev/null @@ -1,189 +0,0 @@ -open Mt - -module type ARRAY = module type of Array -module Make = (Array: ARRAY) => { - let starts_with = (xs, prefix, p) => { - module X = { - exception H - } - let (len1, len2) = { - open Array - (length(xs), length(prefix)) - } - if len2 > len1 { - false - } else { - try { - for i in 0 to len2 - 1 { - if \"@@"(not, p(xs[i], prefix[i])) { - raise(X.H) - } - } - true - } catch { - | X.H => false - } - } - } - - let is_sorted = x => { - let len = Array.length(x) - let rec aux = i => - if i >= len - 1 { - true - } else if x[i] < x[i + 1] { - aux(i + 1) - } else { - false - } - aux(0) - } - - let array_suites = { - open Mt - list{ - ("init", _ => Eq(Array.init(5, x => x), [0, 1, 2, 3, 4])), - ( - "toList", - _ => { - let aux = (xs: list<(array, list)>) => - List.fold_left((acc, (x, y)) => list{(Array.to_list(x), y), ...acc}, list{}, xs) - - let (a, b) = \"@@"(List.split, aux(list{([], list{})})) - Eq(a, b) - }, - ), - ("concat", _ => Eq([0, 1, 2, 3, 4, 5], Array.concat(list{[0, 1, 2], [3, 4], [], [5]}))), - ( - "make", - _ => Eq( - (Array.make(100, 'a'), Array.make_float(100)), - (Array.init(100, _ => 'a'), Array.init(100, _ => 0.)), - ), - ), - ("sub", _ => Eq(Array.sub([0, 1, 2, 3, 4], 2, 2), [2, 3])), - ( - "blit", - _ => { - let u = [100, 0, 0] - let v = Array.init(3, x => x * 2) - let () = Array.blit(v, 1, u, 1, 2) - Eq(([0, 2, 4], [100, 2, 4]), (v, u)) - }, - ), - ( - __LOC__, - { - open Array - _ => { - let a0 = init(100, i => i * 1) - blit(a0, 10, a0, 5, 20) - Eq( - true, - starts_with( - a0, - [ - 0, - 1, - 2, - 3, - 4, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20, - 21, - 22, - 23, - 24, - 25, - 26, - 27, - 28, - ], - \"=", - ), - ) - } - }, - ), - ( - __LOC__, - { - open Array - _ => { - let a0 = init(100, i => i * 1) - blit(a0, 5, a0, 10, 20) - Eq( - true, - starts_with( - a0, - [ - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20, - ], - \"=", - ), - ) - } - }, - ), - ("make", _ => Eq(Array.make(2, 1), [1, 1])), - ( - "sort", - _ => { - let u = [3, 0, 1] - Array.sort((x: int, y) => Pervasives.compare(x, y), u) - Eq([0, 1, 3] == u, true) /* seems [assert.deepEqual] does not do the right job.. */ - }, - ), - ( - "sort_large", - _ => { - let v = Array.init(4, i => mod(i, 17)) - Array.sort((x: int, y) => compare(x, y), v) - Eq(true, is_sorted(v)) - }, - ), - } - } -} - -from_pair_suites( - __MODULE__, - { - module Array_test = Make(Array) - Array_test.array_suites - }, -) diff --git a/jscomp/test/array_test.resi b/jscomp/test/array_test.resi deleted file mode 100644 index 8b13789179..0000000000 --- a/jscomp/test/array_test.resi +++ /dev/null @@ -1 +0,0 @@ - diff --git a/jscomp/test/ast_abstract_test.js b/jscomp/test/ast_abstract_test.js index c8f1e54872..88aae8310f 100644 --- a/jscomp/test/ast_abstract_test.js +++ b/jscomp/test/ast_abstract_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let Runtime_deriving = require("../../lib/js/runtime_deriving.js"); +let Primitive_util = require("../../lib/js/primitive_util.js"); let suites = { contents: /* [] */0 @@ -16,7 +16,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -62,11 +62,11 @@ function xToJs(param) { } function xFromJs(param) { - return Runtime_deriving.raiseWhenNotFound(_map[param]); + return Primitive_util.raiseWhenNotFound(_map[param]); } function idx(v) { - eq("File \"ast_abstract_test.res\", line 26, characters 18-25", xFromJs(v), v); + eq("File \"ast_abstract_test.res\", line 29, characters 18-25", xFromJs(v), v); } idx("a"); diff --git a/jscomp/test/ast_abstract_test.res b/jscomp/test/ast_abstract_test.res index 6f82b0b063..73e4d2b87e 100644 --- a/jscomp/test/ast_abstract_test.res +++ b/jscomp/test/ast_abstract_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } @deriving({jsConverter: newType}) diff --git a/jscomp/test/async_await.js b/jscomp/test/async_await.js index 3bdca2ae5d..7b2eb2411c 100644 --- a/jscomp/test/async_await.js +++ b/jscomp/test/async_await.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_array = require("../../lib/js/caml_array.js"); +let Primitive_array = require("../../lib/js/primitive_array.js"); function next(n) { return n + 1 | 0; @@ -30,7 +30,7 @@ let arr = [ let toplevelAwait = await topFoo(); -let toplevelAwait2 = Caml_array.get(arr, await topFoo()); +let toplevelAwait2 = Primitive_array.get(arr, await topFoo()); async function f(value) { return await Promise.resolve(1); diff --git a/jscomp/test/bal_set_mini.res b/jscomp/test/bal_set_mini.res index 100e0e6f65..4e3ce3f560 100644 --- a/jscomp/test/bal_set_mini.res +++ b/jscomp/test/bal_set_mini.res @@ -153,7 +153,7 @@ let () = { for i in 0 to iter { if !mem(i, v.contents) { - print_endline("impossible") + Js.log("impossible") } } for i in 0 to iter { @@ -161,6 +161,6 @@ let () = { } switch v.contents { | Empty => () - | Node(_) => print_endline("impossible") + | Node(_) => Js.log("impossible") } } diff --git a/jscomp/test/bang_primitive.js b/jscomp/test/bang_primitive.js deleted file mode 100644 index 3411f211e8..0000000000 --- a/jscomp/test/bang_primitive.js +++ /dev/null @@ -1,25 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - - -function test(x, y) { - return [ - x < y, - x <= y, - x > y, - x >= y, - x === y, - x !== y - ]; -} - -function f(x, y) { - return [ - String.fromCharCode.apply(null, x), - 0 - ]; -} - -exports.test = test; -exports.f = f; -/* No side effect */ diff --git a/jscomp/test/bang_primitive.res b/jscomp/test/bang_primitive.res deleted file mode 100644 index 982f441381..0000000000 --- a/jscomp/test/bang_primitive.res +++ /dev/null @@ -1,32 +0,0 @@ -/* -external log : 'a -> unit = "#console.log" - -external log2 : 'a -> unit = "#console.log" - - -let f x = - log x; - log2 x - */ - -external xx: 'a => string = "#anything_to_string" - -external lt: ('a, 'a) => bool = "#unsafe_lt" -external le: ('a, 'a) => bool = "#unsafe_le" -external gt: ('a, 'a) => bool = "#unsafe_gt" -external ge: ('a, 'a) => bool = "#unsafe_ge" -external eq: ('a, 'a) => bool = "#unsafe_eq" -external neq: ('a, 'a) => bool = "#unsafe_neq" -let test = (x, y) => (lt(x, y), le(x, y), gt(x, y), ge(x, y), eq(x, y), neq(x, y)) - -/* -external append : 'a array -> 'a array -> 'a array = "#array_append" - - -let f x y = append x y -*/ - -@val -external of_small_int_array: (@as(json`null`) _, array) => string = "String.fromCharCode.apply" - -let f = (x, y) => (of_small_int_array(x), 0) diff --git a/jscomp/test/basic_module_test.js b/jscomp/test/basic_module_test.js deleted file mode 100644 index cc66bb5a9e..0000000000 --- a/jscomp/test/basic_module_test.js +++ /dev/null @@ -1,35 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let Offset = require("./offset.js"); -let Pr6726 = require("./pr6726.js"); -let Mt_global = require("./mt_global.js"); - -let count = { - contents: 0 -}; - -function test(set) { - count.contents = Offset.$$Set.cardinal(set) + count.contents | 0; -} - -test(Offset.M.$$Set.singleton("42")); - -let suites = { - contents: /* [] */0 -}; - -let test_id = { - contents: 0 -}; - -function eq(f, a, b) { - Mt_global.collect_eq(test_id, suites, f, a, b); -} - -eq("File \"basic_module_test.res\", line 40, characters 12-19", count.contents, 1); - -Mt.from_pair_suites("Basic_module_test", suites.contents); - -/* Not a pure module */ diff --git a/jscomp/test/basic_module_test.res b/jscomp/test/basic_module_test.res deleted file mode 100644 index 2fecf98317..0000000000 --- a/jscomp/test/basic_module_test.res +++ /dev/null @@ -1,42 +0,0 @@ -/* ********************************************************************* */ -/* */ -/* OCaml */ -/* */ -/* Jacques Garrigue, Nagoya University */ -/* */ -/* Copyright 2014 Institut National de Recherche en Informatique et */ -/* en Automatique. All rights reserved. This file is distributed */ -/* under the terms of the Q Public License version 1.0. */ -/* */ -/* ********************************************************************* */ - -/* PR#6435 */ -let count = ref(0) - -module F = ( - M: { - type t - module Set: Set.S with type elt = t - }, -) => { - let test = set => count := M.Set.cardinal(set) + count.contents -} - -module M = F(Offset) - -let () = M.test(Offset.M.Set.singleton("42")) -/* - here we assume value access does not have side effect - however, the module should be included - since it may contain side effect unless we - analyze it does not have side effect -*/ -let v = Pr6726.Test.v - -let suites: ref = ref(list{}) -let test_id = ref(0) -let eq = (f, a, b) => Mt_global.collect_eq(test_id, suites, f, a, b) - -let () = eq(__LOC__, count.contents, 1) - -let () = Mt.from_pair_suites(__MODULE__, suites.contents) diff --git a/jscomp/test/basic_module_test.resi b/jscomp/test/basic_module_test.resi deleted file mode 100644 index e7bcc98fab..0000000000 --- a/jscomp/test/basic_module_test.resi +++ /dev/null @@ -1 +0,0 @@ -/* val v : int */ diff --git a/jscomp/test/bdd.js b/jscomp/test/bdd.js index ac5c277765..682c45eb8f 100644 --- a/jscomp/test/bdd.js +++ b/jscomp/test/bdd.js @@ -1,7 +1,8 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_array = require("../../lib/js/caml_array.js"); +let Belt_Array = require("../../lib/js/belt_Array.js"); +let Primitive_array = require("../../lib/js/primitive_array.js"); function $$eval(_bdd, vars) { while (true) { @@ -13,7 +14,7 @@ function $$eval(_bdd, vars) { return false; } } - if (Caml_array.get(vars, bdd._1)) { + if (Primitive_array.get(vars, bdd._1)) { _bdd = bdd._3; continue; } @@ -43,7 +44,7 @@ let sz_1 = { }; let htab = { - contents: Caml_array.make(sz_1.contents + 1 | 0, /* [] */0) + contents: Belt_Array.make(sz_1.contents + 1 | 0, /* [] */0) }; let n_items = { @@ -57,7 +58,7 @@ function hashVal(x, y, v) { function resize(newSize) { let arr = htab.contents; let newSz_1 = newSize - 1 | 0; - let newArr = Caml_array.make(newSize, /* [] */0); + let newArr = Belt_Array.make(newSize, /* [] */0); let copyBucket = _bucket => { while (true) { let bucket = _bucket; @@ -88,9 +89,9 @@ function resize(newSize) { }; } else { let ind = hashVal(getId(n._0), getId(n._3), n._1) & newSz_1; - Caml_array.set(newArr, ind, { + Primitive_array.set(newArr, ind, { hd: n, - tl: Caml_array.get(newArr, ind) + tl: Primitive_array.get(newArr, ind) }); _bucket = bucket.tl; continue; @@ -98,7 +99,7 @@ function resize(newSize) { }; }; for (let n = 0, n_finish = sz_1.contents; n <= n_finish; ++n) { - copyBucket(Caml_array.get(arr, n)); + copyBucket(Primitive_array.get(arr, n)); } htab.contents = newArr; sz_1.contents = newSz_1; @@ -106,7 +107,7 @@ function resize(newSize) { function insert(idl, idh, v, ind, bucket, newNode) { if (n_items.contents <= sz_1.contents) { - Caml_array.set(htab.contents, ind, { + Primitive_array.set(htab.contents, ind, { hd: newNode, tl: bucket }); @@ -115,15 +116,15 @@ function insert(idl, idh, v, ind, bucket, newNode) { } resize((sz_1.contents + sz_1.contents | 0) + 2 | 0); let ind$1 = hashVal(idl, idh, v) & sz_1.contents; - Caml_array.set(htab.contents, ind$1, { + Primitive_array.set(htab.contents, ind$1, { hd: newNode, - tl: Caml_array.get(htab.contents, ind$1) + tl: Primitive_array.get(htab.contents, ind$1) }); } function resetUnique() { sz_1.contents = 8191; - htab.contents = Caml_array.make(sz_1.contents + 1 | 0, /* [] */0); + htab.contents = Belt_Array.make(sz_1.contents + 1 | 0, /* [] */0); n_items.contents = 0; nodeC.contents = 1; } @@ -135,7 +136,7 @@ function mkNode(low, v, high) { return low; } let ind = hashVal(idl, idh, v) & sz_1.contents; - let bucket = Caml_array.get(htab.contents, ind); + let bucket = Primitive_array.get(htab.contents, ind); let _b = bucket; while (true) { let b = _b; @@ -198,21 +199,21 @@ function mkVar(x) { return mkNode("Zero", x, "One"); } -let andslot1 = Caml_array.make(1999, 0); +let andslot1 = Belt_Array.make(1999, 0); -let andslot2 = Caml_array.make(1999, 0); +let andslot2 = Belt_Array.make(1999, 0); -let andslot3 = Caml_array.make(1999, "Zero"); +let andslot3 = Belt_Array.make(1999, "Zero"); -let xorslot1 = Caml_array.make(1999, 0); +let xorslot1 = Belt_Array.make(1999, 0); -let xorslot2 = Caml_array.make(1999, 0); +let xorslot2 = Belt_Array.make(1999, 0); -let xorslot3 = Caml_array.make(1999, "Zero"); +let xorslot3 = Belt_Array.make(1999, "Zero"); -let notslot1 = Caml_array.make(1999, 0); +let notslot1 = Belt_Array.make(1999, 0); -let notslot2 = Caml_array.make(1999, "One"); +let notslot2 = Belt_Array.make(1999, "One"); function hash(x, y) { return ((x << 1) + y | 0) % 1999; @@ -228,12 +229,12 @@ function not(n) { } let id = n._2; let h = id % 1999; - if (id === Caml_array.get(notslot1, h)) { - return Caml_array.get(notslot2, h); + if (id === Primitive_array.get(notslot1, h)) { + return Primitive_array.get(notslot2, h); } let f = mkNode(not(n._0), n._1, not(n._3)); - Caml_array.set(notslot1, h, id); - Caml_array.set(notslot2, h, f); + Primitive_array.set(notslot1, h, id); + Primitive_array.set(notslot2, h, f); return f; } @@ -261,8 +262,8 @@ function and2(n1, n2) { let v2 = n2._1; let l2 = n2._0; let h = hash(i1, i2); - if (i1 === Caml_array.get(andslot1, h) && i2 === Caml_array.get(andslot2, h)) { - return Caml_array.get(andslot3, h); + if (i1 === Primitive_array.get(andslot1, h) && i2 === Primitive_array.get(andslot2, h)) { + return Primitive_array.get(andslot3, h); } let match = cmpVar(v1, v2); let f; @@ -277,9 +278,9 @@ function and2(n1, n2) { f = mkNode(and2(n1, l2), v2, and2(n1, r2)); break; } - Caml_array.set(andslot1, h, i1); - Caml_array.set(andslot2, h, i2); - Caml_array.set(andslot3, h, f); + Primitive_array.set(andslot1, h, i1); + Primitive_array.set(andslot2, h, i2); + Primitive_array.set(andslot3, h, f); return f; } @@ -307,8 +308,8 @@ function xor(n1, n2) { let v2 = n2._1; let l2 = n2._0; let h = hash(i1, i2); - if (i1 === Caml_array.get(andslot1, h) && i2 === Caml_array.get(andslot2, h)) { - return Caml_array.get(andslot3, h); + if (i1 === Primitive_array.get(andslot1, h) && i2 === Primitive_array.get(andslot2, h)) { + return Primitive_array.get(andslot3, h); } let match = cmpVar(v1, v2); let f; @@ -323,9 +324,9 @@ function xor(n1, n2) { f = mkNode(xor(n1, l2), v2, xor(n1, r2)); break; } - Caml_array.set(andslot1, h, i1); - Caml_array.set(andslot2, h, i2); - Caml_array.set(andslot3, h, f); + Primitive_array.set(andslot1, h, i1); + Primitive_array.set(andslot2, h, i2); + Primitive_array.set(andslot3, h, f); return f; } @@ -357,9 +358,9 @@ function random() { } function random_vars(n) { - let vars = Caml_array.make(n, false); + let vars = Belt_Array.make(n, false); for (let i = 0; i < n; ++i) { - Caml_array.set(vars, i, random()); + Primitive_array.set(vars, i, random()); } return vars; } @@ -381,12 +382,12 @@ function bool_equal(a, b) { function test_hwb(bdd, vars) { let ntrue = 0; for (let i = 0, i_finish = vars.length; i < i_finish; ++i) { - if (Caml_array.get(vars, i)) { + if (Primitive_array.get(vars, i)) { ntrue = ntrue + 1 | 0; } } - return bool_equal($$eval(bdd, vars), ntrue > 0 ? Caml_array.get(vars, ntrue - 1 | 0) : false); + return bool_equal($$eval(bdd, vars), ntrue > 0 ? Primitive_array.get(vars, ntrue - 1 | 0) : false); } function main() { @@ -402,7 +403,7 @@ function main() { RE_EXN_ID: "Assert_failure", _1: [ "bdd.res", - 301, + 302, 2 ], Error: new Error() @@ -455,4 +456,4 @@ exports.random_vars = random_vars; exports.bool_equal = bool_equal; exports.test_hwb = test_hwb; exports.main = main; -/* Not a pure module */ +/* htab Not a pure module */ diff --git a/jscomp/test/bdd.res b/jscomp/test/bdd.res index 109d61da03..3b22084a5e 100644 --- a/jscomp/test/bdd.res +++ b/jscomp/test/bdd.res @@ -39,14 +39,14 @@ let getId = bdd => let initSize_1 = 8 * 1024 - 1 let nodeC = ref(1) let sz_1 = ref(initSize_1) -let htab = ref(Array.make(sz_1.contents + 1, list{})) +let htab = ref(Belt.Array.make(sz_1.contents + 1, list{})) let n_items = ref(0) let hashVal = (x, y, v) => lsl(x, 1) + y + lsl(v, 2) let resize = newSize => { let arr = htab.contents let newSz_1 = newSize - 1 - let newArr = Array.make(newSize, list{}) + let newArr = Belt.Array.make(newSize, list{}) let rec copyBucket = bucket => switch bucket { | list{} => () @@ -81,7 +81,7 @@ let rec insert = (idl, idh, v, ind, bucket, newNode) => let resetUnique = () => { sz_1 := initSize_1 - htab := Array.make(sz_1.contents + 1, list{}) + htab := Belt.Array.make(sz_1.contents + 1, list{}) n_items := 0 nodeC := 1 } @@ -143,14 +143,15 @@ let one = One let mkVar = x => mkNode(zero, x, one) let cacheSize = 1999 -let andslot1 = Array.make(cacheSize, 0) -let andslot2 = Array.make(cacheSize, 0) -let andslot3 = Array.make(cacheSize, zero) -let xorslot1 = Array.make(cacheSize, 0) -let xorslot2 = Array.make(cacheSize, 0) -let xorslot3 = Array.make(cacheSize, zero) -let notslot1 = Array.make(cacheSize, 0) -let notslot2 = Array.make(cacheSize, one) + +let andslot1 = Belt.Array.make(cacheSize, 0) +let andslot2 = Belt.Array.make(cacheSize, 0) +let andslot3 = Belt.Array.make(cacheSize, zero) +let xorslot1 = Belt.Array.make(cacheSize, 0) +let xorslot2 = Belt.Array.make(cacheSize, 0) +let xorslot3 = Belt.Array.make(cacheSize, zero) +let notslot1 = Belt.Array.make(cacheSize, 0) +let notslot2 = Belt.Array.make(cacheSize, one) let hash = (x, y) => mod(lsl(x, 1) + y, cacheSize) let rec not = n => @@ -253,7 +254,7 @@ let random = () => { } let random_vars = n => { - let vars = Array.make(n, false) + let vars = Belt.Array.make(n, false) for i in 0 to n - 1 { vars[i] = random() } @@ -273,7 +274,7 @@ let test_hwb = (bdd, vars) => { eval bdd vars = false if n = 0 where n is the number of "true" elements in vars. */ let ntrue = ref(0) - for i in 0 to Array.length(vars) - 1 { + for i in 0 to Belt.Array.length(vars) - 1 { if vars[i] { incr(ntrue) } diff --git a/jscomp/test/belt_hashmap_ntest.js b/jscomp/test/belt_hashmap_ntest.js index e4cb0fc1a1..682771daab 100644 --- a/jscomp/test/belt_hashmap_ntest.js +++ b/jscomp/test/belt_hashmap_ntest.js @@ -1,11 +1,11 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml = require("../../lib/js/caml.js"); let Hashtbl = require("../../lib/js/hashtbl.js"); let Nodetest = require("node:test"); let Belt_Array = require("../../lib/js/belt_Array.js"); let Belt_HashMap = require("../../lib/js/belt_HashMap.js"); +let Primitive_int = require("../../lib/js/primitive_int.js"); let Belt_SortArray = require("../../lib/js/belt_SortArray.js"); let Node_test_util = require("./node_test_util.js"); let Array_data_util = require("./array_data_util.js"); @@ -17,7 +17,7 @@ function intEq(x, y) { let intHash = Hashtbl.hash; -let cmp = Caml.int_compare; +let cmp = Primitive_int.compare; let Y = { hash: intHash, diff --git a/jscomp/test/belt_list_ntest.js b/jscomp/test/belt_list_ntest.js index b0746daae4..852f5e4527 100644 --- a/jscomp/test/belt_list_ntest.js +++ b/jscomp/test/belt_list_ntest.js @@ -1,12 +1,12 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml = require("../../lib/js/caml.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); let Belt_List = require("../../lib/js/belt_List.js"); let Nodetest = require("node:test"); let Belt_Array = require("../../lib/js/belt_Array.js"); +let Primitive_int = require("../../lib/js/primitive_int.js"); let Node_test_util = require("./node_test_util.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); function sum(xs) { let v = { @@ -1202,7 +1202,7 @@ Nodetest.describe("Belt.List", () => { } }); let ll2 = Belt_List.setAssoc(ll1, 22, "2", (prim0, prim1) => prim0 === prim1); - Node_test_util.ok("File \"belt_list_ntest.res\", line 208, characters 7-14", Caml_obj.equal(ll2, { + Node_test_util.ok("File \"belt_list_ntest.res\", line 208, characters 7-14", Primitive_object.equal(ll2, { hd: [ 22, "2" @@ -1210,7 +1210,7 @@ Nodetest.describe("Belt.List", () => { tl: ll1 })); Node_test_util.ok("File \"belt_list_ntest.res\", line 209, characters 7-14", Belt_List.tailExn(ll2) === ll1); - Node_test_util.ok("File \"belt_list_ntest.res\", line 211, characters 6-13", Caml_obj.equal(Belt_List.setAssoc({ + Node_test_util.ok("File \"belt_list_ntest.res\", line 211, characters 6-13", Primitive_object.equal(Belt_List.setAssoc({ hd: [ 1, "a" @@ -1247,7 +1247,7 @@ Nodetest.describe("Belt.List", () => { } } })); - Node_test_util.ok("File \"belt_list_ntest.res\", line 216, characters 6-13", Caml_obj.equal(Belt_List.setAssoc({ + Node_test_util.ok("File \"belt_list_ntest.res\", line 216, characters 6-13", Primitive_object.equal(Belt_List.setAssoc({ hd: [ 1, "a" @@ -1323,7 +1323,7 @@ Nodetest.describe("Belt.List", () => { tl: /* [] */0 } }); - Node_test_util.ok("File \"belt_list_ntest.res\", line 223, characters 7-14", Caml_obj.equal(Belt_List.getAssoc({ + Node_test_util.ok("File \"belt_list_ntest.res\", line 223, characters 7-14", Primitive_object.equal(Belt_List.getAssoc({ hd: [ 1, "a" @@ -1523,7 +1523,7 @@ Nodetest.describe("Belt.List", () => { tl: /* [] */0 } } - }, "2", (x, s) => String(x) === s), true); + }, "2", (x, s) => x.toString() === s), true); Node_test_util.eq("File \"belt_list_ntest.res\", line 272, characters 7-14", Belt_List.has({ hd: 1, tl: { @@ -1533,7 +1533,7 @@ Nodetest.describe("Belt.List", () => { tl: /* [] */0 } } - }, "0", (x, s) => String(x) === s), false); + }, "0", (x, s) => x.toString() === s), false); Node_test_util.ok("File \"belt_list_ntest.res\", line 274, characters 7-14", Belt_List.reduceReverse({ hd: 1, tl: { @@ -1560,7 +1560,7 @@ Nodetest.describe("Belt.List", () => { } } }, 10, (prim0, prim1) => prim0 - prim1 | 0) === 0); - Node_test_util.ok("File \"belt_list_ntest.res\", line 276, characters 7-14", Caml_obj.equal(Belt_List.reduceReverse({ + Node_test_util.ok("File \"belt_list_ntest.res\", line 276, characters 7-14", Primitive_object.equal(Belt_List.reduceReverse({ hd: 1, tl: { hd: 2, @@ -1611,7 +1611,7 @@ Nodetest.describe("Belt.List", () => { } } }, 10, (prim0, prim1) => prim0 - prim1 | 0) === 0); - Node_test_util.ok("File \"belt_list_ntest.res\", line 279, characters 7-14", Caml_obj.equal(Belt_List.reduce({ + Node_test_util.ok("File \"belt_list_ntest.res\", line 279, characters 7-14", Primitive_object.equal(Belt_List.reduce({ hd: 1, tl: { hd: 2, @@ -1826,7 +1826,7 @@ Nodetest.describe("Belt.List", () => { } } } - }, Caml.int_compare) > 0); + }, Primitive_int.compare) > 0); Node_test_util.ok("File \"belt_list_ntest.res\", line 312, characters 7-14", Belt_List.cmp({ hd: 1, tl: { @@ -1848,7 +1848,7 @@ Nodetest.describe("Belt.List", () => { tl: /* [] */0 } } - }, Caml.int_compare) > 0); + }, Primitive_int.compare) > 0); Node_test_util.ok("File \"belt_list_ntest.res\", line 313, characters 7-14", Belt_List.cmp({ hd: 1, tl: { @@ -1870,7 +1870,7 @@ Nodetest.describe("Belt.List", () => { } } } - }, Caml.int_compare) < 0); + }, Primitive_int.compare) < 0); Node_test_util.ok("File \"belt_list_ntest.res\", line 314, characters 7-14", Belt_List.cmp({ hd: 1, tl: { @@ -1889,7 +1889,7 @@ Nodetest.describe("Belt.List", () => { tl: /* [] */0 } } - }, Caml.int_compare) > 0); + }, Primitive_int.compare) > 0); Node_test_util.ok("File \"belt_list_ntest.res\", line 315, characters 7-14", Belt_List.cmp({ hd: 1, tl: { @@ -1908,7 +1908,7 @@ Nodetest.describe("Belt.List", () => { tl: /* [] */0 } } - }, Caml.int_compare) === 0); + }, Primitive_int.compare) === 0); Node_test_util.ok("File \"belt_list_ntest.res\", line 316, characters 7-14", Belt_List.cmp({ hd: 1, tl: { @@ -1927,7 +1927,7 @@ Nodetest.describe("Belt.List", () => { tl: /* [] */0 } } - }, Caml.int_compare) > 0); + }, Primitive_int.compare) > 0); }); Nodetest.test("cmpByLength", () => { Node_test_util.ok("File \"belt_list_ntest.res\", line 320, characters 7-14", Belt_List.cmpByLength(/* [] */0, /* [] */0) === 0); @@ -2135,7 +2135,7 @@ Nodetest.describe("Belt.List", () => { } } }); - Node_test_util.ok("File \"belt_list_ntest.res\", line 362, characters 6-13", Caml_obj.equal(Belt_List.keepMap({ + Node_test_util.ok("File \"belt_list_ntest.res\", line 362, characters 6-13", Primitive_object.equal(Belt_List.keepMap({ hd: 1, tl: { hd: 2, diff --git a/jscomp/test/belt_list_ntest.res b/jscomp/test/belt_list_ntest.res index d95bbdc9ab..ded4d250d3 100644 --- a/jscomp/test/belt_list_ntest.res +++ b/jscomp/test/belt_list_ntest.res @@ -268,8 +268,8 @@ describe("Belt.List", () => { eq(__LOC__, N.some(list{1, 2, 5}, mod2), true) eq(__LOC__, N.some(list{1, 3, 5}, mod2), false) eq(__LOC__, N.some(list{}, mod2), false) - eq(__LOC__, N.has(list{1, 2, 3}, "2", (x, s) => string_of_int(x) == s), true) - eq(__LOC__, N.has(list{1, 2, 3}, "0", (x, s) => string_of_int(x) == s), false) + eq(__LOC__, N.has(list{1, 2, 3}, "2", (x, s) => Js.Int.toString(x) == s), true) + eq(__LOC__, N.has(list{1, 2, 3}, "0", (x, s) => Js.Int.toString(x) == s), false) ok(__LOC__, N.reduceReverse(list{1, 2, 3, 4}, 0, \"+") == 10) ok(__LOC__, N.reduceReverse(list{1, 2, 3, 4}, 10, \"-") == 0) diff --git a/jscomp/test/bench.js b/jscomp/test/bench.js index aa70b76e77..e689d018b2 100644 --- a/jscomp/test/bench.js +++ b/jscomp/test/bench.js @@ -1,8 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_array = require("../../lib/js/caml_array.js"); -let Pervasives = require("../../lib/js/pervasives.js"); +let Belt_Array = require("../../lib/js/belt_Array.js"); function map(f, a) { let f$1 = x => f(x); @@ -10,7 +9,7 @@ function map(f, a) { if (l === 0) { return []; } - let r = Caml_array.make(l, f$1(a[0])); + let r = Belt_Array.make(l, f$1(a[0])); for (let i = 1; i < l; ++i) { r[i] = f$1(a[i]); } @@ -29,7 +28,7 @@ function init(l, f) { Error: new Error() }; } - let res = Caml_array.make(l, f$1(0)); + let res = Belt_Array.make(l, f$1(0)); for (let i = 1; i < l; ++i) { res[i] = f$1(i); } @@ -49,7 +48,7 @@ function f2() { let arr = init(3000000, i => i); let b = map(i => i + i - 1, arr); let v = fold_left((prim0, prim1) => prim0 + prim1, 0, b); - console.log(Pervasives.string_of_float(v)); + console.log("%f", v); } f2(); diff --git a/jscomp/test/bench.res b/jscomp/test/bench.res index aa0e5cf1e5..0be1bd44f0 100644 --- a/jscomp/test/bench.res +++ b/jscomp/test/bench.res @@ -1,11 +1,13 @@ +open Belt + let map = (f, a) => { let l = Array.length(a) if l == 0 { [] } else { - let r = Array.make(l, f(Array.unsafe_get(a, 0))) + let r = Array.make(l, f(Array.getUnsafe(a, 0))) for i in 1 to l - 1 { - Array.unsafe_set(r, i, f(Array.unsafe_get(a, i))) + Array.setUnsafe(r, i, f(Array.getUnsafe(a, i))) } r } @@ -24,7 +26,7 @@ let init = (l, f) => let res = Array.make(l, f(0)) for i in 1 to pred(l) { - Array.unsafe_set(res, i, f(i)) + Array.setUnsafe(res, i, f(i)) } res } @@ -34,7 +36,7 @@ let init = (l, f) => init(l, x => f(x)) let fold_left = (f, x, a) => { let r = ref(x) for i in 0 to Array.length(a) - 1 { - r := f(r.contents, Array.unsafe_get(a, i)) + r := f(r.contents, Array.getUnsafe(a, i)) } r.contents } @@ -45,11 +47,7 @@ let f2 = () => { let arr = init(3_000_000, i => float_of_int(i)) let b = map(i => i +. i -. 1., arr) let v = fold_left(\"+.", 0., b) - print_endline(string_of_float(v)) + Js.log2("%f", v) } f2() - -/* local variables: */ -/* compile-command: "ocamlc bench.ml -o bench.byte && js_of_ocaml --opt 3 bench.byte -o bench.1.js " */ -/* end: */ diff --git a/jscomp/test/bigint_test.js b/jscomp/test/bigint_test.js index 0701339650..8dc3a51681 100644 --- a/jscomp/test/bigint_test.js +++ b/jscomp/test/bigint_test.js @@ -2,9 +2,9 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml = require("../../lib/js/caml.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); let Mt_global = require("./mt_global.js"); +let Primitive_bigint = require("../../lib/js/primitive_bigint.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); let test_id = { contents: 0 @@ -22,45 +22,45 @@ function approx(loc, x, y) { Mt_global.collect_approx(test_id, suites, loc, x, y); } -let bigint_compare = Caml.bigint_compare; +let bigint_compare = Primitive_bigint.compare; -let generic_compare = Caml_obj.compare; +let generic_compare = Primitive_object.compare; function bigint_equal(x, y) { return x === y; } -let generic_equal = Caml_obj.equal; +let generic_equal = Primitive_object.equal; function bigint_notequal(x, y) { return x !== y; } -let generic_notequal = Caml_obj.notequal; +let generic_notequal = Primitive_object.notequal; function bigint_lessthan(x, y) { return x < y; } -let generic_lessthan = Caml_obj.lessthan; +let generic_lessthan = Primitive_object.lessthan; function bigint_greaterthan(x, y) { return x > y; } -let generic_greaterthan = Caml_obj.greaterthan; +let generic_greaterthan = Primitive_object.greaterthan; function bigint_lessequal(x, y) { return x <= y; } -let generic_lessequal = Caml_obj.lessequal; +let generic_lessequal = Primitive_object.lessequal; function bigint_greaterequal(x, y) { return x >= y; } -let generic_greaterequal = Caml_obj.greaterequal; +let generic_greaterequal = Primitive_object.greaterequal; function bigint_land(prim0, prim1) { return prim0 & prim1; @@ -82,53 +82,53 @@ function bigint_asr(prim0, prim1) { return (prim0 >> prim1); } -eq("File \"bigint_test.res\", line 26, characters 5-12", Caml.bigint_compare(1n, 1n), 0); +eq("File \"bigint_test.res\", line 26, characters 5-12", Primitive_bigint.compare(1n, 1n), 0); -eq("File \"bigint_test.res\", line 27, characters 5-12", Caml_obj.compare(1n, 1n), 0); +eq("File \"bigint_test.res\", line 27, characters 5-12", Primitive_object.compare(1n, 1n), 0); -eq("File \"bigint_test.res\", line 28, characters 5-12", Caml.bigint_compare(-0n, -1n), 1); +eq("File \"bigint_test.res\", line 28, characters 5-12", Primitive_bigint.compare(-0n, -1n), 1); -eq("File \"bigint_test.res\", line 29, characters 5-12", Caml_obj.compare(-0n, -1n), 1); +eq("File \"bigint_test.res\", line 29, characters 5-12", Primitive_object.compare(-0n, -1n), 1); -eq("File \"bigint_test.res\", line 30, characters 5-12", Caml.bigint_compare(0n, -1n), 1); +eq("File \"bigint_test.res\", line 30, characters 5-12", Primitive_bigint.compare(0n, -1n), 1); -eq("File \"bigint_test.res\", line 31, characters 5-12", Caml_obj.compare(0n, -1n), 1); +eq("File \"bigint_test.res\", line 31, characters 5-12", Primitive_object.compare(0n, -1n), 1); -eq("File \"bigint_test.res\", line 32, characters 5-12", Caml.bigint_compare(1n, 2n), -1); +eq("File \"bigint_test.res\", line 32, characters 5-12", Primitive_bigint.compare(1n, 2n), -1); -eq("File \"bigint_test.res\", line 33, characters 5-12", Caml_obj.compare(1n, 2n), -1); +eq("File \"bigint_test.res\", line 33, characters 5-12", Primitive_object.compare(1n, 2n), -1); -eq("File \"bigint_test.res\", line 34, characters 5-12", Caml.bigint_compare(1n, 2n), -1); +eq("File \"bigint_test.res\", line 34, characters 5-12", Primitive_bigint.compare(1n, 2n), -1); -eq("File \"bigint_test.res\", line 35, characters 5-12", Caml_obj.compare(1n, 2n), -1); +eq("File \"bigint_test.res\", line 35, characters 5-12", Primitive_object.compare(1n, 2n), -1); -eq("File \"bigint_test.res\", line 36, characters 5-12", Caml.bigint_compare(1n, 1n), 0); +eq("File \"bigint_test.res\", line 36, characters 5-12", Primitive_bigint.compare(1n, 1n), 0); -eq("File \"bigint_test.res\", line 37, characters 5-12", Caml_obj.compare(1n, 1n), 0); +eq("File \"bigint_test.res\", line 37, characters 5-12", Primitive_object.compare(1n, 1n), 0); eq("File \"bigint_test.res\", line 39, characters 4-11", true, true); -eq("File \"bigint_test.res\", line 47, characters 4-11", Caml_obj.equal(1000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000n), true); +eq("File \"bigint_test.res\", line 47, characters 4-11", Primitive_object.equal(1000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000n), true); eq("File \"bigint_test.res\", line 55, characters 4-11", false, false); -eq("File \"bigint_test.res\", line 63, characters 4-11", Caml_obj.equal(1000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000001n), false); +eq("File \"bigint_test.res\", line 63, characters 4-11", Primitive_object.equal(1000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, 1000000000000000000000000000000000000000000000000000000000000000000000000000000000001n), false); eq("File \"bigint_test.res\", line 71, characters 4-11", false, false); -eq("File \"bigint_test.res\", line 79, characters 4-11", Caml_obj.equal(1000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, -1000000000000000000000000000000000000000000000000000000000000000000000000000000000000n), false); +eq("File \"bigint_test.res\", line 79, characters 4-11", Primitive_object.equal(1000000000000000000000000000000000000000000000000000000000000000000000000000000000000n, -1000000000000000000000000000000000000000000000000000000000000000000000000000000000000n), false); eq("File \"bigint_test.res\", line 87, characters 4-11", true, true); -eq("File \"bigint_test.res\", line 99, characters 4-11", Caml_obj.equal(3n, 3n), true); +eq("File \"bigint_test.res\", line 99, characters 4-11", Primitive_object.equal(3n, 3n), true); eq("File \"bigint_test.res\", line 111, characters 4-11", true, true); -eq("File \"bigint_test.res\", line 123, characters 4-11", Caml_obj.equal(3n, 3n), true); +eq("File \"bigint_test.res\", line 123, characters 4-11", Primitive_object.equal(3n, 3n), true); eq("File \"bigint_test.res\", line 135, characters 4-11", true, true); -eq("File \"bigint_test.res\", line 147, characters 4-11", Caml_obj.equal(3n, 3n), true); +eq("File \"bigint_test.res\", line 147, characters 4-11", Primitive_object.equal(3n, 3n), true); eq("File \"bigint_test.res\", line 158, characters 5-12", 9n & 1n, 1n); diff --git a/jscomp/test/block_alias_test.js b/jscomp/test/block_alias_test.js index 51dc8b4193..7fd98257ae 100644 --- a/jscomp/test/block_alias_test.js +++ b/jscomp/test/block_alias_test.js @@ -2,8 +2,8 @@ 'use strict'; let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); +let Belt_List = require("../../lib/js/belt_List.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); let suites = { contents: /* [] */0 @@ -42,17 +42,17 @@ let N = { v1: v1 }; -let Caml_obj$1 = {}; +let Caml_obj = {}; -let List$1 = {}; +let List = {}; let V = { - List: List$1 + List: List }; -let f = Caml_obj.equal; +let f = Primitive_object.equal; -eq("File \"block_alias_test.res\", line 27, characters 3-10", List.length({ +eq("File \"block_alias_test.res\", line 27, characters 3-10", Belt_List.length({ hd: 1, tl: { hd: 2, @@ -60,7 +60,7 @@ eq("File \"block_alias_test.res\", line 27, characters 3-10", List.length({ } }), 2); -b("File \"block_alias_test.res\", line 28, characters 2-9", Caml_obj.equal(v0, { +b("File \"block_alias_test.res\", line 28, characters 2-9", Primitive_object.equal(v0, { TAG: "A", _0: 0, _1: 1 @@ -70,7 +70,7 @@ eq("File \"block_alias_test.res\", line 29, characters 3-10", v0, v1); Mt.from_pair_suites("Block_alias_test", suites.contents); -let h = List.length; +let h = Belt_List.length; exports.suites = suites; exports.test_id = test_id; @@ -79,7 +79,7 @@ exports.b = b; exports.Block = Block; exports.v0 = v0; exports.N = N; -exports.Caml_obj = Caml_obj$1; +exports.Caml_obj = Caml_obj; exports.V = V; exports.f = f; exports.h = h; diff --git a/jscomp/test/block_alias_test.res b/jscomp/test/block_alias_test.res index fc6b264bc0..2e0d94b438 100644 --- a/jscomp/test/block_alias_test.res +++ b/jscomp/test/block_alias_test.res @@ -22,7 +22,7 @@ module V = { } let f = (a, b) => a == b -let h = List.length +let h = Belt.List.length eq(__LOC__, h(list{1, 2}), 2) b(__LOC__, f(v0, A(0, 1))) diff --git a/jscomp/test/bs_array_test.js b/jscomp/test/bs_array_test.js index e27e892f58..d5cb3693b8 100644 --- a/jscomp/test/bs_array_test.js +++ b/jscomp/test/bs_array_test.js @@ -2,10 +2,10 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml = require("../../lib/js/caml.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); let Belt_List = require("../../lib/js/belt_List.js"); let Belt_Array = require("../../lib/js/belt_Array.js"); +let Primitive_int = require("../../lib/js/primitive_int.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); let suites = { contents: /* [] */0 @@ -31,7 +31,7 @@ function neq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Neq", _0: x, @@ -93,7 +93,7 @@ function f(extra) { ], extra); } -b("File \"bs_array_test.res\", line 38, characters 4-11", Caml_obj.equal([ +b("File \"bs_array_test.res\", line 38, characters 4-11", Primitive_object.equal([ f(0), f(1) ], [ @@ -180,25 +180,25 @@ neq("File \"bs_array_test.res\", line 85, characters 6-13", u, v$5); eq("File \"bs_array_test.res\", line 87, characters 5-12", Belt_Array.reduce(u, 0, add), Belt_Array.reduce(v$5, 0, add)); -b("File \"bs_array_test.res\", line 92, characters 4-11", Caml_obj.equal(Belt_Array.range(0, 3), [ +b("File \"bs_array_test.res\", line 92, characters 4-11", Primitive_object.equal(Belt_Array.range(0, 3), [ 0, 1, 2, 3 ])); -b("File \"bs_array_test.res\", line 93, characters 4-11", Caml_obj.equal(Belt_Array.range(3, 0), [])); +b("File \"bs_array_test.res\", line 93, characters 4-11", Primitive_object.equal(Belt_Array.range(3, 0), [])); -b("File \"bs_array_test.res\", line 94, characters 4-11", Caml_obj.equal(Belt_Array.range(3, 3), [3])); +b("File \"bs_array_test.res\", line 94, characters 4-11", Primitive_object.equal(Belt_Array.range(3, 3), [3])); -b("File \"bs_array_test.res\", line 96, characters 4-11", Caml_obj.equal(Belt_Array.rangeBy(0, 10, 3), [ +b("File \"bs_array_test.res\", line 96, characters 4-11", Primitive_object.equal(Belt_Array.rangeBy(0, 10, 3), [ 0, 3, 6, 9 ])); -b("File \"bs_array_test.res\", line 97, characters 4-11", Caml_obj.equal(Belt_Array.rangeBy(0, 12, 3), [ +b("File \"bs_array_test.res\", line 97, characters 4-11", Primitive_object.equal(Belt_Array.rangeBy(0, 12, 3), [ 0, 3, 6, @@ -206,15 +206,15 @@ b("File \"bs_array_test.res\", line 97, characters 4-11", Caml_obj.equal(Belt_Ar 12 ])); -b("File \"bs_array_test.res\", line 98, characters 4-11", Caml_obj.equal(Belt_Array.rangeBy(33, 0, 1), [])); +b("File \"bs_array_test.res\", line 98, characters 4-11", Primitive_object.equal(Belt_Array.rangeBy(33, 0, 1), [])); -b("File \"bs_array_test.res\", line 99, characters 4-11", Caml_obj.equal(Belt_Array.rangeBy(33, 0, -1), [])); +b("File \"bs_array_test.res\", line 99, characters 4-11", Primitive_object.equal(Belt_Array.rangeBy(33, 0, -1), [])); -b("File \"bs_array_test.res\", line 100, characters 4-11", Caml_obj.equal(Belt_Array.rangeBy(3, 12, -1), [])); +b("File \"bs_array_test.res\", line 100, characters 4-11", Primitive_object.equal(Belt_Array.rangeBy(3, 12, -1), [])); -b("File \"bs_array_test.res\", line 101, characters 4-11", Caml_obj.equal(Belt_Array.rangeBy(3, 3, 0), [])); +b("File \"bs_array_test.res\", line 101, characters 4-11", Primitive_object.equal(Belt_Array.rangeBy(3, 3, 0), [])); -b("File \"bs_array_test.res\", line 102, characters 4-11", Caml_obj.equal(Belt_Array.rangeBy(3, 3, 1), [3])); +b("File \"bs_array_test.res\", line 102, characters 4-11", Primitive_object.equal(Belt_Array.rangeBy(3, 3, 1), [3])); eq("File \"bs_array_test.res\", line 106, characters 5-12", Belt_Array.reduceReverse([], 100, (prim0, prim1) => prim0 - prim1 | 0), 100); @@ -1312,7 +1312,7 @@ b("File \"bs_array_test.res\", line 349, characters 4-11", Belt_Array.cmp([ 1, 2, 3 -], Caml.int_compare) < 0); +], Primitive_int.compare) < 0); b("File \"bs_array_test.res\", line 350, characters 4-11", Belt_Array.cmp([ 0, @@ -1323,7 +1323,7 @@ b("File \"bs_array_test.res\", line 350, characters 4-11", Belt_Array.cmp([ 1, 2, 3 -], Caml.int_compare) > 0); +], Primitive_int.compare) > 0); b("File \"bs_array_test.res\", line 351, characters 4-11", Belt_Array.cmp([ 1, @@ -1333,7 +1333,7 @@ b("File \"bs_array_test.res\", line 351, characters 4-11", Belt_Array.cmp([ 0, 1, 2 -], Caml.int_compare) > 0); +], Primitive_int.compare) > 0); b("File \"bs_array_test.res\", line 352, characters 4-11", Belt_Array.cmp([ 1, @@ -1343,7 +1343,7 @@ b("File \"bs_array_test.res\", line 352, characters 4-11", Belt_Array.cmp([ 1, 2, 3 -], Caml.int_compare) === 0); +], Primitive_int.compare) === 0); b("File \"bs_array_test.res\", line 353, characters 4-11", Belt_Array.cmp([ 1, @@ -1353,7 +1353,7 @@ b("File \"bs_array_test.res\", line 353, characters 4-11", Belt_Array.cmp([ 1, 2, 3 -], Caml.int_compare) > 0); +], Primitive_int.compare) > 0); eq("File \"bs_array_test.res\", line 357, characters 5-12", Belt_Array.getBy([ 1, diff --git a/jscomp/test/bs_array_test.res b/jscomp/test/bs_array_test.res index b14cb0cc8f..b598a344d8 100644 --- a/jscomp/test/bs_array_test.res +++ b/jscomp/test/bs_array_test.res @@ -7,7 +7,7 @@ let neq = (loc, x, y) => { incr(test_id) suites := list{ - (loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Neq(x, y)), + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Neq(x, y)), ...suites.contents, } } diff --git a/jscomp/test/bs_auto_uncurry_test.js b/jscomp/test/bs_auto_uncurry_test.js index c44c98800e..3f46e7548d 100644 --- a/jscomp/test/bs_auto_uncurry_test.js +++ b/jscomp/test/bs_auto_uncurry_test.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -50,7 +50,7 @@ hi(x => { }; }); -eq("File \"bs_auto_uncurry_test.res\", line 24, characters 5-12", xs.contents, { +eq("File \"bs_auto_uncurry_test.res\", line 27, characters 5-12", xs.contents, { hd: undefined, tl: { hd: undefined, @@ -58,7 +58,7 @@ eq("File \"bs_auto_uncurry_test.res\", line 24, characters 5-12", xs.contents, { } }); -eq("File \"bs_auto_uncurry_test.res\", line 28, characters 5-12", [ +eq("File \"bs_auto_uncurry_test.res\", line 31, characters 5-12", [ 1, 2, 3 @@ -68,7 +68,7 @@ eq("File \"bs_auto_uncurry_test.res\", line 28, characters 5-12", [ 4 ]); -eq("File \"bs_auto_uncurry_test.res\", line 29, characters 5-12", [ +eq("File \"bs_auto_uncurry_test.res\", line 32, characters 5-12", [ 1, 2, 3 @@ -78,25 +78,25 @@ eq("File \"bs_auto_uncurry_test.res\", line 29, characters 5-12", [ 4 ]); -eq("File \"bs_auto_uncurry_test.res\", line 31, characters 5-12", [ +eq("File \"bs_auto_uncurry_test.res\", line 34, characters 5-12", [ 1, 2, 3 ].reduce((prim0, prim1) => prim0 + prim1 | 0, 0), 6); -eq("File \"bs_auto_uncurry_test.res\", line 33, characters 5-12", [ +eq("File \"bs_auto_uncurry_test.res\", line 36, characters 5-12", [ 1, 2, 3 ].reduce((x, y, i) => (x + y | 0) + i | 0, 0), 9); -eq("File \"bs_auto_uncurry_test.res\", line 35, characters 5-12", [ +eq("File \"bs_auto_uncurry_test.res\", line 38, characters 5-12", [ 1, 2, 3 ].some(x => x < 1), false); -eq("File \"bs_auto_uncurry_test.res\", line 37, characters 5-12", [ +eq("File \"bs_auto_uncurry_test.res\", line 40, characters 5-12", [ 1, 2, 3 diff --git a/jscomp/test/bs_auto_uncurry_test.res b/jscomp/test/bs_auto_uncurry_test.res index 8a79812ede..5dfac16a7d 100644 --- a/jscomp/test/bs_auto_uncurry_test.res +++ b/jscomp/test/bs_auto_uncurry_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } @send external map: (array<'a>, 'a => 'b) => array<'b> = "map" diff --git a/jscomp/test/bs_ignore_effect.js b/jscomp/test/bs_ignore_effect.js index d432098c6b..49ab49a706 100644 --- a/jscomp/test/bs_ignore_effect.js +++ b/jscomp/test/bs_ignore_effect.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -42,9 +42,9 @@ let h = (v.contents = v.contents + 1 | 0, { let z = (v.contents = v.contents + 1 | 0, "Float", add(3.0, 2.0)); -eq("File \"bs_ignore_effect.res\", line 34, characters 5-12", v.contents, 2); +eq("File \"bs_ignore_effect.res\", line 37, characters 5-12", v.contents, 2); -eq("File \"bs_ignore_effect.res\", line 35, characters 5-12", z, 5.0); +eq("File \"bs_ignore_effect.res\", line 38, characters 5-12", z, 5.0); Mt.from_pair_suites("Bs_ignore_effect", suites.contents); diff --git a/jscomp/test/bs_ignore_effect.res b/jscomp/test/bs_ignore_effect.res index f1ee98525e..fb4c735eb1 100644 --- a/jscomp/test/bs_ignore_effect.res +++ b/jscomp/test/bs_ignore_effect.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } %%raw(` diff --git a/jscomp/test/bs_map_set_dict_test.js b/jscomp/test/bs_map_set_dict_test.js index 5cc84fab8d..3b029f03b1 100644 --- a/jscomp/test/bs_map_set_dict_test.js +++ b/jscomp/test/bs_map_set_dict_test.js @@ -2,12 +2,12 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml = require("../../lib/js/caml.js"); let Belt_Map = require("../../lib/js/belt_Map.js"); let Belt_List = require("../../lib/js/belt_List.js"); let Belt_Array = require("../../lib/js/belt_Array.js"); let Belt_MapDict = require("../../lib/js/belt_MapDict.js"); let Belt_SetDict = require("../../lib/js/belt_SetDict.js"); +let Primitive_int = require("../../lib/js/primitive_int.js"); let Array_data_util = require("./array_data_util.js"); let suites = { @@ -27,15 +27,15 @@ function b(loc, v) { } let Icmp = { - cmp: Caml.int_compare + cmp: Primitive_int.compare }; let Icmp2 = { - cmp: Caml.int_compare + cmp: Primitive_int.compare }; let Ic3 = { - cmp: Caml.int_compare + cmp: Primitive_int.compare }; let m0_cmp = Icmp.cmp; @@ -53,7 +53,7 @@ let m00 = { }; let I2 = { - cmp: (x, y) => Caml.int_compare(y, x) + cmp: (x, y) => Primitive_int.compare(y, x) }; let m_cmp = Icmp2.cmp; diff --git a/jscomp/test/bs_map_test.js b/jscomp/test/bs_map_test.js index 585b8956f4..33e1fd13c5 100644 --- a/jscomp/test/bs_map_test.js +++ b/jscomp/test/bs_map_test.js @@ -18,7 +18,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -33,7 +33,7 @@ function b(loc, v) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Ok", _0: v diff --git a/jscomp/test/bs_map_test.res b/jscomp/test/bs_map_test.res index 6c546fcf17..c5081469fe 100644 --- a/jscomp/test/bs_map_test.res +++ b/jscomp/test/bs_map_test.res @@ -3,13 +3,16 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let b = (loc, v) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Ok(v)), ...suites.contents} + list{(loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Ok(v)), ...suites.contents} } module M = Belt.Map.Int diff --git a/jscomp/test/bs_min_max_test.js b/jscomp/test/bs_min_max_test.js index 1a111e9a33..8d2df459b6 100644 --- a/jscomp/test/bs_min_max_test.js +++ b/jscomp/test/bs_min_max_test.js @@ -2,9 +2,8 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml = require("../../lib/js/caml.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); -let Caml_int64 = require("../../lib/js/caml_int64.js"); +let Primitive_int = require("../../lib/js/primitive_int.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); let suites = { contents: /* [] */0 @@ -23,63 +22,36 @@ function b(extra, extra$1) { } function f(x, y) { - return Caml.int_compare(x + y | 0, y + x | 0); + return Primitive_int.compare(x + y | 0, y + x | 0); } function f2(x, y) { - return Caml.int_compare(x + y | 0, y); + return Primitive_int.compare(x + y | 0, y); } -let f3 = Caml.int_compare; +let f3 = Primitive_int.compare; -function f4(x, y) { - if (x < y) { - return x; - } else { - return y; - } -} - -let f5_min = Caml_obj.min; - -let f5_max = Caml_obj.max; - -b("File \"bs_min_max_test.res\", line 19, characters 4-11", Caml.i64_eq(Caml.i64_min(Caml_int64.zero, Caml_int64.one), Caml_int64.zero)); +let f4 = Primitive_int.min; -b("File \"bs_min_max_test.res\", line 20, characters 4-11", Caml.i64_eq(Caml.i64_max([ - 0, - 22 -], Caml_int64.one), [ - 0, - 22 -])); +let f5_min = Primitive_object.min; -b("File \"bs_min_max_test.res\", line 21, characters 4-11", Caml.i64_eq(Caml.i64_max([ - -1, - 4294967293 -], [ - 0, - 3 -]), [ - 0, - 3 -])); +let f5_max = Primitive_object.max; -eq("File \"bs_min_max_test.res\", line 22, characters 5-12", Caml_obj.min(undefined, 3), undefined); +eq("File \"bs_min_max_test.res\", line 19, characters 5-12", Primitive_object.min(undefined, 3), undefined); -eq("File \"bs_min_max_test.res\", line 23, characters 5-12", Caml_obj.min(3, undefined), undefined); +eq("File \"bs_min_max_test.res\", line 20, characters 5-12", Primitive_object.min(3, undefined), undefined); -eq("File \"bs_min_max_test.res\", line 24, characters 5-12", Caml_obj.max(3, undefined), 3); +eq("File \"bs_min_max_test.res\", line 21, characters 5-12", Primitive_object.max(3, undefined), 3); -eq("File \"bs_min_max_test.res\", line 25, characters 5-12", Caml_obj.max(undefined, 3), 3); +eq("File \"bs_min_max_test.res\", line 22, characters 5-12", Primitive_object.max(undefined, 3), 3); -b("File \"bs_min_max_test.res\", line 26, characters 4-11", Caml_obj.greaterequal(5, undefined)); +b("File \"bs_min_max_test.res\", line 23, characters 4-11", Primitive_object.greaterequal(5, undefined)); -b("File \"bs_min_max_test.res\", line 27, characters 4-11", Caml_obj.lessequal(undefined, 5)); +b("File \"bs_min_max_test.res\", line 24, characters 4-11", Primitive_object.lessequal(undefined, 5)); -b("File \"bs_min_max_test.res\", line 28, characters 4-11", true); +b("File \"bs_min_max_test.res\", line 25, characters 4-11", true); -b("File \"bs_min_max_test.res\", line 29, characters 4-11", true); +b("File \"bs_min_max_test.res\", line 26, characters 4-11", true); Mt.from_pair_suites("Bs_min_max_test", suites.contents); diff --git a/jscomp/test/bs_min_max_test.res b/jscomp/test/bs_min_max_test.res index 165cdba9c1..2a7bc24585 100644 --- a/jscomp/test/bs_min_max_test.res +++ b/jscomp/test/bs_min_max_test.res @@ -16,9 +16,6 @@ let f5_min = (x, y) => min(x, y) let f5_max = (x, y) => max(x, y) let () = { - b(__LOC__, min(0L, 1L) == 0L) - b(__LOC__, max(22L, 1L) == 22L) - b(__LOC__, max(-3L, 3L) == 3L) eq(__LOC__, f5_min(None, Some(3)), None) eq(__LOC__, f5_min(Some(3), None), None) eq(__LOC__, f5_max(Some(3), None), Some(3)) diff --git a/jscomp/test/bs_mutable_set_test.js b/jscomp/test/bs_mutable_set_test.js index 8c17ab5ba9..c4e90e5568 100644 --- a/jscomp/test/bs_mutable_set_test.js +++ b/jscomp/test/bs_mutable_set_test.js @@ -5,8 +5,8 @@ let Mt = require("./mt.js"); let Belt_List = require("../../lib/js/belt_List.js"); let Belt_Array = require("../../lib/js/belt_Array.js"); let Belt_Range = require("../../lib/js/belt_Range.js"); -let Caml_array = require("../../lib/js/caml_array.js"); let Array_data_util = require("./array_data_util.js"); +let Primitive_array = require("../../lib/js/primitive_array.js"); let Belt_MutableSetInt = require("../../lib/js/belt_MutableSetInt.js"); let Belt_internalAVLset = require("../../lib/js/belt_internalAVLset.js"); let Belt_internalSetInt = require("../../lib/js/belt_internalSetInt.js"); @@ -436,7 +436,7 @@ eq("File \"bs_mutable_set_test.res\", line 210, characters 5-12", Belt_internalA let vv = Array_data_util.randomRange(0, 100000); for (let i$4 = 0, i_finish$2 = vv.length; i$4 < i_finish$2; ++i$4) { - Belt_MutableSetInt.remove(v$3, Caml_array.get(vv, i$4)); + Belt_MutableSetInt.remove(v$3, Primitive_array.get(vv, i$4)); } eq("File \"bs_mutable_set_test.res\", line 216, characters 5-12", Belt_internalAVLset.size(v$3.data), 0); @@ -464,7 +464,7 @@ eq("File \"bs_mutable_set_test.res\", line 227, characters 5-12", Belt_internalA let vv$1 = Array_data_util.randomRange(1, 28); for (let i$5 = 0, i_finish$3 = vv$1.length; i$5 < i_finish$3; ++i$5) { - Belt_MutableSetInt.remove(v$4, Caml_array.get(vv$1, i$5)); + Belt_MutableSetInt.remove(v$4, Primitive_array.get(vv$1, i$5)); } eq("File \"bs_mutable_set_test.res\", line 232, characters 5-12", Belt_internalAVLset.size(v$4.data), 0); diff --git a/jscomp/test/bs_poly_map_test.js b/jscomp/test/bs_poly_map_test.js index b1d01724bb..a4232c465e 100644 --- a/jscomp/test/bs_poly_map_test.js +++ b/jscomp/test/bs_poly_map_test.js @@ -2,13 +2,13 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml = require("../../lib/js/caml.js"); let Belt_Map = require("../../lib/js/belt_Map.js"); let Belt_Set = require("../../lib/js/belt_Set.js"); let Belt_Array = require("../../lib/js/belt_Array.js"); -let Caml_option = require("../../lib/js/caml_option.js"); let Belt_MapDict = require("../../lib/js/belt_MapDict.js"); +let Primitive_int = require("../../lib/js/primitive_int.js"); let Array_data_util = require("./array_data_util.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); let suites = { contents: /* [] */0 @@ -27,7 +27,7 @@ function b(loc, v) { } let Icmp = { - cmp: Caml.int_compare + cmp: Primitive_int.compare }; function mapOfArray(x) { @@ -48,7 +48,7 @@ function emptyMap() { function mergeInter(s1, s2) { let m = Belt_Map.merge(s1, s2, (k, v1, v2) => { if (v1 !== undefined && v2 !== undefined) { - return Caml_option.some(undefined); + return Primitive_option.some(undefined); } }); @@ -58,7 +58,7 @@ function mergeInter(s1, s2) { function mergeUnion(s1, s2) { let m = Belt_Map.merge(s1, s2, (k, v1, v2) => { if (v1 !== undefined || v2 !== undefined) { - return Caml_option.some(undefined); + return Primitive_option.some(undefined); } }); @@ -68,7 +68,7 @@ function mergeUnion(s1, s2) { function mergeDiff(s1, s2) { let m = Belt_Map.merge(s1, s2, (k, v1, v2) => { if (v1 !== undefined && v2 === undefined) { - return Caml_option.some(undefined); + return Primitive_option.some(undefined); } }); @@ -162,9 +162,9 @@ let u0$1 = Belt_Map.fromArray(randomRange(0, 100), Icmp); let u1$1 = Belt_Map.set(u0$1, 3, 32); -eq("File \"bs_poly_map_test.res\", line 108, characters 5-12", Belt_Map.get(u1$1, 3), 32); +eq("File \"bs_poly_map_test.res\", line 107, characters 5-12", Belt_Map.get(u1$1, 3), 32); -eq("File \"bs_poly_map_test.res\", line 109, characters 5-12", Belt_Map.get(u0$1, 3), 3); +eq("File \"bs_poly_map_test.res\", line 108, characters 5-12", Belt_Map.get(u0$1, 3), 3); function acc(m, is) { return Belt_Array.reduce(is, m, (a, i) => Belt_Map.update(a, i, n => { @@ -185,7 +185,7 @@ let m = { let m1 = acc(m, Belt_Array.concat(Array_data_util.randomRange(0, 20), Array_data_util.randomRange(10, 30))); -b("File \"bs_poly_map_test.res\", line 126, characters 4-11", Belt_Map.eq(m1, Belt_Map.fromArray(Belt_Array.makeBy(31, i => [ +b("File \"bs_poly_map_test.res\", line 125, characters 4-11", Belt_Map.eq(m1, Belt_Map.fromArray(Belt_Array.makeBy(31, i => [ i, i >= 10 && i <= 20 ? 2 : 1 ]), Icmp), (x, y) => x === y)); @@ -207,7 +207,7 @@ let v2 = Belt_Map.fromArray(Belt_Array.map(Array_data_util.randomRange(0, 10000) x ]), Icmp); -b("File \"bs_poly_map_test.res\", line 150, characters 4-11", Belt_Map.eq(v1, v2, (x, y) => x === y)); +b("File \"bs_poly_map_test.res\", line 149, characters 4-11", Belt_Map.eq(v1, v2, (x, y) => x === y)); function inc(x) { if (x !== undefined) { @@ -229,35 +229,35 @@ let match$1 = match[0]; let match$2 = Belt_Map.get(v3, 10); -b("File \"bs_poly_map_test.res\", line 161, characters 4-11", match$2 !== undefined ? match$2 === 11 : false); +b("File \"bs_poly_map_test.res\", line 160, characters 4-11", match$2 !== undefined ? match$2 === 11 : false); let match$3 = Belt_Map.get(v3, -10); -b("File \"bs_poly_map_test.res\", line 168, characters 4-11", match$3 === undefined); +b("File \"bs_poly_map_test.res\", line 167, characters 4-11", match$3 === undefined); let match$4 = Belt_Map.get(v4, -10); -b("File \"bs_poly_map_test.res\", line 175, characters 4-11", match$4 !== undefined ? match$4 === 0 : false); +b("File \"bs_poly_map_test.res\", line 174, characters 4-11", match$4 !== undefined ? match$4 === 0 : false); let map = Belt_Map.remove({ cmp: Icmp.cmp, data: undefined }, 0); -b("File \"bs_poly_map_test.res\", line 181, characters 4-11", Belt_MapDict.isEmpty(map.data)); +b("File \"bs_poly_map_test.res\", line 180, characters 4-11", Belt_MapDict.isEmpty(map.data)); let map$1 = Belt_Map.removeMany({ cmp: Icmp.cmp, data: undefined }, [0]); -b("File \"bs_poly_map_test.res\", line 182, characters 4-11", Belt_MapDict.isEmpty(map$1.data)); +b("File \"bs_poly_map_test.res\", line 181, characters 4-11", Belt_MapDict.isEmpty(map$1.data)); -b("File \"bs_poly_map_test.res\", line 184, characters 4-11", pres !== undefined ? pres === 5000 : false); +b("File \"bs_poly_map_test.res\", line 183, characters 4-11", pres !== undefined ? pres === 5000 : false); -b("File \"bs_poly_map_test.res\", line 190, characters 4-11", Belt_Array.eq(Belt_MapDict.keysToArray(match$1[0].data), Belt_Array.makeBy(5000, i => i), (prim0, prim1) => prim0 === prim1)); +b("File \"bs_poly_map_test.res\", line 189, characters 4-11", Belt_Array.eq(Belt_MapDict.keysToArray(match$1[0].data), Belt_Array.makeBy(5000, i => i), (prim0, prim1) => prim0 === prim1)); -b("File \"bs_poly_map_test.res\", line 191, characters 4-11", Belt_Array.eq(Belt_MapDict.keysToArray(match$1[1].data), Belt_Array.makeBy(5000, i => 5001 + i | 0), (prim0, prim1) => prim0 === prim1)); +b("File \"bs_poly_map_test.res\", line 190, characters 4-11", Belt_Array.eq(Belt_MapDict.keysToArray(match$1[1].data), Belt_Array.makeBy(5000, i => 5001 + i | 0), (prim0, prim1) => prim0 === prim1)); let v7 = Belt_Map.remove(v3, 5000); @@ -265,11 +265,11 @@ let match$5 = Belt_Map.split(v7, 5000); let match$6 = match$5[0]; -b("File \"bs_poly_map_test.res\", line 196, characters 4-11", match$5[1] === undefined); +b("File \"bs_poly_map_test.res\", line 195, characters 4-11", match$5[1] === undefined); -b("File \"bs_poly_map_test.res\", line 202, characters 4-11", Belt_Array.eq(Belt_MapDict.keysToArray(match$6[0].data), Belt_Array.makeBy(5000, i => i), (prim0, prim1) => prim0 === prim1)); +b("File \"bs_poly_map_test.res\", line 201, characters 4-11", Belt_Array.eq(Belt_MapDict.keysToArray(match$6[0].data), Belt_Array.makeBy(5000, i => i), (prim0, prim1) => prim0 === prim1)); -b("File \"bs_poly_map_test.res\", line 203, characters 4-11", Belt_Array.eq(Belt_MapDict.keysToArray(match$6[1].data), Belt_Array.makeBy(5000, i => 5001 + i | 0), (prim0, prim1) => prim0 === prim1)); +b("File \"bs_poly_map_test.res\", line 202, characters 4-11", Belt_Array.eq(Belt_MapDict.keysToArray(match$6[1].data), Belt_Array.makeBy(5000, i => 5001 + i | 0), (prim0, prim1) => prim0 === prim1)); Mt.from_pair_suites("Bs_poly_map_test", suites.contents); diff --git a/jscomp/test/bs_poly_map_test.res b/jscomp/test/bs_poly_map_test.res index d3084fa487..76d2bbce35 100644 --- a/jscomp/test/bs_poly_map_test.res +++ b/jscomp/test/bs_poly_map_test.res @@ -102,11 +102,10 @@ let () = { } let () = { - module Array = M let u0 = mapOfArray(randomRange(0, 100)) - let u1 = u0[3] = 32 - eq(__LOC__, u1[3], Some(32)) - eq(__LOC__, u0[3], Some(3)) + let u1 = M.set(u0, 3, 32) + eq(__LOC__, M.get(u1, 3), Some(32)) + eq(__LOC__, M.get(u0, 3), Some(3)) } let acc = (m, i) => diff --git a/jscomp/test/bs_poly_mutable_map_test.js b/jscomp/test/bs_poly_mutable_map_test.js index 5d8d490da6..f5ec27f549 100644 --- a/jscomp/test/bs_poly_mutable_map_test.js +++ b/jscomp/test/bs_poly_mutable_map_test.js @@ -2,9 +2,9 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml = require("../../lib/js/caml.js"); let Belt_Set = require("../../lib/js/belt_Set.js"); let Belt_Array = require("../../lib/js/belt_Array.js"); +let Primitive_int = require("../../lib/js/primitive_int.js"); let Array_data_util = require("./array_data_util.js"); let Belt_MutableMap = require("../../lib/js/belt_MutableMap.js"); let Belt_internalAVLtree = require("../../lib/js/belt_internalAVLtree.js"); @@ -26,7 +26,7 @@ function b(loc, v) { } let Icmp = { - cmp: Caml.int_compare + cmp: Primitive_int.compare }; function f(x) { diff --git a/jscomp/test/bs_poly_mutable_set_test.js b/jscomp/test/bs_poly_mutable_set_test.js index 02a95bc8e5..966f655989 100644 --- a/jscomp/test/bs_poly_mutable_set_test.js +++ b/jscomp/test/bs_poly_mutable_set_test.js @@ -2,9 +2,9 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml = require("../../lib/js/caml.js"); let Belt_List = require("../../lib/js/belt_List.js"); let Belt_Array = require("../../lib/js/belt_Array.js"); +let Primitive_int = require("../../lib/js/primitive_int.js"); let Array_data_util = require("./array_data_util.js"); let Belt_MutableSet = require("../../lib/js/belt_MutableSet.js"); let Belt_internalAVLset = require("../../lib/js/belt_internalAVLset.js"); @@ -26,7 +26,7 @@ function b(loc, x) { } let IntCmp = { - cmp: Caml.int_compare + cmp: Primitive_int.compare }; function fromArray(none) { diff --git a/jscomp/test/bs_poly_set_test.js b/jscomp/test/bs_poly_set_test.js index 1645d3d1bd..bda700154b 100644 --- a/jscomp/test/bs_poly_set_test.js +++ b/jscomp/test/bs_poly_set_test.js @@ -2,14 +2,14 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml = require("../../lib/js/caml.js"); let Belt_Set = require("../../lib/js/belt_Set.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); let Belt_List = require("../../lib/js/belt_List.js"); let Belt_Array = require("../../lib/js/belt_Array.js"); let Belt_SetDict = require("../../lib/js/belt_SetDict.js"); +let Primitive_int = require("../../lib/js/primitive_int.js"); let Belt_SortArray = require("../../lib/js/belt_SortArray.js"); let Array_data_util = require("./array_data_util.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); let suites = { contents: /* [] */0 @@ -32,7 +32,7 @@ function t(loc, x) { } let IntCmp = { - cmp: Caml.int_compare + cmp: Primitive_int.compare }; let u0 = Belt_Set.fromArray(Array_data_util.range(0, 30), IntCmp); @@ -156,7 +156,7 @@ let u29 = Belt_Set.union(u26, u27); b("File \"bs_poly_set_test.res\", line 71, characters 4-11", Belt_Set.eq(u28, u29)); -b("File \"bs_poly_set_test.res\", line 72, characters 4-11", Caml_obj.equal(Belt_SetDict.toArray(u29.data), Belt_SortArray.stableSortBy(Belt_Array.concat(ss, [3]), Caml.int_compare))); +b("File \"bs_poly_set_test.res\", line 72, characters 4-11", Primitive_object.equal(Belt_SetDict.toArray(u29.data), Belt_SortArray.stableSortBy(Belt_Array.concat(ss, [3]), Primitive_int.compare))); b("File \"bs_poly_set_test.res\", line 73, characters 4-11", Belt_Set.eq(u19, u20)); @@ -178,7 +178,7 @@ b("File \"bs_poly_set_test.res\", line 81, characters 4-11", Belt_Set.subset(u21 b("File \"bs_poly_set_test.res\", line 82, characters 4-11", 47 === Belt_Set.getUndefined(u22, 47)); -b("File \"bs_poly_set_test.res\", line 83, characters 4-11", Caml_obj.equal(47, Belt_Set.get(u22, 47))); +b("File \"bs_poly_set_test.res\", line 83, characters 4-11", Primitive_object.equal(47, Belt_Set.get(u22, 47))); b("File \"bs_poly_set_test.res\", line 84, characters 4-11", Belt_Set.getUndefined(u22, 59) === undefined); diff --git a/jscomp/test/bs_queue_test.js b/jscomp/test/bs_queue_test.js index 203429cc14..c99f82b0d6 100644 --- a/jscomp/test/bs_queue_test.js +++ b/jscomp/test/bs_queue_test.js @@ -2,8 +2,8 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); let Belt_Array = require("../../lib/js/belt_Array.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); let Belt_MutableQueue = require("../../lib/js/belt_MutableQueue.js"); let suites = { @@ -42,7 +42,7 @@ let q = { last: undefined }; -if (!(Caml_obj.equal(Belt_MutableQueue.toArray(q), []) && q.length === 0)) { +if (!(Primitive_object.equal(Belt_MutableQueue.toArray(q), []) && q.length === 0)) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -54,7 +54,7 @@ if (!(Caml_obj.equal(Belt_MutableQueue.toArray(q), []) && q.length === 0)) { }; } -if (!(Caml_obj.equal(Belt_MutableQueue.toArray((Belt_MutableQueue.add(q, 1), q)), [1]) && q.length === 1)) { +if (!(Primitive_object.equal(Belt_MutableQueue.toArray((Belt_MutableQueue.add(q, 1), q)), [1]) && q.length === 1)) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -66,7 +66,7 @@ if (!(Caml_obj.equal(Belt_MutableQueue.toArray((Belt_MutableQueue.add(q, 1), q)) }; } -if (!(Caml_obj.equal(Belt_MutableQueue.toArray((Belt_MutableQueue.add(q, 2), q)), [ +if (!(Primitive_object.equal(Belt_MutableQueue.toArray((Belt_MutableQueue.add(q, 2), q)), [ 1, 2 ]) && q.length === 2)) { @@ -81,7 +81,7 @@ if (!(Caml_obj.equal(Belt_MutableQueue.toArray((Belt_MutableQueue.add(q, 2), q)) }; } -if (!(Caml_obj.equal(Belt_MutableQueue.toArray((Belt_MutableQueue.add(q, 3), q)), [ +if (!(Primitive_object.equal(Belt_MutableQueue.toArray((Belt_MutableQueue.add(q, 3), q)), [ 1, 2, 3 @@ -97,7 +97,7 @@ if (!(Caml_obj.equal(Belt_MutableQueue.toArray((Belt_MutableQueue.add(q, 3), q)) }; } -if (!(Caml_obj.equal(Belt_MutableQueue.toArray((Belt_MutableQueue.add(q, 4), q)), [ +if (!(Primitive_object.equal(Belt_MutableQueue.toArray((Belt_MutableQueue.add(q, 4), q)), [ 1, 2, 3, @@ -126,7 +126,7 @@ if (Belt_MutableQueue.popExn(q) !== 1) { }; } -if (!(Caml_obj.equal(Belt_MutableQueue.toArray(q), [ +if (!(Primitive_object.equal(Belt_MutableQueue.toArray(q), [ 2, 3, 4 @@ -154,7 +154,7 @@ if (Belt_MutableQueue.popExn(q) !== 2) { }; } -if (!(Caml_obj.equal(Belt_MutableQueue.toArray(q), [ +if (!(Primitive_object.equal(Belt_MutableQueue.toArray(q), [ 3, 4 ]) && q.length === 2)) { @@ -181,7 +181,7 @@ if (Belt_MutableQueue.popExn(q) !== 3) { }; } -if (!(Caml_obj.equal(Belt_MutableQueue.toArray(q), [4]) && q.length === 1)) { +if (!(Primitive_object.equal(Belt_MutableQueue.toArray(q), [4]) && q.length === 1)) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -205,7 +205,7 @@ if (Belt_MutableQueue.popExn(q) !== 4) { }; } -if (!(Caml_obj.equal(Belt_MutableQueue.toArray(q), []) && q.length === 0)) { +if (!(Primitive_object.equal(Belt_MutableQueue.toArray(q), []) && q.length === 0)) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -469,7 +469,7 @@ if (!does_raise(Belt_MutableQueue.popExn, q$3)) { }; } -if (!Caml_obj.equal(q$3, { +if (!Primitive_object.equal(q$3, { length: 0, first: undefined, last: undefined @@ -511,7 +511,7 @@ for (let i$1 = 1; i$1 <= 10; ++i$1) { let q2 = Belt_MutableQueue.copy(q1); -if (!Caml_obj.equal(Belt_MutableQueue.toArray(q1), [ +if (!Primitive_object.equal(Belt_MutableQueue.toArray(q1), [ 1, 2, 3, @@ -534,7 +534,7 @@ if (!Caml_obj.equal(Belt_MutableQueue.toArray(q1), [ }; } -if (!Caml_obj.equal(Belt_MutableQueue.toArray(q2), [ +if (!Primitive_object.equal(Belt_MutableQueue.toArray(q2), [ 1, 2, 3, @@ -759,7 +759,7 @@ if (q1$1.length !== 0) { }; } -if (!Caml_obj.equal(Belt_MutableQueue.toArray(q1$1), [])) { +if (!Primitive_object.equal(Belt_MutableQueue.toArray(q1$1), [])) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -783,7 +783,7 @@ if (q2$1.length !== 0) { }; } -if (!Caml_obj.equal(Belt_MutableQueue.toArray(q2$1), [])) { +if (!Primitive_object.equal(Belt_MutableQueue.toArray(q2$1), [])) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -809,7 +809,7 @@ if (q1$1.length !== 0) { }; } -if (!Caml_obj.equal(Belt_MutableQueue.toArray(q1$1), [])) { +if (!Primitive_object.equal(Belt_MutableQueue.toArray(q1$1), [])) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -833,7 +833,7 @@ if (q2$1.length !== 0) { }; } -if (!Caml_obj.equal(Belt_MutableQueue.toArray(q2$1), [])) { +if (!Primitive_object.equal(Belt_MutableQueue.toArray(q2$1), [])) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -873,7 +873,7 @@ if (q1$2.length !== 4) { }; } -if (!Caml_obj.equal(Belt_MutableQueue.toArray(q1$2), [ +if (!Primitive_object.equal(Belt_MutableQueue.toArray(q1$2), [ 1, 2, 3, @@ -902,7 +902,7 @@ if (q2$2.length !== 0) { }; } -if (!Caml_obj.equal(Belt_MutableQueue.toArray(q2$2), [])) { +if (!Primitive_object.equal(Belt_MutableQueue.toArray(q2$2), [])) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -928,7 +928,7 @@ if (q1$2.length !== 0) { }; } -if (!Caml_obj.equal(Belt_MutableQueue.toArray(q1$2), [])) { +if (!Primitive_object.equal(Belt_MutableQueue.toArray(q1$2), [])) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -952,7 +952,7 @@ if (q2$2.length !== 4) { }; } -if (!Caml_obj.equal(Belt_MutableQueue.toArray(q2$2), [ +if (!Primitive_object.equal(Belt_MutableQueue.toArray(q2$2), [ 1, 2, 3, @@ -997,7 +997,7 @@ if (q1$3.length !== 0) { }; } -if (!Caml_obj.equal(Belt_MutableQueue.toArray(q1$3), [])) { +if (!Primitive_object.equal(Belt_MutableQueue.toArray(q1$3), [])) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -1021,7 +1021,7 @@ if (q2$3.length !== 4) { }; } -if (!Caml_obj.equal(Belt_MutableQueue.toArray(q2$3), [ +if (!Primitive_object.equal(Belt_MutableQueue.toArray(q2$3), [ 5, 6, 7, @@ -1052,7 +1052,7 @@ if (q1$3.length !== 0) { }; } -if (!Caml_obj.equal(Belt_MutableQueue.toArray(q1$3), [])) { +if (!Primitive_object.equal(Belt_MutableQueue.toArray(q1$3), [])) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -1076,7 +1076,7 @@ if (q2$3.length !== 4) { }; } -if (!Caml_obj.equal(Belt_MutableQueue.toArray(q2$3), [ +if (!Primitive_object.equal(Belt_MutableQueue.toArray(q2$3), [ 5, 6, 7, @@ -1125,7 +1125,7 @@ if (q1$4.length !== 4) { }; } -if (!Caml_obj.equal(Belt_MutableQueue.toArray(q1$4), [ +if (!Primitive_object.equal(Belt_MutableQueue.toArray(q1$4), [ 1, 2, 3, @@ -1154,7 +1154,7 @@ if (q2$4.length !== 4) { }; } -if (!Caml_obj.equal(Belt_MutableQueue.toArray(q2$4), [ +if (!Primitive_object.equal(Belt_MutableQueue.toArray(q2$4), [ 5, 6, 7, @@ -1185,7 +1185,7 @@ if (q1$4.length !== 0) { }; } -if (!Caml_obj.equal(Belt_MutableQueue.toArray(q1$4), [])) { +if (!Primitive_object.equal(Belt_MutableQueue.toArray(q1$4), [])) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -1220,7 +1220,7 @@ if (q2$4.length !== 8) { }; } -if (!Caml_obj.equal(Belt_MutableQueue.toArray(q2$4), v)) { +if (!Primitive_object.equal(Belt_MutableQueue.toArray(q2$4), v)) { throw { RE_EXN_ID: "Assert_failure", _1: [ diff --git a/jscomp/test/bs_set_int_test.js b/jscomp/test/bs_set_int_test.js index e2eeb5971f..b6dfe0be99 100644 --- a/jscomp/test/bs_set_int_test.js +++ b/jscomp/test/bs_set_int_test.js @@ -2,8 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); -let $$Array = require("../../lib/js/array.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let Belt_Array = require("../../lib/js/belt_Array.js"); let Belt_SetInt = require("../../lib/js/belt_SetInt.js"); let Array_data_util = require("./array_data_util.js"); @@ -32,7 +31,7 @@ function $eq$star(a, b) { return Belt_SetInt.eq(Belt_SetInt.fromArray(a), Belt_SetInt.fromArray(b)); } -b("File \"bs_set_int_test.res\", line 21, characters 11-18", $eq$star([ +b("File \"bs_set_int_test.res\", line 22, characters 11-18", $eq$star([ 1, 2, 3 @@ -52,21 +51,21 @@ let u = Belt_SetInt.intersect(Belt_SetInt.fromArray([ 5 ])); -b("File \"bs_set_int_test.res\", line 27, characters 11-18", Belt_SetInt.eq(Belt_SetInt.fromArray([3]), u)); +b("File \"bs_set_int_test.res\", line 28, characters 11-18", Belt_SetInt.eq(Belt_SetInt.fromArray([3]), u)); function range(i, j) { - return $$Array.init((j - i | 0) + 1 | 0, k => k + i | 0); + return Belt_Array.init((j - i | 0) + 1 | 0, k => k + i | 0); } function revRange(i, j) { - return $$Array.of_list(List.rev($$Array.to_list($$Array.init((j - i | 0) + 1 | 0, k => k + i | 0)))); + return Belt_List.toArray(Belt_List.reverse(Belt_List.fromArray(Belt_Array.init((j - i | 0) + 1 | 0, k => k + i | 0)))); } -let v = Belt_SetInt.fromArray($$Array.append(range(100, 1000), revRange(400, 1500))); +let v = Belt_SetInt.fromArray(Belt_Array.concat(range(100, 1000), revRange(400, 1500))); let i = range(100, 1500); -b("File \"bs_set_int_test.res\", line 36, characters 4-11", Belt_SetInt.eq(Belt_SetInt.fromArray(i), v)); +b("File \"bs_set_int_test.res\", line 37, characters 4-11", Belt_SetInt.eq(Belt_SetInt.fromArray(i), v)); let match = Belt_SetInt.partition(v, x => x % 3 === 0); @@ -86,45 +85,45 @@ let nl = l; let nr = r; -b("File \"bs_set_int_test.res\", line 49, characters 4-11", Belt_SetInt.eq(match[0], nl)); +b("File \"bs_set_int_test.res\", line 50, characters 4-11", Belt_SetInt.eq(match[0], nl)); -b("File \"bs_set_int_test.res\", line 50, characters 4-11", Belt_SetInt.eq(match[1], nr)); +b("File \"bs_set_int_test.res\", line 51, characters 4-11", Belt_SetInt.eq(match[1], nr)); let i$2 = range(50, 100); let s = Belt_SetInt.intersect(Belt_SetInt.fromArray(range(1, 100)), Belt_SetInt.fromArray(range(50, 200))); -b("File \"bs_set_int_test.res\", line 54, characters 2-9", Belt_SetInt.eq(Belt_SetInt.fromArray(i$2), s)); +b("File \"bs_set_int_test.res\", line 55, characters 2-9", Belt_SetInt.eq(Belt_SetInt.fromArray(i$2), s)); let i$3 = range(1, 200); let s$1 = Belt_SetInt.union(Belt_SetInt.fromArray(range(1, 100)), Belt_SetInt.fromArray(range(50, 200))); -b("File \"bs_set_int_test.res\", line 65, characters 2-9", Belt_SetInt.eq(Belt_SetInt.fromArray(i$3), s$1)); +b("File \"bs_set_int_test.res\", line 66, characters 2-9", Belt_SetInt.eq(Belt_SetInt.fromArray(i$3), s$1)); let i$4 = range(1, 49); let s$2 = Belt_SetInt.diff(Belt_SetInt.fromArray(range(1, 100)), Belt_SetInt.fromArray(range(50, 200))); -b("File \"bs_set_int_test.res\", line 76, characters 2-9", Belt_SetInt.eq(Belt_SetInt.fromArray(i$4), s$2)); +b("File \"bs_set_int_test.res\", line 77, characters 2-9", Belt_SetInt.eq(Belt_SetInt.fromArray(i$4), s$2)); let i$5 = revRange(50, 100); let s$3 = Belt_SetInt.intersect(Belt_SetInt.fromArray(revRange(1, 100)), Belt_SetInt.fromArray(revRange(50, 200))); -b("File \"bs_set_int_test.res\", line 87, characters 2-9", Belt_SetInt.eq(Belt_SetInt.fromArray(i$5), s$3)); +b("File \"bs_set_int_test.res\", line 88, characters 2-9", Belt_SetInt.eq(Belt_SetInt.fromArray(i$5), s$3)); let i$6 = revRange(1, 200); let s$4 = Belt_SetInt.union(Belt_SetInt.fromArray(revRange(1, 100)), Belt_SetInt.fromArray(revRange(50, 200))); -b("File \"bs_set_int_test.res\", line 98, characters 2-9", Belt_SetInt.eq(Belt_SetInt.fromArray(i$6), s$4)); +b("File \"bs_set_int_test.res\", line 99, characters 2-9", Belt_SetInt.eq(Belt_SetInt.fromArray(i$6), s$4)); let i$7 = revRange(1, 49); let s$5 = Belt_SetInt.diff(Belt_SetInt.fromArray(revRange(1, 100)), Belt_SetInt.fromArray(revRange(50, 200))); -b("File \"bs_set_int_test.res\", line 109, characters 2-9", Belt_SetInt.eq(Belt_SetInt.fromArray(i$7), s$5)); +b("File \"bs_set_int_test.res\", line 110, characters 2-9", Belt_SetInt.eq(Belt_SetInt.fromArray(i$7), s$5)); let ss = [ 1, @@ -156,11 +155,11 @@ function approx(loc, x, y) { b(loc, x === y); } -eq("File \"bs_set_int_test.res\", line 124, characters 5-12", Belt_SetInt.reduce(v$1, 0, (x, y) => x + y | 0), Belt_Array.reduce(ss, 0, (prim0, prim1) => prim0 + prim1 | 0)); +eq("File \"bs_set_int_test.res\", line 125, characters 5-12", Belt_SetInt.reduce(v$1, 0, (x, y) => x + y | 0), Belt_Array.reduce(ss, 0, (prim0, prim1) => prim0 + prim1 | 0)); -approx("File \"bs_set_int_test.res\", line 125, characters 9-16", -1, minv); +approx("File \"bs_set_int_test.res\", line 126, characters 9-16", -1, minv); -approx("File \"bs_set_int_test.res\", line 126, characters 9-16", 222, maxv); +approx("File \"bs_set_int_test.res\", line 127, characters 9-16", 222, maxv); let v$2 = Belt_SetInt.remove(v$1, 3); @@ -168,9 +167,9 @@ let minv$1 = Belt_SetInt.minimum(v$2); let maxv$1 = Belt_SetInt.maximum(v$2); -eq("File \"bs_set_int_test.res\", line 129, characters 5-12", minv$1, -1); +eq("File \"bs_set_int_test.res\", line 130, characters 5-12", minv$1, -1); -eq("File \"bs_set_int_test.res\", line 130, characters 5-12", maxv$1, 222); +eq("File \"bs_set_int_test.res\", line 131, characters 5-12", maxv$1, 222); let v$3 = Belt_SetInt.remove(v$2, 222); @@ -178,9 +177,9 @@ let minv$2 = Belt_SetInt.minimum(v$3); let maxv$2 = Belt_SetInt.maximum(v$3); -eq("File \"bs_set_int_test.res\", line 133, characters 5-12", minv$2, -1); +eq("File \"bs_set_int_test.res\", line 134, characters 5-12", minv$2, -1); -eq("File \"bs_set_int_test.res\", line 134, characters 5-12", maxv$2, 33); +eq("File \"bs_set_int_test.res\", line 135, characters 5-12", maxv$2, 33); let v$4 = Belt_SetInt.remove(v$3, -1); @@ -188,9 +187,9 @@ let minv$3 = Belt_SetInt.minimum(v$4); let maxv$3 = Belt_SetInt.maximum(v$4); -eq("File \"bs_set_int_test.res\", line 137, characters 5-12", minv$3, 0); +eq("File \"bs_set_int_test.res\", line 138, characters 5-12", minv$3, 0); -eq("File \"bs_set_int_test.res\", line 138, characters 5-12", maxv$3, 33); +eq("File \"bs_set_int_test.res\", line 139, characters 5-12", maxv$3, 33); let v$5 = Belt_SetInt.remove(v$4, 0); @@ -204,7 +203,7 @@ let v$9 = Belt_SetInt.remove(v$8, 4); let v$10 = Belt_SetInt.remove(v$9, 1); -b("File \"bs_set_int_test.res\", line 145, characters 4-11", Belt_SetInt.isEmpty(v$10)); +b("File \"bs_set_int_test.res\", line 146, characters 4-11", Belt_SetInt.isEmpty(v$10)); let v$11 = Belt_Array.makeByAndShuffle(1000000, i => i); @@ -218,7 +217,7 @@ let xx = Belt_Array.reduce(firstHalf, u$1, Belt_SetInt.remove); Belt_SetInt.checkInvariantInternal(u$1); -b("File \"bs_set_int_test.res\", line 157, characters 4-11", Belt_SetInt.eq(Belt_SetInt.union(Belt_SetInt.fromArray(firstHalf), xx), u$1)); +b("File \"bs_set_int_test.res\", line 158, characters 4-11", Belt_SetInt.eq(Belt_SetInt.union(Belt_SetInt.fromArray(firstHalf), xx), u$1)); let aa = Belt_SetInt.fromArray(Array_data_util.randomRange(0, 100)); @@ -228,17 +227,17 @@ let cc = Belt_SetInt.fromArray(Array_data_util.randomRange(120, 200)); let dd = Belt_SetInt.union(aa, cc); -b("File \"bs_set_int_test.res\", line 170, characters 4-11", Belt_SetInt.subset(aa, bb)); +b("File \"bs_set_int_test.res\", line 171, characters 4-11", Belt_SetInt.subset(aa, bb)); -b("File \"bs_set_int_test.res\", line 171, characters 4-11", Belt_SetInt.subset(dd, bb)); +b("File \"bs_set_int_test.res\", line 172, characters 4-11", Belt_SetInt.subset(dd, bb)); -b("File \"bs_set_int_test.res\", line 172, characters 4-11", Belt_SetInt.subset(Belt_SetInt.add(dd, 200), bb)); +b("File \"bs_set_int_test.res\", line 173, characters 4-11", Belt_SetInt.subset(Belt_SetInt.add(dd, 200), bb)); -b("File \"bs_set_int_test.res\", line 173, characters 4-11", Belt_SetInt.add(dd, 200) === dd); +b("File \"bs_set_int_test.res\", line 174, characters 4-11", Belt_SetInt.add(dd, 200) === dd); -b("File \"bs_set_int_test.res\", line 174, characters 4-11", Belt_SetInt.add(dd, 0) === dd); +b("File \"bs_set_int_test.res\", line 175, characters 4-11", Belt_SetInt.add(dd, 0) === dd); -b("File \"bs_set_int_test.res\", line 175, characters 4-11", !Belt_SetInt.subset(Belt_SetInt.add(dd, 201), bb)); +b("File \"bs_set_int_test.res\", line 176, characters 4-11", !Belt_SetInt.subset(Belt_SetInt.add(dd, 201), bb)); let aa$1 = Belt_SetInt.fromArray(Array_data_util.randomRange(0, 100)); @@ -250,13 +249,13 @@ let dd$1 = Belt_SetInt.remove(bb$1, 99); let ee = Belt_SetInt.add(dd$1, 101); -b("File \"bs_set_int_test.res\", line 184, characters 4-11", Belt_SetInt.eq(aa$1, bb$1)); +b("File \"bs_set_int_test.res\", line 185, characters 4-11", Belt_SetInt.eq(aa$1, bb$1)); -b("File \"bs_set_int_test.res\", line 185, characters 4-11", !Belt_SetInt.eq(aa$1, cc$1)); +b("File \"bs_set_int_test.res\", line 186, characters 4-11", !Belt_SetInt.eq(aa$1, cc$1)); -b("File \"bs_set_int_test.res\", line 186, characters 4-11", !Belt_SetInt.eq(dd$1, cc$1)); +b("File \"bs_set_int_test.res\", line 187, characters 4-11", !Belt_SetInt.eq(dd$1, cc$1)); -b("File \"bs_set_int_test.res\", line 187, characters 4-11", !Belt_SetInt.eq(bb$1, ee)); +b("File \"bs_set_int_test.res\", line 188, characters 4-11", !Belt_SetInt.eq(bb$1, ee)); let a1 = Belt_SetInt.mergeMany(undefined, Array_data_util.randomRange(0, 100)); @@ -272,17 +271,17 @@ let a5 = match$2[1]; let a4 = match$2[0]; -b("File \"bs_set_int_test.res\", line 196, characters 4-11", Belt_SetInt.eq(a1, Belt_SetInt.fromArray(Array_data_util.randomRange(0, 100)))); +b("File \"bs_set_int_test.res\", line 197, characters 4-11", Belt_SetInt.eq(a1, Belt_SetInt.fromArray(Array_data_util.randomRange(0, 100)))); -b("File \"bs_set_int_test.res\", line 197, characters 4-11", Belt_SetInt.eq(a2, a3)); +b("File \"bs_set_int_test.res\", line 198, characters 4-11", Belt_SetInt.eq(a2, a3)); -b("File \"bs_set_int_test.res\", line 198, characters 4-11", match$1[1]); +b("File \"bs_set_int_test.res\", line 199, characters 4-11", match$1[1]); -b("File \"bs_set_int_test.res\", line 199, characters 4-11", Belt_SetInt.eq(a3, a4)); +b("File \"bs_set_int_test.res\", line 200, characters 4-11", Belt_SetInt.eq(a3, a4)); let a6 = Belt_SetInt.remove(Belt_SetInt.removeMany(a1, Array_data_util.randomRange(0, 39)), 40); -b("File \"bs_set_int_test.res\", line 201, characters 4-11", Belt_SetInt.eq(a5, a6)); +b("File \"bs_set_int_test.res\", line 202, characters 4-11", Belt_SetInt.eq(a5, a6)); let a7 = Belt_SetInt.remove(a1, 40); @@ -292,29 +291,29 @@ let match$4 = match$3[0]; let a9 = match$4[1]; -b("File \"bs_set_int_test.res\", line 204, characters 4-11", !match$3[1]); +b("File \"bs_set_int_test.res\", line 205, characters 4-11", !match$3[1]); -b("File \"bs_set_int_test.res\", line 205, characters 4-11", Belt_SetInt.eq(a4, match$4[0])); +b("File \"bs_set_int_test.res\", line 206, characters 4-11", Belt_SetInt.eq(a4, match$4[0])); -b("File \"bs_set_int_test.res\", line 206, characters 4-11", Belt_SetInt.eq(a5, a9)); +b("File \"bs_set_int_test.res\", line 207, characters 4-11", Belt_SetInt.eq(a5, a9)); let a10 = Belt_SetInt.removeMany(a9, Array_data_util.randomRange(42, 2000)); -eq("File \"bs_set_int_test.res\", line 208, characters 5-12", Belt_SetInt.size(a10), 1); +eq("File \"bs_set_int_test.res\", line 209, characters 5-12", Belt_SetInt.size(a10), 1); let a11 = Belt_SetInt.removeMany(a9, Array_data_util.randomRange(0, 2000)); -b("File \"bs_set_int_test.res\", line 210, characters 4-11", Belt_SetInt.isEmpty(a11)); +b("File \"bs_set_int_test.res\", line 211, characters 4-11", Belt_SetInt.isEmpty(a11)); let match$5 = Belt_SetInt.split(undefined, 0); let match$6 = match$5[0]; -b("File \"bs_set_int_test.res\", line 215, characters 4-11", Belt_SetInt.isEmpty(match$6[0])); +b("File \"bs_set_int_test.res\", line 216, characters 4-11", Belt_SetInt.isEmpty(match$6[0])); -b("File \"bs_set_int_test.res\", line 216, characters 4-11", Belt_SetInt.isEmpty(match$6[1])); +b("File \"bs_set_int_test.res\", line 217, characters 4-11", Belt_SetInt.isEmpty(match$6[1])); -b("File \"bs_set_int_test.res\", line 217, characters 4-11", !match$5[1]); +b("File \"bs_set_int_test.res\", line 218, characters 4-11", !match$5[1]); let v$12 = Belt_SetInt.fromArray(Array_data_util.randomRange(0, 2000)); @@ -339,23 +338,23 @@ let counted = Belt_Array.reduce(us, 0, (acc, x) => { } }); -eq("File \"bs_set_int_test.res\", line 234, characters 5-12", counted, 1001); +eq("File \"bs_set_int_test.res\", line 235, characters 5-12", counted, 1001); -b("File \"bs_set_int_test.res\", line 235, characters 4-11", Belt_SetInt.eq(v$12, v0)); +b("File \"bs_set_int_test.res\", line 236, characters 4-11", Belt_SetInt.eq(v$12, v0)); -b("File \"bs_set_int_test.res\", line 236, characters 4-11", Belt_SetInt.cmp(v$12, v0) === 0); +b("File \"bs_set_int_test.res\", line 237, characters 4-11", Belt_SetInt.cmp(v$12, v0) === 0); -b("File \"bs_set_int_test.res\", line 237, characters 4-11", Belt_SetInt.cmp(v$12, v1) < 0); +b("File \"bs_set_int_test.res\", line 238, characters 4-11", Belt_SetInt.cmp(v$12, v1) < 0); -b("File \"bs_set_int_test.res\", line 238, characters 4-11", Belt_SetInt.cmp(v$12, v2) > 0); +b("File \"bs_set_int_test.res\", line 239, characters 4-11", Belt_SetInt.cmp(v$12, v2) > 0); -b("File \"bs_set_int_test.res\", line 239, characters 4-11", Belt_SetInt.subset(v3, v0)); +b("File \"bs_set_int_test.res\", line 240, characters 4-11", Belt_SetInt.subset(v3, v0)); -b("File \"bs_set_int_test.res\", line 240, characters 4-11", !Belt_SetInt.subset(v1, v0)); +b("File \"bs_set_int_test.res\", line 241, characters 4-11", !Belt_SetInt.subset(v1, v0)); -eq("File \"bs_set_int_test.res\", line 241, characters 5-12", Belt_SetInt.get(v$12, 30), 30); +eq("File \"bs_set_int_test.res\", line 242, characters 5-12", Belt_SetInt.get(v$12, 30), 30); -eq("File \"bs_set_int_test.res\", line 242, characters 5-12", Belt_SetInt.get(v$12, 3000), undefined); +eq("File \"bs_set_int_test.res\", line 243, characters 5-12", Belt_SetInt.get(v$12, 3000), undefined); Mt.from_pair_suites("Bs_set_int_test", suites.contents); @@ -363,6 +362,8 @@ let N; let I; +let L; + let A; let ofA = Belt_SetInt.fromArray; @@ -373,6 +374,7 @@ exports.eq = eq; exports.b = b; exports.N = N; exports.I = I; +exports.L = L; exports.A = A; exports.$eq$tilde = $eq$tilde; exports.$eq$star = $eq$star; diff --git a/jscomp/test/bs_set_int_test.res b/jscomp/test/bs_set_int_test.res index 9b5223c511..44b6dd8c37 100644 --- a/jscomp/test/bs_set_int_test.res +++ b/jscomp/test/bs_set_int_test.res @@ -7,6 +7,7 @@ let b = (loc, v) => Mt.bool_suites(~suites, ~test_id, loc, v) module N = Belt.Set.Int module I = Array_data_util +module L = Belt.List module A = Belt.Array let \"=~" = (s, i) => { open N @@ -27,12 +28,12 @@ let u = { let () = b(__LOC__, \"=~"(u, [3])) /* inclusive */ -let range = (i, j) => Array.init(j - i + 1, k => k + i) +let range = (i, j) => A.init(j - i + 1, k => k + i) -let revRange = (i, j) => Array.of_list(List.rev(Array.to_list(Array.init(j - i + 1, k => k + i)))) +let revRange = (i, j) => L.toArray(L.reverse(L.fromArray(A.init(j - i + 1, k => k + i)))) let () = { - let v = ofA(Array.append(range(100, 1000), revRange(400, 1500))) + let v = ofA(A.concat(range(100, 1000), revRange(400, 1500))) b(__LOC__, \"=~"(v, range(100, 1500))) let (l, r) = N.partition(v, x => mod(x, 3) == 0) let (nl, nr) = { @@ -151,7 +152,7 @@ let () = { let u = N.fromArray(v) N.checkInvariantInternal(u) let firstHalf = A.slice(v, ~offset=0, ~len=2_000) - let xx = Belt.Array.reduce(firstHalf, u, N.remove) + let xx = A.reduce(firstHalf, u, N.remove) N.checkInvariantInternal(u) b( __LOC__, diff --git a/jscomp/test/bs_stack_test.js b/jscomp/test/bs_stack_test.js index f30fee5221..fa4ed88fee 100644 --- a/jscomp/test/bs_stack_test.js +++ b/jscomp/test/bs_stack_test.js @@ -2,8 +2,8 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_option = require("../../lib/js/caml_option.js"); let Js_undefined = require("../../lib/js/js_undefined.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); let Belt_MutableQueue = require("../../lib/js/belt_MutableQueue.js"); let Belt_MutableStack = require("../../lib/js/belt_MutableStack.js"); @@ -110,7 +110,7 @@ function n(l, r, a) { }; } -let test1 = n(Caml_option.some(n(Caml_option.some(n(undefined, undefined, 4)), Caml_option.some(n(undefined, undefined, 5)), 2)), Caml_option.some(n(undefined, undefined, 3)), 1); +let test1 = n(Primitive_option.some(n(Primitive_option.some(n(undefined, undefined, 4)), Primitive_option.some(n(undefined, undefined, 5)), 2)), Primitive_option.some(n(undefined, undefined, 3)), 1); function pushAllLeft(st1, s1) { let current = st1; @@ -121,9 +121,9 @@ function pushAllLeft(st1, s1) { }; } -let test2 = n(Caml_option.some(n(Caml_option.some(n(Caml_option.some(n(Caml_option.some(n(undefined, undefined, 4)), undefined, 2)), undefined, 5)), undefined, 1)), undefined, 3); +let test2 = n(Primitive_option.some(n(Primitive_option.some(n(Primitive_option.some(n(Primitive_option.some(n(undefined, undefined, 4)), undefined, 2)), undefined, 5)), undefined, 1)), undefined, 3); -let test3 = n(Caml_option.some(n(Caml_option.some(n(Caml_option.some(n(undefined, undefined, 4)), undefined, 2)), undefined, 5)), Caml_option.some(n(undefined, undefined, 3)), 1); +let test3 = n(Primitive_option.some(n(Primitive_option.some(n(Primitive_option.some(n(undefined, undefined, 4)), undefined, 2)), undefined, 5)), Primitive_option.some(n(undefined, undefined, 3)), 1); eq("File \"bs_stack_test.res\", line 98, characters 3-10", inOrder(test1), [ 4, diff --git a/jscomp/test/bs_string_test.js b/jscomp/test/bs_string_test.js index 3dc70613f0..c7176e11e2 100644 --- a/jscomp/test/bs_string_test.js +++ b/jscomp/test/bs_string_test.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -26,7 +26,7 @@ function eq(loc, x, y) { }; } -eq("File \"bs_string_test.res\", line 10, characters 2-9", "ghso ghso g".split(" ").reduce((x, y) => x + ("-" + y), ""), "-ghso-ghso-g"); +eq("File \"bs_string_test.res\", line 13, characters 2-9", "ghso ghso g".split(" ").reduce((x, y) => x + ("-" + y), ""), "-ghso-ghso-g"); Mt.from_pair_suites("Bs_string_test", suites.contents); diff --git a/jscomp/test/bs_string_test.res b/jscomp/test/bs_string_test.res index 5f787bccd4..89ba251510 100644 --- a/jscomp/test/bs_string_test.res +++ b/jscomp/test/bs_string_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let () = eq( diff --git a/jscomp/test/bs_unwrap_test.js b/jscomp/test/bs_unwrap_test.js index 9280a5b7ba..21420194d0 100644 --- a/jscomp/test/bs_unwrap_test.js +++ b/jscomp/test/bs_unwrap_test.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); console.log([ "hello world", @@ -44,14 +44,14 @@ let some_arg = { VAL: true }; -console.log(5, Caml_option.option_unwrap(some_arg)); +console.log(5, Primitive_option.unwrapPolyVar(some_arg)); console.log(6, undefined); -console.log(7, Caml_option.option_unwrap((console.log("trace"), undefined))); +console.log(7, Primitive_option.unwrapPolyVar((console.log("trace"), undefined))); function dyn_log3(prim0, prim1, prim2) { - console.log(prim0.VAL, Caml_option.option_unwrap(prim1)); + console.log(prim0.VAL, Primitive_option.unwrapPolyVar(prim1)); } dyn_log3({ @@ -81,11 +81,11 @@ function f(x) { } function ff0(x, p) { - console.log(Caml_option.option_unwrap(x), p); + console.log(Primitive_option.unwrapPolyVar(x), p); } function ff1(x, p) { - console.log(Caml_option.option_unwrap(x()), p); + console.log(Primitive_option.unwrapPolyVar(x()), p); } function test00() { diff --git a/jscomp/test/bs_unwrap_test.res b/jscomp/test/bs_unwrap_test.res index 6360f8dd26..c89fb14e7b 100644 --- a/jscomp/test/bs_unwrap_test.res +++ b/jscomp/test/bs_unwrap_test.res @@ -56,7 +56,7 @@ let _ = log3( ~req=#Int(7), ~opt=?( _ => { - print_endline("trace") + Js.log("trace") None } )(), diff --git a/jscomp/test/buffer_test.js b/jscomp/test/buffer_test.js deleted file mode 100644 index b67e35703a..0000000000 --- a/jscomp/test/buffer_test.js +++ /dev/null @@ -1,74 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let Bytes = require("../../lib/js/bytes.js"); -let Buffer = require("../../lib/js/buffer.js"); -let Caml_bytes = require("../../lib/js/caml_bytes.js"); -let Caml_string = require("../../lib/js/caml_string.js"); - -let v = "gso"; - -let suites_0 = [ - "equal", - param => ({ - TAG: "Eq", - _0: [ - Caml_bytes.get(Bytes.make(3, /* 'a' */97), 0), - Bytes.make(3, /* 'a' */97)[0] - ], - _1: [ - /* 'a' */97, - /* 'a' */97 - ] - }) -]; - -let suites_1 = { - hd: [ - "equal2", - param => { - let u = Bytes.make(3, /* 'a' */97); - u[0] = /* 'b' */98; - return { - TAG: "Eq", - _0: [ - u[0], - Caml_string.get(v, 0) - ], - _1: [ - /* 'b' */98, - /* 'g' */103 - ] - }; - } - ], - tl: { - hd: [ - "buffer", - param => { - let v = Buffer.create(30); - for (let i = 0; i <= 10; ++i) { - Buffer.add_string(v, String(i)); - } - return { - TAG: "Eq", - _0: Buffer.contents(v), - _1: "012345678910" - }; - } - ], - tl: /* [] */0 - } -}; - -let suites = { - hd: suites_0, - tl: suites_1 -}; - -Mt.from_pair_suites("Buffer_test", suites); - -exports.v = v; -exports.suites = suites; -/* Not a pure module */ diff --git a/jscomp/test/buffer_test.res b/jscomp/test/buffer_test.res deleted file mode 100644 index 7745b20bd2..0000000000 --- a/jscomp/test/buffer_test.res +++ /dev/null @@ -1,34 +0,0 @@ -let v = "gso" - -let suites = { - open Mt - list{ - ( - "equal", - _ => Eq( - (Bytes.get(Bytes.make(3, 'a'), 0), Bytes.unsafe_get(Bytes.make(3, 'a'), 0)), - ('a', 'a'), - ), - ), - ( - "equal2", - _ => { - let u = Bytes.make(3, 'a') - Bytes.unsafe_set(u, 0, 'b') - Eq((Bytes.unsafe_get(u, 0), String.get(v, 0)), ('b', 'g')) - }, - ), - ( - "buffer", - _ => { - let v = Buffer.create(30) - for i in 0 to 10 { - Buffer.add_string(v, string_of_int(i)) - } - Eq(Buffer.contents(v), "012345678910") - }, - ), - } -} - -Mt.from_pair_suites(__MODULE__, suites) diff --git a/jscomp/test/build.ninja b/jscomp/test/build.ninja index c5da618a05..1057a91a41 100644 --- a/jscomp/test/build.ninja +++ b/jscomp/test/build.ninja @@ -1,5 +1,5 @@ -bsc_flags = -bs-cross-module-opt -make-runtime-test -bs-package-output commonjs:jscomp/test -w -3-6-26-27-29-30-32..40-44-45-52-60-9-106+104 -warn-error A -I runtime -I $stdlib -I others +bsc_flags = -bs-cross-module-opt -make-runtime-test -bs-package-output commonjs:jscomp/test -w -3-6-26-27-29-30-32..40-44-45-52-60-9-106+104 -warn-error A -I runtime -I others rule cc command = $bsc -bs-cmi -bs-cmj $bsc_flags -I test $in @@ -8,692 +8,619 @@ rule cc_cmi command = $bsc -bs-read-cmi -bs-cmi -bs-cmj $bsc_flags -I test $in description = $in -> $out -o test/406_primitive_test.cmi test/406_primitive_test.cmj : cc test/406_primitive_test.res | test/mt.cmj $bsc $stdlib runtime -o test/AsInUncurriedExternals.cmi test/AsInUncurriedExternals.cmj : cc test/AsInUncurriedExternals.res | $bsc $stdlib runtime -o test/Coercion.cmi test/Coercion.cmj : cc test/Coercion.res | $bsc $stdlib runtime -o test/DerivingAccessorsCurried.cmi test/DerivingAccessorsCurried.cmj : cc test/DerivingAccessorsCurried.res | $bsc $stdlib runtime -o test/DerivingAccessorsUncurried.cmi test/DerivingAccessorsUncurried.cmj : cc test/DerivingAccessorsUncurried.res | $bsc $stdlib runtime -o test/DictInference.cmi test/DictInference.cmj : cc test/DictInference.res | $bsc $stdlib runtime -o test/DictTests.cmi test/DictTests.cmj : cc test/DictTests.res | $bsc $stdlib runtime -o test/DisambiguateOptionalFields.cmi test/DisambiguateOptionalFields.cmj : cc test/DisambiguateOptionalFields.res | $bsc $stdlib runtime -o test/DotDotDot.cmi test/DotDotDot.cmj : cc test/DotDotDot.res | $bsc $stdlib runtime -o test/EmptyRecord.cmi test/EmptyRecord.cmj : cc test/EmptyRecord.res | $bsc $stdlib runtime -o test/ExternalArity.cmi test/ExternalArity.cmj : cc test/ExternalArity.res | $bsc $stdlib runtime -o test/FFI.cmi test/FFI.cmj : cc test/FFI.res | $bsc $stdlib runtime -o test/Import.cmi test/Import.cmj : cc test/Import.res | $bsc $stdlib runtime -o test/ImportAttributes.cmi test/ImportAttributes.cmj : cc test/ImportAttributes.res | $bsc $stdlib runtime -o test/PartialApplicationNoRuntimeCurry.cmi test/PartialApplicationNoRuntimeCurry.cmj : cc test/PartialApplicationNoRuntimeCurry.res | $bsc $stdlib runtime -o test/RecordCoercion.cmi test/RecordCoercion.cmj : cc test/RecordCoercion.res | $bsc $stdlib runtime -o test/RecordOrObject.cmi test/RecordOrObject.cmj : cc test/RecordOrObject.res | $bsc $stdlib runtime -o test/SafePromises.cmi test/SafePromises.cmj : cc test/SafePromises.res | $bsc $stdlib runtime -o test/UncurriedAlways.cmi test/UncurriedAlways.cmj : cc test/UncurriedAlways.res | $bsc $stdlib runtime -o test/UncurriedExternals.cmi test/UncurriedExternals.cmj : cc test/UncurriedExternals.res | $bsc $stdlib runtime -o test/UncurriedPervasives.cmi test/UncurriedPervasives.cmj : cc test/UncurriedPervasives.res | $bsc $stdlib runtime -o test/UntaggedVariants.cmi test/UntaggedVariants.cmj : cc test/UntaggedVariants.res | $bsc $stdlib runtime -o test/VariantCoercion.cmi test/VariantCoercion.cmj : cc test/VariantCoercion.res | $bsc $stdlib runtime -o test/VariantPatternMatchingSpreads.cmi test/VariantPatternMatchingSpreads.cmj : cc test/VariantPatternMatchingSpreads.res | $bsc $stdlib runtime -o test/VariantPatternMatchingSpreadsWithPayloads.cmi test/VariantPatternMatchingSpreadsWithPayloads.cmj : cc test/VariantPatternMatchingSpreadsWithPayloads.res | $bsc $stdlib runtime -o test/VariantSpreads.cmi test/VariantSpreads.cmj : cc test/VariantSpreads.res | $bsc $stdlib runtime -o test/a.cmi test/a.cmj : cc test/a.res | test/test_order.cmj $bsc $stdlib runtime -o test/a_filename_test.cmi test/a_filename_test.cmj : cc test/a_filename_test.res | test/ext_filename_test.cmj test/mt.cmj $bsc $stdlib runtime -o test/a_list_test.cmi test/a_list_test.cmj : cc test/a_list_test.res | test/ext_list_test.cmj test/mt.cmj $bsc $stdlib runtime -o test/a_recursive_type.cmj : cc_cmi test/a_recursive_type.res | test/a_recursive_type.cmi $bsc $stdlib runtime -o test/a_recursive_type.cmi : cc test/a_recursive_type.resi | $bsc $stdlib runtime -o test/a_scope_bug.cmi test/a_scope_bug.cmj : cc test/a_scope_bug.res | $bsc $stdlib runtime -o test/a_string_test.cmi test/a_string_test.cmj : cc test/a_string_test.res | test/ext_string_test.cmj test/mt.cmj $bsc $stdlib runtime -o test/abstract_type.cmj : cc_cmi test/abstract_type.res | test/abstract_type.cmi $bsc $stdlib runtime -o test/abstract_type.cmi : cc test/abstract_type.resi | test/mt.cmi $bsc $stdlib runtime -o test/adt_optimize_test.cmi test/adt_optimize_test.cmj : cc test/adt_optimize_test.res | $bsc $stdlib runtime -o test/alias_default_value_test.cmi test/alias_default_value_test.cmj : cc test/alias_default_value_test.res | test/react.cmj $bsc $stdlib runtime -o test/alias_test.cmj : cc_cmi test/alias_test.res | test/alias_test.cmi $bsc $stdlib runtime -o test/alias_test.cmi : cc test/alias_test.resi | $bsc $stdlib runtime -o test/and_or_tailcall_test.cmi test/and_or_tailcall_test.cmj : cc test/and_or_tailcall_test.res | test/mt.cmj $bsc $stdlib runtime -o test/argv_test.cmi test/argv_test.cmj : cc test/argv_test.res | $bsc $stdlib runtime -o test/ari_regress_test.cmj : cc_cmi test/ari_regress_test.res | test/ari_regress_test.cmi test/mt.cmj $bsc $stdlib runtime -o test/ari_regress_test.cmi : cc test/ari_regress_test.resi | $bsc $stdlib runtime -o test/arith_lexer.cmi test/arith_lexer.cmj : cc test/arith_lexer.res | test/arith_parser.cmj test/arith_syntax.cmj $bsc $stdlib runtime -o test/arith_parser.cmi test/arith_parser.cmj : cc test/arith_parser.res | test/arith_syntax.cmj $bsc $stdlib runtime -o test/arith_syntax.cmi test/arith_syntax.cmj : cc test/arith_syntax.res | $bsc $stdlib runtime -o test/arity.cmi test/arity.cmj : cc test/arity.res | $bsc $stdlib runtime -o test/arity_deopt.cmi test/arity_deopt.cmj : cc test/arity_deopt.res | test/mt.cmj $bsc $stdlib runtime -o test/arity_infer.cmi test/arity_infer.cmj : cc test/arity_infer.res | $bsc $stdlib runtime -o test/array_data_util.cmi test/array_data_util.cmj : cc test/array_data_util.res | $bsc $stdlib runtime -o test/array_safe_get.cmi test/array_safe_get.cmj : cc test/array_safe_get.res | $bsc $stdlib runtime -o test/array_subtle_test.cmi test/array_subtle_test.cmj : cc test/array_subtle_test.res | test/mt.cmj $bsc $stdlib runtime -o test/array_test.cmj : cc_cmi test/array_test.res | test/array_test.cmi test/mt.cmj $bsc $stdlib runtime -o test/array_test.cmi : cc test/array_test.resi | $bsc $stdlib runtime -o test/as_inline_record_test.cmi test/as_inline_record_test.cmj : cc test/as_inline_record_test.res | $bsc $stdlib runtime -o test/ast_abstract_test.cmi test/ast_abstract_test.cmj : cc test/ast_abstract_test.res | test/mt.cmj $bsc $stdlib runtime -o test/ast_mapper_unused_warning_test.cmi test/ast_mapper_unused_warning_test.cmj : cc test/ast_mapper_unused_warning_test.res | $bsc $stdlib runtime -o test/async_await.cmi test/async_await.cmj : cc test/async_await.res | $bsc $stdlib runtime -o test/async_inline.cmi test/async_inline.cmj : cc test/async_inline.res | $bsc $stdlib runtime -o test/async_inside_loop.cmi test/async_inside_loop.cmj : cc test/async_inside_loop.res | $bsc $stdlib runtime -o test/attr_test.cmi test/attr_test.cmj : cc test/attr_test.res | $bsc $stdlib runtime -o test/b.cmi test/b.cmj : cc test/b.res | $bsc $stdlib runtime -o test/bal_set_mini.cmi test/bal_set_mini.cmj : cc test/bal_set_mini.res | $bsc $stdlib runtime -o test/bang_primitive.cmi test/bang_primitive.cmj : cc test/bang_primitive.res | $bsc $stdlib runtime -o test/basic_module_test.cmj : cc_cmi test/basic_module_test.res | test/basic_module_test.cmi test/mt.cmj test/mt_global.cmj test/offset.cmj test/pr6726.cmj $bsc $stdlib runtime -o test/basic_module_test.cmi : cc test/basic_module_test.resi | $bsc $stdlib runtime -o test/bb.cmi test/bb.cmj : cc test/bb.res | $bsc $stdlib runtime -o test/bdd.cmi test/bdd.cmj : cc test/bdd.res | $bsc $stdlib runtime -o test/belt_float_ntest.cmi test/belt_float_ntest.cmj : cc test/belt_float_ntest.res | test/node_test.cmj test/node_test_util.cmj $bsc $stdlib runtime -o test/belt_hashmap_ntest.cmi test/belt_hashmap_ntest.cmj : cc test/belt_hashmap_ntest.res | test/array_data_util.cmj test/node_test.cmj test/node_test_util.cmj $bsc $stdlib runtime -o test/belt_hashset_int_ntest.cmi test/belt_hashset_int_ntest.cmj : cc test/belt_hashset_int_ntest.res | test/array_data_util.cmj test/node_test.cmj test/node_test_util.cmj $bsc $stdlib runtime -o test/belt_int_ntest.cmi test/belt_int_ntest.cmj : cc test/belt_int_ntest.res | test/node_test.cmj test/node_test_util.cmj $bsc $stdlib runtime -o test/belt_internal_test.cmi test/belt_internal_test.cmj : cc test/belt_internal_test.res | $bsc $stdlib runtime -o test/belt_list_ntest.cmi test/belt_list_ntest.cmj : cc test/belt_list_ntest.res | test/node_test.cmj test/node_test_util.cmj $bsc $stdlib runtime -o test/belt_mapint_ntest.cmi test/belt_mapint_ntest.cmj : cc test/belt_mapint_ntest.res | test/node_test.cmj test/node_test_util.cmj $bsc $stdlib runtime -o test/belt_result_alias_test.cmi test/belt_result_alias_test.cmj : cc test/belt_result_alias_test.res | $bsc $stdlib runtime -o test/belt_sortarray_ntest.cmi test/belt_sortarray_ntest.cmj : cc test/belt_sortarray_ntest.res | test/array_data_util.cmj test/node_test.cmj test/node_test_util.cmj $bsc $stdlib runtime -o test/bench.cmi test/bench.cmj : cc test/bench.res | $bsc $stdlib runtime -o test/big_enum.cmi test/big_enum.cmj : cc test/big_enum.res | $bsc $stdlib runtime -o test/big_polyvar_test.cmi test/big_polyvar_test.cmj : cc test/big_polyvar_test.res | $bsc $stdlib runtime -o test/bigint_test.cmi test/bigint_test.cmj : cc test/bigint_test.res | test/mt.cmj test/mt_global.cmj $bsc $stdlib runtime -o test/block_alias_test.cmi test/block_alias_test.cmj : cc test/block_alias_test.res | test/mt.cmj $bsc $stdlib runtime -o test/boolean_test.cmi test/boolean_test.cmj : cc test/boolean_test.res | test/mt.cmj test/test_bool_equal.cmj $bsc $stdlib runtime -o test/bs_abstract_test.cmj : cc_cmi test/bs_abstract_test.res | test/bs_abstract_test.cmi $bsc $stdlib runtime -o test/bs_abstract_test.cmi : cc test/bs_abstract_test.resi | $bsc $stdlib runtime -o test/bs_array_test.cmi test/bs_array_test.cmj : cc test/bs_array_test.res | test/mt.cmj $bsc $stdlib runtime -o test/bs_auto_uncurry.cmi test/bs_auto_uncurry.cmj : cc test/bs_auto_uncurry.res | $bsc $stdlib runtime -o test/bs_auto_uncurry_test.cmi test/bs_auto_uncurry_test.cmj : cc test/bs_auto_uncurry_test.res | test/mt.cmj $bsc $stdlib runtime -o test/bs_ignore_effect.cmi test/bs_ignore_effect.cmj : cc test/bs_ignore_effect.res | test/mt.cmj $bsc $stdlib runtime -o test/bs_ignore_test.cmi test/bs_ignore_test.cmj : cc test/bs_ignore_test.res | $bsc $stdlib runtime -o test/bs_map_set_dict_test.cmi test/bs_map_set_dict_test.cmj : cc test/bs_map_set_dict_test.res | test/array_data_util.cmj test/mt.cmj $bsc $stdlib runtime -o test/bs_map_test.cmi test/bs_map_test.cmj : cc test/bs_map_test.res | test/mt.cmj $bsc $stdlib runtime -o test/bs_min_max_test.cmi test/bs_min_max_test.cmj : cc test/bs_min_max_test.res | test/mt.cmj $bsc $stdlib runtime -o test/bs_mutable_set_test.cmi test/bs_mutable_set_test.cmj : cc test/bs_mutable_set_test.res | test/array_data_util.cmj test/mt.cmj $bsc $stdlib runtime -o test/bs_poly_map_test.cmi test/bs_poly_map_test.cmj : cc test/bs_poly_map_test.res | test/array_data_util.cmj test/mt.cmj $bsc $stdlib runtime -o test/bs_poly_mutable_map_test.cmi test/bs_poly_mutable_map_test.cmj : cc test/bs_poly_mutable_map_test.res | test/array_data_util.cmj test/mt.cmj $bsc $stdlib runtime -o test/bs_poly_mutable_set_test.cmi test/bs_poly_mutable_set_test.cmj : cc test/bs_poly_mutable_set_test.res | test/array_data_util.cmj test/mt.cmj $bsc $stdlib runtime -o test/bs_poly_set_test.cmi test/bs_poly_set_test.cmj : cc test/bs_poly_set_test.res | test/array_data_util.cmj test/mt.cmj $bsc $stdlib runtime -o test/bs_qualified.cmi test/bs_qualified.cmj : cc test/bs_qualified.res | $bsc $stdlib runtime -o test/bs_queue_test.cmi test/bs_queue_test.cmj : cc test/bs_queue_test.res | test/mt.cmj $bsc $stdlib runtime -o test/bs_rest_test.cmi test/bs_rest_test.cmj : cc test/bs_rest_test.res | $bsc $stdlib runtime -o test/bs_set_int_test.cmi test/bs_set_int_test.cmj : cc test/bs_set_int_test.res | test/array_data_util.cmj test/mt.cmj $bsc $stdlib runtime -o test/bs_splice_partial.cmi test/bs_splice_partial.cmj : cc test/bs_splice_partial.res | $bsc $stdlib runtime -o test/bs_stack_test.cmi test/bs_stack_test.cmj : cc test/bs_stack_test.res | test/mt.cmj $bsc $stdlib runtime -o test/bs_string_test.cmi test/bs_string_test.cmj : cc test/bs_string_test.res | test/mt.cmj $bsc $stdlib runtime -o test/bs_unwrap_test.cmi test/bs_unwrap_test.cmj : cc test/bs_unwrap_test.res | $bsc $stdlib runtime -o test/buffer_test.cmi test/buffer_test.cmj : cc test/buffer_test.res | test/mt.cmj $bsc $stdlib runtime -o test/bytes_split_gpr_743_test.cmi test/bytes_split_gpr_743_test.cmj : cc test/bytes_split_gpr_743_test.res | test/mt.cmj $bsc $stdlib runtime -o test/caml_compare_bigint_test.cmi test/caml_compare_bigint_test.cmj : cc test/caml_compare_bigint_test.res | test/mt.cmj $bsc $stdlib runtime -o test/caml_compare_test.cmi test/caml_compare_test.cmj : cc test/caml_compare_test.res | test/mt.cmj $bsc $stdlib runtime -o test/caml_format_test.cmi test/caml_format_test.cmj : cc test/caml_format_test.res | test/mt.cmj $bsc $stdlib runtime -o test/chain_code_test.cmi test/chain_code_test.cmj : cc test/chain_code_test.res | test/mt.cmj $bsc $stdlib runtime -o test/chn_test.cmi test/chn_test.cmj : cc test/chn_test.res | test/mt.cmj $bsc $stdlib runtime -o test/class_type_ffi_test.cmi test/class_type_ffi_test.cmj : cc test/class_type_ffi_test.res | $bsc $stdlib runtime -o test/coercion_module_alias_test.cmi test/coercion_module_alias_test.cmj : cc test/coercion_module_alias_test.res | $bsc $stdlib runtime -o test/compare_test.cmi test/compare_test.cmj : cc test/compare_test.res | $bsc $stdlib runtime -o test/complete_parmatch_test.cmi test/complete_parmatch_test.cmj : cc test/complete_parmatch_test.res | $bsc $stdlib runtime -o test/complex_if_test.cmi test/complex_if_test.cmj : cc test/complex_if_test.res | test/mt.cmj $bsc $stdlib runtime -o test/complex_test.cmi test/complex_test.cmj : cc test/complex_test.res | test/mt.cmj $bsc $stdlib runtime -o test/complex_while_loop.cmi test/complex_while_loop.cmj : cc test/complex_while_loop.res | $bsc $stdlib runtime -o test/condition_compilation_test.cmi test/condition_compilation_test.cmj : cc test/condition_compilation_test.res | test/mt.cmj $bsc $stdlib runtime -o test/config1_test.cmi test/config1_test.cmj : cc test/config1_test.res | $bsc $stdlib runtime -o test/console_log_test.cmi test/console_log_test.cmj : cc test/console_log_test.res | $bsc $stdlib runtime -o test/const_block_test.cmj : cc_cmi test/const_block_test.res | test/const_block_test.cmi test/mt.cmj $bsc $stdlib runtime -o test/const_block_test.cmi : cc test/const_block_test.resi | $bsc $stdlib runtime -o test/const_defs.cmi test/const_defs.cmj : cc test/const_defs.res | $bsc $stdlib runtime -o test/const_defs_test.cmi test/const_defs_test.cmj : cc test/const_defs_test.res | test/const_defs.cmj $bsc $stdlib runtime -o test/const_test.cmi test/const_test.cmj : cc test/const_test.res | $bsc $stdlib runtime -o test/cont_int_fold_test.cmi test/cont_int_fold_test.cmj : cc test/cont_int_fold_test.res | $bsc $stdlib runtime -o test/cps_test.cmi test/cps_test.cmj : cc test/cps_test.res | test/mt.cmj $bsc $stdlib runtime -o test/cross_module_inline_test.cmi test/cross_module_inline_test.cmj : cc test/cross_module_inline_test.res | test/test_char.cmj $bsc $stdlib runtime -o test/custom_error_test.cmi test/custom_error_test.cmj : cc test/custom_error_test.res | $bsc $stdlib runtime -o test/debug_keep_test.cmi test/debug_keep_test.cmj : cc test/debug_keep_test.res | $bsc $stdlib runtime -o test/debug_mode_value.cmi test/debug_mode_value.cmj : cc test/debug_mode_value.res | $bsc $stdlib runtime -o test/debug_tmp.cmi test/debug_tmp.cmj : cc test/debug_tmp.res | $bsc $stdlib runtime -o test/debugger_test.cmi test/debugger_test.cmj : cc test/debugger_test.res | $bsc $stdlib runtime -o test/default_export_test.cmi test/default_export_test.cmj : cc test/default_export_test.res | $bsc $stdlib runtime -o test/defunctor_make_test.cmi test/defunctor_make_test.cmj : cc test/defunctor_make_test.res | $bsc $stdlib runtime -o test/demo_int_map.cmj : cc_cmi test/demo_int_map.res | test/demo_int_map.cmi $bsc $stdlib runtime -o test/demo_int_map.cmi : cc test/demo_int_map.resi | $bsc $stdlib runtime -o test/demo_page.cmi test/demo_page.cmj : cc test/demo_page.res | $bsc $stdlib runtime -o test/demo_pipe.cmi test/demo_pipe.cmj : cc test/demo_pipe.res | $bsc $stdlib runtime -o test/derive_projector_test.cmj : cc_cmi test/derive_projector_test.res | test/derive_projector_test.cmi $bsc $stdlib runtime -o test/derive_projector_test.cmi : cc test/derive_projector_test.resi | $bsc $stdlib runtime -o test/digest_test.cmi test/digest_test.cmj : cc test/digest_test.res | test/ext_array_test.cmj test/mt.cmj $bsc $stdlib runtime -o test/directives.cmi test/directives.cmj : cc test/directives.res | $bsc $stdlib runtime -o test/div_by_zero_test.cmi test/div_by_zero_test.cmj : cc test/div_by_zero_test.res | test/mt.cmj $bsc $stdlib runtime -o test/dollar_escape_test.cmi test/dollar_escape_test.cmj : cc test/dollar_escape_test.res | test/mt.cmj $bsc $stdlib runtime -o test/earger_curry_test.cmi test/earger_curry_test.cmj : cc test/earger_curry_test.res | test/mt.cmj $bsc $stdlib runtime -o test/effect.cmi test/effect.cmj : cc test/effect.res | $bsc $stdlib runtime -o test/epsilon_test.cmi test/epsilon_test.cmj : cc test/epsilon_test.res | test/mt.cmj $bsc $stdlib runtime -o test/equal_box_test.cmi test/equal_box_test.cmj : cc test/equal_box_test.res | test/mt.cmj $bsc $stdlib runtime -o test/equal_exception_test.cmi test/equal_exception_test.cmj : cc test/equal_exception_test.res | test/mt.cmj $bsc $stdlib runtime -o test/equal_test.cmi test/equal_test.cmj : cc test/equal_test.res | $bsc $stdlib runtime -o test/es6_export.cmi test/es6_export.cmj : cc test/es6_export.res | $bsc $stdlib runtime -o test/es6_import.cmi test/es6_import.cmj : cc test/es6_import.res | test/es6_export.cmj $bsc $stdlib runtime -o test/es6_module_test.cmi test/es6_module_test.cmj : cc test/es6_module_test.res | test/mt.cmj $bsc $stdlib runtime -o test/escape_esmodule.cmi test/escape_esmodule.cmj : cc test/escape_esmodule.res | $bsc $stdlib runtime -o test/esmodule_ref.cmi test/esmodule_ref.cmj : cc test/esmodule_ref.res | test/escape_esmodule.cmj $bsc $stdlib runtime -o test/event_ffi.cmi test/event_ffi.cmj : cc test/event_ffi.res | $bsc $stdlib runtime -o test/exception_alias.cmi test/exception_alias.cmj : cc test/exception_alias.res | $bsc $stdlib runtime -o test/exception_raise_test.cmi test/exception_raise_test.cmj : cc test/exception_raise_test.res | test/mt.cmj $bsc $stdlib runtime -o test/exception_rebound_err_test.cmi test/exception_rebound_err_test.cmj : cc test/exception_rebound_err_test.res | test/mt.cmj $bsc $stdlib runtime -o test/exception_value_test.cmi test/exception_value_test.cmj : cc test/exception_value_test.res | $bsc $stdlib runtime -o test/exotic_labels_test.cmi test/exotic_labels_test.cmj : cc test/exotic_labels_test.res | $bsc $stdlib runtime -o test/exponentiation_precedence_test.cmi test/exponentiation_precedence_test.cmj : cc test/exponentiation_precedence_test.res | $bsc $stdlib runtime -o test/export_keyword.cmi test/export_keyword.cmj : cc test/export_keyword.res | $bsc $stdlib runtime -o test/ext_array_test.cmi test/ext_array_test.cmj : cc test/ext_array_test.res | $bsc $stdlib runtime -o test/ext_bytes_test.cmi test/ext_bytes_test.cmj : cc test/ext_bytes_test.res | test/mt.cmj $bsc $stdlib runtime -o test/ext_filename_test.cmi test/ext_filename_test.cmj : cc test/ext_filename_test.res | test/ext_string_test.cmj test/test_literals.cmj $bsc $stdlib runtime -o test/ext_list_test.cmi test/ext_list_test.cmj : cc test/ext_list_test.res | test/ext_string_test.cmj $bsc $stdlib runtime -o test/ext_pervasives_test.cmj : cc_cmi test/ext_pervasives_test.res | test/ext_pervasives_test.cmi $bsc $stdlib runtime -o test/ext_pervasives_test.cmi : cc test/ext_pervasives_test.resi | $bsc $stdlib runtime -o test/ext_string_test.cmi test/ext_string_test.cmj : cc test/ext_string_test.res | test/ext_bytes_test.cmj $bsc $stdlib runtime -o test/ext_sys_test.cmj : cc_cmi test/ext_sys_test.res | test/ext_sys_test.cmi $bsc $stdlib runtime -o test/ext_sys_test.cmi : cc test/ext_sys_test.resi | $bsc $stdlib runtime -o test/extensible_variant_test.cmi test/extensible_variant_test.cmj : cc test/extensible_variant_test.res | test/mt.cmj $bsc $stdlib runtime -o test/external_ppx.cmi test/external_ppx.cmj : cc test/external_ppx.res | $bsc $stdlib runtime -o test/external_ppx2.cmi test/external_ppx2.cmj : cc test/external_ppx2.res | $bsc $stdlib runtime -o test/ffi_arity_test.cmi test/ffi_arity_test.cmj : cc test/ffi_arity_test.res | test/mt.cmj $bsc $stdlib runtime -o test/ffi_array_test.cmi test/ffi_array_test.cmj : cc test/ffi_array_test.res | test/mt.cmj $bsc $stdlib runtime -o test/ffi_js_test.cmi test/ffi_js_test.cmj : cc test/ffi_js_test.res | test/mt.cmj $bsc $stdlib runtime -o test/ffi_splice_test.cmi test/ffi_splice_test.cmj : cc test/ffi_splice_test.res | test/mt.cmj $bsc $stdlib runtime -o test/ffi_test.cmi test/ffi_test.cmj : cc test/ffi_test.res | $bsc $stdlib runtime -o test/fib.cmi test/fib.cmj : cc test/fib.res | $bsc $stdlib runtime -o test/flattern_order_test.cmi test/flattern_order_test.cmj : cc test/flattern_order_test.res | $bsc $stdlib runtime -o test/flexible_array_test.cmi test/flexible_array_test.cmj : cc test/flexible_array_test.res | $bsc $stdlib runtime -o test/float_array.cmi test/float_array.cmj : cc test/float_array.res | $bsc $stdlib runtime -o test/float_of_bits_test.cmi test/float_of_bits_test.cmj : cc test/float_of_bits_test.res | test/mt.cmj $bsc $stdlib runtime -o test/float_record.cmj : cc_cmi test/float_record.res | test/float_record.cmi $bsc $stdlib runtime -o test/float_record.cmi : cc test/float_record.resi | $bsc $stdlib runtime -o test/float_test.cmi test/float_test.cmj : cc test/float_test.res | test/mt.cmj test/mt_global.cmj $bsc $stdlib runtime -o test/floatarray_test.cmi test/floatarray_test.cmj : cc test/floatarray_test.res | test/mt.cmj $bsc $stdlib runtime -o test/for_loop_test.cmi test/for_loop_test.cmj : cc test/for_loop_test.res | test/mt.cmj $bsc $stdlib runtime -o test/for_side_effect_test.cmi test/for_side_effect_test.cmj : cc test/for_side_effect_test.res | test/mt.cmj $bsc $stdlib runtime -o test/format_regression.cmi test/format_regression.cmj : cc test/format_regression.res | $bsc $stdlib runtime -o test/format_test.cmi test/format_test.cmj : cc test/format_test.res | test/mt.cmj $bsc $stdlib runtime -o test/fun_pattern_match.cmi test/fun_pattern_match.cmj : cc test/fun_pattern_match.res | $bsc $stdlib runtime -o test/function_directives.cmi test/function_directives.cmj : cc test/function_directives.res | $bsc $stdlib runtime -o test/function_directives_no_inline.cmi test/function_directives_no_inline.cmj : cc test/function_directives_no_inline.res | $bsc $stdlib runtime -o test/functor_app_test.cmi test/functor_app_test.cmj : cc test/functor_app_test.res | test/functor_def.cmj test/functor_inst.cmj test/mt.cmj $bsc $stdlib runtime -o test/functor_def.cmi test/functor_def.cmj : cc test/functor_def.res | $bsc $stdlib runtime -o test/functor_ffi.cmi test/functor_ffi.cmj : cc test/functor_ffi.res | $bsc $stdlib runtime -o test/functor_inst.cmi test/functor_inst.cmj : cc test/functor_inst.res | $bsc $stdlib runtime -o test/functors.cmi test/functors.cmj : cc test/functors.res | $bsc $stdlib runtime -o test/gbk.cmi test/gbk.cmj : cc test/gbk.res | $bsc $stdlib runtime -o test/genlex_test.cmi test/genlex_test.cmj : cc test/genlex_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gentTypeReTest.cmi test/gentTypeReTest.cmj : cc test/gentTypeReTest.res | $bsc $stdlib runtime -o test/global_exception_regression_test.cmi test/global_exception_regression_test.cmj : cc test/global_exception_regression_test.res | test/mt.cmj $bsc $stdlib runtime -o test/global_mangles.cmi test/global_mangles.cmj : cc test/global_mangles.res | $bsc $stdlib runtime -o test/global_module_alias_test.cmi test/global_module_alias_test.cmj : cc test/global_module_alias_test.res | test/mt.cmj $bsc $stdlib runtime -o test/google_closure_test.cmi test/google_closure_test.cmj : cc test/google_closure_test.res | test/mt.cmj test/test_google_closure.cmj $bsc $stdlib runtime -o test/gpr496_test.cmi test/gpr496_test.cmj : cc test/gpr496_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_1072.cmi test/gpr_1072.cmj : cc test/gpr_1072.res | $bsc $stdlib runtime -o test/gpr_1072_reg.cmi test/gpr_1072_reg.cmj : cc test/gpr_1072_reg.res | $bsc $stdlib runtime -o test/gpr_1150.cmi test/gpr_1150.cmj : cc test/gpr_1150.res | $bsc $stdlib runtime -o test/gpr_1154_test.cmi test/gpr_1154_test.cmj : cc test/gpr_1154_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_1170.cmi test/gpr_1170.cmj : cc test/gpr_1170.res | $bsc $stdlib runtime -o test/gpr_1240_missing_unbox.cmi test/gpr_1240_missing_unbox.cmj : cc test/gpr_1240_missing_unbox.res | $bsc $stdlib runtime -o test/gpr_1245_test.cmi test/gpr_1245_test.cmj : cc test/gpr_1245_test.res | $bsc $stdlib runtime -o test/gpr_1268.cmi test/gpr_1268.cmj : cc test/gpr_1268.res | $bsc $stdlib runtime -o test/gpr_1409_test.cmi test/gpr_1409_test.cmj : cc test/gpr_1409_test.res | test/mt.cmj test/string_set.cmj $bsc $stdlib runtime -o test/gpr_1423_app_test.cmi test/gpr_1423_app_test.cmj : cc test/gpr_1423_app_test.res | test/gpr_1423_nav.cmj test/mt.cmj $bsc $stdlib runtime -o test/gpr_1423_nav.cmi test/gpr_1423_nav.cmj : cc test/gpr_1423_nav.res | $bsc $stdlib runtime -o test/gpr_1438.cmi test/gpr_1438.cmj : cc test/gpr_1438.res | $bsc $stdlib runtime -o test/gpr_1481.cmi test/gpr_1481.cmj : cc test/gpr_1481.res | $bsc $stdlib runtime -o test/gpr_1484.cmi test/gpr_1484.cmj : cc test/gpr_1484.res | $bsc $stdlib runtime -o test/gpr_1503_test.cmi test/gpr_1503_test.cmj : cc test/gpr_1503_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_1539_test.cmi test/gpr_1539_test.cmj : cc test/gpr_1539_test.res | $bsc $stdlib runtime -o test/gpr_1658_test.cmi test/gpr_1658_test.cmj : cc test/gpr_1658_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_1667_test.cmi test/gpr_1667_test.cmj : cc test/gpr_1667_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_1692_test.cmi test/gpr_1692_test.cmj : cc test/gpr_1692_test.res | $bsc $stdlib runtime -o test/gpr_1698_test.cmi test/gpr_1698_test.cmj : cc test/gpr_1698_test.res | $bsc $stdlib runtime -o test/gpr_1701_test.cmi test/gpr_1701_test.cmj : cc test/gpr_1701_test.res | $bsc $stdlib runtime -o test/gpr_1716_test.cmi test/gpr_1716_test.cmj : cc test/gpr_1716_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_1717_test.cmi test/gpr_1717_test.cmj : cc test/gpr_1717_test.res | $bsc $stdlib runtime -o test/gpr_1728_test.cmi test/gpr_1728_test.cmj : cc test/gpr_1728_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_1749_test.cmi test/gpr_1749_test.cmj : cc test/gpr_1749_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_1759_test.cmi test/gpr_1759_test.cmj : cc test/gpr_1759_test.res | $bsc $stdlib runtime -o test/gpr_1760_test.cmi test/gpr_1760_test.cmj : cc test/gpr_1760_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_1762_test.cmi test/gpr_1762_test.cmj : cc test/gpr_1762_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_1817_test.cmi test/gpr_1817_test.cmj : cc test/gpr_1817_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_1822_test.cmi test/gpr_1822_test.cmj : cc test/gpr_1822_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_1891_test.cmi test/gpr_1891_test.cmj : cc test/gpr_1891_test.res | $bsc $stdlib runtime -o test/gpr_1943_test.cmi test/gpr_1943_test.cmj : cc test/gpr_1943_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_1946_test.cmi test/gpr_1946_test.cmj : cc test/gpr_1946_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_2316_test.cmi test/gpr_2316_test.cmj : cc test/gpr_2316_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_2352_test.cmi test/gpr_2352_test.cmj : cc test/gpr_2352_test.res | $bsc $stdlib runtime -o test/gpr_2413_test.cmi test/gpr_2413_test.cmj : cc test/gpr_2413_test.res | $bsc $stdlib runtime -o test/gpr_2474.cmi test/gpr_2474.cmj : cc test/gpr_2474.res | $bsc $stdlib runtime -o test/gpr_2487.cmi test/gpr_2487.cmj : cc test/gpr_2487.res | $bsc $stdlib runtime -o test/gpr_2503_test.cmi test/gpr_2503_test.cmj : cc test/gpr_2503_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_2608_test.cmi test/gpr_2608_test.cmj : cc test/gpr_2608_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_2614_test.cmi test/gpr_2614_test.cmj : cc test/gpr_2614_test.res | $bsc $stdlib runtime -o test/gpr_2633_test.cmi test/gpr_2633_test.cmj : cc test/gpr_2633_test.res | $bsc $stdlib runtime -o test/gpr_2642_test.cmi test/gpr_2642_test.cmj : cc test/gpr_2642_test.res | $bsc $stdlib runtime -o test/gpr_2682_test.cmi test/gpr_2682_test.cmj : cc test/gpr_2682_test.res | $bsc $stdlib runtime -o test/gpr_2700_test.cmi test/gpr_2700_test.cmj : cc test/gpr_2700_test.res | $bsc $stdlib runtime -o test/gpr_2731_test.cmi test/gpr_2731_test.cmj : cc test/gpr_2731_test.res | $bsc $stdlib runtime -o test/gpr_2789_test.cmi test/gpr_2789_test.cmj : cc test/gpr_2789_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_2931_test.cmi test/gpr_2931_test.cmj : cc test/gpr_2931_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_3142_test.cmi test/gpr_3142_test.cmj : cc test/gpr_3142_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_3154_test.cmi test/gpr_3154_test.cmj : cc test/gpr_3154_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_3209_test.cmi test/gpr_3209_test.cmj : cc test/gpr_3209_test.res | $bsc $stdlib runtime -o test/gpr_3492_test.cmi test/gpr_3492_test.cmj : cc test/gpr_3492_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_3519_jsx_test.cmi test/gpr_3519_jsx_test.cmj : cc test/gpr_3519_jsx_test.res | $bsc $stdlib runtime -o test/gpr_3519_test.cmi test/gpr_3519_test.cmj : cc test/gpr_3519_test.res | $bsc $stdlib runtime -o test/gpr_3536_test.cmi test/gpr_3536_test.cmj : cc test/gpr_3536_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_3546_test.cmi test/gpr_3546_test.cmj : cc test/gpr_3546_test.res | $bsc $stdlib runtime -o test/gpr_3548_test.cmi test/gpr_3548_test.cmj : cc test/gpr_3548_test.res | $bsc $stdlib runtime -o test/gpr_3549_test.cmi test/gpr_3549_test.cmj : cc test/gpr_3549_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_3566_drive_test.cmi test/gpr_3566_drive_test.cmj : cc test/gpr_3566_drive_test.res | test/gpr_3566_test.cmj test/mt.cmj $bsc $stdlib runtime -o test/gpr_3566_test.cmi test/gpr_3566_test.cmj : cc test/gpr_3566_test.res | $bsc $stdlib runtime -o test/gpr_3595_test.cmi test/gpr_3595_test.cmj : cc test/gpr_3595_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_3609_test.cmi test/gpr_3609_test.cmj : cc test/gpr_3609_test.res | $bsc $stdlib runtime -o test/gpr_3697_test.cmi test/gpr_3697_test.cmj : cc test/gpr_3697_test.res | $bsc $stdlib runtime -o test/gpr_373_test.cmi test/gpr_373_test.cmj : cc test/gpr_373_test.res | $bsc $stdlib runtime -o test/gpr_3770_test.cmi test/gpr_3770_test.cmj : cc test/gpr_3770_test.res | $bsc $stdlib runtime -o test/gpr_3852_alias.cmi test/gpr_3852_alias.cmj : cc test/gpr_3852_alias.res | test/gpr_3852_effect.cmj $bsc $stdlib runtime -o test/gpr_3852_alias_reify.cmj : cc_cmi test/gpr_3852_alias_reify.res | test/gpr_3852_alias_reify.cmi test/gpr_3852_effect.cmj $bsc $stdlib runtime -o test/gpr_3852_alias_reify.cmi : cc test/gpr_3852_alias_reify.resi | $bsc $stdlib runtime -o test/gpr_3852_effect.cmi test/gpr_3852_effect.cmj : cc test/gpr_3852_effect.res | $bsc $stdlib runtime -o test/gpr_3865.cmi test/gpr_3865.cmj : cc test/gpr_3865.res | test/gpr_3865_bar.cmj test/gpr_3865_foo.cmj $bsc $stdlib runtime -o test/gpr_3865_bar.cmi test/gpr_3865_bar.cmj : cc test/gpr_3865_bar.res | $bsc $stdlib runtime -o test/gpr_3865_foo.cmi test/gpr_3865_foo.cmj : cc test/gpr_3865_foo.res | $bsc $stdlib runtime -o test/gpr_3875_test.cmi test/gpr_3875_test.cmj : cc test/gpr_3875_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_3877_test.cmi test/gpr_3877_test.cmj : cc test/gpr_3877_test.res | $bsc $stdlib runtime -o test/gpr_3895_test.cmi test/gpr_3895_test.cmj : cc test/gpr_3895_test.res | $bsc $stdlib runtime -o test/gpr_3897_test.cmi test/gpr_3897_test.cmj : cc test/gpr_3897_test.res | $bsc $stdlib runtime -o test/gpr_3931_test.cmi test/gpr_3931_test.cmj : cc test/gpr_3931_test.res | $bsc $stdlib runtime -o test/gpr_3980_test.cmi test/gpr_3980_test.cmj : cc test/gpr_3980_test.res | $bsc $stdlib runtime -o test/gpr_4025_test.cmi test/gpr_4025_test.cmj : cc test/gpr_4025_test.res | $bsc $stdlib runtime -o test/gpr_405_test.cmj : cc_cmi test/gpr_405_test.res | test/gpr_405_test.cmi $bsc $stdlib runtime -o test/gpr_405_test.cmi : cc test/gpr_405_test.resi | $bsc $stdlib runtime -o test/gpr_4069_test.cmi test/gpr_4069_test.cmj : cc test/gpr_4069_test.res | $bsc $stdlib runtime -o test/gpr_4265_test.cmi test/gpr_4265_test.cmj : cc test/gpr_4265_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_4274_test.cmi test/gpr_4274_test.cmj : cc test/gpr_4274_test.res | $bsc $stdlib runtime -o test/gpr_4280_test.cmi test/gpr_4280_test.cmj : cc test/gpr_4280_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_4407_test.cmi test/gpr_4407_test.cmj : cc test/gpr_4407_test.res | test/debug_mode_value.cmj test/mt.cmj $bsc $stdlib runtime -o test/gpr_441.cmi test/gpr_441.cmj : cc test/gpr_441.res | $bsc $stdlib runtime -o test/gpr_4442_test.cmi test/gpr_4442_test.cmj : cc test/gpr_4442_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_4491_test.cmi test/gpr_4491_test.cmj : cc test/gpr_4491_test.res | $bsc $stdlib runtime -o test/gpr_4494_test.cmi test/gpr_4494_test.cmj : cc test/gpr_4494_test.res | $bsc $stdlib runtime -o test/gpr_4519_test.cmi test/gpr_4519_test.cmj : cc test/gpr_4519_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_459_test.cmi test/gpr_459_test.cmj : cc test/gpr_459_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_4632.cmi test/gpr_4632.cmj : cc test/gpr_4632.res | $bsc $stdlib runtime -o test/gpr_4639_test.cmi test/gpr_4639_test.cmj : cc test/gpr_4639_test.res | $bsc $stdlib runtime -o test/gpr_4900_test.cmi test/gpr_4900_test.cmj : cc test/gpr_4900_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_4924_test.cmi test/gpr_4924_test.cmj : cc test/gpr_4924_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_4931.cmi test/gpr_4931.cmj : cc test/gpr_4931.res | $bsc $stdlib runtime -o test/gpr_4931_allow.cmi test/gpr_4931_allow.cmj : cc test/gpr_4931_allow.res | $bsc $stdlib runtime -o test/gpr_5071_test.cmi test/gpr_5071_test.cmj : cc test/gpr_5071_test.res | test/react.cmj $bsc $stdlib runtime -o test/gpr_5169_test.cmi test/gpr_5169_test.cmj : cc test/gpr_5169_test.res | $bsc $stdlib runtime -o test/gpr_5218_test.cmi test/gpr_5218_test.cmj : cc test/gpr_5218_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_5280_optimize_test.cmi test/gpr_5280_optimize_test.cmj : cc test/gpr_5280_optimize_test.res | $bsc $stdlib runtime -o test/gpr_5557.cmi test/gpr_5557.cmj : cc test/gpr_5557.res | $bsc $stdlib runtime -o test/gpr_5753.cmi test/gpr_5753.cmj : cc test/gpr_5753.res | $bsc $stdlib runtime -o test/gpr_658.cmi test/gpr_658.cmj : cc test/gpr_658.res | $bsc $stdlib runtime -o test/gpr_7012_test.cmi test/gpr_7012_test.cmj : cc test/gpr_7012_test.res | $bsc $stdlib runtime -o test/gpr_858_test.cmi test/gpr_858_test.cmj : cc test/gpr_858_test.res | $bsc $stdlib runtime -o test/gpr_858_unit2_test.cmi test/gpr_858_unit2_test.cmj : cc test/gpr_858_unit2_test.res | $bsc $stdlib runtime -o test/gpr_904_test.cmi test/gpr_904_test.cmj : cc test/gpr_904_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_974_test.cmi test/gpr_974_test.cmj : cc test/gpr_974_test.res | $bsc $stdlib runtime -o test/gpr_977_test.cmi test/gpr_977_test.cmj : cc test/gpr_977_test.res | test/mt.cmj $bsc $stdlib runtime -o test/gpr_return_type_unused_attribute.cmi test/gpr_return_type_unused_attribute.cmj : cc test/gpr_return_type_unused_attribute.res | $bsc $stdlib runtime -o test/gray_code_test.cmi test/gray_code_test.cmj : cc test/gray_code_test.res | $bsc $stdlib runtime -o test/guide_for_ext.cmi test/guide_for_ext.cmj : cc test/guide_for_ext.res | $bsc $stdlib runtime -o test/hash_collision_test.cmi test/hash_collision_test.cmj : cc test/hash_collision_test.res | test/mt.cmj $bsc $stdlib runtime -o test/hash_sugar_desugar.cmj : cc_cmi test/hash_sugar_desugar.res | test/hash_sugar_desugar.cmi $bsc $stdlib runtime -o test/hash_sugar_desugar.cmi : cc test/hash_sugar_desugar.resi | $bsc $stdlib runtime -o test/hash_test.cmi test/hash_test.cmj : cc test/hash_test.res | test/mt.cmj test/mt_global.cmj $bsc $stdlib runtime -o test/hashtbl_test.cmi test/hashtbl_test.cmj : cc test/hashtbl_test.res | test/mt.cmj $bsc $stdlib runtime -o test/hello.foo.cmi test/hello.foo.cmj : cc test/hello.foo.res | $bsc $stdlib runtime -o test/hello_res.cmj : cc_cmi test/hello_res.res | test/hello_res.cmi $bsc $stdlib runtime -o test/hello_res.cmi : cc test/hello_res.resi | $bsc $stdlib runtime -o test/ignore_test.cmi test/ignore_test.cmj : cc test/ignore_test.res | test/mt.cmj $bsc $stdlib runtime -o test/ignore_uncurry_attribute.cmi test/ignore_uncurry_attribute.cmj : cc test/ignore_uncurry_attribute.res | $bsc $stdlib runtime -o test/import2.cmi test/import2.cmj : cc test/import2.res | test/import_external.cmj $bsc $stdlib runtime -o test/import_external.cmi test/import_external.cmj : cc test/import_external.res | $bsc $stdlib runtime -o test/import_side_effect.cmi test/import_side_effect.cmj : cc test/import_side_effect.res | test/side_effect.cmj test/side_effect2.cmj $bsc $stdlib runtime -o test/import_side_effect_free.cmi test/import_side_effect_free.cmj : cc test/import_side_effect_free.res | test/side_effect_free.cmj $bsc $stdlib runtime -o test/include_side_effect.cmi test/include_side_effect.cmj : cc test/include_side_effect.res | test/side_effect.cmj $bsc $stdlib runtime -o test/include_side_effect_free.cmi test/include_side_effect_free.cmj : cc test/include_side_effect_free.res | test/side_effect_free.cmj $bsc $stdlib runtime -o test/incomplete_toplevel_test.cmi test/incomplete_toplevel_test.cmj : cc test/incomplete_toplevel_test.res | $bsc $stdlib runtime -o test/infer_type_test.cmj : cc_cmi test/infer_type_test.res | test/infer_type_test.cmi $bsc $stdlib runtime -o test/infer_type_test.cmi : cc test/infer_type_test.resi | $bsc $stdlib runtime -o test/inline_condition_with_pattern_matching.cmi test/inline_condition_with_pattern_matching.cmj : cc test/inline_condition_with_pattern_matching.res | $bsc $stdlib runtime -o test/inline_const.cmj : cc_cmi test/inline_const.res | test/inline_const.cmi $bsc $stdlib runtime -o test/inline_const.cmi : cc test/inline_const.resi | $bsc $stdlib runtime -o test/inline_const_test.cmi test/inline_const_test.cmj : cc test/inline_const_test.res | test/inline_const.cmj test/mt.cmj $bsc $stdlib runtime -o test/inline_edge_cases.cmj : cc_cmi test/inline_edge_cases.res | test/inline_edge_cases.cmi $bsc $stdlib runtime -o test/inline_edge_cases.cmi : cc test/inline_edge_cases.resi | $bsc $stdlib runtime -o test/inline_map2_test.cmi test/inline_map2_test.cmj : cc test/inline_map2_test.res | test/mt.cmj $bsc $stdlib runtime -o test/inline_map_demo.cmi test/inline_map_demo.cmj : cc test/inline_map_demo.res | test/mt.cmj $bsc $stdlib runtime -o test/inline_map_test.cmj : cc_cmi test/inline_map_test.res | test/inline_map_test.cmi test/mt.cmj $bsc $stdlib runtime -o test/inline_map_test.cmi : cc test/inline_map_test.resi | $bsc $stdlib runtime -o test/inline_record_test.cmi test/inline_record_test.cmj : cc test/inline_record_test.res | test/mt.cmj $bsc $stdlib runtime -o test/inline_regression_test.cmi test/inline_regression_test.cmj : cc test/inline_regression_test.res | test/mt.cmj $bsc $stdlib runtime -o test/inline_string_test.cmi test/inline_string_test.cmj : cc test/inline_string_test.res | $bsc $stdlib runtime -o test/inner_call.cmi test/inner_call.cmj : cc test/inner_call.res | test/inner_define.cmj $bsc $stdlib runtime -o test/inner_define.cmj : cc_cmi test/inner_define.res | test/inner_define.cmi $bsc $stdlib runtime -o test/inner_define.cmi : cc test/inner_define.resi | $bsc $stdlib runtime -o test/inner_unused.cmi test/inner_unused.cmj : cc test/inner_unused.res | $bsc $stdlib runtime -o test/installation_test.cmi test/installation_test.cmj : cc test/installation_test.res | test/mt.cmj $bsc $stdlib runtime -o test/int32_test.cmi test/int32_test.cmj : cc test/int32_test.res | test/ext_array_test.cmj test/mt.cmj $bsc $stdlib runtime -o test/int64_mul_div_test.cmi test/int64_mul_div_test.cmj : cc test/int64_mul_div_test.res | test/mt.cmj $bsc $stdlib runtime -o test/int64_string_bench.cmi test/int64_string_bench.cmj : cc test/int64_string_bench.res | $bsc $stdlib runtime -o test/int64_string_test.cmi test/int64_string_test.cmj : cc test/int64_string_test.res | test/mt.cmj $bsc $stdlib runtime -o test/int64_test.cmi test/int64_test.cmj : cc test/int64_test.res | test/ext_array_test.cmj test/mt.cmj $bsc $stdlib runtime -o test/int_hashtbl_test.cmi test/int_hashtbl_test.cmj : cc test/int_hashtbl_test.res | test/mt.cmj $bsc $stdlib runtime -o test/int_map.cmi test/int_map.cmj : cc test/int_map.res | $bsc $stdlib runtime -o test/int_overflow_test.cmi test/int_overflow_test.cmj : cc test/int_overflow_test.res | test/mt.cmj $bsc $stdlib runtime -o test/int_poly_var.cmi test/int_poly_var.cmj : cc test/int_poly_var.res | test/mt.cmj test/test2.cmj $bsc $stdlib runtime -o test/int_switch_test.cmi test/int_switch_test.cmj : cc test/int_switch_test.res | test/mt.cmj $bsc $stdlib runtime -o test/internal_unused_test.cmi test/internal_unused_test.cmj : cc test/internal_unused_test.res | $bsc $stdlib runtime -o test/io_test.cmi test/io_test.cmj : cc test/io_test.res | $bsc $stdlib runtime -o test/js_array_test.cmi test/js_array_test.cmj : cc test/js_array_test.res | test/mt.cmj $bsc $stdlib runtime -o test/js_bool_test.cmi test/js_bool_test.cmj : cc test/js_bool_test.res | test/mt.cmj $bsc $stdlib runtime -o test/js_cast_test.cmi test/js_cast_test.cmj : cc test/js_cast_test.res | test/mt.cmj $bsc $stdlib runtime -o test/js_date_test.cmi test/js_date_test.cmj : cc test/js_date_test.res | test/mt.cmj $bsc $stdlib runtime -o test/js_dict_test.cmi test/js_dict_test.cmj : cc test/js_dict_test.res | test/mt.cmj $bsc $stdlib runtime -o test/js_exception_catch_test.cmi test/js_exception_catch_test.cmj : cc test/js_exception_catch_test.res | test/mt.cmj $bsc $stdlib runtime -o test/js_float_test.cmi test/js_float_test.cmj : cc test/js_float_test.res | test/mt.cmj $bsc $stdlib runtime -o test/js_global_test.cmi test/js_global_test.cmj : cc test/js_global_test.res | test/mt.cmj $bsc $stdlib runtime -o test/js_int_test.cmi test/js_int_test.cmj : cc test/js_int_test.res | test/mt.cmj $bsc $stdlib runtime -o test/js_json_test.cmi test/js_json_test.cmj : cc test/js_json_test.res | test/mt.cmj $bsc $stdlib runtime -o test/js_math_test.cmi test/js_math_test.cmj : cc test/js_math_test.res | test/mt.cmj $bsc $stdlib runtime -o test/js_null_test.cmi test/js_null_test.cmj : cc test/js_null_test.res | test/mt.cmj $bsc $stdlib runtime -o test/js_null_undefined_test.cmi test/js_null_undefined_test.cmj : cc test/js_null_undefined_test.res | test/mt.cmj $bsc $stdlib runtime -o test/js_nullable_test.cmi test/js_nullable_test.cmj : cc test/js_nullable_test.res | test/mt.cmj $bsc $stdlib runtime -o test/js_obj_test.cmi test/js_obj_test.cmj : cc test/js_obj_test.res | test/mt.cmj $bsc $stdlib runtime -o test/js_option_test.cmi test/js_option_test.cmj : cc test/js_option_test.res | test/mt.cmj $bsc $stdlib runtime -o test/js_re_test.cmi test/js_re_test.cmj : cc test/js_re_test.res | test/mt.cmj $bsc $stdlib runtime -o test/js_string_test.cmi test/js_string_test.cmj : cc test/js_string_test.res | test/mt.cmj $bsc $stdlib runtime -o test/js_undefined_test.cmi test/js_undefined_test.cmj : cc test/js_undefined_test.res | test/mt.cmj $bsc $stdlib runtime -o test/js_val.cmi test/js_val.cmj : cc test/js_val.res | $bsc $stdlib runtime -o test/jsoo_400_test.cmi test/jsoo_400_test.cmj : cc test/jsoo_400_test.res | test/mt.cmj $bsc $stdlib runtime -o test/jsoo_485_test.cmi test/jsoo_485_test.cmj : cc test/jsoo_485_test.res | $bsc $stdlib runtime -o test/jsxv4_newtype.cmi test/jsxv4_newtype.cmj : cc test/jsxv4_newtype.res | test/react.cmj $bsc $stdlib runtime -o test/keep_uncurry_attribute.cmi test/keep_uncurry_attribute.cmj : cc test/keep_uncurry_attribute.res | $bsc $stdlib runtime -o test/key_word_property.cmi test/key_word_property.cmj : cc test/key_word_property.res | $bsc $stdlib runtime -o test/key_word_property2.cmi test/key_word_property2.cmj : cc test/key_word_property2.res | test/export_keyword.cmj $bsc $stdlib runtime -o test/key_word_property_plus_test.cmi test/key_word_property_plus_test.cmj : cc test/key_word_property_plus_test.res | test/global_mangles.cmj test/mt.cmj $bsc $stdlib runtime -o test/label_uncurry.cmi test/label_uncurry.cmj : cc test/label_uncurry.res | $bsc $stdlib runtime -o test/large_integer_pat.cmi test/large_integer_pat.cmj : cc test/large_integer_pat.res | $bsc $stdlib runtime -o test/large_record_duplication_test.cmi test/large_record_duplication_test.cmj : cc test/large_record_duplication_test.res | test/mt.cmj $bsc $stdlib runtime -o test/largest_int_flow.cmi test/largest_int_flow.cmj : cc test/largest_int_flow.res | $bsc $stdlib runtime -o test/lazy_demo.cmi test/lazy_demo.cmj : cc test/lazy_demo.res | $bsc $stdlib runtime -o test/lazy_test.cmi test/lazy_test.cmj : cc test/lazy_test.res | test/mt.cmj $bsc $stdlib runtime -o test/lib_js_test.cmi test/lib_js_test.cmj : cc test/lib_js_test.res | test/mt.cmj $bsc $stdlib runtime -o test/libarg_test.cmi test/libarg_test.cmj : cc test/libarg_test.res | test/mt.cmj $bsc $stdlib runtime -o test/libqueue_test.cmi test/libqueue_test.cmj : cc test/libqueue_test.res | $bsc $stdlib runtime -o test/limits_test.cmi test/limits_test.cmj : cc test/limits_test.res | test/mt.cmj $bsc $stdlib runtime -o test/list_stack.cmi test/list_stack.cmj : cc test/list_stack.res | $bsc $stdlib runtime -o test/list_test.cmi test/list_test.cmj : cc test/list_test.res | test/mt.cmj $bsc $stdlib runtime -o test/local_exception_test.cmi test/local_exception_test.cmj : cc test/local_exception_test.res | $bsc $stdlib runtime -o test/loop_regression_test.cmi test/loop_regression_test.cmj : cc test/loop_regression_test.res | test/mt.cmj $bsc $stdlib runtime -o test/map_find_test.cmi test/map_find_test.cmj : cc test/map_find_test.res | test/mt.cmj $bsc $stdlib runtime -o test/map_test.cmi test/map_test.cmj : cc test/map_test.res | test/mt.cmj $bsc $stdlib runtime -o test/mario_game.cmi test/mario_game.cmj : cc test/mario_game.res | $bsc $stdlib runtime -o test/meth_annotation.cmi test/meth_annotation.cmj : cc test/meth_annotation.res | $bsc $stdlib runtime -o test/method_name_test.cmi test/method_name_test.cmj : cc test/method_name_test.res | test/mt.cmj $bsc $stdlib runtime -o test/method_string_name.cmi test/method_string_name.cmj : cc test/method_string_name.res | $bsc $stdlib runtime -o test/minimal_test.cmi test/minimal_test.cmj : cc test/minimal_test.res | $bsc $stdlib runtime -o test/miss_colon_test.cmi test/miss_colon_test.cmj : cc test/miss_colon_test.res | $bsc $stdlib runtime -o test/mock_mt.cmi test/mock_mt.cmj : cc test/mock_mt.res | test/mt.cmj $bsc $stdlib runtime -o test/module_alias_test.cmi test/module_alias_test.cmj : cc test/module_alias_test.res | test/ext_pervasives_test.cmj test/mt.cmj $bsc $stdlib runtime -o test/module_as_class_ffi.cmi test/module_as_class_ffi.cmj : cc test/module_as_class_ffi.res | $bsc $stdlib runtime -o test/module_as_function.cmi test/module_as_function.cmj : cc test/module_as_function.res | $bsc $stdlib runtime -o test/module_missing_conversion.cmi test/module_missing_conversion.cmj : cc test/module_missing_conversion.res | $bsc $stdlib runtime -o test/module_parameter_test.cmi test/module_parameter_test.cmj : cc test/module_parameter_test.res | test/mt.cmj $bsc $stdlib runtime -o test/module_splice_test.cmi test/module_splice_test.cmj : cc test/module_splice_test.res | test/mt.cmj $bsc $stdlib runtime -o test/more_poly_variant_test.cmi test/more_poly_variant_test.cmj : cc test/more_poly_variant_test.res | $bsc $stdlib runtime -o test/more_uncurry.cmi test/more_uncurry.cmj : cc test/more_uncurry.res | $bsc $stdlib runtime -o test/mpr_6033_test.cmi test/mpr_6033_test.cmj : cc test/mpr_6033_test.res | test/mt.cmj $bsc $stdlib runtime -o test/mt.cmj : cc_cmi test/mt.res | test/mt.cmi $bsc $stdlib runtime -o test/mt.cmi : cc test/mt.resi | $bsc $stdlib runtime -o test/mt_global.cmj : cc_cmi test/mt_global.res | test/mt.cmj test/mt_global.cmi $bsc $stdlib runtime -o test/mt_global.cmi : cc test/mt_global.resi | test/mt.cmi $bsc $stdlib runtime -o test/mutable_obj_test.cmi test/mutable_obj_test.cmj : cc test/mutable_obj_test.res | $bsc $stdlib runtime -o test/mutable_uncurry_test.cmi test/mutable_uncurry_test.cmj : cc test/mutable_uncurry_test.res | test/mt.cmj $bsc $stdlib runtime -o test/mutual_non_recursive_type.cmi test/mutual_non_recursive_type.cmj : cc test/mutual_non_recursive_type.res | $bsc $stdlib runtime -o test/name_mangle_test.cmi test/name_mangle_test.cmj : cc test/name_mangle_test.res | test/mt.cmj $bsc $stdlib runtime -o test/nested_include.cmi test/nested_include.cmj : cc test/nested_include.res | $bsc $stdlib runtime -o test/nested_module_alias.cmi test/nested_module_alias.cmj : cc test/nested_module_alias.res | $bsc $stdlib runtime -o test/nested_obj_literal.cmi test/nested_obj_literal.cmj : cc test/nested_obj_literal.res | $bsc $stdlib runtime -o test/nested_obj_test.cmi test/nested_obj_test.cmj : cc test/nested_obj_test.res | $bsc $stdlib runtime -o test/nested_pattern_match_test.cmi test/nested_pattern_match_test.cmj : cc test/nested_pattern_match_test.res | $bsc $stdlib runtime -o test/noassert.cmi test/noassert.cmj : cc test/noassert.res | $bsc $stdlib runtime -o test/node_assert.cmi test/node_assert.cmj : cc test/node_assert.res | $bsc $stdlib runtime -o test/node_path_test.cmi test/node_path_test.cmj : cc test/node_path_test.res | $bsc $stdlib runtime -o test/node_test.cmi test/node_test.cmj : cc test/node_test.res | $bsc $stdlib runtime -o test/node_test_util.cmi test/node_test_util.cmj : cc test/node_test_util.res | test/node_assert.cmj $bsc $stdlib runtime -o test/number_lexer.cmi test/number_lexer.cmj : cc test/number_lexer.res | $bsc $stdlib runtime -o test/obj_literal_ppx.cmi test/obj_literal_ppx.cmj : cc test/obj_literal_ppx.res | $bsc $stdlib runtime -o test/obj_literal_ppx_test.cmi test/obj_literal_ppx_test.cmj : cc test/obj_literal_ppx_test.res | $bsc $stdlib runtime -o test/obj_magic_test.cmi test/obj_magic_test.cmj : cc test/obj_magic_test.res | test/mt.cmj $bsc $stdlib runtime -o test/obj_type_test.cmi test/obj_type_test.cmj : cc test/obj_type_test.res | $bsc $stdlib runtime -o test/ocaml_re_test.cmi test/ocaml_re_test.cmj : cc test/ocaml_re_test.res | test/mt.cmj $bsc $stdlib runtime -o test/of_string_test.cmi test/of_string_test.cmj : cc test/of_string_test.res | test/mt.cmj $bsc $stdlib runtime -o test/offset.cmi test/offset.cmj : cc test/offset.res | $bsc $stdlib runtime -o test/omit_trailing_undefined_in_external_calls.cmi test/omit_trailing_undefined_in_external_calls.cmj : cc test/omit_trailing_undefined_in_external_calls.res | $bsc $stdlib runtime -o test/option_encoding_test.cmi test/option_encoding_test.cmj : cc test/option_encoding_test.res | $bsc $stdlib runtime -o test/option_repr_test.cmi test/option_repr_test.cmj : cc test/option_repr_test.res | test/mt.cmj $bsc $stdlib runtime -o test/optional_ffi_test.cmi test/optional_ffi_test.cmj : cc test/optional_ffi_test.res | test/mt.cmj $bsc $stdlib runtime -o test/optional_regression_test.cmi test/optional_regression_test.cmj : cc test/optional_regression_test.res | test/mt.cmj $bsc $stdlib runtime -o test/pipe_send_readline.cmi test/pipe_send_readline.cmj : cc test/pipe_send_readline.res | $bsc $stdlib runtime -o test/pipe_syntax.cmi test/pipe_syntax.cmj : cc test/pipe_syntax.res | $bsc $stdlib runtime -o test/poly_empty_array.cmi test/poly_empty_array.cmj : cc test/poly_empty_array.res | $bsc $stdlib runtime -o test/poly_variant_test.cmj : cc_cmi test/poly_variant_test.res | test/mt.cmj test/poly_variant_test.cmi $bsc $stdlib runtime -o test/poly_variant_test.cmi : cc test/poly_variant_test.resi | $bsc $stdlib runtime -o test/polymorphic_raw_test.cmi test/polymorphic_raw_test.cmj : cc test/polymorphic_raw_test.res | test/mt.cmj $bsc $stdlib runtime -o test/polymorphism_test.cmj : cc_cmi test/polymorphism_test.res | test/polymorphism_test.cmi $bsc $stdlib runtime -o test/polymorphism_test.cmi : cc test/polymorphism_test.resi | $bsc $stdlib runtime -o test/polyvar_convert.cmi test/polyvar_convert.cmj : cc test/polyvar_convert.res | $bsc $stdlib runtime -o test/polyvar_test.cmi test/polyvar_test.cmj : cc test/polyvar_test.res | $bsc $stdlib runtime -o test/ppx_apply_test.cmi test/ppx_apply_test.cmj : cc test/ppx_apply_test.res | test/mt.cmj $bsc $stdlib runtime -o test/pq_test.cmi test/pq_test.cmj : cc test/pq_test.res | $bsc $stdlib runtime -o test/pr6726.cmi test/pr6726.cmj : cc test/pr6726.res | $bsc $stdlib runtime -o test/prepend_data_ffi.cmi test/prepend_data_ffi.cmj : cc test/prepend_data_ffi.res | $bsc $stdlib runtime -o test/primitive_reg_test.cmi test/primitive_reg_test.cmj : cc test/primitive_reg_test.res | $bsc $stdlib runtime -o test/print_alpha_test.cmi test/print_alpha_test.cmj : cc test/print_alpha_test.res | test/mt.cmj $bsc $stdlib runtime -o test/queue_402.cmi test/queue_402.cmj : cc test/queue_402.res | $bsc $stdlib runtime -o test/queue_test.cmi test/queue_test.cmj : cc test/queue_test.res | test/mt.cmj test/queue_402.cmj $bsc $stdlib runtime -o test/random_test.cmi test/random_test.cmj : cc test/random_test.res | test/mt.cmj test/mt_global.cmj $bsc $stdlib runtime -o test/raw_hash_tbl_bench.cmi test/raw_hash_tbl_bench.cmj : cc test/raw_hash_tbl_bench.res | $bsc $stdlib runtime -o test/raw_output_test.cmi test/raw_output_test.cmj : cc test/raw_output_test.res | $bsc $stdlib runtime -o test/raw_pure_test.cmi test/raw_pure_test.cmj : cc test/raw_pure_test.res | $bsc $stdlib runtime -o test/rbset.cmi test/rbset.cmj : cc test/rbset.res | $bsc $stdlib runtime -o test/react.cmi test/react.cmj : cc test/react.res | $bsc $stdlib runtime -o test/reactDOMRe.cmi test/reactDOMRe.cmj : cc test/reactDOMRe.res | test/react.cmj test/reactEvent.cmj test/reasonReact.cmj $bsc $stdlib runtime -o test/reactDOMServerRe.cmi test/reactDOMServerRe.cmj : cc test/reactDOMServerRe.res | test/react.cmj $bsc $stdlib runtime -o test/reactEvent.cmj : cc_cmi test/reactEvent.res | test/reactEvent.cmi $bsc $stdlib runtime -o test/reactEvent.cmi : cc test/reactEvent.resi | $bsc $stdlib runtime -o test/reactTestUtils.cmj : cc_cmi test/reactTestUtils.res | test/react.cmj test/reactTestUtils.cmi $bsc $stdlib runtime -o test/reactTestUtils.cmi : cc test/reactTestUtils.resi | test/react.cmi $bsc $stdlib runtime -o test/reasonReact.cmj : cc_cmi test/reasonReact.res | test/react.cmj test/reasonReact.cmi test/reasonReactRouter.cmj $bsc $stdlib runtime -o test/reasonReact.cmi : cc test/reasonReact.resi | test/react.cmi test/reasonReactRouter.cmi $bsc $stdlib runtime -o test/reasonReactCompat.cmj : cc_cmi test/reasonReactCompat.res | test/react.cmj test/reasonReact.cmj test/reasonReactCompat.cmi $bsc $stdlib runtime -o test/reasonReactCompat.cmi : cc test/reasonReactCompat.resi | test/react.cmi test/reasonReact.cmi $bsc $stdlib runtime -o test/reasonReactOptimizedCreateClass.cmi test/reasonReactOptimizedCreateClass.cmj : cc test/reasonReactOptimizedCreateClass.res | $bsc $stdlib runtime -o test/reasonReactRouter.cmj : cc_cmi test/reasonReactRouter.res | test/react.cmj test/reasonReactRouter.cmi $bsc $stdlib runtime -o test/reasonReactRouter.cmi : cc test/reasonReactRouter.resi | $bsc $stdlib runtime -o test/rebind_module.cmi test/rebind_module.cmj : cc test/rebind_module.res | $bsc $stdlib runtime -o test/rebind_module_test.cmi test/rebind_module_test.cmj : cc test/rebind_module_test.res | test/rebind_module.cmj $bsc $stdlib runtime -o test/rec_array_test.cmi test/rec_array_test.cmj : cc test/rec_array_test.res | $bsc $stdlib runtime -o test/rec_fun_test.cmi test/rec_fun_test.cmj : cc test/rec_fun_test.res | test/mt.cmj $bsc $stdlib runtime -o test/rec_module_opt.cmi test/rec_module_opt.cmj : cc test/rec_module_opt.res | $bsc $stdlib runtime -o test/rec_module_test.cmi test/rec_module_test.cmj : cc test/rec_module_test.res | test/mt.cmj $bsc $stdlib runtime -o test/recmodule.cmi test/recmodule.cmj : cc test/recmodule.res | $bsc $stdlib runtime -o test/record_debug_test.cmi test/record_debug_test.cmj : cc test/record_debug_test.res | test/mt.cmj $bsc $stdlib runtime -o test/record_extension_test.cmi test/record_extension_test.cmj : cc test/record_extension_test.res | test/mt.cmj $bsc $stdlib runtime -o test/record_name_test.cmi test/record_name_test.cmj : cc test/record_name_test.res | $bsc $stdlib runtime -o test/record_regression.cmi test/record_regression.cmj : cc test/record_regression.res | $bsc $stdlib runtime -o test/record_type_spread.cmi test/record_type_spread.cmj : cc test/record_type_spread.res | $bsc $stdlib runtime -o test/record_with_test.cmi test/record_with_test.cmj : cc test/record_with_test.res | test/mt.cmj $bsc $stdlib runtime -o test/recursive_module.cmi test/recursive_module.cmj : cc test/recursive_module.res | test/mt.cmj $bsc $stdlib runtime -o test/recursive_module_test.cmi test/recursive_module_test.cmj : cc test/recursive_module_test.res | test/mt.cmj $bsc $stdlib runtime -o test/recursive_react_component.cmi test/recursive_react_component.cmj : cc test/recursive_react_component.res | test/react.cmj $bsc $stdlib runtime -o test/recursive_records_test.cmi test/recursive_records_test.cmj : cc test/recursive_records_test.res | test/mt.cmj $bsc $stdlib runtime -o test/recursive_unbound_module_test.cmi test/recursive_unbound_module_test.cmj : cc test/recursive_unbound_module_test.res | $bsc $stdlib runtime -o test/regression_print.cmi test/regression_print.cmj : cc test/regression_print.res | $bsc $stdlib runtime -o test/relative_path.cmi test/relative_path.cmj : cc test/relative_path.res | $bsc $stdlib runtime -o test/res_debug.cmi test/res_debug.cmj : cc test/res_debug.res | $bsc $stdlib runtime -o test/return_check.cmi test/return_check.cmj : cc test/return_check.res | $bsc $stdlib runtime -o test/runtime_encoding_test.cmi test/runtime_encoding_test.cmj : cc test/runtime_encoding_test.res | $bsc $stdlib runtime -o test/set_annotation.cmi test/set_annotation.cmj : cc test/set_annotation.res | $bsc $stdlib runtime -o test/set_gen.cmi test/set_gen.cmj : cc test/set_gen.res | $bsc $stdlib runtime -o test/sexp.cmj : cc_cmi test/sexp.res | test/sexp.cmi $bsc $stdlib runtime -o test/sexp.cmi : cc test/sexp.resi | $bsc $stdlib runtime -o test/sexpm.cmj : cc_cmi test/sexpm.res | test/sexpm.cmi $bsc $stdlib runtime -o test/sexpm.cmi : cc test/sexpm.resi | $bsc $stdlib runtime -o test/sexpm_test.cmi test/sexpm_test.cmj : cc test/sexpm_test.res | test/mt.cmj test/sexpm.cmj $bsc $stdlib runtime -o test/side_effect.cmi test/side_effect.cmj : cc test/side_effect.res | $bsc $stdlib runtime -o test/side_effect2.cmi test/side_effect2.cmj : cc test/side_effect2.res | $bsc $stdlib runtime -o test/side_effect_free.cmi test/side_effect_free.cmj : cc test/side_effect_free.res | $bsc $stdlib runtime -o test/simplify_lambda_632o.cmi test/simplify_lambda_632o.cmj : cc test/simplify_lambda_632o.res | $bsc $stdlib runtime -o test/single_module_alias.cmi test/single_module_alias.cmj : cc test/single_module_alias.res | $bsc $stdlib runtime -o test/singular_unit_test.cmi test/singular_unit_test.cmj : cc test/singular_unit_test.res | $bsc $stdlib runtime -o test/small_inline_test.cmi test/small_inline_test.cmj : cc test/small_inline_test.res | $bsc $stdlib runtime -o test/splice_test.cmi test/splice_test.cmj : cc test/splice_test.res | test/mt.cmj $bsc $stdlib runtime -o test/stack_comp_test.cmi test/stack_comp_test.cmj : cc test/stack_comp_test.res | test/mt.cmj test/mt_global.cmj $bsc $stdlib runtime -o test/stack_test.cmi test/stack_test.cmj : cc test/stack_test.res | test/mt.cmj $bsc $stdlib runtime -o test/stream_parser_test.cmi test/stream_parser_test.cmj : cc test/stream_parser_test.res | test/mt.cmj $bsc $stdlib runtime -o test/string_bound_get_test.cmi test/string_bound_get_test.cmj : cc test/string_bound_get_test.res | $bsc $stdlib runtime -o test/string_constant_compare.cmi test/string_constant_compare.cmj : cc test/string_constant_compare.res | $bsc $stdlib runtime -o test/string_get_set_test.cmi test/string_get_set_test.cmj : cc test/string_get_set_test.res | test/mt.cmj $bsc $stdlib runtime -o test/string_runtime_test.cmi test/string_runtime_test.cmj : cc test/string_runtime_test.res | test/mt.cmj test/test_char.cmj $bsc $stdlib runtime -o test/string_set.cmi test/string_set.cmj : cc test/string_set.res | test/set_gen.cmj $bsc $stdlib runtime -o test/string_set_test.cmi test/string_set_test.cmj : cc test/string_set_test.res | test/mt.cmj test/string_set.cmj $bsc $stdlib runtime -o test/string_test.cmi test/string_test.cmj : cc test/string_test.res | test/ext_string_test.cmj test/mt.cmj $bsc $stdlib runtime -o test/string_unicode_test.cmi test/string_unicode_test.cmj : cc test/string_unicode_test.res | test/mt.cmj $bsc $stdlib runtime -o test/stringmatch_test.cmi test/stringmatch_test.cmj : cc test/stringmatch_test.res | $bsc $stdlib runtime -o test/submodule.cmi test/submodule.cmj : cc test/submodule.res | $bsc $stdlib runtime -o test/submodule_call.cmi test/submodule_call.cmj : cc test/submodule_call.res | test/submodule.cmj $bsc $stdlib runtime -o test/switch_case_test.cmi test/switch_case_test.cmj : cc test/switch_case_test.res | test/mt.cmj $bsc $stdlib runtime -o test/switch_string.cmi test/switch_string.cmj : cc test/switch_string.res | $bsc $stdlib runtime -o test/tagged_template_test.cmi test/tagged_template_test.cmj : cc test/tagged_template_test.res | test/mt.cmj $bsc $stdlib runtime -o test/tailcall_inline_test.cmi test/tailcall_inline_test.cmj : cc test/tailcall_inline_test.res | test/mt.cmj $bsc $stdlib runtime -o test/template.cmi test/template.cmj : cc test/template.res | $bsc $stdlib runtime -o test/test2.cmi test/test2.cmj : cc test/test2.res | $bsc $stdlib runtime -o test/test_alias.cmi test/test_alias.cmj : cc test/test_alias.res | test/test_global_print.cmj $bsc $stdlib runtime -o test/test_ari.cmi test/test_ari.cmj : cc test/test_ari.res | $bsc $stdlib runtime -o test/test_array.cmi test/test_array.cmj : cc test/test_array.res | $bsc $stdlib runtime -o test/test_array_append.cmi test/test_array_append.cmj : cc test/test_array_append.res | $bsc $stdlib runtime -o test/test_array_primitive.cmi test/test_array_primitive.cmj : cc test/test_array_primitive.res | $bsc $stdlib runtime -o test/test_bool_equal.cmi test/test_bool_equal.cmj : cc test/test_bool_equal.res | $bsc $stdlib runtime -o test/test_bs_this.cmi test/test_bs_this.cmj : cc test/test_bs_this.res | $bsc $stdlib runtime -o test/test_bug.cmi test/test_bug.cmj : cc test/test_bug.res | test/test_char.cmj $bsc $stdlib runtime -o test/test_bytes.cmi test/test_bytes.cmj : cc test/test_bytes.res | $bsc $stdlib runtime -o test/test_case_opt_collision.cmi test/test_case_opt_collision.cmj : cc test/test_case_opt_collision.res | test/mt.cmj $bsc $stdlib runtime -o test/test_case_set.cmi test/test_case_set.cmj : cc test/test_case_set.res | $bsc $stdlib runtime -o test/test_char.cmi test/test_char.cmj : cc test/test_char.res | $bsc $stdlib runtime -o test/test_closure.cmi test/test_closure.cmj : cc test/test_closure.res | $bsc $stdlib runtime -o test/test_common.cmi test/test_common.cmj : cc test/test_common.res | $bsc $stdlib runtime -o test/test_const_elim.cmi test/test_const_elim.cmj : cc test/test_const_elim.res | $bsc $stdlib runtime -o test/test_const_propogate.cmi test/test_const_propogate.cmj : cc test/test_const_propogate.res | $bsc $stdlib runtime -o test/test_cpp.cmi test/test_cpp.cmj : cc test/test_cpp.res | $bsc $stdlib runtime -o test/test_cps.cmi test/test_cps.cmj : cc test/test_cps.res | $bsc $stdlib runtime -o test/test_demo.cmi test/test_demo.cmj : cc test/test_demo.res | $bsc $stdlib runtime -o test/test_dup_param.cmi test/test_dup_param.cmj : cc test/test_dup_param.res | $bsc $stdlib runtime -o test/test_eq.cmi test/test_eq.cmj : cc test/test_eq.res | $bsc $stdlib runtime -o test/test_exception.cmi test/test_exception.cmj : cc test/test_exception.res | test/test_common.cmj $bsc $stdlib runtime -o test/test_exception_escape.cmi test/test_exception_escape.cmj : cc test/test_exception_escape.res | $bsc $stdlib runtime -o test/test_export2.cmi test/test_export2.cmj : cc test/test_export2.res | $bsc $stdlib runtime -o test/test_external.cmi test/test_external.cmj : cc test/test_external.res | $bsc $stdlib runtime -o test/test_external_unit.cmi test/test_external_unit.cmj : cc test/test_external_unit.res | $bsc $stdlib runtime -o test/test_ffi.cmi test/test_ffi.cmj : cc test/test_ffi.res | $bsc $stdlib runtime -o test/test_fib.cmi test/test_fib.cmj : cc test/test_fib.res | $bsc $stdlib runtime -o test/test_filename.cmi test/test_filename.cmj : cc test/test_filename.res | $bsc $stdlib runtime -o test/test_for_loop.cmi test/test_for_loop.cmj : cc test/test_for_loop.res | $bsc $stdlib runtime -o test/test_for_map.cmi test/test_for_map.cmj : cc test/test_for_map.res | $bsc $stdlib runtime -o test/test_for_map2.cmi test/test_for_map2.cmj : cc test/test_for_map2.res | test/int_map.cmj $bsc $stdlib runtime -o test/test_functor_dead_code.cmi test/test_functor_dead_code.cmj : cc test/test_functor_dead_code.res | $bsc $stdlib runtime -o test/test_generative_module.cmi test/test_generative_module.cmj : cc test/test_generative_module.res | $bsc $stdlib runtime -o test/test_global_print.cmi test/test_global_print.cmj : cc test/test_global_print.res | $bsc $stdlib runtime -o test/test_google_closure.cmi test/test_google_closure.cmj : cc test/test_google_closure.res | $bsc $stdlib runtime -o test/test_include.cmi test/test_include.cmj : cc test/test_include.res | test/test_order.cmj $bsc $stdlib runtime -o test/test_incomplete.cmi test/test_incomplete.cmj : cc test/test_incomplete.res | $bsc $stdlib runtime -o test/test_incr_ref.cmi test/test_incr_ref.cmj : cc test/test_incr_ref.res | $bsc $stdlib runtime -o test/test_int_map_find.cmi test/test_int_map_find.cmj : cc test/test_int_map_find.res | $bsc $stdlib runtime -o test/test_is_js.cmi test/test_is_js.cmj : cc test/test_is_js.res | test/mt.cmj $bsc $stdlib runtime -o test/test_js_ffi.cmi test/test_js_ffi.cmj : cc test/test_js_ffi.res | $bsc $stdlib runtime -o test/test_let.cmi test/test_let.cmj : cc test/test_let.res | $bsc $stdlib runtime -o test/test_list.cmi test/test_list.cmj : cc test/test_list.res | $bsc $stdlib runtime -o test/test_literal.cmi test/test_literal.cmj : cc test/test_literal.res | $bsc $stdlib runtime -o test/test_literals.cmi test/test_literals.cmj : cc test/test_literals.res | $bsc $stdlib runtime -o test/test_match_exception.cmi test/test_match_exception.cmj : cc test/test_match_exception.res | $bsc $stdlib runtime -o test/test_mutliple.cmi test/test_mutliple.cmj : cc test/test_mutliple.res | $bsc $stdlib runtime -o test/test_nat64.cmi test/test_nat64.cmj : cc test/test_nat64.res | $bsc $stdlib runtime -o test/test_nested_let.cmi test/test_nested_let.cmj : cc test/test_nested_let.res | $bsc $stdlib runtime -o test/test_nested_print.cmi test/test_nested_print.cmj : cc test/test_nested_print.res | $bsc $stdlib runtime -o test/test_non_export.cmi test/test_non_export.cmj : cc test/test_non_export.res | $bsc $stdlib runtime -o test/test_nullary.cmi test/test_nullary.cmj : cc test/test_nullary.res | $bsc $stdlib runtime -o test/test_obj.cmi test/test_obj.cmj : cc test/test_obj.res | $bsc $stdlib runtime -o test/test_order.cmi test/test_order.cmj : cc test/test_order.res | $bsc $stdlib runtime -o test/test_order_tailcall.cmi test/test_order_tailcall.cmj : cc test/test_order_tailcall.res | $bsc $stdlib runtime -o test/test_other_exn.cmi test/test_other_exn.cmj : cc test/test_other_exn.res | $bsc $stdlib runtime -o test/test_per.cmi test/test_per.cmj : cc test/test_per.res | $bsc $stdlib runtime -o test/test_pervasive.cmi test/test_pervasive.cmj : cc test/test_pervasive.res | $bsc $stdlib runtime -o test/test_pervasives2.cmi test/test_pervasives2.cmj : cc test/test_pervasives2.res | $bsc $stdlib runtime -o test/test_pervasives3.cmi test/test_pervasives3.cmj : cc test/test_pervasives3.res | $bsc $stdlib runtime -o test/test_primitive.cmi test/test_primitive.cmj : cc test/test_primitive.res | $bsc $stdlib runtime -o test/test_ramification.cmi test/test_ramification.cmj : cc test/test_ramification.res | $bsc $stdlib runtime -o test/test_react.cmi test/test_react.cmj : cc test/test_react.res | $bsc $stdlib runtime -o test/test_react_case.cmi test/test_react_case.cmj : cc test/test_react_case.res | $bsc $stdlib runtime -o test/test_regex.cmi test/test_regex.cmj : cc test/test_regex.res | $bsc $stdlib runtime -o test/test_runtime_encoding.cmi test/test_runtime_encoding.cmj : cc test/test_runtime_encoding.res | $bsc $stdlib runtime -o test/test_scope.cmi test/test_scope.cmj : cc test/test_scope.res | $bsc $stdlib runtime -o test/test_seq.cmi test/test_seq.cmj : cc test/test_seq.res | $bsc $stdlib runtime -o test/test_set.cmi test/test_set.cmj : cc test/test_set.res | $bsc $stdlib runtime -o test/test_side_effect_functor.cmi test/test_side_effect_functor.cmj : cc test/test_side_effect_functor.res | $bsc $stdlib runtime -o test/test_simple_include.cmi test/test_simple_include.cmj : cc test/test_simple_include.res | $bsc $stdlib runtime -o test/test_simple_pattern_match.cmi test/test_simple_pattern_match.cmj : cc test/test_simple_pattern_match.res | $bsc $stdlib runtime -o test/test_simple_ref.cmi test/test_simple_ref.cmj : cc test/test_simple_ref.res | $bsc $stdlib runtime -o test/test_simple_tailcall.cmi test/test_simple_tailcall.cmj : cc test/test_simple_tailcall.res | $bsc $stdlib runtime -o test/test_small.cmi test/test_small.cmj : cc test/test_small.res | $bsc $stdlib runtime -o test/test_stack.cmi test/test_stack.cmj : cc test/test_stack.res | $bsc $stdlib runtime -o test/test_static_catch_ident.cmi test/test_static_catch_ident.cmj : cc test/test_static_catch_ident.res | $bsc $stdlib runtime -o test/test_string.cmi test/test_string.cmj : cc test/test_string.res | $bsc $stdlib runtime -o test/test_string_case.cmi test/test_string_case.cmj : cc test/test_string_case.res | $bsc $stdlib runtime -o test/test_string_const.cmi test/test_string_const.cmj : cc test/test_string_const.res | $bsc $stdlib runtime -o test/test_string_map.cmi test/test_string_map.cmj : cc test/test_string_map.res | $bsc $stdlib runtime -o test/test_string_switch.cmi test/test_string_switch.cmj : cc test/test_string_switch.res | $bsc $stdlib runtime -o test/test_switch.cmi test/test_switch.cmj : cc test/test_switch.res | $bsc $stdlib runtime -o test/test_trywith.cmi test/test_trywith.cmj : cc test/test_trywith.res | $bsc $stdlib runtime -o test/test_tuple.cmi test/test_tuple.cmj : cc test/test_tuple.res | $bsc $stdlib runtime -o test/test_tuple_destructring.cmi test/test_tuple_destructring.cmj : cc test/test_tuple_destructring.res | $bsc $stdlib runtime -o test/test_type_based_arity.cmi test/test_type_based_arity.cmj : cc test/test_type_based_arity.res | test/abstract_type.cmj $bsc $stdlib runtime -o test/test_u.cmi test/test_u.cmj : cc test/test_u.res | $bsc $stdlib runtime -o test/test_unknown.cmi test/test_unknown.cmj : cc test/test_unknown.res | $bsc $stdlib runtime -o test/test_unsafe_cmp.cmi test/test_unsafe_cmp.cmj : cc test/test_unsafe_cmp.res | $bsc $stdlib runtime -o test/test_unsafe_obj_ffi.cmj : cc_cmi test/test_unsafe_obj_ffi.res | test/test_unsafe_obj_ffi.cmi $bsc $stdlib runtime -o test/test_unsafe_obj_ffi.cmi : cc test/test_unsafe_obj_ffi.resi | $bsc $stdlib runtime -o test/test_unsafe_obj_ffi_ppx.cmj : cc_cmi test/test_unsafe_obj_ffi_ppx.res | test/test_unsafe_obj_ffi_ppx.cmi $bsc $stdlib runtime -o test/test_unsafe_obj_ffi_ppx.cmi : cc test/test_unsafe_obj_ffi_ppx.resi | $bsc $stdlib runtime -o test/test_while_closure.cmi test/test_while_closure.cmj : cc test/test_while_closure.res | $bsc $stdlib runtime -o test/test_while_side_effect.cmi test/test_while_side_effect.cmj : cc test/test_while_side_effect.res | $bsc $stdlib runtime -o test/test_zero_nullable.cmi test/test_zero_nullable.cmj : cc test/test_zero_nullable.res | test/mt.cmj $bsc $stdlib runtime -o test/then_mangle_test.cmi test/then_mangle_test.cmj : cc test/then_mangle_test.res | test/mt.cmj $bsc $stdlib runtime -o test/ticker.cmi test/ticker.cmj : cc test/ticker.res | $bsc $stdlib runtime -o test/to_string_test.cmi test/to_string_test.cmj : cc test/to_string_test.res | test/mt.cmj $bsc $stdlib runtime -o test/topsort_test.cmi test/topsort_test.cmj : cc test/topsort_test.res | $bsc $stdlib runtime -o test/tramp_fib.cmi test/tramp_fib.cmj : cc test/tramp_fib.res | test/mt.cmj $bsc $stdlib runtime -o test/tuple_alloc.cmi test/tuple_alloc.cmj : cc test/tuple_alloc.res | $bsc $stdlib runtime -o test/type-coercion-free-vars.cmi test/type-coercion-free-vars.cmj : cc test/type-coercion-free-vars.res | $bsc $stdlib runtime -o test/type_disambiguate.cmi test/type_disambiguate.cmj : cc test/type_disambiguate.res | $bsc $stdlib runtime -o test/typeof_test.cmi test/typeof_test.cmj : cc test/typeof_test.res | test/mt.cmj $bsc $stdlib runtime -o test/unboxed_attribute.cmi test/unboxed_attribute.cmj : cc test/unboxed_attribute.res | $bsc $stdlib runtime -o test/unboxed_attribute_test.cmi test/unboxed_attribute_test.cmj : cc test/unboxed_attribute_test.res | test/mt.cmj $bsc $stdlib runtime -o test/unboxed_crash.cmi test/unboxed_crash.cmj : cc test/unboxed_crash.res | $bsc $stdlib runtime -o test/unboxed_use_case.cmj : cc_cmi test/unboxed_use_case.res | test/unboxed_use_case.cmi $bsc $stdlib runtime -o test/unboxed_use_case.cmi : cc test/unboxed_use_case.resi | $bsc $stdlib runtime -o test/uncurried_cast.cmi test/uncurried_cast.cmj : cc test/uncurried_cast.res | $bsc $stdlib runtime -o test/uncurried_default.args.cmi test/uncurried_default.args.cmj : cc test/uncurried_default.args.res | $bsc $stdlib runtime -o test/uncurried_pipe.cmi test/uncurried_pipe.cmj : cc test/uncurried_pipe.res | $bsc $stdlib runtime -o test/uncurry_external_test.cmi test/uncurry_external_test.cmj : cc test/uncurry_external_test.res | test/mt.cmj $bsc $stdlib runtime -o test/uncurry_glob_test.cmi test/uncurry_glob_test.cmj : cc test/uncurry_glob_test.res | $bsc $stdlib runtime -o test/uncurry_test.cmj : cc_cmi test/uncurry_test.res | test/uncurry_test.cmi $bsc $stdlib runtime -o test/uncurry_test.cmi : cc test/uncurry_test.resi | $bsc $stdlib runtime -o test/undef_regression_test.cmi test/undef_regression_test.cmj : cc test/undef_regression_test.res | $bsc $stdlib runtime -o test/unit_undefined_test.cmi test/unit_undefined_test.cmj : cc test/unit_undefined_test.res | test/mt.cmj $bsc $stdlib runtime -o test/unsafe_full_apply_primitive.cmi test/unsafe_full_apply_primitive.cmj : cc test/unsafe_full_apply_primitive.res | $bsc $stdlib runtime -o test/unsafe_ppx_test.cmi test/unsafe_ppx_test.cmj : cc test/unsafe_ppx_test.res | test/ffi_js_test.cmj test/mt.cmj $bsc $stdlib runtime -o test/update_record_test.cmi test/update_record_test.cmj : cc test/update_record_test.res | test/mt.cmj $bsc $stdlib runtime -o test/variant.cmi test/variant.cmj : cc test/variant.res | $bsc $stdlib runtime -o test/variantsMatching.cmi test/variantsMatching.cmj : cc test/variantsMatching.res | $bsc $stdlib runtime -o test/webpack_config.cmi test/webpack_config.cmj : cc test/webpack_config.res | $bsc $stdlib runtime -o test : phony test/406_primitive_test.cmi test/406_primitive_test.cmj test/AsInUncurriedExternals.cmi test/AsInUncurriedExternals.cmj test/Coercion.cmi test/Coercion.cmj test/DerivingAccessorsCurried.cmi test/DerivingAccessorsCurried.cmj test/DerivingAccessorsUncurried.cmi test/DerivingAccessorsUncurried.cmj test/DictInference.cmi test/DictInference.cmj test/DictTests.cmi test/DictTests.cmj test/DisambiguateOptionalFields.cmi test/DisambiguateOptionalFields.cmj test/DotDotDot.cmi test/DotDotDot.cmj test/EmptyRecord.cmi test/EmptyRecord.cmj test/ExternalArity.cmi test/ExternalArity.cmj test/FFI.cmi test/FFI.cmj test/Import.cmi test/Import.cmj test/ImportAttributes.cmi test/ImportAttributes.cmj test/PartialApplicationNoRuntimeCurry.cmi test/PartialApplicationNoRuntimeCurry.cmj test/RecordCoercion.cmi test/RecordCoercion.cmj test/RecordOrObject.cmi test/RecordOrObject.cmj test/SafePromises.cmi test/SafePromises.cmj test/UncurriedAlways.cmi test/UncurriedAlways.cmj test/UncurriedExternals.cmi test/UncurriedExternals.cmj test/UncurriedPervasives.cmi test/UncurriedPervasives.cmj test/UntaggedVariants.cmi test/UntaggedVariants.cmj test/VariantCoercion.cmi test/VariantCoercion.cmj test/VariantPatternMatchingSpreads.cmi test/VariantPatternMatchingSpreads.cmj test/VariantPatternMatchingSpreadsWithPayloads.cmi test/VariantPatternMatchingSpreadsWithPayloads.cmj test/VariantSpreads.cmi test/VariantSpreads.cmj test/a.cmi test/a.cmj test/a_filename_test.cmi test/a_filename_test.cmj test/a_list_test.cmi test/a_list_test.cmj test/a_recursive_type.cmi test/a_recursive_type.cmj test/a_scope_bug.cmi test/a_scope_bug.cmj test/a_string_test.cmi test/a_string_test.cmj test/abstract_type.cmi test/abstract_type.cmj test/adt_optimize_test.cmi test/adt_optimize_test.cmj test/alias_default_value_test.cmi test/alias_default_value_test.cmj test/alias_test.cmi test/alias_test.cmj test/and_or_tailcall_test.cmi test/and_or_tailcall_test.cmj test/argv_test.cmi test/argv_test.cmj test/ari_regress_test.cmi test/ari_regress_test.cmj test/arith_lexer.cmi test/arith_lexer.cmj test/arith_parser.cmi test/arith_parser.cmj test/arith_syntax.cmi test/arith_syntax.cmj test/arity.cmi test/arity.cmj test/arity_deopt.cmi test/arity_deopt.cmj test/arity_infer.cmi test/arity_infer.cmj test/array_data_util.cmi test/array_data_util.cmj test/array_safe_get.cmi test/array_safe_get.cmj test/array_subtle_test.cmi test/array_subtle_test.cmj test/array_test.cmi test/array_test.cmj test/as_inline_record_test.cmi test/as_inline_record_test.cmj test/ast_abstract_test.cmi test/ast_abstract_test.cmj test/ast_mapper_unused_warning_test.cmi test/ast_mapper_unused_warning_test.cmj test/async_await.cmi test/async_await.cmj test/async_inline.cmi test/async_inline.cmj test/async_inside_loop.cmi test/async_inside_loop.cmj test/attr_test.cmi test/attr_test.cmj test/b.cmi test/b.cmj test/bal_set_mini.cmi test/bal_set_mini.cmj test/bang_primitive.cmi test/bang_primitive.cmj test/basic_module_test.cmi test/basic_module_test.cmj test/bb.cmi test/bb.cmj test/bdd.cmi test/bdd.cmj test/belt_float_ntest.cmi test/belt_float_ntest.cmj test/belt_hashmap_ntest.cmi test/belt_hashmap_ntest.cmj test/belt_hashset_int_ntest.cmi test/belt_hashset_int_ntest.cmj test/belt_int_ntest.cmi test/belt_int_ntest.cmj test/belt_internal_test.cmi test/belt_internal_test.cmj test/belt_list_ntest.cmi test/belt_list_ntest.cmj test/belt_mapint_ntest.cmi test/belt_mapint_ntest.cmj test/belt_result_alias_test.cmi test/belt_result_alias_test.cmj test/belt_sortarray_ntest.cmi test/belt_sortarray_ntest.cmj test/bench.cmi test/bench.cmj test/big_enum.cmi test/big_enum.cmj test/big_polyvar_test.cmi test/big_polyvar_test.cmj test/bigint_test.cmi test/bigint_test.cmj test/block_alias_test.cmi test/block_alias_test.cmj test/boolean_test.cmi test/boolean_test.cmj test/bs_abstract_test.cmi test/bs_abstract_test.cmj test/bs_array_test.cmi test/bs_array_test.cmj test/bs_auto_uncurry.cmi test/bs_auto_uncurry.cmj test/bs_auto_uncurry_test.cmi test/bs_auto_uncurry_test.cmj test/bs_ignore_effect.cmi test/bs_ignore_effect.cmj test/bs_ignore_test.cmi test/bs_ignore_test.cmj test/bs_map_set_dict_test.cmi test/bs_map_set_dict_test.cmj test/bs_map_test.cmi test/bs_map_test.cmj test/bs_min_max_test.cmi test/bs_min_max_test.cmj test/bs_mutable_set_test.cmi test/bs_mutable_set_test.cmj test/bs_poly_map_test.cmi test/bs_poly_map_test.cmj test/bs_poly_mutable_map_test.cmi test/bs_poly_mutable_map_test.cmj test/bs_poly_mutable_set_test.cmi test/bs_poly_mutable_set_test.cmj test/bs_poly_set_test.cmi test/bs_poly_set_test.cmj test/bs_qualified.cmi test/bs_qualified.cmj test/bs_queue_test.cmi test/bs_queue_test.cmj test/bs_rest_test.cmi test/bs_rest_test.cmj test/bs_set_int_test.cmi test/bs_set_int_test.cmj test/bs_splice_partial.cmi test/bs_splice_partial.cmj test/bs_stack_test.cmi test/bs_stack_test.cmj test/bs_string_test.cmi test/bs_string_test.cmj test/bs_unwrap_test.cmi test/bs_unwrap_test.cmj test/buffer_test.cmi test/buffer_test.cmj test/bytes_split_gpr_743_test.cmi test/bytes_split_gpr_743_test.cmj test/caml_compare_bigint_test.cmi test/caml_compare_bigint_test.cmj test/caml_compare_test.cmi test/caml_compare_test.cmj test/caml_format_test.cmi test/caml_format_test.cmj test/chain_code_test.cmi test/chain_code_test.cmj test/chn_test.cmi test/chn_test.cmj test/class_type_ffi_test.cmi test/class_type_ffi_test.cmj test/coercion_module_alias_test.cmi test/coercion_module_alias_test.cmj test/compare_test.cmi test/compare_test.cmj test/complete_parmatch_test.cmi test/complete_parmatch_test.cmj test/complex_if_test.cmi test/complex_if_test.cmj test/complex_test.cmi test/complex_test.cmj test/complex_while_loop.cmi test/complex_while_loop.cmj test/condition_compilation_test.cmi test/condition_compilation_test.cmj test/config1_test.cmi test/config1_test.cmj test/console_log_test.cmi test/console_log_test.cmj test/const_block_test.cmi test/const_block_test.cmj test/const_defs.cmi test/const_defs.cmj test/const_defs_test.cmi test/const_defs_test.cmj test/const_test.cmi test/const_test.cmj test/cont_int_fold_test.cmi test/cont_int_fold_test.cmj test/cps_test.cmi test/cps_test.cmj test/cross_module_inline_test.cmi test/cross_module_inline_test.cmj test/custom_error_test.cmi test/custom_error_test.cmj test/debug_keep_test.cmi test/debug_keep_test.cmj test/debug_mode_value.cmi test/debug_mode_value.cmj test/debug_tmp.cmi test/debug_tmp.cmj test/debugger_test.cmi test/debugger_test.cmj test/default_export_test.cmi test/default_export_test.cmj test/defunctor_make_test.cmi test/defunctor_make_test.cmj test/demo_int_map.cmi test/demo_int_map.cmj test/demo_page.cmi test/demo_page.cmj test/demo_pipe.cmi test/demo_pipe.cmj test/derive_projector_test.cmi test/derive_projector_test.cmj test/digest_test.cmi test/digest_test.cmj test/directives.cmi test/directives.cmj test/div_by_zero_test.cmi test/div_by_zero_test.cmj test/dollar_escape_test.cmi test/dollar_escape_test.cmj test/earger_curry_test.cmi test/earger_curry_test.cmj test/effect.cmi test/effect.cmj test/epsilon_test.cmi test/epsilon_test.cmj test/equal_box_test.cmi test/equal_box_test.cmj test/equal_exception_test.cmi test/equal_exception_test.cmj test/equal_test.cmi test/equal_test.cmj test/es6_export.cmi test/es6_export.cmj test/es6_import.cmi test/es6_import.cmj test/es6_module_test.cmi test/es6_module_test.cmj test/escape_esmodule.cmi test/escape_esmodule.cmj test/esmodule_ref.cmi test/esmodule_ref.cmj test/event_ffi.cmi test/event_ffi.cmj test/exception_alias.cmi test/exception_alias.cmj test/exception_raise_test.cmi test/exception_raise_test.cmj test/exception_rebound_err_test.cmi test/exception_rebound_err_test.cmj test/exception_value_test.cmi test/exception_value_test.cmj test/exotic_labels_test.cmi test/exotic_labels_test.cmj test/exponentiation_precedence_test.cmi test/exponentiation_precedence_test.cmj test/export_keyword.cmi test/export_keyword.cmj test/ext_array_test.cmi test/ext_array_test.cmj test/ext_bytes_test.cmi test/ext_bytes_test.cmj test/ext_filename_test.cmi test/ext_filename_test.cmj test/ext_list_test.cmi test/ext_list_test.cmj test/ext_pervasives_test.cmi test/ext_pervasives_test.cmj test/ext_string_test.cmi test/ext_string_test.cmj test/ext_sys_test.cmi test/ext_sys_test.cmj test/extensible_variant_test.cmi test/extensible_variant_test.cmj test/external_ppx.cmi test/external_ppx.cmj test/external_ppx2.cmi test/external_ppx2.cmj test/ffi_arity_test.cmi test/ffi_arity_test.cmj test/ffi_array_test.cmi test/ffi_array_test.cmj test/ffi_js_test.cmi test/ffi_js_test.cmj test/ffi_splice_test.cmi test/ffi_splice_test.cmj test/ffi_test.cmi test/ffi_test.cmj test/fib.cmi test/fib.cmj test/flattern_order_test.cmi test/flattern_order_test.cmj test/flexible_array_test.cmi test/flexible_array_test.cmj test/float_array.cmi test/float_array.cmj test/float_of_bits_test.cmi test/float_of_bits_test.cmj test/float_record.cmi test/float_record.cmj test/float_test.cmi test/float_test.cmj test/floatarray_test.cmi test/floatarray_test.cmj test/for_loop_test.cmi test/for_loop_test.cmj test/for_side_effect_test.cmi test/for_side_effect_test.cmj test/format_regression.cmi test/format_regression.cmj test/format_test.cmi test/format_test.cmj test/fun_pattern_match.cmi test/fun_pattern_match.cmj test/function_directives.cmi test/function_directives.cmj test/function_directives_no_inline.cmi test/function_directives_no_inline.cmj test/functor_app_test.cmi test/functor_app_test.cmj test/functor_def.cmi test/functor_def.cmj test/functor_ffi.cmi test/functor_ffi.cmj test/functor_inst.cmi test/functor_inst.cmj test/functors.cmi test/functors.cmj test/gbk.cmi test/gbk.cmj test/genlex_test.cmi test/genlex_test.cmj test/gentTypeReTest.cmi test/gentTypeReTest.cmj test/global_exception_regression_test.cmi test/global_exception_regression_test.cmj test/global_mangles.cmi test/global_mangles.cmj test/global_module_alias_test.cmi test/global_module_alias_test.cmj test/google_closure_test.cmi test/google_closure_test.cmj test/gpr496_test.cmi test/gpr496_test.cmj test/gpr_1072.cmi test/gpr_1072.cmj test/gpr_1072_reg.cmi test/gpr_1072_reg.cmj test/gpr_1150.cmi test/gpr_1150.cmj test/gpr_1154_test.cmi test/gpr_1154_test.cmj test/gpr_1170.cmi test/gpr_1170.cmj test/gpr_1240_missing_unbox.cmi test/gpr_1240_missing_unbox.cmj test/gpr_1245_test.cmi test/gpr_1245_test.cmj test/gpr_1268.cmi test/gpr_1268.cmj test/gpr_1409_test.cmi test/gpr_1409_test.cmj test/gpr_1423_app_test.cmi test/gpr_1423_app_test.cmj test/gpr_1423_nav.cmi test/gpr_1423_nav.cmj test/gpr_1438.cmi test/gpr_1438.cmj test/gpr_1481.cmi test/gpr_1481.cmj test/gpr_1484.cmi test/gpr_1484.cmj test/gpr_1503_test.cmi test/gpr_1503_test.cmj test/gpr_1539_test.cmi test/gpr_1539_test.cmj test/gpr_1658_test.cmi test/gpr_1658_test.cmj test/gpr_1667_test.cmi test/gpr_1667_test.cmj test/gpr_1692_test.cmi test/gpr_1692_test.cmj test/gpr_1698_test.cmi test/gpr_1698_test.cmj test/gpr_1701_test.cmi test/gpr_1701_test.cmj test/gpr_1716_test.cmi test/gpr_1716_test.cmj test/gpr_1717_test.cmi test/gpr_1717_test.cmj test/gpr_1728_test.cmi test/gpr_1728_test.cmj test/gpr_1749_test.cmi test/gpr_1749_test.cmj test/gpr_1759_test.cmi test/gpr_1759_test.cmj test/gpr_1760_test.cmi test/gpr_1760_test.cmj test/gpr_1762_test.cmi test/gpr_1762_test.cmj test/gpr_1817_test.cmi test/gpr_1817_test.cmj test/gpr_1822_test.cmi test/gpr_1822_test.cmj test/gpr_1891_test.cmi test/gpr_1891_test.cmj test/gpr_1943_test.cmi test/gpr_1943_test.cmj test/gpr_1946_test.cmi test/gpr_1946_test.cmj test/gpr_2316_test.cmi test/gpr_2316_test.cmj test/gpr_2352_test.cmi test/gpr_2352_test.cmj test/gpr_2413_test.cmi test/gpr_2413_test.cmj test/gpr_2474.cmi test/gpr_2474.cmj test/gpr_2487.cmi test/gpr_2487.cmj test/gpr_2503_test.cmi test/gpr_2503_test.cmj test/gpr_2608_test.cmi test/gpr_2608_test.cmj test/gpr_2614_test.cmi test/gpr_2614_test.cmj test/gpr_2633_test.cmi test/gpr_2633_test.cmj test/gpr_2642_test.cmi test/gpr_2642_test.cmj test/gpr_2682_test.cmi test/gpr_2682_test.cmj test/gpr_2700_test.cmi test/gpr_2700_test.cmj test/gpr_2731_test.cmi test/gpr_2731_test.cmj test/gpr_2789_test.cmi test/gpr_2789_test.cmj test/gpr_2931_test.cmi test/gpr_2931_test.cmj test/gpr_3142_test.cmi test/gpr_3142_test.cmj test/gpr_3154_test.cmi test/gpr_3154_test.cmj test/gpr_3209_test.cmi test/gpr_3209_test.cmj test/gpr_3492_test.cmi test/gpr_3492_test.cmj test/gpr_3519_jsx_test.cmi test/gpr_3519_jsx_test.cmj test/gpr_3519_test.cmi test/gpr_3519_test.cmj test/gpr_3536_test.cmi test/gpr_3536_test.cmj test/gpr_3546_test.cmi test/gpr_3546_test.cmj test/gpr_3548_test.cmi test/gpr_3548_test.cmj test/gpr_3549_test.cmi test/gpr_3549_test.cmj test/gpr_3566_drive_test.cmi test/gpr_3566_drive_test.cmj test/gpr_3566_test.cmi test/gpr_3566_test.cmj test/gpr_3595_test.cmi test/gpr_3595_test.cmj test/gpr_3609_test.cmi test/gpr_3609_test.cmj test/gpr_3697_test.cmi test/gpr_3697_test.cmj test/gpr_373_test.cmi test/gpr_373_test.cmj test/gpr_3770_test.cmi test/gpr_3770_test.cmj test/gpr_3852_alias.cmi test/gpr_3852_alias.cmj test/gpr_3852_alias_reify.cmi test/gpr_3852_alias_reify.cmj test/gpr_3852_effect.cmi test/gpr_3852_effect.cmj test/gpr_3865.cmi test/gpr_3865.cmj test/gpr_3865_bar.cmi test/gpr_3865_bar.cmj test/gpr_3865_foo.cmi test/gpr_3865_foo.cmj test/gpr_3875_test.cmi test/gpr_3875_test.cmj test/gpr_3877_test.cmi test/gpr_3877_test.cmj test/gpr_3895_test.cmi test/gpr_3895_test.cmj test/gpr_3897_test.cmi test/gpr_3897_test.cmj test/gpr_3931_test.cmi test/gpr_3931_test.cmj test/gpr_3980_test.cmi test/gpr_3980_test.cmj test/gpr_4025_test.cmi test/gpr_4025_test.cmj test/gpr_405_test.cmi test/gpr_405_test.cmj test/gpr_4069_test.cmi test/gpr_4069_test.cmj test/gpr_4265_test.cmi test/gpr_4265_test.cmj test/gpr_4274_test.cmi test/gpr_4274_test.cmj test/gpr_4280_test.cmi test/gpr_4280_test.cmj test/gpr_4407_test.cmi test/gpr_4407_test.cmj test/gpr_441.cmi test/gpr_441.cmj test/gpr_4442_test.cmi test/gpr_4442_test.cmj test/gpr_4491_test.cmi test/gpr_4491_test.cmj test/gpr_4494_test.cmi test/gpr_4494_test.cmj test/gpr_4519_test.cmi test/gpr_4519_test.cmj test/gpr_459_test.cmi test/gpr_459_test.cmj test/gpr_4632.cmi test/gpr_4632.cmj test/gpr_4639_test.cmi test/gpr_4639_test.cmj test/gpr_4900_test.cmi test/gpr_4900_test.cmj test/gpr_4924_test.cmi test/gpr_4924_test.cmj test/gpr_4931.cmi test/gpr_4931.cmj test/gpr_4931_allow.cmi test/gpr_4931_allow.cmj test/gpr_5071_test.cmi test/gpr_5071_test.cmj test/gpr_5169_test.cmi test/gpr_5169_test.cmj test/gpr_5218_test.cmi test/gpr_5218_test.cmj test/gpr_5280_optimize_test.cmi test/gpr_5280_optimize_test.cmj test/gpr_5557.cmi test/gpr_5557.cmj test/gpr_5753.cmi test/gpr_5753.cmj test/gpr_658.cmi test/gpr_658.cmj test/gpr_7012_test.cmi test/gpr_7012_test.cmj test/gpr_858_test.cmi test/gpr_858_test.cmj test/gpr_858_unit2_test.cmi test/gpr_858_unit2_test.cmj test/gpr_904_test.cmi test/gpr_904_test.cmj test/gpr_974_test.cmi test/gpr_974_test.cmj test/gpr_977_test.cmi test/gpr_977_test.cmj test/gpr_return_type_unused_attribute.cmi test/gpr_return_type_unused_attribute.cmj test/gray_code_test.cmi test/gray_code_test.cmj test/guide_for_ext.cmi test/guide_for_ext.cmj test/hash_collision_test.cmi test/hash_collision_test.cmj test/hash_sugar_desugar.cmi test/hash_sugar_desugar.cmj test/hash_test.cmi test/hash_test.cmj test/hashtbl_test.cmi test/hashtbl_test.cmj test/hello.foo.cmi test/hello.foo.cmj test/hello_res.cmi test/hello_res.cmj test/ignore_test.cmi test/ignore_test.cmj test/ignore_uncurry_attribute.cmi test/ignore_uncurry_attribute.cmj test/import2.cmi test/import2.cmj test/import_external.cmi test/import_external.cmj test/import_side_effect.cmi test/import_side_effect.cmj test/import_side_effect_free.cmi test/import_side_effect_free.cmj test/include_side_effect.cmi test/include_side_effect.cmj test/include_side_effect_free.cmi test/include_side_effect_free.cmj test/incomplete_toplevel_test.cmi test/incomplete_toplevel_test.cmj test/infer_type_test.cmi test/infer_type_test.cmj test/inline_condition_with_pattern_matching.cmi test/inline_condition_with_pattern_matching.cmj test/inline_const.cmi test/inline_const.cmj test/inline_const_test.cmi test/inline_const_test.cmj test/inline_edge_cases.cmi test/inline_edge_cases.cmj test/inline_map2_test.cmi test/inline_map2_test.cmj test/inline_map_demo.cmi test/inline_map_demo.cmj test/inline_map_test.cmi test/inline_map_test.cmj test/inline_record_test.cmi test/inline_record_test.cmj test/inline_regression_test.cmi test/inline_regression_test.cmj test/inline_string_test.cmi test/inline_string_test.cmj test/inner_call.cmi test/inner_call.cmj test/inner_define.cmi test/inner_define.cmj test/inner_unused.cmi test/inner_unused.cmj test/installation_test.cmi test/installation_test.cmj test/int32_test.cmi test/int32_test.cmj test/int64_mul_div_test.cmi test/int64_mul_div_test.cmj test/int64_string_bench.cmi test/int64_string_bench.cmj test/int64_string_test.cmi test/int64_string_test.cmj test/int64_test.cmi test/int64_test.cmj test/int_hashtbl_test.cmi test/int_hashtbl_test.cmj test/int_map.cmi test/int_map.cmj test/int_overflow_test.cmi test/int_overflow_test.cmj test/int_poly_var.cmi test/int_poly_var.cmj test/int_switch_test.cmi test/int_switch_test.cmj test/internal_unused_test.cmi test/internal_unused_test.cmj test/io_test.cmi test/io_test.cmj test/js_array_test.cmi test/js_array_test.cmj test/js_bool_test.cmi test/js_bool_test.cmj test/js_cast_test.cmi test/js_cast_test.cmj test/js_date_test.cmi test/js_date_test.cmj test/js_dict_test.cmi test/js_dict_test.cmj test/js_exception_catch_test.cmi test/js_exception_catch_test.cmj test/js_float_test.cmi test/js_float_test.cmj test/js_global_test.cmi test/js_global_test.cmj test/js_int_test.cmi test/js_int_test.cmj test/js_json_test.cmi test/js_json_test.cmj test/js_math_test.cmi test/js_math_test.cmj test/js_null_test.cmi test/js_null_test.cmj test/js_null_undefined_test.cmi test/js_null_undefined_test.cmj test/js_nullable_test.cmi test/js_nullable_test.cmj test/js_obj_test.cmi test/js_obj_test.cmj test/js_option_test.cmi test/js_option_test.cmj test/js_re_test.cmi test/js_re_test.cmj test/js_string_test.cmi test/js_string_test.cmj test/js_undefined_test.cmi test/js_undefined_test.cmj test/js_val.cmi test/js_val.cmj test/jsoo_400_test.cmi test/jsoo_400_test.cmj test/jsoo_485_test.cmi test/jsoo_485_test.cmj test/jsxv4_newtype.cmi test/jsxv4_newtype.cmj test/keep_uncurry_attribute.cmi test/keep_uncurry_attribute.cmj test/key_word_property.cmi test/key_word_property.cmj test/key_word_property2.cmi test/key_word_property2.cmj test/key_word_property_plus_test.cmi test/key_word_property_plus_test.cmj test/label_uncurry.cmi test/label_uncurry.cmj test/large_integer_pat.cmi test/large_integer_pat.cmj test/large_record_duplication_test.cmi test/large_record_duplication_test.cmj test/largest_int_flow.cmi test/largest_int_flow.cmj test/lazy_demo.cmi test/lazy_demo.cmj test/lazy_test.cmi test/lazy_test.cmj test/lib_js_test.cmi test/lib_js_test.cmj test/libarg_test.cmi test/libarg_test.cmj test/libqueue_test.cmi test/libqueue_test.cmj test/limits_test.cmi test/limits_test.cmj test/list_stack.cmi test/list_stack.cmj test/list_test.cmi test/list_test.cmj test/local_exception_test.cmi test/local_exception_test.cmj test/loop_regression_test.cmi test/loop_regression_test.cmj test/map_find_test.cmi test/map_find_test.cmj test/map_test.cmi test/map_test.cmj test/mario_game.cmi test/mario_game.cmj test/meth_annotation.cmi test/meth_annotation.cmj test/method_name_test.cmi test/method_name_test.cmj test/method_string_name.cmi test/method_string_name.cmj test/minimal_test.cmi test/minimal_test.cmj test/miss_colon_test.cmi test/miss_colon_test.cmj test/mock_mt.cmi test/mock_mt.cmj test/module_alias_test.cmi test/module_alias_test.cmj test/module_as_class_ffi.cmi test/module_as_class_ffi.cmj test/module_as_function.cmi test/module_as_function.cmj test/module_missing_conversion.cmi test/module_missing_conversion.cmj test/module_parameter_test.cmi test/module_parameter_test.cmj test/module_splice_test.cmi test/module_splice_test.cmj test/more_poly_variant_test.cmi test/more_poly_variant_test.cmj test/more_uncurry.cmi test/more_uncurry.cmj test/mpr_6033_test.cmi test/mpr_6033_test.cmj test/mt.cmi test/mt.cmj test/mt_global.cmi test/mt_global.cmj test/mutable_obj_test.cmi test/mutable_obj_test.cmj test/mutable_uncurry_test.cmi test/mutable_uncurry_test.cmj test/mutual_non_recursive_type.cmi test/mutual_non_recursive_type.cmj test/name_mangle_test.cmi test/name_mangle_test.cmj test/nested_include.cmi test/nested_include.cmj test/nested_module_alias.cmi test/nested_module_alias.cmj test/nested_obj_literal.cmi test/nested_obj_literal.cmj test/nested_obj_test.cmi test/nested_obj_test.cmj test/nested_pattern_match_test.cmi test/nested_pattern_match_test.cmj test/noassert.cmi test/noassert.cmj test/node_assert.cmi test/node_assert.cmj test/node_path_test.cmi test/node_path_test.cmj test/node_test.cmi test/node_test.cmj test/node_test_util.cmi test/node_test_util.cmj test/number_lexer.cmi test/number_lexer.cmj test/obj_literal_ppx.cmi test/obj_literal_ppx.cmj test/obj_literal_ppx_test.cmi test/obj_literal_ppx_test.cmj test/obj_magic_test.cmi test/obj_magic_test.cmj test/obj_type_test.cmi test/obj_type_test.cmj test/ocaml_re_test.cmi test/ocaml_re_test.cmj test/of_string_test.cmi test/of_string_test.cmj test/offset.cmi test/offset.cmj test/omit_trailing_undefined_in_external_calls.cmi test/omit_trailing_undefined_in_external_calls.cmj test/option_encoding_test.cmi test/option_encoding_test.cmj test/option_repr_test.cmi test/option_repr_test.cmj test/optional_ffi_test.cmi test/optional_ffi_test.cmj test/optional_regression_test.cmi test/optional_regression_test.cmj test/pipe_send_readline.cmi test/pipe_send_readline.cmj test/pipe_syntax.cmi test/pipe_syntax.cmj test/poly_empty_array.cmi test/poly_empty_array.cmj test/poly_variant_test.cmi test/poly_variant_test.cmj test/polymorphic_raw_test.cmi test/polymorphic_raw_test.cmj test/polymorphism_test.cmi test/polymorphism_test.cmj test/polyvar_convert.cmi test/polyvar_convert.cmj test/polyvar_test.cmi test/polyvar_test.cmj test/ppx_apply_test.cmi test/ppx_apply_test.cmj test/pq_test.cmi test/pq_test.cmj test/pr6726.cmi test/pr6726.cmj test/prepend_data_ffi.cmi test/prepend_data_ffi.cmj test/primitive_reg_test.cmi test/primitive_reg_test.cmj test/print_alpha_test.cmi test/print_alpha_test.cmj test/queue_402.cmi test/queue_402.cmj test/queue_test.cmi test/queue_test.cmj test/random_test.cmi test/random_test.cmj test/raw_hash_tbl_bench.cmi test/raw_hash_tbl_bench.cmj test/raw_output_test.cmi test/raw_output_test.cmj test/raw_pure_test.cmi test/raw_pure_test.cmj test/rbset.cmi test/rbset.cmj test/react.cmi test/react.cmj test/reactDOMRe.cmi test/reactDOMRe.cmj test/reactDOMServerRe.cmi test/reactDOMServerRe.cmj test/reactEvent.cmi test/reactEvent.cmj test/reactTestUtils.cmi test/reactTestUtils.cmj test/reasonReact.cmi test/reasonReact.cmj test/reasonReactCompat.cmi test/reasonReactCompat.cmj test/reasonReactOptimizedCreateClass.cmi test/reasonReactOptimizedCreateClass.cmj test/reasonReactRouter.cmi test/reasonReactRouter.cmj test/rebind_module.cmi test/rebind_module.cmj test/rebind_module_test.cmi test/rebind_module_test.cmj test/rec_array_test.cmi test/rec_array_test.cmj test/rec_fun_test.cmi test/rec_fun_test.cmj test/rec_module_opt.cmi test/rec_module_opt.cmj test/rec_module_test.cmi test/rec_module_test.cmj test/recmodule.cmi test/recmodule.cmj test/record_debug_test.cmi test/record_debug_test.cmj test/record_extension_test.cmi test/record_extension_test.cmj test/record_name_test.cmi test/record_name_test.cmj test/record_regression.cmi test/record_regression.cmj test/record_type_spread.cmi test/record_type_spread.cmj test/record_with_test.cmi test/record_with_test.cmj test/recursive_module.cmi test/recursive_module.cmj test/recursive_module_test.cmi test/recursive_module_test.cmj test/recursive_react_component.cmi test/recursive_react_component.cmj test/recursive_records_test.cmi test/recursive_records_test.cmj test/recursive_unbound_module_test.cmi test/recursive_unbound_module_test.cmj test/regression_print.cmi test/regression_print.cmj test/relative_path.cmi test/relative_path.cmj test/res_debug.cmi test/res_debug.cmj test/return_check.cmi test/return_check.cmj test/runtime_encoding_test.cmi test/runtime_encoding_test.cmj test/set_annotation.cmi test/set_annotation.cmj test/set_gen.cmi test/set_gen.cmj test/sexp.cmi test/sexp.cmj test/sexpm.cmi test/sexpm.cmj test/sexpm_test.cmi test/sexpm_test.cmj test/side_effect.cmi test/side_effect.cmj test/side_effect2.cmi test/side_effect2.cmj test/side_effect_free.cmi test/side_effect_free.cmj test/simplify_lambda_632o.cmi test/simplify_lambda_632o.cmj test/single_module_alias.cmi test/single_module_alias.cmj test/singular_unit_test.cmi test/singular_unit_test.cmj test/small_inline_test.cmi test/small_inline_test.cmj test/splice_test.cmi test/splice_test.cmj test/stack_comp_test.cmi test/stack_comp_test.cmj test/stack_test.cmi test/stack_test.cmj test/stream_parser_test.cmi test/stream_parser_test.cmj test/string_bound_get_test.cmi test/string_bound_get_test.cmj test/string_constant_compare.cmi test/string_constant_compare.cmj test/string_get_set_test.cmi test/string_get_set_test.cmj test/string_runtime_test.cmi test/string_runtime_test.cmj test/string_set.cmi test/string_set.cmj test/string_set_test.cmi test/string_set_test.cmj test/string_test.cmi test/string_test.cmj test/string_unicode_test.cmi test/string_unicode_test.cmj test/stringmatch_test.cmi test/stringmatch_test.cmj test/submodule.cmi test/submodule.cmj test/submodule_call.cmi test/submodule_call.cmj test/switch_case_test.cmi test/switch_case_test.cmj test/switch_string.cmi test/switch_string.cmj test/tagged_template_test.cmi test/tagged_template_test.cmj test/tailcall_inline_test.cmi test/tailcall_inline_test.cmj test/template.cmi test/template.cmj test/test2.cmi test/test2.cmj test/test_alias.cmi test/test_alias.cmj test/test_ari.cmi test/test_ari.cmj test/test_array.cmi test/test_array.cmj test/test_array_append.cmi test/test_array_append.cmj test/test_array_primitive.cmi test/test_array_primitive.cmj test/test_bool_equal.cmi test/test_bool_equal.cmj test/test_bs_this.cmi test/test_bs_this.cmj test/test_bug.cmi test/test_bug.cmj test/test_bytes.cmi test/test_bytes.cmj test/test_case_opt_collision.cmi test/test_case_opt_collision.cmj test/test_case_set.cmi test/test_case_set.cmj test/test_char.cmi test/test_char.cmj test/test_closure.cmi test/test_closure.cmj test/test_common.cmi test/test_common.cmj test/test_const_elim.cmi test/test_const_elim.cmj test/test_const_propogate.cmi test/test_const_propogate.cmj test/test_cpp.cmi test/test_cpp.cmj test/test_cps.cmi test/test_cps.cmj test/test_demo.cmi test/test_demo.cmj test/test_dup_param.cmi test/test_dup_param.cmj test/test_eq.cmi test/test_eq.cmj test/test_exception.cmi test/test_exception.cmj test/test_exception_escape.cmi test/test_exception_escape.cmj test/test_export2.cmi test/test_export2.cmj test/test_external.cmi test/test_external.cmj test/test_external_unit.cmi test/test_external_unit.cmj test/test_ffi.cmi test/test_ffi.cmj test/test_fib.cmi test/test_fib.cmj test/test_filename.cmi test/test_filename.cmj test/test_for_loop.cmi test/test_for_loop.cmj test/test_for_map.cmi test/test_for_map.cmj test/test_for_map2.cmi test/test_for_map2.cmj test/test_functor_dead_code.cmi test/test_functor_dead_code.cmj test/test_generative_module.cmi test/test_generative_module.cmj test/test_global_print.cmi test/test_global_print.cmj test/test_google_closure.cmi test/test_google_closure.cmj test/test_include.cmi test/test_include.cmj test/test_incomplete.cmi test/test_incomplete.cmj test/test_incr_ref.cmi test/test_incr_ref.cmj test/test_int_map_find.cmi test/test_int_map_find.cmj test/test_is_js.cmi test/test_is_js.cmj test/test_js_ffi.cmi test/test_js_ffi.cmj test/test_let.cmi test/test_let.cmj test/test_list.cmi test/test_list.cmj test/test_literal.cmi test/test_literal.cmj test/test_literals.cmi test/test_literals.cmj test/test_match_exception.cmi test/test_match_exception.cmj test/test_mutliple.cmi test/test_mutliple.cmj test/test_nat64.cmi test/test_nat64.cmj test/test_nested_let.cmi test/test_nested_let.cmj test/test_nested_print.cmi test/test_nested_print.cmj test/test_non_export.cmi test/test_non_export.cmj test/test_nullary.cmi test/test_nullary.cmj test/test_obj.cmi test/test_obj.cmj test/test_order.cmi test/test_order.cmj test/test_order_tailcall.cmi test/test_order_tailcall.cmj test/test_other_exn.cmi test/test_other_exn.cmj test/test_per.cmi test/test_per.cmj test/test_pervasive.cmi test/test_pervasive.cmj test/test_pervasives2.cmi test/test_pervasives2.cmj test/test_pervasives3.cmi test/test_pervasives3.cmj test/test_primitive.cmi test/test_primitive.cmj test/test_ramification.cmi test/test_ramification.cmj test/test_react.cmi test/test_react.cmj test/test_react_case.cmi test/test_react_case.cmj test/test_regex.cmi test/test_regex.cmj test/test_runtime_encoding.cmi test/test_runtime_encoding.cmj test/test_scope.cmi test/test_scope.cmj test/test_seq.cmi test/test_seq.cmj test/test_set.cmi test/test_set.cmj test/test_side_effect_functor.cmi test/test_side_effect_functor.cmj test/test_simple_include.cmi test/test_simple_include.cmj test/test_simple_pattern_match.cmi test/test_simple_pattern_match.cmj test/test_simple_ref.cmi test/test_simple_ref.cmj test/test_simple_tailcall.cmi test/test_simple_tailcall.cmj test/test_small.cmi test/test_small.cmj test/test_stack.cmi test/test_stack.cmj test/test_static_catch_ident.cmi test/test_static_catch_ident.cmj test/test_string.cmi test/test_string.cmj test/test_string_case.cmi test/test_string_case.cmj test/test_string_const.cmi test/test_string_const.cmj test/test_string_map.cmi test/test_string_map.cmj test/test_string_switch.cmi test/test_string_switch.cmj test/test_switch.cmi test/test_switch.cmj test/test_trywith.cmi test/test_trywith.cmj test/test_tuple.cmi test/test_tuple.cmj test/test_tuple_destructring.cmi test/test_tuple_destructring.cmj test/test_type_based_arity.cmi test/test_type_based_arity.cmj test/test_u.cmi test/test_u.cmj test/test_unknown.cmi test/test_unknown.cmj test/test_unsafe_cmp.cmi test/test_unsafe_cmp.cmj test/test_unsafe_obj_ffi.cmi test/test_unsafe_obj_ffi.cmj test/test_unsafe_obj_ffi_ppx.cmi test/test_unsafe_obj_ffi_ppx.cmj test/test_while_closure.cmi test/test_while_closure.cmj test/test_while_side_effect.cmi test/test_while_side_effect.cmj test/test_zero_nullable.cmi test/test_zero_nullable.cmj test/then_mangle_test.cmi test/then_mangle_test.cmj test/ticker.cmi test/ticker.cmj test/to_string_test.cmi test/to_string_test.cmj test/topsort_test.cmi test/topsort_test.cmj test/tramp_fib.cmi test/tramp_fib.cmj test/tuple_alloc.cmi test/tuple_alloc.cmj test/type-coercion-free-vars.cmi test/type-coercion-free-vars.cmj test/type_disambiguate.cmi test/type_disambiguate.cmj test/typeof_test.cmi test/typeof_test.cmj test/unboxed_attribute.cmi test/unboxed_attribute.cmj test/unboxed_attribute_test.cmi test/unboxed_attribute_test.cmj test/unboxed_crash.cmi test/unboxed_crash.cmj test/unboxed_use_case.cmi test/unboxed_use_case.cmj test/uncurried_cast.cmi test/uncurried_cast.cmj test/uncurried_default.args.cmi test/uncurried_default.args.cmj test/uncurried_pipe.cmi test/uncurried_pipe.cmj test/uncurry_external_test.cmi test/uncurry_external_test.cmj test/uncurry_glob_test.cmi test/uncurry_glob_test.cmj test/uncurry_test.cmi test/uncurry_test.cmj test/undef_regression_test.cmi test/undef_regression_test.cmj test/unit_undefined_test.cmi test/unit_undefined_test.cmj test/unsafe_full_apply_primitive.cmi test/unsafe_full_apply_primitive.cmj test/unsafe_ppx_test.cmi test/unsafe_ppx_test.cmj test/update_record_test.cmi test/update_record_test.cmj test/variant.cmi test/variant.cmj test/variantsMatching.cmi test/variantsMatching.cmj test/webpack_config.cmi test/webpack_config.cmj +o test/AsInUncurriedExternals.cmi test/AsInUncurriedExternals.cmj : cc test/AsInUncurriedExternals.res | $bsc others runtime +o test/Coercion.cmi test/Coercion.cmj : cc test/Coercion.res | $bsc others runtime +o test/DerivingAccessorsCurried.cmi test/DerivingAccessorsCurried.cmj : cc test/DerivingAccessorsCurried.res | $bsc others runtime +o test/DerivingAccessorsUncurried.cmi test/DerivingAccessorsUncurried.cmj : cc test/DerivingAccessorsUncurried.res | $bsc others runtime +o test/DictInference.cmi test/DictInference.cmj : cc test/DictInference.res | $bsc others runtime +o test/DictTests.cmi test/DictTests.cmj : cc test/DictTests.res | $bsc others runtime +o test/DisambiguateOptionalFields.cmi test/DisambiguateOptionalFields.cmj : cc test/DisambiguateOptionalFields.res | $bsc others runtime +o test/DotDotDot.cmi test/DotDotDot.cmj : cc test/DotDotDot.res | $bsc others runtime +o test/EmptyRecord.cmi test/EmptyRecord.cmj : cc test/EmptyRecord.res | $bsc others runtime +o test/ExternalArity.cmi test/ExternalArity.cmj : cc test/ExternalArity.res | $bsc others runtime +o test/FFI.cmi test/FFI.cmj : cc test/FFI.res | $bsc others runtime +o test/Import.cmi test/Import.cmj : cc test/Import.res | $bsc others runtime +o test/ImportAttributes.cmi test/ImportAttributes.cmj : cc test/ImportAttributes.res | $bsc others runtime +o test/PartialApplicationNoRuntimeCurry.cmi test/PartialApplicationNoRuntimeCurry.cmj : cc test/PartialApplicationNoRuntimeCurry.res | $bsc others runtime +o test/RecordCoercion.cmi test/RecordCoercion.cmj : cc test/RecordCoercion.res | $bsc others runtime +o test/RecordOrObject.cmi test/RecordOrObject.cmj : cc test/RecordOrObject.res | $bsc others runtime +o test/SafePromises.cmi test/SafePromises.cmj : cc test/SafePromises.res | $bsc others runtime +o test/UncurriedAlways.cmi test/UncurriedAlways.cmj : cc test/UncurriedAlways.res | $bsc others runtime +o test/UncurriedExternals.cmi test/UncurriedExternals.cmj : cc test/UncurriedExternals.res | $bsc others runtime +o test/UncurriedPervasives.cmi test/UncurriedPervasives.cmj : cc test/UncurriedPervasives.res | $bsc others runtime +o test/UntaggedVariants.cmi test/UntaggedVariants.cmj : cc test/UntaggedVariants.res | $bsc others runtime +o test/VariantCoercion.cmi test/VariantCoercion.cmj : cc test/VariantCoercion.res | $bsc others runtime +o test/VariantPatternMatchingSpreads.cmi test/VariantPatternMatchingSpreads.cmj : cc test/VariantPatternMatchingSpreads.res | $bsc others runtime +o test/VariantPatternMatchingSpreadsWithPayloads.cmi test/VariantPatternMatchingSpreadsWithPayloads.cmj : cc test/VariantPatternMatchingSpreadsWithPayloads.res | $bsc others runtime +o test/VariantSpreads.cmi test/VariantSpreads.cmj : cc test/VariantSpreads.res | $bsc others runtime +o test/a.cmi test/a.cmj : cc test/a.res | test/test_order.cmj $bsc others runtime +o test/a_recursive_type.cmj : cc_cmi test/a_recursive_type.res | test/a_recursive_type.cmi $bsc others runtime +o test/a_recursive_type.cmi : cc test/a_recursive_type.resi | $bsc others runtime +o test/a_scope_bug.cmi test/a_scope_bug.cmj : cc test/a_scope_bug.res | $bsc others runtime +o test/abstract_type.cmj : cc_cmi test/abstract_type.res | test/abstract_type.cmi $bsc others runtime +o test/abstract_type.cmi : cc test/abstract_type.resi | test/mt.cmi $bsc others runtime +o test/adt_optimize_test.cmi test/adt_optimize_test.cmj : cc test/adt_optimize_test.res | $bsc others runtime +o test/alias_default_value_test.cmi test/alias_default_value_test.cmj : cc test/alias_default_value_test.res | test/react.cmj $bsc others runtime +o test/alias_test.cmj : cc_cmi test/alias_test.res | test/alias_test.cmi $bsc others runtime +o test/alias_test.cmi : cc test/alias_test.resi | $bsc others runtime +o test/and_or_tailcall_test.cmi test/and_or_tailcall_test.cmj : cc test/and_or_tailcall_test.res | test/mt.cmj $bsc others runtime +o test/ari_regress_test.cmj : cc_cmi test/ari_regress_test.res | test/ari_regress_test.cmi test/mt.cmj $bsc others runtime +o test/ari_regress_test.cmi : cc test/ari_regress_test.resi | $bsc others runtime +o test/arith_syntax.cmi test/arith_syntax.cmj : cc test/arith_syntax.res | $bsc others runtime +o test/arity.cmi test/arity.cmj : cc test/arity.res | $bsc others runtime +o test/arity_deopt.cmi test/arity_deopt.cmj : cc test/arity_deopt.res | test/mt.cmj $bsc others runtime +o test/arity_infer.cmi test/arity_infer.cmj : cc test/arity_infer.res | $bsc others runtime +o test/array_data_util.cmi test/array_data_util.cmj : cc test/array_data_util.res | $bsc others runtime +o test/array_safe_get.cmi test/array_safe_get.cmj : cc test/array_safe_get.res | $bsc others runtime +o test/array_subtle_test.cmi test/array_subtle_test.cmj : cc test/array_subtle_test.res | test/mt.cmj $bsc others runtime +o test/as_inline_record_test.cmi test/as_inline_record_test.cmj : cc test/as_inline_record_test.res | $bsc others runtime +o test/ast_abstract_test.cmi test/ast_abstract_test.cmj : cc test/ast_abstract_test.res | test/mt.cmj $bsc others runtime +o test/ast_mapper_unused_warning_test.cmi test/ast_mapper_unused_warning_test.cmj : cc test/ast_mapper_unused_warning_test.res | $bsc others runtime +o test/async_await.cmi test/async_await.cmj : cc test/async_await.res | $bsc others runtime +o test/async_inline.cmi test/async_inline.cmj : cc test/async_inline.res | $bsc others runtime +o test/async_inside_loop.cmi test/async_inside_loop.cmj : cc test/async_inside_loop.res | $bsc others runtime +o test/attr_test.cmi test/attr_test.cmj : cc test/attr_test.res | $bsc others runtime +o test/b.cmi test/b.cmj : cc test/b.res | $bsc others runtime +o test/bal_set_mini.cmi test/bal_set_mini.cmj : cc test/bal_set_mini.res | $bsc others runtime +o test/bb.cmi test/bb.cmj : cc test/bb.res | $bsc others runtime +o test/bdd.cmi test/bdd.cmj : cc test/bdd.res | $bsc others runtime +o test/belt_float_ntest.cmi test/belt_float_ntest.cmj : cc test/belt_float_ntest.res | test/node_test.cmj test/node_test_util.cmj $bsc others runtime +o test/belt_hashmap_ntest.cmi test/belt_hashmap_ntest.cmj : cc test/belt_hashmap_ntest.res | test/array_data_util.cmj test/node_test.cmj test/node_test_util.cmj $bsc others runtime +o test/belt_hashset_int_ntest.cmi test/belt_hashset_int_ntest.cmj : cc test/belt_hashset_int_ntest.res | test/array_data_util.cmj test/node_test.cmj test/node_test_util.cmj $bsc others runtime +o test/belt_int_ntest.cmi test/belt_int_ntest.cmj : cc test/belt_int_ntest.res | test/node_test.cmj test/node_test_util.cmj $bsc others runtime +o test/belt_internal_test.cmi test/belt_internal_test.cmj : cc test/belt_internal_test.res | $bsc others runtime +o test/belt_list_ntest.cmi test/belt_list_ntest.cmj : cc test/belt_list_ntest.res | test/node_test.cmj test/node_test_util.cmj $bsc others runtime +o test/belt_mapint_ntest.cmi test/belt_mapint_ntest.cmj : cc test/belt_mapint_ntest.res | test/node_test.cmj test/node_test_util.cmj $bsc others runtime +o test/belt_result_alias_test.cmi test/belt_result_alias_test.cmj : cc test/belt_result_alias_test.res | $bsc others runtime +o test/belt_sortarray_ntest.cmi test/belt_sortarray_ntest.cmj : cc test/belt_sortarray_ntest.res | test/array_data_util.cmj test/node_test.cmj test/node_test_util.cmj $bsc others runtime +o test/bench.cmi test/bench.cmj : cc test/bench.res | $bsc others runtime +o test/big_enum.cmi test/big_enum.cmj : cc test/big_enum.res | $bsc others runtime +o test/big_polyvar_test.cmi test/big_polyvar_test.cmj : cc test/big_polyvar_test.res | $bsc others runtime +o test/bigint_test.cmi test/bigint_test.cmj : cc test/bigint_test.res | test/mt.cmj test/mt_global.cmj $bsc others runtime +o test/block_alias_test.cmi test/block_alias_test.cmj : cc test/block_alias_test.res | test/mt.cmj $bsc others runtime +o test/boolean_test.cmi test/boolean_test.cmj : cc test/boolean_test.res | test/mt.cmj test/test_bool_equal.cmj $bsc others runtime +o test/bs_abstract_test.cmj : cc_cmi test/bs_abstract_test.res | test/bs_abstract_test.cmi $bsc others runtime +o test/bs_abstract_test.cmi : cc test/bs_abstract_test.resi | $bsc others runtime +o test/bs_array_test.cmi test/bs_array_test.cmj : cc test/bs_array_test.res | test/mt.cmj $bsc others runtime +o test/bs_auto_uncurry.cmi test/bs_auto_uncurry.cmj : cc test/bs_auto_uncurry.res | $bsc others runtime +o test/bs_auto_uncurry_test.cmi test/bs_auto_uncurry_test.cmj : cc test/bs_auto_uncurry_test.res | test/mt.cmj $bsc others runtime +o test/bs_ignore_effect.cmi test/bs_ignore_effect.cmj : cc test/bs_ignore_effect.res | test/mt.cmj $bsc others runtime +o test/bs_ignore_test.cmi test/bs_ignore_test.cmj : cc test/bs_ignore_test.res | $bsc others runtime +o test/bs_map_set_dict_test.cmi test/bs_map_set_dict_test.cmj : cc test/bs_map_set_dict_test.res | test/array_data_util.cmj test/mt.cmj $bsc others runtime +o test/bs_map_test.cmi test/bs_map_test.cmj : cc test/bs_map_test.res | test/mt.cmj $bsc others runtime +o test/bs_min_max_test.cmi test/bs_min_max_test.cmj : cc test/bs_min_max_test.res | test/mt.cmj $bsc others runtime +o test/bs_mutable_set_test.cmi test/bs_mutable_set_test.cmj : cc test/bs_mutable_set_test.res | test/array_data_util.cmj test/mt.cmj $bsc others runtime +o test/bs_poly_map_test.cmi test/bs_poly_map_test.cmj : cc test/bs_poly_map_test.res | test/array_data_util.cmj test/mt.cmj $bsc others runtime +o test/bs_poly_mutable_map_test.cmi test/bs_poly_mutable_map_test.cmj : cc test/bs_poly_mutable_map_test.res | test/array_data_util.cmj test/mt.cmj $bsc others runtime +o test/bs_poly_mutable_set_test.cmi test/bs_poly_mutable_set_test.cmj : cc test/bs_poly_mutable_set_test.res | test/array_data_util.cmj test/mt.cmj $bsc others runtime +o test/bs_poly_set_test.cmi test/bs_poly_set_test.cmj : cc test/bs_poly_set_test.res | test/array_data_util.cmj test/mt.cmj $bsc others runtime +o test/bs_qualified.cmi test/bs_qualified.cmj : cc test/bs_qualified.res | $bsc others runtime +o test/bs_queue_test.cmi test/bs_queue_test.cmj : cc test/bs_queue_test.res | test/mt.cmj $bsc others runtime +o test/bs_rest_test.cmi test/bs_rest_test.cmj : cc test/bs_rest_test.res | $bsc others runtime +o test/bs_set_int_test.cmi test/bs_set_int_test.cmj : cc test/bs_set_int_test.res | test/array_data_util.cmj test/mt.cmj $bsc others runtime +o test/bs_splice_partial.cmi test/bs_splice_partial.cmj : cc test/bs_splice_partial.res | $bsc others runtime +o test/bs_stack_test.cmi test/bs_stack_test.cmj : cc test/bs_stack_test.res | test/mt.cmj $bsc others runtime +o test/bs_string_test.cmi test/bs_string_test.cmj : cc test/bs_string_test.res | test/mt.cmj $bsc others runtime +o test/bs_unwrap_test.cmi test/bs_unwrap_test.cmj : cc test/bs_unwrap_test.res | $bsc others runtime +o test/caml_compare_bigint_test.cmi test/caml_compare_bigint_test.cmj : cc test/caml_compare_bigint_test.res | test/mt.cmj $bsc others runtime +o test/caml_compare_test.cmi test/caml_compare_test.cmj : cc test/caml_compare_test.res | test/mt.cmj $bsc others runtime +o test/chain_code_test.cmi test/chain_code_test.cmj : cc test/chain_code_test.res | test/mt.cmj $bsc others runtime +o test/chn_test.cmi test/chn_test.cmj : cc test/chn_test.res | test/mt.cmj $bsc others runtime +o test/class_type_ffi_test.cmi test/class_type_ffi_test.cmj : cc test/class_type_ffi_test.res | $bsc others runtime +o test/coercion_module_alias_test.cmi test/coercion_module_alias_test.cmj : cc test/coercion_module_alias_test.res | $bsc others runtime +o test/compare_test.cmi test/compare_test.cmj : cc test/compare_test.res | $bsc others runtime +o test/complete_parmatch_test.cmi test/complete_parmatch_test.cmj : cc test/complete_parmatch_test.res | $bsc others runtime +o test/complex_while_loop.cmi test/complex_while_loop.cmj : cc test/complex_while_loop.res | $bsc others runtime +o test/condition_compilation_test.cmi test/condition_compilation_test.cmj : cc test/condition_compilation_test.res | test/mt.cmj $bsc others runtime +o test/config1_test.cmi test/config1_test.cmj : cc test/config1_test.res | $bsc others runtime +o test/console_log_test.cmi test/console_log_test.cmj : cc test/console_log_test.res | $bsc others runtime +o test/const_block_test.cmj : cc_cmi test/const_block_test.res | test/const_block_test.cmi test/mt.cmj $bsc others runtime +o test/const_block_test.cmi : cc test/const_block_test.resi | $bsc others runtime +o test/const_defs.cmi test/const_defs.cmj : cc test/const_defs.res | $bsc others runtime +o test/const_defs_test.cmi test/const_defs_test.cmj : cc test/const_defs_test.res | test/const_defs.cmj $bsc others runtime +o test/const_test.cmi test/const_test.cmj : cc test/const_test.res | $bsc others runtime +o test/cont_int_fold_test.cmi test/cont_int_fold_test.cmj : cc test/cont_int_fold_test.res | $bsc others runtime +o test/cps_test.cmi test/cps_test.cmj : cc test/cps_test.res | test/mt.cmj $bsc others runtime +o test/cross_module_inline_test.cmi test/cross_module_inline_test.cmj : cc test/cross_module_inline_test.res | test/test_char.cmj $bsc others runtime +o test/custom_error_test.cmi test/custom_error_test.cmj : cc test/custom_error_test.res | $bsc others runtime +o test/debug_keep_test.cmi test/debug_keep_test.cmj : cc test/debug_keep_test.res | $bsc others runtime +o test/debug_mode_value.cmi test/debug_mode_value.cmj : cc test/debug_mode_value.res | $bsc others runtime +o test/debug_tmp.cmi test/debug_tmp.cmj : cc test/debug_tmp.res | $bsc others runtime +o test/debugger_test.cmi test/debugger_test.cmj : cc test/debugger_test.res | $bsc others runtime +o test/default_export_test.cmi test/default_export_test.cmj : cc test/default_export_test.res | $bsc others runtime +o test/defunctor_make_test.cmi test/defunctor_make_test.cmj : cc test/defunctor_make_test.res | $bsc others runtime +o test/demo_int_map.cmj : cc_cmi test/demo_int_map.res | test/demo_int_map.cmi $bsc others runtime +o test/demo_int_map.cmi : cc test/demo_int_map.resi | $bsc others runtime +o test/demo_page.cmi test/demo_page.cmj : cc test/demo_page.res | $bsc others runtime +o test/demo_pipe.cmi test/demo_pipe.cmj : cc test/demo_pipe.res | $bsc others runtime +o test/derive_projector_test.cmj : cc_cmi test/derive_projector_test.res | test/derive_projector_test.cmi $bsc others runtime +o test/derive_projector_test.cmi : cc test/derive_projector_test.resi | $bsc others runtime +o test/directives.cmi test/directives.cmj : cc test/directives.res | $bsc others runtime +o test/div_by_zero_test.cmi test/div_by_zero_test.cmj : cc test/div_by_zero_test.res | test/mt.cmj $bsc others runtime +o test/dollar_escape_test.cmi test/dollar_escape_test.cmj : cc test/dollar_escape_test.res | test/mt.cmj $bsc others runtime +o test/earger_curry_test.cmi test/earger_curry_test.cmj : cc test/earger_curry_test.res | test/mt.cmj $bsc others runtime +o test/effect.cmi test/effect.cmj : cc test/effect.res | $bsc others runtime +o test/epsilon_test.cmi test/epsilon_test.cmj : cc test/epsilon_test.res | test/mt.cmj $bsc others runtime +o test/equal_box_test.cmi test/equal_box_test.cmj : cc test/equal_box_test.res | test/mt.cmj $bsc others runtime +o test/equal_exception_test.cmi test/equal_exception_test.cmj : cc test/equal_exception_test.res | test/mt.cmj $bsc others runtime +o test/equal_test.cmi test/equal_test.cmj : cc test/equal_test.res | $bsc others runtime +o test/es6_export.cmi test/es6_export.cmj : cc test/es6_export.res | $bsc others runtime +o test/es6_import.cmi test/es6_import.cmj : cc test/es6_import.res | test/es6_export.cmj $bsc others runtime +o test/es6_module_test.cmi test/es6_module_test.cmj : cc test/es6_module_test.res | test/mt.cmj $bsc others runtime +o test/escape_esmodule.cmi test/escape_esmodule.cmj : cc test/escape_esmodule.res | $bsc others runtime +o test/esmodule_ref.cmi test/esmodule_ref.cmj : cc test/esmodule_ref.res | test/escape_esmodule.cmj $bsc others runtime +o test/event_ffi.cmi test/event_ffi.cmj : cc test/event_ffi.res | $bsc others runtime +o test/exception_alias.cmi test/exception_alias.cmj : cc test/exception_alias.res | $bsc others runtime +o test/exception_raise_test.cmi test/exception_raise_test.cmj : cc test/exception_raise_test.res | test/mt.cmj $bsc others runtime +o test/exception_rebound_err_test.cmi test/exception_rebound_err_test.cmj : cc test/exception_rebound_err_test.res | test/mt.cmj $bsc others runtime +o test/exception_value_test.cmi test/exception_value_test.cmj : cc test/exception_value_test.res | $bsc others runtime +o test/exotic_labels_test.cmi test/exotic_labels_test.cmj : cc test/exotic_labels_test.res | $bsc others runtime +o test/exponentiation_precedence_test.cmi test/exponentiation_precedence_test.cmj : cc test/exponentiation_precedence_test.res | $bsc others runtime +o test/export_keyword.cmi test/export_keyword.cmj : cc test/export_keyword.res | $bsc others runtime +o test/ext_array_test.cmi test/ext_array_test.cmj : cc test/ext_array_test.res | $bsc others runtime +o test/ext_pervasives_test.cmj : cc_cmi test/ext_pervasives_test.res | test/ext_pervasives_test.cmi $bsc others runtime +o test/ext_pervasives_test.cmi : cc test/ext_pervasives_test.resi | $bsc others runtime +o test/extensible_variant_test.cmi test/extensible_variant_test.cmj : cc test/extensible_variant_test.res | test/mt.cmj $bsc others runtime +o test/external_ppx.cmi test/external_ppx.cmj : cc test/external_ppx.res | $bsc others runtime +o test/external_ppx2.cmi test/external_ppx2.cmj : cc test/external_ppx2.res | $bsc others runtime +o test/ffi_arity_test.cmi test/ffi_arity_test.cmj : cc test/ffi_arity_test.res | test/mt.cmj $bsc others runtime +o test/ffi_array_test.cmi test/ffi_array_test.cmj : cc test/ffi_array_test.res | test/mt.cmj $bsc others runtime +o test/ffi_js_test.cmi test/ffi_js_test.cmj : cc test/ffi_js_test.res | test/mt.cmj $bsc others runtime +o test/ffi_splice_test.cmi test/ffi_splice_test.cmj : cc test/ffi_splice_test.res | test/mt.cmj $bsc others runtime +o test/ffi_test.cmi test/ffi_test.cmj : cc test/ffi_test.res | $bsc others runtime +o test/fib.cmi test/fib.cmj : cc test/fib.res | $bsc others runtime +o test/flattern_order_test.cmi test/flattern_order_test.cmj : cc test/flattern_order_test.res | $bsc others runtime +o test/flexible_array_test.cmi test/flexible_array_test.cmj : cc test/flexible_array_test.res | $bsc others runtime +o test/float_array.cmi test/float_array.cmj : cc test/float_array.res | $bsc others runtime +o test/float_record.cmj : cc_cmi test/float_record.res | test/float_record.cmi $bsc others runtime +o test/float_record.cmi : cc test/float_record.resi | $bsc others runtime +o test/float_test.cmi test/float_test.cmj : cc test/float_test.res | test/mt.cmj test/mt_global.cmj $bsc others runtime +o test/for_loop_test.cmi test/for_loop_test.cmj : cc test/for_loop_test.res | test/mt.cmj $bsc others runtime +o test/for_side_effect_test.cmi test/for_side_effect_test.cmj : cc test/for_side_effect_test.res | test/mt.cmj $bsc others runtime +o test/format_regression.cmi test/format_regression.cmj : cc test/format_regression.res | $bsc others runtime +o test/fun_pattern_match.cmi test/fun_pattern_match.cmj : cc test/fun_pattern_match.res | $bsc others runtime +o test/function_directives.cmi test/function_directives.cmj : cc test/function_directives.res | $bsc others runtime +o test/function_directives_no_inline.cmi test/function_directives_no_inline.cmj : cc test/function_directives_no_inline.res | $bsc others runtime +o test/functor_app_test.cmi test/functor_app_test.cmj : cc test/functor_app_test.res | test/functor_def.cmj test/functor_inst.cmj test/mt.cmj $bsc others runtime +o test/functor_def.cmi test/functor_def.cmj : cc test/functor_def.res | $bsc others runtime +o test/functor_ffi.cmi test/functor_ffi.cmj : cc test/functor_ffi.res | $bsc others runtime +o test/functor_inst.cmi test/functor_inst.cmj : cc test/functor_inst.res | $bsc others runtime +o test/functors.cmi test/functors.cmj : cc test/functors.res | $bsc others runtime +o test/gbk.cmi test/gbk.cmj : cc test/gbk.res | $bsc others runtime +o test/gentTypeReTest.cmi test/gentTypeReTest.cmj : cc test/gentTypeReTest.res | $bsc others runtime +o test/global_exception_regression_test.cmi test/global_exception_regression_test.cmj : cc test/global_exception_regression_test.res | test/mt.cmj $bsc others runtime +o test/global_mangles.cmi test/global_mangles.cmj : cc test/global_mangles.res | $bsc others runtime +o test/global_module_alias_test.cmi test/global_module_alias_test.cmj : cc test/global_module_alias_test.res | test/mt.cmj $bsc others runtime +o test/google_closure_test.cmi test/google_closure_test.cmj : cc test/google_closure_test.res | test/mt.cmj test/test_google_closure.cmj $bsc others runtime +o test/gpr496_test.cmi test/gpr496_test.cmj : cc test/gpr496_test.res | test/mt.cmj $bsc others runtime +o test/gpr_1072.cmi test/gpr_1072.cmj : cc test/gpr_1072.res | $bsc others runtime +o test/gpr_1072_reg.cmi test/gpr_1072_reg.cmj : cc test/gpr_1072_reg.res | $bsc others runtime +o test/gpr_1150.cmi test/gpr_1150.cmj : cc test/gpr_1150.res | $bsc others runtime +o test/gpr_1170.cmi test/gpr_1170.cmj : cc test/gpr_1170.res | $bsc others runtime +o test/gpr_1240_missing_unbox.cmi test/gpr_1240_missing_unbox.cmj : cc test/gpr_1240_missing_unbox.res | $bsc others runtime +o test/gpr_1245_test.cmi test/gpr_1245_test.cmj : cc test/gpr_1245_test.res | $bsc others runtime +o test/gpr_1268.cmi test/gpr_1268.cmj : cc test/gpr_1268.res | $bsc others runtime +o test/gpr_1409_test.cmi test/gpr_1409_test.cmj : cc test/gpr_1409_test.res | test/mt.cmj test/string_set.cmj $bsc others runtime +o test/gpr_1423_app_test.cmi test/gpr_1423_app_test.cmj : cc test/gpr_1423_app_test.res | test/gpr_1423_nav.cmj test/mt.cmj $bsc others runtime +o test/gpr_1423_nav.cmi test/gpr_1423_nav.cmj : cc test/gpr_1423_nav.res | $bsc others runtime +o test/gpr_1438.cmi test/gpr_1438.cmj : cc test/gpr_1438.res | $bsc others runtime +o test/gpr_1481.cmi test/gpr_1481.cmj : cc test/gpr_1481.res | $bsc others runtime +o test/gpr_1484.cmi test/gpr_1484.cmj : cc test/gpr_1484.res | $bsc others runtime +o test/gpr_1539_test.cmi test/gpr_1539_test.cmj : cc test/gpr_1539_test.res | $bsc others runtime +o test/gpr_1658_test.cmi test/gpr_1658_test.cmj : cc test/gpr_1658_test.res | test/mt.cmj $bsc others runtime +o test/gpr_1667_test.cmi test/gpr_1667_test.cmj : cc test/gpr_1667_test.res | test/mt.cmj $bsc others runtime +o test/gpr_1692_test.cmi test/gpr_1692_test.cmj : cc test/gpr_1692_test.res | $bsc others runtime +o test/gpr_1698_test.cmi test/gpr_1698_test.cmj : cc test/gpr_1698_test.res | $bsc others runtime +o test/gpr_1701_test.cmi test/gpr_1701_test.cmj : cc test/gpr_1701_test.res | $bsc others runtime +o test/gpr_1716_test.cmi test/gpr_1716_test.cmj : cc test/gpr_1716_test.res | test/mt.cmj $bsc others runtime +o test/gpr_1717_test.cmi test/gpr_1717_test.cmj : cc test/gpr_1717_test.res | $bsc others runtime +o test/gpr_1728_test.cmi test/gpr_1728_test.cmj : cc test/gpr_1728_test.res | test/mt.cmj $bsc others runtime +o test/gpr_1749_test.cmi test/gpr_1749_test.cmj : cc test/gpr_1749_test.res | test/mt.cmj $bsc others runtime +o test/gpr_1759_test.cmi test/gpr_1759_test.cmj : cc test/gpr_1759_test.res | $bsc others runtime +o test/gpr_1760_test.cmi test/gpr_1760_test.cmj : cc test/gpr_1760_test.res | test/mt.cmj $bsc others runtime +o test/gpr_1762_test.cmi test/gpr_1762_test.cmj : cc test/gpr_1762_test.res | test/mt.cmj $bsc others runtime +o test/gpr_1817_test.cmi test/gpr_1817_test.cmj : cc test/gpr_1817_test.res | test/mt.cmj $bsc others runtime +o test/gpr_1822_test.cmi test/gpr_1822_test.cmj : cc test/gpr_1822_test.res | test/mt.cmj $bsc others runtime +o test/gpr_1891_test.cmi test/gpr_1891_test.cmj : cc test/gpr_1891_test.res | $bsc others runtime +o test/gpr_1943_test.cmi test/gpr_1943_test.cmj : cc test/gpr_1943_test.res | test/mt.cmj $bsc others runtime +o test/gpr_1946_test.cmi test/gpr_1946_test.cmj : cc test/gpr_1946_test.res | test/mt.cmj $bsc others runtime +o test/gpr_2316_test.cmi test/gpr_2316_test.cmj : cc test/gpr_2316_test.res | test/mt.cmj $bsc others runtime +o test/gpr_2352_test.cmi test/gpr_2352_test.cmj : cc test/gpr_2352_test.res | $bsc others runtime +o test/gpr_2413_test.cmi test/gpr_2413_test.cmj : cc test/gpr_2413_test.res | $bsc others runtime +o test/gpr_2474.cmi test/gpr_2474.cmj : cc test/gpr_2474.res | $bsc others runtime +o test/gpr_2487.cmi test/gpr_2487.cmj : cc test/gpr_2487.res | $bsc others runtime +o test/gpr_2503_test.cmi test/gpr_2503_test.cmj : cc test/gpr_2503_test.res | test/mt.cmj $bsc others runtime +o test/gpr_2608_test.cmi test/gpr_2608_test.cmj : cc test/gpr_2608_test.res | test/mt.cmj $bsc others runtime +o test/gpr_2614_test.cmi test/gpr_2614_test.cmj : cc test/gpr_2614_test.res | $bsc others runtime +o test/gpr_2633_test.cmi test/gpr_2633_test.cmj : cc test/gpr_2633_test.res | $bsc others runtime +o test/gpr_2642_test.cmi test/gpr_2642_test.cmj : cc test/gpr_2642_test.res | $bsc others runtime +o test/gpr_2682_test.cmi test/gpr_2682_test.cmj : cc test/gpr_2682_test.res | $bsc others runtime +o test/gpr_2700_test.cmi test/gpr_2700_test.cmj : cc test/gpr_2700_test.res | $bsc others runtime +o test/gpr_2731_test.cmi test/gpr_2731_test.cmj : cc test/gpr_2731_test.res | $bsc others runtime +o test/gpr_2789_test.cmi test/gpr_2789_test.cmj : cc test/gpr_2789_test.res | test/mt.cmj $bsc others runtime +o test/gpr_2931_test.cmi test/gpr_2931_test.cmj : cc test/gpr_2931_test.res | test/mt.cmj $bsc others runtime +o test/gpr_3142_test.cmi test/gpr_3142_test.cmj : cc test/gpr_3142_test.res | test/mt.cmj $bsc others runtime +o test/gpr_3154_test.cmi test/gpr_3154_test.cmj : cc test/gpr_3154_test.res | test/mt.cmj $bsc others runtime +o test/gpr_3209_test.cmi test/gpr_3209_test.cmj : cc test/gpr_3209_test.res | $bsc others runtime +o test/gpr_3492_test.cmi test/gpr_3492_test.cmj : cc test/gpr_3492_test.res | test/mt.cmj $bsc others runtime +o test/gpr_3519_jsx_test.cmi test/gpr_3519_jsx_test.cmj : cc test/gpr_3519_jsx_test.res | $bsc others runtime +o test/gpr_3519_test.cmi test/gpr_3519_test.cmj : cc test/gpr_3519_test.res | $bsc others runtime +o test/gpr_3536_test.cmi test/gpr_3536_test.cmj : cc test/gpr_3536_test.res | test/mt.cmj $bsc others runtime +o test/gpr_3546_test.cmi test/gpr_3546_test.cmj : cc test/gpr_3546_test.res | $bsc others runtime +o test/gpr_3548_test.cmi test/gpr_3548_test.cmj : cc test/gpr_3548_test.res | $bsc others runtime +o test/gpr_3549_test.cmi test/gpr_3549_test.cmj : cc test/gpr_3549_test.res | test/mt.cmj $bsc others runtime +o test/gpr_3566_drive_test.cmi test/gpr_3566_drive_test.cmj : cc test/gpr_3566_drive_test.res | test/gpr_3566_test.cmj test/mt.cmj $bsc others runtime +o test/gpr_3566_test.cmi test/gpr_3566_test.cmj : cc test/gpr_3566_test.res | $bsc others runtime +o test/gpr_3595_test.cmi test/gpr_3595_test.cmj : cc test/gpr_3595_test.res | test/mt.cmj $bsc others runtime +o test/gpr_3609_test.cmi test/gpr_3609_test.cmj : cc test/gpr_3609_test.res | $bsc others runtime +o test/gpr_3697_test.cmi test/gpr_3697_test.cmj : cc test/gpr_3697_test.res | $bsc others runtime +o test/gpr_373_test.cmi test/gpr_373_test.cmj : cc test/gpr_373_test.res | $bsc others runtime +o test/gpr_3770_test.cmi test/gpr_3770_test.cmj : cc test/gpr_3770_test.res | $bsc others runtime +o test/gpr_3852_alias.cmi test/gpr_3852_alias.cmj : cc test/gpr_3852_alias.res | test/gpr_3852_effect.cmj $bsc others runtime +o test/gpr_3852_alias_reify.cmj : cc_cmi test/gpr_3852_alias_reify.res | test/gpr_3852_alias_reify.cmi test/gpr_3852_effect.cmj $bsc others runtime +o test/gpr_3852_alias_reify.cmi : cc test/gpr_3852_alias_reify.resi | $bsc others runtime +o test/gpr_3852_effect.cmi test/gpr_3852_effect.cmj : cc test/gpr_3852_effect.res | $bsc others runtime +o test/gpr_3865.cmi test/gpr_3865.cmj : cc test/gpr_3865.res | test/gpr_3865_bar.cmj test/gpr_3865_foo.cmj $bsc others runtime +o test/gpr_3865_bar.cmi test/gpr_3865_bar.cmj : cc test/gpr_3865_bar.res | $bsc others runtime +o test/gpr_3865_foo.cmi test/gpr_3865_foo.cmj : cc test/gpr_3865_foo.res | $bsc others runtime +o test/gpr_3875_test.cmi test/gpr_3875_test.cmj : cc test/gpr_3875_test.res | test/mt.cmj $bsc others runtime +o test/gpr_3877_test.cmi test/gpr_3877_test.cmj : cc test/gpr_3877_test.res | $bsc others runtime +o test/gpr_3895_test.cmi test/gpr_3895_test.cmj : cc test/gpr_3895_test.res | $bsc others runtime +o test/gpr_3897_test.cmi test/gpr_3897_test.cmj : cc test/gpr_3897_test.res | $bsc others runtime +o test/gpr_3931_test.cmi test/gpr_3931_test.cmj : cc test/gpr_3931_test.res | $bsc others runtime +o test/gpr_3980_test.cmi test/gpr_3980_test.cmj : cc test/gpr_3980_test.res | $bsc others runtime +o test/gpr_4025_test.cmi test/gpr_4025_test.cmj : cc test/gpr_4025_test.res | $bsc others runtime +o test/gpr_4069_test.cmi test/gpr_4069_test.cmj : cc test/gpr_4069_test.res | $bsc others runtime +o test/gpr_4265_test.cmi test/gpr_4265_test.cmj : cc test/gpr_4265_test.res | test/mt.cmj $bsc others runtime +o test/gpr_4274_test.cmi test/gpr_4274_test.cmj : cc test/gpr_4274_test.res | $bsc others runtime +o test/gpr_4280_test.cmi test/gpr_4280_test.cmj : cc test/gpr_4280_test.res | test/mt.cmj $bsc others runtime +o test/gpr_4407_test.cmi test/gpr_4407_test.cmj : cc test/gpr_4407_test.res | test/debug_mode_value.cmj test/mt.cmj $bsc others runtime +o test/gpr_441.cmi test/gpr_441.cmj : cc test/gpr_441.res | $bsc others runtime +o test/gpr_4442_test.cmi test/gpr_4442_test.cmj : cc test/gpr_4442_test.res | test/mt.cmj $bsc others runtime +o test/gpr_4491_test.cmi test/gpr_4491_test.cmj : cc test/gpr_4491_test.res | $bsc others runtime +o test/gpr_4494_test.cmi test/gpr_4494_test.cmj : cc test/gpr_4494_test.res | $bsc others runtime +o test/gpr_4519_test.cmi test/gpr_4519_test.cmj : cc test/gpr_4519_test.res | test/mt.cmj $bsc others runtime +o test/gpr_459_test.cmi test/gpr_459_test.cmj : cc test/gpr_459_test.res | test/mt.cmj $bsc others runtime +o test/gpr_4632.cmi test/gpr_4632.cmj : cc test/gpr_4632.res | $bsc others runtime +o test/gpr_4639_test.cmi test/gpr_4639_test.cmj : cc test/gpr_4639_test.res | $bsc others runtime +o test/gpr_4900_test.cmi test/gpr_4900_test.cmj : cc test/gpr_4900_test.res | test/mt.cmj $bsc others runtime +o test/gpr_4924_test.cmi test/gpr_4924_test.cmj : cc test/gpr_4924_test.res | test/mt.cmj $bsc others runtime +o test/gpr_4931.cmi test/gpr_4931.cmj : cc test/gpr_4931.res | $bsc others runtime +o test/gpr_4931_allow.cmi test/gpr_4931_allow.cmj : cc test/gpr_4931_allow.res | $bsc others runtime +o test/gpr_5071_test.cmi test/gpr_5071_test.cmj : cc test/gpr_5071_test.res | test/react.cmj $bsc others runtime +o test/gpr_5169_test.cmi test/gpr_5169_test.cmj : cc test/gpr_5169_test.res | $bsc others runtime +o test/gpr_5218_test.cmi test/gpr_5218_test.cmj : cc test/gpr_5218_test.res | test/mt.cmj $bsc others runtime +o test/gpr_5280_optimize_test.cmi test/gpr_5280_optimize_test.cmj : cc test/gpr_5280_optimize_test.res | $bsc others runtime +o test/gpr_5557.cmi test/gpr_5557.cmj : cc test/gpr_5557.res | $bsc others runtime +o test/gpr_5753.cmi test/gpr_5753.cmj : cc test/gpr_5753.res | $bsc others runtime +o test/gpr_658.cmi test/gpr_658.cmj : cc test/gpr_658.res | $bsc others runtime +o test/gpr_7012_test.cmi test/gpr_7012_test.cmj : cc test/gpr_7012_test.res | $bsc others runtime +o test/gpr_858_test.cmi test/gpr_858_test.cmj : cc test/gpr_858_test.res | $bsc others runtime +o test/gpr_858_unit2_test.cmi test/gpr_858_unit2_test.cmj : cc test/gpr_858_unit2_test.res | $bsc others runtime +o test/gpr_904_test.cmi test/gpr_904_test.cmj : cc test/gpr_904_test.res | test/mt.cmj $bsc others runtime +o test/gpr_974_test.cmi test/gpr_974_test.cmj : cc test/gpr_974_test.res | $bsc others runtime +o test/gpr_977_test.cmi test/gpr_977_test.cmj : cc test/gpr_977_test.res | test/mt.cmj $bsc others runtime +o test/gpr_return_type_unused_attribute.cmi test/gpr_return_type_unused_attribute.cmj : cc test/gpr_return_type_unused_attribute.res | $bsc others runtime +o test/gray_code_test.cmi test/gray_code_test.cmj : cc test/gray_code_test.res | $bsc others runtime +o test/guide_for_ext.cmi test/guide_for_ext.cmj : cc test/guide_for_ext.res | $bsc others runtime +o test/hash_collision_test.cmi test/hash_collision_test.cmj : cc test/hash_collision_test.res | test/mt.cmj $bsc others runtime +o test/hash_sugar_desugar.cmj : cc_cmi test/hash_sugar_desugar.res | test/hash_sugar_desugar.cmi $bsc others runtime +o test/hash_sugar_desugar.cmi : cc test/hash_sugar_desugar.resi | $bsc others runtime +o test/hash_test.cmi test/hash_test.cmj : cc test/hash_test.res | test/mt.cmj test/mt_global.cmj $bsc others runtime +o test/hello.foo.cmi test/hello.foo.cmj : cc test/hello.foo.res | $bsc others runtime +o test/hello_res.cmj : cc_cmi test/hello_res.res | test/hello_res.cmi $bsc others runtime +o test/hello_res.cmi : cc test/hello_res.resi | $bsc others runtime +o test/ignore_test.cmi test/ignore_test.cmj : cc test/ignore_test.res | test/mt.cmj $bsc others runtime +o test/ignore_uncurry_attribute.cmi test/ignore_uncurry_attribute.cmj : cc test/ignore_uncurry_attribute.res | $bsc others runtime +o test/import2.cmi test/import2.cmj : cc test/import2.res | test/import_external.cmj $bsc others runtime +o test/import_external.cmi test/import_external.cmj : cc test/import_external.res | $bsc others runtime +o test/import_side_effect.cmi test/import_side_effect.cmj : cc test/import_side_effect.res | test/side_effect.cmj test/side_effect2.cmj $bsc others runtime +o test/import_side_effect_free.cmi test/import_side_effect_free.cmj : cc test/import_side_effect_free.res | test/side_effect_free.cmj $bsc others runtime +o test/include_side_effect.cmi test/include_side_effect.cmj : cc test/include_side_effect.res | test/side_effect.cmj $bsc others runtime +o test/include_side_effect_free.cmi test/include_side_effect_free.cmj : cc test/include_side_effect_free.res | test/side_effect_free.cmj $bsc others runtime +o test/incomplete_toplevel_test.cmi test/incomplete_toplevel_test.cmj : cc test/incomplete_toplevel_test.res | $bsc others runtime +o test/infer_type_test.cmj : cc_cmi test/infer_type_test.res | test/infer_type_test.cmi $bsc others runtime +o test/infer_type_test.cmi : cc test/infer_type_test.resi | $bsc others runtime +o test/inline_condition_with_pattern_matching.cmi test/inline_condition_with_pattern_matching.cmj : cc test/inline_condition_with_pattern_matching.res | $bsc others runtime +o test/inline_const.cmj : cc_cmi test/inline_const.res | test/inline_const.cmi $bsc others runtime +o test/inline_const.cmi : cc test/inline_const.resi | $bsc others runtime +o test/inline_const_test.cmi test/inline_const_test.cmj : cc test/inline_const_test.res | test/inline_const.cmj test/mt.cmj $bsc others runtime +o test/inline_edge_cases.cmj : cc_cmi test/inline_edge_cases.res | test/inline_edge_cases.cmi $bsc others runtime +o test/inline_edge_cases.cmi : cc test/inline_edge_cases.resi | $bsc others runtime +o test/inline_map2_test.cmi test/inline_map2_test.cmj : cc test/inline_map2_test.res | test/mt.cmj $bsc others runtime +o test/inline_map_demo.cmi test/inline_map_demo.cmj : cc test/inline_map_demo.res | test/mt.cmj $bsc others runtime +o test/inline_map_test.cmj : cc_cmi test/inline_map_test.res | test/inline_map_test.cmi test/mt.cmj $bsc others runtime +o test/inline_map_test.cmi : cc test/inline_map_test.resi | $bsc others runtime +o test/inline_record_test.cmi test/inline_record_test.cmj : cc test/inline_record_test.res | test/mt.cmj $bsc others runtime +o test/inline_regression_test.cmi test/inline_regression_test.cmj : cc test/inline_regression_test.res | test/mt.cmj $bsc others runtime +o test/inline_string_test.cmi test/inline_string_test.cmj : cc test/inline_string_test.res | $bsc others runtime +o test/inner_call.cmi test/inner_call.cmj : cc test/inner_call.res | test/inner_define.cmj $bsc others runtime +o test/inner_define.cmj : cc_cmi test/inner_define.res | test/inner_define.cmi $bsc others runtime +o test/inner_define.cmi : cc test/inner_define.resi | $bsc others runtime +o test/inner_unused.cmi test/inner_unused.cmj : cc test/inner_unused.res | $bsc others runtime +o test/installation_test.cmi test/installation_test.cmj : cc test/installation_test.res | test/mt.cmj $bsc others runtime +o test/int_map.cmi test/int_map.cmj : cc test/int_map.res | $bsc others runtime +o test/int_overflow_test.cmi test/int_overflow_test.cmj : cc test/int_overflow_test.res | test/mt.cmj $bsc others runtime +o test/int_poly_var.cmi test/int_poly_var.cmj : cc test/int_poly_var.res | test/mt.cmj test/test2.cmj $bsc others runtime +o test/int_switch_test.cmi test/int_switch_test.cmj : cc test/int_switch_test.res | test/mt.cmj $bsc others runtime +o test/internal_unused_test.cmi test/internal_unused_test.cmj : cc test/internal_unused_test.res | $bsc others runtime +o test/js_array_test.cmi test/js_array_test.cmj : cc test/js_array_test.res | test/mt.cmj $bsc others runtime +o test/js_bool_test.cmi test/js_bool_test.cmj : cc test/js_bool_test.res | test/mt.cmj $bsc others runtime +o test/js_cast_test.cmi test/js_cast_test.cmj : cc test/js_cast_test.res | test/mt.cmj $bsc others runtime +o test/js_date_test.cmi test/js_date_test.cmj : cc test/js_date_test.res | test/mt.cmj $bsc others runtime +o test/js_dict_test.cmi test/js_dict_test.cmj : cc test/js_dict_test.res | test/mt.cmj $bsc others runtime +o test/js_exception_catch_test.cmi test/js_exception_catch_test.cmj : cc test/js_exception_catch_test.res | test/mt.cmj $bsc others runtime +o test/js_float_test.cmi test/js_float_test.cmj : cc test/js_float_test.res | test/mt.cmj $bsc others runtime +o test/js_global_test.cmi test/js_global_test.cmj : cc test/js_global_test.res | test/mt.cmj $bsc others runtime +o test/js_int_test.cmi test/js_int_test.cmj : cc test/js_int_test.res | test/mt.cmj $bsc others runtime +o test/js_json_test.cmi test/js_json_test.cmj : cc test/js_json_test.res | test/mt.cmj $bsc others runtime +o test/js_math_test.cmi test/js_math_test.cmj : cc test/js_math_test.res | test/mt.cmj $bsc others runtime +o test/js_null_test.cmi test/js_null_test.cmj : cc test/js_null_test.res | test/mt.cmj $bsc others runtime +o test/js_null_undefined_test.cmi test/js_null_undefined_test.cmj : cc test/js_null_undefined_test.res | test/mt.cmj $bsc others runtime +o test/js_nullable_test.cmi test/js_nullable_test.cmj : cc test/js_nullable_test.res | test/mt.cmj $bsc others runtime +o test/js_obj_test.cmi test/js_obj_test.cmj : cc test/js_obj_test.res | test/mt.cmj $bsc others runtime +o test/js_option_test.cmi test/js_option_test.cmj : cc test/js_option_test.res | test/mt.cmj $bsc others runtime +o test/js_re_test.cmi test/js_re_test.cmj : cc test/js_re_test.res | test/mt.cmj $bsc others runtime +o test/js_string_test.cmi test/js_string_test.cmj : cc test/js_string_test.res | test/mt.cmj $bsc others runtime +o test/js_undefined_test.cmi test/js_undefined_test.cmj : cc test/js_undefined_test.res | test/mt.cmj $bsc others runtime +o test/js_val.cmi test/js_val.cmj : cc test/js_val.res | $bsc others runtime +o test/jsoo_400_test.cmi test/jsoo_400_test.cmj : cc test/jsoo_400_test.res | test/mt.cmj $bsc others runtime +o test/jsoo_485_test.cmi test/jsoo_485_test.cmj : cc test/jsoo_485_test.res | $bsc others runtime +o test/jsxv4_newtype.cmi test/jsxv4_newtype.cmj : cc test/jsxv4_newtype.res | test/react.cmj $bsc others runtime +o test/keep_uncurry_attribute.cmi test/keep_uncurry_attribute.cmj : cc test/keep_uncurry_attribute.res | $bsc others runtime +o test/key_word_property.cmi test/key_word_property.cmj : cc test/key_word_property.res | $bsc others runtime +o test/key_word_property2.cmi test/key_word_property2.cmj : cc test/key_word_property2.res | test/export_keyword.cmj $bsc others runtime +o test/key_word_property_plus_test.cmi test/key_word_property_plus_test.cmj : cc test/key_word_property_plus_test.res | test/global_mangles.cmj test/mt.cmj $bsc others runtime +o test/label_uncurry.cmi test/label_uncurry.cmj : cc test/label_uncurry.res | $bsc others runtime +o test/large_integer_pat.cmi test/large_integer_pat.cmj : cc test/large_integer_pat.res | $bsc others runtime +o test/large_record_duplication_test.cmi test/large_record_duplication_test.cmj : cc test/large_record_duplication_test.res | test/mt.cmj $bsc others runtime +o test/largest_int_flow.cmi test/largest_int_flow.cmj : cc test/largest_int_flow.res | $bsc others runtime +o test/lazy_demo.cmi test/lazy_demo.cmj : cc test/lazy_demo.res | $bsc others runtime +o test/lazy_test.cmi test/lazy_test.cmj : cc test/lazy_test.res | test/mt.cmj $bsc others runtime +o test/lib_js_test.cmi test/lib_js_test.cmj : cc test/lib_js_test.res | test/mt.cmj $bsc others runtime +o test/limits_test.cmi test/limits_test.cmj : cc test/limits_test.res | test/mt.cmj $bsc others runtime +o test/list_test.cmi test/list_test.cmj : cc test/list_test.res | test/mt.cmj $bsc others runtime +o test/local_exception_test.cmi test/local_exception_test.cmj : cc test/local_exception_test.res | $bsc others runtime +o test/loop_regression_test.cmi test/loop_regression_test.cmj : cc test/loop_regression_test.res | test/mt.cmj $bsc others runtime +o test/map_find_test.cmi test/map_find_test.cmj : cc test/map_find_test.res | test/mt.cmj $bsc others runtime +o test/mario_game.cmi test/mario_game.cmj : cc test/mario_game.res | $bsc others runtime +o test/meth_annotation.cmi test/meth_annotation.cmj : cc test/meth_annotation.res | $bsc others runtime +o test/method_name_test.cmi test/method_name_test.cmj : cc test/method_name_test.res | test/mt.cmj $bsc others runtime +o test/method_string_name.cmi test/method_string_name.cmj : cc test/method_string_name.res | $bsc others runtime +o test/minimal_test.cmi test/minimal_test.cmj : cc test/minimal_test.res | $bsc others runtime +o test/miss_colon_test.cmi test/miss_colon_test.cmj : cc test/miss_colon_test.res | $bsc others runtime +o test/mock_mt.cmi test/mock_mt.cmj : cc test/mock_mt.res | test/mt.cmj $bsc others runtime +o test/module_alias_test.cmi test/module_alias_test.cmj : cc test/module_alias_test.res | test/ext_pervasives_test.cmj test/mt.cmj $bsc others runtime +o test/module_as_class_ffi.cmi test/module_as_class_ffi.cmj : cc test/module_as_class_ffi.res | $bsc others runtime +o test/module_as_function.cmi test/module_as_function.cmj : cc test/module_as_function.res | $bsc others runtime +o test/module_missing_conversion.cmi test/module_missing_conversion.cmj : cc test/module_missing_conversion.res | $bsc others runtime +o test/module_parameter_test.cmi test/module_parameter_test.cmj : cc test/module_parameter_test.res | test/mt.cmj $bsc others runtime +o test/module_splice_test.cmi test/module_splice_test.cmj : cc test/module_splice_test.res | test/mt.cmj $bsc others runtime +o test/more_poly_variant_test.cmi test/more_poly_variant_test.cmj : cc test/more_poly_variant_test.res | $bsc others runtime +o test/more_uncurry.cmi test/more_uncurry.cmj : cc test/more_uncurry.res | $bsc others runtime +o test/mpr_6033_test.cmi test/mpr_6033_test.cmj : cc test/mpr_6033_test.res | test/mt.cmj $bsc others runtime +o test/mt.cmj : cc_cmi test/mt.res | test/mt.cmi $bsc others runtime +o test/mt.cmi : cc test/mt.resi | $bsc others runtime +o test/mt_global.cmj : cc_cmi test/mt_global.res | test/mt.cmj test/mt_global.cmi $bsc others runtime +o test/mt_global.cmi : cc test/mt_global.resi | test/mt.cmi $bsc others runtime +o test/mutable_obj_test.cmi test/mutable_obj_test.cmj : cc test/mutable_obj_test.res | $bsc others runtime +o test/mutable_uncurry_test.cmi test/mutable_uncurry_test.cmj : cc test/mutable_uncurry_test.res | test/mt.cmj $bsc others runtime +o test/mutual_non_recursive_type.cmi test/mutual_non_recursive_type.cmj : cc test/mutual_non_recursive_type.res | $bsc others runtime +o test/name_mangle_test.cmi test/name_mangle_test.cmj : cc test/name_mangle_test.res | test/mt.cmj $bsc others runtime +o test/nested_include.cmi test/nested_include.cmj : cc test/nested_include.res | $bsc others runtime +o test/nested_module_alias.cmi test/nested_module_alias.cmj : cc test/nested_module_alias.res | $bsc others runtime +o test/nested_obj_literal.cmi test/nested_obj_literal.cmj : cc test/nested_obj_literal.res | $bsc others runtime +o test/nested_obj_test.cmi test/nested_obj_test.cmj : cc test/nested_obj_test.res | $bsc others runtime +o test/nested_pattern_match_test.cmi test/nested_pattern_match_test.cmj : cc test/nested_pattern_match_test.res | $bsc others runtime +o test/noassert.cmi test/noassert.cmj : cc test/noassert.res | $bsc others runtime +o test/node_assert.cmi test/node_assert.cmj : cc test/node_assert.res | $bsc others runtime +o test/node_path_test.cmi test/node_path_test.cmj : cc test/node_path_test.res | $bsc others runtime +o test/node_test.cmi test/node_test.cmj : cc test/node_test.res | $bsc others runtime +o test/node_test_util.cmi test/node_test_util.cmj : cc test/node_test_util.res | test/node_assert.cmj $bsc others runtime +o test/obj_literal_ppx.cmi test/obj_literal_ppx.cmj : cc test/obj_literal_ppx.res | $bsc others runtime +o test/obj_literal_ppx_test.cmi test/obj_literal_ppx_test.cmj : cc test/obj_literal_ppx_test.res | $bsc others runtime +o test/obj_magic_test.cmi test/obj_magic_test.cmj : cc test/obj_magic_test.res | test/mt.cmj $bsc others runtime +o test/obj_type_test.cmi test/obj_type_test.cmj : cc test/obj_type_test.res | $bsc others runtime +o test/offset.cmi test/offset.cmj : cc test/offset.res | $bsc others runtime +o test/omit_trailing_undefined_in_external_calls.cmi test/omit_trailing_undefined_in_external_calls.cmj : cc test/omit_trailing_undefined_in_external_calls.res | $bsc others runtime +o test/option_encoding_test.cmi test/option_encoding_test.cmj : cc test/option_encoding_test.res | $bsc others runtime +o test/option_repr_test.cmi test/option_repr_test.cmj : cc test/option_repr_test.res | test/mt.cmj $bsc others runtime +o test/optional_ffi_test.cmi test/optional_ffi_test.cmj : cc test/optional_ffi_test.res | test/mt.cmj $bsc others runtime +o test/optional_regression_test.cmi test/optional_regression_test.cmj : cc test/optional_regression_test.res | test/mt.cmj $bsc others runtime +o test/pipe_send_readline.cmi test/pipe_send_readline.cmj : cc test/pipe_send_readline.res | $bsc others runtime +o test/pipe_syntax.cmi test/pipe_syntax.cmj : cc test/pipe_syntax.res | $bsc others runtime +o test/poly_empty_array.cmi test/poly_empty_array.cmj : cc test/poly_empty_array.res | $bsc others runtime +o test/poly_variant_test.cmj : cc_cmi test/poly_variant_test.res | test/mt.cmj test/poly_variant_test.cmi $bsc others runtime +o test/poly_variant_test.cmi : cc test/poly_variant_test.resi | $bsc others runtime +o test/polymorphic_raw_test.cmi test/polymorphic_raw_test.cmj : cc test/polymorphic_raw_test.res | test/mt.cmj $bsc others runtime +o test/polymorphism_test.cmj : cc_cmi test/polymorphism_test.res | test/polymorphism_test.cmi $bsc others runtime +o test/polymorphism_test.cmi : cc test/polymorphism_test.resi | $bsc others runtime +o test/polyvar_convert.cmi test/polyvar_convert.cmj : cc test/polyvar_convert.res | $bsc others runtime +o test/polyvar_test.cmi test/polyvar_test.cmj : cc test/polyvar_test.res | $bsc others runtime +o test/ppx_apply_test.cmi test/ppx_apply_test.cmj : cc test/ppx_apply_test.res | test/mt.cmj $bsc others runtime +o test/pq_test.cmi test/pq_test.cmj : cc test/pq_test.res | $bsc others runtime +o test/pr6726.cmi test/pr6726.cmj : cc test/pr6726.res | $bsc others runtime +o test/prepend_data_ffi.cmi test/prepend_data_ffi.cmj : cc test/prepend_data_ffi.res | $bsc others runtime +o test/print_alpha_test.cmi test/print_alpha_test.cmj : cc test/print_alpha_test.res | test/mt.cmj $bsc others runtime +o test/queue_402.cmi test/queue_402.cmj : cc test/queue_402.res | $bsc others runtime +o test/raw_output_test.cmi test/raw_output_test.cmj : cc test/raw_output_test.res | $bsc others runtime +o test/raw_pure_test.cmi test/raw_pure_test.cmj : cc test/raw_pure_test.res | $bsc others runtime +o test/rbset.cmi test/rbset.cmj : cc test/rbset.res | $bsc others runtime +o test/react.cmi test/react.cmj : cc test/react.res | $bsc others runtime +o test/reactDOMRe.cmi test/reactDOMRe.cmj : cc test/reactDOMRe.res | test/react.cmj test/reactEvent.cmj test/reasonReact.cmj $bsc others runtime +o test/reactDOMServerRe.cmi test/reactDOMServerRe.cmj : cc test/reactDOMServerRe.res | test/react.cmj $bsc others runtime +o test/reactEvent.cmj : cc_cmi test/reactEvent.res | test/reactEvent.cmi $bsc others runtime +o test/reactEvent.cmi : cc test/reactEvent.resi | $bsc others runtime +o test/reactTestUtils.cmj : cc_cmi test/reactTestUtils.res | test/react.cmj test/reactTestUtils.cmi $bsc others runtime +o test/reactTestUtils.cmi : cc test/reactTestUtils.resi | test/react.cmi $bsc others runtime +o test/reasonReact.cmj : cc_cmi test/reasonReact.res | test/react.cmj test/reasonReact.cmi test/reasonReactRouter.cmj $bsc others runtime +o test/reasonReact.cmi : cc test/reasonReact.resi | test/react.cmi test/reasonReactRouter.cmi $bsc others runtime +o test/reasonReactCompat.cmj : cc_cmi test/reasonReactCompat.res | test/react.cmj test/reasonReact.cmj test/reasonReactCompat.cmi $bsc others runtime +o test/reasonReactCompat.cmi : cc test/reasonReactCompat.resi | test/react.cmi test/reasonReact.cmi $bsc others runtime +o test/reasonReactOptimizedCreateClass.cmi test/reasonReactOptimizedCreateClass.cmj : cc test/reasonReactOptimizedCreateClass.res | $bsc others runtime +o test/reasonReactRouter.cmj : cc_cmi test/reasonReactRouter.res | test/react.cmj test/reasonReactRouter.cmi $bsc others runtime +o test/reasonReactRouter.cmi : cc test/reasonReactRouter.resi | $bsc others runtime +o test/rebind_module.cmi test/rebind_module.cmj : cc test/rebind_module.res | $bsc others runtime +o test/rebind_module_test.cmi test/rebind_module_test.cmj : cc test/rebind_module_test.res | test/rebind_module.cmj $bsc others runtime +o test/rec_array_test.cmi test/rec_array_test.cmj : cc test/rec_array_test.res | $bsc others runtime +o test/rec_fun_test.cmi test/rec_fun_test.cmj : cc test/rec_fun_test.res | test/mt.cmj $bsc others runtime +o test/rec_module_opt.cmi test/rec_module_opt.cmj : cc test/rec_module_opt.res | $bsc others runtime +o test/rec_module_test.cmi test/rec_module_test.cmj : cc test/rec_module_test.res | test/mt.cmj $bsc others runtime +o test/recmodule.cmi test/recmodule.cmj : cc test/recmodule.res | $bsc others runtime +o test/record_debug_test.cmi test/record_debug_test.cmj : cc test/record_debug_test.res | test/mt.cmj $bsc others runtime +o test/record_extension_test.cmi test/record_extension_test.cmj : cc test/record_extension_test.res | test/mt.cmj $bsc others runtime +o test/record_name_test.cmi test/record_name_test.cmj : cc test/record_name_test.res | $bsc others runtime +o test/record_regression.cmi test/record_regression.cmj : cc test/record_regression.res | $bsc others runtime +o test/record_type_spread.cmi test/record_type_spread.cmj : cc test/record_type_spread.res | $bsc others runtime +o test/record_with_test.cmi test/record_with_test.cmj : cc test/record_with_test.res | test/mt.cmj $bsc others runtime +o test/recursive_module.cmi test/recursive_module.cmj : cc test/recursive_module.res | test/mt.cmj $bsc others runtime +o test/recursive_module_test.cmi test/recursive_module_test.cmj : cc test/recursive_module_test.res | test/mt.cmj $bsc others runtime +o test/recursive_react_component.cmi test/recursive_react_component.cmj : cc test/recursive_react_component.res | test/react.cmj $bsc others runtime +o test/recursive_records_test.cmi test/recursive_records_test.cmj : cc test/recursive_records_test.res | test/mt.cmj $bsc others runtime +o test/recursive_unbound_module_test.cmi test/recursive_unbound_module_test.cmj : cc test/recursive_unbound_module_test.res | $bsc others runtime +o test/regression_print.cmi test/regression_print.cmj : cc test/regression_print.res | $bsc others runtime +o test/relative_path.cmi test/relative_path.cmj : cc test/relative_path.res | $bsc others runtime +o test/res_debug.cmi test/res_debug.cmj : cc test/res_debug.res | $bsc others runtime +o test/return_check.cmi test/return_check.cmj : cc test/return_check.res | $bsc others runtime +o test/runtime_encoding_test.cmi test/runtime_encoding_test.cmj : cc test/runtime_encoding_test.res | $bsc others runtime +o test/set_annotation.cmi test/set_annotation.cmj : cc test/set_annotation.res | $bsc others runtime +o test/set_gen.cmi test/set_gen.cmj : cc test/set_gen.res | $bsc others runtime +o test/side_effect.cmi test/side_effect.cmj : cc test/side_effect.res | $bsc others runtime +o test/side_effect2.cmi test/side_effect2.cmj : cc test/side_effect2.res | $bsc others runtime +o test/side_effect_free.cmi test/side_effect_free.cmj : cc test/side_effect_free.res | $bsc others runtime +o test/simplify_lambda_632o.cmi test/simplify_lambda_632o.cmj : cc test/simplify_lambda_632o.res | $bsc others runtime +o test/singular_unit_test.cmi test/singular_unit_test.cmj : cc test/singular_unit_test.res | $bsc others runtime +o test/small_inline_test.cmi test/small_inline_test.cmj : cc test/small_inline_test.res | $bsc others runtime +o test/splice_test.cmi test/splice_test.cmj : cc test/splice_test.res | test/mt.cmj $bsc others runtime +o test/string_bound_get_test.cmi test/string_bound_get_test.cmj : cc test/string_bound_get_test.res | $bsc others runtime +o test/string_constant_compare.cmi test/string_constant_compare.cmj : cc test/string_constant_compare.res | $bsc others runtime +o test/string_set.cmi test/string_set.cmj : cc test/string_set.res | test/set_gen.cmj $bsc others runtime +o test/string_set_test.cmi test/string_set_test.cmj : cc test/string_set_test.res | test/mt.cmj test/string_set.cmj $bsc others runtime +o test/string_unicode_test.cmi test/string_unicode_test.cmj : cc test/string_unicode_test.res | test/mt.cmj $bsc others runtime +o test/stringmatch_test.cmi test/stringmatch_test.cmj : cc test/stringmatch_test.res | $bsc others runtime +o test/submodule.cmi test/submodule.cmj : cc test/submodule.res | $bsc others runtime +o test/submodule_call.cmi test/submodule_call.cmj : cc test/submodule_call.res | test/submodule.cmj $bsc others runtime +o test/switch_case_test.cmi test/switch_case_test.cmj : cc test/switch_case_test.res | test/mt.cmj $bsc others runtime +o test/switch_string.cmi test/switch_string.cmj : cc test/switch_string.res | $bsc others runtime +o test/tagged_template_test.cmi test/tagged_template_test.cmj : cc test/tagged_template_test.res | test/mt.cmj $bsc others runtime +o test/tailcall_inline_test.cmi test/tailcall_inline_test.cmj : cc test/tailcall_inline_test.res | test/mt.cmj $bsc others runtime +o test/template.cmi test/template.cmj : cc test/template.res | $bsc others runtime +o test/test2.cmi test/test2.cmj : cc test/test2.res | $bsc others runtime +o test/test_ari.cmi test/test_ari.cmj : cc test/test_ari.res | $bsc others runtime +o test/test_array.cmi test/test_array.cmj : cc test/test_array.res | $bsc others runtime +o test/test_array_append.cmi test/test_array_append.cmj : cc test/test_array_append.res | $bsc others runtime +o test/test_bool_equal.cmi test/test_bool_equal.cmj : cc test/test_bool_equal.res | $bsc others runtime +o test/test_bs_this.cmi test/test_bs_this.cmj : cc test/test_bs_this.res | $bsc others runtime +o test/test_case_opt_collision.cmi test/test_case_opt_collision.cmj : cc test/test_case_opt_collision.res | test/mt.cmj $bsc others runtime +o test/test_case_set.cmi test/test_case_set.cmj : cc test/test_case_set.res | $bsc others runtime +o test/test_char.cmi test/test_char.cmj : cc test/test_char.res | $bsc others runtime +o test/test_closure.cmi test/test_closure.cmj : cc test/test_closure.res | $bsc others runtime +o test/test_common.cmi test/test_common.cmj : cc test/test_common.res | $bsc others runtime +o test/test_const_elim.cmi test/test_const_elim.cmj : cc test/test_const_elim.res | $bsc others runtime +o test/test_const_propogate.cmi test/test_const_propogate.cmj : cc test/test_const_propogate.res | $bsc others runtime +o test/test_cpp.cmi test/test_cpp.cmj : cc test/test_cpp.res | $bsc others runtime +o test/test_cps.cmi test/test_cps.cmj : cc test/test_cps.res | $bsc others runtime +o test/test_demo.cmi test/test_demo.cmj : cc test/test_demo.res | $bsc others runtime +o test/test_dup_param.cmi test/test_dup_param.cmj : cc test/test_dup_param.res | $bsc others runtime +o test/test_eq.cmi test/test_eq.cmj : cc test/test_eq.res | $bsc others runtime +o test/test_exception.cmi test/test_exception.cmj : cc test/test_exception.res | test/test_common.cmj $bsc others runtime +o test/test_exception_escape.cmi test/test_exception_escape.cmj : cc test/test_exception_escape.res | $bsc others runtime +o test/test_export2.cmi test/test_export2.cmj : cc test/test_export2.res | $bsc others runtime +o test/test_external.cmi test/test_external.cmj : cc test/test_external.res | $bsc others runtime +o test/test_external_unit.cmi test/test_external_unit.cmj : cc test/test_external_unit.res | $bsc others runtime +o test/test_ffi.cmi test/test_ffi.cmj : cc test/test_ffi.res | $bsc others runtime +o test/test_fib.cmi test/test_fib.cmj : cc test/test_fib.res | $bsc others runtime +o test/test_for_loop.cmi test/test_for_loop.cmj : cc test/test_for_loop.res | $bsc others runtime +o test/test_for_map.cmi test/test_for_map.cmj : cc test/test_for_map.res | $bsc others runtime +o test/test_for_map2.cmi test/test_for_map2.cmj : cc test/test_for_map2.res | $bsc others runtime +o test/test_functor_dead_code.cmi test/test_functor_dead_code.cmj : cc test/test_functor_dead_code.res | $bsc others runtime +o test/test_generative_module.cmi test/test_generative_module.cmj : cc test/test_generative_module.res | $bsc others runtime +o test/test_google_closure.cmi test/test_google_closure.cmj : cc test/test_google_closure.res | $bsc others runtime +o test/test_include.cmi test/test_include.cmj : cc test/test_include.res | test/test_order.cmj $bsc others runtime +o test/test_incomplete.cmi test/test_incomplete.cmj : cc test/test_incomplete.res | $bsc others runtime +o test/test_incr_ref.cmi test/test_incr_ref.cmj : cc test/test_incr_ref.res | $bsc others runtime +o test/test_int_map_find.cmi test/test_int_map_find.cmj : cc test/test_int_map_find.res | $bsc others runtime +o test/test_is_js.cmi test/test_is_js.cmj : cc test/test_is_js.res | test/mt.cmj $bsc others runtime +o test/test_js_ffi.cmi test/test_js_ffi.cmj : cc test/test_js_ffi.res | test/test_order.cmj $bsc others runtime +o test/test_let.cmi test/test_let.cmj : cc test/test_let.res | $bsc others runtime +o test/test_list.cmi test/test_list.cmj : cc test/test_list.res | $bsc others runtime +o test/test_literal.cmi test/test_literal.cmj : cc test/test_literal.res | $bsc others runtime +o test/test_literals.cmi test/test_literals.cmj : cc test/test_literals.res | $bsc others runtime +o test/test_match_exception.cmi test/test_match_exception.cmj : cc test/test_match_exception.res | $bsc others runtime +o test/test_nested_let.cmi test/test_nested_let.cmj : cc test/test_nested_let.res | $bsc others runtime +o test/test_nested_print.cmi test/test_nested_print.cmj : cc test/test_nested_print.res | $bsc others runtime +o test/test_non_export.cmi test/test_non_export.cmj : cc test/test_non_export.res | test/test_order.cmj $bsc others runtime +o test/test_nullary.cmi test/test_nullary.cmj : cc test/test_nullary.res | $bsc others runtime +o test/test_obj.cmi test/test_obj.cmj : cc test/test_obj.res | $bsc others runtime +o test/test_order.cmi test/test_order.cmj : cc test/test_order.res | $bsc others runtime +o test/test_order_tailcall.cmi test/test_order_tailcall.cmj : cc test/test_order_tailcall.res | $bsc others runtime +o test/test_other_exn.cmi test/test_other_exn.cmj : cc test/test_other_exn.res | $bsc others runtime +o test/test_per.cmi test/test_per.cmj : cc test/test_per.res | $bsc others runtime +o test/test_pervasive.cmi test/test_pervasive.cmj : cc test/test_pervasive.res | $bsc others runtime +o test/test_pervasives3.cmi test/test_pervasives3.cmj : cc test/test_pervasives3.res | $bsc others runtime +o test/test_primitive.cmi test/test_primitive.cmj : cc test/test_primitive.res | $bsc others runtime +o test/test_ramification.cmi test/test_ramification.cmj : cc test/test_ramification.res | $bsc others runtime +o test/test_react.cmi test/test_react.cmj : cc test/test_react.res | $bsc others runtime +o test/test_react_case.cmi test/test_react_case.cmj : cc test/test_react_case.res | $bsc others runtime +o test/test_regex.cmi test/test_regex.cmj : cc test/test_regex.res | $bsc others runtime +o test/test_runtime_encoding.cmi test/test_runtime_encoding.cmj : cc test/test_runtime_encoding.res | $bsc others runtime +o test/test_scope.cmi test/test_scope.cmj : cc test/test_scope.res | $bsc others runtime +o test/test_seq.cmi test/test_seq.cmj : cc test/test_seq.res | $bsc others runtime +o test/test_set.cmi test/test_set.cmj : cc test/test_set.res | $bsc others runtime +o test/test_side_effect_functor.cmi test/test_side_effect_functor.cmj : cc test/test_side_effect_functor.res | $bsc others runtime +o test/test_simple_include.cmi test/test_simple_include.cmj : cc test/test_simple_include.res | $bsc others runtime +o test/test_simple_pattern_match.cmi test/test_simple_pattern_match.cmj : cc test/test_simple_pattern_match.res | $bsc others runtime +o test/test_simple_ref.cmi test/test_simple_ref.cmj : cc test/test_simple_ref.res | $bsc others runtime +o test/test_simple_tailcall.cmi test/test_simple_tailcall.cmj : cc test/test_simple_tailcall.res | $bsc others runtime +o test/test_small.cmi test/test_small.cmj : cc test/test_small.res | $bsc others runtime +o test/test_static_catch_ident.cmi test/test_static_catch_ident.cmj : cc test/test_static_catch_ident.res | $bsc others runtime +o test/test_string.cmi test/test_string.cmj : cc test/test_string.res | $bsc others runtime +o test/test_string_case.cmi test/test_string_case.cmj : cc test/test_string_case.res | $bsc others runtime +o test/test_string_const.cmi test/test_string_const.cmj : cc test/test_string_const.res | $bsc others runtime +o test/test_string_map.cmi test/test_string_map.cmj : cc test/test_string_map.res | $bsc others runtime +o test/test_string_switch.cmi test/test_string_switch.cmj : cc test/test_string_switch.res | $bsc others runtime +o test/test_switch.cmi test/test_switch.cmj : cc test/test_switch.res | $bsc others runtime +o test/test_trywith.cmi test/test_trywith.cmj : cc test/test_trywith.res | $bsc others runtime +o test/test_tuple.cmi test/test_tuple.cmj : cc test/test_tuple.res | $bsc others runtime +o test/test_tuple_destructring.cmi test/test_tuple_destructring.cmj : cc test/test_tuple_destructring.res | $bsc others runtime +o test/test_type_based_arity.cmi test/test_type_based_arity.cmj : cc test/test_type_based_arity.res | test/abstract_type.cmj $bsc others runtime +o test/test_u.cmi test/test_u.cmj : cc test/test_u.res | $bsc others runtime +o test/test_unknown.cmi test/test_unknown.cmj : cc test/test_unknown.res | $bsc others runtime +o test/test_unsafe_cmp.cmi test/test_unsafe_cmp.cmj : cc test/test_unsafe_cmp.res | $bsc others runtime +o test/test_unsafe_obj_ffi.cmj : cc_cmi test/test_unsafe_obj_ffi.res | test/test_unsafe_obj_ffi.cmi $bsc others runtime +o test/test_unsafe_obj_ffi.cmi : cc test/test_unsafe_obj_ffi.resi | $bsc others runtime +o test/test_unsafe_obj_ffi_ppx.cmj : cc_cmi test/test_unsafe_obj_ffi_ppx.res | test/test_unsafe_obj_ffi_ppx.cmi $bsc others runtime +o test/test_unsafe_obj_ffi_ppx.cmi : cc test/test_unsafe_obj_ffi_ppx.resi | $bsc others runtime +o test/test_while_closure.cmi test/test_while_closure.cmj : cc test/test_while_closure.res | $bsc others runtime +o test/test_while_side_effect.cmi test/test_while_side_effect.cmj : cc test/test_while_side_effect.res | $bsc others runtime +o test/test_zero_nullable.cmi test/test_zero_nullable.cmj : cc test/test_zero_nullable.res | test/mt.cmj $bsc others runtime +o test/then_mangle_test.cmi test/then_mangle_test.cmj : cc test/then_mangle_test.res | test/mt.cmj $bsc others runtime +o test/ticker.cmi test/ticker.cmj : cc test/ticker.res | $bsc others runtime +o test/to_string_test.cmi test/to_string_test.cmj : cc test/to_string_test.res | test/mt.cmj $bsc others runtime +o test/topsort_test.cmi test/topsort_test.cmj : cc test/topsort_test.res | $bsc others runtime +o test/tramp_fib.cmi test/tramp_fib.cmj : cc test/tramp_fib.res | test/mt.cmj $bsc others runtime +o test/tuple_alloc.cmi test/tuple_alloc.cmj : cc test/tuple_alloc.res | $bsc others runtime +o test/type-coercion-free-vars.cmi test/type-coercion-free-vars.cmj : cc test/type-coercion-free-vars.res | $bsc others runtime +o test/type_disambiguate.cmi test/type_disambiguate.cmj : cc test/type_disambiguate.res | $bsc others runtime +o test/typeof_test.cmi test/typeof_test.cmj : cc test/typeof_test.res | test/mt.cmj $bsc others runtime +o test/unboxed_attribute.cmi test/unboxed_attribute.cmj : cc test/unboxed_attribute.res | $bsc others runtime +o test/unboxed_attribute_test.cmi test/unboxed_attribute_test.cmj : cc test/unboxed_attribute_test.res | test/mt.cmj $bsc others runtime +o test/unboxed_crash.cmi test/unboxed_crash.cmj : cc test/unboxed_crash.res | $bsc others runtime +o test/unboxed_use_case.cmj : cc_cmi test/unboxed_use_case.res | test/unboxed_use_case.cmi $bsc others runtime +o test/unboxed_use_case.cmi : cc test/unboxed_use_case.resi | $bsc others runtime +o test/uncurried_cast.cmi test/uncurried_cast.cmj : cc test/uncurried_cast.res | $bsc others runtime +o test/uncurried_default.args.cmi test/uncurried_default.args.cmj : cc test/uncurried_default.args.res | $bsc others runtime +o test/uncurried_pipe.cmi test/uncurried_pipe.cmj : cc test/uncurried_pipe.res | $bsc others runtime +o test/uncurry_external_test.cmi test/uncurry_external_test.cmj : cc test/uncurry_external_test.res | test/mt.cmj $bsc others runtime +o test/uncurry_glob_test.cmi test/uncurry_glob_test.cmj : cc test/uncurry_glob_test.res | $bsc others runtime +o test/uncurry_test.cmj : cc_cmi test/uncurry_test.res | test/uncurry_test.cmi $bsc others runtime +o test/uncurry_test.cmi : cc test/uncurry_test.resi | $bsc others runtime +o test/undef_regression_test.cmi test/undef_regression_test.cmj : cc test/undef_regression_test.res | $bsc others runtime +o test/unit_undefined_test.cmi test/unit_undefined_test.cmj : cc test/unit_undefined_test.res | test/mt.cmj $bsc others runtime +o test/unsafe_full_apply_primitive.cmi test/unsafe_full_apply_primitive.cmj : cc test/unsafe_full_apply_primitive.res | $bsc others runtime +o test/unsafe_ppx_test.cmi test/unsafe_ppx_test.cmj : cc test/unsafe_ppx_test.res | test/ffi_js_test.cmj test/mt.cmj $bsc others runtime +o test/update_record_test.cmi test/update_record_test.cmj : cc test/update_record_test.res | test/mt.cmj $bsc others runtime +o test/variant.cmi test/variant.cmj : cc test/variant.res | $bsc others runtime +o test/variantsMatching.cmi test/variantsMatching.cmj : cc test/variantsMatching.res | $bsc others runtime +o test/webpack_config.cmi test/webpack_config.cmj : cc test/webpack_config.res | $bsc others runtime +o test : phony test/AsInUncurriedExternals.cmi test/AsInUncurriedExternals.cmj test/Coercion.cmi test/Coercion.cmj test/DerivingAccessorsCurried.cmi test/DerivingAccessorsCurried.cmj test/DerivingAccessorsUncurried.cmi test/DerivingAccessorsUncurried.cmj test/DictInference.cmi test/DictInference.cmj test/DictTests.cmi test/DictTests.cmj test/DisambiguateOptionalFields.cmi test/DisambiguateOptionalFields.cmj test/DotDotDot.cmi test/DotDotDot.cmj test/EmptyRecord.cmi test/EmptyRecord.cmj test/ExternalArity.cmi test/ExternalArity.cmj test/FFI.cmi test/FFI.cmj test/Import.cmi test/Import.cmj test/ImportAttributes.cmi test/ImportAttributes.cmj test/PartialApplicationNoRuntimeCurry.cmi test/PartialApplicationNoRuntimeCurry.cmj test/RecordCoercion.cmi test/RecordCoercion.cmj test/RecordOrObject.cmi test/RecordOrObject.cmj test/SafePromises.cmi test/SafePromises.cmj test/UncurriedAlways.cmi test/UncurriedAlways.cmj test/UncurriedExternals.cmi test/UncurriedExternals.cmj test/UncurriedPervasives.cmi test/UncurriedPervasives.cmj test/UntaggedVariants.cmi test/UntaggedVariants.cmj test/VariantCoercion.cmi test/VariantCoercion.cmj test/VariantPatternMatchingSpreads.cmi test/VariantPatternMatchingSpreads.cmj test/VariantPatternMatchingSpreadsWithPayloads.cmi test/VariantPatternMatchingSpreadsWithPayloads.cmj test/VariantSpreads.cmi test/VariantSpreads.cmj test/a.cmi test/a.cmj test/a_recursive_type.cmi test/a_recursive_type.cmj test/a_scope_bug.cmi test/a_scope_bug.cmj test/abstract_type.cmi test/abstract_type.cmj test/adt_optimize_test.cmi test/adt_optimize_test.cmj test/alias_default_value_test.cmi test/alias_default_value_test.cmj test/alias_test.cmi test/alias_test.cmj test/and_or_tailcall_test.cmi test/and_or_tailcall_test.cmj test/ari_regress_test.cmi test/ari_regress_test.cmj test/arith_syntax.cmi test/arith_syntax.cmj test/arity.cmi test/arity.cmj test/arity_deopt.cmi test/arity_deopt.cmj test/arity_infer.cmi test/arity_infer.cmj test/array_data_util.cmi test/array_data_util.cmj test/array_safe_get.cmi test/array_safe_get.cmj test/array_subtle_test.cmi test/array_subtle_test.cmj test/as_inline_record_test.cmi test/as_inline_record_test.cmj test/ast_abstract_test.cmi test/ast_abstract_test.cmj test/ast_mapper_unused_warning_test.cmi test/ast_mapper_unused_warning_test.cmj test/async_await.cmi test/async_await.cmj test/async_inline.cmi test/async_inline.cmj test/async_inside_loop.cmi test/async_inside_loop.cmj test/attr_test.cmi test/attr_test.cmj test/b.cmi test/b.cmj test/bal_set_mini.cmi test/bal_set_mini.cmj test/bb.cmi test/bb.cmj test/bdd.cmi test/bdd.cmj test/belt_float_ntest.cmi test/belt_float_ntest.cmj test/belt_hashmap_ntest.cmi test/belt_hashmap_ntest.cmj test/belt_hashset_int_ntest.cmi test/belt_hashset_int_ntest.cmj test/belt_int_ntest.cmi test/belt_int_ntest.cmj test/belt_internal_test.cmi test/belt_internal_test.cmj test/belt_list_ntest.cmi test/belt_list_ntest.cmj test/belt_mapint_ntest.cmi test/belt_mapint_ntest.cmj test/belt_result_alias_test.cmi test/belt_result_alias_test.cmj test/belt_sortarray_ntest.cmi test/belt_sortarray_ntest.cmj test/bench.cmi test/bench.cmj test/big_enum.cmi test/big_enum.cmj test/big_polyvar_test.cmi test/big_polyvar_test.cmj test/bigint_test.cmi test/bigint_test.cmj test/block_alias_test.cmi test/block_alias_test.cmj test/boolean_test.cmi test/boolean_test.cmj test/bs_abstract_test.cmi test/bs_abstract_test.cmj test/bs_array_test.cmi test/bs_array_test.cmj test/bs_auto_uncurry.cmi test/bs_auto_uncurry.cmj test/bs_auto_uncurry_test.cmi test/bs_auto_uncurry_test.cmj test/bs_ignore_effect.cmi test/bs_ignore_effect.cmj test/bs_ignore_test.cmi test/bs_ignore_test.cmj test/bs_map_set_dict_test.cmi test/bs_map_set_dict_test.cmj test/bs_map_test.cmi test/bs_map_test.cmj test/bs_min_max_test.cmi test/bs_min_max_test.cmj test/bs_mutable_set_test.cmi test/bs_mutable_set_test.cmj test/bs_poly_map_test.cmi test/bs_poly_map_test.cmj test/bs_poly_mutable_map_test.cmi test/bs_poly_mutable_map_test.cmj test/bs_poly_mutable_set_test.cmi test/bs_poly_mutable_set_test.cmj test/bs_poly_set_test.cmi test/bs_poly_set_test.cmj test/bs_qualified.cmi test/bs_qualified.cmj test/bs_queue_test.cmi test/bs_queue_test.cmj test/bs_rest_test.cmi test/bs_rest_test.cmj test/bs_set_int_test.cmi test/bs_set_int_test.cmj test/bs_splice_partial.cmi test/bs_splice_partial.cmj test/bs_stack_test.cmi test/bs_stack_test.cmj test/bs_string_test.cmi test/bs_string_test.cmj test/bs_unwrap_test.cmi test/bs_unwrap_test.cmj test/caml_compare_bigint_test.cmi test/caml_compare_bigint_test.cmj test/caml_compare_test.cmi test/caml_compare_test.cmj test/chain_code_test.cmi test/chain_code_test.cmj test/chn_test.cmi test/chn_test.cmj test/class_type_ffi_test.cmi test/class_type_ffi_test.cmj test/coercion_module_alias_test.cmi test/coercion_module_alias_test.cmj test/compare_test.cmi test/compare_test.cmj test/complete_parmatch_test.cmi test/complete_parmatch_test.cmj test/complex_while_loop.cmi test/complex_while_loop.cmj test/condition_compilation_test.cmi test/condition_compilation_test.cmj test/config1_test.cmi test/config1_test.cmj test/console_log_test.cmi test/console_log_test.cmj test/const_block_test.cmi test/const_block_test.cmj test/const_defs.cmi test/const_defs.cmj test/const_defs_test.cmi test/const_defs_test.cmj test/const_test.cmi test/const_test.cmj test/cont_int_fold_test.cmi test/cont_int_fold_test.cmj test/cps_test.cmi test/cps_test.cmj test/cross_module_inline_test.cmi test/cross_module_inline_test.cmj test/custom_error_test.cmi test/custom_error_test.cmj test/debug_keep_test.cmi test/debug_keep_test.cmj test/debug_mode_value.cmi test/debug_mode_value.cmj test/debug_tmp.cmi test/debug_tmp.cmj test/debugger_test.cmi test/debugger_test.cmj test/default_export_test.cmi test/default_export_test.cmj test/defunctor_make_test.cmi test/defunctor_make_test.cmj test/demo_int_map.cmi test/demo_int_map.cmj test/demo_page.cmi test/demo_page.cmj test/demo_pipe.cmi test/demo_pipe.cmj test/derive_projector_test.cmi test/derive_projector_test.cmj test/directives.cmi test/directives.cmj test/div_by_zero_test.cmi test/div_by_zero_test.cmj test/dollar_escape_test.cmi test/dollar_escape_test.cmj test/earger_curry_test.cmi test/earger_curry_test.cmj test/effect.cmi test/effect.cmj test/epsilon_test.cmi test/epsilon_test.cmj test/equal_box_test.cmi test/equal_box_test.cmj test/equal_exception_test.cmi test/equal_exception_test.cmj test/equal_test.cmi test/equal_test.cmj test/es6_export.cmi test/es6_export.cmj test/es6_import.cmi test/es6_import.cmj test/es6_module_test.cmi test/es6_module_test.cmj test/escape_esmodule.cmi test/escape_esmodule.cmj test/esmodule_ref.cmi test/esmodule_ref.cmj test/event_ffi.cmi test/event_ffi.cmj test/exception_alias.cmi test/exception_alias.cmj test/exception_raise_test.cmi test/exception_raise_test.cmj test/exception_rebound_err_test.cmi test/exception_rebound_err_test.cmj test/exception_value_test.cmi test/exception_value_test.cmj test/exotic_labels_test.cmi test/exotic_labels_test.cmj test/exponentiation_precedence_test.cmi test/exponentiation_precedence_test.cmj test/export_keyword.cmi test/export_keyword.cmj test/ext_array_test.cmi test/ext_array_test.cmj test/ext_pervasives_test.cmi test/ext_pervasives_test.cmj test/extensible_variant_test.cmi test/extensible_variant_test.cmj test/external_ppx.cmi test/external_ppx.cmj test/external_ppx2.cmi test/external_ppx2.cmj test/ffi_arity_test.cmi test/ffi_arity_test.cmj test/ffi_array_test.cmi test/ffi_array_test.cmj test/ffi_js_test.cmi test/ffi_js_test.cmj test/ffi_splice_test.cmi test/ffi_splice_test.cmj test/ffi_test.cmi test/ffi_test.cmj test/fib.cmi test/fib.cmj test/flattern_order_test.cmi test/flattern_order_test.cmj test/flexible_array_test.cmi test/flexible_array_test.cmj test/float_array.cmi test/float_array.cmj test/float_record.cmi test/float_record.cmj test/float_test.cmi test/float_test.cmj test/for_loop_test.cmi test/for_loop_test.cmj test/for_side_effect_test.cmi test/for_side_effect_test.cmj test/format_regression.cmi test/format_regression.cmj test/fun_pattern_match.cmi test/fun_pattern_match.cmj test/function_directives.cmi test/function_directives.cmj test/function_directives_no_inline.cmi test/function_directives_no_inline.cmj test/functor_app_test.cmi test/functor_app_test.cmj test/functor_def.cmi test/functor_def.cmj test/functor_ffi.cmi test/functor_ffi.cmj test/functor_inst.cmi test/functor_inst.cmj test/functors.cmi test/functors.cmj test/gbk.cmi test/gbk.cmj test/gentTypeReTest.cmi test/gentTypeReTest.cmj test/global_exception_regression_test.cmi test/global_exception_regression_test.cmj test/global_mangles.cmi test/global_mangles.cmj test/global_module_alias_test.cmi test/global_module_alias_test.cmj test/google_closure_test.cmi test/google_closure_test.cmj test/gpr496_test.cmi test/gpr496_test.cmj test/gpr_1072.cmi test/gpr_1072.cmj test/gpr_1072_reg.cmi test/gpr_1072_reg.cmj test/gpr_1150.cmi test/gpr_1150.cmj test/gpr_1170.cmi test/gpr_1170.cmj test/gpr_1240_missing_unbox.cmi test/gpr_1240_missing_unbox.cmj test/gpr_1245_test.cmi test/gpr_1245_test.cmj test/gpr_1268.cmi test/gpr_1268.cmj test/gpr_1409_test.cmi test/gpr_1409_test.cmj test/gpr_1423_app_test.cmi test/gpr_1423_app_test.cmj test/gpr_1423_nav.cmi test/gpr_1423_nav.cmj test/gpr_1438.cmi test/gpr_1438.cmj test/gpr_1481.cmi test/gpr_1481.cmj test/gpr_1484.cmi test/gpr_1484.cmj test/gpr_1539_test.cmi test/gpr_1539_test.cmj test/gpr_1658_test.cmi test/gpr_1658_test.cmj test/gpr_1667_test.cmi test/gpr_1667_test.cmj test/gpr_1692_test.cmi test/gpr_1692_test.cmj test/gpr_1698_test.cmi test/gpr_1698_test.cmj test/gpr_1701_test.cmi test/gpr_1701_test.cmj test/gpr_1716_test.cmi test/gpr_1716_test.cmj test/gpr_1717_test.cmi test/gpr_1717_test.cmj test/gpr_1728_test.cmi test/gpr_1728_test.cmj test/gpr_1749_test.cmi test/gpr_1749_test.cmj test/gpr_1759_test.cmi test/gpr_1759_test.cmj test/gpr_1760_test.cmi test/gpr_1760_test.cmj test/gpr_1762_test.cmi test/gpr_1762_test.cmj test/gpr_1817_test.cmi test/gpr_1817_test.cmj test/gpr_1822_test.cmi test/gpr_1822_test.cmj test/gpr_1891_test.cmi test/gpr_1891_test.cmj test/gpr_1943_test.cmi test/gpr_1943_test.cmj test/gpr_1946_test.cmi test/gpr_1946_test.cmj test/gpr_2316_test.cmi test/gpr_2316_test.cmj test/gpr_2352_test.cmi test/gpr_2352_test.cmj test/gpr_2413_test.cmi test/gpr_2413_test.cmj test/gpr_2474.cmi test/gpr_2474.cmj test/gpr_2487.cmi test/gpr_2487.cmj test/gpr_2503_test.cmi test/gpr_2503_test.cmj test/gpr_2608_test.cmi test/gpr_2608_test.cmj test/gpr_2614_test.cmi test/gpr_2614_test.cmj test/gpr_2633_test.cmi test/gpr_2633_test.cmj test/gpr_2642_test.cmi test/gpr_2642_test.cmj test/gpr_2682_test.cmi test/gpr_2682_test.cmj test/gpr_2700_test.cmi test/gpr_2700_test.cmj test/gpr_2731_test.cmi test/gpr_2731_test.cmj test/gpr_2789_test.cmi test/gpr_2789_test.cmj test/gpr_2931_test.cmi test/gpr_2931_test.cmj test/gpr_3142_test.cmi test/gpr_3142_test.cmj test/gpr_3154_test.cmi test/gpr_3154_test.cmj test/gpr_3209_test.cmi test/gpr_3209_test.cmj test/gpr_3492_test.cmi test/gpr_3492_test.cmj test/gpr_3519_jsx_test.cmi test/gpr_3519_jsx_test.cmj test/gpr_3519_test.cmi test/gpr_3519_test.cmj test/gpr_3536_test.cmi test/gpr_3536_test.cmj test/gpr_3546_test.cmi test/gpr_3546_test.cmj test/gpr_3548_test.cmi test/gpr_3548_test.cmj test/gpr_3549_test.cmi test/gpr_3549_test.cmj test/gpr_3566_drive_test.cmi test/gpr_3566_drive_test.cmj test/gpr_3566_test.cmi test/gpr_3566_test.cmj test/gpr_3595_test.cmi test/gpr_3595_test.cmj test/gpr_3609_test.cmi test/gpr_3609_test.cmj test/gpr_3697_test.cmi test/gpr_3697_test.cmj test/gpr_373_test.cmi test/gpr_373_test.cmj test/gpr_3770_test.cmi test/gpr_3770_test.cmj test/gpr_3852_alias.cmi test/gpr_3852_alias.cmj test/gpr_3852_alias_reify.cmi test/gpr_3852_alias_reify.cmj test/gpr_3852_effect.cmi test/gpr_3852_effect.cmj test/gpr_3865.cmi test/gpr_3865.cmj test/gpr_3865_bar.cmi test/gpr_3865_bar.cmj test/gpr_3865_foo.cmi test/gpr_3865_foo.cmj test/gpr_3875_test.cmi test/gpr_3875_test.cmj test/gpr_3877_test.cmi test/gpr_3877_test.cmj test/gpr_3895_test.cmi test/gpr_3895_test.cmj test/gpr_3897_test.cmi test/gpr_3897_test.cmj test/gpr_3931_test.cmi test/gpr_3931_test.cmj test/gpr_3980_test.cmi test/gpr_3980_test.cmj test/gpr_4025_test.cmi test/gpr_4025_test.cmj test/gpr_4069_test.cmi test/gpr_4069_test.cmj test/gpr_4265_test.cmi test/gpr_4265_test.cmj test/gpr_4274_test.cmi test/gpr_4274_test.cmj test/gpr_4280_test.cmi test/gpr_4280_test.cmj test/gpr_4407_test.cmi test/gpr_4407_test.cmj test/gpr_441.cmi test/gpr_441.cmj test/gpr_4442_test.cmi test/gpr_4442_test.cmj test/gpr_4491_test.cmi test/gpr_4491_test.cmj test/gpr_4494_test.cmi test/gpr_4494_test.cmj test/gpr_4519_test.cmi test/gpr_4519_test.cmj test/gpr_459_test.cmi test/gpr_459_test.cmj test/gpr_4632.cmi test/gpr_4632.cmj test/gpr_4639_test.cmi test/gpr_4639_test.cmj test/gpr_4900_test.cmi test/gpr_4900_test.cmj test/gpr_4924_test.cmi test/gpr_4924_test.cmj test/gpr_4931.cmi test/gpr_4931.cmj test/gpr_4931_allow.cmi test/gpr_4931_allow.cmj test/gpr_5071_test.cmi test/gpr_5071_test.cmj test/gpr_5169_test.cmi test/gpr_5169_test.cmj test/gpr_5218_test.cmi test/gpr_5218_test.cmj test/gpr_5280_optimize_test.cmi test/gpr_5280_optimize_test.cmj test/gpr_5557.cmi test/gpr_5557.cmj test/gpr_5753.cmi test/gpr_5753.cmj test/gpr_658.cmi test/gpr_658.cmj test/gpr_7012_test.cmi test/gpr_7012_test.cmj test/gpr_858_test.cmi test/gpr_858_test.cmj test/gpr_858_unit2_test.cmi test/gpr_858_unit2_test.cmj test/gpr_904_test.cmi test/gpr_904_test.cmj test/gpr_974_test.cmi test/gpr_974_test.cmj test/gpr_977_test.cmi test/gpr_977_test.cmj test/gpr_return_type_unused_attribute.cmi test/gpr_return_type_unused_attribute.cmj test/gray_code_test.cmi test/gray_code_test.cmj test/guide_for_ext.cmi test/guide_for_ext.cmj test/hash_collision_test.cmi test/hash_collision_test.cmj test/hash_sugar_desugar.cmi test/hash_sugar_desugar.cmj test/hash_test.cmi test/hash_test.cmj test/hello.foo.cmi test/hello.foo.cmj test/hello_res.cmi test/hello_res.cmj test/ignore_test.cmi test/ignore_test.cmj test/ignore_uncurry_attribute.cmi test/ignore_uncurry_attribute.cmj test/import2.cmi test/import2.cmj test/import_external.cmi test/import_external.cmj test/import_side_effect.cmi test/import_side_effect.cmj test/import_side_effect_free.cmi test/import_side_effect_free.cmj test/include_side_effect.cmi test/include_side_effect.cmj test/include_side_effect_free.cmi test/include_side_effect_free.cmj test/incomplete_toplevel_test.cmi test/incomplete_toplevel_test.cmj test/infer_type_test.cmi test/infer_type_test.cmj test/inline_condition_with_pattern_matching.cmi test/inline_condition_with_pattern_matching.cmj test/inline_const.cmi test/inline_const.cmj test/inline_const_test.cmi test/inline_const_test.cmj test/inline_edge_cases.cmi test/inline_edge_cases.cmj test/inline_map2_test.cmi test/inline_map2_test.cmj test/inline_map_demo.cmi test/inline_map_demo.cmj test/inline_map_test.cmi test/inline_map_test.cmj test/inline_record_test.cmi test/inline_record_test.cmj test/inline_regression_test.cmi test/inline_regression_test.cmj test/inline_string_test.cmi test/inline_string_test.cmj test/inner_call.cmi test/inner_call.cmj test/inner_define.cmi test/inner_define.cmj test/inner_unused.cmi test/inner_unused.cmj test/installation_test.cmi test/installation_test.cmj test/int_map.cmi test/int_map.cmj test/int_overflow_test.cmi test/int_overflow_test.cmj test/int_poly_var.cmi test/int_poly_var.cmj test/int_switch_test.cmi test/int_switch_test.cmj test/internal_unused_test.cmi test/internal_unused_test.cmj test/js_array_test.cmi test/js_array_test.cmj test/js_bool_test.cmi test/js_bool_test.cmj test/js_cast_test.cmi test/js_cast_test.cmj test/js_date_test.cmi test/js_date_test.cmj test/js_dict_test.cmi test/js_dict_test.cmj test/js_exception_catch_test.cmi test/js_exception_catch_test.cmj test/js_float_test.cmi test/js_float_test.cmj test/js_global_test.cmi test/js_global_test.cmj test/js_int_test.cmi test/js_int_test.cmj test/js_json_test.cmi test/js_json_test.cmj test/js_math_test.cmi test/js_math_test.cmj test/js_null_test.cmi test/js_null_test.cmj test/js_null_undefined_test.cmi test/js_null_undefined_test.cmj test/js_nullable_test.cmi test/js_nullable_test.cmj test/js_obj_test.cmi test/js_obj_test.cmj test/js_option_test.cmi test/js_option_test.cmj test/js_re_test.cmi test/js_re_test.cmj test/js_string_test.cmi test/js_string_test.cmj test/js_undefined_test.cmi test/js_undefined_test.cmj test/js_val.cmi test/js_val.cmj test/jsoo_400_test.cmi test/jsoo_400_test.cmj test/jsoo_485_test.cmi test/jsoo_485_test.cmj test/jsxv4_newtype.cmi test/jsxv4_newtype.cmj test/keep_uncurry_attribute.cmi test/keep_uncurry_attribute.cmj test/key_word_property.cmi test/key_word_property.cmj test/key_word_property2.cmi test/key_word_property2.cmj test/key_word_property_plus_test.cmi test/key_word_property_plus_test.cmj test/label_uncurry.cmi test/label_uncurry.cmj test/large_integer_pat.cmi test/large_integer_pat.cmj test/large_record_duplication_test.cmi test/large_record_duplication_test.cmj test/largest_int_flow.cmi test/largest_int_flow.cmj test/lazy_demo.cmi test/lazy_demo.cmj test/lazy_test.cmi test/lazy_test.cmj test/lib_js_test.cmi test/lib_js_test.cmj test/limits_test.cmi test/limits_test.cmj test/list_test.cmi test/list_test.cmj test/local_exception_test.cmi test/local_exception_test.cmj test/loop_regression_test.cmi test/loop_regression_test.cmj test/map_find_test.cmi test/map_find_test.cmj test/mario_game.cmi test/mario_game.cmj test/meth_annotation.cmi test/meth_annotation.cmj test/method_name_test.cmi test/method_name_test.cmj test/method_string_name.cmi test/method_string_name.cmj test/minimal_test.cmi test/minimal_test.cmj test/miss_colon_test.cmi test/miss_colon_test.cmj test/mock_mt.cmi test/mock_mt.cmj test/module_alias_test.cmi test/module_alias_test.cmj test/module_as_class_ffi.cmi test/module_as_class_ffi.cmj test/module_as_function.cmi test/module_as_function.cmj test/module_missing_conversion.cmi test/module_missing_conversion.cmj test/module_parameter_test.cmi test/module_parameter_test.cmj test/module_splice_test.cmi test/module_splice_test.cmj test/more_poly_variant_test.cmi test/more_poly_variant_test.cmj test/more_uncurry.cmi test/more_uncurry.cmj test/mpr_6033_test.cmi test/mpr_6033_test.cmj test/mt.cmi test/mt.cmj test/mt_global.cmi test/mt_global.cmj test/mutable_obj_test.cmi test/mutable_obj_test.cmj test/mutable_uncurry_test.cmi test/mutable_uncurry_test.cmj test/mutual_non_recursive_type.cmi test/mutual_non_recursive_type.cmj test/name_mangle_test.cmi test/name_mangle_test.cmj test/nested_include.cmi test/nested_include.cmj test/nested_module_alias.cmi test/nested_module_alias.cmj test/nested_obj_literal.cmi test/nested_obj_literal.cmj test/nested_obj_test.cmi test/nested_obj_test.cmj test/nested_pattern_match_test.cmi test/nested_pattern_match_test.cmj test/noassert.cmi test/noassert.cmj test/node_assert.cmi test/node_assert.cmj test/node_path_test.cmi test/node_path_test.cmj test/node_test.cmi test/node_test.cmj test/node_test_util.cmi test/node_test_util.cmj test/obj_literal_ppx.cmi test/obj_literal_ppx.cmj test/obj_literal_ppx_test.cmi test/obj_literal_ppx_test.cmj test/obj_magic_test.cmi test/obj_magic_test.cmj test/obj_type_test.cmi test/obj_type_test.cmj test/offset.cmi test/offset.cmj test/omit_trailing_undefined_in_external_calls.cmi test/omit_trailing_undefined_in_external_calls.cmj test/option_encoding_test.cmi test/option_encoding_test.cmj test/option_repr_test.cmi test/option_repr_test.cmj test/optional_ffi_test.cmi test/optional_ffi_test.cmj test/optional_regression_test.cmi test/optional_regression_test.cmj test/pipe_send_readline.cmi test/pipe_send_readline.cmj test/pipe_syntax.cmi test/pipe_syntax.cmj test/poly_empty_array.cmi test/poly_empty_array.cmj test/poly_variant_test.cmi test/poly_variant_test.cmj test/polymorphic_raw_test.cmi test/polymorphic_raw_test.cmj test/polymorphism_test.cmi test/polymorphism_test.cmj test/polyvar_convert.cmi test/polyvar_convert.cmj test/polyvar_test.cmi test/polyvar_test.cmj test/ppx_apply_test.cmi test/ppx_apply_test.cmj test/pq_test.cmi test/pq_test.cmj test/pr6726.cmi test/pr6726.cmj test/prepend_data_ffi.cmi test/prepend_data_ffi.cmj test/print_alpha_test.cmi test/print_alpha_test.cmj test/queue_402.cmi test/queue_402.cmj test/raw_output_test.cmi test/raw_output_test.cmj test/raw_pure_test.cmi test/raw_pure_test.cmj test/rbset.cmi test/rbset.cmj test/react.cmi test/react.cmj test/reactDOMRe.cmi test/reactDOMRe.cmj test/reactDOMServerRe.cmi test/reactDOMServerRe.cmj test/reactEvent.cmi test/reactEvent.cmj test/reactTestUtils.cmi test/reactTestUtils.cmj test/reasonReact.cmi test/reasonReact.cmj test/reasonReactCompat.cmi test/reasonReactCompat.cmj test/reasonReactOptimizedCreateClass.cmi test/reasonReactOptimizedCreateClass.cmj test/reasonReactRouter.cmi test/reasonReactRouter.cmj test/rebind_module.cmi test/rebind_module.cmj test/rebind_module_test.cmi test/rebind_module_test.cmj test/rec_array_test.cmi test/rec_array_test.cmj test/rec_fun_test.cmi test/rec_fun_test.cmj test/rec_module_opt.cmi test/rec_module_opt.cmj test/rec_module_test.cmi test/rec_module_test.cmj test/recmodule.cmi test/recmodule.cmj test/record_debug_test.cmi test/record_debug_test.cmj test/record_extension_test.cmi test/record_extension_test.cmj test/record_name_test.cmi test/record_name_test.cmj test/record_regression.cmi test/record_regression.cmj test/record_type_spread.cmi test/record_type_spread.cmj test/record_with_test.cmi test/record_with_test.cmj test/recursive_module.cmi test/recursive_module.cmj test/recursive_module_test.cmi test/recursive_module_test.cmj test/recursive_react_component.cmi test/recursive_react_component.cmj test/recursive_records_test.cmi test/recursive_records_test.cmj test/recursive_unbound_module_test.cmi test/recursive_unbound_module_test.cmj test/regression_print.cmi test/regression_print.cmj test/relative_path.cmi test/relative_path.cmj test/res_debug.cmi test/res_debug.cmj test/return_check.cmi test/return_check.cmj test/runtime_encoding_test.cmi test/runtime_encoding_test.cmj test/set_annotation.cmi test/set_annotation.cmj test/set_gen.cmi test/set_gen.cmj test/side_effect.cmi test/side_effect.cmj test/side_effect2.cmi test/side_effect2.cmj test/side_effect_free.cmi test/side_effect_free.cmj test/simplify_lambda_632o.cmi test/simplify_lambda_632o.cmj test/singular_unit_test.cmi test/singular_unit_test.cmj test/small_inline_test.cmi test/small_inline_test.cmj test/splice_test.cmi test/splice_test.cmj test/string_bound_get_test.cmi test/string_bound_get_test.cmj test/string_constant_compare.cmi test/string_constant_compare.cmj test/string_set.cmi test/string_set.cmj test/string_set_test.cmi test/string_set_test.cmj test/string_unicode_test.cmi test/string_unicode_test.cmj test/stringmatch_test.cmi test/stringmatch_test.cmj test/submodule.cmi test/submodule.cmj test/submodule_call.cmi test/submodule_call.cmj test/switch_case_test.cmi test/switch_case_test.cmj test/switch_string.cmi test/switch_string.cmj test/tagged_template_test.cmi test/tagged_template_test.cmj test/tailcall_inline_test.cmi test/tailcall_inline_test.cmj test/template.cmi test/template.cmj test/test2.cmi test/test2.cmj test/test_ari.cmi test/test_ari.cmj test/test_array.cmi test/test_array.cmj test/test_array_append.cmi test/test_array_append.cmj test/test_bool_equal.cmi test/test_bool_equal.cmj test/test_bs_this.cmi test/test_bs_this.cmj test/test_case_opt_collision.cmi test/test_case_opt_collision.cmj test/test_case_set.cmi test/test_case_set.cmj test/test_char.cmi test/test_char.cmj test/test_closure.cmi test/test_closure.cmj test/test_common.cmi test/test_common.cmj test/test_const_elim.cmi test/test_const_elim.cmj test/test_const_propogate.cmi test/test_const_propogate.cmj test/test_cpp.cmi test/test_cpp.cmj test/test_cps.cmi test/test_cps.cmj test/test_demo.cmi test/test_demo.cmj test/test_dup_param.cmi test/test_dup_param.cmj test/test_eq.cmi test/test_eq.cmj test/test_exception.cmi test/test_exception.cmj test/test_exception_escape.cmi test/test_exception_escape.cmj test/test_export2.cmi test/test_export2.cmj test/test_external.cmi test/test_external.cmj test/test_external_unit.cmi test/test_external_unit.cmj test/test_ffi.cmi test/test_ffi.cmj test/test_fib.cmi test/test_fib.cmj test/test_for_loop.cmi test/test_for_loop.cmj test/test_for_map.cmi test/test_for_map.cmj test/test_for_map2.cmi test/test_for_map2.cmj test/test_functor_dead_code.cmi test/test_functor_dead_code.cmj test/test_generative_module.cmi test/test_generative_module.cmj test/test_google_closure.cmi test/test_google_closure.cmj test/test_include.cmi test/test_include.cmj test/test_incomplete.cmi test/test_incomplete.cmj test/test_incr_ref.cmi test/test_incr_ref.cmj test/test_int_map_find.cmi test/test_int_map_find.cmj test/test_is_js.cmi test/test_is_js.cmj test/test_js_ffi.cmi test/test_js_ffi.cmj test/test_let.cmi test/test_let.cmj test/test_list.cmi test/test_list.cmj test/test_literal.cmi test/test_literal.cmj test/test_literals.cmi test/test_literals.cmj test/test_match_exception.cmi test/test_match_exception.cmj test/test_nested_let.cmi test/test_nested_let.cmj test/test_nested_print.cmi test/test_nested_print.cmj test/test_non_export.cmi test/test_non_export.cmj test/test_nullary.cmi test/test_nullary.cmj test/test_obj.cmi test/test_obj.cmj test/test_order.cmi test/test_order.cmj test/test_order_tailcall.cmi test/test_order_tailcall.cmj test/test_other_exn.cmi test/test_other_exn.cmj test/test_per.cmi test/test_per.cmj test/test_pervasive.cmi test/test_pervasive.cmj test/test_pervasives3.cmi test/test_pervasives3.cmj test/test_primitive.cmi test/test_primitive.cmj test/test_ramification.cmi test/test_ramification.cmj test/test_react.cmi test/test_react.cmj test/test_react_case.cmi test/test_react_case.cmj test/test_regex.cmi test/test_regex.cmj test/test_runtime_encoding.cmi test/test_runtime_encoding.cmj test/test_scope.cmi test/test_scope.cmj test/test_seq.cmi test/test_seq.cmj test/test_set.cmi test/test_set.cmj test/test_side_effect_functor.cmi test/test_side_effect_functor.cmj test/test_simple_include.cmi test/test_simple_include.cmj test/test_simple_pattern_match.cmi test/test_simple_pattern_match.cmj test/test_simple_ref.cmi test/test_simple_ref.cmj test/test_simple_tailcall.cmi test/test_simple_tailcall.cmj test/test_small.cmi test/test_small.cmj test/test_static_catch_ident.cmi test/test_static_catch_ident.cmj test/test_string.cmi test/test_string.cmj test/test_string_case.cmi test/test_string_case.cmj test/test_string_const.cmi test/test_string_const.cmj test/test_string_map.cmi test/test_string_map.cmj test/test_string_switch.cmi test/test_string_switch.cmj test/test_switch.cmi test/test_switch.cmj test/test_trywith.cmi test/test_trywith.cmj test/test_tuple.cmi test/test_tuple.cmj test/test_tuple_destructring.cmi test/test_tuple_destructring.cmj test/test_type_based_arity.cmi test/test_type_based_arity.cmj test/test_u.cmi test/test_u.cmj test/test_unknown.cmi test/test_unknown.cmj test/test_unsafe_cmp.cmi test/test_unsafe_cmp.cmj test/test_unsafe_obj_ffi.cmi test/test_unsafe_obj_ffi.cmj test/test_unsafe_obj_ffi_ppx.cmi test/test_unsafe_obj_ffi_ppx.cmj test/test_while_closure.cmi test/test_while_closure.cmj test/test_while_side_effect.cmi test/test_while_side_effect.cmj test/test_zero_nullable.cmi test/test_zero_nullable.cmj test/then_mangle_test.cmi test/then_mangle_test.cmj test/ticker.cmi test/ticker.cmj test/to_string_test.cmi test/to_string_test.cmj test/topsort_test.cmi test/topsort_test.cmj test/tramp_fib.cmi test/tramp_fib.cmj test/tuple_alloc.cmi test/tuple_alloc.cmj test/type-coercion-free-vars.cmi test/type-coercion-free-vars.cmj test/type_disambiguate.cmi test/type_disambiguate.cmj test/typeof_test.cmi test/typeof_test.cmj test/unboxed_attribute.cmi test/unboxed_attribute.cmj test/unboxed_attribute_test.cmi test/unboxed_attribute_test.cmj test/unboxed_crash.cmi test/unboxed_crash.cmj test/unboxed_use_case.cmi test/unboxed_use_case.cmj test/uncurried_cast.cmi test/uncurried_cast.cmj test/uncurried_default.args.cmi test/uncurried_default.args.cmj test/uncurried_pipe.cmi test/uncurried_pipe.cmj test/uncurry_external_test.cmi test/uncurry_external_test.cmj test/uncurry_glob_test.cmi test/uncurry_glob_test.cmj test/uncurry_test.cmi test/uncurry_test.cmj test/undef_regression_test.cmi test/undef_regression_test.cmj test/unit_undefined_test.cmi test/unit_undefined_test.cmj test/unsafe_full_apply_primitive.cmi test/unsafe_full_apply_primitive.cmj test/unsafe_ppx_test.cmi test/unsafe_ppx_test.cmj test/update_record_test.cmi test/update_record_test.cmj test/variant.cmi test/variant.cmj test/variantsMatching.cmi test/variantsMatching.cmj test/webpack_config.cmi test/webpack_config.cmj diff --git a/jscomp/test/bytes_split_gpr_743_test.js b/jscomp/test/bytes_split_gpr_743_test.js deleted file mode 100644 index 7ab680613a..0000000000 --- a/jscomp/test/bytes_split_gpr_743_test.js +++ /dev/null @@ -1,84 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let Bytes = require("../../lib/js/bytes.js"); -let Caml_bytes = require("../../lib/js/caml_bytes.js"); - -let suites = { - contents: /* [] */0 -}; - -let test_id = { - contents: 0 -}; - -function eq(loc, param) { - let y = param[1]; - let x = param[0]; - test_id.contents = test_id.contents + 1 | 0; - suites.contents = { - hd: [ - loc + (" id " + String(test_id.contents)), - () => ({ - TAG: "Eq", - _0: x, - _1: y - }) - ], - tl: suites.contents - }; -} - -let b = [ - 0, - 0, - 0 -]; - -Caml_bytes.set(b, 0, /* 'a' */97); - -Caml_bytes.set(b, 1, /* 'b' */98); - -Caml_bytes.set(b, 2, /* 'c' */99); - -Bytes.blit(b, 0, b, 1, 2); - -let res = Bytes.unsafe_to_string(b); - -console.log(res); - -eq("File \"bytes_split_gpr_743_test.res\", line 17, characters 5-12", [ - "aab", - res -]); - -let b$1 = [ - 0, - 0, - 0 -]; - -Caml_bytes.set(b$1, 0, /* 'a' */97); - -Caml_bytes.set(b$1, 1, /* 'b' */98); - -Caml_bytes.set(b$1, 2, /* 'c' */99); - -Bytes.blit(b$1, 1, b$1, 0, 2); - -let res2 = Bytes.unsafe_to_string(b$1); - -console.log(res2); - -eq("File \"bytes_split_gpr_743_test.res\", line 32, characters 5-12", [ - "bcc", - res2 -]); - -Mt.from_pair_suites("Bytes_split_gpr_743_test", suites.contents); - -exports.suites = suites; -exports.test_id = test_id; -exports.eq = eq; -/* Not a pure module */ diff --git a/jscomp/test/bytes_split_gpr_743_test.res b/jscomp/test/bytes_split_gpr_743_test.res deleted file mode 100644 index 3c11f35c88..0000000000 --- a/jscomp/test/bytes_split_gpr_743_test.res +++ /dev/null @@ -1,35 +0,0 @@ -let suites: ref = ref(list{}) -let test_id = ref(0) -let eq = (loc, (x, y)) => { - incr(test_id) - suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} -} - -let () = { - let b = Bytes.create(3) - Bytes.set(b, 0, 'a') - Bytes.set(b, 1, 'b') - Bytes.set(b, 2, 'c') - Bytes.blit(b, 0, b, 1, 2) - let res = Bytes.unsafe_to_string(b) - Js.log(res) /* "aab" */ - eq(__LOC__, ("aab", res)) -} -/* assert('a' = Bytes.get b 0); */ -/* assert('a' = Bytes.get b 1); */ -/* assert('b' = Bytes.get b 2); */ -/* () */ - -let () = { - let b = Bytes.create(3) - Bytes.set(b, 0, 'a') - Bytes.set(b, 1, 'b') - Bytes.set(b, 2, 'c') - Bytes.blit(b, 1, b, 0, 2) - let res2 = Bytes.unsafe_to_string(b) - Js.log(res2) /* "bcc" */ - eq(__LOC__, ("bcc", res2)) -} - -let () = Mt.from_pair_suites(__MODULE__, suites.contents) diff --git a/jscomp/test/caml_compare_bigint_test.js b/jscomp/test/caml_compare_bigint_test.js index 7d451210b5..b594285187 100644 --- a/jscomp/test/caml_compare_bigint_test.js +++ b/jscomp/test/caml_compare_bigint_test.js @@ -2,8 +2,8 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); let Pervasives = require("../../lib/js/pervasives.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); function isLessThan(title, small, big) { return { @@ -12,7 +12,7 @@ function isLessThan(title, small, big) { param => ({ TAG: "Eq", _0: true, - _1: Caml_obj.compare(big, small) > 0 + _1: big > small }) ], tl: { @@ -21,7 +21,7 @@ function isLessThan(title, small, big) { param => ({ TAG: "Eq", _0: true, - _1: Caml_obj.compare(small, big) < 0 + _1: small < big }) ], tl: { @@ -30,7 +30,7 @@ function isLessThan(title, small, big) { param => ({ TAG: "Eq", _0: true, - _1: Caml_obj.lessthan(small, big) + _1: Primitive_object.lessthan(small, big) }) ], tl: { @@ -39,7 +39,7 @@ function isLessThan(title, small, big) { param => ({ TAG: "Eq", _0: true, - _1: Caml_obj.lessequal(small, big) + _1: Primitive_object.lessequal(small, big) }) ], tl: { @@ -48,7 +48,7 @@ function isLessThan(title, small, big) { param => ({ TAG: "Eq", _0: true, - _1: Caml_obj.greaterthan(big, small) + _1: Primitive_object.greaterthan(big, small) }) ], tl: { @@ -57,7 +57,7 @@ function isLessThan(title, small, big) { param => ({ TAG: "Eq", _0: true, - _1: Caml_obj.greaterequal(big, small) + _1: Primitive_object.greaterequal(big, small) }) ], tl: { @@ -66,7 +66,7 @@ function isLessThan(title, small, big) { param => ({ TAG: "Eq", _0: small, - _1: Caml_obj.min(big, small) + _1: Primitive_object.min(big, small) }) ], tl: { @@ -75,7 +75,7 @@ function isLessThan(title, small, big) { param => ({ TAG: "Eq", _0: small, - _1: Caml_obj.min(small, big) + _1: Primitive_object.min(small, big) }) ], tl: { @@ -84,7 +84,7 @@ function isLessThan(title, small, big) { param => ({ TAG: "Eq", _0: big, - _1: Caml_obj.max(big, small) + _1: Primitive_object.max(big, small) }) ], tl: { @@ -93,7 +93,7 @@ function isLessThan(title, small, big) { param => ({ TAG: "Eq", _0: big, - _1: Caml_obj.max(small, big) + _1: Primitive_object.max(small, big) }) ], tl: { @@ -120,7 +120,7 @@ function isLessThan(title, small, big) { param => ({ TAG: "Eq", _0: true, - _1: Caml_obj.notequal(big, small) + _1: Primitive_object.notequal(big, small) }) ], tl: { @@ -129,7 +129,7 @@ function isLessThan(title, small, big) { param => ({ TAG: "Eq", _0: true, - _1: Caml_obj.notequal(small, big) + _1: Primitive_object.notequal(small, big) }) ], tl: { @@ -138,7 +138,7 @@ function isLessThan(title, small, big) { param => ({ TAG: "Eq", _0: false, - _1: Caml_obj.equal(big, small) + _1: Primitive_object.equal(big, small) }) ], tl: { @@ -147,7 +147,7 @@ function isLessThan(title, small, big) { param => ({ TAG: "Eq", _0: false, - _1: Caml_obj.equal(small, big) + _1: Primitive_object.equal(small, big) }) ], tl: { @@ -196,7 +196,7 @@ function isEqual(title, num1, num2) { param => ({ TAG: "Eq", _0: false, - _1: Caml_obj.lessthan(num2, num1) + _1: Primitive_object.lessthan(num2, num1) }) ], tl: { @@ -205,7 +205,7 @@ function isEqual(title, num1, num2) { param => ({ TAG: "Eq", _0: true, - _1: Caml_obj.lessequal(num2, num1) + _1: Primitive_object.lessequal(num2, num1) }) ], tl: { @@ -214,7 +214,7 @@ function isEqual(title, num1, num2) { param => ({ TAG: "Eq", _0: false, - _1: Caml_obj.greaterthan(num1, num2) + _1: Primitive_object.greaterthan(num1, num2) }) ], tl: { @@ -223,7 +223,7 @@ function isEqual(title, num1, num2) { param => ({ TAG: "Eq", _0: true, - _1: Caml_obj.greaterequal(num1, num2) + _1: Primitive_object.greaterequal(num1, num2) }) ], tl: { @@ -232,7 +232,7 @@ function isEqual(title, num1, num2) { param => ({ TAG: "Eq", _0: num1, - _1: Caml_obj.min(num1, num2) + _1: Primitive_object.min(num1, num2) }) ], tl: { @@ -241,7 +241,7 @@ function isEqual(title, num1, num2) { param => ({ TAG: "Eq", _0: num1, - _1: Caml_obj.max(num1, num2) + _1: Primitive_object.max(num1, num2) }) ], tl: { @@ -250,7 +250,7 @@ function isEqual(title, num1, num2) { param => ({ TAG: "Eq", _0: 0, - _1: Caml_obj.compare(num1, num2) + _1: Primitive_object.compare(num1, num2) }) ], tl: { @@ -259,7 +259,7 @@ function isEqual(title, num1, num2) { param => ({ TAG: "Eq", _0: 0, - _1: Caml_obj.compare(num2, num1) + _1: Primitive_object.compare(num2, num1) }) ], tl: { @@ -286,7 +286,7 @@ function isEqual(title, num1, num2) { param => ({ TAG: "Eq", _0: false, - _1: Caml_obj.notequal(num1, num2) + _1: Primitive_object.notequal(num1, num2) }) ], tl: { @@ -295,7 +295,7 @@ function isEqual(title, num1, num2) { param => ({ TAG: "Eq", _0: false, - _1: Caml_obj.notequal(num2, num1) + _1: Primitive_object.notequal(num2, num1) }) ], tl: { @@ -304,7 +304,7 @@ function isEqual(title, num1, num2) { param => ({ TAG: "Eq", _0: true, - _1: Caml_obj.equal(num1, num2) + _1: Primitive_object.equal(num1, num2) }) ], tl: { @@ -313,7 +313,7 @@ function isEqual(title, num1, num2) { param => ({ TAG: "Eq", _0: true, - _1: Caml_obj.equal(num2, num1) + _1: Primitive_object.equal(num2, num1) }) ], tl: { diff --git a/jscomp/test/caml_compare_test.js b/jscomp/test/caml_compare_test.js index 2ecd05a679..72a3801ee3 100644 --- a/jscomp/test/caml_compare_test.js +++ b/jscomp/test/caml_compare_test.js @@ -2,15 +2,15 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); let function_equal_test; try { - function_equal_test = Caml_obj.equal(x => x + 1 | 0, x => x + 2 | 0); + function_equal_test = Primitive_object.equal(x => x + 1 | 0, x => x + 2 | 0); } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + let exn = Primitive_exceptions.internalToException(raw_exn); function_equal_test = exn.RE_EXN_ID === "Invalid_argument" && exn._1 === "equal: functional value" ? true : false; } @@ -21,7 +21,7 @@ let suites = { () => ({ TAG: "Eq", _0: true, - _1: Caml_obj.lessthan(undefined, 1) + _1: Primitive_object.lessthan(undefined, 1) }) ], tl: { @@ -30,7 +30,7 @@ let suites = { () => ({ TAG: "Eq", _0: true, - _1: Caml_obj.lessthan(1, 2) + _1: Primitive_object.lessthan(1, 2) }) ], tl: { @@ -39,7 +39,7 @@ let suites = { () => ({ TAG: "Eq", _0: true, - _1: Caml_obj.greaterthan({ + _1: Primitive_object.greaterthan({ hd: 1, tl: /* [] */0 }, /* [] */0) @@ -51,7 +51,7 @@ let suites = { () => ({ TAG: "Eq", _0: true, - _1: Caml_obj.equal({ + _1: Primitive_object.equal({ hd: 1, tl: { hd: 2, @@ -78,7 +78,7 @@ let suites = { () => ({ TAG: "Eq", _0: true, - _1: Caml_obj.greaterthan({ + _1: Primitive_object.greaterthan({ hd: 1, tl: { hd: 2, @@ -105,7 +105,7 @@ let suites = { () => ({ TAG: "Eq", _0: true, - _1: Caml_obj.greaterthan([ + _1: Primitive_object.greaterthan([ { TAG: "A", _0: 3 @@ -142,7 +142,7 @@ let suites = { () => ({ TAG: "Eq", _0: true, - _1: Caml_obj.equal([ + _1: Primitive_object.equal([ { TAG: "A", _0: 3 @@ -188,7 +188,7 @@ let suites = { () => ({ TAG: "Eq", _0: true, - _1: Caml_obj.lessthan(undefined, 1) + _1: Primitive_object.lessthan(undefined, 1) }) ], tl: { @@ -197,7 +197,7 @@ let suites = { () => ({ TAG: "Eq", _0: true, - _1: Caml_obj.lessthan(undefined, [ + _1: Primitive_object.lessthan(undefined, [ 1, 30 ]) @@ -209,7 +209,7 @@ let suites = { () => ({ TAG: "Eq", _0: true, - _1: Caml_obj.greaterthan([ + _1: Primitive_object.greaterthan([ 1, 30 ], undefined) @@ -221,7 +221,7 @@ let suites = { () => ({ TAG: "Eq", _0: true, - _1: Caml_obj.lessthan({ + _1: Primitive_object.lessthan({ hd: 2, tl: { hd: 6, @@ -287,7 +287,7 @@ let suites = { () => ({ TAG: "Eq", _0: true, - _1: Caml_obj.lessthan({ + _1: Primitive_object.lessthan({ hd: 1, tl: /* [] */0 }, { @@ -305,7 +305,7 @@ let suites = { () => ({ TAG: "Eq", _0: true, - _1: Caml_obj.lessthan(/* [] */0, { + _1: Primitive_object.lessthan(/* [] */0, { hd: 409, tl: /* [] */0 }) @@ -317,7 +317,7 @@ let suites = { () => ({ TAG: "Eq", _0: true, - _1: Caml_obj.greaterthan({ + _1: Primitive_object.greaterthan({ hd: 2, tl: { hd: 6, @@ -401,7 +401,7 @@ let suites = { () => ({ TAG: "Eq", _0: false, - _1: Caml_obj.equal({ + _1: Primitive_object.equal({ hd: 2, tl: { hd: 6, @@ -467,7 +467,7 @@ let suites = { () => ({ TAG: "Eq", _0: false, - _1: Caml_obj.equal({ + _1: Primitive_object.equal({ hd: 2, tl: { hd: 6, @@ -532,7 +532,7 @@ let suites = { "cmp_id", () => ({ TAG: "Eq", - _0: Caml_obj.compare({ + _0: Primitive_object.compare({ x: 1, y: 2 }, { @@ -547,7 +547,7 @@ let suites = { "cmp_val", () => ({ TAG: "Eq", - _0: Caml_obj.compare({ + _0: Primitive_object.compare({ x: 1 }, { x: 2 @@ -560,7 +560,7 @@ let suites = { "cmp_val2", () => ({ TAG: "Eq", - _0: Caml_obj.compare({ + _0: Primitive_object.compare({ x: 2 }, { x: 1 @@ -573,7 +573,7 @@ let suites = { "cmp_empty", () => ({ TAG: "Eq", - _0: Caml_obj.compare({}, {}), + _0: Primitive_object.compare({}, {}), _1: 0 }) ], @@ -582,7 +582,7 @@ let suites = { "cmp_empty2", () => ({ TAG: "Eq", - _0: Caml_obj.compare({}, {x:1}), + _0: Primitive_object.compare({}, {x:1}), _1: -1 }) ], @@ -591,7 +591,7 @@ let suites = { "cmp_swap", () => ({ TAG: "Eq", - _0: Caml_obj.compare({ + _0: Primitive_object.compare({ x: 1, y: 2 }, { @@ -606,7 +606,7 @@ let suites = { "cmp_size", () => ({ TAG: "Eq", - _0: Caml_obj.compare({x:1}, {x:1, y:2}), + _0: Primitive_object.compare({x:1}, {x:1, y:2}), _1: -1 }) ], @@ -615,7 +615,7 @@ let suites = { "cmp_size2", () => ({ TAG: "Eq", - _0: Caml_obj.compare({x:1, y:2}, {x:1}), + _0: Primitive_object.compare({x:1, y:2}, {x:1}), _1: 1 }) ], @@ -624,7 +624,7 @@ let suites = { "cmp_order", () => ({ TAG: "Eq", - _0: Caml_obj.compare({ + _0: Primitive_object.compare({ x: 0, y: 1 }, { @@ -639,7 +639,7 @@ let suites = { "cmp_order2", () => ({ TAG: "Eq", - _0: Caml_obj.compare({ + _0: Primitive_object.compare({ x: 1, y: 0 }, { @@ -654,7 +654,7 @@ let suites = { "cmp_in_list", () => ({ TAG: "Eq", - _0: Caml_obj.compare({ + _0: Primitive_object.compare({ hd: { x: 1 }, @@ -673,7 +673,7 @@ let suites = { "cmp_in_list2", () => ({ TAG: "Eq", - _0: Caml_obj.compare({ + _0: Primitive_object.compare({ hd: { x: 2 }, @@ -692,7 +692,7 @@ let suites = { "cmp_with_list", () => ({ TAG: "Eq", - _0: Caml_obj.compare({ + _0: Primitive_object.compare({ x: { hd: 0, tl: /* [] */0 @@ -711,7 +711,7 @@ let suites = { "cmp_with_list2", () => ({ TAG: "Eq", - _0: Caml_obj.compare({ + _0: Primitive_object.compare({ x: { hd: 1, tl: /* [] */0 @@ -730,7 +730,7 @@ let suites = { "eq_id", () => ({ TAG: "Ok", - _0: Caml_obj.equal({ + _0: Primitive_object.equal({ x: 1, y: 2 }, { @@ -744,7 +744,7 @@ let suites = { "eq_val", () => ({ TAG: "Eq", - _0: Caml_obj.equal({ + _0: Primitive_object.equal({ x: 1 }, { x: 2 @@ -757,7 +757,7 @@ let suites = { "eq_val2", () => ({ TAG: "Eq", - _0: Caml_obj.equal({ + _0: Primitive_object.equal({ x: 2 }, { x: 1 @@ -770,7 +770,7 @@ let suites = { "eq_empty", () => ({ TAG: "Eq", - _0: Caml_obj.equal({}, {}), + _0: Primitive_object.equal({}, {}), _1: true }) ], @@ -779,7 +779,7 @@ let suites = { "eq_empty2", () => ({ TAG: "Eq", - _0: Caml_obj.equal({}, {x:1}), + _0: Primitive_object.equal({}, {x:1}), _1: false }) ], @@ -788,7 +788,7 @@ let suites = { "eq_swap", () => ({ TAG: "Ok", - _0: Caml_obj.equal({ + _0: Primitive_object.equal({ x: 1, y: 2 }, { @@ -802,7 +802,7 @@ let suites = { "eq_size", () => ({ TAG: "Eq", - _0: Caml_obj.equal({x:1}, {x:1, y:2}), + _0: Primitive_object.equal({x:1}, {x:1, y:2}), _1: false }) ], @@ -811,7 +811,7 @@ let suites = { "eq_size2", () => ({ TAG: "Eq", - _0: Caml_obj.equal({x:1, y:2}, {x:1}), + _0: Primitive_object.equal({x:1, y:2}, {x:1}), _1: false }) ], @@ -820,7 +820,7 @@ let suites = { "eq_in_list", () => ({ TAG: "Eq", - _0: Caml_obj.equal({ + _0: Primitive_object.equal({ hd: { x: 1 }, @@ -839,7 +839,7 @@ let suites = { "eq_in_list2", () => ({ TAG: "Eq", - _0: Caml_obj.equal({ + _0: Primitive_object.equal({ hd: { x: 2 }, @@ -858,7 +858,7 @@ let suites = { "eq_with_list", () => ({ TAG: "Eq", - _0: Caml_obj.equal({ + _0: Primitive_object.equal({ x: { hd: 0, tl: /* [] */0 @@ -877,7 +877,7 @@ let suites = { "eq_with_list2", () => ({ TAG: "Eq", - _0: Caml_obj.equal({ + _0: Primitive_object.equal({ x: { hd: 0, tl: /* [] */0 @@ -896,7 +896,7 @@ let suites = { "eq_no_prototype", () => ({ TAG: "Eq", - _0: Caml_obj.equal({x:1}, ((function(){let o = Object.create(null);o.x = 1;return o;})())), + _0: Primitive_object.equal({x:1}, ((function(){let o = Object.create(null);o.x = 1;return o;})())), _1: true }) ], @@ -905,7 +905,7 @@ let suites = { "File \"caml_compare_test.res\", line 76, characters 5-12", () => ({ TAG: "Eq", - _0: Caml_obj.compare(null, { + _0: Primitive_object.compare(null, { hd: 3, tl: /* [] */0 }), @@ -917,7 +917,7 @@ let suites = { "File \"caml_compare_test.res\", line 77, characters 5-12", () => ({ TAG: "Eq", - _0: Caml_obj.compare({ + _0: Primitive_object.compare({ hd: 3, tl: /* [] */0 }, null), @@ -929,7 +929,7 @@ let suites = { "File \"caml_compare_test.res\", line 78, characters 5-12", () => ({ TAG: "Eq", - _0: Caml_obj.compare(null, 0), + _0: Primitive_object.compare(null, 0), _1: -1 }) ], @@ -938,7 +938,7 @@ let suites = { "File \"caml_compare_test.res\", line 79, characters 5-12", () => ({ TAG: "Eq", - _0: Caml_obj.compare(0, null), + _0: Primitive_object.compare(0, null), _1: 1 }) ], @@ -947,7 +947,7 @@ let suites = { "File \"caml_compare_test.res\", line 80, characters 5-12", () => ({ TAG: "Eq", - _0: Caml_obj.compare(undefined, 0), + _0: Primitive_object.compare(undefined, 0), _1: -1 }) ], @@ -956,7 +956,7 @@ let suites = { "File \"caml_compare_test.res\", line 81, characters 5-12", () => ({ TAG: "Eq", - _0: Caml_obj.compare(0, undefined), + _0: Primitive_object.compare(0, undefined), _1: 1 }) ], @@ -1023,21 +1023,21 @@ function eq(loc, x, y) { Mt.eq_suites(test_id, suites, loc, x, y); } -eq("File \"caml_compare_test.res\", line 88, characters 3-10", true, Caml_obj.greaterthan(1, undefined)); +eq("File \"caml_compare_test.res\", line 88, characters 3-10", true, Primitive_object.greaterthan(1, undefined)); -eq("File \"caml_compare_test.res\", line 89, characters 3-10", true, Caml_obj.lessthan(/* [] */0, { +eq("File \"caml_compare_test.res\", line 89, characters 3-10", true, Primitive_object.lessthan(/* [] */0, { hd: 1, tl: /* [] */0 })); -eq("File \"caml_compare_test.res\", line 90, characters 3-10", false, Caml_obj.greaterthan(undefined, 1)); +eq("File \"caml_compare_test.res\", line 90, characters 3-10", false, Primitive_object.greaterthan(undefined, 1)); -eq("File \"caml_compare_test.res\", line 91, characters 3-10", false, Caml_obj.greaterthan(undefined, [ +eq("File \"caml_compare_test.res\", line 91, characters 3-10", false, Primitive_object.greaterthan(undefined, [ 1, 30 ])); -eq("File \"caml_compare_test.res\", line 92, characters 3-10", false, Caml_obj.lessthan([ +eq("File \"caml_compare_test.res\", line 92, characters 3-10", false, Primitive_object.lessthan([ 1, 30 ], undefined)); diff --git a/jscomp/test/caml_format_test.js b/jscomp/test/caml_format_test.js deleted file mode 100644 index cd25cfec4b..0000000000 --- a/jscomp/test/caml_format_test.js +++ /dev/null @@ -1,458 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let $$Array = require("../../lib/js/array.js"); -let Caml_int64 = require("../../lib/js/caml_int64.js"); -let Pervasives = require("../../lib/js/pervasives.js"); -let Caml_format = require("../../lib/js/caml_format.js"); - -let of_string = [ - [ - 0, - "0" - ], - [ - 3, - "03" - ], - [ - -3, - "-03" - ], - [ - -63, - "-0x3f" - ], - [ - -31, - "-0x1f" - ], - [ - 47, - "0X2f" - ], - [ - 11, - "0O13" - ], - [ - 8, - "0o10" - ], - [ - 3, - "0b11" - ], - [ - 1, - "0b01" - ], - [ - 0, - "0b00" - ], - [ - -3, - "-0b11" - ], - [ - -5, - "-0B101" - ], - [ - 332, - "0332" - ], - [ - -32, - "-32" - ], - [ - 1, - "-0xffff_ffff" - ], - [ - -1, - "0xffff_ffff" - ] -]; - -function from_float_of_string(xs) { - return $$Array.mapi((i, param) => Pervasives.string_of_float, xs); -} - -function from_of_string(xs) { - return $$Array.to_list($$Array.mapi((i, param) => { - let b = param[1]; - let a = param[0]; - return [ - "of_string " + String(i), - param => ({ - TAG: "Eq", - _0: Caml_format.int_of_string(b), - _1: a - }) - ]; - }, of_string)); -} - -let to_str = Caml_format.int_of_string; - -let pairs = [ - [ - "FP_infinite", - "infinity" - ], - [ - "FP_infinite", - "+infinity" - ], - [ - "FP_infinite", - "-infinity" - ], - [ - "FP_zero", - "0" - ], - [ - "FP_zero", - "0." - ] -]; - -let pairs$1 = [ - [ - 3232, - "32_32.0" - ], - [ - 1.000, - "1.000" - ], - [ - 12.000, - "12.000" - ] -]; - -let suites = Pervasives.$at(from_of_string(of_string), Pervasives.$at({ - hd: [ - "isnan_of_string", - () => ({ - TAG: "Eq", - _0: true, - _1: Pervasives.classify_float(Caml_format.float_of_string("nan")) === "FP_nan" - }) - ], - tl: /* [] */0 -}, Pervasives.$at($$Array.to_list($$Array.mapi((i, param) => { - let b = param[1]; - let a = param[0]; - return [ - "infinity_of_string " + String(i), - () => ({ - TAG: "Eq", - _0: a, - _1: Pervasives.classify_float(Caml_format.float_of_string(b)) - }) - ]; -}, pairs)), Pervasives.$at({ - hd: [ - "throw", - () => ({ - TAG: "ThrowAny", - _0: () => { - Caml_format.float_of_string(""); - } - }) - ], - tl: { - hd: [ - "format_int", - () => ({ - TAG: "Eq", - _0: " 33", - _1: Caml_format.format_int("%32d", 33) - }) - ], - tl: /* [] */0 - } -}, $$Array.to_list($$Array.mapi((i, param) => { - let b = param[1]; - let a = param[0]; - return [ - "normal_float_of_string " + String(i), - () => ({ - TAG: "Eq", - _0: a, - _1: Caml_format.float_of_string(b) - }) - ]; -}, pairs$1)))))); - -function ff(extra) { - return Caml_format.format_int("%32d", extra); -} - -let float_data = [ - [ - "%f", - 32, - "32.000000" - ], - [ - "%f", - Number.NaN, - "nan" - ], - [ - "%f", - Pervasives.infinity, - "inf" - ], - [ - "%f", - Pervasives.neg_infinity, - "-inf" - ], - [ - "%1.e", - 13000, - "1e+04" - ], - [ - "%1.3e", - 2.3e-05, - "2.300e-05" - ], - [ - "%3.10e", - 3e+56, - "3.0000000000e+56" - ], - [ - "%3.10f", - 20000000000, - "20000000000.0000000000" - ], - [ - "%3.3f", - -3300, - "-3300.000" - ], - [ - "%1.g", - 13000, - "1e+04" - ], - [ - "%1.3g", - 2.3e-05, - "2.3e-05" - ], - [ - "%3.10g", - 3e+56, - "3e+56" - ], - [ - "%3.10g", - 20000000000, - "2e+10" - ], - [ - "%3.3g", - -3300, - "-3.3e+03" - ], - [ - "%3.3g", - -0.0033, - "-0.0033" - ], - [ - "%3.10g", - 30000000000, - "3e+10" - ], - [ - "%3.0g", - 30000000000, - "3e+10" - ], - [ - "%3.g", - 30000000000, - "3e+10" - ], - [ - "%3.g", - 3, - " 3" - ], - [ - "%1.1g", - 2.1, - "2" - ], - [ - "%1.2g", - 2.1, - "2.1" - ] -]; - -let int64_suites_0 = [ - "i64_simple7", - param => ({ - TAG: "Eq", - _0: Caml_int64.to_string([ - 0, - 3333 - ]), - _1: "3333" - }) -]; - -let int64_suites_1 = { - hd: [ - "i64_simple15", - param => ({ - TAG: "Eq", - _0: Caml_int64.to_string(Caml_int64.neg_one), - _1: "-1" - }) - ], - tl: { - hd: [ - "i64_simple16", - param => ({ - TAG: "Eq", - _0: Caml_int64.to_string([ - -1, - 4294956185 - ]), - _1: "-11111" - }) - ], - tl: /* [] */0 - } -}; - -let int64_suites = { - hd: int64_suites_0, - tl: int64_suites_1 -}; - -let of_string_data = [ - [ - Caml_int64.zero, - "0" - ], - [ - [ - 0, - 3 - ], - "3" - ], - [ - [ - 0, - 33 - ], - "33" - ], - [ - [ - 0, - 333 - ], - "33_3" - ], - [ - [ - 0, - 33333 - ], - "33_33_3" - ], - [ - [ - 77, - 2620851541 - ], - "333333333333" - ], - [ - Caml_int64.neg_one, - "0xffff_ffff_ffff_ffff" - ], - [ - [ - 0, - 113 - ], - "0b01110001" - ], - [ - Caml_int64.one, - "-0xffff_ffff_ffff_ffff" - ] -]; - -Mt.from_pair_suites("Caml_format_test", Pervasives.$at(suites, Pervasives.$at($$Array.to_list($$Array.mapi((i, param) => { - let str_result = param[2]; - let f = param[1]; - let fmt = param[0]; - return [ - "loat_format " + String(i), - () => ({ - TAG: "Eq", - _0: Caml_format.format_float(fmt, f), - _1: str_result - }) - ]; -}, float_data)), Pervasives.$at(int64_suites, $$Array.to_list($$Array.mapi((i, param) => { - let b = param[1]; - let a = param[0]; - return [ - "int64_of_string " + String(i) + " ", - () => ({ - TAG: "Eq", - _0: Caml_format.int64_of_string(b), - _1: a - }) - ]; -}, of_string_data)))))); - -let float_suites = { - hd: "float_nan", - tl: /* [] */0 -}; - -let hh = [ - 214748364, - 3435973836 -]; - -let hhh = [ - 268435456, - 0 -]; - -exports.of_string = of_string; -exports.from_float_of_string = from_float_of_string; -exports.from_of_string = from_of_string; -exports.to_str = to_str; -exports.suites = suites; -exports.ff = ff; -exports.float_data = float_data; -exports.float_suites = float_suites; -exports.int64_suites = int64_suites; -exports.hh = hh; -exports.hhh = hhh; -exports.of_string_data = of_string_data; -/* suites Not a pure module */ diff --git a/jscomp/test/caml_format_test.res b/jscomp/test/caml_format_test.res deleted file mode 100644 index b2bf039c62..0000000000 --- a/jscomp/test/caml_format_test.res +++ /dev/null @@ -1,181 +0,0 @@ -@@warning("-107") - -let of_string = [ - (0, "0"), - (3, "03"), - (-3, "-03"), - (-63, "-0x3f"), - (-31, "-0x1f"), - (47, "0X2f"), - (11, "0O13"), - (8, "0o10"), - (3, "0b11"), - (1, "0b01"), - (0, "0b00"), - (-3, "-0b11"), - (-5, "-0B101"), - (332, "0332"), - (-32, "-32"), - (-4294967295, "-0xffff_ffff"), - (-1, "0xffff_ffff"), -] - -/* let float_of_string = */ -/* [| "nan", nan ; */ -/* "infinity", infinity; */ -/* "0.", 0. */ -/* |] */ - -let from_float_of_string = xs => Array.mapi((i, (a, b)) => string_of_float, xs) - -let from_of_string = xs => - Array.to_list( - Array.mapi( - (i, (a, b)) => (`of_string ${string_of_int(i)}`, _ => Mt.Eq(int_of_string(b), a)), - of_string, - ), - ) - -let to_str = s => int_of_string(s) - -external format_int: (string, int) => string = "?format_int" - -let suites: Mt.pair_suites = \"@"( - from_of_string(of_string), - \"@"( - list{("isnan_of_string", _ => Mt.Eq(true, classify_float(float_of_string("nan")) == FP_nan))}, - \"@"( - { - let pairs = [ - (FP_infinite, "infinity"), - (FP_infinite, "+infinity"), - (FP_infinite, "-infinity"), - (FP_zero, "0"), - (FP_zero, "0."), - ] - - Array.to_list( - Array.mapi( - (i, (a, b)) => ( - `infinity_of_string ${string_of_int(i)}`, - _ => Mt.Eq(a, \"@@"(classify_float, float_of_string(b))), - ), - pairs, - ), - ) - }, - \"@"( - list{ - ("throw", _ => Mt.ThrowAny(_ => \"@@"(ignore, float_of_string("")))), - ("format_int", _ => Mt.Eq(" 33", format_int("%32d", 33))), - }, - { - let pairs = [(3232., "32_32.0"), (1.000, "1.000"), (12.000, "12.000")] - - Array.to_list( - Array.mapi( - (i, (a, b)) => ( - `normal_float_of_string ${string_of_int(i)}`, - _ => Mt.Eq(a, float_of_string(b)), - ), - pairs, - ), - ) - }, - ), - ), - ), -) - -let ff = format_int("%32d", ...) - -external format_float: (string, float) => string = "?format_float" - -/* ("%3.10f", 3e+56, */ -/* "300000000000000005792779041490073052596128503513888063488.0000000000"); */ - -let float_data = [ - ("%f", 32., "32.000000"), - ("%f", nan, "nan"), - ("%f", infinity, "inf"), - ("%f", neg_infinity, "-inf"), - ("%1.e", 13000., "1e+04"), - ("%1.3e", 2.3e-05, "2.300e-05"), - ("%3.10e", 3e+56, "3.0000000000e+56"), - ("%3.10f", 20000000000., "20000000000.0000000000"), - ("%3.3f", -3300., "-3300.000"), - ("%1.g", 13000., "1e+04"), - ("%1.3g", 2.3e-05, "2.3e-05"), - ("%3.10g", 3e+56, "3e+56"), - ("%3.10g", 20000000000., "2e+10"), - ("%3.3g", -3300., "-3.3e+03"), - ("%3.3g", -0.0033, "-0.0033"), - ("%3.10g", 30000000000., "3e+10"), - ("%3.0g", 30000000000., "3e+10"), - ("%3.g", 30000000000., "3e+10"), - ("%3.g", 3., " 3"), - ("%1.1g", 2.1, "2"), - ("%1.2g", 2.1, "2.1"), -] - -let float_suites = { - open Mt - list{"float_nan"} -} - -/* module Mt = Mock_mt */ - -let int64_suites = { - open Mt - list{ - ("i64_simple7", _ => Eq(Int64.to_string(3333L), "3333")), - ("i64_simple15", _ => Eq(Int64.to_string(-1L), "-1")), - ("i64_simple16", _ => Eq(Int64.to_string(-11111L), "-11111")), - } -} - -let hh = 922337203685477580L /* 2 ^ 63 / 10 */ -let hhh = 1152921504606846976L -let of_string_data = [ - (0L, "0"), - (3L, "3"), - (33L, "33"), - (333L, "33_3"), - (33333L, "33_33_3"), - (333333333333L, "333333333333"), - (-1L, "0xffff_ffff_ffff_ffff"), - (113L, "0b01110001"), - (1L, "-0xffff_ffff_ffff_ffff"), -] - -/* module Mt = Mock_mt */ - -let () = \"@@"( - Mt.from_pair_suites(__MODULE__, ...), - \"@"( - suites, - \"@"( - Array.to_list( - Array.mapi( - (i, (fmt, f, str_result)) => ( - `loat_format ${string_of_int(i)}`, - _ => Mt.Eq(format_float(fmt, f), str_result), - ), - float_data, - ), - ), - \"@"( - int64_suites, - Array.to_list( - Array.mapi( - (i, (a, b)) => ( - `int64_of_string ${string_of_int(i)} `, - _ => Mt.Eq(Int64.of_string(b), a), - ), - of_string_data, - ), - ), - ), - ), - ) -) diff --git a/jscomp/test/chain_code_test.js b/jscomp/test/chain_code_test.js index 74d651ce60..b00658505f 100644 --- a/jscomp/test/chain_code_test.js +++ b/jscomp/test/chain_code_test.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -49,7 +49,7 @@ function f4(h, x, y) { ]; } -eq("File \"chain_code_test.res\", line 24, characters 12-19", 32, ({ +eq("File \"chain_code_test.res\", line 27, characters 12-19", 32, ({ x: { y: { z: 32 diff --git a/jscomp/test/chain_code_test.res b/jscomp/test/chain_code_test.res index cc02b684a7..dfdc23134e 100644 --- a/jscomp/test/chain_code_test.res +++ b/jscomp/test/chain_code_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let f = h => h["x"]["y"]["z"] diff --git a/jscomp/test/chn_test.js b/jscomp/test/chn_test.js index cbd83e9c6e..c73f9a3699 100644 --- a/jscomp/test/chn_test.js +++ b/jscomp/test/chn_test.js @@ -2,8 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let $$Array = require("../../lib/js/array.js"); -let Caml_string = require("../../lib/js/caml_string.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let suites = { contents: /* [] */0 @@ -17,7 +16,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -33,7 +32,7 @@ console.log("你好,\n世界"); console.log("\x3f\u003f\b\t\n\v\f\r\0\"'"); function convert(s) { - return $$Array.to_list(Array.from(s, x => { + return Belt_List.fromArray(Array.from(s, x => { let x$1 = x.codePointAt(0); if (x$1 !== undefined) { return x$1; @@ -42,7 +41,7 @@ function convert(s) { RE_EXN_ID: "Assert_failure", _1: [ "chn_test.res", - 18, + 23, 16 ], Error: new Error() @@ -50,9 +49,9 @@ function convert(s) { })); } -eq("File \"chn_test.res\", line 26, characters 4-11", "你好,\n世界", "你好,\n世界"); +eq("File \"chn_test.res\", line 31, characters 4-11", "你好,\n世界", "你好,\n世界"); -eq("File \"chn_test.res\", line 32, characters 4-11", convert("汉字是世界上最美丽的character"), { +eq("File \"chn_test.res\", line 37, characters 4-11", convert("汉字是世界上最美丽的character"), { hd: 27721, tl: { hd: 23383, @@ -111,7 +110,7 @@ eq("File \"chn_test.res\", line 32, characters 4-11", convert("汉字是世界 } }); -eq("File \"chn_test.res\", line 56, characters 5-12", convert("\x3f\x3fa"), { +eq("File \"chn_test.res\", line 61, characters 5-12", convert("\x3f\x3fa"), { hd: 63, tl: { hd: 63, @@ -122,7 +121,7 @@ eq("File \"chn_test.res\", line 56, characters 5-12", convert("\x3f\x3fa"), { } }); -eq("File \"chn_test.res\", line 57, characters 5-12", convert("??a"), { +eq("File \"chn_test.res\", line 62, characters 5-12", convert("??a"), { hd: 63, tl: { hd: 63, @@ -133,7 +132,7 @@ eq("File \"chn_test.res\", line 57, characters 5-12", convert("??a"), { } }); -eq("File \"chn_test.res\", line 58, characters 5-12", convert("\u003f\x3fa"), { +eq("File \"chn_test.res\", line 63, characters 5-12", convert("\u003f\x3fa"), { hd: 63, tl: { hd: 63, @@ -144,7 +143,7 @@ eq("File \"chn_test.res\", line 58, characters 5-12", convert("\u003f\x3fa"), { } }); -eq("File \"chn_test.res\", line 59, characters 5-12", convert("🚀🚀a"), { +eq("File \"chn_test.res\", line 64, characters 5-12", convert("🚀🚀a"), { hd: 128640, tl: { hd: 128640, @@ -155,7 +154,7 @@ eq("File \"chn_test.res\", line 59, characters 5-12", convert("🚀🚀a"), { } }); -eq("File \"chn_test.res\", line 60, characters 5-12", convert("\uD83D\uDE80a"), { +eq("File \"chn_test.res\", line 65, characters 5-12", convert("\uD83D\uDE80a"), { hd: 128640, tl: { hd: 97, @@ -163,7 +162,7 @@ eq("File \"chn_test.res\", line 60, characters 5-12", convert("\uD83D\uDE80a"), } }); -eq("File \"chn_test.res\", line 61, characters 5-12", convert("\uD83D\uDE80\x3f"), { +eq("File \"chn_test.res\", line 66, characters 5-12", convert("\uD83D\uDE80\x3f"), { hd: 128640, tl: { hd: 63, @@ -171,7 +170,7 @@ eq("File \"chn_test.res\", line 61, characters 5-12", convert("\uD83D\uDE80\x3f" } }); -eq("File \"chn_test.res\", line 65, characters 5-12", convert("\uD83D\uDE80\uD83D\uDE80a"), { +eq("File \"chn_test.res\", line 70, characters 5-12", convert("\uD83D\uDE80\uD83D\uDE80a"), { hd: 128640, tl: { hd: 128640, @@ -184,16 +183,16 @@ eq("File \"chn_test.res\", line 65, characters 5-12", convert("\uD83D\uDE80\uD83 eq("No inline string length", "\uD83D\uDE80\0".length, 3); -eq("File \"chn_test.res\", line 72, characters 4-11", Caml_string.get("\uD83D\uDE80\0", 0), 128640); +eq("File \"chn_test.res\", line 77, characters 4-11", "\uD83D\uDE80\0".codePointAt(0), 128640); -eq("File \"chn_test.res\", line 77, characters 5-12", Caml_string.get("🚀", 0), 128640); +eq("File \"chn_test.res\", line 82, characters 5-12", "🚀".codePointAt(0), 128640); -eq("File \"chn_test.res\", line 82, characters 5-12", convert("\uD83D\uDE80"), { +eq("File \"chn_test.res\", line 87, characters 5-12", convert("\uD83D\uDE80"), { hd: 128640, tl: /* [] */0 }); -eq("File \"chn_test.res\", line 83, characters 5-12", convert("\uD83D\uDE80\uD83D\uDE80"), { +eq("File \"chn_test.res\", line 88, characters 5-12", convert("\uD83D\uDE80\uD83D\uDE80"), { hd: 128640, tl: { hd: 128640, @@ -201,7 +200,7 @@ eq("File \"chn_test.res\", line 83, characters 5-12", convert("\uD83D\uDE80\uD83 } }); -eq("File \"chn_test.res\", line 84, characters 5-12", convert(" \b\t\n\v\f\ra"), { +eq("File \"chn_test.res\", line 89, characters 5-12", convert(" \b\t\n\v\f\ra"), { hd: 32, tl: { hd: 8, @@ -227,7 +226,7 @@ eq("File \"chn_test.res\", line 84, characters 5-12", convert(" \b\t\n\v\f\ra"), } }); -eq("File \"chn_test.res\", line 90, characters 5-12", convert(" \b\t\n\v\f\r\"'\\\0a"), { +eq("File \"chn_test.res\", line 95, characters 5-12", convert(" \b\t\n\v\f\r\"'\\\0a"), { hd: 32, tl: { hd: 8, diff --git a/jscomp/test/chn_test.res b/jscomp/test/chn_test.res index e7d3010a4b..9e9b743245 100644 --- a/jscomp/test/chn_test.res +++ b/jscomp/test/chn_test.res @@ -1,9 +1,14 @@ +open Belt + let suites: ref = ref(list{}) let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } Js.log(`你好, @@ -12,7 +17,7 @@ Js.log(`你好, Js.log(`\x3f\u003f\b\t\n\v\f\r\0"'`) let convert = (s: string): list => - Array.to_list( + List.fromArray( Js_array2.fromMap(Js_string.castToArrayLike(s), x => switch Js_string2.codePointAt(x, 0) { | None => assert(false) diff --git a/jscomp/test/coercion_module_alias_test.js b/jscomp/test/coercion_module_alias_test.js index 5d8e7c4612..2ce60262d5 100644 --- a/jscomp/test/coercion_module_alias_test.js +++ b/jscomp/test/coercion_module_alias_test.js @@ -2,7 +2,7 @@ 'use strict'; let Char = require("../../lib/js/char.js"); -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); function l(prim) { console.log(prim); @@ -10,24 +10,20 @@ function l(prim) { let C$p = Char; -let prim = Char.chr(66); +console.log(66); -console.log(prim); - -let prim$1 = Char.chr(66); - -console.log(prim$1); +console.log(66); let C3 = Char; -let prim$2 = Char.chr(66); +let prim = 66; -console.log(prim$2); +console.log(prim); -let f = List.length; +let f = Belt_List.length; function g(x) { - return List.length(List.map(prim => prim + 1 | 0, x)); + return Belt_List.length(Belt_List.map(x, prim => prim + 1 | 0)); } function F(X) { @@ -36,9 +32,9 @@ function F(X) { let C4 = Char; -let prim$3 = Char.chr(66); +let prim$1 = 66; -console.log(prim$3); +console.log(prim$1); function G(X) { return X; @@ -150,17 +146,17 @@ let M9 = { C$p: C$p$1 }; -let prim$4 = Char.chr(66); +let prim$2 = Char.chr(66); -console.log(prim$4); +console.log(prim$2); let M10 = { C$p: Char }; -let prim$5 = M10.C$p.chr(66); +let prim$3 = M10.C$p.chr(66); -console.log(prim$5); +console.log(prim$3); let C; @@ -209,4 +205,4 @@ exports.M7 = M7; exports.M8 = M8; exports.M9 = M9; exports.M10 = M10; -/* prim Not a pure module */ +/* Not a pure module */ diff --git a/jscomp/test/coercion_module_alias_test.res b/jscomp/test/coercion_module_alias_test.res index e89afae008..70cfb77cfb 100644 --- a/jscomp/test/coercion_module_alias_test.res +++ b/jscomp/test/coercion_module_alias_test.res @@ -1,3 +1,5 @@ +open Belt + let l = Js.log module C = Char @@ -22,7 +24,7 @@ let f = x => { } let g = x => { module L = List - L.length(L.map(succ, x)) + L.length(L.map(x, succ)) } module F = (X: {}) => Char diff --git a/jscomp/test/complex_if_test.js b/jscomp/test/complex_if_test.js deleted file mode 100644 index 15a13ed2bc..0000000000 --- a/jscomp/test/complex_if_test.js +++ /dev/null @@ -1,143 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let Bytes = require("../../lib/js/bytes.js"); -let Caml_bytes = require("../../lib/js/caml_bytes.js"); - -function fib(x) { - if (x !== 1 && x !== 23) { - return fib(x - 1 | 0) + fib(x - 2 | 0) | 0; - } else { - return 11111123; - } -} - -function escaped(s) { - let n = 0; - for (let i = 0, i_finish = s.length; i < i_finish; ++i) { - let match = s[i]; - n = n + ( - match >= 32 ? ( - match > 92 || match < 34 ? ( - match >= 127 ? 4 : 1 - ) : ( - match > 91 || match < 35 ? 2 : 1 - ) - ) : ( - match >= 11 ? ( - match !== 13 ? 4 : 2 - ) : ( - match >= 8 ? 2 : 4 - ) - ) - ) | 0; - } - if (n === s.length) { - return Bytes.copy(s); - } - let s$p = Caml_bytes.create(n); - n = 0; - for (let i$1 = 0, i_finish$1 = s.length; i$1 < i_finish$1; ++i$1) { - let c = s[i$1]; - let exit = 0; - if (c >= 35) { - if (c !== 92) { - if (c >= 127) { - exit = 1; - } else { - s$p[n] = c; - } - } else { - exit = 2; - } - } else if (c >= 32) { - if (c >= 34) { - exit = 2; - } else { - s$p[n] = c; - } - } else if (c >= 14) { - exit = 1; - } else { - switch (c) { - case 8 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 'b' */98; - break; - case 9 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 't' */116; - break; - case 10 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 'n' */110; - break; - case 0 : - case 1 : - case 2 : - case 3 : - case 4 : - case 5 : - case 6 : - case 7 : - case 11 : - case 12 : - exit = 1; - break; - case 13 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 'r' */114; - break; - } - } - switch (exit) { - case 1 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = 48 + (c / 100 | 0) | 0; - n = n + 1 | 0; - s$p[n] = 48 + (c / 10 | 0) % 10 | 0; - n = n + 1 | 0; - s$p[n] = 48 + c % 10 | 0; - break; - case 2 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = c; - break; - } - n = n + 1 | 0; - } - return s$p; -} - -function string_escaped(s) { - return Bytes.to_string(escaped(Bytes.of_string(s))); -} - -let suites_0 = [ - "complete_escape", - param => ({ - TAG: "Eq", - _0: Bytes.to_string(escaped(Bytes.of_string("\x00\x01\x02\x03\x04\x05\x06\x07\b\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"))), - _1: "\\000\\001\\002\\003\\004\\005\\006\\007\\b\\t\\n\\011\\012\\r\\014\\015\\016\\017\\018\\019\\020\\021\\022\\023\\024\\025\\026\\027\\028\\029\\030\\031 !\\\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\\127\\128\\129\\130\\131\\132\\133\\134\\135\\136\\137\\138\\139\\140\\141\\142\\143\\144\\145\\146\\147\\148\\149\\150\\151\\152\\153\\154\\155\\156\\157\\158\\159\\160\\161\\162\\163\\164\\165\\166\\167\\168\\169\\170\\171\\172\\173\\174\\175\\176\\177\\178\\179\\180\\181\\182\\183\\184\\185\\186\\187\\188\\189\\190\\191\\192\\193\\194\\195\\196\\197\\198\\199\\200\\201\\202\\203\\204\\205\\206\\207\\208\\209\\210\\211\\212\\213\\214\\215\\216\\217\\218\\219\\220\\221\\222\\223\\224\\225\\226\\227\\228\\229\\230\\231\\232\\233\\234\\235\\236\\237\\238\\239\\240\\241\\242\\243\\244\\245\\246\\247\\248\\249\\250\\251\\252\\253\\254\\255" - }) -]; - -let suites = { - hd: suites_0, - tl: /* [] */0 -}; - -Mt.from_pair_suites("Complex_if_test", suites); - -exports.fib = fib; -exports.escaped = escaped; -exports.string_escaped = string_escaped; -exports.suites = suites; -/* Not a pure module */ diff --git a/jscomp/test/complex_if_test.res b/jscomp/test/complex_if_test.res deleted file mode 100644 index c3e838f8df..0000000000 --- a/jscomp/test/complex_if_test.res +++ /dev/null @@ -1,82 +0,0 @@ -let rec fib = x => - switch x { - | 1 | 23 => 11111123 - | n => fib(n - 1) + fib(n - 2) - } - -open Bytes -external char_code: char => int = "%identity" -external char_chr: int => char = "%identity" - -let escaped = s => { - let n = ref(0) - for i in 0 to length(s) - 1 { - n := - n.contents + - switch unsafe_get(s, i) { - | '"' | '\\' | '\n' | '\t' | '\r' | '\b' => 2 - | ' ' .. '~' => 1 - | _ => 4 - } - } - if n.contents == length(s) { - copy(s) - } else { - let s' = create(n.contents) - n := 0 - for i in 0 to length(s) - 1 { - switch unsafe_get(s, i) { - | ('"' | '\\') as c => - unsafe_set(s', n.contents, '\\') - incr(n) - unsafe_set(s', n.contents, c) - | '\n' => - unsafe_set(s', n.contents, '\\') - incr(n) - unsafe_set(s', n.contents, 'n') - | '\t' => - unsafe_set(s', n.contents, '\\') - incr(n) - unsafe_set(s', n.contents, 't') - | '\r' => - unsafe_set(s', n.contents, '\\') - incr(n) - unsafe_set(s', n.contents, 'r') - | '\b' => - unsafe_set(s', n.contents, '\\') - incr(n) - unsafe_set(s', n.contents, 'b') - | ' ' .. '~' as c => unsafe_set(s', n.contents, c) - | c => - let a = char_code(c) - unsafe_set(s', n.contents, '\\') - incr(n) - unsafe_set(s', n.contents, char_chr(48 + a / 100)) - incr(n) - unsafe_set(s', n.contents, char_chr(48 + mod(a / 10, 10))) - incr(n) - unsafe_set(s', n.contents, char_chr(48 + mod(a, 10))) - } - incr(n) - } - s' - } -} -let string_escaped = s => Bytes.to_string(escaped(Bytes.of_string(s))) - -/* let s = (let v = ref "" in for i = 0 to 255 do v := !v ^ (String.make 1 (Char.chr i)) done ; !v);; */ -let suites = { - open Mt - list{ - ( - "complete_escape", - _ => Eq( - string_escaped( - "\x00\x01\x02\x03\x04\x05\x06\x07\b\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff", - ), - "\\000\\001\\002\\003\\004\\005\\006\\007\\b\\t\\n\\011\\012\\r\\014\\015\\016\\017\\018\\019\\020\\021\\022\\023\\024\\025\\026\\027\\028\\029\\030\\031 !\\\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\\127\\128\\129\\130\\131\\132\\133\\134\\135\\136\\137\\138\\139\\140\\141\\142\\143\\144\\145\\146\\147\\148\\149\\150\\151\\152\\153\\154\\155\\156\\157\\158\\159\\160\\161\\162\\163\\164\\165\\166\\167\\168\\169\\170\\171\\172\\173\\174\\175\\176\\177\\178\\179\\180\\181\\182\\183\\184\\185\\186\\187\\188\\189\\190\\191\\192\\193\\194\\195\\196\\197\\198\\199\\200\\201\\202\\203\\204\\205\\206\\207\\208\\209\\210\\211\\212\\213\\214\\215\\216\\217\\218\\219\\220\\221\\222\\223\\224\\225\\226\\227\\228\\229\\230\\231\\232\\233\\234\\235\\236\\237\\238\\239\\240\\241\\242\\243\\244\\245\\246\\247\\248\\249\\250\\251\\252\\253\\254\\255", - ), - ), - } -} -Mt.from_pair_suites(__MODULE__, suites) diff --git a/jscomp/test/complex_test.js b/jscomp/test/complex_test.js deleted file mode 100644 index e822054260..0000000000 --- a/jscomp/test/complex_test.js +++ /dev/null @@ -1,27 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let Complex = require("../../lib/js/complex.js"); - -let suites_0 = [ - "basic_add", - param => ({ - TAG: "Eq", - _0: { - re: 2, - im: 2 - }, - _1: Complex.add(Complex.add(Complex.add(Complex.one, Complex.one), Complex.i), Complex.i) - }) -]; - -let suites = { - hd: suites_0, - tl: /* [] */0 -}; - -Mt.from_pair_suites("Complex_test", suites); - -exports.suites = suites; -/* Not a pure module */ diff --git a/jscomp/test/complex_test.res b/jscomp/test/complex_test.res deleted file mode 100644 index ab34efa39d..0000000000 --- a/jscomp/test/complex_test.res +++ /dev/null @@ -1,8 +0,0 @@ -open Complex - -let suites = { - open Mt - list{("basic_add", _ => Eq({re: 2., im: 2.}, add(add(add(one, one), i), i)))} -} - -Mt.from_pair_suites(__MODULE__, suites) diff --git a/jscomp/test/complex_while_loop.js b/jscomp/test/complex_while_loop.js index 74fe66fea8..cd4fa0c7eb 100644 --- a/jscomp/test/complex_while_loop.js +++ b/jscomp/test/complex_while_loop.js @@ -14,7 +14,7 @@ function f() { }; return fib(n) > 10; })()) { - console.log(String(n)); + console.log(n.toString()); n = n + 1 | 0; }; } diff --git a/jscomp/test/complex_while_loop.res b/jscomp/test/complex_while_loop.res index eb6cf4d3e5..7fceaac61a 100644 --- a/jscomp/test/complex_while_loop.res +++ b/jscomp/test/complex_while_loop.res @@ -8,7 +8,7 @@ let f = () => { } fib(n.contents) > 10 } { - print_endline(string_of_int(n.contents)) + n.contents->Js.Int.toString->Js.log incr(n) } } diff --git a/jscomp/test/condition_compilation_test.js b/jscomp/test/condition_compilation_test.js index da2f401b42..5bca8c3fab 100644 --- a/jscomp/test/condition_compilation_test.js +++ b/jscomp/test/condition_compilation_test.js @@ -23,7 +23,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -34,9 +34,9 @@ function eq(loc, x, y) { }; } -eq("File \"condition_compilation_test.res\", line 60, characters 5-12", 3, 3); +eq("File \"condition_compilation_test.res\", line 63, characters 5-12", 3, 3); -eq("File \"condition_compilation_test.res\", line 61, characters 5-12", v.contents, 2); +eq("File \"condition_compilation_test.res\", line 64, characters 5-12", v.contents, 2); Mt.from_pair_suites("Condition_compilation_test", suites.contents); diff --git a/jscomp/test/condition_compilation_test.res b/jscomp/test/condition_compilation_test.res index c988eba721..5bf56bed1b 100644 --- a/jscomp/test/condition_compilation_test.res +++ b/jscomp/test/condition_compilation_test.res @@ -53,7 +53,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let () = { diff --git a/jscomp/test/console_log_test.js b/jscomp/test/console_log_test.js index a366b77f4e..a26d6b1808 100644 --- a/jscomp/test/console_log_test.js +++ b/jscomp/test/console_log_test.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_obj = require("../../lib/js/caml_obj.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); function min_int(prim0, prim1) { return Math.min(prim0, prim1); @@ -11,7 +11,7 @@ function say(prim0, prim1) { return prim0.say(prim1); } -let v = Caml_obj.compare; +let v = Primitive_object.compare; exports.min_int = min_int; exports.say = say; diff --git a/jscomp/test/const_block_test.js b/jscomp/test/const_block_test.js index bbe5d66ae1..8710e9f35a 100644 --- a/jscomp/test/const_block_test.js +++ b/jscomp/test/const_block_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_array = require("../../lib/js/caml_array.js"); +let Primitive_array = require("../../lib/js/primitive_array.js"); let a = [ 0, @@ -26,8 +26,8 @@ let c = [ ]; function f() { - Caml_array.set(a, 0, 3.0); - Caml_array.set(b, 0, 3); + Primitive_array.set(a, 0, 3.0); + Primitive_array.set(b, 0, 3); } function h() { @@ -39,8 +39,8 @@ function g() { return { TAG: "Eq", _0: [ - Caml_array.get(a, 0), - Caml_array.get(b, 0) + Primitive_array.get(a, 0), + Primitive_array.get(b, 0) ], _1: [ 3.0, @@ -58,8 +58,8 @@ let suites_1 = { hd: [ "avoid_mutable_inline_test", () => { - Caml_array.set(c, 0, 3); - Caml_array.set(c, 1, 4); + Primitive_array.set(c, 0, 3); + Primitive_array.set(c, 1, 4); return { TAG: "Eq", _0: [ diff --git a/jscomp/test/cps_test.js b/jscomp/test/cps_test.js index 89b9d6eb94..15eb645e43 100644 --- a/jscomp/test/cps_test.js +++ b/jscomp/test/cps_test.js @@ -2,8 +2,8 @@ 'use strict'; let Mt = require("./mt.js"); -let $$Array = require("../../lib/js/array.js"); -let Caml_array = require("../../lib/js/caml_array.js"); +let Belt_Array = require("../../lib/js/belt_Array.js"); +let Primitive_array = require("../../lib/js/primitive_array.js"); function test() { let v = { @@ -32,13 +32,13 @@ function test_closure() { let v = { contents: 0 }; - let arr = Caml_array.make(6, x => x); + let arr = Belt_Array.make(6, x => x); for (let i = 0; i <= 5; ++i) { - Caml_array.set(arr, i, param => i); + Primitive_array.set(arr, i, param => i); } - $$Array.iter(i => { + Belt_Array.forEach(arr, i => { v.contents = v.contents + i(0) | 0; - }, arr); + }); return v.contents; } @@ -46,14 +46,14 @@ function test_closure2() { let v = { contents: 0 }; - let arr = Caml_array.make(6, x => x); + let arr = Belt_Array.make(6, x => x); for (let i = 0; i <= 5; ++i) { let j = i + i | 0; - Caml_array.set(arr, i, param => j); + Primitive_array.set(arr, i, param => j); } - $$Array.iter(i => { + Belt_Array.forEach(arr, i => { v.contents = v.contents + i(0) | 0; - }, arr); + }); return v.contents; } diff --git a/jscomp/test/cps_test.res b/jscomp/test/cps_test.res index 4c4ee70940..01f9004efc 100644 --- a/jscomp/test/cps_test.res +++ b/jscomp/test/cps_test.res @@ -16,23 +16,23 @@ let test = () => { let test_closure = () => { let n = 6 let v = ref(0) - let arr = Array.make(n, x => x) + let arr = Belt.Array.make(n, x => x) for i in 0 to n - 1 { arr[i] = _ => i } - Array.iter(i => v := v.contents + i(0), arr) + arr->Belt.Array.forEach(i => v := v.contents + i(0)) v.contents } let test_closure2 = () => { let n = 6 let v = ref(0) - let arr = Array.make(n, x => x) + let arr = Belt.Array.make(n, x => x) for i in 0 to n - 1 { let j = i + i arr[i] = _ => j } - Array.iter(i => v := v.contents + i(0), arr) + arr->Belt.Array.forEach(i => v := v.contents + i(0)) v.contents } diff --git a/jscomp/test/custom_error_test.js b/jscomp/test/custom_error_test.js index 882aa937a0..c4549b0f05 100644 --- a/jscomp/test/custom_error_test.js +++ b/jscomp/test/custom_error_test.js @@ -2,14 +2,14 @@ 'use strict'; let Js_exn = require("../../lib/js/js_exn.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); function test_js_error() { let e; try { e = JSON.parse(" {\"x\" : }"); } catch (raw_err) { - let err = Caml_js_exceptions.internalToOCamlException(raw_err); + let err = Primitive_exceptions.internalToException(raw_err); if (err.RE_EXN_ID === Js_exn.$$Error) { console.log(err._1.stack); return; @@ -23,7 +23,7 @@ function test_js_error2() { try { return JSON.parse(" {\"x\" : }"); } catch (raw_e) { - let e = Caml_js_exceptions.internalToOCamlException(raw_e); + let e = Primitive_exceptions.internalToException(raw_e); if (e.RE_EXN_ID === Js_exn.$$Error) { console.log(e._1.stack); throw e; @@ -37,7 +37,7 @@ function example1() { try { v = JSON.parse(" {\"x\" }"); } catch (raw_err) { - let err = Caml_js_exceptions.internalToOCamlException(raw_err); + let err = Primitive_exceptions.internalToException(raw_err); if (err.RE_EXN_ID === Js_exn.$$Error) { console.log(err._1.stack); return; @@ -51,7 +51,7 @@ function example2() { try { return JSON.parse(" {\"x\"}"); } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + let exn = Primitive_exceptions.internalToException(raw_exn); if (exn.RE_EXN_ID === Js_exn.$$Error) { return; } diff --git a/jscomp/test/defunctor_make_test.js b/jscomp/test/defunctor_make_test.js index efc2f442f8..2b30da619f 100644 --- a/jscomp/test/defunctor_make_test.js +++ b/jscomp/test/defunctor_make_test.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml = require("../../lib/js/caml.js"); +let Primitive_int = require("../../lib/js/primitive_int.js"); function getcompare(x) { return x; @@ -147,13 +147,13 @@ function empty(v) { }; } -let compare = Caml.int_compare; +let compare = Primitive_int.compare; let V0 = { compare: compare }; -let compare$1 = Caml.int_compare; +let compare$1 = Primitive_int.compare; let V1 = { compare: compare$1 diff --git a/jscomp/test/demo_int_map.js b/jscomp/test/demo_int_map.js index 71b93d86cc..9355999c5b 100644 --- a/jscomp/test/demo_int_map.js +++ b/jscomp/test/demo_int_map.js @@ -1,162 +1,15 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; - -function height(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} - -function create(l, x, d, r) { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} - -function bal(l, x, d, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; -} - -function add(x, data, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = x - v | 0; - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function find(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let c = x - param.v | 0; - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} +let Belt_MapInt = require("../../lib/js/belt_MapInt.js"); function test() { - let m = "Empty"; + let m; for (let i = 0; i <= 1000000; ++i) { - m = add(i, i, m); + m = Belt_MapInt.set(m, i, i); } for (let i$1 = 0; i$1 <= 1000000; ++i$1) { - find(i$1, m); + Belt_MapInt.get(m, i$1); } } diff --git a/jscomp/test/demo_int_map.res b/jscomp/test/demo_int_map.res index d2ec1f1905..d549afc645 100644 --- a/jscomp/test/demo_int_map.res +++ b/jscomp/test/demo_int_map.res @@ -1,16 +1,13 @@ -module IntMap = Map.Make({ - type t = int - let compare = (x: int, y) => x - y -}) +open Belt let test = () => { - let m = ref(IntMap.empty) + let m = ref(Map.Int.empty) let count = 1000_000 for i in 0 to count { - m := IntMap.add(i, i, m.contents) + m := m.contents->Map.Int.set(i, i) } for i in 0 to count { - ignore(IntMap.find(i, m.contents)) + m.contents->Map.Int.get(i)->ignore } } diff --git a/jscomp/test/digest_test.js b/jscomp/test/digest_test.js deleted file mode 100644 index 732af43acb..0000000000 --- a/jscomp/test/digest_test.js +++ /dev/null @@ -1,218 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let $$Array = require("../../lib/js/array.js"); -let Digest = require("../../lib/js/digest.js"); -let Caml_array = require("../../lib/js/caml_array.js"); -let Pervasives = require("../../lib/js/pervasives.js"); -let Ext_array_test = require("./ext_array_test.js"); - -function f(x) { - return Digest.to_hex(Digest.string(x)); -} - -let ref = [ - "d41d8cd98f00b204e9800998ecf8427e", - "0cc175b9c0f1b6a831c399e269772661", - "4124bc0a9335c27f086f24ba207a4912", - "47bce5c74f589f4867dbd57e9ca9f808", - "74b87337454200d4d33f80c4663dc5e5", - "594f803b380a41396ed63dca39503542", - "0b4e7a0e5fe84ad35fb5f95b9ceeac79", - "5d793fc5b00a2348c3fb9ab59e5ca98a", - "3dbe00a167653a1aaee01d93e77e730e", - "552e6a97297c53e592208cf97fbb3b60", - "e09c80c42fda55f9d992e59ca6b3307d", - "d57f21e6a273781dbf8b7657940f3b03", - "45e4812014d83dde5666ebdf5a8ed1ed", - "c162de19c4c3731ca3428769d0cd593d", - "451599a5f9afa91a0f2097040a796f3d", - "12f9cf6998d52dbe773b06f848bb3608", - "23ca472302f49b3ea5592b146a312da0", - "88e42e96cc71151b6e1938a1699b0a27", - "2c60c24e7087e18e45055a33f9a5be91", - "639d76897485360b3147e66e0a8a3d6c", - "22d42eb002cefa81e9ad604ea57bc01d", - "bd049f221af82804c5a2826809337c9b", - "ff49cfac3968dbce26ebe7d4823e58bd", - "d95dbfee231e34cccb8c04444412ed7d", - "40edae4bad0e5bf6d6c2dc5615a86afb", - "a5a8bfa3962f49330227955e24a2e67c", - "ae791f19bdf77357ff10bb6b0e97e121", - "aaab9c59a88bf0bdfcb170546c5459d6", - "b0f0545856af1a340acdedce23c54b97", - "f7ce3d7d44f3342107d884bfa90c966a", - "59e794d45697b360e18ba972bada0123", - "3b0845db57c200be6052466f87b2198a", - "5eca9bd3eb07c006cd43ae48dfde7fd3", - "b4f13cb081e412f44e99742cb128a1a5", - "4c660346451b8cf91ef50f4634458d41", - "11db24dc3f6c2145701db08625dd6d76", - "80dad3aad8584778352c68ab06250327", - "1227fe415e79db47285cb2689c93963f", - "8e084f489f1bdf08c39f98ff6447ce6d", - "08b2f2b0864bac1ba1585043362cbec9", - "4697843037d962f62a5a429e611e0f5f", - "10c4da18575c092b486f8ab96c01c02f", - "af205d729450b663f48b11d839a1c8df", - "0d3f91798fac6ee279ec2485b25f1124", - "4c3c7c067634daec9716a80ea886d123", - "d1e358e6e3b707282cdd06e919f7e08c", - "8c6ded4f0af86e0a7e301f8a716c4363", - "4c2d8bcb02d982d7cb77f649c0a2dea8", - "bdb662f765cd310f2a547cab1cfecef6", - "08ff5f7301d30200ab89169f6afdb7af", - "6eb6a030bcce166534b95bc2ab45d9cf", - "1bb77918e5695c944be02c16ae29b25e", - "b6fe77c19f0f0f4946c761d62585bfea", - "e9e7e260dce84ffa6e0e7eb5fd9d37fc", - "eced9e0b81ef2bba605cbc5e2e76a1d0", - "ef1772b6dff9a122358552954ad0df65", - "3b0c8ac703f828b04c6c197006d17218", - "652b906d60af96844ebd21b674f35e93", - "dc2f2f2462a0d72358b2f99389458606", - "762fc2665994b217c52c3c2eb7d9f406", - "cc7ed669cf88f201c3297c6a91e1d18d", - "cced11f7bbbffea2f718903216643648", - "24612f0ce2c9d2cf2b022ef1e027a54f", - "b06521f39153d618550606be297466d5", - "014842d480b571495a4a0363793f7367", - "c743a45e0d2e6a95cb859adae0248435", - "def5d97e01e1219fb2fc8da6c4d6ba2f", - "92cb737f8687ccb93022fdb411a77cca", - "a0d1395c7fb36247bfe2d49376d9d133", - "ab75504250558b788f99d1ebd219abf2", - "0f5c6c4e740bfcc08c3c26ccb2673d46", - "cddd19bec7f310d8c87149ef47a1828f", - "96b39b8b95e016c79d104d83395b8133", - "f1fc0b14ff8fa674b02344577e23eeb1", - "0e8d28a1cafa3ffcff22afd480cce7d8", - "448539ffc17e1e81005b65581855cef4", - "61e39aae7c53e6e77db2e4405d9fb157", - "618a426895ee6133a372bebd1129b63e", - "046c90690c9e36578b9d4a7e1d249c75", - "aadab38075c43296ee7e12466ebb03e3", - "b15af9cdabbaea0516866a33d8fd0f98", - "986e6938ed767a8ae9530eef54bfe5f1", - "7ae25a72b71a42ccbc5477fd989cd512", - "98d34e50d4aa7a893cc7919a91acb0e3", - "3fc53fc22ea40f1a0afd78fc2cd9aa0f", - "923e37c738b9d7b1526f70b65229cc3d", - "b3966b7a08e5d46fd0774b797ba78dc2", - "f50c7286b540bb181db1d6e05a51a296", - "4efd6c8826e65a61f82af954d431b59b", - "ef1031e79e7a15a4470a5e98b23781b5", - "067876bfd0df0f4c5002780ec85e6f8c", - "789851dfa4c03563e9cef5f7bc050a7e", - "baf934720818ee49477e74fc644faa5e", - "9a0ea77ca26d2c121ddcc179edb76308", - "20c825561572e33d026f99ddfd999538", - "464c461455c5a927079a13609c20b637", - "cf37d42f89b6adb0e1a9e99104501b82", - "d266af45e3d06b70d9f52e2df4344186", - "f8b59fa22eb0ba944e2b7aa24d67b681", - "0918d7c2f9062743450a86eae9dde1a3", - "36a92cc94a9e0fa21f625f8bfb007adf", - "681d73898dad5685d48b5e8438bc3a66", - "337ccef058459c3c16411381778da0c4", - "6ccdfcc742862036ce07583633c5f77e", - "ddfa1adc974649dc5b414be86def7457", - "650ebc28ad85f11aa4b63b6ee565b89d", - "e4571793bcaba284017eeabd8df85697", - "4fc040d354ad9ba5e4f62862109d3e17", - "25814274e02aa7cc03d6314eb703e655", - "11378ecaee0089c840d26352704027e3", - "86f950bfcd824d5546da01c40576db31", - "089f243d1e831c5879aa375ee364a06e", - "9146ef3527c7cfcc66dc615c3986e391", - "d727cfdfc9ed0347e6917a68b982f7bc", - "da8f45e1fdc12deecfe56aeb5288796e", - "29cfcf52d8250a253a535cf7989c7bd2", - "0f6eb555b8e3c35411eebe9348594193", - "a922439f963e7e59040e4756992c6f1b", - "81f8453cf3f7e5ee5479c777e5a8d80c", - "8a7bd0732ed6a28ce75f6dabc90e1613", - "5f61c0ccad4cac44c75ff505e1f1e537", - "f6acfca2d47c87f2b14ca038234d3614", - "269fc62c517f3d55c368152addca57e7", - "50587cb16413da779b35508018721647", - "5e4a3ecfdaa4636b84a39b6a7be7c047", - "c5339dc2af6bf595580281ffb07353f6", - "e51176a47347e167ed0ed766b6de1a0c", - "020406e1d05cdc2aa287641f7ae2cc39", - "e510683b3f5ffe4093d021808bc6ff70", - "b325dc1c6f5e7a2b7cf465b9feab7948" -]; - -Mt.from_pair_suites("Digest_test", Pervasives.$at({ - hd: [ - "File \"digest_test.res\", line 9, characters 9-16", - () => ({ - TAG: "Eq", - _0: Digest.to_hex(Digest.string("value")), - _1: "2063c1608d6e0baf80249c42e2be5804" - }) - ], - tl: { - hd: [ - "File \"digest_test.res\", line 11, characters 10-17", - () => ({ - TAG: "Eq", - _0: Digest.to_hex(Digest.string("The quick brown fox jumps over the lazy dog")), - _1: "9e107d9d372bb6826bd81d3542a419d6" - }) - ], - tl: { - hd: [ - "File \"digest_test.res\", line 18, characters 10-17", - () => ({ - TAG: "Eq", - _0: Digest.to_hex(Digest.string("The quick brown fox jumps over the lazy dog.")), - _1: "e4d909c290d0fb1ca068ffaddf22cbd0" - }) - ], - tl: { - hd: [ - "File \"digest_test.res\", line 24, characters 9-16", - () => ({ - TAG: "Eq", - _0: Digest.to_hex(Digest.string("")), - _1: "d41d8cd98f00b204e9800998ecf8427e" - }) - ], - tl: { - hd: [ - "File \"digest_test.res\", line 26, characters 10-17", - () => ({ - TAG: "Eq", - _0: Digest.to_hex(Digest.string("The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.")), - _1: "7065cc36bba1d155fb09f9d02f22e8bf" - }) - ], - tl: { - hd: [ - "File \"digest_test.res\", line 45, characters 10-17", - () => ({ - TAG: "Eq", - _0: Digest.to_hex(Digest.string("The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.The quick brown fox jumps over the lazy dog.")), - _1: "b9193d1df4b7a8f0a25ffdd1005c5b2b" - }) - ], - tl: /* [] */0 - } - } - } - } - } -}, $$Array.to_list($$Array.map(i => [ - String(i), - () => ({ - TAG: "Eq", - _0: Digest.to_hex(Digest.string("a".repeat(i))), - _1: Caml_array.get(ref, i) - }) -], Ext_array_test.range(0, 129))))); - -exports.f = f; -/* Not a pure module */ diff --git a/jscomp/test/digest_test.res b/jscomp/test/digest_test.res deleted file mode 100644 index 96ce3f2931..0000000000 --- a/jscomp/test/digest_test.res +++ /dev/null @@ -1,202 +0,0 @@ -let f = x => \"@@"(Digest.to_hex, Digest.string(x)) - -\"@@"( - Mt.from_pair_suites(__MODULE__, ...), - \"@"( - { - open Mt - list{ - (__LOC__, _ => Eq(f("value"), "2063c1608d6e0baf80249c42e2be5804")), - ( - __LOC__, - _ => Eq( - f("The quick brown fox jumps over the lazy dog"), - "9e107d9d372bb6826bd81d3542a419d6", - ), - ), - ( - __LOC__, - _ => Eq( - f("The quick brown fox jumps over the lazy dog."), - "e4d909c290d0fb1ca068ffaddf22cbd0", - ), - ), - (__LOC__, _ => Eq(f(""), "d41d8cd98f00b204e9800998ecf8427e")), - ( - __LOC__, - _ => Eq( - f( - "The quick brown fox jumps over the lazy dog." ++ - ("The quick brown fox jumps over the lazy dog." ++ - ("The quick brown fox jumps over the lazy dog." ++ - ("The quick brown fox jumps over the lazy dog." ++ - ("The quick brown fox jumps over the lazy dog." ++ - ("The quick brown fox jumps over the lazy dog." ++ - ("The quick brown fox jumps over the lazy dog." ++ - ("The quick brown fox jumps over the lazy dog." ++ - ("The quick brown fox jumps over the lazy dog." ++ - ("The quick brown fox jumps over the lazy dog." ++ - ("The quick brown fox jumps over the lazy dog." ++ "The quick brown fox jumps over the lazy dog.")))))))))), - ), - "7065cc36bba1d155fb09f9d02f22e8bf", - ), - ), - ( - __LOC__, - _ => Eq( - f( - "The quick brown fox jumps over the lazy dog." ++ - ("The quick brown fox jumps over the lazy dog." ++ - "The quick brown fox jumps over the lazy dog."), - ), - "b9193d1df4b7a8f0a25ffdd1005c5b2b", - ), - ), - } - }, - { - let ref = [ - "d41d8cd98f00b204e9800998ecf8427e", - "0cc175b9c0f1b6a831c399e269772661", - "4124bc0a9335c27f086f24ba207a4912", - "47bce5c74f589f4867dbd57e9ca9f808", - "74b87337454200d4d33f80c4663dc5e5", - "594f803b380a41396ed63dca39503542", - "0b4e7a0e5fe84ad35fb5f95b9ceeac79", - "5d793fc5b00a2348c3fb9ab59e5ca98a", - "3dbe00a167653a1aaee01d93e77e730e", - "552e6a97297c53e592208cf97fbb3b60", - "e09c80c42fda55f9d992e59ca6b3307d", - "d57f21e6a273781dbf8b7657940f3b03", - "45e4812014d83dde5666ebdf5a8ed1ed", - "c162de19c4c3731ca3428769d0cd593d", - "451599a5f9afa91a0f2097040a796f3d", - "12f9cf6998d52dbe773b06f848bb3608", - "23ca472302f49b3ea5592b146a312da0", - "88e42e96cc71151b6e1938a1699b0a27", - "2c60c24e7087e18e45055a33f9a5be91", - "639d76897485360b3147e66e0a8a3d6c", - "22d42eb002cefa81e9ad604ea57bc01d", - "bd049f221af82804c5a2826809337c9b", - "ff49cfac3968dbce26ebe7d4823e58bd", - "d95dbfee231e34cccb8c04444412ed7d", - "40edae4bad0e5bf6d6c2dc5615a86afb", - "a5a8bfa3962f49330227955e24a2e67c", - "ae791f19bdf77357ff10bb6b0e97e121", - "aaab9c59a88bf0bdfcb170546c5459d6", - "b0f0545856af1a340acdedce23c54b97", - "f7ce3d7d44f3342107d884bfa90c966a", - "59e794d45697b360e18ba972bada0123", - "3b0845db57c200be6052466f87b2198a", - "5eca9bd3eb07c006cd43ae48dfde7fd3", - "b4f13cb081e412f44e99742cb128a1a5", - "4c660346451b8cf91ef50f4634458d41", - "11db24dc3f6c2145701db08625dd6d76", - "80dad3aad8584778352c68ab06250327", - "1227fe415e79db47285cb2689c93963f", - "8e084f489f1bdf08c39f98ff6447ce6d", - "08b2f2b0864bac1ba1585043362cbec9", - "4697843037d962f62a5a429e611e0f5f", - "10c4da18575c092b486f8ab96c01c02f", - "af205d729450b663f48b11d839a1c8df", - "0d3f91798fac6ee279ec2485b25f1124", - "4c3c7c067634daec9716a80ea886d123", - "d1e358e6e3b707282cdd06e919f7e08c", - "8c6ded4f0af86e0a7e301f8a716c4363", - "4c2d8bcb02d982d7cb77f649c0a2dea8", - "bdb662f765cd310f2a547cab1cfecef6", - "08ff5f7301d30200ab89169f6afdb7af", - "6eb6a030bcce166534b95bc2ab45d9cf", - "1bb77918e5695c944be02c16ae29b25e", - "b6fe77c19f0f0f4946c761d62585bfea", - "e9e7e260dce84ffa6e0e7eb5fd9d37fc", - "eced9e0b81ef2bba605cbc5e2e76a1d0", - "ef1772b6dff9a122358552954ad0df65", - "3b0c8ac703f828b04c6c197006d17218", - "652b906d60af96844ebd21b674f35e93", - "dc2f2f2462a0d72358b2f99389458606", - "762fc2665994b217c52c3c2eb7d9f406", - "cc7ed669cf88f201c3297c6a91e1d18d", - "cced11f7bbbffea2f718903216643648", - "24612f0ce2c9d2cf2b022ef1e027a54f", - "b06521f39153d618550606be297466d5", - "014842d480b571495a4a0363793f7367", - "c743a45e0d2e6a95cb859adae0248435", - "def5d97e01e1219fb2fc8da6c4d6ba2f", - "92cb737f8687ccb93022fdb411a77cca", - "a0d1395c7fb36247bfe2d49376d9d133", - "ab75504250558b788f99d1ebd219abf2", - "0f5c6c4e740bfcc08c3c26ccb2673d46", - "cddd19bec7f310d8c87149ef47a1828f", - "96b39b8b95e016c79d104d83395b8133", - "f1fc0b14ff8fa674b02344577e23eeb1", - "0e8d28a1cafa3ffcff22afd480cce7d8", - "448539ffc17e1e81005b65581855cef4", - "61e39aae7c53e6e77db2e4405d9fb157", - "618a426895ee6133a372bebd1129b63e", - "046c90690c9e36578b9d4a7e1d249c75", - "aadab38075c43296ee7e12466ebb03e3", - "b15af9cdabbaea0516866a33d8fd0f98", - "986e6938ed767a8ae9530eef54bfe5f1", - "7ae25a72b71a42ccbc5477fd989cd512", - "98d34e50d4aa7a893cc7919a91acb0e3", - "3fc53fc22ea40f1a0afd78fc2cd9aa0f", - "923e37c738b9d7b1526f70b65229cc3d", - "b3966b7a08e5d46fd0774b797ba78dc2", - "f50c7286b540bb181db1d6e05a51a296", - "4efd6c8826e65a61f82af954d431b59b", - "ef1031e79e7a15a4470a5e98b23781b5", - "067876bfd0df0f4c5002780ec85e6f8c", - "789851dfa4c03563e9cef5f7bc050a7e", - "baf934720818ee49477e74fc644faa5e", - "9a0ea77ca26d2c121ddcc179edb76308", - "20c825561572e33d026f99ddfd999538", - "464c461455c5a927079a13609c20b637", - "cf37d42f89b6adb0e1a9e99104501b82", - "d266af45e3d06b70d9f52e2df4344186", - "f8b59fa22eb0ba944e2b7aa24d67b681", - "0918d7c2f9062743450a86eae9dde1a3", - "36a92cc94a9e0fa21f625f8bfb007adf", - "681d73898dad5685d48b5e8438bc3a66", - "337ccef058459c3c16411381778da0c4", - "6ccdfcc742862036ce07583633c5f77e", - "ddfa1adc974649dc5b414be86def7457", - "650ebc28ad85f11aa4b63b6ee565b89d", - "e4571793bcaba284017eeabd8df85697", - "4fc040d354ad9ba5e4f62862109d3e17", - "25814274e02aa7cc03d6314eb703e655", - "11378ecaee0089c840d26352704027e3", - "86f950bfcd824d5546da01c40576db31", - "089f243d1e831c5879aa375ee364a06e", - "9146ef3527c7cfcc66dc615c3986e391", - "d727cfdfc9ed0347e6917a68b982f7bc", - "da8f45e1fdc12deecfe56aeb5288796e", - "29cfcf52d8250a253a535cf7989c7bd2", - "0f6eb555b8e3c35411eebe9348594193", - "a922439f963e7e59040e4756992c6f1b", - "81f8453cf3f7e5ee5479c777e5a8d80c", - "8a7bd0732ed6a28ce75f6dabc90e1613", - "5f61c0ccad4cac44c75ff505e1f1e537", - "f6acfca2d47c87f2b14ca038234d3614", - "269fc62c517f3d55c368152addca57e7", - "50587cb16413da779b35508018721647", - "5e4a3ecfdaa4636b84a39b6a7be7c047", - "c5339dc2af6bf595580281ffb07353f6", - "e51176a47347e167ed0ed766b6de1a0c", - "020406e1d05cdc2aa287641f7ae2cc39", - "e510683b3f5ffe4093d021808bc6ff70", - "b325dc1c6f5e7a2b7cf465b9feab7948", - ] - - Array.to_list( - Array.map( - i => ( - Belt.Int.toString(i), - _ => Mt.Eq(\"@@"(Digest.to_hex, \"@@"(Digest.string, String.make(i, 'a'))), ref[i]), - ), - Ext_array_test.range(0, 129), - ), - ) - }, - ) -) diff --git a/jscomp/test/div_by_zero_test.js b/jscomp/test/div_by_zero_test.js index 3ef3a489e5..c2d6d28c1d 100644 --- a/jscomp/test/div_by_zero_test.js +++ b/jscomp/test/div_by_zero_test.js @@ -2,8 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_int32 = require("../../lib/js/caml_int32.js"); -let Caml_int64 = require("../../lib/js/caml_int64.js"); +let Primitive_int = require("../../lib/js/primitive_int.js"); let suites = { contents: /* [] */0 @@ -17,7 +16,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -35,42 +34,12 @@ function add(suite) { }; } -add([ - "File \"div_by_zero_test.res\", line 11, characters 7-14", - () => ({ - TAG: "ThrowAny", - _0: () => { - Caml_int32.div(3, 0); - } - }) -]); - -add([ - "File \"div_by_zero_test.res\", line 12, characters 7-14", - () => ({ - TAG: "ThrowAny", - _0: () => { - Caml_int32.mod_(3, 0); - } - }) -]); - -add([ - "File \"div_by_zero_test.res\", line 13, characters 7-14", - () => ({ - TAG: "ThrowAny", - _0: () => { - Caml_int32.div(3, 0); - } - }) -]); - add([ "File \"div_by_zero_test.res\", line 14, characters 7-14", () => ({ TAG: "ThrowAny", _0: () => { - Caml_int32.mod_(3, 0); + Primitive_int.div(3, 0); } }) ]); @@ -80,29 +49,13 @@ add([ () => ({ TAG: "ThrowAny", _0: () => { - Caml_int64.div([ - 0, - 3 - ], Caml_int64.zero); - } - }) -]); - -add([ - "File \"div_by_zero_test.res\", line 16, characters 7-14", - () => ({ - TAG: "ThrowAny", - _0: () => { - Caml_int64.mod_([ - 0, - 3 - ], Caml_int64.zero); + Primitive_int.mod_(3, 0); } }) ]); function div(x, y) { - return Caml_int32.div(x, y) + 3 | 0; + return Primitive_int.div(x, y) + 3 | 0; } Mt.from_pair_suites("Div_by_zero_test", suites.contents); diff --git a/jscomp/test/div_by_zero_test.res b/jscomp/test/div_by_zero_test.res index 3450b6c5d8..6185cd1c26 100644 --- a/jscomp/test/div_by_zero_test.res +++ b/jscomp/test/div_by_zero_test.res @@ -3,17 +3,16 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let add = suite => suites := list{suite, ...suites.contents} let () = { add((__LOC__, _ => ThrowAny(_ => ignore(3 / 0)))) add((__LOC__, _ => ThrowAny(_ => ignore(mod(3, 0))))) - add((__LOC__, _ => ThrowAny(_ => ignore(Int32.div(3l, 0l))))) - add((__LOC__, _ => ThrowAny(_ => ignore(Int32.rem(3l, 0l))))) - add((__LOC__, _ => ThrowAny(_ => ignore(Int64.div(3L, 0L))))) - add((__LOC__, _ => ThrowAny(_ => ignore(Int64.rem(3L, 0L))))) } let div = (x, y) => x / y + 3 diff --git a/jscomp/test/dollar_escape_test.js b/jscomp/test/dollar_escape_test.js index 4e8146f941..1c547e8f66 100644 --- a/jscomp/test/dollar_escape_test.js +++ b/jscomp/test/dollar_escape_test.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -38,9 +38,9 @@ function $$$plus(x, y) { let u = 3; -eq("File \"dollar_escape_test.res\", line 17, characters 3-10", v, 3); +eq("File \"dollar_escape_test.res\", line 20, characters 3-10", v, 3); -eq("File \"dollar_escape_test.res\", line 18, characters 3-10", u, 3); +eq("File \"dollar_escape_test.res\", line 21, characters 3-10", u, 3); Mt.from_pair_suites("Dollar_escape_test", suites.contents); diff --git a/jscomp/test/dollar_escape_test.res b/jscomp/test/dollar_escape_test.res index aec582fbf9..83af08e4b0 100644 --- a/jscomp/test/dollar_escape_test.res +++ b/jscomp/test/dollar_escape_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let \"$$" = (x, y) => x + y diff --git a/jscomp/test/earger_curry_test.js b/jscomp/test/earger_curry_test.js index fb598eacf0..98bbe7755a 100644 --- a/jscomp/test/earger_curry_test.js +++ b/jscomp/test/earger_curry_test.js @@ -2,8 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_array = require("../../lib/js/caml_array.js"); -let Pervasives = require("../../lib/js/pervasives.js"); +let Belt_Array = require("../../lib/js/belt_Array.js"); function map(f, a) { let f$1 = x => f(x); @@ -11,7 +10,7 @@ function map(f, a) { if (l === 0) { return []; } - let r = Caml_array.make(l, f$1(a[0])); + let r = Belt_Array.make(l, f$1(a[0])); for (let i = 1; i < l; ++i) { r[i] = f$1(a[i]); } @@ -30,7 +29,7 @@ function init(l, f) { Error: new Error() }; } - let res = Caml_array.make(l, f$1(0)); + let res = Belt_Array.make(l, f$1(0)); for (let i = 1; i < l; ++i) { res[i] = f$1(i); } @@ -47,10 +46,10 @@ function fold_left(f, x, a) { } function f2() { - let arr = init(30000000, i => i); - let b = map(i => i + i - 1, arr); - let v = fold_left((prim0, prim1) => prim0 + prim1, 0, b); - console.log(Pervasives.string_of_float(v)); + let arr = Belt_Array.init(30000000, i => i); + let b = Belt_Array.map(arr, i => i + i - 1); + let v = Belt_Array.reduceReverse(b, 0, (prim0, prim1) => prim0 + prim1); + console.log(v.toString()); } f2(); @@ -67,7 +66,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -122,15 +121,15 @@ let c = g(0)(3, 4); let d = g(0)(3, 5); -eq("File \"earger_curry_test.res\", line 142, characters 5-12", a, 10); +eq("File \"earger_curry_test.res\", line 148, characters 5-12", a, 10); -eq("File \"earger_curry_test.res\", line 143, characters 5-12", b, 11); +eq("File \"earger_curry_test.res\", line 149, characters 5-12", b, 11); -eq("File \"earger_curry_test.res\", line 144, characters 5-12", c, 10); +eq("File \"earger_curry_test.res\", line 150, characters 5-12", c, 10); -eq("File \"earger_curry_test.res\", line 145, characters 5-12", d, 11); +eq("File \"earger_curry_test.res\", line 151, characters 5-12", d, 11); -eq("File \"earger_curry_test.res\", line 146, characters 5-12", all_v.contents, { +eq("File \"earger_curry_test.res\", line 152, characters 5-12", all_v.contents, { hd: 8, tl: { hd: 6, diff --git a/jscomp/test/earger_curry_test.res b/jscomp/test/earger_curry_test.res index b676b0b51d..1f06624f6f 100644 --- a/jscomp/test/earger_curry_test.res +++ b/jscomp/test/earger_curry_test.res @@ -1,3 +1,5 @@ +open Belt + let f = g => x => g(x) let map = (f, a) => { @@ -5,9 +7,9 @@ let map = (f, a) => { if l == 0 { [] } else { - let r = Array.make(l, f(Array.unsafe_get(a, 0))) + let r = Array.make(l, f(Array.getUnsafe(a, 0))) for i in 1 to l - 1 { - Array.unsafe_set(r, i, f(Array.unsafe_get(a, i))) + Array.setUnsafe(r, i, f(Array.getUnsafe(a, i))) } r } @@ -26,7 +28,7 @@ let init = (l, f) => let res = Array.make(l, f(0)) for i in 1 to pred(l) { - Array.unsafe_set(res, i, f(i)) + Array.setUnsafe(res, i, f(i)) } res } @@ -36,7 +38,7 @@ let init = (l, f) => init(l, x => f(x)) let fold_left = (f, x, a) => { let r = ref(x) for i in 0 to Array.length(a) - 1 { - r := f(r.contents, Array.unsafe_get(a, i)) + r := f(r.contents, Array.getUnsafe(a, i)) } r.contents } @@ -51,17 +53,18 @@ let f = { open Array () => { let arr = init(10000000, i => float_of_int(i)) - let b = map(i => i +. i -. 1., arr) - let v = fold_left(\"+.", 0., b) - print_endline(string_of_float(v)) + let b = arr->map(i => i +. i -. 1.) + let v = b->reduceReverse(0., \"+.") + v->Js.Float.toString->Js.log } } let f2 = () => { + open Array let arr = init(30_000_000, i => float_of_int(i)) - let b = map(i => i +. i -. 1., arr) - let v = fold_left(\"+.", 0., b) - print_endline(string_of_float(v)) + let b = arr->map(i => i +. i -. 1.) + let v = b->reduceReverse(0., \"+.") + v->Js.Float.toString->Js.log } /* let time label f = */ @@ -83,7 +86,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let v = ref(0) diff --git a/jscomp/test/equal_box_test.js b/jscomp/test/equal_box_test.js index a3df571f19..420f8e4635 100644 --- a/jscomp/test/equal_box_test.js +++ b/jscomp/test/equal_box_test.js @@ -2,14 +2,13 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); -let Caml_int64 = require("../../lib/js/caml_int64.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); -let aa = Caml_obj.equal_null; +let aa = Primitive_object.equal; -let bb = Caml_obj.equal_undefined; +let bb = Primitive_object.equal; -let cc = Caml_obj.equal_nullable; +let cc = Primitive_object.equal; let suites = { contents: /* [] */0 @@ -35,81 +34,75 @@ function shouldBeNull() { return null; } -b("File \"equal_box_test.res\", line 18, characters 4-11", 3 !== null); +b("File \"equal_box_test.res\", line 14, characters 4-11", 3 !== null); -b("File \"equal_box_test.res\", line 19, characters 4-11", undefined !== null); +b("File \"equal_box_test.res\", line 15, characters 4-11", true); -b("File \"equal_box_test.res\", line 20, characters 4-11", "3" !== null); +b("File \"equal_box_test.res\", line 16, characters 4-11", "3" !== null); -b("File \"equal_box_test.res\", line 21, characters 4-11", /* '3' */51 !== null); +b("File \"equal_box_test.res\", line 17, characters 4-11", /* '3' */51 !== null); -b("File \"equal_box_test.res\", line 22, characters 4-11", !Caml_int64.equal_null(Caml_int64.zero, null)); +b("File \"equal_box_test.res\", line 18, characters 4-11", 0 !== null); -b("File \"equal_box_test.res\", line 23, characters 4-11", 0 !== null); +b("File \"equal_box_test.res\", line 19, characters 4-11", 0 !== null); -b("File \"equal_box_test.res\", line 24, characters 4-11", true); +b("File \"equal_box_test.res\", line 20, characters 4-11", true); -b("File \"equal_box_test.res\", line 25, characters 4-11", !Caml_obj.equal_null(undefined, null)); +b("File \"equal_box_test.res\", line 21, characters 4-11", true); -b("File \"equal_box_test.res\", line 26, characters 4-11", Caml_obj.equal_null(null, null)); +b("File \"equal_box_test.res\", line 22, characters 4-11", true); -b("File \"equal_box_test.res\", line 27, characters 4-11", true); +b("File \"equal_box_test.res\", line 23, characters 4-11", true); -b("File \"equal_box_test.res\", line 28, characters 4-11", true); - -b("File \"equal_box_test.res\", line 29, characters 4-11", !Caml_obj.equal_null(3, undefined)); +b("File \"equal_box_test.res\", line 24, characters 4-11", 3 !== undefined); let v = null; -b("File \"equal_box_test.res\", line 34, characters 4-11", 3 !== v); - -b("File \"equal_box_test.res\", line 35, characters 4-11", undefined !== v); - -b("File \"equal_box_test.res\", line 36, characters 4-11", "3" !== v); +b("File \"equal_box_test.res\", line 29, characters 4-11", 3 !== v); -b("File \"equal_box_test.res\", line 37, characters 4-11", /* '3' */51 !== v); +b("File \"equal_box_test.res\", line 30, characters 4-11", undefined !== v); -b("File \"equal_box_test.res\", line 38, characters 4-11", !Caml_int64.equal_nullable(Caml_int64.zero, v)); +b("File \"equal_box_test.res\", line 31, characters 4-11", "3" !== v); -b("File \"equal_box_test.res\", line 39, characters 4-11", 0 !== v); +b("File \"equal_box_test.res\", line 32, characters 4-11", /* '3' */51 !== v); -b("File \"equal_box_test.res\", line 40, characters 4-11", 0 !== v); +b("File \"equal_box_test.res\", line 33, characters 4-11", 0 !== v); -b("File \"equal_box_test.res\", line 41, characters 4-11", !Caml_obj.equal_nullable(undefined, v)); +b("File \"equal_box_test.res\", line 34, characters 4-11", 0 !== v); -b("File \"equal_box_test.res\", line 42, characters 4-11", Caml_obj.equal_nullable(null, v)); +b("File \"equal_box_test.res\", line 35, characters 4-11", undefined !== v); -b("File \"equal_box_test.res\", line 43, characters 4-11", true); +b("File \"equal_box_test.res\", line 36, characters 4-11", null === v); -b("File \"equal_box_test.res\", line 44, characters 4-11", true); +b("File \"equal_box_test.res\", line 37, characters 4-11", true); -b("File \"equal_box_test.res\", line 45, characters 4-11", !Caml_obj.equal_nullable(3, undefined)); +b("File \"equal_box_test.res\", line 38, characters 4-11", true); -b("File \"equal_box_test.res\", line 51, characters 4-11", 3 !== undefined); +b("File \"equal_box_test.res\", line 39, characters 4-11", 3 !== undefined); -b("File \"equal_box_test.res\", line 52, characters 4-11", true); +b("File \"equal_box_test.res\", line 45, characters 4-11", 3 !== undefined); -b("File \"equal_box_test.res\", line 53, characters 4-11", "3" !== undefined); +b("File \"equal_box_test.res\", line 46, characters 4-11", true); -b("File \"equal_box_test.res\", line 54, characters 4-11", /* '3' */51 !== undefined); +b("File \"equal_box_test.res\", line 47, characters 4-11", "3" !== undefined); -b("File \"equal_box_test.res\", line 55, characters 4-11", !Caml_int64.equal_undefined(Caml_int64.zero, undefined)); +b("File \"equal_box_test.res\", line 48, characters 4-11", /* '3' */51 !== undefined); -b("File \"equal_box_test.res\", line 56, characters 4-11", 0 !== undefined); +b("File \"equal_box_test.res\", line 49, characters 4-11", 0 !== undefined); -b("File \"equal_box_test.res\", line 57, characters 4-11", true); +b("File \"equal_box_test.res\", line 50, characters 4-11", 0 !== undefined); -b("File \"equal_box_test.res\", line 58, characters 4-11", Caml_obj.equal_undefined(undefined, undefined)); +b("File \"equal_box_test.res\", line 51, characters 4-11", true); -b("File \"equal_box_test.res\", line 62, characters 4-11", !Caml_obj.equal_undefined(null, undefined)); +b("File \"equal_box_test.res\", line 55, characters 4-11", true); -b("File \"equal_box_test.res\", line 63, characters 4-11", true); +b("File \"equal_box_test.res\", line 56, characters 4-11", true); -b("File \"equal_box_test.res\", line 64, characters 4-11", true); +b("File \"equal_box_test.res\", line 57, characters 4-11", true); -b("File \"equal_box_test.res\", line 65, characters 4-11", !Caml_obj.equal_undefined(3, undefined)); +b("File \"equal_box_test.res\", line 58, characters 4-11", 3 !== undefined); -Mt.from_pair_suites("File \"equal_box_test.res\", line 68, characters 20-27", suites.contents); +Mt.from_pair_suites("File \"equal_box_test.res\", line 61, characters 20-27", suites.contents); exports.aa = aa; exports.bb = bb; diff --git a/jscomp/test/equal_box_test.res b/jscomp/test/equal_box_test.res index 1af73e2e7a..c299a54538 100644 --- a/jscomp/test/equal_box_test.res +++ b/jscomp/test/equal_box_test.res @@ -1,8 +1,4 @@ -external eqNull: ('a, ~box: Js.null<'a>) => bool = "%bs_equal_null" -external eqUndefined: ('a, ~box: Js.undefined<'a>) => bool = "%bs_equal_undefined" - -external eqNullable: ('a, ~box: Js.nullable<'a>) => bool = "%bs_equal_nullable" - +open Js let (aa, bb, cc) = (eqNull, eqUndefined, eqNullable) let suites = ref(list{}) @@ -15,54 +11,51 @@ let f = () => None let shouldBeNull = () => Js.null let () = { - b(__LOC__, !eqNull(3, ~box=Js.null)) - b(__LOC__, !eqNull(None, ~box=Js.null)) - b(__LOC__, !eqNull("3", ~box=Js.null)) - b(__LOC__, !eqNull('3', ~box=Js.null)) - b(__LOC__, !eqNull(0L, ~box=Js.null)) - b(__LOC__, !eqNull(0, ~box=Js.null)) - b(__LOC__, !eqNull(0., ~box=Js.null)) - b(__LOC__, !eqNull(f(), ~box=Js.null)) - b(__LOC__, eqNull(shouldBeNull(), ~box=Js.null)) - b(__LOC__, !eqNull(1, ~box=Js.Null.return(3))) - b(__LOC__, eqNull(None, ~box=Js.Null.return(None))) - b(__LOC__, !eqNull(Some(3), ~box=Js.Null.return(None))) + b(__LOC__, !eqNull(3, Js.null)) + b(__LOC__, !eqNull(None, Js.null)) + b(__LOC__, !eqNull("3", Js.null)) + b(__LOC__, !eqNull('3', Js.null)) + b(__LOC__, !eqNull(0, Js.null)) + b(__LOC__, !eqNull(0., Js.null)) + b(__LOC__, !eqNull(f(), Js.null)) + b(__LOC__, eqNull(shouldBeNull(), Js.null)) + b(__LOC__, !eqNull(1, Js.Null.return(3))) + b(__LOC__, eqNull(None, Js.Null.return(None))) + b(__LOC__, !eqNull(Some(3), Js.Null.return(None))) } let () = { - let v = Js.Nullable.null - b(__LOC__, !eqNullable(3, ~box=v)) - b(__LOC__, !eqNullable(None, ~box=v)) - b(__LOC__, !eqNullable("3", ~box=v)) - b(__LOC__, !eqNullable('3', ~box=v)) - b(__LOC__, !eqNullable(0L, ~box=v)) - b(__LOC__, !eqNullable(0, ~box=v)) - b(__LOC__, !eqNullable(0., ~box=v)) - b(__LOC__, !eqNullable(f(), ~box=v)) - b(__LOC__, eqNullable(shouldBeNull(), ~box=v)) - b(__LOC__, !eqNullable(1, ~box=Js.Nullable.return(3))) - b(__LOC__, eqNullable(None, ~box=Js.Nullable.return(None))) - b(__LOC__, !eqNullable(Some(3), ~box=Js.Nullable.return(None))) + let v = Nullable.null + b(__LOC__, !eqNullable(3, v)) + b(__LOC__, !eqNullable(None, v)) + b(__LOC__, !eqNullable("3", v)) + b(__LOC__, !eqNullable('3', v)) + b(__LOC__, !eqNullable(0, v)) + b(__LOC__, !eqNullable(0., v)) + b(__LOC__, !eqNullable(f(), v)) + b(__LOC__, eqNullable(shouldBeNull(), v)) + b(__LOC__, !eqNullable(1, Nullable.return(3))) + b(__LOC__, eqNullable(None, Nullable.return(None))) + b(__LOC__, !eqNullable(Some(3), Nullable.return(None))) } let () = { - let v = Js.Undefined.empty - - b(__LOC__, !eqUndefined(3, ~box=v)) - b(__LOC__, eqUndefined(None, ~box=v)) - b(__LOC__, !eqUndefined("3", ~box=v)) - b(__LOC__, !eqUndefined('3', ~box=v)) - b(__LOC__, !eqUndefined(0L, ~box=v)) - b(__LOC__, !eqUndefined(0, ~box=v)) - b(__LOC__, !eqUndefined(0., ~box=v)) - b(__LOC__, eqUndefined(f(), ~box=v)) + let v = Undefined.empty + + b(__LOC__, !eqUndefined(3, v)) + b(__LOC__, eqUndefined(None, v)) + b(__LOC__, !eqUndefined("3", v)) + b(__LOC__, !eqUndefined('3', v)) + b(__LOC__, !eqUndefined(0, v)) + b(__LOC__, !eqUndefined(0., v)) + b(__LOC__, eqUndefined(f(), v)) /* [ None === undefined] [ None === Js.Undefined.return None] */ - b(__LOC__, !eqUndefined(shouldBeNull(), ~box=v)) - b(__LOC__, !eqUndefined(1, ~box=Js.Undefined.return(3))) - b(__LOC__, eqUndefined(None, ~box=Js.Undefined.return(None))) - b(__LOC__, !eqUndefined(Some(3), ~box=Js.Undefined.return(None))) + b(__LOC__, !eqUndefined(shouldBeNull(), v)) + b(__LOC__, !eqUndefined(1, Undefined.return(3))) + b(__LOC__, eqUndefined(None, Undefined.return(None))) + b(__LOC__, !eqUndefined(Some(3), Undefined.return(None))) } Mt.from_pair_suites(__LOC__, suites.contents) diff --git a/jscomp/test/equal_exception_test.js b/jscomp/test/equal_exception_test.js index 04bff576e3..6cc7cf5bf0 100644 --- a/jscomp/test/equal_exception_test.js +++ b/jscomp/test/equal_exception_test.js @@ -2,59 +2,20 @@ 'use strict'; let Mt = require("./mt.js"); -let Bytes = require("../../lib/js/bytes.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); -let Caml_bytes = require("../../lib/js/caml_bytes.js"); -let Caml_string = require("../../lib/js/caml_string.js"); -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); let v = "gso"; function is_equal() { - if (Caml_bytes.get(Bytes.make(3, /* 'a' */97), 0) !== /* 'a' */97) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "equal_exception_test.res", - 4, - 2 - ], - Error: new Error() - }; - } - if (Bytes.make(3, /* 'a' */97)[0] !== /* 'a' */97) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "equal_exception_test.res", - 5, - 2 - ], - Error: new Error() - }; - } - let u = Bytes.make(3, /* 'a' */97); - u[0] = /* 'b' */98; - if (u[0] !== /* 'b' */98) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "equal_exception_test.res", - 8, - 2 - ], - Error: new Error() - }; - } - if (Caml_string.get(v, 0) === /* 'g' */103) { + if (v.codePointAt(0) === /* 'g' */103) { return; } throw { RE_EXN_ID: "Assert_failure", _1: [ "equal_exception_test.res", - 9, + 4, 2 ], Error: new Error() @@ -68,7 +29,7 @@ function is_exception() { Error: new Error() }; } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + let exn = Primitive_exceptions.internalToException(raw_exn); if (exn.RE_EXN_ID === "Not_found") { return; } @@ -77,7 +38,7 @@ function is_exception() { } function is_normal_exception(_x) { - let A = /* @__PURE__ */Caml_exceptions.create("A"); + let A = /* @__PURE__ */Primitive_exceptions.create("A"); let v = { RE_EXN_ID: A, _1: 3 @@ -85,7 +46,7 @@ function is_normal_exception(_x) { try { throw v; } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + let exn = Primitive_exceptions.internalToException(raw_exn); if (exn.RE_EXN_ID === A) { if (exn._1 === 3) { return; @@ -97,7 +58,7 @@ function is_normal_exception(_x) { } function is_arbitrary_exception() { - let A = /* @__PURE__ */Caml_exceptions.create("A"); + let A = /* @__PURE__ */Primitive_exceptions.create("A"); try { throw { RE_EXN_ID: A, @@ -146,16 +107,16 @@ function eq(x) { return x.RE_EXN_ID === "Not_found"; } -let Not_found = /* @__PURE__ */Caml_exceptions.create("Equal_exception_test.Not_found"); +let Not_found = /* @__PURE__ */Primitive_exceptions.create("Equal_exception_test.Not_found"); -if (Caml_obj.equal(e, { +if (Primitive_object.equal(e, { RE_EXN_ID: Not_found }) !== false) { throw { RE_EXN_ID: "Assert_failure", _1: [ "equal_exception_test.res", - 50, + 45, 0 ], Error: new Error() @@ -167,7 +128,7 @@ if (Not_found === "Not_found" !== false) { RE_EXN_ID: "Assert_failure", _1: [ "equal_exception_test.res", - 51, + 46, 0 ], Error: new Error() diff --git a/jscomp/test/equal_exception_test.res b/jscomp/test/equal_exception_test.res index fc21456964..dd7d77e301 100644 --- a/jscomp/test/equal_exception_test.res +++ b/jscomp/test/equal_exception_test.res @@ -1,11 +1,6 @@ let v = "gso" let is_equal = () => { - assert(Bytes.get(Bytes.make(3, 'a'), 0) == 'a') - assert(Bytes.unsafe_get(Bytes.make(3, 'a'), 0) == 'a') - let u = Bytes.make(3, 'a') - Bytes.unsafe_set(u, 0, 'b') - assert(Bytes.unsafe_get(u, 0) == 'b') assert(String.get(v, 0) == 'g') } diff --git a/jscomp/test/equal_test.js b/jscomp/test/equal_test.js index f41ecca9b3..a4cfefc608 100644 --- a/jscomp/test/equal_test.js +++ b/jscomp/test/equal_test.js @@ -23,4 +23,4 @@ exports.str_b = str_b; exports.int_equal = int_equal; exports.v = v; exports.float_equal = float_equal; -/* str_b Not a pure module */ +/* No side effect */ diff --git a/jscomp/test/es6_module_test.js b/jscomp/test/es6_module_test.js index 63507f8917..ef867e0329 100644 --- a/jscomp/test/es6_module_test.js +++ b/jscomp/test/es6_module_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); function length(param) { return 3; @@ -13,7 +13,7 @@ Mt.from_pair_suites("Es6_module_test", { "list_length", () => ({ TAG: "Eq", - _0: List.length({ + _0: Belt_List.length({ hd: 1, tl: { hd: 2, diff --git a/jscomp/test/es6_module_test.res b/jscomp/test/es6_module_test.res index dbc4bd887f..5245fd4eb3 100644 --- a/jscomp/test/es6_module_test.res +++ b/jscomp/test/es6_module_test.res @@ -4,7 +4,7 @@ let length = _ => 3 Mt.from_pair_suites( __MODULE__, list{ - ("list_length", _ => Eq(List.length(list{1, 2}), 2)), + ("list_length", _ => Eq(Belt.List.length(list{1, 2}), 2)), ("length", _ => Eq(length(list{1, 2}), 3)), }, ) diff --git a/jscomp/test/event_ffi.js b/jscomp/test/event_ffi.js index 55421f3adb..1a92a6f004 100644 --- a/jscomp/test/event_ffi.js +++ b/jscomp/test/event_ffi.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); function h0(x) { return x(); @@ -57,7 +57,7 @@ function xx() { }; } -let test_as = List.map; +let test_as = Belt_List.map; exports.h0 = h0; exports.h00 = h00; diff --git a/jscomp/test/event_ffi.res b/jscomp/test/event_ffi.res index 13d03efe6e..b5821c612f 100644 --- a/jscomp/test/event_ffi.res +++ b/jscomp/test/event_ffi.res @@ -59,7 +59,7 @@ let a3 = (x, y, z) => x + y + z /* let b44 () = Js.Internal.fn_mk4 (fun x y z d -> (x,y,z,d)) */ /* polymoprhic restriction */ -let test_as: ('a => 'a, _ as 'b) => 'b = List.map +let test_as: (_ as 'b, 'a => 'a) => 'b = Belt.List.map let xx: unit => _ => unit = () => _ => Js.log(3) diff --git a/jscomp/test/exception_alias.js b/jscomp/test/exception_alias.js index da3b52db8c..620e7f226b 100644 --- a/jscomp/test/exception_alias.js +++ b/jscomp/test/exception_alias.js @@ -1,13 +1,13 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let a0 = { RE_EXN_ID: "Not_found" }; -let b = List.length({ +let b = Belt_List.length({ hd: 1, tl: { hd: 2, @@ -15,58 +15,94 @@ let b = List.length({ } }); -let List$1 = { - compare_lengths: List.compare_lengths, - compare_length_with: List.compare_length_with, - cons: List.cons, - hd: List.hd, - tl: List.tl, - nth: List.nth, - nth_opt: List.nth_opt, - rev: List.rev, - init: List.init, - append: List.append, - rev_append: List.rev_append, - concat: List.concat, - flatten: List.flatten, - iter: List.iter, - iteri: List.iteri, - map: List.map, - mapi: List.mapi, - rev_map: List.rev_map, - fold_left: List.fold_left, - fold_right: List.fold_right, - iter2: List.iter2, - map2: List.map2, - rev_map2: List.rev_map2, - fold_left2: List.fold_left2, - fold_right2: List.fold_right2, - for_all: List.for_all, - exists: List.exists, - for_all2: List.for_all2, - exists2: List.exists2, - mem: List.mem, - memq: List.memq, - find: List.find, - find_opt: List.find_opt, - filter: List.filter, - find_all: List.find_all, - partition: List.partition, - assoc: List.assoc, - assoc_opt: List.assoc_opt, - assq: List.assq, - assq_opt: List.assq_opt, - mem_assoc: List.mem_assoc, - mem_assq: List.mem_assq, - remove_assoc: List.remove_assoc, - remove_assq: List.remove_assq, - split: List.split, - combine: List.combine, - sort: List.sort, - stable_sort: List.stable_sort, - fast_sort: List.fast_sort, - sort_uniq: List.sort_uniq, - merge: List.merge, +let List = { + size: Belt_List.size, + head: Belt_List.head, + headExn: Belt_List.headExn, + tail: Belt_List.tail, + tailExn: Belt_List.tailExn, + add: Belt_List.add, + get: Belt_List.get, + getExn: Belt_List.getExn, + make: Belt_List.make, + makeByU: Belt_List.makeByU, + makeBy: Belt_List.makeBy, + shuffle: Belt_List.shuffle, + drop: Belt_List.drop, + take: Belt_List.take, + splitAt: Belt_List.splitAt, + concat: Belt_List.concat, + concatMany: Belt_List.concatMany, + reverseConcat: Belt_List.reverseConcat, + flatten: Belt_List.flatten, + mapU: Belt_List.mapU, + map: Belt_List.map, + zip: Belt_List.zip, + zipByU: Belt_List.zipByU, + zipBy: Belt_List.zipBy, + mapWithIndexU: Belt_List.mapWithIndexU, + mapWithIndex: Belt_List.mapWithIndex, + fromArray: Belt_List.fromArray, + toArray: Belt_List.toArray, + reverse: Belt_List.reverse, + mapReverseU: Belt_List.mapReverseU, + mapReverse: Belt_List.mapReverse, + forEachU: Belt_List.forEachU, + forEach: Belt_List.forEach, + forEachWithIndexU: Belt_List.forEachWithIndexU, + forEachWithIndex: Belt_List.forEachWithIndex, + reduceU: Belt_List.reduceU, + reduce: Belt_List.reduce, + reduceWithIndexU: Belt_List.reduceWithIndexU, + reduceWithIndex: Belt_List.reduceWithIndex, + reduceReverseU: Belt_List.reduceReverseU, + reduceReverse: Belt_List.reduceReverse, + mapReverse2U: Belt_List.mapReverse2U, + mapReverse2: Belt_List.mapReverse2, + forEach2U: Belt_List.forEach2U, + forEach2: Belt_List.forEach2, + reduce2U: Belt_List.reduce2U, + reduce2: Belt_List.reduce2, + reduceReverse2U: Belt_List.reduceReverse2U, + reduceReverse2: Belt_List.reduceReverse2, + everyU: Belt_List.everyU, + every: Belt_List.every, + someU: Belt_List.someU, + some: Belt_List.some, + every2U: Belt_List.every2U, + every2: Belt_List.every2, + some2U: Belt_List.some2U, + some2: Belt_List.some2, + cmpByLength: Belt_List.cmpByLength, + cmpU: Belt_List.cmpU, + cmp: Belt_List.cmp, + eqU: Belt_List.eqU, + eq: Belt_List.eq, + hasU: Belt_List.hasU, + has: Belt_List.has, + getByU: Belt_List.getByU, + getBy: Belt_List.getBy, + keepU: Belt_List.keepU, + keep: Belt_List.keep, + filter: Belt_List.filter, + keepWithIndexU: Belt_List.keepWithIndexU, + keepWithIndex: Belt_List.keepWithIndex, + filterWithIndex: Belt_List.filterWithIndex, + keepMapU: Belt_List.keepMapU, + keepMap: Belt_List.keepMap, + partitionU: Belt_List.partitionU, + partition: Belt_List.partition, + unzip: Belt_List.unzip, + getAssocU: Belt_List.getAssocU, + getAssoc: Belt_List.getAssoc, + hasAssocU: Belt_List.hasAssocU, + hasAssoc: Belt_List.hasAssoc, + removeAssocU: Belt_List.removeAssocU, + removeAssoc: Belt_List.removeAssoc, + setAssocU: Belt_List.setAssocU, + setAssoc: Belt_List.setAssoc, + sortU: Belt_List.sortU, + sort: Belt_List.sort, b: b, length: 3 }; @@ -87,5 +123,5 @@ exports.a2 = a2; exports.a3 = a3; exports.a4 = a4; exports.a5 = a5; -exports.List = List$1; +exports.List = List; /* b Not a pure module */ diff --git a/jscomp/test/exception_alias.res b/jscomp/test/exception_alias.res index cdd03d5190..205b2c1d78 100644 --- a/jscomp/test/exception_alias.res +++ b/jscomp/test/exception_alias.res @@ -10,6 +10,8 @@ let a4 = a3 let a5 = a4 +open Belt + module List = { include List let b = length(list{1, 2}) diff --git a/jscomp/test/exception_raise_test.js b/jscomp/test/exception_raise_test.js index d39772e1ca..687870fc21 100644 --- a/jscomp/test/exception_raise_test.js +++ b/jscomp/test/exception_raise_test.js @@ -2,25 +2,24 @@ 'use strict'; let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); let Js_exn = require("../../lib/js/js_exn.js"); -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); +let Belt_List = require("../../lib/js/belt_List.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); -let Local = /* @__PURE__ */Caml_exceptions.create("Exception_raise_test.Local"); +let Local = /* @__PURE__ */Primitive_exceptions.create("Exception_raise_test.Local"); -let B = /* @__PURE__ */Caml_exceptions.create("Exception_raise_test.B"); +let B = /* @__PURE__ */Primitive_exceptions.create("Exception_raise_test.B"); -let C = /* @__PURE__ */Caml_exceptions.create("Exception_raise_test.C"); +let C = /* @__PURE__ */Primitive_exceptions.create("Exception_raise_test.C"); -let D = /* @__PURE__ */Caml_exceptions.create("Exception_raise_test.D"); +let D = /* @__PURE__ */Primitive_exceptions.create("Exception_raise_test.D"); function appf(g, x) { - let A = /* @__PURE__ */Caml_exceptions.create("A"); + let A = /* @__PURE__ */Primitive_exceptions.create("A"); try { return g(x); } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + let exn = Primitive_exceptions.internalToException(raw_exn); if (exn.RE_EXN_ID === Local) { return 3; } @@ -56,14 +55,14 @@ function appf(g, x) { } } -let A = /* @__PURE__ */Caml_exceptions.create("Exception_raise_test.A"); +let A = /* @__PURE__ */Primitive_exceptions.create("Exception_raise_test.A"); let f; try { f = (function () {throw (new Error ("x"))} ()); } catch (raw_x) { - let x = Caml_js_exceptions.internalToOCamlException(raw_x); + let x = Primitive_exceptions.internalToException(raw_x); f = x.RE_EXN_ID === A ? x._1 : 2; } @@ -72,7 +71,7 @@ let ff; try { ff = (function () {throw 3} ()); } catch (raw_x$1) { - let x$1 = Caml_js_exceptions.internalToOCamlException(raw_x$1); + let x$1 = Primitive_exceptions.internalToException(raw_x$1); ff = x$1.RE_EXN_ID === A ? x$1._1 : 2; } @@ -81,7 +80,7 @@ let fff; try { fff = (function () {throw 2} ()); } catch (raw_x$2) { - let x$2 = Caml_js_exceptions.internalToOCamlException(raw_x$2); + let x$2 = Primitive_exceptions.internalToException(raw_x$2); fff = x$2.RE_EXN_ID === A ? x$2._1 : 2; } @@ -90,7 +89,7 @@ let a0; try { a0 = (function (){throw 2} ()); } catch (raw_x$3) { - let x$3 = Caml_js_exceptions.internalToOCamlException(raw_x$3); + let x$3 = Primitive_exceptions.internalToException(raw_x$3); if (x$3.RE_EXN_ID === A || x$3.RE_EXN_ID === Js_exn.$$Error) { a0 = x$3._1; } else { @@ -111,7 +110,7 @@ let a1; try { a1 = (function (){throw 2} ()); } catch (raw_e) { - a1 = Caml_js_exceptions.internalToOCamlException(raw_e); + a1 = Primitive_exceptions.internalToException(raw_e); } let a2; @@ -119,7 +118,7 @@ let a2; try { a2 = (function (){throw (new Error("x"))} ()); } catch (raw_e$1) { - a2 = Caml_js_exceptions.internalToOCamlException(raw_e$1); + a2 = Primitive_exceptions.internalToException(raw_e$1); } let suites = { @@ -180,8 +179,8 @@ function eq(loc, x, y) { try { ((()=>{throw 2})()); } catch (raw_e$2) { - let e = Caml_js_exceptions.internalToOCamlException(raw_e$2); - eq("File \"exception_raise_test.res\", line 137, characters 10-17", Caml_js_exceptions.as_js_exn(e) !== undefined, true); + let e = Primitive_exceptions.internalToException(raw_e$2); + eq("File \"exception_raise_test.res\", line 137, characters 10-17", Js_exn.asJsExn(e) !== undefined, true); } try { @@ -190,8 +189,8 @@ try { Error: new Error() }; } catch (raw_e$3) { - let e$1 = Caml_js_exceptions.internalToOCamlException(raw_e$3); - eq("File \"exception_raise_test.res\", line 141, characters 10-17", Caml_js_exceptions.as_js_exn(e$1) !== undefined, false); + let e$1 = Primitive_exceptions.internalToException(raw_e$3); + eq("File \"exception_raise_test.res\", line 141, characters 10-17", Js_exn.asJsExn(e$1) !== undefined, false); } function fff0(x, g) { @@ -211,7 +210,7 @@ function input_lines(ic, _acc) { try { line = input_line(ic); } catch (exn) { - return List.rev(acc); + return Belt_List.reverse(acc); } _acc = { hd: line, diff --git a/jscomp/test/exception_raise_test.res b/jscomp/test/exception_raise_test.res index bd1e269665..407bc1597e 100644 --- a/jscomp/test/exception_raise_test.res +++ b/jscomp/test/exception_raise_test.res @@ -150,7 +150,7 @@ type in_channel @val external input_line: in_channel => string = "input_line" let rec input_lines = (ic, acc) => switch input_line(ic) { - | exception _ => List.rev(acc) + | exception _ => Belt.List.reverse(acc) | line => input_lines(ic, list{line, ...acc}) } diff --git a/jscomp/test/exception_rebound_err_test.js b/jscomp/test/exception_rebound_err_test.js index 4fe7c956c2..71cd0d8fd1 100644 --- a/jscomp/test/exception_rebound_err_test.js +++ b/jscomp/test/exception_rebound_err_test.js @@ -2,8 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); let suites = { contents: /* [] */0 @@ -17,7 +16,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -28,18 +27,18 @@ function eq(loc, x, y) { }; } -let A = /* @__PURE__ */Caml_exceptions.create("Exception_rebound_err_test.A"); +let A = /* @__PURE__ */Primitive_exceptions.create("Exception_rebound_err_test.A"); -let B = /* @__PURE__ */Caml_exceptions.create("Exception_rebound_err_test.B"); +let B = /* @__PURE__ */Primitive_exceptions.create("Exception_rebound_err_test.B"); -let C = /* @__PURE__ */Caml_exceptions.create("Exception_rebound_err_test.C"); +let C = /* @__PURE__ */Primitive_exceptions.create("Exception_rebound_err_test.C"); function test_js_error4() { try { JSON.parse(" {\"x\"}"); return 1; } catch (raw_e) { - let e = Caml_js_exceptions.internalToOCamlException(raw_e); + let e = Primitive_exceptions.internalToException(raw_e); if (e.RE_EXN_ID === "Not_found") { return 2; } @@ -66,7 +65,7 @@ function f(g) { try { return g(); } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + let exn = Primitive_exceptions.internalToException(raw_exn); if (exn.RE_EXN_ID === "Not_found") { return 1; } @@ -74,7 +73,7 @@ function f(g) { } } -eq("File \"exception_rebound_err_test.res\", line 31, characters 3-10", test_js_error4(), 7); +eq("File \"exception_rebound_err_test.res\", line 34, characters 3-10", test_js_error4(), 7); Mt.from_pair_suites("Exception_rebound_err_test", suites.contents); diff --git a/jscomp/test/exception_rebound_err_test.res b/jscomp/test/exception_rebound_err_test.res index aa03004a84..3415599e4b 100644 --- a/jscomp/test/exception_rebound_err_test.res +++ b/jscomp/test/exception_rebound_err_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } exception A(int) diff --git a/jscomp/test/exception_value_test.js b/jscomp/test/exception_value_test.js index 8be5392bda..8dc4aa6cf6 100644 --- a/jscomp/test/exception_value_test.js +++ b/jscomp/test/exception_value_test.js @@ -2,8 +2,7 @@ 'use strict'; let Js_exn = require("../../lib/js/js_exn.js"); -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); function f() { throw { @@ -34,11 +33,11 @@ function hh() { }; } -let A = /* @__PURE__ */Caml_exceptions.create("Exception_value_test.A"); +let A = /* @__PURE__ */Primitive_exceptions.create("Exception_value_test.A"); -let B = /* @__PURE__ */Caml_exceptions.create("Exception_value_test.B"); +let B = /* @__PURE__ */Primitive_exceptions.create("Exception_value_test.B"); -let C = /* @__PURE__ */Caml_exceptions.create("Exception_value_test.C"); +let C = /* @__PURE__ */Primitive_exceptions.create("Exception_value_test.C"); let u = { RE_EXN_ID: A, @@ -49,7 +48,7 @@ function test_not_found(f, param) { try { return f(); } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + let exn = Primitive_exceptions.internalToException(raw_exn); if (exn.RE_EXN_ID === "Not_found") { return 2; } @@ -61,7 +60,7 @@ function test_js_error2() { try { return JSON.parse(" {\"x\" : }"); } catch (raw_e) { - let e = Caml_js_exceptions.internalToOCamlException(raw_e); + let e = Primitive_exceptions.internalToException(raw_e); if (e.RE_EXN_ID === Js_exn.$$Error) { console.log(e._1.stack); throw e; diff --git a/jscomp/test/ext_array_test.js b/jscomp/test/ext_array_test.js index db46f8d66a..30c572653f 100644 --- a/jscomp/test/ext_array_test.js +++ b/jscomp/test/ext_array_test.js @@ -1,10 +1,9 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); -let $$Array = require("../../lib/js/array.js"); -let Caml_array = require("../../lib/js/caml_array.js"); -let Caml_option = require("../../lib/js/caml_option.js"); +let Belt_List = require("../../lib/js/belt_List.js"); +let Belt_Array = require("../../lib/js/belt_Array.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); function reverse_range(a, i, len) { if (len === 0) { @@ -26,7 +25,7 @@ function reverse(a) { if (b_len === 0) { return []; } - let b = $$Array.copy(a); + let b = a.slice(0); for (let i = 0; i < b_len; ++i) { b[i] = a[(b_len - 1 | 0) - i | 0]; } @@ -37,8 +36,8 @@ function reverse_of_list(x) { if (!x) { return []; } - let len = List.length(x); - let a = Caml_array.make(len, x.hd); + let len = Belt_List.length(x); + let a = Belt_Array.make(len, x.hd); let _i = 0; let _x = x.tl; while (true) { @@ -93,7 +92,7 @@ function filter_map(f, a) { if (v$1 !== undefined) { _i = i + 1 | 0; _acc = { - hd: Caml_option.valFromOption(v$1), + hd: Primitive_option.valFromOption(v$1), tl: acc }; continue; @@ -111,7 +110,7 @@ function range(from, to_) { Error: new Error() }; } - return $$Array.init((to_ - from | 0) + 1 | 0, i => i + from | 0); + return Belt_Array.init((to_ - from | 0) + 1 | 0, i => i + from | 0); } function map2i(f, a, b) { @@ -123,7 +122,7 @@ function map2i(f, a, b) { Error: new Error() }; } - return $$Array.mapi((i, a) => f(i, a, b[i]), a); + return Belt_Array.mapWithIndex(a, (i, a) => f(i, a, b[i])); } function tolist_aux(a, f, _i, _res) { @@ -136,7 +135,7 @@ function tolist_aux(a, f, _i, _res) { let v = a[i]; let v$1 = f(v); _res = v$1 !== undefined ? ({ - hd: Caml_option.valFromOption(v$1), + hd: Primitive_option.valFromOption(v$1), tl: res }) : res; _i = i - 1 | 0; @@ -158,8 +157,8 @@ function of_list_map(f, a) { } let tl = a.tl; let hd = f(a.hd); - let len = List.length(tl) + 1 | 0; - let arr = Caml_array.make(len, hd); + let len = Belt_List.length(tl) + 1 | 0; + let arr = Belt_Array.make(len, hd); let _i = 1; let _x = tl; while (true) { @@ -199,8 +198,8 @@ function rfind_and_split(arr, cmp, v) { return { NAME: "Split", VAL: [ - $$Array.sub(arr, 0, i), - $$Array.sub(arr, i + 1 | 0, (arr.length - i | 0) - 1 | 0) + Belt_Array.slice(arr, 0, i), + Belt_Array.slice(arr, i + 1 | 0, (arr.length - i | 0) - 1 | 0) ] }; } @@ -230,8 +229,8 @@ function find_and_split(arr, cmp, v) { return { NAME: "Split", VAL: [ - $$Array.sub(arr, 0, i), - $$Array.sub(arr, i + 1 | 0, (arr.length - i | 0) - 1 | 0) + Belt_Array.slice(arr, 0, i), + Belt_Array.slice(arr, i + 1 | 0, (arr.length - i | 0) - 1 | 0) ] }; } diff --git a/jscomp/test/ext_array_test.res b/jscomp/test/ext_array_test.res index 53a71e3894..c2fbe5e4f9 100644 --- a/jscomp/test/ext_array_test.res +++ b/jscomp/test/ext_array_test.res @@ -22,14 +22,16 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +open Belt + let reverse_range = (a, i, len) => if len == 0 { () } else { for k in 0 to (len - 1) / 2 { - let t = Array.unsafe_get(a, i + k) - Array.unsafe_set(a, i + k, Array.unsafe_get(a, i + len - 1 - k)) - Array.unsafe_set(a, i + len - 1 - k, t) + let t = Array.getUnsafe(a, i + k) + Array.setUnsafe(a, i + k, Array.getUnsafe(a, i + len - 1 - k)) + Array.setUnsafe(a, i + len - 1 - k, t) } } @@ -42,7 +44,7 @@ let reverse = a => { } else { let b = Array.copy(a) for i in 0 to b_len - 1 { - Array.unsafe_set(b, i, Array.unsafe_get(a, b_len - 1 - i)) + Array.setUnsafe(b, i, Array.getUnsafe(a, b_len - 1 - i)) } b } @@ -58,7 +60,7 @@ let reverse_of_list = x => switch x { | list{} => a | list{hd, ...tl} => - Array.unsafe_set(a, len - i - 2, hd) + Array.setUnsafe(a, len - i - 2, hd) fill(i + 1, tl) } fill(0, tl) @@ -70,7 +72,7 @@ let filter = (f, a) => { if i == arr_len { reverse_of_list(acc) } else { - let v = Array.unsafe_get(a, i) + let v = Array.getUnsafe(a, i) if f(v) { aux(list{v, ...acc}, i + 1) } else { @@ -86,7 +88,7 @@ let filter_map = (f: _ => option<_>, a) => { if i == arr_len { reverse_of_list(acc) } else { - let v = Array.unsafe_get(a, i) + let v = Array.getUnsafe(a, i) switch f(v) { | Some(v) => aux(list{v, ...acc}, i + 1) | None => aux(acc, i + 1) @@ -107,7 +109,7 @@ let map2i = (f, a, b) => { if len != Array.length(b) { invalid_arg("Ext_array_test.map2i") } else { - Array.mapi((i, a) => f(i, a, Array.unsafe_get(b, i)), a) + a->Array.mapWithIndex((i, a) => f(i, a, Array.getUnsafe(b, i))) } } @@ -115,7 +117,7 @@ let rec tolist_aux = (a, f, i, res) => if i < 0 { res } else { - let v = Array.unsafe_get(a, i) + let v = Array.getUnsafe(a, i) tolist_aux( a, f, @@ -143,7 +145,7 @@ let of_list_map = (f, a) => switch x { | list{} => arr | list{hd, ...tl} => - Array.unsafe_set(arr, i, f(hd)) + Array.setUnsafe(arr, i, f(hd)) fill(i + 1, tl) } fill(1, tl) @@ -166,7 +168,7 @@ let rfind_with_index = (arr, cmp, v) => { let rec aux = i => if i < 0 { i - } else if cmp(Array.unsafe_get(arr, i), v) { + } else if cmp(Array.getUnsafe(arr, i), v) { i } else { aux(i - 1) @@ -180,7 +182,10 @@ let rfind_and_split = (arr, cmp, v): split<_> => { if i < 0 { #No_split } else { - #Split(Array.sub(arr, 0, i), Array.sub(arr, i + 1, Array.length(arr) - i - 1)) + #Split( + Array.slice(arr, ~offset=0, ~len=i), + Array.slice(arr, ~offset=i + 1, ~len=Array.length(arr) - i - 1), + ) } } @@ -189,7 +194,7 @@ let find_with_index = (arr, cmp, v) => { let rec aux = (i, len) => if i >= len { -1 - } else if cmp(Array.unsafe_get(arr, i), v) { + } else if cmp(Array.getUnsafe(arr, i), v) { i } else { aux(i + 1, len) @@ -202,18 +207,19 @@ let find_and_split = (arr, cmp, v): split<_> => { if i < 0 { #No_split } else { - #Split(Array.sub(arr, 0, i), Array.sub(arr, i + 1, Array.length(arr) - i - 1)) + #Split( + Array.slice(arr, ~offset=0, ~len=i), + Array.slice(arr, ~offset=i + 1, ~len=Array.length(arr) - i - 1), + ) } } -/* TODO: available since 4.03, use {!Array.exists} */ - let exists = (p, a) => { let n = Array.length(a) let rec loop = i => if i == n { false - } else if p(Array.unsafe_get(a, i)) { + } else if p(Array.getUnsafe(a, i)) { true } else { loop(succ(i)) @@ -227,7 +233,7 @@ let rec unsafe_loop = (index, len, p, xs, ys) => if index >= len { true } else { - p(Array.unsafe_get(xs, index), Array.unsafe_get(ys, index)) && + p(Array.getUnsafe(xs, index), Array.getUnsafe(ys, index)) && unsafe_loop(succ(index), len, p, xs, ys) } diff --git a/jscomp/test/ext_bytes_test.js b/jscomp/test/ext_bytes_test.js deleted file mode 100644 index 768eb67bc4..0000000000 --- a/jscomp/test/ext_bytes_test.js +++ /dev/null @@ -1,213 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let Caml = require("../../lib/js/caml.js"); -let Char = require("../../lib/js/char.js"); -let Bytes = require("../../lib/js/bytes.js"); -let Caml_bytes = require("../../lib/js/caml_bytes.js"); -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); - -let suites = { - contents: /* [] */0 -}; - -let test_id = { - contents: 0 -}; - -function eq(loc, x, y) { - Mt.eq_suites(test_id, suites, loc, x, y); -} - -function escaped(s) { - let n = 0; - for (let i = 0, i_finish = s.length; i < i_finish; ++i) { - let match = s[i]; - n = n + ( - match >= 32 ? ( - match > 92 || match < 34 ? ( - match >= 127 ? 4 : 1 - ) : ( - match > 91 || match < 35 ? 2 : 1 - ) - ) : ( - match >= 11 ? ( - match !== 13 ? 4 : 2 - ) : ( - match >= 8 ? 2 : 4 - ) - ) - ) | 0; - } - if (n === s.length) { - return Bytes.copy(s); - } - let s$p = Caml_bytes.create(n); - n = 0; - for (let i$1 = 0, i_finish$1 = s.length; i$1 < i_finish$1; ++i$1) { - let c = s[i$1]; - let exit = 0; - if (c >= 35) { - if (c !== 92) { - if (c >= 127) { - exit = 1; - } else { - s$p[n] = c; - } - } else { - exit = 2; - } - } else if (c >= 32) { - if (c >= 34) { - exit = 2; - } else { - s$p[n] = c; - } - } else if (c >= 14) { - exit = 1; - } else { - switch (c) { - case 8 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 'b' */98; - break; - case 9 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 't' */116; - break; - case 10 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 'n' */110; - break; - case 0 : - case 1 : - case 2 : - case 3 : - case 4 : - case 5 : - case 6 : - case 7 : - case 11 : - case 12 : - exit = 1; - break; - case 13 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 'r' */114; - break; - } - } - switch (exit) { - case 1 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = 48 + (c / 100 | 0) | 0; - n = n + 1 | 0; - s$p[n] = 48 + (c / 10 | 0) % 10 | 0; - n = n + 1 | 0; - s$p[n] = 48 + c % 10 | 0; - break; - case 2 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = c; - break; - } - n = n + 1 | 0; - } - return s$p; -} - -function starts_with(xs, prefix, p) { - let H = /* @__PURE__ */Caml_exceptions.create("H"); - let len1 = xs.length; - let len2 = prefix.length; - if (len2 > len1) { - return false; - } - try { - for (let i = 0; i < len2; ++i) { - if (!p(Caml_bytes.get(xs, i), Caml_bytes.get(prefix, i))) { - throw { - RE_EXN_ID: H, - Error: new Error() - }; - } - - } - return true; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === H) { - return false; - } - throw exn; - } -} - -let a = Bytes.init(100, Char.chr); - -Bytes.blit(a, 5, a, 10, 10); - -eq("File \"ext_bytes_test.res\", line 116, characters 4-11", a, Bytes.of_string("\x00\x01\x02\x03\x04\x05\x06\x07\b\t\x05\x06\x07\b\t\n\x0b\x0c\r\x0e\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abc")); - -let a$1 = Bytes.init(100, Char.chr); - -Bytes.blit(a$1, 10, a$1, 5, 10); - -eq("File \"ext_bytes_test.res\", line 128, characters 4-11", a$1, Bytes.of_string("\x00\x01\x02\x03\x04\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abc")); - -let f = Char.chr; - -let a$2 = Bytes.unsafe_to_string(Bytes.init(100, f)); - -let b = Bytes.init(100, i => /* '\000' */0); - -Bytes.blit_string(a$2, 10, b, 5, 10); - -eq("File \"ext_bytes_test.res\", line 141, characters 4-11", b, Bytes.of_string("\x00\x00\x00\x00\x00\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")); - -let s = Bytes.init(50000, i => Char.chr(i % 137)); - -let s1 = Bytes.to_string(s); - -let s2 = Bytes.of_string(s1); - -eq("File \"ext_bytes_test.res\", line 153, characters 5-12", s, s2); - -function f$1(a, b) { - return [ - Caml_bytes.bytes_greaterthan(a, b), - Caml_bytes.bytes_greaterequal(a, b), - Caml_bytes.bytes_lessthan(a, b), - Caml_bytes.bytes_lessequal(a, b), - Caml_bytes.bytes_equal(a, b) - ]; -} - -function f_0(a, b) { - return [ - Caml.i64_gt(a, b), - Caml.i64_ge(a, b), - Caml.i64_lt(a, b), - Caml.i64_le(a, b), - Caml.i64_eq(a, b) - ]; -} - -Mt.from_pair_suites("Ext_bytes_test", suites.contents); - -exports.suites = suites; -exports.test_id = test_id; -exports.eq = eq; -exports.escaped = escaped; -exports.starts_with = starts_with; -exports.f = f$1; -exports.f_0 = f_0; -/* a Not a pure module */ diff --git a/jscomp/test/ext_bytes_test.res b/jscomp/test/ext_bytes_test.res deleted file mode 100644 index 1672db940f..0000000000 Binary files a/jscomp/test/ext_bytes_test.res and /dev/null differ diff --git a/jscomp/test/ext_filename_test.js b/jscomp/test/ext_filename_test.js deleted file mode 100644 index 40c76532e1..0000000000 --- a/jscomp/test/ext_filename_test.js +++ /dev/null @@ -1,372 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Sys = require("../../lib/js/sys.js"); -let List = require("../../lib/js/list.js"); -let $$Array = require("../../lib/js/array.js"); -let Bytes = require("../../lib/js/bytes.js"); -let Caml_sys = require("../../lib/js/caml_sys.js"); -let Filename = require("../../lib/js/filename.js"); -let Pervasives = require("../../lib/js/pervasives.js"); -let Test_literals = require("./test_literals.js"); -let Ext_string_test = require("./ext_string_test.js"); -let CamlinternalLazy = require("../../lib/js/camlinternalLazy.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); - -let node_sep = "/"; - -let node_parent = ".."; - -let node_current = "."; - -let cwd = CamlinternalLazy.from_fun(() => Caml_sys.sys_getcwd()); - -function path_as_directory(x) { - if (x === "" || Ext_string_test.ends_with(x, Filename.dir_sep)) { - return x; - } else { - return x + Filename.dir_sep; - } -} - -function absolute_path(s) { - let s$1 = Filename.is_relative(s) ? Filename.concat(CamlinternalLazy.force(cwd), s) : s; - let aux = _s => { - while (true) { - let s = _s; - let base = Filename.basename(s); - let dir = Filename.dirname(s); - if (dir === s) { - return dir; - } - if (base !== Filename.current_dir_name) { - if (base === Filename.parent_dir_name) { - return Filename.dirname(aux(dir)); - } else { - return Filename.concat(aux(dir), base); - } - } - _s = dir; - continue; - }; - }; - return aux(s$1); -} - -function chop_extension(locOpt, name) { - let loc = locOpt !== undefined ? locOpt : ""; - try { - return Filename.chop_extension(name); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Invalid_argument") { - let s = "Filename.chop_extension ( " + loc + " : " + name + " )"; - throw { - RE_EXN_ID: "Invalid_argument", - _1: s, - Error: new Error() - }; - } - throw exn; - } -} - -function chop_extension_if_any(fname) { - try { - return Filename.chop_extension(fname); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Invalid_argument") { - return fname; - } - throw exn; - } -} - -let os_path_separator_char = Filename.dir_sep.codePointAt(0); - -function relative_path(file_or_dir_1, file_or_dir_2) { - let relevant_dir1 = file_or_dir_1.NAME === "File" ? Filename.dirname(file_or_dir_1.VAL) : file_or_dir_1.VAL; - let relevant_dir2 = file_or_dir_2.NAME === "File" ? Filename.dirname(file_or_dir_2.VAL) : file_or_dir_2.VAL; - let dir1 = Ext_string_test.split(undefined, relevant_dir1, os_path_separator_char); - let dir2 = Ext_string_test.split(undefined, relevant_dir2, os_path_separator_char); - let go = (_dir1, _dir2) => { - while (true) { - let dir2 = _dir2; - let dir1 = _dir1; - if (dir1 && dir2 && dir1.hd === dir2.hd) { - _dir2 = dir2.tl; - _dir1 = dir1.tl; - continue; - } - return Pervasives.$at(List.map(param => node_parent, dir2), dir1); - }; - }; - let ys = go(dir1, dir2); - if (ys && ys.hd === node_parent) { - return $$Array.of_list(ys).join(node_sep); - } - let xs = { - hd: node_current, - tl: ys - }; - return $$Array.of_list(xs).join(node_sep); -} - -function node_relative_path(node_modules_shorten, file1, dep_file) { - let file2 = dep_file.VAL; - let v = Ext_string_test.find(undefined, Test_literals.node_modules, file2); - let len = file2.length; - if (!(node_modules_shorten && v >= 0)) { - return relative_path(dep_file.NAME === "File" ? ({ - NAME: "File", - VAL: absolute_path(dep_file.VAL) - }) : ({ - NAME: "Dir", - VAL: absolute_path(dep_file.VAL) - }), file1.NAME === "File" ? ({ - NAME: "File", - VAL: absolute_path(file1.VAL) - }) : ({ - NAME: "Dir", - VAL: absolute_path(file1.VAL) - })) + (node_sep + Filename.basename(file2)); - } - let skip = _i => { - while (true) { - let i = _i; - if (i >= len) { - let s = "invalid path: " + file2; - throw { - RE_EXN_ID: "Failure", - _1: s, - Error: new Error() - }; - } - let curr_char = file2.codePointAt(i); - if (!(curr_char === os_path_separator_char || curr_char === /* '.' */46)) { - return i; - } - _i = i + 1 | 0; - continue; - }; - }; - return Ext_string_test.tail_from(file2, skip(v + Test_literals.node_modules_length | 0)); -} - -function find_root_filename(_cwd, filename) { - while (true) { - let cwd = _cwd; - if (Caml_sys.sys_file_exists(Filename.concat(cwd, filename))) { - return cwd; - } - let cwd$p = Filename.dirname(cwd); - if (cwd$p.length < cwd.length) { - _cwd = cwd$p; - continue; - } - let s = filename + " not found from " + cwd; - throw { - RE_EXN_ID: "Failure", - _1: s, - Error: new Error() - }; - }; -} - -function find_package_json_dir(cwd) { - return find_root_filename(cwd, Test_literals.bsconfig_json); -} - -let package_dir = CamlinternalLazy.from_fun(() => { - let cwd$1 = CamlinternalLazy.force(cwd); - return find_root_filename(cwd$1, Test_literals.bsconfig_json); -}); - -function module_name_of_file(file) { - let s = Filename.chop_extension(Filename.basename(file)); - return Bytes.unsafe_to_string(Bytes.capitalize_ascii(Bytes.unsafe_of_string(s))); -} - -function module_name_of_file_if_any(file) { - let s = chop_extension_if_any(Filename.basename(file)); - return Bytes.unsafe_to_string(Bytes.capitalize_ascii(Bytes.unsafe_of_string(s))); -} - -function combine(p1, p2) { - if (p1 === "" || p1 === Filename.current_dir_name) { - return p2; - } else if (p2 === "" || p2 === Filename.current_dir_name) { - return p1; - } else if (Filename.is_relative(p2)) { - return Filename.concat(p1, p2); - } else { - return p2; - } -} - -function split_aux(p) { - let _p = p; - let _acc = /* [] */0; - while (true) { - let acc = _acc; - let p$1 = _p; - let dir = Filename.dirname(p$1); - if (dir === p$1) { - return [ - dir, - acc - ]; - } - let new_path = Filename.basename(p$1); - if (new_path === Filename.dir_sep) { - _p = dir; - continue; - } - _acc = { - hd: new_path, - tl: acc - }; - _p = dir; - continue; - }; -} - -function rel_normalized_absolute_path(from, to_) { - let match = split_aux(from); - let match$1 = split_aux(to_); - let root2 = match$1[0]; - if (match[0] !== root2) { - return root2; - } - let _xss = match[1]; - let _yss = match$1[1]; - while (true) { - let yss = _yss; - let xss = _xss; - if (!xss) { - if (yss) { - return List.fold_left(Filename.concat, yss.hd, yss.tl); - } else { - return Ext_string_test.empty; - } - } - let xs = xss.tl; - if (!yss) { - return List.fold_left((acc, param) => Filename.concat(acc, Ext_string_test.parent_dir_lit), Ext_string_test.parent_dir_lit, xs); - } - if (xss.hd === yss.hd) { - _yss = yss.tl; - _xss = xs; - continue; - } - let start = List.fold_left((acc, param) => Filename.concat(acc, Ext_string_test.parent_dir_lit), Ext_string_test.parent_dir_lit, xs); - return List.fold_left(Filename.concat, start, yss); - }; -} - -function normalize_absolute_path(x) { - let drop_if_exist = xs => { - if (xs) { - return xs.tl; - } else { - return /* [] */0; - } - }; - let normalize_list = (_acc, _paths) => { - while (true) { - let paths = _paths; - let acc = _acc; - if (!paths) { - return acc; - } - let xs = paths.tl; - let x = paths.hd; - if (x === Ext_string_test.current_dir_lit) { - _paths = xs; - continue; - } - if (x === Ext_string_test.parent_dir_lit) { - _paths = xs; - _acc = drop_if_exist(acc); - continue; - } - _paths = xs; - _acc = { - hd: x, - tl: acc - }; - continue; - }; - }; - let match = split_aux(x); - let root = match[0]; - let rev_paths = normalize_list(/* [] */0, match[1]); - if (rev_paths) { - let _acc = rev_paths.hd; - let _rev_paths = rev_paths.tl; - while (true) { - let rev_paths$1 = _rev_paths; - let acc = _acc; - if (!rev_paths$1) { - return Filename.concat(root, acc); - } - _rev_paths = rev_paths$1.tl; - _acc = Filename.concat(rev_paths$1.hd, acc); - continue; - }; - } else { - return root; - } -} - -function get_extension(x) { - let pos = Ext_string_test.rindex_neg(x, /* '.' */46); - if (pos < 0) { - return ""; - } else { - return Ext_string_test.tail_from(x, pos); - } -} - -let simple_convert_node_path_to_os_path; - -if (Sys.unix) { - simple_convert_node_path_to_os_path = x => x; -} else if (Sys.win32 || false) { - simple_convert_node_path_to_os_path = Ext_string_test.replace_slash_backward; -} else { - let s = "Unknown OS : " + Sys.os_type; - throw { - RE_EXN_ID: "Failure", - _1: s, - Error: new Error() - }; -} - -let $slash$slash = Filename.concat; - -exports.node_sep = node_sep; -exports.node_parent = node_parent; -exports.node_current = node_current; -exports.cwd = cwd; -exports.$slash$slash = $slash$slash; -exports.path_as_directory = path_as_directory; -exports.absolute_path = absolute_path; -exports.chop_extension = chop_extension; -exports.chop_extension_if_any = chop_extension_if_any; -exports.os_path_separator_char = os_path_separator_char; -exports.relative_path = relative_path; -exports.node_relative_path = node_relative_path; -exports.find_root_filename = find_root_filename; -exports.find_package_json_dir = find_package_json_dir; -exports.package_dir = package_dir; -exports.module_name_of_file = module_name_of_file; -exports.module_name_of_file_if_any = module_name_of_file_if_any; -exports.combine = combine; -exports.split_aux = split_aux; -exports.rel_normalized_absolute_path = rel_normalized_absolute_path; -exports.normalize_absolute_path = normalize_absolute_path; -exports.get_extension = get_extension; -exports.simple_convert_node_path_to_os_path = simple_convert_node_path_to_os_path; -/* simple_convert_node_path_to_os_path Not a pure module */ diff --git a/jscomp/test/ext_filename_test.res b/jscomp/test/ext_filename_test.res deleted file mode 100644 index 1237d97f1c..0000000000 --- a/jscomp/test/ext_filename_test.res +++ /dev/null @@ -1,386 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -/** Used when produce node compatible paths */ -let node_sep = "/" -let node_parent = ".." -let node_current = "." - -type t = [ - | #File(string) - | #Dir(string) -] - -let cwd = Lazy.from_fun(() => Sys.getcwd()) - -let \"//" = Filename.concat - -let combine = (path1, path2) => - if path1 == "" { - path2 - } else if path2 == "" { - path1 - } else if Filename.is_relative(path2) { - \"//"(path1, path2) - } else { - path2 - } - -/* Note that [.//] is the same as [./] */ -let path_as_directory = x => - if x == "" { - x - } else if Ext_string_test.ends_with(x, Filename.dir_sep) { - x - } else { - x ++ Filename.dir_sep - } - -let absolute_path = s => { - let process = s => { - let s = if Filename.is_relative(s) { - \"//"(Lazy.force(cwd), s) - } else { - s - } - /* Now simplify . and .. components */ - let rec aux = s => { - let (base, dir) = (Filename.basename(s), Filename.dirname(s)) - if dir == s { - dir - } else if base == Filename.current_dir_name { - aux(dir) - } else if base == Filename.parent_dir_name { - Filename.dirname(aux(dir)) - } else { - \"//"(aux(dir), base) - } - } - aux(s) - } - process(s) -} - -let chop_extension = (~loc="", name) => - try Filename.chop_extension(name) catch { - | Invalid_argument(_) => invalid_arg("Filename.chop_extension ( " ++ loc ++ " : " ++ name ++ " )") - } - -let chop_extension_if_any = fname => - try Filename.chop_extension(fname) catch { - | Invalid_argument(_) => fname - } - -let os_path_separator_char = String.unsafe_get(Filename.dir_sep, 0) - -/** example - {[ - \"/bb/mbigc/mbig2899/bgit/bucklescript/jscomp/stdlib/external/pervasives.cmj\" - \"/bb/mbigc/mbig2899/bgit/bucklescript/jscomp/stdlib/ocaml_array.ml\" - ]} - - The other way - {[ - - \"/bb/mbigc/mbig2899/bgit/bucklescript/jscomp/stdlib/ocaml_array.ml\" - \"/bb/mbigc/mbig2899/bgit/bucklescript/jscomp/stdlib/external/pervasives.cmj\" - ]} - {[ - \"/bb/mbigc/mbig2899/bgit/bucklescript/jscomp/stdlib//ocaml_array.ml\" - ]} - {[ - /a/b - /c/d - ]} -*/ -let relative_path = (file_or_dir_1, file_or_dir_2) => { - let sep_char = os_path_separator_char - let relevant_dir1 = switch file_or_dir_1 { - | #Dir(x) => x - | #File(file1) => Filename.dirname(file1) - } - let relevant_dir2 = switch file_or_dir_2 { - | #Dir(x) => x - | #File(file2) => Filename.dirname(file2) - } - let dir1 = Ext_string_test.split(relevant_dir1, sep_char) - let dir2 = Ext_string_test.split(relevant_dir2, sep_char) - let rec go = (dir1: list, dir2: list) => - switch (dir1, dir2) { - | (list{x, ...xs}, list{y, ...ys}) if x == y => go(xs, ys) - | (_, _) => \"@"(List.map(_ => node_parent, dir2), dir1) - } - - switch go(dir1, dir2) { - | list{x, ..._} as ys if x == node_parent => String.concat(node_sep, ys) - | ys => \"@@"(String.concat(node_sep, _), list{node_current, ...ys}) - } -} - -/** path2: a/b - path1: a - result: ./b - TODO: [Filename.concat] with care - - [file1] is currently compilation file - [file2] is the dependency - - TODO: this is a hackish function: FIXME -*/ -let node_relative_path = ( - node_modules_shorten, - file1: t, - #File(file2) as dep_file: [#File(string)], -) => { - let v = Ext_string_test.find(file2, ~sub=Test_literals.node_modules) - let len = String.length(file2) - if node_modules_shorten && v >= 0 { - let rec skip = i => - if i >= len { - failwith("invalid path: " ++ file2) - } else { - /* https://en.wikipedia.org/wiki/Path_(computing)) - most path separator are a single char - */ - let curr_char = String.unsafe_get(file2, i) - if curr_char == os_path_separator_char || curr_char == '.' { - skip(i + 1) - } else { - i - } - } - /* - TODO: we need do more than this suppose user - input can be - {[ - "xxxghsoghos/ghsoghso/node_modules/../buckle-stdlib/list.js" - ]} - This seems weird though - */ - - Ext_string_test.tail_from(file2, skip(v + Test_literals.node_modules_length)) - } else { - relative_path( - switch dep_file { - | #File(x) => #File(absolute_path(x)) - | #Dir(x) => #Dir(absolute_path(x)) - }, - switch file1 { - | #File(x) => #File(absolute_path(x)) - | #Dir(x) => #Dir(absolute_path(x)) - }, - ) ++ - (node_sep ++ - /* chop_extension_if_any */ Filename.basename(file2)) - } -} - -/* Input must be absolute directory */ -let rec find_root_filename = (~cwd, filename) => - if Sys.file_exists(\"//"(cwd, filename)) { - cwd - } else { - let cwd' = Filename.dirname(cwd) - if String.length(cwd') < String.length(cwd) { - find_root_filename(~cwd=cwd', filename) - } else { - failwith("" ++ filename ++ " not found from " ++ cwd) - } - } - -let find_package_json_dir = cwd => find_root_filename(~cwd, Test_literals.bsconfig_json) - -let package_dir = Lazy.from_fun(() => find_package_json_dir(Lazy.force(cwd))) - -let module_name_of_file = file => - String.capitalize_ascii(\"@@"(Filename.chop_extension, Filename.basename(file))) - -let module_name_of_file_if_any = file => - String.capitalize_ascii(\"@@"(chop_extension_if_any, Filename.basename(file))) - -/* For win32 or case insensitve OS - [\".cmj\"] is the same as [\".CMJ\"] -*/ -/* let has_exact_suffix_then_chop fname suf = */ - -let combine = (p1, p2) => - if p1 == "" || p1 == Filename.current_dir_name { - p2 - } else if p2 == "" || p2 == Filename.current_dir_name { - p1 - } else if Filename.is_relative(p2) { - Filename.concat(p1, p2) - } else { - p2 - } - -/** - {[ - split_aux \"//ghosg//ghsogh/\";; - - : string * string list = (\"/\", [\"ghosg\"; \"ghsogh\"]) - ]} - Note that - {[ - Filename.dirname \"/a/\" = \"/\" - Filename.dirname \"/a/b/\" = Filename.dirname \"/a/b\" = \"/a\" - ]} - Special case: - {[ - basename \"//\" = \"/\" - basename \"///\" = \"/\" - ]} - {[ - basename \"\" = \".\" - basename \"\" = \".\" - dirname \"\" = \".\" - dirname \"\" = \".\" - ]} -*/ -let split_aux = p => { - let rec go = (p, acc) => { - let dir = Filename.dirname(p) - if dir == p { - (dir, acc) - } else { - let new_path = Filename.basename(p) - if Ext_string_test.equal(new_path, Filename.dir_sep) { - go(dir, acc) - } else { - /* We could do more path simplification here - leave to [rel_normalized_absolute_path] - */ - - go(dir, list{new_path, ...acc}) - } - } - } - - go(p, list{}) -} - -/** - TODO: optimization - if [from] and [to] resolve to the same path, a zero-length string is returned -*/ -let rel_normalized_absolute_path = (from, to_) => { - let (root1, paths1) = split_aux(from) - let (root2, paths2) = split_aux(to_) - if root1 != root2 { - root2 - } else { - let rec go = (xss, yss) => - switch (xss, yss) { - | (list{x, ...xs}, list{y, ...ys}) => - if Ext_string_test.equal(x, y) { - go(xs, ys) - } else { - let start = List.fold_left( - (acc, _) => \"//"(acc, Ext_string_test.parent_dir_lit), - Ext_string_test.parent_dir_lit, - xs, - ) - List.fold_left((acc, v) => \"//"(acc, v), start, yss) - } - | (list{}, list{}) => Ext_string_test.empty - | (list{}, list{y, ...ys}) => List.fold_left((acc, x) => \"//"(acc, x), y, ys) - | (list{x, ...xs}, list{}) => - List.fold_left( - (acc, _) => \"//"(acc, Ext_string_test.parent_dir_lit), - Ext_string_test.parent_dir_lit, - xs, - ) - } - go(paths1, paths2) - } -} - -/* TODO: could be hgighly optimized later - {[ - normalize_absolute_path "/gsho/./..";; - - normalize_absolute_path "/a/b/../c../d/e/f";; - - normalize_absolute_path "/gsho/./..";; - - normalize_absolute_path "/gsho/./../..";; - - normalize_absolute_path "/a/b/c/d";; - - normalize_absolute_path "/a/b/c/d/";; - - normalize_absolute_path "/a/";; - - normalize_absolute_path "/a";; - ]} -*/ - -/** See tests in {!Ounit_path_tests} */ -let normalize_absolute_path = x => { - let drop_if_exist = xs => - switch xs { - | list{} => list{} - | list{_, ...xs} => xs - } - let rec normalize_list = (acc, paths) => - switch paths { - | list{} => acc - | list{x, ...xs} => - if Ext_string_test.equal(x, Ext_string_test.current_dir_lit) { - normalize_list(acc, xs) - } else if Ext_string_test.equal(x, Ext_string_test.parent_dir_lit) { - normalize_list(drop_if_exist(acc), xs) - } else { - normalize_list(list{x, ...acc}, xs) - } - } - - let (root, paths) = split_aux(x) - let rev_paths = normalize_list(list{}, paths) - let rec go = (acc, rev_paths) => - switch rev_paths { - | list{} => Filename.concat(root, acc) - | list{last, ...rest} => go(Filename.concat(last, acc), rest) - } - switch rev_paths { - | list{} => root - | list{last, ...rest} => go(last, rest) - } -} - -let get_extension = x => { - let pos = Ext_string_test.rindex_neg(x, '.') - if pos < 0 { - "" - } else { - Ext_string_test.tail_from(x, pos) - } -} - -let simple_convert_node_path_to_os_path = if Sys.unix { - x => x -} else if Sys.win32 || Sys.cygwin { - Ext_string_test.replace_slash_backward -} else { - failwith("Unknown OS : " ++ Sys.os_type) -} diff --git a/jscomp/test/ext_list_test.js b/jscomp/test/ext_list_test.js deleted file mode 100644 index 0293bd0bb7..0000000000 --- a/jscomp/test/ext_list_test.js +++ /dev/null @@ -1,981 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let List = require("../../lib/js/list.js"); -let $$Array = require("../../lib/js/array.js"); -let Caml_option = require("../../lib/js/caml_option.js"); -let Ext_string_test = require("./ext_string_test.js"); - -function filter_map(f, _xs) { - while (true) { - let xs = _xs; - if (!xs) { - return /* [] */0; - } - let ys = xs.tl; - let z = f(xs.hd); - if (z !== undefined) { - return { - hd: Caml_option.valFromOption(z), - tl: filter_map(f, ys) - }; - } - _xs = ys; - continue; - }; -} - -function excludes(p, l) { - let excluded = { - contents: false - }; - let aux = (_accu, _x) => { - while (true) { - let x = _x; - let accu = _accu; - if (!x) { - return List.rev(accu); - } - let l = x.tl; - let x$1 = x.hd; - if (p(x$1)) { - excluded.contents = true; - _x = l; - continue; - } - _x = l; - _accu = { - hd: x$1, - tl: accu - }; - continue; - }; - }; - let v = aux(/* [] */0, l); - if (excluded.contents) { - return [ - true, - v - ]; - } else { - return [ - false, - l - ]; - } -} - -function exclude_with_fact(p, l) { - let excluded = { - contents: undefined - }; - let aux = (_accu, _x) => { - while (true) { - let x = _x; - let accu = _accu; - if (!x) { - return List.rev(accu); - } - let l = x.tl; - let x$1 = x.hd; - if (p(x$1)) { - excluded.contents = Caml_option.some(x$1); - _x = l; - continue; - } - _x = l; - _accu = { - hd: x$1, - tl: accu - }; - continue; - }; - }; - let v = aux(/* [] */0, l); - return [ - excluded.contents, - excluded.contents !== undefined ? v : l - ]; -} - -function exclude_with_fact2(p1, p2, l) { - let excluded1 = { - contents: undefined - }; - let excluded2 = { - contents: undefined - }; - let aux = (_accu, _x) => { - while (true) { - let x = _x; - let accu = _accu; - if (!x) { - return List.rev(accu); - } - let l = x.tl; - let x$1 = x.hd; - if (p1(x$1)) { - excluded1.contents = Caml_option.some(x$1); - _x = l; - continue; - } - if (p2(x$1)) { - excluded2.contents = Caml_option.some(x$1); - _x = l; - continue; - } - _x = l; - _accu = { - hd: x$1, - tl: accu - }; - continue; - }; - }; - let v = aux(/* [] */0, l); - return [ - excluded1.contents, - excluded2.contents, - excluded1.contents !== undefined && excluded2.contents !== undefined ? v : l - ]; -} - -function same_length(_xs, _ys) { - while (true) { - let ys = _ys; - let xs = _xs; - if (!xs) { - if (ys) { - return false; - } else { - return true; - } - } - if (!ys) { - return false; - } - _ys = ys.tl; - _xs = xs.tl; - continue; - }; -} - -function filter_mapi(f, xs) { - let aux = (_i, _xs) => { - while (true) { - let xs = _xs; - let i = _i; - if (!xs) { - return /* [] */0; - } - let ys = xs.tl; - let z = f(i, xs.hd); - if (z !== undefined) { - return { - hd: Caml_option.valFromOption(z), - tl: aux(i + 1 | 0, ys) - }; - } - _xs = ys; - _i = i + 1 | 0; - continue; - }; - }; - return aux(0, xs); -} - -function filter_map2(f, _xs, _ys) { - while (true) { - let ys = _ys; - let xs = _xs; - if (xs) { - if (ys) { - let vs = ys.tl; - let us = xs.tl; - let z = f(xs.hd, ys.hd); - if (z !== undefined) { - return { - hd: Caml_option.valFromOption(z), - tl: filter_map2(f, us, vs) - }; - } - _ys = vs; - _xs = us; - continue; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Ext_list_test.filter_map2", - Error: new Error() - }; - } - if (!ys) { - return /* [] */0; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Ext_list_test.filter_map2", - Error: new Error() - }; - }; -} - -function filter_map2i(f, xs, ys) { - let aux = (_i, _xs, _ys) => { - while (true) { - let ys = _ys; - let xs = _xs; - let i = _i; - if (xs) { - if (ys) { - let vs = ys.tl; - let us = xs.tl; - let z = f(i, xs.hd, ys.hd); - if (z !== undefined) { - return { - hd: Caml_option.valFromOption(z), - tl: aux(i + 1 | 0, us, vs) - }; - } - _ys = vs; - _xs = us; - _i = i + 1 | 0; - continue; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Ext_list_test.filter_map2i", - Error: new Error() - }; - } - if (!ys) { - return /* [] */0; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Ext_list_test.filter_map2i", - Error: new Error() - }; - }; - }; - return aux(0, xs, ys); -} - -function rev_map_append(f, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (!l1) { - return l2; - } - _l2 = { - hd: f(l1.hd), - tl: l2 - }; - _l1 = l1.tl; - continue; - }; -} - -function flat_map2(f, lx, ly) { - let _acc = /* [] */0; - let _lx = lx; - let _ly = ly; - while (true) { - let ly$1 = _ly; - let lx$1 = _lx; - let acc = _acc; - if (lx$1) { - if (ly$1) { - _ly = ly$1.tl; - _lx = lx$1.tl; - _acc = List.rev_append(f(lx$1.hd, ly$1.hd), acc); - continue; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Ext_list_test.flat_map2", - Error: new Error() - }; - } - if (ly$1) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Ext_list_test.flat_map2", - Error: new Error() - }; - } - return List.rev(acc); - }; -} - -function flat_map_aux(f, _acc, append, _lx) { - while (true) { - let lx = _lx; - let acc = _acc; - if (!lx) { - return List.rev_append(acc, append); - } - _lx = lx.tl; - _acc = List.rev_append(f(lx.hd), acc); - continue; - }; -} - -function flat_map(f, lx) { - return flat_map_aux(f, /* [] */0, /* [] */0, lx); -} - -function flat_map_acc(f, append, lx) { - return flat_map_aux(f, /* [] */0, append, lx); -} - -function map2_last(f, l1, l2) { - if (l1) { - let l1$1 = l1.tl; - let u = l1.hd; - if (!l1$1) { - if (l2) { - if (!l2.tl) { - return { - hd: f(true, u, l2.hd), - tl: /* [] */0 - }; - } - - } else { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.map2_last", - Error: new Error() - }; - } - } - if (l2) { - let r = f(false, u, l2.hd); - return { - hd: r, - tl: map2_last(f, l1$1, l2.tl) - }; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.map2_last", - Error: new Error() - }; - } - if (!l2) { - return /* [] */0; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.map2_last", - Error: new Error() - }; -} - -function map_last(f, l1) { - if (!l1) { - return /* [] */0; - } - let l1$1 = l1.tl; - let u = l1.hd; - if (!l1$1) { - return { - hd: f(true, u), - tl: /* [] */0 - }; - } - let r = f(false, u); - return { - hd: r, - tl: map_last(f, l1$1) - }; -} - -function fold_right2_last(f, l1, l2, accu) { - if (l1) { - let l1$1 = l1.tl; - let last1 = l1.hd; - if (!l1$1) { - if (l2) { - if (!l2.tl) { - return f(true, last1, l2.hd, accu); - } - - } else { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_right2", - Error: new Error() - }; - } - } - if (l2) { - return f(false, last1, l2.hd, fold_right2_last(f, l1$1, l2.tl, accu)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_right2", - Error: new Error() - }; - } - if (l2) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_right2", - Error: new Error() - }; - } - return accu; -} - -function init(n, f) { - return $$Array.to_list($$Array.init(n, f)); -} - -function take(n, l) { - let arr = $$Array.of_list(l); - let arr_length = arr.length; - if (arr_length < n) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Ext_list_test.take", - Error: new Error() - }; - } - return [ - $$Array.to_list($$Array.sub(arr, 0, n)), - $$Array.to_list($$Array.sub(arr, n, arr_length - n | 0)) - ]; -} - -function try_take(n, l) { - let arr = $$Array.of_list(l); - let arr_length = arr.length; - if (arr_length <= n) { - return [ - l, - arr_length, - /* [] */0 - ]; - } else { - return [ - $$Array.to_list($$Array.sub(arr, 0, n)), - n, - $$Array.to_list($$Array.sub(arr, n, arr_length - n | 0)) - ]; - } -} - -function length_compare(_l, _n) { - while (true) { - let n = _n; - let l = _l; - if (n < 0) { - return "Gt"; - } - if (!l) { - if (n === 0) { - return "Eq"; - } else { - return "Lt"; - } - } - _n = n - 1 | 0; - _l = l.tl; - continue; - }; -} - -function length_larger_than_n(n, _xs, _ys) { - while (true) { - let ys = _ys; - let xs = _xs; - if (!ys) { - return length_compare(xs, n) === "Eq"; - } - if (!xs) { - return false; - } - _ys = ys.tl; - _xs = xs.tl; - continue; - }; -} - -function exclude_tail(x) { - let _acc = /* [] */0; - let _x = x; - while (true) { - let x$1 = _x; - let acc = _acc; - if (x$1) { - let ys = x$1.tl; - let x$2 = x$1.hd; - if (!ys) { - return [ - x$2, - List.rev(acc) - ]; - } - _x = ys; - _acc = { - hd: x$2, - tl: acc - }; - continue; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Ext_list_test.exclude_tail", - Error: new Error() - }; - }; -} - -function group(cmp, lst) { - if (lst) { - return aux(cmp, lst.hd, group(cmp, lst.tl)); - } else { - return /* [] */0; - } -} - -function aux(cmp, x, xss) { - if (!xss) { - return { - hd: { - hd: x, - tl: /* [] */0 - }, - tl: /* [] */0 - }; - } - let ys = xss.tl; - let y = xss.hd; - if (cmp(x, List.hd(y))) { - return { - hd: { - hd: x, - tl: y - }, - tl: ys - }; - } else { - return { - hd: y, - tl: aux(cmp, x, ys) - }; - } -} - -function stable_group(cmp, lst) { - return List.rev(group(cmp, lst)); -} - -function drop(_n, _h) { - while (true) { - let h = _h; - let n = _n; - if (n < 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Ext_list_test.drop", - Error: new Error() - }; - } - if (n === 0) { - return h; - } - if (h === /* [] */0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Ext_list_test.drop", - Error: new Error() - }; - } - _h = List.tl(h); - _n = n - 1 | 0; - continue; - }; -} - -function find_first_not(p, _x) { - while (true) { - let x = _x; - if (!x) { - return; - } - let a = x.hd; - if (!p(a)) { - return Caml_option.some(a); - } - _x = x.tl; - continue; - }; -} - -function for_all_opt(p, _x) { - while (true) { - let x = _x; - if (!x) { - return; - } - let v = p(x.hd); - if (v !== undefined) { - return v; - } - _x = x.tl; - continue; - }; -} - -function fold(f, l, init) { - return List.fold_left((acc, i) => f(i, init), init, l); -} - -function rev_map_acc(acc, f, l) { - let _accu = acc; - let _x = l; - while (true) { - let x = _x; - let accu = _accu; - if (!x) { - return accu; - } - _x = x.tl; - _accu = { - hd: f(x.hd), - tl: accu - }; - continue; - }; -} - -function map_acc(acc, f, l) { - if (l) { - return { - hd: f(l.hd), - tl: map_acc(acc, f, l.tl) - }; - } else { - return acc; - } -} - -function rev_iter(f, xs) { - if (xs) { - rev_iter(f, xs.tl); - return f(xs.hd); - } - -} - -function for_all2_no_exn(p, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (!l1) { - if (l2) { - return false; - } else { - return true; - } - } - if (!l2) { - return false; - } - if (!p(l1.hd, l2.hd)) { - return false; - } - _l2 = l2.tl; - _l1 = l1.tl; - continue; - }; -} - -function find_no_exn(p, _x) { - while (true) { - let x = _x; - if (!x) { - return; - } - let x$1 = x.hd; - if (p(x$1)) { - return Caml_option.some(x$1); - } - _x = x.tl; - continue; - }; -} - -function find_opt(p, _x) { - while (true) { - let x = _x; - if (!x) { - return; - } - let v = p(x.hd); - if (v !== undefined) { - return v; - } - _x = x.tl; - continue; - }; -} - -function split_map(f, xs) { - let _bs = /* [] */0; - let _cs = /* [] */0; - let _xs = xs; - while (true) { - let xs$1 = _xs; - let cs = _cs; - let bs = _bs; - if (!xs$1) { - return [ - List.rev(bs), - List.rev(cs) - ]; - } - let match = f(xs$1.hd); - _xs = xs$1.tl; - _cs = { - hd: match[1], - tl: cs - }; - _bs = { - hd: match[0], - tl: bs - }; - continue; - }; -} - -function reduce_from_right(fn, lst) { - let match = List.rev(lst); - if (match) { - return List.fold_left((x, y) => fn(y, x), match.hd, match.tl); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Ext_list_test.reduce", - Error: new Error() - }; -} - -function reduce_from_left(fn, lst) { - if (lst) { - return List.fold_left(fn, lst.hd, lst.tl); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Ext_list_test.reduce_from_left", - Error: new Error() - }; -} - -function create_ref_empty() { - return { - contents: /* [] */0 - }; -} - -function ref_top(x) { - let match = x.contents; - if (match) { - return match.hd; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Ext_list_test.ref_top", - Error: new Error() - }; -} - -function ref_empty(x) { - let match = x.contents; - if (match) { - return false; - } else { - return true; - } -} - -function ref_push(x, refs) { - refs.contents = { - hd: x, - tl: refs.contents - }; -} - -function ref_pop(refs) { - let match = refs.contents; - if (match) { - refs.contents = match.tl; - return match.hd; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Ext_list_test.ref_pop", - Error: new Error() - }; -} - -function rev_except_last(xs) { - let _acc = /* [] */0; - let _xs = xs; - while (true) { - let xs$1 = _xs; - let acc = _acc; - if (xs$1) { - let xs$2 = xs$1.tl; - let x = xs$1.hd; - if (!xs$2) { - return [ - acc, - x - ]; - } - _xs = xs$2; - _acc = { - hd: x, - tl: acc - }; - continue; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Ext_list_test.rev_except_last", - Error: new Error() - }; - }; -} - -function sort_via_array(cmp, lst) { - let arr = $$Array.of_list(lst); - $$Array.sort(cmp, arr); - return $$Array.to_list(arr); -} - -function last(_xs) { - while (true) { - let xs = _xs; - if (xs) { - let tl = xs.tl; - if (!tl) { - return xs.hd; - } - _xs = tl; - continue; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Ext_list_test.last", - Error: new Error() - }; - }; -} - -function assoc_by_string(def, k, _lst) { - while (true) { - let lst = _lst; - if (lst) { - let match = lst.hd; - if (match[0] === k) { - return match[1]; - } - _lst = lst.tl; - continue; - } - if (def !== undefined) { - return Caml_option.valFromOption(def); - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "ext_list_test.res", - 472, - 14 - ], - Error: new Error() - }; - }; -} - -function assoc_by_int(def, k, _lst) { - while (true) { - let lst = _lst; - if (lst) { - let match = lst.hd; - if (match[0] === k) { - return match[1]; - } - _lst = lst.tl; - continue; - } - if (def !== undefined) { - return Caml_option.valFromOption(def); - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "ext_list_test.res", - 487, - 14 - ], - Error: new Error() - }; - }; -} - -exports.filter_map = filter_map; -exports.excludes = excludes; -exports.exclude_with_fact = exclude_with_fact; -exports.exclude_with_fact2 = exclude_with_fact2; -exports.same_length = same_length; -exports.filter_mapi = filter_mapi; -exports.filter_map2 = filter_map2; -exports.filter_map2i = filter_map2i; -exports.rev_map_append = rev_map_append; -exports.flat_map2 = flat_map2; -exports.flat_map_aux = flat_map_aux; -exports.flat_map = flat_map; -exports.flat_map_acc = flat_map_acc; -exports.map2_last = map2_last; -exports.map_last = map_last; -exports.fold_right2_last = fold_right2_last; -exports.init = init; -exports.take = take; -exports.try_take = try_take; -exports.length_compare = length_compare; -exports.length_larger_than_n = length_larger_than_n; -exports.exclude_tail = exclude_tail; -exports.group = group; -exports.aux = aux; -exports.stable_group = stable_group; -exports.drop = drop; -exports.find_first_not = find_first_not; -exports.for_all_opt = for_all_opt; -exports.fold = fold; -exports.rev_map_acc = rev_map_acc; -exports.map_acc = map_acc; -exports.rev_iter = rev_iter; -exports.for_all2_no_exn = for_all2_no_exn; -exports.find_no_exn = find_no_exn; -exports.find_opt = find_opt; -exports.split_map = split_map; -exports.reduce_from_right = reduce_from_right; -exports.reduce_from_left = reduce_from_left; -exports.create_ref_empty = create_ref_empty; -exports.ref_top = ref_top; -exports.ref_empty = ref_empty; -exports.ref_push = ref_push; -exports.ref_pop = ref_pop; -exports.rev_except_last = rev_except_last; -exports.sort_via_array = sort_via_array; -exports.last = last; -exports.assoc_by_string = assoc_by_string; -exports.assoc_by_int = assoc_by_int; -/* Ext_string_test Not a pure module */ diff --git a/jscomp/test/ext_list_test.res b/jscomp/test/ext_list_test.res deleted file mode 100644 index bf90e21a09..0000000000 --- a/jscomp/test/ext_list_test.res +++ /dev/null @@ -1,501 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -let rec filter_map = (f: 'a => option<'b>, xs) => - switch xs { - | list{} => list{} - | list{y, ...ys} => - switch f(y) { - | None => filter_map(f, ys) - | Some(z) => list{z, ...filter_map(f, ys)} - } - } - -let excludes = (p: 'a => bool, l): (bool, list<'a>) => { - let excluded = ref(false) - let rec aux = (accu, x) => - switch x { - | list{} => List.rev(accu) - | list{x, ...l} => - if p(x) { - excluded := true - aux(accu, l) - } else { - aux(list{x, ...accu}, l) - } - } - let v = aux(list{}, l) - if excluded.contents { - (true, v) - } else { - (false, l) - } -} - -let exclude_with_fact = (p, l) => { - let excluded = ref(None) - let rec aux = (accu, x) => - switch x { - | list{} => List.rev(accu) - | list{x, ...l} => - if p(x) { - excluded := Some(x) - aux(accu, l) - } else { - aux(list{x, ...accu}, l) - } - } - let v = aux(list{}, l) - ( - excluded.contents, - if excluded.contents != None { - v - } else { - l - }, - ) -} - -/** Make sure [p2 x] and [p1 x] will not hold at the same time */ -let exclude_with_fact2 = (p1, p2, l) => { - let excluded1 = ref(None) - let excluded2 = ref(None) - let rec aux = (accu, x) => - switch x { - | list{} => List.rev(accu) - | list{x, ...l} => - if p1(x) { - excluded1 := Some(x) - aux(accu, l) - } else if p2(x) { - excluded2 := Some(x) - aux(accu, l) - } else { - aux(list{x, ...accu}, l) - } - } - let v = aux(list{}, l) - ( - excluded1.contents, - excluded2.contents, - if excluded1.contents != None && excluded2.contents != None { - v - } else { - l - }, - ) -} - -let rec same_length = (xs, ys) => - switch (xs, ys) { - | (list{}, list{}) => true - | (list{_, ...xs}, list{_, ...ys}) => same_length(xs, ys) - | (_, _) => false - } - -let filter_mapi = (f: (int, 'a) => option<'b>, xs) => { - let rec aux = (i, xs) => - switch xs { - | list{} => list{} - | list{y, ...ys} => - switch f(i, y) { - | None => aux(i + 1, ys) - | Some(z) => list{z, ...aux(i + 1, ys)} - } - } - aux(0, xs) -} - -let rec filter_map2 = (f: ('a, 'b) => option<'c>, xs, ys) => - switch (xs, ys) { - | (list{}, list{}) => list{} - | (list{u, ...us}, list{v, ...vs}) => - switch f(u, v) { - | None => filter_map2(f, us, vs) /* idea: rec f us vs instead? */ - | Some(z) => list{z, ...filter_map2(f, us, vs)} - } - | _ => invalid_arg("Ext_list_test.filter_map2") - } - -let filter_map2i = (f: (int, 'a, 'b) => option<'c>, xs, ys) => { - let rec aux = (i, xs, ys) => - switch (xs, ys) { - | (list{}, list{}) => list{} - | (list{u, ...us}, list{v, ...vs}) => - switch f(i, u, v) { - | None => aux(i + 1, us, vs) /* idea: rec f us vs instead? */ - | Some(z) => list{z, ...aux(i + 1, us, vs)} - } - | _ => invalid_arg("Ext_list_test.filter_map2i") - } - aux(0, xs, ys) -} - -let rec rev_map_append = (f, l1, l2) => - switch l1 { - | list{} => l2 - | list{a, ...l} => rev_map_append(f, l, list{f(a), ...l2}) - } - -let flat_map2 = (f, lx, ly) => { - let rec aux = (acc, lx, ly) => - switch (lx, ly) { - | (list{}, list{}) => List.rev(acc) - | (list{x, ...xs}, list{y, ...ys}) => aux(List.rev_append(f(x, y), acc), xs, ys) - | (_, _) => invalid_arg("Ext_list_test.flat_map2") - } - aux(list{}, lx, ly) -} - -let rec flat_map_aux = (f, acc, append, lx) => - switch lx { - | list{} => List.rev_append(acc, append) - | list{y, ...ys} => flat_map_aux(f, List.rev_append(f(y), acc), append, ys) - } - -let flat_map = (f, lx) => flat_map_aux(f, list{}, list{}, lx) - -let flat_map_acc = (f, append, lx) => flat_map_aux(f, list{}, append, lx) - -let rec map2_last = (f, l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => list{} - | (list{u}, list{v}) => list{f(true, u, v)} - | (list{a1, ...l1}, list{a2, ...l2}) => - let r = f(false, a1, a2) - list{r, ...map2_last(f, l1, l2)} - | (_, _) => invalid_arg("List.map2_last") - } - -let rec map_last = (f, l1) => - switch l1 { - | list{} => list{} - | list{u} => list{f(true, u)} - | list{a1, ...l1} => - let r = f(false, a1) - list{r, ...map_last(f, l1)} - } - -let rec fold_right2_last = (f, l1, l2, accu) => - switch (l1, l2) { - | (list{}, list{}) => accu - | (list{last1}, list{last2}) => f(true, last1, last2, accu) - | (list{a1, ...l1}, list{a2, ...l2}) => f(false, a1, a2, fold_right2_last(f, l1, l2, accu)) - | (_, _) => invalid_arg("List.fold_right2") - } - -let init = (n, f) => Array.to_list(Array.init(n, f)) - -let take = (n, l) => { - let arr = Array.of_list(l) - let arr_length = Array.length(arr) - if arr_length < n { - invalid_arg("Ext_list_test.take") - } else { - (Array.to_list(Array.sub(arr, 0, n)), Array.to_list(Array.sub(arr, n, arr_length - n))) - } -} - -let try_take = (n, l) => { - let arr = Array.of_list(l) - let arr_length = Array.length(arr) - if arr_length <= n { - (l, arr_length, list{}) - } else { - (Array.to_list(Array.sub(arr, 0, n)), n, Array.to_list(Array.sub(arr, n, arr_length - n))) - } -} - -/** - - {[length xs = length ys + n ]} -*/ -let rec length_compare = (l, n) => - if n < 0 { - #Gt - } else { - switch l { - | list{_, ...xs} => length_compare(xs, n - 1) - | list{} => - if n == 0 { - #Eq - } else { - #Lt - } - } - } - -/** - - {[length xs = length ys + n ]} -*/ -let rec length_larger_than_n = (n, xs, ys) => - switch (xs, ys) { - | (_, list{}) => length_compare(xs, n) == #Eq - | (list{_, ...xs}, list{_, ...ys}) => length_larger_than_n(n, xs, ys) - | (list{}, _) => false - } - -let exclude_tail = (x: list<'a>) => { - let rec aux = (acc, x) => - switch x { - | list{} => invalid_arg("Ext_list_test.exclude_tail") - | list{x} => (x, List.rev(acc)) - | list{y0, ...ys} => aux(list{y0, ...acc}, ys) - } - aux(list{}, x) -} - -/* For small list, only need partial equality - {[ - group (=) [1;2;3;4;3] - ;; - - : int list list = [[3; 3]; [4]; [2]; [1]] - # group (=) [];; - - : 'a list list = [] - ]} -*/ -let rec group = (cmp: ('a, 'a) => bool, lst: list<'a>): list> => - switch lst { - | list{} => list{} - | list{x, ...xs} => aux(cmp, x, group(cmp, xs)) - } - -and aux = (cmp, x: 'a, xss: list>): list> => - switch xss { - | list{} => list{list{x}} - | list{y, ...ys} => - if cmp(x, List.hd(y)) /* cannot be null */ { - list{list{x, ...y}, ...ys} - } else { - list{y, ...aux(cmp, x, ys)} - } - } - -let stable_group = (cmp, lst) => List.rev(group(cmp, lst)) - -let rec drop = (n, h) => - if n < 0 { - invalid_arg("Ext_list_test.drop") - } else if n == 0 { - h - } else if h == list{} { - invalid_arg("Ext_list_test.drop") - } else { - drop(n - 1, List.tl(h)) - } - -let rec find_first_not = (p, x) => - switch x { - | list{} => None - | list{a, ...l} => - if p(a) { - find_first_not(p, l) - } else { - Some(a) - } - } - -let rec for_all_opt = (p, x) => - switch x { - | list{} => None - | list{a, ...l} => - switch p(a) { - | None => for_all_opt(p, l) - | v => v - } - } - -let fold = (f, l, init) => List.fold_left((acc, i) => f(i, init), init, l) - -let rev_map_acc = (acc, f, l) => { - let rec rmap_f = (accu, x) => - switch x { - | list{} => accu - | list{a, ...l} => rmap_f(list{f(a), ...accu}, l) - } - - rmap_f(acc, l) -} - -let rec map_acc = (acc, f, l) => - switch l { - | list{} => acc - | list{h, ...hs} => list{f(h), ...map_acc(acc, f, hs)} - } - -let rec rev_iter = (f, xs) => - switch xs { - | list{} => () - | list{y, ...ys} => - rev_iter(f, ys) - f(y) - } - -let rec for_all2_no_exn = (p, l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => true - | (list{a1, ...l1}, list{a2, ...l2}) => p(a1, a2) && for_all2_no_exn(p, l1, l2) - | (_, _) => false - } - -let rec find_no_exn = (p, x) => - switch x { - | list{} => None - | list{x, ...l} => - if p(x) { - Some(x) - } else { - find_no_exn(p, l) - } - } - -let rec find_opt = (p, x) => - switch x { - | list{} => None - | list{x, ...l} => - switch p(x) { - | Some(_) as v => v - | None => find_opt(p, l) - } - } - -let split_map = (f: 'a => ('b, 'c), xs: list<'a>): (list<'b>, list<'c>) => { - let rec aux = (bs, cs, xs) => - switch xs { - | list{} => (List.rev(bs), List.rev(cs)) - | list{u, ...us} => - let (b, c) = f(u) - aux(list{b, ...bs}, list{c, ...cs}, us) - } - - aux(list{}, list{}, xs) -} - -/* - {[ - reduce_from_right (-) [1;2;3];; - - : int = 2 - # reduce_from_right (-) [1;2;3; 4];; - - : int = -2 - # reduce_from_right (-) [1];; - - : int = 1 - # reduce_from_right (-) [1;2;3; 4; 5];; - - : int = 3 - ]} -*/ -let reduce_from_right = (fn, lst) => - switch List.rev(lst) { - | list{last, ...rest} => List.fold_left((x, y) => fn(y, x), last, rest) - | _ => invalid_arg("Ext_list_test.reduce") - } -let reduce_from_left = (fn, lst) => - switch lst { - | list{first, ...rest} => List.fold_left(fn, first, rest) - | _ => invalid_arg("Ext_list_test.reduce_from_left") - } - -type t<'a> = ref> - -let create_ref_empty = () => ref(list{}) - -let ref_top = x => - switch x.contents { - | list{y, ..._} => y - | _ => invalid_arg("Ext_list_test.ref_top") - } - -let ref_empty = x => - switch x.contents { - | list{} => true - | _ => false - } - -let ref_push = (x, refs) => refs := list{x, ...refs.contents} - -let ref_pop = refs => - switch refs.contents { - | list{} => invalid_arg("Ext_list_test.ref_pop") - | list{x, ...rest} => - refs := rest - x - } - -let rev_except_last = xs => { - let rec aux = (acc, xs) => - switch xs { - | list{} => invalid_arg("Ext_list_test.rev_except_last") - | list{x} => (acc, x) - | list{x, ...xs} => aux(list{x, ...acc}, xs) - } - aux(list{}, xs) -} - -let sort_via_array = (cmp, lst) => { - let arr = Array.of_list(lst) - Array.sort(cmp, arr) - Array.to_list(arr) -} - -let rec last = xs => - switch xs { - | list{x} => x - | list{_, ...tl} => last(tl) - | list{} => invalid_arg("Ext_list_test.last") - } - -let rec assoc_by_string = (def, k: string, lst) => - switch lst { - | list{} => - switch def { - | None => assert(false) - | Some(x) => x - } - | list{(k1, v1), ...rest} => - if Ext_string_test.equal(k1, k) { - v1 - } else { - assoc_by_string(def, k, rest) - } - } - -let rec assoc_by_int = (def, k: int, lst) => - switch lst { - | list{} => - switch def { - | None => assert(false) - | Some(x) => x - } - | list{(k1, v1), ...rest} => - if k1 == k { - v1 - } else { - assoc_by_int(def, k, rest) - } - } - -/* `modulo [1;2;3;4] [1;2;3]` => [1;2;3], Some [4] ` - modulo [1;2;3] [1;2;3;4] => [1;2;3] None - modulo [1;2;3] [1;2;3] => [1;2;3] Some [] - */ diff --git a/jscomp/test/ext_pervasives_test.js b/jscomp/test/ext_pervasives_test.js index d32b817ff6..abdc710db7 100644 --- a/jscomp/test/ext_pervasives_test.js +++ b/jscomp/test/ext_pervasives_test.js @@ -1,9 +1,6 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_string = require("../../lib/js/caml_string.js"); -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); function $$finally(v, action, f) { let e; @@ -17,76 +14,10 @@ function $$finally(v, action, f) { return e; } -function is_pos_pow(n) { - let E = /* @__PURE__ */Caml_exceptions.create("E"); - try { - let _c = 0; - let _n = n; - while (true) { - let n$1 = _n; - let c = _c; - if (n$1 <= 0) { - return -2; - } - if (n$1 === 1) { - return c; - } - if ((n$1 & 1) === 0) { - _n = (n$1 >> 1); - _c = c + 1 | 0; - continue; - } - throw { - RE_EXN_ID: E, - Error: new Error() - }; - }; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === E) { - return -1; - } - throw exn; - } -} - -function is_pos_pow_2(n) { - let E = /* @__PURE__ */Caml_exceptions.create("E"); - try { - let _c = 0; - let _n = n; - while (true) { - let n$1 = _n; - let c = _c; - if (n$1 <= 0) { - return -2; - } - if (n$1 === 1) { - return c; - } - if ((n$1 & 1) === 0) { - _n = (n$1 >> 1); - _c = c + 1 | 0; - continue; - } - throw { - RE_EXN_ID: E, - Error: new Error() - }; - }; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === E) { - return -1; - } - throw exn; - } -} - function hash_variant(s) { let accu = 0; for (let i = 0, i_finish = s.length; i < i_finish; ++i) { - accu = Math.imul(223, accu) + Caml_string.get(s, i) | 0; + accu = Math.imul(223, accu) + s.codePointAt(i) | 0; } accu = accu & 2147483647; if (accu > 1073741823) { @@ -101,8 +32,6 @@ let LargeFile = { }; exports.$$finally = $$finally; -exports.is_pos_pow = is_pos_pow; -exports.is_pos_pow_2 = is_pos_pow_2; exports.hash_variant = hash_variant; exports.LargeFile = LargeFile; /* No side effect */ diff --git a/jscomp/test/ext_pervasives_test.res b/jscomp/test/ext_pervasives_test.res index d10ac5dd1c..daea9db334 100644 --- a/jscomp/test/ext_pervasives_test.res +++ b/jscomp/test/ext_pervasives_test.res @@ -22,7 +22,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -external reraise: exn => 'a = "%reraise" +external reraise: exn => 'a = "%raise" let finally = (v, action, f) => switch f(v) { @@ -34,42 +34,6 @@ let finally = (v, action, f) => e } -let is_pos_pow = n => { - module M = { - exception E - } - let rec aux = (c, n: Int32.t) => - if n <= 0l { - -2 - } else if n == 1l { - c - } else if Int32.logand(n, 1l) == 0l { - aux(c + 1, Int32.shift_right(n, 1)) - } else { - raise(M.E) - } - try aux(0, n) catch { - | M.E => -1 - } -} - -let is_pos_pow_2 = n => { - exception E - let rec aux = (c, n: Int32.t) => - if n <= 0l { - -2 - } else if n == 1l { - c - } else if Int32.logand(n, 1l) == 0l { - aux(c + 1, Int32.shift_right(n, 1)) - } else { - raise(E) - } - try aux(0, n) catch { - | E => -1 - } -} - let hash_variant = s => { let accu = ref(0) for i in 0 to String.length(s) - 1 { diff --git a/jscomp/test/ext_pervasives_test.resi b/jscomp/test/ext_pervasives_test.resi index 60ad175c9d..13a6533355 100644 --- a/jscomp/test/ext_pervasives_test.resi +++ b/jscomp/test/ext_pervasives_test.resi @@ -25,14 +25,10 @@ /*** Extension to standard library [Pervavives] module, safe to open */ -external reraise: exn => 'a = "%reraise" +external reraise: exn => 'a = "%raise" let finally: ('a, 'a => 'c, 'a => 'b) => 'b -let is_pos_pow: Int32.t => int - -let is_pos_pow_2: Int32.t => int - /** Copied from {!Btype.hash_variant}: need sync up and add test case */ diff --git a/jscomp/test/ext_string_test.js b/jscomp/test/ext_string_test.js deleted file mode 100644 index 75b2da3878..0000000000 --- a/jscomp/test/ext_string_test.js +++ /dev/null @@ -1,650 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let List = require("../../lib/js/list.js"); -let Bytes = require("../../lib/js/bytes.js"); -let $$String = require("../../lib/js/string.js"); -let Caml_bytes = require("../../lib/js/caml_bytes.js"); -let Caml_string = require("../../lib/js/caml_string.js"); -let Ext_bytes_test = require("./ext_bytes_test.js"); -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); - -function split_by(keep_emptyOpt, is_delim, str) { - let keep_empty = keep_emptyOpt !== undefined ? keep_emptyOpt : false; - let len = str.length; - let _acc = /* [] */0; - let _last_pos = len; - let _pos = len - 1 | 0; - while (true) { - let pos = _pos; - let last_pos = _last_pos; - let acc = _acc; - if (pos === -1) { - if (last_pos === 0 && !keep_empty) { - return acc; - } else { - return { - hd: $$String.sub(str, 0, last_pos), - tl: acc - }; - } - } - if (is_delim(Caml_string.get(str, pos))) { - let new_len = (last_pos - pos | 0) - 1 | 0; - if (new_len !== 0 || keep_empty) { - let v = $$String.sub(str, pos + 1 | 0, new_len); - _pos = pos - 1 | 0; - _last_pos = pos; - _acc = { - hd: v, - tl: acc - }; - continue; - } - _pos = pos - 1 | 0; - _last_pos = pos; - continue; - } - _pos = pos - 1 | 0; - continue; - }; -} - -function trim(s) { - let i = 0; - let j = s.length; - while ((() => { - let tmp = false; - if (i < j) { - let u = s.codePointAt(i); - tmp = u === /* '\t' */9 || u === /* '\n' */10 || u === /* ' ' */32; - } - return tmp; - })()) { - i = i + 1 | 0; - }; - let k = j - 1 | 0; - while ((() => { - let tmp = false; - if (k >= i) { - let u = s.codePointAt(k); - tmp = u === /* '\t' */9 || u === /* '\n' */10 || u === /* ' ' */32; - } - return tmp; - })()) { - k = k - 1 | 0; - }; - return $$String.sub(s, i, (k - i | 0) + 1 | 0); -} - -function split(keep_empty, str, on) { - if (str === "") { - return /* [] */0; - } else { - return split_by(keep_empty, x => x === on, str); - } -} - -function quick_split_by_ws(str) { - return split_by(false, x => { - if (x === /* '\t' */9 || x === /* '\n' */10) { - return true; - } else { - return x === /* ' ' */32; - } - }, str); -} - -function starts_with(s, beg) { - let beg_len = beg.length; - let s_len = s.length; - if (beg_len > s_len) { - return false; - } - let i = 0; - while (i < beg_len && s.codePointAt(i) === beg.codePointAt(i)) { - i = i + 1 | 0; - }; - return i === beg_len; -} - -function ends_with_index(s, end_) { - let s_finish = s.length - 1 | 0; - let s_beg = end_.length - 1 | 0; - if (s_beg > s_finish) { - return -1; - } - let _j = s_finish; - let _k = s_beg; - while (true) { - let k = _k; - let j = _j; - if (k < 0) { - return j + 1 | 0; - } - if (s.codePointAt(j) !== end_.codePointAt(k)) { - return -1; - } - _k = k - 1 | 0; - _j = j - 1 | 0; - continue; - }; -} - -function ends_with(s, end_) { - return ends_with_index(s, end_) >= 0; -} - -function ends_with_then_chop(s, beg) { - let i = ends_with_index(s, beg); - if (i >= 0) { - return $$String.sub(s, 0, i); - } - -} - -function check_any_suffix_case(s, suffixes) { - return List.exists(x => ends_with(s, x), suffixes); -} - -function check_any_suffix_case_then_chop(s, suffixes) { - let _suffixes = suffixes; - while (true) { - let suffixes$1 = _suffixes; - if (!suffixes$1) { - return; - } - let id = ends_with_index(s, suffixes$1.hd); - if (id >= 0) { - return $$String.sub(s, 0, id); - } - _suffixes = suffixes$1.tl; - continue; - }; -} - -function escaped(s) { - let needs_escape = _i => { - while (true) { - let i = _i; - if (i >= s.length) { - return false; - } - let match = s.codePointAt(i); - if (match < 32) { - return true; - } - if (match > 92 || match < 34) { - if (match >= 127) { - return true; - } - _i = i + 1 | 0; - continue; - } - if (match > 91 || match < 35) { - return true; - } - _i = i + 1 | 0; - continue; - }; - }; - if (needs_escape(0)) { - return Bytes.unsafe_to_string(Ext_bytes_test.escaped(Bytes.unsafe_of_string(s))); - } else { - return s; - } -} - -function unsafe_for_all_range(s, _start, finish, p) { - while (true) { - let start = _start; - if (start > finish) { - return true; - } - if (!p(s.codePointAt(start))) { - return false; - } - _start = start + 1 | 0; - continue; - }; -} - -function for_all_range(s, start, finish, p) { - let len = s.length; - if (start < 0 || finish >= len) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Ext_string_test.for_all_range", - Error: new Error() - }; - } - return unsafe_for_all_range(s, start, finish, p); -} - -function for_all(p, s) { - return unsafe_for_all_range(s, 0, s.length - 1 | 0, p); -} - -function is_empty(s) { - return s.length === 0; -} - -function repeat(n, s) { - let len = s.length; - let res = Caml_bytes.create(Math.imul(n, len)); - for (let i = 0; i < n; ++i) { - $$String.blit(s, 0, res, Math.imul(i, len), len); - } - return Bytes.to_string(res); -} - -function unsafe_is_sub(sub, i, s, j, len) { - if ((j + len | 0) <= s.length) { - let _k = 0; - while (true) { - let k = _k; - if (k === len) { - return true; - } - if (sub.codePointAt(i + k | 0) !== s.codePointAt(j + k | 0)) { - return false; - } - _k = k + 1 | 0; - continue; - }; - } else { - return false; - } -} - -let Local_exit = /* @__PURE__ */Caml_exceptions.create("Ext_string_test.Local_exit"); - -function find(startOpt, sub, s) { - let start = startOpt !== undefined ? startOpt : 0; - let n = sub.length; - let s_len = s.length; - let i = start; - try { - while ((i + n | 0) <= s_len) { - if (unsafe_is_sub(sub, 0, s, i, n)) { - throw { - RE_EXN_ID: Local_exit, - Error: new Error() - }; - } - i = i + 1 | 0; - }; - return -1; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === Local_exit) { - return i; - } - throw exn; - } -} - -function contain_substring(s, sub) { - return find(undefined, sub, s) >= 0; -} - -function non_overlap_count(sub, s) { - let sub_len = sub.length; - if (sub.length === 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Ext_string_test.non_overlap_count", - Error: new Error() - }; - } - let _acc = 0; - let _off = 0; - while (true) { - let off = _off; - let acc = _acc; - let i = find(off, sub, s); - if (i < 0) { - return acc; - } - _off = i + sub_len | 0; - _acc = acc + 1 | 0; - continue; - }; -} - -function rfind(sub, s) { - let n = sub.length; - let i = s.length - n | 0; - try { - while (i >= 0) { - if (unsafe_is_sub(sub, 0, s, i, n)) { - throw { - RE_EXN_ID: Local_exit, - Error: new Error() - }; - } - i = i - 1 | 0; - }; - return -1; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === Local_exit) { - return i; - } - throw exn; - } -} - -function tail_from(s, x) { - let len = s.length; - if (x <= len) { - return $$String.sub(s, x, len - x | 0); - } - let s$1 = "Ext_string_test.tail_from " + (s + (" : " + String(x))); - throw { - RE_EXN_ID: "Invalid_argument", - _1: s$1, - Error: new Error() - }; -} - -function digits_of_str(s, offset, x) { - let _i = 0; - let _acc = 0; - while (true) { - let acc = _acc; - let i = _i; - if (i >= x) { - return acc; - } - _acc = (Math.imul(10, acc) + Caml_string.get(s, offset + i | 0) | 0) - 48 | 0; - _i = i + 1 | 0; - continue; - }; -} - -function starts_with_and_number(s, offset, beg) { - let beg_len = beg.length; - let s_len = s.length; - let finish_delim = offset + beg_len | 0; - if (finish_delim > s_len) { - return -1; - } - let i = offset; - while (i < finish_delim && s.codePointAt(i) === beg.codePointAt(i - offset | 0)) { - i = i + 1 | 0; - }; - if (i === finish_delim) { - return digits_of_str(s, finish_delim, 2); - } else { - return -1; - } -} - -function equal(x, y) { - return x === y; -} - -function rindex_rec(s, _i, c) { - while (true) { - let i = _i; - if (i < 0) { - return i; - } - if (s.codePointAt(i) === c) { - return i; - } - _i = i - 1 | 0; - continue; - }; -} - -function rindex_rec_opt(s, _i, c) { - while (true) { - let i = _i; - if (i < 0) { - return; - } - if (s.codePointAt(i) === c) { - return i; - } - _i = i - 1 | 0; - continue; - }; -} - -function rindex_neg(s, c) { - return rindex_rec(s, s.length - 1 | 0, c); -} - -function rindex_opt(s, c) { - return rindex_rec_opt(s, s.length - 1 | 0, c); -} - -function is_valid_module_file(s) { - let len = s.length; - if (len <= 0) { - return false; - } - let match = s.codePointAt(0); - if (match >= 91) { - if (match > 122 || match < 97) { - return false; - } - - } else if (match < 65) { - return false; - } - return unsafe_for_all_range(s, 1, len - 1 | 0, x => { - if (x >= 65) { - if (x > 96 || x < 91) { - return x < 123; - } else { - return x === 95; - } - } else if (x >= 48) { - return x < 58; - } else { - return x === 39; - } - }); -} - -function is_valid_npm_package_name(s) { - let len = s.length; - if (len > 214) { - return false; - } - if (len <= 0) { - return false; - } - let match = s.codePointAt(0); - if (match >= 97) { - if (match >= 123) { - return false; - } - - } else if (match !== 64) { - return false; - } - return unsafe_for_all_range(s, 1, len - 1 | 0, x => { - if (x >= 58) { - if (x >= 97) { - return x < 123; - } else { - return x === 95; - } - } else if (x !== 45) { - return x >= 48; - } else { - return true; - } - }); -} - -function is_valid_source_name(name) { - let x = check_any_suffix_case_then_chop(name, { - hd: ".ml", - tl: { - hd: ".res", - tl: { - hd: ".mli", - tl: { - hd: ".resi", - tl: /* [] */0 - } - } - } - }); - if (x !== undefined) { - if (is_valid_module_file(x)) { - return "Good"; - } else { - return "Invalid_module_name"; - } - } else { - return "Suffix_mismatch"; - } -} - -function unsafe_no_char(x, ch, _i, last_idx) { - while (true) { - let i = _i; - if (i > last_idx) { - return true; - } - if (x.codePointAt(i) === ch) { - return false; - } - _i = i + 1 | 0; - continue; - }; -} - -function unsafe_no_char_idx(x, ch, _i, last_idx) { - while (true) { - let i = _i; - if (i > last_idx) { - return -1; - } - if (x.codePointAt(i) === ch) { - return i; - } - _i = i + 1 | 0; - continue; - }; -} - -function no_char(x, ch, i, len) { - let str_len = x.length; - if (i < 0 || i >= str_len || len >= str_len) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Ext_string_test.no_char", - Error: new Error() - }; - } - return unsafe_no_char(x, ch, i, len); -} - -function no_slash(x) { - return unsafe_no_char(x, /* '/' */47, 0, x.length - 1 | 0); -} - -function no_slash_idx(x) { - return unsafe_no_char_idx(x, /* '/' */47, 0, x.length - 1 | 0); -} - -function replace_slash_backward(x) { - let len = x.length; - if (unsafe_no_char(x, /* '/' */47, 0, len - 1 | 0)) { - return x; - } else { - return $$String.map(x => { - if (x !== 47) { - return x; - } else { - return /* '\\' */92; - } - }, x); - } -} - -function replace_backward_slash(x) { - let len = x.length; - if (unsafe_no_char(x, /* '\\' */92, 0, len - 1 | 0)) { - return x; - } else { - return $$String.map(x => { - if (x !== 92) { - return x; - } else { - return /* '/' */47; - } - }, x); - } -} - -let check_suffix_case = ends_with; - -let check_suffix_case_then_chop = ends_with_then_chop; - -let empty = ""; - -let single_space = " "; - -let single_colon = ":"; - -let parent_dir_lit = ".."; - -let current_dir_lit = "."; - -exports.split_by = split_by; -exports.trim = trim; -exports.split = split; -exports.quick_split_by_ws = quick_split_by_ws; -exports.starts_with = starts_with; -exports.ends_with_index = ends_with_index; -exports.ends_with = ends_with; -exports.ends_with_then_chop = ends_with_then_chop; -exports.check_suffix_case = check_suffix_case; -exports.check_suffix_case_then_chop = check_suffix_case_then_chop; -exports.check_any_suffix_case = check_any_suffix_case; -exports.check_any_suffix_case_then_chop = check_any_suffix_case_then_chop; -exports.escaped = escaped; -exports.unsafe_for_all_range = unsafe_for_all_range; -exports.for_all_range = for_all_range; -exports.for_all = for_all; -exports.is_empty = is_empty; -exports.repeat = repeat; -exports.unsafe_is_sub = unsafe_is_sub; -exports.Local_exit = Local_exit; -exports.find = find; -exports.contain_substring = contain_substring; -exports.non_overlap_count = non_overlap_count; -exports.rfind = rfind; -exports.tail_from = tail_from; -exports.digits_of_str = digits_of_str; -exports.starts_with_and_number = starts_with_and_number; -exports.equal = equal; -exports.rindex_rec = rindex_rec; -exports.rindex_rec_opt = rindex_rec_opt; -exports.rindex_neg = rindex_neg; -exports.rindex_opt = rindex_opt; -exports.is_valid_module_file = is_valid_module_file; -exports.is_valid_npm_package_name = is_valid_npm_package_name; -exports.is_valid_source_name = is_valid_source_name; -exports.unsafe_no_char = unsafe_no_char; -exports.unsafe_no_char_idx = unsafe_no_char_idx; -exports.no_char = no_char; -exports.no_slash = no_slash; -exports.no_slash_idx = no_slash_idx; -exports.replace_slash_backward = replace_slash_backward; -exports.replace_backward_slash = replace_backward_slash; -exports.empty = empty; -exports.single_space = single_space; -exports.single_colon = single_colon; -exports.parent_dir_lit = parent_dir_lit; -exports.current_dir_lit = current_dir_lit; -/* Ext_bytes_test Not a pure module */ diff --git a/jscomp/test/ext_string_test.res b/jscomp/test/ext_string_test.res deleted file mode 100644 index 89dc2b107e..0000000000 --- a/jscomp/test/ext_string_test.res +++ /dev/null @@ -1,581 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -/* - {[ split " test_unsafe_obj_ffi_ppx.cmi" ~keep_empty:false ' ']} -*/ -let split_by = (~keep_empty=false, is_delim, str) => { - let len = String.length(str) - let rec loop = (acc, last_pos, pos) => - if pos == -1 { - if last_pos == 0 && !keep_empty { - acc - } else { - list{String.sub(str, 0, last_pos), ...acc} - } - } else if is_delim(String.get(str, pos)) { - let new_len = last_pos - pos - 1 - if new_len != 0 || keep_empty { - let v = String.sub(str, pos + 1, new_len) - loop(list{v, ...acc}, pos, pos - 1) - } else { - loop(acc, pos, pos - 1) - } - } else { - loop(acc, last_pos, pos - 1) - } - - loop(list{}, len, len - 1) -} - -let trim = s => { - let i = ref(0) - let j = String.length(s) - while ( - i.contents < j && { - let u = String.unsafe_get(s, i.contents) - u == '\t' || (u == '\n' || u == ' ') - } - ) { - incr(i) - } - let k = ref(j - 1) - while ( - k.contents >= i.contents && { - let u = String.unsafe_get(s, k.contents) - u == '\t' || (u == '\n' || u == ' ') - } - ) { - decr(k) - } - String.sub(s, i.contents, k.contents - i.contents + 1) -} - -let split = (~keep_empty=?, str, on) => - if str == "" { - list{} - } else { - split_by(~keep_empty?, x => (x: char) == on, str) - } - -let quick_split_by_ws = (str): list => - split_by(~keep_empty=false, x => x == '\t' || (x == '\n' || x == ' '), str) - -let starts_with = (s, beg) => { - let beg_len = String.length(beg) - let s_len = String.length(s) - beg_len <= s_len && { - let i = ref(0) - while ( - i.contents < beg_len && - String.unsafe_get(s, i.contents) == String.unsafe_get(beg, i.contents) - ) { - incr(i) - } - i.contents == beg_len - } -} - -/** return an index which is minus when [s] does not - end with [beg] -*/ -let ends_with_index = (s, end_) => { - let s_finish = String.length(s) - 1 - let s_beg = String.length(end_) - 1 - if s_beg > s_finish { - -1 - } else { - let rec aux = (j, k) => - if k < 0 { - j + 1 - } else if String.unsafe_get(s, j) == String.unsafe_get(end_, k) { - aux(j - 1, k - 1) - } else { - -1 - } - aux(s_finish, s_beg) - } -} - -let ends_with = (s, end_) => ends_with_index(s, end_) >= 0 - -let ends_with_then_chop = (s, beg) => { - let i = ends_with_index(s, beg) - if i >= 0 { - Some(String.sub(s, 0, i)) - } else { - None - } -} - -let check_suffix_case = ends_with -let check_suffix_case_then_chop = ends_with_then_chop - -let check_any_suffix_case = (s, suffixes) => List.exists(x => check_suffix_case(s, x), suffixes) - -let check_any_suffix_case_then_chop = (s, suffixes) => { - let rec aux = suffixes => - switch suffixes { - | list{} => None - | list{x, ...xs} => - let id = ends_with_index(s, x) - if id >= 0 { - Some(String.sub(s, 0, id)) - } else { - aux(xs) - } - } - aux(suffixes) -} - -/** In OCaml 4.02.3, {!String.escaped} is locale senstive, - this version try to make it not locale senstive, this bug is fixed - in the compiler trunk -*/ -let escaped = s => { - let rec needs_escape = i => - if i >= String.length(s) { - false - } else { - switch String.unsafe_get(s, i) { - | '"' | '\\' | '\n' | '\t' | '\r' | '\b' => true - | ' ' .. '~' => needs_escape(i + 1) - | _ => true - } - } - - if needs_escape(0) { - Bytes.unsafe_to_string(Ext_bytes_test.escaped(Bytes.unsafe_of_string(s))) - } else { - s - } -} - -/* it is unsafe to expose such API as unsafe since - user can provide bad input range - -*/ -let rec unsafe_for_all_range = (s, ~start, ~finish, p) => - start > finish || - (p(String.unsafe_get(s, start)) && unsafe_for_all_range(s, ~start=start + 1, ~finish, p)) - -let for_all_range = (s, ~start, ~finish, p) => { - let len = String.length(s) - if start < 0 || finish >= len { - invalid_arg("Ext_string_test.for_all_range") - } else { - unsafe_for_all_range(s, ~start, ~finish, p) - } -} - -let for_all = (p: char => bool, s) => - unsafe_for_all_range(s, ~start=0, ~finish=String.length(s) - 1, p) - -let is_empty = s => String.length(s) == 0 - -let repeat = (n, s) => { - let len = String.length(s) - let res = Bytes.create(n * len) - for i in 0 to pred(n) { - String.blit(s, 0, res, i * len, len) - } - Bytes.to_string(res) -} - -let equal = (x: string, y) => x == y - -let unsafe_is_sub = (~sub, i, s, j, ~len) => { - let rec check = k => - if k == len { - true - } else { - String.unsafe_get(sub, i + k) == String.unsafe_get(s, j + k) && check(k + 1) - } - - j + len <= String.length(s) && check(0) -} - -exception Local_exit -let find = (~start=0, ~sub, s) => { - let n = String.length(sub) - let s_len = String.length(s) - let i = ref(start) - try { - while i.contents + n <= s_len { - if unsafe_is_sub(~sub, 0, s, i.contents, ~len=n) { - raise_notrace(Local_exit) - } - incr(i) - } - -1 - } catch { - | Local_exit => i.contents - } -} - -let contain_substring = (s, sub) => find(s, ~sub) >= 0 - -/** TODO: optimize - avoid nonterminating when string is empty -*/ -let non_overlap_count = (~sub, s) => { - let sub_len = String.length(sub) - let rec aux = (acc, off) => { - let i = find(~start=off, ~sub, s) - if i < 0 { - acc - } else { - aux(acc + 1, i + sub_len) - } - } - if String.length(sub) == 0 { - invalid_arg("Ext_string_test.non_overlap_count") - } else { - aux(0, 0) - } -} - -let rfind = (~sub, s) => { - let n = String.length(sub) - let i = ref(String.length(s) - n) - module M = { - exception Exit - } - try { - while i.contents >= 0 { - if unsafe_is_sub(~sub, 0, s, i.contents, ~len=n) { - raise_notrace(Local_exit) - } - decr(i) - } - -1 - } catch { - | Local_exit => i.contents - } -} - -let tail_from = (s, x) => { - let len = String.length(s) - if x > len { - invalid_arg("Ext_string_test.tail_from " ++ (s ++ (" : " ++ string_of_int(x)))) - } else { - String.sub(s, x, len - x) - } -} - -/** - {[ - digits_of_str \"11_js\" 2 == 11 - ]} -*/ -let digits_of_str = (s, ~offset, x) => { - let rec aux = (i, acc, s, x) => - if i >= x { - acc - } else { - aux(i + 1, 10 * acc + Char.code(String.get(s, offset + i)) - 48 /* Char.code '0' */, s, x) - } - aux(0, 0, s, x) -} - -/* - {[ - starts_with_and_number "js_fn_mk_01" 0 "js_fn_mk_" = 1 ;; - starts_with_and_number "js_fn_run_02" 0 "js_fn_mk_" = -1 ;; - starts_with_and_number "js_fn_mk_03" 6 "mk_" = 3 ;; - starts_with_and_number "js_fn_mk_04" 6 "run_" = -1;; - starts_with_and_number "js_fn_run_04" 6 "run_" = 4;; - (starts_with_and_number "js_fn_run_04" 6 "run_" = 3) = false ;; - ]} -*/ -let starts_with_and_number = (s, ~offset, beg) => { - let beg_len = String.length(beg) - let s_len = String.length(s) - let finish_delim = offset + beg_len - - if finish_delim > s_len { - -1 - } else { - let i = ref(offset) - while ( - i.contents < finish_delim && - String.unsafe_get(s, i.contents) == String.unsafe_get(beg, i.contents - offset) - ) { - incr(i) - } - if i.contents == finish_delim { - digits_of_str(~offset=finish_delim, s, 2) - } else { - -1 - } - } -} - -let equal = (x: string, y) => x == y - -/* let unsafe_concat_with_length len sep l = - match l with - | [] -> "" - | hd :: tl -> (* num is positive *) - let r = Bytes.create len in - let hd_len = String.length hd in - let sep_len = String.length sep in - String.unsafe_blit hd 0 r 0 hd_len; - let pos = ref hd_len in - List.iter - (fun s -> - let s_len = String.length s in - String.unsafe_blit sep 0 r !pos sep_len; - pos := !pos + sep_len; - String.unsafe_blit s 0 r !pos s_len; - pos := !pos + s_len) - tl; - Bytes.unsafe_to_string r */ - -let rec rindex_rec = (s, i, c) => - if i < 0 { - i - } else if String.unsafe_get(s, i) == c { - i - } else { - rindex_rec(s, i - 1, c) - } - -let rec rindex_rec_opt = (s, i, c) => - if i < 0 { - None - } else if String.unsafe_get(s, i) == c { - Some(i) - } else { - rindex_rec_opt(s, i - 1, c) - } - -let rindex_neg = (s, c) => rindex_rec(s, String.length(s) - 1, c) - -let rindex_opt = (s, c) => rindex_rec_opt(s, String.length(s) - 1, c) - -let is_valid_module_file = (s: string) => { - let len = String.length(s) - len > 0 && - switch String.unsafe_get(s, 0) { - | 'A' .. 'Z' - | 'a' .. 'z' => - unsafe_for_all_range(s, ~start=1, ~finish=len - 1, x => - switch x { - | 'A' .. 'Z' | 'a' .. 'z' | '0' .. '9' | '_' | '\'' => true - | _ => false - } - ) - | _ => false - } -} - -/* https://docs.npmjs.com/files/package.json - Some rules: - The name must be less than or equal to 214 characters. This includes the scope for scoped packages. - The name can't start with a dot or an underscore. - New packages must not have uppercase letters in the name. - The name ends up being part of a URL, an argument on the command line, and a folder name. Therefore, the name can't contain any non-URL-safe characters. -*/ -let is_valid_npm_package_name = (s: string) => { - let len = String.length(s) - len <= 214 && - /* magic number forced by npm */ - (len > 0 && - switch String.unsafe_get(s, 0) { - | 'a' .. 'z' | '@' => - unsafe_for_all_range(s, ~start=1, ~finish=len - 1, x => - switch x { - | 'a' .. 'z' | '0' .. '9' | '_' | '-' => true - | _ => false - } - ) - | _ => false - }) -} - -type check_result = - | Good - | Invalid_module_name - | /** - TODO: move to another module - Make {!Ext_filename_test} not stateful -*/ - Suffix_mismatch - -let is_valid_source_name = (name): check_result => - switch check_any_suffix_case_then_chop(name, list{".ml", ".res", ".mli", ".resi"}) { - | None => Suffix_mismatch - | Some(x) => - if is_valid_module_file(x) { - Good - } else { - Invalid_module_name - } - } - -/** TODO: can be improved to return a positive integer instead */ -let rec unsafe_no_char = (x, ch, i, last_idx) => - i > last_idx || (String.unsafe_get(x, i) != ch && unsafe_no_char(x, ch, i + 1, last_idx)) - -let rec unsafe_no_char_idx = (x, ch, i, last_idx) => - if i > last_idx { - -1 - } else if String.unsafe_get(x, i) != ch { - unsafe_no_char_idx(x, ch, i + 1, last_idx) - } else { - i - } - -let no_char = (x, ch, i, len): bool => { - let str_len = String.length(x) - if i < 0 || (i >= str_len || len >= str_len) { - invalid_arg("Ext_string_test.no_char") - } else { - unsafe_no_char(x, ch, i, len) - } -} - -let no_slash = x => unsafe_no_char(x, '/', 0, String.length(x) - 1) - -let no_slash_idx = x => unsafe_no_char_idx(x, '/', 0, String.length(x) - 1) - -let replace_slash_backward = (x: string) => { - let len = String.length(x) - if unsafe_no_char(x, '/', 0, len - 1) { - x - } else { - String.map(x => - switch x { - | '/' => '\\' - | x => x - } - , x) - } -} - -let replace_backward_slash = (x: string) => { - let len = String.length(x) - if unsafe_no_char(x, '\\', 0, len - 1) { - x - } else { - String.map(x => - switch x { - | '\\' => '/' - | x => x - } - , x) - } -} - -let empty = "" - -external compare: (string, string) => int = "?string_length_based_compare" - -let single_space = " " -let single_colon = ":" - -/* let concat_array sep (s : string array) = - let s_len = Array.length s in - match s_len with - | 0 -> empty - | 1 -> Array.unsafe_get s 0 - | _ -> - let sep_len = String.length sep in - let len = ref 0 in - for i = 0 to s_len - 1 do - len := !len + String.length (Array.unsafe_get s i) - done; - let target = - Bytes.create - (!len + (s_len - 1) * sep_len ) in - let hd = (Array.unsafe_get s 0) in - let hd_len = String.length hd in - String.unsafe_blit hd 0 target 0 hd_len; - let current_offset = ref hd_len in - for i = 1 to s_len - 1 do - String.unsafe_blit sep 0 target !current_offset sep_len; - let cur = Array.unsafe_get s i in - let cur_len = String.length cur in - let new_off_set = (!current_offset + sep_len ) in - String.unsafe_blit cur 0 target new_off_set cur_len; - current_offset := - new_off_set + cur_len ; - done; - Bytes.unsafe_to_string target */ - -/* let concat3 a b c = - let a_len = String.length a in - let b_len = String.length b in - let c_len = String.length c in - let len = a_len + b_len + c_len in - let target = Bytes.create len in - String.unsafe_blit a 0 target 0 a_len ; - String.unsafe_blit b 0 target a_len b_len; - String.unsafe_blit c 0 target (a_len + b_len) c_len; - Bytes.unsafe_to_string target */ - -/* let concat4 a b c d = - let a_len = String.length a in - let b_len = String.length b in - let c_len = String.length c in - let d_len = String.length d in - let len = a_len + b_len + c_len + d_len in - - let target = Bytes.create len in - String.unsafe_blit a 0 target 0 a_len ; - String.unsafe_blit b 0 target a_len b_len; - String.unsafe_blit c 0 target (a_len + b_len) c_len; - String.unsafe_blit d 0 target (a_len + b_len + c_len) d_len; - Bytes.unsafe_to_string target - */ -/* -let concat5 a b c d e = - let a_len = String.length a in - let b_len = String.length b in - let c_len = String.length c in - let d_len = String.length d in - let e_len = String.length e in - let len = a_len + b_len + c_len + d_len + e_len in - - let target = Bytes.create len in - String.unsafe_blit a 0 target 0 a_len ; - String.unsafe_blit b 0 target a_len b_len; - String.unsafe_blit c 0 target (a_len + b_len) c_len; - String.unsafe_blit d 0 target (a_len + b_len + c_len) d_len; - String.unsafe_blit e 0 target (a_len + b_len + c_len + d_len) e_len; - Bytes.unsafe_to_string target - */ - -/* let inter2 a b = - concat3 a single_space b */ - -/* let inter3 a b c = - concat5 a single_space b single_space c */ - -/* let inter4 a b c d = - concat_array single_space [| a; b ; c; d|] */ - -let parent_dir_lit = ".." -let current_dir_lit = "." diff --git a/jscomp/test/ext_sys_test.js b/jscomp/test/ext_sys_test.js deleted file mode 100644 index c002fe1c74..0000000000 --- a/jscomp/test/ext_sys_test.js +++ /dev/null @@ -1,9 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Sys = require("../../lib/js/sys.js"); - -let is_windows_or_cygwin = Sys.win32 || false; - -exports.is_windows_or_cygwin = is_windows_or_cygwin; -/* No side effect */ diff --git a/jscomp/test/ext_sys_test.res b/jscomp/test/ext_sys_test.res deleted file mode 100644 index d224881d0c..0000000000 --- a/jscomp/test/ext_sys_test.res +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -/** TODO: not exported yet, wait for Windows Fix */ -let is_directory_no_exn = f => - try Sys.is_directory(f) catch { - | _ => false - } - -let is_windows_or_cygwin = Sys.win32 || Sys.cygwin diff --git a/jscomp/test/ext_sys_test.resi b/jscomp/test/ext_sys_test.resi deleted file mode 100644 index 4cd88d51c0..0000000000 --- a/jscomp/test/ext_sys_test.resi +++ /dev/null @@ -1,28 +0,0 @@ -/* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - -/* Not used yet */ -/* val is_directory_no_exn : string -> bool */ - -let is_windows_or_cygwin: bool diff --git a/jscomp/test/extensible_variant_test.js b/jscomp/test/extensible_variant_test.js index c80e4eac79..42f4e0a101 100644 --- a/jscomp/test/extensible_variant_test.js +++ b/jscomp/test/extensible_variant_test.js @@ -2,17 +2,17 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); -let Str = /* @__PURE__ */Caml_exceptions.create("Extensible_variant_test.Str"); +let Str = /* @__PURE__ */Primitive_exceptions.create("Extensible_variant_test.Str"); -let Int = /* @__PURE__ */Caml_exceptions.create("Extensible_variant_test.N.Int"); +let Int = /* @__PURE__ */Primitive_exceptions.create("Extensible_variant_test.N.Int"); let N = { Int: Int }; -let Int$1 = /* @__PURE__ */Caml_exceptions.create("Extensible_variant_test.Int"); +let Int$1 = /* @__PURE__ */Primitive_exceptions.create("Extensible_variant_test.Int"); function to_int(x) { if (x.RE_EXN_ID === Str) { diff --git a/jscomp/test/ffi_array_test.js b/jscomp/test/ffi_array_test.js index ea510b33cf..1249fd62cd 100644 --- a/jscomp/test/ffi_array_test.js +++ b/jscomp/test/ffi_array_test.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -26,7 +26,7 @@ function eq(loc, x, y) { }; } -eq("File \"ffi_array_test.res\", line 11, characters 12-19", [ +eq("File \"ffi_array_test.res\", line 14, characters 12-19", [ 1, 2, 3, diff --git a/jscomp/test/ffi_array_test.res b/jscomp/test/ffi_array_test.res index 6ad8c568c3..4431a9f824 100644 --- a/jscomp/test/ffi_array_test.res +++ b/jscomp/test/ffi_array_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } @send external map: (Js_array2.t<'a>, 'a => 'b) => Js_array2.t<'b> = "map" diff --git a/jscomp/test/ffi_js_test.js b/jscomp/test/ffi_js_test.js index 6fd4eb6399..bc0b64e95d 100644 --- a/jscomp/test/ffi_js_test.js +++ b/jscomp/test/ffi_js_test.js @@ -26,7 +26,7 @@ function eq(loc, param) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -47,7 +47,7 @@ let string_config = { low: "32" }; -eq("File \"ffi_js_test.res\", line 30, characters 12-19", [ +eq("File \"ffi_js_test.res\", line 33, characters 12-19", [ 6, $$higher_order(1)(2, 3) ]); @@ -79,12 +79,12 @@ let same_type = [ same_type_1 ]; -eq("File \"ffi_js_test.res\", line 38, characters 5-12", [ +eq("File \"ffi_js_test.res\", line 41, characters 5-12", [ Object.keys(int_config).length, 2 ]); -eq("File \"ffi_js_test.res\", line 39, characters 5-12", [ +eq("File \"ffi_js_test.res\", line 42, characters 5-12", [ Object.keys(string_config).length, 2 ]); @@ -98,7 +98,7 @@ let side_effect_config = (u.contents = u.contents + 1 | 0, "Int", { low: 32 }); -eq("File \"ffi_js_test.res\", line 53, characters 12-19", [ +eq("File \"ffi_js_test.res\", line 56, characters 12-19", [ u.contents, 4 ]); diff --git a/jscomp/test/ffi_js_test.res b/jscomp/test/ffi_js_test.res index ec405c71d1..c47353cdb8 100644 --- a/jscomp/test/ffi_js_test.res +++ b/jscomp/test/ffi_js_test.res @@ -14,7 +14,10 @@ let test_id = ref(0) let eq = (loc, (x, y)) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } type rec kind<_> = @@ -35,8 +38,8 @@ let same_type = ( ) let () = { - eq(__LOC__, (Array.length(Js_obj.keys(int_config)), 2)) - eq(__LOC__, (Array.length(Js_obj.keys(string_config)), 2)) + eq(__LOC__, (Belt.Array.length(Js_obj.keys(int_config)), 2)) + eq(__LOC__, (Belt.Array.length(Js_obj.keys(string_config)), 2)) } let u = ref(3) diff --git a/jscomp/test/ffi_splice_test.js b/jscomp/test/ffi_splice_test.js index 1885b6ec2e..f43416a0bb 100644 --- a/jscomp/test/ffi_splice_test.js +++ b/jscomp/test/ffi_splice_test.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -54,7 +54,7 @@ let v = new Make(1, 2, 3, 4); let u = v.sum(); -eq("File \"ffi_splice_test.res\", line 55, characters 12-19", u, 10); +eq("File \"ffi_splice_test.res\", line 58, characters 12-19", u, 10); Mt.from_pair_suites("Ffi_splice_test", suites.contents); diff --git a/jscomp/test/ffi_splice_test.res b/jscomp/test/ffi_splice_test.res index a0f60c031b..bf820c3b8e 100644 --- a/jscomp/test/ffi_splice_test.res +++ b/jscomp/test/ffi_splice_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } /* diff --git a/jscomp/test/ffi_test.res b/jscomp/test/ffi_test.res index 1bc6084b96..fc3ef608d0 100644 --- a/jscomp/test/ffi_test.res +++ b/jscomp/test/ffi_test.res @@ -37,6 +37,6 @@ let f = () => { module Array = Int32Array let v = Array.create(32) - v[0] = 3 - v[0] + Int32Array.set(v, 0, 3) + Int32Array.get(v, 0) } diff --git a/jscomp/test/flexible_array_test.js b/jscomp/test/flexible_array_test.js index 0a99587305..77a5eb86e2 100644 --- a/jscomp/test/flexible_array_test.js +++ b/jscomp/test/flexible_array_test.js @@ -1,9 +1,9 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let $$Array = require("../../lib/js/array.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); -let Caml_array = require("../../lib/js/caml_array.js"); +let Belt_Array = require("../../lib/js/belt_Array.js"); +let Primitive_array = require("../../lib/js/primitive_array.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); function sub(_tr, _k) { while (true) { @@ -260,20 +260,20 @@ function sort(s) { return s; } let head = get(s, 0); - let larger = sort(filter_from(1, x => Caml_obj.greaterthan(x, head), s)); - let smaller = sort(filter_from(1, x => Caml_obj.lessequal(x, head), s)); + let larger = sort(filter_from(1, x => Primitive_object.greaterthan(x, head), s)); + let smaller = sort(filter_from(1, x => Primitive_object.lessequal(x, head), s)); return append(smaller, push_front(larger, head)); } function of_array(arr) { let v = empty; for (let i = 0, i_finish = arr.length; i < i_finish; ++i) { - v = push_back(v, Caml_array.get(arr, i)); + v = push_back(v, Primitive_array.get(arr, i)); } return v; } -let equal = Caml_obj.equal; +let equal = Primitive_object.equal; let Int_array = { empty: empty, @@ -290,7 +290,7 @@ let Int_array = { }; function $eq$tilde(x, y) { - return Caml_obj.equal(x, of_array(y)); + return Primitive_object.equal(x, of_array(y)); } let u = of_array([ @@ -321,9 +321,9 @@ if (!$eq$tilde(sort(u), [ }; } -let v = $$Array.init(500, i => 500 - i | 0); +let v = Belt_Array.init(500, i => 500 - i | 0); -$eq$tilde(sort(of_array(v)), $$Array.init(500, i => i + 1 | 0)); +$eq$tilde(sort(of_array(v)), Belt_Array.init(500, i => i + 1 | 0)); exports.sub = sub; exports.update = update; diff --git a/jscomp/test/flexible_array_test.res b/jscomp/test/flexible_array_test.res index 4ffee6666a..5508abf8bd 100644 --- a/jscomp/test/flexible_array_test.res +++ b/jscomp/test/flexible_array_test.res @@ -168,7 +168,7 @@ module Int_array: { } let of_array = arr => { let v = ref(empty) - for i in 0 to Array.length(arr) - 1 { + for i in 0 to Belt.Array.length(arr) - 1 { v := push_back(v.contents, arr[i]) } v.contents @@ -183,6 +183,6 @@ let _ = { let u = Int_array.of_array([1, 2, 2, 5, 3, 6]) assert(\"=~"(Int_array.sort(u), [1, 2, 2, 3, 5, 6])) let len = 500 - let v = Array.init(len, i => len - i) - \"=~"(Int_array.sort(Int_array.of_array(v)), Array.init(len, i => i + 1)) + let v = Belt.Array.init(len, i => len - i) + \"=~"(Int_array.sort(Int_array.of_array(v)), Belt.Array.init(len, i => i + 1)) } diff --git a/jscomp/test/float_of_bits_test.js b/jscomp/test/float_of_bits_test.js deleted file mode 100644 index d4f450973a..0000000000 --- a/jscomp/test/float_of_bits_test.js +++ /dev/null @@ -1,83 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); -let $$Array = require("../../lib/js/array.js"); -let Caml_float = require("../../lib/js/caml_float.js"); -let Caml_int64 = require("../../lib/js/caml_int64.js"); -let Pervasives = require("../../lib/js/pervasives.js"); - -let one_float = [ - 1072693248, - 0 -]; - -let int32_pairs = [ - [ - 32, - 4.48415508583941463e-44 - ], - [ - 3, - 4.20389539297445121e-45 - ] -]; - -function from_pairs(pair) { - return List.concat($$Array.to_list($$Array.mapi((i, param) => { - let f = param[1]; - let i32 = param[0]; - return { - hd: [ - "int32_float_of_bits " + i, - param => ({ - TAG: "Eq", - _0: Caml_float.int_float_of_bits(i32), - _1: f - }) - ], - tl: { - hd: [ - "int32_bits_of_float " + i, - param => ({ - TAG: "Eq", - _0: Caml_float.int_bits_of_float(f), - _1: i32 - }) - ], - tl: /* [] */0 - } - }; - }, int32_pairs))); -} - -let suites = Pervasives.$at({ - hd: [ - "one", - () => ({ - TAG: "Eq", - _0: Caml_int64.bits_of_float(1.0), - _1: one_float - }) - ], - tl: { - hd: [ - "two", - () => ({ - TAG: "Eq", - _0: Caml_int64.float_of_bits(one_float), - _1: 1.0 - }) - ], - tl: /* [] */0 - } -}, from_pairs(int32_pairs)); - -Mt.from_pair_suites("Float_of_bits_test", suites); - -exports.one_float = one_float; -exports.int32_pairs = int32_pairs; -exports.from_pairs = from_pairs; -exports.suites = suites; -/* suites Not a pure module */ diff --git a/jscomp/test/float_of_bits_test.res b/jscomp/test/float_of_bits_test.res deleted file mode 100644 index fa4bf47f62..0000000000 --- a/jscomp/test/float_of_bits_test.res +++ /dev/null @@ -1,29 +0,0 @@ -/* Int64.bits_of_float 1.0 */ -let one_float = 4607182418800017408L - -let int32_pairs = [(32l, 4.48415508583941463e-44), (3l, 4.20389539297445121e-45)] - -let from_pairs = pair => - List.concat( - Array.to_list( - Array.mapi( - (i, (i32, f)) => list{ - ("int32_float_of_bits " ++ __unsafe_cast(i), _ => Mt.Eq(Int32.float_of_bits(i32), f)), - ("int32_bits_of_float " ++ __unsafe_cast(i), _ => Mt.Eq(Int32.bits_of_float(f), i32)), - }, - int32_pairs, - ), - ), - ) -let suites = \"@"( - { - open Mt - list{ - ("one", _ => Eq(Int64.bits_of_float(1.0), one_float)), - ("two", _ => Eq(Int64.float_of_bits(one_float), 1.0)), - } - }, - from_pairs(int32_pairs), -) - -Mt.from_pair_suites(__MODULE__, suites) diff --git a/jscomp/test/float_test.js b/jscomp/test/float_test.js index 5242aa892f..b4a0a5c128 100644 --- a/jscomp/test/float_test.js +++ b/jscomp/test/float_test.js @@ -1,14 +1,12 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Mt = require("./mt.js"); -let Caml = require("../../lib/js/caml.js"); -let $$Array = require("../../lib/js/array.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let Mt_global = require("./mt_global.js"); -let Caml_float = require("../../lib/js/caml_float.js"); -let Caml_int64 = require("../../lib/js/caml_int64.js"); +let Belt_Array = require("../../lib/js/belt_Array.js"); let Pervasives = require("../../lib/js/pervasives.js"); +let Primitive_float = require("../../lib/js/primitive_float.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); let test_id = { contents: 0 @@ -26,99 +24,8 @@ function approx(loc, x, y) { Mt_global.collect_approx(test_id, suites, loc, x, y); } -let epsilon_float = Caml_int64.float_of_bits([ - 1018167296, - 0 -]); - -let match = Caml_float.frexp_float(12.0); - -let match$1 = Caml_float.frexp_float(0); - -let match$2 = Caml_float.frexp_float(-12.0); - -let results = $$Array.append([ - [ - Math.log10(2), - 0.301029995663981198 - ], - [ - Caml_float.ldexp_float(1, 6), - 64 - ], - [ - Caml_float.ldexp_float(1, 5), - 32 - ], - [ - Caml_float.ldexp_float(1.e-5, 1024), - 1.79769313486231605e+303 - ], - [ - Caml_float.ldexp_float(1, -1024), - 5.56268464626800346e-309 - ], - [ - Caml_float.hypot_float(3, 4), - 5 - ], - [ - Caml_float.hypot_float(4, 3), - 5 - ], - [ - Caml_float.hypot_float(5, 12), - 13 - ], - [ - Caml_float.hypot_float(12, 5), - 13 - ], - [ - Caml_float.copysign_float(22.3, -1), - -22.3 - ], - [ - Caml_float.copysign_float(22.3, 1), - 22.3 - ], - [ - Caml_float.expm1_float(1e-15), - 1.00000000000000067e-15 - ], - [ - Math.log1p(1e-10), - 9.9999999995000007e-11 - ] -], [ - [ - match$1[0], - 0 - ], - [ - match$1[1], - 0 - ], - [ - match[0], - 0.75 - ], - [ - match[1], - 4 - ], - [ - match$2[0], - -0.75 - ], - [ - match$2[1], - 4 - ] -]); - function from_pairs(ps) { - return $$Array.to_list($$Array.mapi((i, param) => { + return Belt_List.fromArray(Belt_Array.mapWithIndex(ps, (i, param) => { let b = param[1]; let a = param[0]; return [ @@ -129,75 +36,56 @@ function from_pairs(ps) { _1: b }) ]; - }, ps)); + })); } -let float_compare = Caml.float_compare; +let float_compare = Primitive_float.compare; -let generic_compare = Caml_obj.compare; +let generic_compare = Primitive_object.compare; function float_equal(x, y) { return x === y; } -let generic_equal = Caml_obj.equal; +let generic_equal = Primitive_object.equal; function float_notequal(x, y) { return x !== y; } -let generic_notequal = Caml_obj.notequal; +let generic_notequal = Primitive_object.notequal; function float_lessthan(x, y) { return x < y; } -let generic_lessthan = Caml_obj.lessthan; +let generic_lessthan = Primitive_object.lessthan; function float_greaterthan(x, y) { return x > y; } -let generic_greaterthan = Caml_obj.greaterthan; +let generic_greaterthan = Primitive_object.greaterthan; function float_lessequal(x, y) { return x <= y; } -let generic_lessequal = Caml_obj.lessequal; +let generic_lessequal = Primitive_object.lessequal; function float_greaterequal(x, y) { return x >= y; } -let generic_greaterequal = Caml_obj.greaterequal; - -eq("File \"float_test.res\", line 57, characters 5-12", Pervasives.classify_float(3), "FP_normal"); - -eq("File \"float_test.res\", line 58, characters 5-12", Caml_float.modf_float(-3.125), [ - -0.125, - -3 -]); +let generic_greaterequal = Primitive_object.greaterequal; -let match$3 = Caml_float.modf_float(Number.NaN); +eq("File \"float_test.res\", line 28, characters 5-12", Pervasives.classify_float(3), "FP_normal"); -eq("File \"float_test.res\", line 60, characters 4-11", [ - Number.isNaN(match$3[0]), - Number.isNaN(match$3[1]) -], [ - true, - true -]); - -eq("File \"float_test.res\", line 68, characters 5-12", $$Array.map(x => { - if (x > 0) { - return 1; - } else if (x < 0) { - return -1; - } else { - return 0; - } -}, $$Array.map(param => Caml.float_compare(param[0], param[1]), [ +eq("File \"float_test.res\", line 30, characters 4-11", [ + -1, + 1, + 1 +], Belt_Array.map(Belt_Array.map([ [ 1, 3 @@ -210,162 +98,108 @@ eq("File \"float_test.res\", line 68, characters 5-12", $$Array.map(x => { 3, 2 ] -])), [ - -1, - 1, - 1 -]); - -eq("File \"float_test.res\", line 77, characters 5-12", Caml_float.copysign_float(-3, 0), 3); - -eq("File \"float_test.res\", line 78, characters 5-12", Caml_float.copysign_float(3, 0), 3); - -eq("File \"float_test.res\", line 79, characters 5-12", Math.log10(10), 1); - -eq("File \"float_test.res\", line 80, characters 5-12", Caml_float.expm1_float(0), 0); - -eq("File \"float_test.res\", line 81, characters 5-12", Number("3.0"), 3.0); - -approx("File \"float_test.res\", line 82, characters 9-16", Caml_float.expm1_float(2), 6.38905609893065); - -eq("File \"float_test.res\", line 83, characters 5-12", Caml.float_compare(NaN, NaN), 0); - -eq("File \"float_test.res\", line 84, characters 5-12", Caml_obj.compare(NaN, NaN), 0); +], param => Primitive_float.compare(param[0], param[1])), x => { + if (x > 0) { + return 1; + } else if (x < 0) { + return -1; + } else { + return 0; + } +})); -eq("File \"float_test.res\", line 85, characters 5-12", Caml.float_compare(NaN, Pervasives.neg_infinity), -1); +eq("File \"float_test.res\", line 44, characters 5-12", Math.log10(10), 1); -eq("File \"float_test.res\", line 86, characters 5-12", Caml_obj.compare(NaN, Pervasives.neg_infinity), -1); +eq("File \"float_test.res\", line 45, characters 5-12", Number("3.0"), 3.0); -eq("File \"float_test.res\", line 87, characters 5-12", Caml.float_compare(Pervasives.neg_infinity, NaN), 1); +eq("File \"float_test.res\", line 46, characters 5-12", Primitive_float.compare(NaN, NaN), 0); -eq("File \"float_test.res\", line 88, characters 5-12", Caml_obj.compare(Pervasives.neg_infinity, NaN), 1); +eq("File \"float_test.res\", line 47, characters 5-12", Primitive_object.compare(NaN, NaN), 0); -eq("File \"float_test.res\", line 89, characters 5-12", NaN === NaN, false); +eq("File \"float_test.res\", line 48, characters 5-12", Primitive_float.compare(NaN, Pervasives.neg_infinity), -1); -eq("File \"float_test.res\", line 90, characters 5-12", Caml_obj.equal(NaN, NaN), false); +eq("File \"float_test.res\", line 49, characters 5-12", Primitive_object.compare(NaN, Pervasives.neg_infinity), -1); -eq("File \"float_test.res\", line 91, characters 5-12", 4.2 === NaN, false); +eq("File \"float_test.res\", line 50, characters 5-12", Primitive_float.compare(Pervasives.neg_infinity, NaN), 1); -eq("File \"float_test.res\", line 92, characters 5-12", Caml_obj.equal(4.2, NaN), false); +eq("File \"float_test.res\", line 51, characters 5-12", Primitive_object.compare(Pervasives.neg_infinity, NaN), 1); -eq("File \"float_test.res\", line 93, characters 5-12", NaN === 4.2, false); +eq("File \"float_test.res\", line 52, characters 5-12", NaN === NaN, false); -eq("File \"float_test.res\", line 94, characters 5-12", Caml_obj.equal(NaN, 4.2), false); +eq("File \"float_test.res\", line 53, characters 5-12", Primitive_object.equal(NaN, NaN), false); -eq("File \"float_test.res\", line 95, characters 5-12", NaN !== NaN, true); +eq("File \"float_test.res\", line 54, characters 5-12", 4.2 === NaN, false); -eq("File \"float_test.res\", line 96, characters 5-12", Caml_obj.notequal(NaN, NaN), true); +eq("File \"float_test.res\", line 55, characters 5-12", Primitive_object.equal(4.2, NaN), false); -eq("File \"float_test.res\", line 97, characters 5-12", 4.2 !== NaN, true); +eq("File \"float_test.res\", line 56, characters 5-12", NaN === 4.2, false); -eq("File \"float_test.res\", line 98, characters 5-12", Caml_obj.notequal(4.2, NaN), true); +eq("File \"float_test.res\", line 57, characters 5-12", Primitive_object.equal(NaN, 4.2), false); -eq("File \"float_test.res\", line 99, characters 5-12", NaN !== 4.2, true); +eq("File \"float_test.res\", line 58, characters 5-12", NaN !== NaN, true); -eq("File \"float_test.res\", line 100, characters 5-12", Caml_obj.notequal(NaN, 4.2), true); +eq("File \"float_test.res\", line 59, characters 5-12", Primitive_object.notequal(NaN, NaN), true); -eq("File \"float_test.res\", line 101, characters 5-12", NaN < NaN, false); +eq("File \"float_test.res\", line 60, characters 5-12", 4.2 !== NaN, true); -eq("File \"float_test.res\", line 102, characters 5-12", Caml_obj.lessthan(NaN, NaN), false); +eq("File \"float_test.res\", line 61, characters 5-12", Primitive_object.notequal(4.2, NaN), true); -eq("File \"float_test.res\", line 103, characters 5-12", 4.2 < NaN, false); +eq("File \"float_test.res\", line 62, characters 5-12", NaN !== 4.2, true); -eq("File \"float_test.res\", line 104, characters 5-12", Caml_obj.lessthan(4.2, NaN), false); +eq("File \"float_test.res\", line 63, characters 5-12", Primitive_object.notequal(NaN, 4.2), true); -eq("File \"float_test.res\", line 105, characters 5-12", NaN < 4.2, false); +eq("File \"float_test.res\", line 64, characters 5-12", NaN < NaN, false); -eq("File \"float_test.res\", line 106, characters 5-12", Caml_obj.lessthan(NaN, 4.2), false); +eq("File \"float_test.res\", line 65, characters 5-12", Primitive_object.lessthan(NaN, NaN), false); -eq("File \"float_test.res\", line 107, characters 5-12", NaN > NaN, false); +eq("File \"float_test.res\", line 66, characters 5-12", 4.2 < NaN, false); -eq("File \"float_test.res\", line 108, characters 5-12", Caml_obj.greaterthan(NaN, NaN), false); +eq("File \"float_test.res\", line 67, characters 5-12", Primitive_object.lessthan(4.2, NaN), false); -eq("File \"float_test.res\", line 109, characters 5-12", 4.2 > NaN, false); +eq("File \"float_test.res\", line 68, characters 5-12", NaN < 4.2, false); -eq("File \"float_test.res\", line 110, characters 5-12", Caml_obj.greaterthan(4.2, NaN), false); +eq("File \"float_test.res\", line 69, characters 5-12", Primitive_object.lessthan(NaN, 4.2), false); -eq("File \"float_test.res\", line 111, characters 5-12", NaN > 4.2, false); +eq("File \"float_test.res\", line 70, characters 5-12", NaN > NaN, false); -eq("File \"float_test.res\", line 112, characters 5-12", Caml_obj.greaterthan(NaN, 4.2), false); +eq("File \"float_test.res\", line 71, characters 5-12", Primitive_object.greaterthan(NaN, NaN), false); -eq("File \"float_test.res\", line 113, characters 5-12", NaN <= NaN, false); +eq("File \"float_test.res\", line 72, characters 5-12", 4.2 > NaN, false); -eq("File \"float_test.res\", line 114, characters 5-12", Caml_obj.lessequal(NaN, NaN), false); +eq("File \"float_test.res\", line 73, characters 5-12", Primitive_object.greaterthan(4.2, NaN), false); -eq("File \"float_test.res\", line 115, characters 5-12", 4.2 <= NaN, false); +eq("File \"float_test.res\", line 74, characters 5-12", NaN > 4.2, false); -eq("File \"float_test.res\", line 116, characters 5-12", Caml_obj.lessequal(4.2, NaN), false); +eq("File \"float_test.res\", line 75, characters 5-12", Primitive_object.greaterthan(NaN, 4.2), false); -eq("File \"float_test.res\", line 117, characters 5-12", NaN <= 4.2, false); +eq("File \"float_test.res\", line 76, characters 5-12", NaN <= NaN, false); -eq("File \"float_test.res\", line 118, characters 5-12", Caml_obj.lessequal(NaN, 4.2), false); +eq("File \"float_test.res\", line 77, characters 5-12", Primitive_object.lessequal(NaN, NaN), false); -eq("File \"float_test.res\", line 119, characters 5-12", NaN >= NaN, false); +eq("File \"float_test.res\", line 78, characters 5-12", 4.2 <= NaN, false); -eq("File \"float_test.res\", line 120, characters 5-12", Caml_obj.greaterequal(NaN, NaN), false); +eq("File \"float_test.res\", line 79, characters 5-12", Primitive_object.lessequal(4.2, NaN), false); -eq("File \"float_test.res\", line 121, characters 5-12", 4.2 >= NaN, false); +eq("File \"float_test.res\", line 80, characters 5-12", NaN <= 4.2, false); -eq("File \"float_test.res\", line 122, characters 5-12", Caml_obj.greaterequal(4.2, NaN), false); +eq("File \"float_test.res\", line 81, characters 5-12", Primitive_object.lessequal(NaN, 4.2), false); -eq("File \"float_test.res\", line 123, characters 5-12", NaN >= 4.2, false); +eq("File \"float_test.res\", line 82, characters 5-12", NaN >= NaN, false); -eq("File \"float_test.res\", line 124, characters 5-12", Caml_obj.greaterequal(NaN, 4.2), false); +eq("File \"float_test.res\", line 83, characters 5-12", Primitive_object.greaterequal(NaN, NaN), false); -let match$4 = Caml_float.modf_float(32.3); +eq("File \"float_test.res\", line 84, characters 5-12", 4.2 >= NaN, false); -let b = match$4[1]; +eq("File \"float_test.res\", line 85, characters 5-12", Primitive_object.greaterequal(4.2, NaN), false); -let a = match$4[0]; +eq("File \"float_test.res\", line 86, characters 5-12", NaN >= 4.2, false); -Mt.from_pair_suites("Float_test", Pervasives.$at({ - hd: [ - "mod_float", - () => ({ - TAG: "Approx", - _0: 3.2 % 0.5, - _1: 0.200000000000000178 - }) - ], - tl: { - hd: [ - "modf_float1", - () => ({ - TAG: "Approx", - _0: a, - _1: 0.299999999999997158 - }) - ], - tl: { - hd: [ - "modf_float2", - () => ({ - TAG: "Approx", - _0: b, - _1: 32 - }) - ], - tl: { - hd: [ - "int_of_float", - () => ({ - TAG: "Eq", - _0: 3, - _1: 3 - }) - ], - tl: /* [] */0 - } - } - } -}, Pervasives.$at(from_pairs(results), suites.contents))); +eq("File \"float_test.res\", line 87, characters 5-12", Primitive_object.greaterequal(NaN, 4.2), false); exports.test_id = test_id; exports.suites = suites; exports.eq = eq; exports.approx = approx; -exports.epsilon_float = epsilon_float; -exports.results = results; exports.from_pairs = from_pairs; exports.float_compare = float_compare; exports.generic_compare = generic_compare; @@ -381,4 +215,4 @@ exports.float_lessequal = float_lessequal; exports.generic_lessequal = generic_lessequal; exports.float_greaterequal = float_greaterequal; exports.generic_greaterequal = generic_greaterequal; -/* results Not a pure module */ +/* Not a pure module */ diff --git a/jscomp/test/float_test.res b/jscomp/test/float_test.res index 6281fd99c1..c16fcdc0a2 100644 --- a/jscomp/test/float_test.res +++ b/jscomp/test/float_test.res @@ -1,42 +1,13 @@ +open Belt + let (test_id, suites) = (ref(0), ref(list{})) let eq = (loc, x, y) => Mt_global.collect_eq(test_id, suites, loc, x, y) let approx = (loc, x, y) => Mt_global.collect_approx(test_id, suites, loc, x, y) -let epsilon_float = Int64.float_of_bits(0x3C_B0_00_00_00_00_00_00L) - -let results = Array.append( - [ - (log10(2.), 0.301029995663981198), - (ldexp(1., 6), 64.) /* 1. * 2. ^ 6 */, - (ldexp(1., 5), 32.), - (ldexp(1.e-5, 1024), 1.79769313486231605e+303), - (ldexp(1., -1024), 5.56268464626800346e-309), - (hypot(3., 4.), 5.), - (hypot(4., 3.), 5.), - (hypot(5., 12.), 13.), - (hypot(12., 5.), 13.), - (copysign(22.3, -1.), -22.3), - (copysign(22.3, 1.), 22.3), - (expm1(1e-15), 1.00000000000000067e-15), - (log1p(1e-10), 9.9999999995000007e-11), - ], - { - let (a, b) = frexp(12.0) - let (c, d) = frexp(0.) - let (e, f) = frexp(-12.0) - [ - (c, 0.), - (float_of_int(d), 0.), - (a, 0.75), - (float_of_int(b), 4.), - (e, -0.75), - (float_of_int(f), 4.), - ] - }, -) - let from_pairs = ps => - Array.to_list(Array.mapi((i, (a, b)) => ("pair " ++ __unsafe_cast(i), _ => Mt.Approx(a, b)), ps)) + List.fromArray( + ps->Array.mapWithIndex((i, (a, b)) => ("pair " ++ __unsafe_cast(i), _ => Mt.Approx(a, b))), + ) let float_compare = (x: float, y) => Pervasives.compare(x, y) let generic_compare = Pervasives.compare @@ -55,17 +26,12 @@ let generic_greaterequal = \">=" let () = { eq(__LOC__, classify_float(3.), FP_normal) - eq(__LOC__, modf(-3.125), (-0.125, -3.)) eq( __LOC__, - { - let (a, b) = modf(nan) - (Js_float.isNaN(a), Js_float.isNaN(b)) - }, - (true, true), - ) - /* modf nan => (nan,nan) */ - eq(__LOC__, Array.map(x => + [-1, 1, 1], + [(1., 3.), (2., 1.), (3., 2.)] + ->Array.map(((x, y)) => float_compare(x, y)) + ->Array.map(x => if x > 0 { 1 } else if x < 0 { @@ -73,13 +39,10 @@ let () = { } else { 0 } - , Array.map(((x, y)) => float_compare(x, y), [(1., 3.), (2., 1.), (3., 2.)])), [-1, 1, 1]) - eq(__LOC__, copysign(-3., 0.), 3.) - eq(__LOC__, copysign(3., 0.), 3.) + ), + ) eq(__LOC__, log10(10.), 1.) - eq(__LOC__, expm1(0.), 0.) eq(__LOC__, Js.Float.fromString("3.0"), 3.0) - approx(__LOC__, expm1(2.), 6.38905609893065) eq(__LOC__, float_compare(Js.Float._NaN, Js.Float._NaN), 0) eq(__LOC__, generic_compare(Js.Float._NaN, Js.Float._NaN), 0) eq(__LOC__, float_compare(Js.Float._NaN, neg_infinity), -1) @@ -123,22 +86,3 @@ let () = { eq(__LOC__, float_greaterequal(Js.Float._NaN, 4.2), false) eq(__LOC__, generic_greaterequal(Js.Float._NaN, 4.2), false) } - -let () = { - let (a, b) = modf(32.3) - \"@@"( - Mt.from_pair_suites(__MODULE__, ...), - \"@"( - { - open Mt - list{ - ("mod_float", _ => Approx(mod_float(3.2, 0.5), 0.200000000000000178)), - ("modf_float1", _ => Approx(a, 0.299999999999997158)), - ("modf_float2", _ => Approx(b, 32.)), - ("int_of_float", _ => Eq(int_of_float(3.2), 3)), - } - }, - \"@"(from_pairs(results), suites.contents), - ) - ) -} diff --git a/jscomp/test/floatarray_test.js b/jscomp/test/floatarray_test.js deleted file mode 100644 index 1a799f592d..0000000000 --- a/jscomp/test/floatarray_test.js +++ /dev/null @@ -1,45 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let Caml_array = require("../../lib/js/caml_array.js"); - -let suites = { - contents: /* [] */0 -}; - -let test_id = { - contents: 0 -}; - -function eq(loc, x, y) { - Mt.eq_suites(test_id, suites, loc, x, y); -} - -let v = Caml_array.make_float(5); - -for (let i = 0; i <= 4; ++i) { - v[i] = 0; -} - -Caml_array.set(v, 2, 15.5); - -eq("File \"floatarray_test.res\", line 15, characters 5-12", [ - v.length, - v[2], - Caml_array.get(v, 1) -], [ - 5, - 15.5, - 0 -]); - -Mt.from_pair_suites("Floatarray_test", suites.contents); - -let K; - -exports.suites = suites; -exports.test_id = test_id; -exports.eq = eq; -exports.K = K; -/* v Not a pure module */ diff --git a/jscomp/test/floatarray_test.res b/jscomp/test/floatarray_test.res deleted file mode 100644 index 620069de91..0000000000 --- a/jscomp/test/floatarray_test.res +++ /dev/null @@ -1,18 +0,0 @@ -let suites: ref = ref(list{}) -let test_id = ref(0) -let eq = (loc, x, y) => Mt.eq_suites(~test_id, ~suites, loc, x, y) - -module K = Array.Floatarray - -let () = { - let len = 5 - let v = K.create(len) - - for i in 0 to len - 1 { - K.unsafe_set(v, i, 0.) - } - K.set(v, 2, 0x1.fp3) - eq(__LOC__, (K.length(v), K.unsafe_get(v, 2), K.get(v, 1)), (len, 0x1.fp3, 0.)) -} - -let () = Mt.from_pair_suites(__MODULE__, suites.contents) diff --git a/jscomp/test/for_loop_test.js b/jscomp/test/for_loop_test.js index 11a546508a..aa2e40fc74 100644 --- a/jscomp/test/for_loop_test.js +++ b/jscomp/test/for_loop_test.js @@ -1,22 +1,22 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); -let $$Array = require("../../lib/js/array.js"); -let Caml_array = require("../../lib/js/caml_array.js"); +let Belt_List = require("../../lib/js/belt_List.js"); +let Belt_Array = require("../../lib/js/belt_Array.js"); +let Primitive_array = require("../../lib/js/primitive_array.js"); function for_3(x) { let v = { contents: 0 }; - let arr = $$Array.map(param => (() => {}), x); + let arr = Belt_Array.map(x, param => (() => {})); for (let i = 0, i_finish = x.length; i < i_finish; ++i) { let j = (i << 1); - Caml_array.set(arr, i, () => { + Primitive_array.set(arr, i, () => { v.contents = v.contents + j | 0; }); } - $$Array.iter(x => x(), arr); + Belt_Array.forEach(arr, x => x()); return v.contents; } @@ -24,15 +24,15 @@ function for_4(x) { let v = { contents: 0 }; - let arr = $$Array.map(param => (() => {}), x); + let arr = Belt_Array.map(x, param => (() => {})); for (let i = 0, i_finish = x.length; i < i_finish; ++i) { let j = (i << 1); let k = (j << 1); - Caml_array.set(arr, i, () => { + Primitive_array.set(arr, i, () => { v.contents = v.contents + k | 0; }); } - $$Array.iter(x => x(), arr); + Belt_Array.forEach(arr, x => x()); return v.contents; } @@ -40,14 +40,14 @@ function for_5(x, u) { let v = { contents: 0 }; - let arr = $$Array.map(param => (() => {}), x); + let arr = Belt_Array.map(x, param => (() => {})); for (let i = 0, i_finish = x.length; i < i_finish; ++i) { let k = Math.imul((u << 1), u); - Caml_array.set(arr, i, () => { + Primitive_array.set(arr, i, () => { v.contents = v.contents + k | 0; }); } - $$Array.iter(x => x(), arr); + Belt_Array.forEach(arr, x => x()); return v.contents; } @@ -55,7 +55,7 @@ function for_6(x, u) { let v = { contents: 0 }; - let arr = $$Array.map(param => (() => {}), x); + let arr = Belt_Array.map(x, param => (() => {})); let v4 = { contents: 0 }; @@ -73,13 +73,13 @@ function for_6(x, u) { let k = Math.imul((u << 1), u); let h = (v5.contents << 1); v2.contents = v2.contents + 1 | 0; - Caml_array.set(arr, i, () => { + Primitive_array.set(arr, i, () => { v.contents = (((((v.contents + k | 0) + v2.contents | 0) + v4.contents | 0) + v5.contents | 0) + h | 0) + u | 0; }); } inspect_3 = v2.contents; } - $$Array.iter(x => x(), arr); + Belt_Array.forEach(arr, x => x()); return [ v.contents, v4.contents, @@ -92,15 +92,15 @@ function for_7() { let v = { contents: 0 }; - let arr = Caml_array.make(21, () => {}); + let arr = Belt_Array.make(21, () => {}); for (let i = 0; i <= 6; ++i) { for (let j = 0; j <= 2; ++j) { - Caml_array.set(arr, Math.imul(i, 3) + j | 0, () => { + Primitive_array.set(arr, Math.imul(i, 3) + j | 0, () => { v.contents = (v.contents + i | 0) + j | 0; }); } } - $$Array.iter(f => f(), arr); + Belt_Array.forEach(arr, f => f()); return v.contents; } @@ -108,17 +108,17 @@ function for_8() { let v = { contents: 0 }; - let arr = Caml_array.make(21, () => {}); + let arr = Belt_Array.make(21, () => {}); for (let i = 0; i <= 6; ++i) { let k = (i << 1); for (let j = 0; j <= 2; ++j) { let h = i + j | 0; - Caml_array.set(arr, Math.imul(i, 3) + j | 0, () => { + Primitive_array.set(arr, Math.imul(i, 3) + j | 0, () => { v.contents = (((v.contents + i | 0) + j | 0) + h | 0) + k | 0; }); } } - $$Array.iter(f => f(), arr); + Belt_Array.forEach(arr, f => f()); return v.contents; } @@ -138,8 +138,8 @@ function for_9() { let vv2 = { contents: 0 }; - let arr = Caml_array.make(4, () => {}); - let arr2 = Caml_array.make(2, () => {}); + let arr = Belt_Array.make(4, () => {}); + let arr2 = Belt_Array.make(2, () => {}); for (let i = 0; i <= 1; ++i) { let v$1 = { contents: 0 @@ -148,19 +148,19 @@ function for_9() { for (let j = 0; j <= 1; ++j) { v$1.contents = v$1.contents + 1 | 0; collect(v$1.contents); - Caml_array.set(arr, (i << 1) + j | 0, () => { + Primitive_array.set(arr, (i << 1) + j | 0, () => { vv.contents = vv.contents + v$1.contents | 0; }); } - Caml_array.set(arr2, i, () => { + Primitive_array.set(arr2, i, () => { vv2.contents = vv2.contents + v$1.contents | 0; }); } - $$Array.iter(f => f(), arr); - $$Array.iter(f => f(), arr2); + Belt_Array.forEach(arr, f => f()); + Belt_Array.forEach(arr2, f => f()); return [[ vv.contents, - $$Array.of_list(List.rev(v.contents)), + Belt_List.toArray(Belt_List.reverse(v.contents)), vv2.contents ]]; } @@ -170,7 +170,7 @@ let suites_0 = [ param => ({ TAG: "Eq", _0: 90, - _1: for_3(Caml_array.make(10, 2)) + _1: for_3(Belt_Array.make(10, 2)) }) ]; @@ -180,7 +180,7 @@ let suites_1 = { param => ({ TAG: "Eq", _0: 180, - _1: for_4(Caml_array.make(10, 2)) + _1: for_4(Belt_Array.make(10, 2)) }) ], tl: { @@ -189,7 +189,7 @@ let suites_1 = { param => ({ TAG: "Eq", _0: 2420, - _1: for_5(Caml_array.make(10, 2), 11) + _1: for_5(Belt_Array.make(10, 2), 11) }) ], tl: { @@ -203,7 +203,7 @@ let suites_1 = { 2, 3 ], - _1: for_6(Caml_array.make(3, 0), 0) + _1: for_6(Belt_Array.make(3, 0), 0) }) ], tl: { diff --git a/jscomp/test/for_loop_test.res b/jscomp/test/for_loop_test.res index 89f8085f07..057b78dbf0 100644 --- a/jscomp/test/for_loop_test.res +++ b/jscomp/test/for_loop_test.res @@ -1,41 +1,41 @@ let for_3 = x => { let v = ref(0) - let arr = Array.map(_ => _ => (), x) - for i in 0 to Array.length(x) - 1 { + let arr = x->Belt.Array.map(_ => _ => ()) + for i in 0 to Belt.Array.length(x) - 1 { let j = i * 2 arr[i] = _ => v := v.contents + j } - Array.iter(x => x(), arr) + arr->Belt.Array.forEach(x => x()) v.contents } let for_4 = x => { let v = ref(0) - let arr = Array.map(_ => _ => (), x) - for i in 0 to Array.length(x) - 1 { + let arr = x->Belt.Array.map(_ => _ => ()) + for i in 0 to Belt.Array.length(x) - 1 { let j = i * 2 let k = 2 * j arr[i] = _ => v := v.contents + k } - Array.iter(x => x(), arr) + arr->Belt.Array.forEach(x => x()) v.contents } let for_5 = (x, u) => { let v = ref(0) - let arr = Array.map(_ => _ => (), x) - for i in 0 to Array.length(x) - 1 { + let arr = x->Belt.Array.map(_ => _ => ()) + for i in 0 to Belt.Array.length(x) - 1 { let _j = i * 2 let k = 2 * u * u arr[i] = _ => v := v.contents + k } - Array.iter(x => x(), arr) + arr->Belt.Array.forEach(x => x()) v.contents } let for_6 = (x, u) => { let v = ref(0) - let arr = Array.map(_ => _ => (), x) + let arr = x->Belt.Array.map(_ => _ => ()) let v4 = ref(0) let v5 = ref(0) let inspect_3 = ref(-1) @@ -44,7 +44,7 @@ let for_6 = (x, u) => { incr(v5) let v2 = ref(0) let v3 = u - for i in 0 to Array.length(x) - 1 { + for i in 0 to Belt.Array.length(x) - 1 { let _j = i * 2 let k = 2 * u * u let h = 2 * v5.contents @@ -54,7 +54,7 @@ let for_6 = (x, u) => { } inspect_3 := v2.contents } - Array.iter(x => x(), arr) + arr->Belt.Array.forEach(x => x()) [v.contents, v4.contents, v5.contents, inspect_3.contents] } @@ -62,13 +62,13 @@ let for_7 = () => { let i_len = 7 let j_len = 3 let v = ref(0) - let arr = Array.make(i_len * j_len, _ => ()) + let arr = Belt.Array.make(i_len * j_len, _ => ()) for i in 0 to i_len - 1 { for j in 0 to j_len - 1 { arr[i * j_len + j] = _ => v := v.contents + i + j } } - Array.iter(f => f(), arr) + arr->Belt.Array.forEach(f => f()) v.contents } @@ -76,7 +76,7 @@ let for_8 = () => { let i_len = 7 let j_len = 3 let v = ref(0) - let arr = Array.make(i_len * j_len, _ => ()) + let arr = Belt.Array.make(i_len * j_len, _ => ()) for i in 0 to i_len - 1 { let k = 2 * i for j in 0 to j_len - 1 { @@ -84,22 +84,25 @@ let for_8 = () => { arr[i * j_len + j] = _ => v := v.contents + i + j + h + k } } - Array.iter(f => f(), arr) + arr->Belt.Array.forEach(f => f()) v.contents } let for_9 = () => { let (collect, get) = { let v: ref> = ref(list{}) - (x => v := list{x, ...v.contents}, () => \"@@"(Array.of_list, List.rev(v.contents))) + ( + x => v := list{x, ...v.contents}, + () => \"@@"(Belt.List.toArray, Belt.List.reverse(v.contents)), + ) } let i_len = 2 let j_len = 2 let vv = ref(0) let vv2 = ref(0) - let arr = Array.make(i_len * j_len, _ => ()) - let arr2 = Array.make(i_len, _ => ()) + let arr = Belt.Array.make(i_len * j_len, _ => ()) + let arr2 = Belt.Array.make(i_len, _ => ()) for i in 0 to i_len - 1 { let v = ref(0) /* incr v ; */ @@ -128,8 +131,8 @@ let for_9 = () => { v is changed */ } - Array.iter(f => f(), arr) - Array.iter(f => f(), arr2) + arr->Belt.Array.forEach(f => f()) + arr2->Belt.Array.forEach(f => f()) [(vv.contents, get(), vv2.contents)] } @@ -158,10 +161,10 @@ console.log(result,u) */ let suites = list{ - ("for_loop_test_3", _ => Mt.Eq(90, \"@@"(for_3, Array.make(10, 2)))), - ("for_loop_test_4", _ => Mt.Eq(180, \"@@"(for_4, Array.make(10, 2)))), - ("for_loop_test_5", _ => Mt.Eq(2420, for_5(Array.make(10, 2), 11))), - ("for_loop_test_6", _ => Mt.Eq([30, 1, 2, 3], for_6(Array.make(3, 0), 0))), + ("for_loop_test_3", _ => Mt.Eq(90, \"@@"(for_3, Belt.Array.make(10, 2)))), + ("for_loop_test_4", _ => Mt.Eq(180, \"@@"(for_4, Belt.Array.make(10, 2)))), + ("for_loop_test_5", _ => Mt.Eq(2420, for_5(Belt.Array.make(10, 2), 11))), + ("for_loop_test_6", _ => Mt.Eq([30, 1, 2, 3], for_6(Belt.Array.make(3, 0), 0))), ("for_loop_test_7", _ => Mt.Eq(84, for_7())), ("for_loop_test_8", _ => Mt.Eq(294, for_8())), ("for_loop_test_9", _ => Mt.Eq([(10, [1, 2, 2, 3], 5)], for_9())), diff --git a/jscomp/test/for_side_effect_test.res b/jscomp/test/for_side_effect_test.res index e1b66ba3ca..016d0c1a8c 100644 --- a/jscomp/test/for_side_effect_test.res +++ b/jscomp/test/for_side_effect_test.res @@ -1,9 +1,9 @@ let tst = () => for i in { - print_endline("hi") + Js.log("hi") 0 } to { - print_endline("hello") + Js.log("hello") 3 } { () diff --git a/jscomp/test/format_test.js b/jscomp/test/format_test.js deleted file mode 100644 index 126980a702..0000000000 --- a/jscomp/test/format_test.js +++ /dev/null @@ -1,201 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); -let Bytes = require("../../lib/js/bytes.js"); -let Pervasives = require("../../lib/js/pervasives.js"); -let Caml_format = require("../../lib/js/caml_format.js"); - -let suites = { - contents: /* [] */0 -}; - -let test_id = { - contents: 0 -}; - -function eq(loc, x, y) { - test_id.contents = test_id.contents + 1 | 0; - suites.contents = { - hd: [ - loc + (" id " + String(test_id.contents)), - () => ({ - TAG: "Eq", - _0: x, - _1: y - }) - ], - tl: suites.contents - }; -} - -function eq3(loc, a, b, c) { - eq(loc, a, b); - eq(loc, b, c); - eq(loc, a, c); -} - -let M = {}; - -eq("File \"format_test.res\", line 23, characters 5-12", 7.875, 7.875); - -eq("File \"format_test.res\", line 25, characters 5-12", -7.875, -7.875); - -eq3("File \"format_test.res\", line 29, characters 6-13", Infinity, Number.POSITIVE_INFINITY, Pervasives.infinity); - -eq3("File \"format_test.res\", line 30, characters 6-13", -Infinity, Number.NEGATIVE_INFINITY, Pervasives.neg_infinity); - -eq3("File \"format_test.res\", line 31, characters 6-13", Pervasives.max_float, 1.79769313486231571e+308, Number.MAX_VALUE); - -eq("File \"format_test.res\", line 32, characters 5-12", Pervasives.classify_float(Infinity), "FP_infinite"); - -eq("File \"format_test.res\", line 33, characters 5-12", Pervasives.classify_float(Infinity), "FP_infinite"); - -eq("File \"format_test.res\", line 35, characters 5-12", Pervasives.min_float, 2.22507385850720138e-308); - -eq("File \"format_test.res\", line 36, characters 5-12", Pervasives.epsilon_float, 2.22044604925031308e-16); - -eq("File \"format_test.res\", line 37, characters 5-12", 4.94065645841e-324, 5e-324); - -eq("File \"format_test.res\", line 38, characters 5-12", 1.00000000000000022 - 1, Pervasives.epsilon_float); - -eq("File \"format_test.res\", line 39, characters 5-12", 1.11253692925360069e-308 / 2.22507385850720138e-308, 0.5); - -eq("File \"format_test.res\", line 40, characters 5-12", Pervasives.classify_float(1.11253692925360069e-308), "FP_subnormal"); - -eq("File \"format_test.res\", line 41, characters 5-12", 1.11253692925360069e-308, 1.11253692925360069e-308); - -eq("File \"format_test.res\", line 42, characters 5-12", 2.22507385850720138e-308, 2.22507385850720138e-308); - -eq("File \"format_test.res\", line 44, characters 5-12", (1 + 255 / 256) * 8, 15.96875); - -eq("File \"format_test.res\", line 45, characters 5-12", (1 + 4095 / 4096) * 8, 15.998046875); - -eq("File \"format_test.res\", line 46, characters 5-12", (1 + 65535 / 65536) * 8, 15.9998779296875); - -function f(loc, ls) { - List.iter(param => eq(loc, Caml_format.float_of_string(param[0]), param[1]), ls); -} - -f("File \"format_test.res\", line 53, characters 11-18", { - hd: [ - "0x3.fp+1", - 7.875 - ], - tl: { - hd: [ - " 0x3.fp2", - 15.75 - ], - tl: { - hd: [ - " 0x4.fp2", - 19.75 - ], - tl: /* [] */0 - } - } -}); - -function sl(f) { - return Caml_format.hexstring_of_float(f, -1, /* '-' */45); -} - -function aux_list(loc, ls) { - List.iter(param => eq(loc, Caml_format.hexstring_of_float(param[0], -1, /* '-' */45), param[1]), ls); -} - -let literals_0 = [ - 7.875, - "0x1.f8p+2" -]; - -let literals_1 = { - hd: [ - 0.3, - "0x1.3333333333333p-2" - ], - tl: { - hd: [ - Pervasives.infinity, - "infinity" - ], - tl: { - hd: [ - 0.4, - "0x1.999999999999ap-2" - ], - tl: { - hd: [ - 0.5, - "0x1p-1" - ], - tl: { - hd: [ - 0.6, - "0x1.3333333333333p-1" - ], - tl: { - hd: [ - 0.7, - "0x1.6666666666666p-1" - ], - tl: { - hd: [ - 0.8, - "0x1.999999999999ap-1" - ], - tl: { - hd: [ - 0.9, - "0x1.ccccccccccccdp-1" - ], - tl: /* [] */0 - } - } - } - } - } - } - } -}; - -let literals = { - hd: literals_0, - tl: literals_1 -}; - -aux_list("File \"format_test.res\", line 72, characters 18-25", literals); - -let s = Caml_format.hexstring_of_float(7.875, -1, /* '-' */45); - -eq("File \"format_test.res\", line 74, characters 12-19", Bytes.unsafe_to_string(Bytes.uppercase_ascii(Bytes.unsafe_of_string(s))), "0X1.F8P+2"); - -function scan_float(loc, s, expect) { - eq(loc, Caml_format.float_of_string(s), expect); -} - -scan_float("File \"format_test.res\", line 80, characters 13-20", "0x3f.p1", 126); - -scan_float("File \"format_test.res\", line 81, characters 13-20", "0x1.3333333333333p-2", 0.3); - -List.iter(param => scan_float("File \"format_test.res\", line 82, characters 35-42", param[1], param[0]), literals); - -let f1 = - -9.9; - -eq("File \"format_test.res\", line 88, characters 5-12", f1, 9.9); - -Mt.from_pair_suites("Format_test", suites.contents); - -exports.suites = suites; -exports.test_id = test_id; -exports.eq = eq; -exports.eq3 = eq3; -exports.M = M; -exports.f = f; -exports.sl = sl; -exports.aux_list = aux_list; -exports.literals = literals; -exports.scan_float = scan_float; -/* Not a pure module */ diff --git a/jscomp/test/format_test.res b/jscomp/test/format_test.res deleted file mode 100644 index 663cb9df67..0000000000 --- a/jscomp/test/format_test.res +++ /dev/null @@ -1,91 +0,0 @@ -let suites: ref = ref(list{}) -let test_id = ref(0) -let eq = (loc, x, y) => { - incr(test_id) - suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} -} - -let eq3 = (loc, a, b, c) => { - eq(loc, a, b) - eq(loc, b, c) - eq(loc, a, c) -} - -module M = { - @val @scope("Number") external infinity: float = "POSITIVE_INFINITY" - @val @scope("Number") external neg_infinity: float = "NEGATIVE_INFINITY" - @val @scope("Number") external nan: float = "NaN" - @val @scope("Number") external max_float: float = "MAX_VALUE" -} - -let () = { - eq(__LOC__, 0x3.fp+1, 7.875) - - eq(__LOC__, -0x3.fp+1, -7.875) - /* in standard, it is still infinity, but - ideally should give an warning - */ - eq3(__LOC__, 0x1p2047, M.infinity, infinity) - eq3(__LOC__, -0x1p2047, M.neg_infinity, neg_infinity) - eq3(__LOC__, max_float, 0x1.ffff_ffff_ffff_fp+1023, M.max_float) - eq(__LOC__, classify_float(0x1.2p2047), FP_infinite) - eq(__LOC__, classify_float(0x1.1p2047), FP_infinite) - - eq(__LOC__, min_float, 0x1p-1022) - eq(__LOC__, epsilon_float, 0x1p-52) - eq(__LOC__, 0x0.0000_0000_0000_1p-1022, 5e-324) - eq(__LOC__, 0x1.0000_0000_0000_1 -. 1., epsilon_float) - eq(__LOC__, 0x1p-1023 /. 0x1p-1022, 0x1p-1) - eq(__LOC__, classify_float(0x1p-1023), FP_subnormal) - eq(__LOC__, 0x1p-1023, 0x0.8p-1022) - eq(__LOC__, 0x0.ffff_ffff_ffff_ffff_ffp-1022, 0x1p-1022) - - eq(__LOC__, (1. +. 0xffp0 /. 0x100p0) *. 8., 0x1.ffp3) - eq(__LOC__, (1. +. 0xfffp0 /. 0x1000p0) *. 8., 0x1.fffp3) - eq(__LOC__, (1. +. 0xffffp0 /. 0x10000p0) *. 8., 0x1.ffffp3) -} - -/* TODO: add scanf example */ - -let f = (loc, ls) => List.iter(((a, b)) => eq(loc, float_of_string(a), b), ls) - -let () = f(__LOC__, list{("0x3.fp+1", 0x3.fp+1), (" 0x3.fp2", 0x3.fp2), (" 0x4.fp2", 0x4.fp2)}) - -external hexstring_of_float: (float, int, char) => string = "?hexstring_of_float" - -let sl = (f: float): string => hexstring_of_float(f, -1, '-') - -let aux_list = (loc, ls) => List.iter(((a, b)) => eq(loc, sl(a), b), ls) -let literals = list{ - (0x3.fp+1, "0x1.f8p+2") /* (1. +. 0xf8p0 /. 0x1_00p0) *. 4. */, - (0.3, "0x1.3333333333333p-2"), - (infinity, "infinity"), - (0.4, "0x1.999999999999ap-2"), - (0.5, "0x1p-1"), - (0.6, "0x1.3333333333333p-1"), - (0.7, "0x1.6666666666666p-1"), - (0.8, "0x1.999999999999ap-1"), - (0.9, "0x1.ccccccccccccdp-1"), -} - -let () = aux_list(__LOC__, literals) - -let () = eq(__LOC__, String.uppercase_ascii(hexstring_of_float(0x3.fp+1, -1, '-')), "0X1.F8P+2") -/* The internal does some thing similar with "%H" */ -let scan_float = (loc, s, expect) => eq(loc, float_of_string(s), expect) -/* Scanf.sscanf s "%h" (fun result -> eq loc result expect) */ - -let () = { - scan_float(__LOC__, "0x3f.p1", 0x3f.p1) - scan_float(__LOC__, "0x1.3333333333333p-2", 0.3) - List.iter(((a, b)) => scan_float(__LOC__, b, a), literals) -} - -let () = { - let f = -9.9 - let f1 = -.f - eq(__LOC__, f1, 9.9) -} - -let () = Mt.from_pair_suites(__MODULE__, suites.contents) diff --git a/jscomp/test/fun_pattern_match.js b/jscomp/test/fun_pattern_match.js index 9b3880f260..5e7c8e1637 100644 --- a/jscomp/test/fun_pattern_match.js +++ b/jscomp/test/fun_pattern_match.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml = require("../../lib/js/caml.js"); +let Primitive_int = require("../../lib/js/primitive_int.js"); function f(param, v) { return ((((param.x0 + param.x1 | 0) + param.x2 | 0) + param.x3 | 0) + param.x4 | 0) + v | 0; @@ -18,7 +18,7 @@ function f3(param, param$1) { lhs === "Uninitialized"; } else { if (typeof rhs === "object") { - return Caml.int_compare(lhs._0, rhs._0); + return Primitive_int.compare(lhs._0, rhs._0); } rhs === "Uninitialized"; } @@ -40,7 +40,7 @@ function f4(param, param$1) { lhs === "Uninitialized"; } else { if (typeof rhs === "object") { - return Caml.int_compare(lhs._0, rhs._0); + return Primitive_int.compare(lhs._0, rhs._0); } rhs === "Uninitialized"; } diff --git a/jscomp/test/functor_app_test.js b/jscomp/test/functor_app_test.js index 0bbeb2abfc..f989957a63 100644 --- a/jscomp/test/functor_app_test.js +++ b/jscomp/test/functor_app_test.js @@ -17,7 +17,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -32,13 +32,13 @@ let Y0 = Functor_def.Make(Functor_inst); let Y1 = Functor_def.Make(Functor_inst); -eq("File \"functor_app_test.res\", line 15, characters 3-10", Y0.h(1, 2), 4); +eq("File \"functor_app_test.res\", line 18, characters 3-10", Y0.h(1, 2), 4); -eq("File \"functor_app_test.res\", line 16, characters 3-10", Y1.h(2, 3), 6); +eq("File \"functor_app_test.res\", line 19, characters 3-10", Y1.h(2, 3), 6); let v = Functor_def.$$return(); -eq("File \"functor_app_test.res\", line 20, characters 3-10", v, 2); +eq("File \"functor_app_test.res\", line 23, characters 3-10", v, 2); Mt.from_pair_suites("Functor_app_test", suites.contents); diff --git a/jscomp/test/functor_app_test.res b/jscomp/test/functor_app_test.res index 7a1fdfc825..eb81c9fd98 100644 --- a/jscomp/test/functor_app_test.res +++ b/jscomp/test/functor_app_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } /* module X = Map.Make(String) */ diff --git a/jscomp/test/functor_ffi.js b/jscomp/test/functor_ffi.js index 70f82d1356..bf32551bd7 100644 --- a/jscomp/test/functor_ffi.js +++ b/jscomp/test/functor_ffi.js @@ -1,17 +1,17 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); function Make(S) { - let opt_get = (f, i) => Caml_option.undefined_to_opt(f[i]); + let opt_get = (f, i) => Primitive_option.fromUndefined(f[i]); return { opt_get: opt_get }; } function opt_get(f, i) { - return Caml_option.undefined_to_opt(f[i]); + return Primitive_option.fromUndefined(f[i]); } let Int_arr = { @@ -21,7 +21,7 @@ let Int_arr = { function f(v) { return [ v[0], - Caml_option.undefined_to_opt(v[1]) + Primitive_option.fromUndefined(v[1]) ]; } diff --git a/jscomp/test/genlex_test.js b/jscomp/test/genlex_test.js deleted file mode 100644 index 00a8e97383..0000000000 --- a/jscomp/test/genlex_test.js +++ /dev/null @@ -1,119 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); -let Genlex = require("../../lib/js/genlex.js"); -let Stream = require("../../lib/js/stream.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); - -let lexer = Genlex.make_lexer({ - hd: "+", - tl: { - hd: "-", - tl: { - hd: "*", - tl: { - hd: "/", - tl: { - hd: "let", - tl: { - hd: "=", - tl: { - hd: "(", - tl: { - hd: ")", - tl: /* [] */0 - } - } - } - } - } - } - } -}); - -function to_list(s) { - let _acc = /* [] */0; - while (true) { - let acc = _acc; - let v; - try { - v = Stream.next(s); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === Stream.Failure) { - return List.rev(acc); - } - throw exn; - } - _acc = { - hd: v, - tl: acc - }; - continue; - }; -} - -let suites_0 = [ - "lexer_stream_genlex", - param => ({ - TAG: "Eq", - _0: { - hd: { - TAG: "Int", - _0: 3 - }, - tl: { - hd: { - TAG: "Kwd", - _0: "(" - }, - tl: { - hd: { - TAG: "Int", - _0: 3 - }, - tl: { - hd: { - TAG: "Kwd", - _0: "+" - }, - tl: { - hd: { - TAG: "Int", - _0: 2 - }, - tl: { - hd: { - TAG: "Int", - _0: -1 - }, - tl: { - hd: { - TAG: "Kwd", - _0: ")" - }, - tl: /* [] */0 - } - } - } - } - } - } - }, - _1: to_list(lexer(Stream.of_string("3(3 + 2 -1)"))) - }) -]; - -let suites = { - hd: suites_0, - tl: /* [] */0 -}; - -Mt.from_pair_suites("Genlex_test", suites); - -exports.lexer = lexer; -exports.to_list = to_list; -exports.suites = suites; -/* lexer Not a pure module */ diff --git a/jscomp/test/genlex_test.res b/jscomp/test/genlex_test.res deleted file mode 100644 index d727895a3d..0000000000 --- a/jscomp/test/genlex_test.res +++ /dev/null @@ -1,27 +0,0 @@ -open Genlex - -let lexer = make_lexer(list{"+", "-", "*", "/", "let", "=", "(", ")"}) - -let to_list = s => { - let rec aux = acc => - switch Stream.next(s) { - | exception Stream.Failure => List.rev(acc) - | v => aux(list{v, ...acc}) - } - aux(list{}) -} - -let suites = { - open Mt - list{ - ( - "lexer_stream_genlex", - _ => Eq( - list{Int(3), Kwd("("), Int(3), Kwd("+"), Int(2), Int(-1), Kwd(")")}, - to_list(lexer(Stream.of_string("3(3 + 2 -1)"))), - ), - ), - } -} - -Mt.from_pair_suites(__MODULE__, suites) diff --git a/jscomp/test/global_module_alias_test.js b/jscomp/test/global_module_alias_test.js index 7752010026..4e52e501c5 100644 --- a/jscomp/test/global_module_alias_test.js +++ b/jscomp/test/global_module_alias_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let suites = { contents: /* [] */0 @@ -16,7 +16,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -45,10 +45,10 @@ function f() { v.contents = v.contents + 1 | 0; v.contents = v.contents + 1 | 0; v.contents = v.contents + 1 | 0; - return List; + return Belt_List; } -eq("File \"global_module_alias_test.res\", line 48, characters 12-19", List.length({ +eq("File \"global_module_alias_test.res\", line 53, characters 12-19", Belt_List.length({ hd: 1, tl: { hd: 2, @@ -80,12 +80,12 @@ v.contents = v.contents + 1 | 0; v.contents = v.contents + 1 | 0; -let H = List; +let H = Belt_List; -eq("File \"global_module_alias_test.res\", line 52, characters 12-19", v.contents, 12); +eq("File \"global_module_alias_test.res\", line 57, characters 12-19", v.contents, 12); function g() { - return List.length({ + return Belt_List.length({ hd: 1, tl: { hd: 2, @@ -104,14 +104,14 @@ function xx() { v.contents = v.contents + 1 | 0; v.contents = v.contents + 1 | 0; v.contents = v.contents + 1 | 0; - return List; + return Belt_List; } -eq("File \"global_module_alias_test.res\", line 80, characters 12-19", g(), 4); +eq("File \"global_module_alias_test.res\", line 85, characters 12-19", g(), 4); let V = xx(); -eq("File \"global_module_alias_test.res\", line 84, characters 5-12", V.length({ +eq("File \"global_module_alias_test.res\", line 89, characters 5-12", V.length({ hd: 1, tl: { hd: 2, @@ -122,11 +122,11 @@ eq("File \"global_module_alias_test.res\", line 84, characters 5-12", V.length({ } }), 3); -eq("File \"global_module_alias_test.res\", line 85, characters 5-12", v.contents, 15); +eq("File \"global_module_alias_test.res\", line 90, characters 5-12", v.contents, 15); let H$1 = f(); -eq("File \"global_module_alias_test.res\", line 87, characters 5-12", H$1.length({ +eq("File \"global_module_alias_test.res\", line 92, characters 5-12", H$1.length({ hd: 1, tl: { hd: 2, @@ -134,7 +134,7 @@ eq("File \"global_module_alias_test.res\", line 87, characters 5-12", H$1.length } }), 2); -eq("File \"global_module_alias_test.res\", line 88, characters 5-12", v.contents, 21); +eq("File \"global_module_alias_test.res\", line 93, characters 5-12", v.contents, 21); Mt.from_pair_suites("Global_module_alias_test", suites.contents); diff --git a/jscomp/test/global_module_alias_test.res b/jscomp/test/global_module_alias_test.res index b2339fa3a8..ba6bdad41e 100644 --- a/jscomp/test/global_module_alias_test.res +++ b/jscomp/test/global_module_alias_test.res @@ -1,9 +1,14 @@ +open Belt + let suites: ref = ref(list{}) let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } module A = List diff --git a/jscomp/test/gpr496_test.js b/jscomp/test/gpr496_test.js index b7c42a58bc..e99639332d 100644 --- a/jscomp/test/gpr496_test.js +++ b/jscomp/test/gpr496_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml = require("../../lib/js/caml.js"); +let Primitive_bool = require("../../lib/js/primitive_bool.js"); let suites = { contents: /* [] */0 @@ -16,7 +16,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -60,15 +60,15 @@ let u = [ 0 ]; -eq("File \"gpr496_test.res\", line 32, characters 12-19", expected, u); +eq("File \"gpr496_test.res\", line 35, characters 12-19", expected, u); -eq("File \"gpr496_test.res\", line 34, characters 12-19", expected, expected2); +eq("File \"gpr496_test.res\", line 37, characters 12-19", expected, expected2); function ff(x, y) { - return Caml.bool_min(x, y()); + return Primitive_bool.min(x, y()); } -eq("File \"gpr496_test.res\", line 37, characters 12-19", true < false ? true : false, false); +eq("File \"gpr496_test.res\", line 40, characters 12-19", true < false ? true : false, false); Mt.from_pair_suites("Gpr496_test", suites.contents); @@ -79,4 +79,4 @@ exports.expected = expected; exports.expected2 = expected2; exports.u = u; exports.ff = ff; -/* expected Not a pure module */ +/* Not a pure module */ diff --git a/jscomp/test/gpr496_test.res b/jscomp/test/gpr496_test.res index 7a3273e785..cf473ad6fb 100644 --- a/jscomp/test/gpr496_test.res +++ b/jscomp/test/gpr496_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let expected = ( diff --git a/jscomp/test/gpr_1154_test.js b/jscomp/test/gpr_1154_test.js deleted file mode 100644 index 409b24e7fa..0000000000 --- a/jscomp/test/gpr_1154_test.js +++ /dev/null @@ -1,68 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let Int64 = require("../../lib/js/int64.js"); -let Caml_int64 = require("../../lib/js/caml_int64.js"); - -let suites = { - contents: /* [] */0 -}; - -let test_id = { - contents: 0 -}; - -function eq(loc, x, y) { - test_id.contents = test_id.contents + 1 | 0; - suites.contents = { - hd: [ - loc + (" id " + String(test_id.contents)), - () => ({ - TAG: "Eq", - _0: x, - _1: y - }) - ], - tl: suites.contents - }; -} - -function f(x) { - console.log("f"); - return x; -} - -function g(x) { - return Caml_int64.or_(x, (console.log("f"), x)); -} - -let v = { - contents: 0 -}; - -function f2(x) { - v.contents = v.contents + 1 | 0; - return x; -} - -function g2(x) { - return Caml_int64.or_(x, (v.contents = v.contents + 1 | 0, x)); -} - -let a = Caml_int64.or_(Int64.one, (v.contents = v.contents + 1 | 0, Int64.one)); - -eq("File \"gpr_1154_test.res\", line 28, characters 12-19", v.contents, 1); - -Mt.from_pair_suites("Gpr_1154_test", suites.contents); - -exports.suites = suites; -exports.test_id = test_id; -exports.eq = eq; -exports.f = f; -exports.g = g; -exports.v = v; -exports.f2 = f2; -exports.g2 = g2; -exports.a = a; -/* a Not a pure module */ diff --git a/jscomp/test/gpr_1154_test.res b/jscomp/test/gpr_1154_test.res deleted file mode 100644 index e1821b8d1e..0000000000 --- a/jscomp/test/gpr_1154_test.res +++ /dev/null @@ -1,29 +0,0 @@ -let suites: ref = ref(list{}) -let test_id = ref(0) -let eq = (loc, x, y) => { - incr(test_id) - suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} -} - -let f = x => { - print_string("f") - x -} -let g = x => Int64.logor(x, f(x)) - -let v = ref(0) -let f2 = x => { - incr(v) - x -} - -let g2 = x => Int64.logor(x, f2(x)) - -/* TODO: should be shared for small integers, - also we should not inline it (more allocations here) - */ -let a = g2 /* 1L */(Int64.one) - -let () = eq(__LOC__, v.contents, 1) -let () = Mt.from_pair_suites(__MODULE__, suites.contents) diff --git a/jscomp/test/gpr_1245_test.js b/jscomp/test/gpr_1245_test.js index 3ed9c70903..95c87c2ef3 100644 --- a/jscomp/test/gpr_1245_test.js +++ b/jscomp/test/gpr_1245_test.js @@ -1,8 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); let x = { contents: 1 @@ -38,11 +37,11 @@ function a0(f) { } function a1(f) { - let E = /* @__PURE__ */Caml_exceptions.create("E"); + let E = /* @__PURE__ */Primitive_exceptions.create("E"); try { return f(); } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + let exn = Primitive_exceptions.internalToException(raw_exn); if (exn.RE_EXN_ID === E) { return 1; } diff --git a/jscomp/test/gpr_1409_test.js b/jscomp/test/gpr_1409_test.js index 0fd2d32db4..3e72c1d893 100644 --- a/jscomp/test/gpr_1409_test.js +++ b/jscomp/test/gpr_1409_test.js @@ -2,9 +2,9 @@ 'use strict'; let Mt = require("./mt.js"); -let $$Array = require("../../lib/js/array.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let String_set = require("./string_set.js"); -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); let suites = { contents: /* [] */0 @@ -18,7 +18,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -37,14 +37,14 @@ let b = { function map(f, x) { if (x !== undefined) { - return Caml_option.some(f(Caml_option.valFromOption(x))); + return Primitive_option.some(f(Primitive_option.valFromOption(x))); } } function make(foo, param) { let tmp = {}; - let tmp$1 = map(prim => String(prim), foo); + let tmp$1 = map(prim => prim.toString(), foo); if (tmp$1 !== undefined) { tmp.foo = tmp$1; } @@ -55,13 +55,13 @@ let a_ = make(undefined, undefined); let b_ = make(42, undefined); -eq("File \"gpr_1409_test.res\", line 26, characters 3-10", b_.foo, "42"); +eq("File \"gpr_1409_test.res\", line 31, characters 3-10", b_.foo, "42"); console.log(Object.keys(a_)); console.log(a, b, a_, b_); -eq("File \"gpr_1409_test.res\", line 31, characters 3-10", Object.keys(a_).length, 0); +eq("File \"gpr_1409_test.res\", line 36, characters 3-10", Object.keys(a_).length, 0); let test2 = { hi: 2 @@ -128,15 +128,15 @@ function test6(f, x) { } function keys(xs, ys) { - return String_set.equal(String_set.of_list(xs), String_set.of_list($$Array.to_list(ys))); + return String_set.equal(String_set.of_list(xs), String_set.of_list(Belt_List.fromArray(ys))); } -eq("File \"gpr_1409_test.res\", line 69, characters 3-10", keys({ +eq("File \"gpr_1409_test.res\", line 74, characters 3-10", keys({ hd: "hi", tl: /* [] */0 }, Object.keys(test3(undefined, undefined))), true); -eq("File \"gpr_1409_test.res\", line 71, characters 3-10", keys({ +eq("File \"gpr_1409_test.res\", line 76, characters 3-10", keys({ hd: "hi", tl: { hd: "_open", @@ -144,7 +144,7 @@ eq("File \"gpr_1409_test.res\", line 71, characters 3-10", keys({ } }, Object.keys(test3(2, undefined))), true); -eq("File \"gpr_1409_test.res\", line 73, characters 3-10", keys({ +eq("File \"gpr_1409_test.res\", line 78, characters 3-10", keys({ hd: "hi", tl: { hd: "_open", diff --git a/jscomp/test/gpr_1409_test.res b/jscomp/test/gpr_1409_test.res index ce8af26025..52455e2eb5 100644 --- a/jscomp/test/gpr_1409_test.res +++ b/jscomp/test/gpr_1409_test.res @@ -1,9 +1,14 @@ +open Belt + let suites: ref = ref(list{}) let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } /* type t */ @@ -18,7 +23,7 @@ let map = (f, x) => | Some(x) => Some(f(x)) } -let make = (~foo: option=?, ()) => make(~foo=?map(string_of_int, foo), ()) +let make = (~foo: option=?, ()) => make(~foo=?map(Js.Int.toString, foo), ()) let a_ = make() let b_ = make(~foo=42, ()) @@ -64,7 +69,7 @@ let test6 = (f, x) => { } let keys = (xs, ys) => - String_set.equal(String_set.of_list(xs), String_set.of_list(Array.to_list(ys))) + String_set.equal(String_set.of_list(xs), String_set.of_list(List.fromArray(ys))) eq(__LOC__, keys(list{"hi"}, Js.Obj.keys(test3(None, None))), true) diff --git a/jscomp/test/gpr_1423_app_test.js b/jscomp/test/gpr_1423_app_test.js index e87c3e1fc1..f3e36863a1 100644 --- a/jscomp/test/gpr_1423_app_test.js +++ b/jscomp/test/gpr_1423_app_test.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -36,7 +36,7 @@ function foo2(f) { return f("a1", undefined); } -eq("File \"gpr_1423_app_test.res\", line 15, characters 12-19", "a1a2", "a1a2"); +eq("File \"gpr_1423_app_test.res\", line 18, characters 12-19", "a1a2", "a1a2"); Mt.from_pair_suites("Gpr_1423_app_test", suites.contents); diff --git a/jscomp/test/gpr_1423_app_test.res b/jscomp/test/gpr_1423_app_test.res index 5ae7060ee9..ed16e139e0 100644 --- a/jscomp/test/gpr_1423_app_test.res +++ b/jscomp/test/gpr_1423_app_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let foo = f => Js.log(f(~a1="a1", ())) diff --git a/jscomp/test/gpr_1503_test.js b/jscomp/test/gpr_1503_test.js deleted file mode 100644 index c5bd31f0c6..0000000000 --- a/jscomp/test/gpr_1503_test.js +++ /dev/null @@ -1,57 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let Int64 = require("../../lib/js/int64.js"); -let Caml_int64 = require("../../lib/js/caml_int64.js"); -let Caml_format = require("../../lib/js/caml_format.js"); - -let suites = { - contents: /* [] */0 -}; - -let test_id = { - contents: 0 -}; - -function eq(loc, x, y) { - test_id.contents = test_id.contents + 1 | 0; - suites.contents = { - hd: [ - loc + (" id " + String(test_id.contents)), - () => ({ - TAG: "Eq", - _0: x, - _1: y - }) - ], - tl: suites.contents - }; -} - -function id(x) { - return Caml_format.int64_of_string(Caml_int64.to_string(x)); -} - -let i = [ - 2074848171, - 2880154539 -]; - -let s = Caml_int64.to_string(i); - -let i$p = Caml_format.int64_of_string(s); - -eq("File \"gpr_1503_test.res\", line 15, characters 5-12", i, i$p); - -eq("File \"gpr_1503_test.res\", line 19, characters 5-12", Int64.max_int, Caml_format.int64_of_string(Caml_int64.to_string(Int64.max_int))); - -eq("File \"gpr_1503_test.res\", line 20, characters 5-12", Int64.min_int, Caml_format.int64_of_string(Caml_int64.to_string(Int64.min_int))); - -Mt.from_pair_suites("Gpr_1503_test", suites.contents); - -exports.suites = suites; -exports.test_id = test_id; -exports.eq = eq; -exports.id = id; -/* s Not a pure module */ diff --git a/jscomp/test/gpr_1503_test.res b/jscomp/test/gpr_1503_test.res deleted file mode 100644 index 91d165b9c7..0000000000 --- a/jscomp/test/gpr_1503_test.res +++ /dev/null @@ -1,23 +0,0 @@ -let suites: ref = ref(list{}) -let test_id = ref(0) -let eq = (loc, x, y) => { - incr(test_id) - suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} -} - -let id = x => Int64.of_string(Int64.to_string(x)) - -let () = { - let i = 0x7BABABABABABABABL - let s = Int64.to_string(i) - let i' = Int64.of_string(s) - eq(__LOC__, i, i') -} - -let () = { - eq(__LOC__, Int64.max_int, id(Int64.max_int)) - eq(__LOC__, Int64.min_int, id(Int64.min_int)) -} - -let () = Mt.from_pair_suites(__MODULE__, suites.contents) diff --git a/jscomp/test/gpr_1539_test.js b/jscomp/test/gpr_1539_test.js index e8b2d507a8..6fa24f0d57 100644 --- a/jscomp/test/gpr_1539_test.js +++ b/jscomp/test/gpr_1539_test.js @@ -1,9 +1,9 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_module = require("../../lib/js/caml_module.js"); +let Primitive_module = require("../../lib/js/primitive_module.js"); -let Point = Caml_module.init_mod([ +let Point = Primitive_module.init([ "gpr_1539_test.res", 11, 4 @@ -15,7 +15,7 @@ let Point = Caml_module.init_mod([ ]] }); -Caml_module.update_mod({ +Primitive_module.update({ TAG: "Module", _0: [[ "Function", diff --git a/jscomp/test/gpr_1658_test.js b/jscomp/test/gpr_1658_test.js index f0b9e8752e..6da586473f 100644 --- a/jscomp/test/gpr_1658_test.js +++ b/jscomp/test/gpr_1658_test.js @@ -16,7 +16,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -27,19 +27,19 @@ function eq(loc, x, y) { }; } -eq("File \"gpr_1658_test.res\", line 10, characters 5-12", null, null); +eq("File \"gpr_1658_test.res\", line 13, characters 5-12", null, null); let match = Js_types.classify(null); if (typeof match !== "object" && match === "JSNull") { - eq("File \"gpr_1658_test.res\", line 12, characters 17-24", true, true); + eq("File \"gpr_1658_test.res\", line 15, characters 17-24", true, true); } else { - eq("File \"gpr_1658_test.res\", line 13, characters 12-19", true, false); + eq("File \"gpr_1658_test.res\", line 16, characters 12-19", true, false); } -eq("File \"gpr_1658_test.res\", line 15, characters 5-12", true, Js_types.test(null, "Null")); +eq("File \"gpr_1658_test.res\", line 18, characters 5-12", true, Js_types.test(null, "Null")); -Mt.from_pair_suites("File \"gpr_1658_test.res\", line 18, characters 20-27", suites.contents); +Mt.from_pair_suites("File \"gpr_1658_test.res\", line 21, characters 20-27", suites.contents); exports.suites = suites; exports.test_id = test_id; diff --git a/jscomp/test/gpr_1658_test.res b/jscomp/test/gpr_1658_test.res index b25a155802..b71684c34f 100644 --- a/jscomp/test/gpr_1658_test.res +++ b/jscomp/test/gpr_1658_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let () = { diff --git a/jscomp/test/gpr_1667_test.js b/jscomp/test/gpr_1667_test.js index 91ee789e76..71234de8d6 100644 --- a/jscomp/test/gpr_1667_test.js +++ b/jscomp/test/gpr_1667_test.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -26,7 +26,7 @@ function eq(loc, x, y) { }; } -eq("File \"gpr_1667_test.res\", line 25, characters 5-12", 0, 0); +eq("File \"gpr_1667_test.res\", line 28, characters 5-12", 0, 0); Mt.from_pair_suites("Gpr_1667_test", suites.contents); diff --git a/jscomp/test/gpr_1667_test.res b/jscomp/test/gpr_1667_test.res index 011f488c03..d7278f49e3 100644 --- a/jscomp/test/gpr_1667_test.res +++ b/jscomp/test/gpr_1667_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } { diff --git a/jscomp/test/gpr_1701_test.js b/jscomp/test/gpr_1701_test.js index b55d0aa9b7..a452a89361 100644 --- a/jscomp/test/gpr_1701_test.js +++ b/jscomp/test/gpr_1701_test.js @@ -1,11 +1,10 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); +let Belt_List = require("../../lib/js/belt_List.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); -let Foo = /* @__PURE__ */Caml_exceptions.create("Gpr_1701_test.Foo"); +let Foo = /* @__PURE__ */Primitive_exceptions.create("Gpr_1701_test.Foo"); function test(n) { if (n === 0) { @@ -17,7 +16,7 @@ function test(n) { try { return test(n - 1 | 0); } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + let exn = Primitive_exceptions.internalToException(raw_exn); if (exn.RE_EXN_ID === Foo) { return; } @@ -35,7 +34,7 @@ function read_lines(inc) { try { l = input_line(inc); } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + let exn = Primitive_exceptions.internalToException(raw_exn); if (exn.RE_EXN_ID === "End_of_file") { l = undefined; } else { @@ -43,7 +42,7 @@ function read_lines(inc) { } } if (l === undefined) { - return List.rev(acc); + return Belt_List.reverse(acc); } _acc = { hd: l, @@ -61,9 +60,9 @@ function read_lines2(inc) { try { l = input_line(inc); } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + let exn = Primitive_exceptions.internalToException(raw_exn); if (exn.RE_EXN_ID === "End_of_file") { - return List.rev(acc); + return Belt_List.reverse(acc); } throw exn; } @@ -84,9 +83,9 @@ function read_lines3(inc) { tl: acc }); } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + let exn = Primitive_exceptions.internalToException(raw_exn); if (exn.RE_EXN_ID === "End_of_file") { - return List.rev(acc); + return Belt_List.reverse(acc); } throw exn; } diff --git a/jscomp/test/gpr_1701_test.res b/jscomp/test/gpr_1701_test.res index ec95e04d28..371efe038b 100644 --- a/jscomp/test/gpr_1701_test.res +++ b/jscomp/test/gpr_1701_test.res @@ -1,3 +1,5 @@ +open Belt + exception Foo let rec test = n => @@ -20,7 +22,7 @@ let read_lines = inc => { | End_of_file => None } { | Some(l) => loop(list{l, ...acc}) - | None => List.rev(acc) + | None => List.reverse(acc) } loop(list{}) @@ -30,7 +32,7 @@ let read_lines2 = inc => { let rec loop = acc => switch input_line(inc) { | l => loop(list{l, ...acc}) - | exception End_of_file => List.rev(acc) + | exception End_of_file => List.reverse(acc) } loop(list{}) @@ -42,7 +44,7 @@ let read_lines3 = inc => { let l = input_line(inc) loop(list{l, ...acc}) } catch { - | End_of_file => List.rev(acc) + | End_of_file => List.reverse(acc) } loop(list{}) diff --git a/jscomp/test/gpr_1716_test.js b/jscomp/test/gpr_1716_test.js index 63584127f3..e51ee0b7fd 100644 --- a/jscomp/test/gpr_1716_test.js +++ b/jscomp/test/gpr_1716_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); let suites = { contents: /* [] */0 @@ -16,7 +16,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -31,11 +31,11 @@ let a = {}; let b = {}; -Caml_obj.update_dummy(a, { +Primitive_object.updateDummy(a, { b: b }); -Caml_obj.update_dummy(b, { +Primitive_object.updateDummy(b, { a: a }); @@ -43,7 +43,7 @@ function is_inifite(x) { return x.b.a === x; } -eq("File \"gpr_1716_test.res\", line 16, characters 3-10", true, is_inifite(a)); +eq("File \"gpr_1716_test.res\", line 19, characters 3-10", true, is_inifite(a)); Mt.from_pair_suites("Gpr_1716_test", suites.contents); diff --git a/jscomp/test/gpr_1716_test.res b/jscomp/test/gpr_1716_test.res index b2e3f99a80..ebd58805b7 100644 --- a/jscomp/test/gpr_1716_test.res +++ b/jscomp/test/gpr_1716_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } type rec a = {b: b} diff --git a/jscomp/test/gpr_1728_test.js b/jscomp/test/gpr_1728_test.js index a593c54a84..629b951788 100644 --- a/jscomp/test/gpr_1728_test.js +++ b/jscomp/test/gpr_1728_test.js @@ -2,7 +2,6 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_format = require("../../lib/js/caml_format.js"); let suites = { contents: /* [] */0 @@ -16,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -28,35 +27,29 @@ function eq(loc, x, y) { } function foo(x) { - return Caml_format.int_of_string(x) !== 3; + return Number.parseInt(x) !== 3; } function badInlining(obj) { let x = obj.field; - Caml_format.int_of_string(x) !== 3; + Number.parseInt(x) !== 3; } -eq("File \"gpr_1728_test.res\", line 16, characters 3-10", badInlining({ +eq("File \"gpr_1728_test.res\", line 21, characters 3-10", badInlining({ field: "3" }), undefined); -eq("File \"gpr_1728_test.res\", line 18, characters 3-10", Caml_format.int_of_string("-13"), -13); +eq("File \"gpr_1728_test.res\", line 23, characters 3-10", Number.parseInt("-13"), -13); -eq("File \"gpr_1728_test.res\", line 19, characters 3-10", Caml_format.int_of_string("+13"), 13); +eq("File \"gpr_1728_test.res\", line 24, characters 3-10", Number.parseInt("+13"), 13); -eq("File \"gpr_1728_test.res\", line 20, characters 3-10", Caml_format.int_of_string("13"), 13); +eq("File \"gpr_1728_test.res\", line 25, characters 3-10", Number.parseInt("13"), 13); -eq("File \"gpr_1728_test.res\", line 21, characters 3-10", Caml_format.int_of_string("0u32"), 32); +eq("File \"gpr_1728_test.res\", line 26, characters 3-10", Number.parseInt("+0x32"), 50); -eq("File \"gpr_1728_test.res\", line 22, characters 3-10", Caml_format.int_of_string("-0u32"), -32); +eq("File \"gpr_1728_test.res\", line 27, characters 3-10", Number.parseInt("-0x32"), -50); -eq("File \"gpr_1728_test.res\", line 23, characters 3-10", Caml_format.int_of_string("+0u32"), 32); - -eq("File \"gpr_1728_test.res\", line 24, characters 3-10", Caml_format.int_of_string("+0x32"), 50); - -eq("File \"gpr_1728_test.res\", line 25, characters 3-10", Caml_format.int_of_string("-0x32"), -50); - -eq("File \"gpr_1728_test.res\", line 26, characters 3-10", Caml_format.int_of_string("0x32"), 50); +eq("File \"gpr_1728_test.res\", line 28, characters 3-10", Number.parseInt("0x32"), 50); Mt.from_pair_suites("Gpr_1728_test", suites.contents); diff --git a/jscomp/test/gpr_1728_test.res b/jscomp/test/gpr_1728_test.res index 655b40b3c8..c86ebbad45 100644 --- a/jscomp/test/gpr_1728_test.res +++ b/jscomp/test/gpr_1728_test.res @@ -3,10 +3,15 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } -let foo = x => int_of_string(x) !== 3 +@scope("Number") external parseInt: string => int = "parseInt" + +let foo = x => parseInt(x) !== 3 let badInlining = obj => if foo(obj["field"]) { @@ -15,13 +20,10 @@ let badInlining = obj => eq(__LOC__, badInlining({"field": "3"}), ()) -eq(__LOC__, int_of_string("-13"), -13) -eq(__LOC__, int_of_string("+13"), 13) -eq(__LOC__, int_of_string("13"), 13) -eq(__LOC__, int_of_string("0u32"), 32) -eq(__LOC__, int_of_string("-0u32"), -32) -eq(__LOC__, int_of_string("+0u32"), 32) -eq(__LOC__, int_of_string("+0x32"), 50) -eq(__LOC__, int_of_string("-0x32"), -50) -eq(__LOC__, int_of_string("0x32"), 50) +eq(__LOC__, parseInt("-13"), -13) +eq(__LOC__, parseInt("+13"), 13) +eq(__LOC__, parseInt("13"), 13) +eq(__LOC__, parseInt("+0x32"), 50) +eq(__LOC__, parseInt("-0x32"), -50) +eq(__LOC__, parseInt("0x32"), 50) Mt.from_pair_suites(__MODULE__, suites.contents) diff --git a/jscomp/test/gpr_1749_test.js b/jscomp/test/gpr_1749_test.js index a253398ae6..72fc1b73ba 100644 --- a/jscomp/test/gpr_1749_test.js +++ b/jscomp/test/gpr_1749_test.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -26,7 +26,7 @@ function eq(loc, x, y) { }; } -eq("File \"gpr_1749_test.res\", line 15, characters 3-10", 0, 0); +eq("File \"gpr_1749_test.res\", line 18, characters 3-10", 0, 0); Mt.from_pair_suites("Gpr_1749_test", suites.contents); diff --git a/jscomp/test/gpr_1749_test.res b/jscomp/test/gpr_1749_test.res index 8b6bc6a223..039b814bc0 100644 --- a/jscomp/test/gpr_1749_test.res +++ b/jscomp/test/gpr_1749_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let a = if 1. < (1. < 1. ? 1. : 10.) { diff --git a/jscomp/test/gpr_1760_test.js b/jscomp/test/gpr_1760_test.js index a1a7811211..a542734cc0 100644 --- a/jscomp/test/gpr_1760_test.js +++ b/jscomp/test/gpr_1760_test.js @@ -2,8 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_int32 = require("../../lib/js/caml_int32.js"); -let Caml_int64 = require("../../lib/js/caml_int64.js"); +let Primitive_int = require("../../lib/js/primitive_int.js"); let suites = { contents: /* [] */0 @@ -17,7 +16,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -31,7 +30,7 @@ function eq(loc, x, y) { let a0; try { - Caml_int32.div(0, 0); + Primitive_int.div(0, 0); a0 = 0; } catch (exn) { a0 = 1; @@ -40,60 +39,16 @@ try { let a1; try { - Caml_int32.mod_(0, 0); + Primitive_int.mod_(0, 0); a1 = 0; } catch (exn$1) { a1 = 1; } -let a4; - -try { - Caml_int32.div(0, 0); - a4 = 0; -} catch (exn$2) { - a4 = 1; -} - -let a5; - -try { - Caml_int32.mod_(0, 0); - a5 = 0; -} catch (exn$3) { - a5 = 1; -} - -let a6; - -try { - Caml_int64.div(Caml_int64.zero, Caml_int64.zero); - a6 = 0; -} catch (exn$4) { - a6 = 1; -} - -let a7; - -try { - Caml_int64.mod_(Caml_int64.zero, Caml_int64.zero); - a7 = 0; -} catch (exn$5) { - a7 = 1; -} - -eq("File \"gpr_1760_test.res\", line 57, characters 3-10", [ +eq("File \"gpr_1760_test.res\", line 26, characters 3-10", [ a0, - a1, - a4, - a5, - a6, - a7 + a1 ], [ - 1, - 1, - 1, - 1, 1, 1 ]); @@ -105,8 +60,4 @@ exports.test_id = test_id; exports.eq = eq; exports.a0 = a0; exports.a1 = a1; -exports.a4 = a4; -exports.a5 = a5; -exports.a6 = a6; -exports.a7 = a7; /* a0 Not a pure module */ diff --git a/jscomp/test/gpr_1760_test.res b/jscomp/test/gpr_1760_test.res index c4e86f6c8f..477708ead3 100644 --- a/jscomp/test/gpr_1760_test.res +++ b/jscomp/test/gpr_1760_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let a0 = try { @@ -20,40 +23,6 @@ let a1 = try { | _ => 1 } -/* -let a2 = try (let _h = Nativeint.div 0n 0n in 0) with _ -> 1 - -let a3 = try (let _h = Nativeint.rem 0n 0n in 0 ) with _ -> 1 -*/ -/* TODO: more work on int32 effect anaylsys */ - -let a4 = try { - let _ = Int32.div(0l, 0l) - 0 -} catch { -| _ => 1 -} - -let a5 = try { - let _ = Int32.rem(0l, 0l) - 0 -} catch { -| _ => 1 -} - -let a6 = try { - let _ = Int64.div(0L, 0L) - 0 -} catch { -| _ => 1 -} -let a7 = try { - let _ = Int64.rem(0L, 0L) - 0 -} catch { -| _ => 1 -} - -eq(__LOC__, (a0, a1, a4, a5, a6, a7), (1, 1, 1, 1, 1, 1)) +eq(__LOC__, (a0, a1), (1, 1)) Mt.from_pair_suites(__MODULE__, suites.contents) diff --git a/jscomp/test/gpr_1762_test.js b/jscomp/test/gpr_1762_test.js index 5624f6b6c7..b17bbc3718 100644 --- a/jscomp/test/gpr_1762_test.js +++ b/jscomp/test/gpr_1762_test.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -37,7 +37,7 @@ function update() { v.contents = v.contents + 1 | 0; -eq("File \"gpr_1762_test.res\", line 24, characters 3-10", v.contents, 4); +eq("File \"gpr_1762_test.res\", line 27, characters 3-10", v.contents, 4); Mt.from_pair_suites("Gpr_1762_test", suites.contents); diff --git a/jscomp/test/gpr_1762_test.res b/jscomp/test/gpr_1762_test.res index 76126707b6..89f05a0741 100644 --- a/jscomp/test/gpr_1762_test.res +++ b/jscomp/test/gpr_1762_test.res @@ -5,7 +5,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let v = ref(3) diff --git a/jscomp/test/gpr_1817_test.js b/jscomp/test/gpr_1817_test.js index a8e9c48e83..3bbc97fa2d 100644 --- a/jscomp/test/gpr_1817_test.js +++ b/jscomp/test/gpr_1817_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); let suites = { contents: /* [] */0 @@ -16,7 +16,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -31,8 +31,8 @@ function f() { let x = new Date(); let y = new Date(); return [ - Caml_obj.greaterthan(y, x), - Caml_obj.lessthan(y, x), + Primitive_object.greaterthan(y, x), + Primitive_object.lessthan(y, x), true ]; } @@ -47,7 +47,7 @@ let a0 = match[0]; console.log(a0, a1); -eq("File \"gpr_1817_test.res\", line 20, characters 3-10", a2, true); +eq("File \"gpr_1817_test.res\", line 23, characters 3-10", a2, true); Mt.from_pair_suites("Gpr_1817_test", suites.contents); diff --git a/jscomp/test/gpr_1817_test.res b/jscomp/test/gpr_1817_test.res index 1189106392..940f02746e 100644 --- a/jscomp/test/gpr_1817_test.res +++ b/jscomp/test/gpr_1817_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } type t diff --git a/jscomp/test/gpr_1822_test.js b/jscomp/test/gpr_1822_test.js index bbabae4d9f..71b86d9e3f 100644 --- a/jscomp/test/gpr_1822_test.js +++ b/jscomp/test/gpr_1822_test.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -35,7 +35,7 @@ let area; area = myShape.TAG === "Circle" ? 100 * 3.14 : Math.imul(10, myShape._1); -eq("File \"gpr_1822_test.res\", line 20, characters 3-10", area, 314); +eq("File \"gpr_1822_test.res\", line 23, characters 3-10", area, 314); Mt.from_pair_suites("Gpr_1822_test", suites.contents); diff --git a/jscomp/test/gpr_1822_test.res b/jscomp/test/gpr_1822_test.res index af4434d94d..0d9006280f 100644 --- a/jscomp/test/gpr_1822_test.res +++ b/jscomp/test/gpr_1822_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } type shape = diff --git a/jscomp/test/gpr_1891_test.res b/jscomp/test/gpr_1891_test.res index d4eea9df65..83c763ecbf 100644 --- a/jscomp/test/gpr_1891_test.res +++ b/jscomp/test/gpr_1891_test.res @@ -1,7 +1,7 @@ let foo = x => switch x { - | #Foo(3) => print_endline("1") - | _ => print_endline("2") + | #Foo(3) => Js.log("1") + | _ => Js.log("2") } let foo2 = x => diff --git a/jscomp/test/gpr_1943_test.js b/jscomp/test/gpr_1943_test.js index 0231c905ae..a49712564e 100644 --- a/jscomp/test/gpr_1943_test.js +++ b/jscomp/test/gpr_1943_test.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -48,7 +48,7 @@ let v = f({ "x'": 6 }); -eq("File \"gpr_1943_test.res\", line 23, characters 3-10", [ +eq("File \"gpr_1943_test.res\", line 26, characters 3-10", [ 0, 1, 2, diff --git a/jscomp/test/gpr_1943_test.res b/jscomp/test/gpr_1943_test.res index df8fc2eac2..3252942707 100644 --- a/jscomp/test/gpr_1943_test.res +++ b/jscomp/test/gpr_1943_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let f = x => (x["_003"], x["_50"], x["_50x"], x["__50"], x["__50x"], x["_50x'"], x["x'"]) diff --git a/jscomp/test/gpr_2316_test.js b/jscomp/test/gpr_2316_test.js index f9c22395bd..0c63484372 100644 --- a/jscomp/test/gpr_2316_test.js +++ b/jscomp/test/gpr_2316_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); let suites = { contents: /* [] */0 @@ -16,7 +16,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -36,7 +36,7 @@ try { Error: new Error() }; } catch (raw_msg) { - let msg = Caml_js_exceptions.internalToOCamlException(raw_msg); + let msg = Primitive_exceptions.internalToException(raw_msg); if (msg.RE_EXN_ID === "Failure") { y = msg._1; } else { @@ -55,7 +55,7 @@ try { Error: new Error() }; } catch (raw_msg$1) { - let msg$1 = Caml_js_exceptions.internalToOCamlException(raw_msg$1); + let msg$1 = Primitive_exceptions.internalToException(raw_msg$1); if (msg$1.RE_EXN_ID === "Failure") { x = msg$1._1; } else { @@ -68,9 +68,9 @@ if (exit === 1) { x = undefined; } -eq("File \"gpr_2316_test.res\", line 22, characters 5-12", y, "boo"); +eq("File \"gpr_2316_test.res\", line 25, characters 5-12", y, "boo"); -eq("File \"gpr_2316_test.res\", line 23, characters 5-12", x, "boo"); +eq("File \"gpr_2316_test.res\", line 26, characters 5-12", x, "boo"); Mt.from_pair_suites("Gpr_2316_test", suites.contents); diff --git a/jscomp/test/gpr_2316_test.res b/jscomp/test/gpr_2316_test.res index f74153316c..d1a9139eca 100644 --- a/jscomp/test/gpr_2316_test.res +++ b/jscomp/test/gpr_2316_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let y = switch failwith("boo") { diff --git a/jscomp/test/gpr_2503_test.js b/jscomp/test/gpr_2503_test.js index 5c6dd53d0f..80d482c7ea 100644 --- a/jscomp/test/gpr_2503_test.js +++ b/jscomp/test/gpr_2503_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); let suites = { contents: /* [] */0 @@ -23,7 +23,7 @@ function b(loc, b$1) { function makeWrapper(foo, param) { let tmp = {}; if (foo !== undefined) { - tmp.foo = Caml_option.valFromOption(foo); + tmp.foo = Primitive_option.valFromOption(foo); } console.log(tmp); } @@ -40,7 +40,7 @@ function makeWrapper3(foo, param) { console.log(2); let tmp = {}; if (foo !== undefined) { - tmp.foo = Caml_option.valFromOption(foo); + tmp.foo = Primitive_option.valFromOption(foo); } return tmp; } @@ -52,7 +52,7 @@ function makeWrapper4(foo, param) { foo > 10 ? "b" : "a" ); if (tmp$1 !== undefined) { - tmp.foo = Caml_option.valFromOption(tmp$1); + tmp.foo = Primitive_option.valFromOption(tmp$1); } return tmp; } diff --git a/jscomp/test/gpr_2608_test.js b/jscomp/test/gpr_2608_test.js index f3a4853f53..94a1db8a63 100644 --- a/jscomp/test/gpr_2608_test.js +++ b/jscomp/test/gpr_2608_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let suites = { contents: /* [] */0 @@ -23,21 +23,21 @@ let oppHeroes = { let huntGrootCondition = false; -if (List.length(/* [] */0) > 0) { - let x = List.filter(h => List.hd(/* [] */0) <= 1000, oppHeroes); - huntGrootCondition = List.length(x) === 0; +if (Belt_List.length(/* [] */0) > 0) { + let x = Belt_List.filter(oppHeroes, h => Belt_List.headExn(/* [] */0) <= 1000); + huntGrootCondition = Belt_List.length(x) === 0; } let huntGrootCondition2 = true; -if (List.length(/* [] */0) < 0) { - let x$1 = List.filter(h => List.hd(/* [] */0) <= 1000, oppHeroes); - huntGrootCondition2 = List.length(x$1) === 0; +if (Belt_List.length(/* [] */0) < 0) { + let x$1 = Belt_List.filter(oppHeroes, h => Belt_List.headExn(/* [] */0) <= 1000); + huntGrootCondition2 = Belt_List.length(x$1) === 0; } -eq("File \"gpr_2608_test.res\", line 21, characters 5-12", huntGrootCondition, false); +eq("File \"gpr_2608_test.res\", line 23, characters 5-12", huntGrootCondition, false); -eq("File \"gpr_2608_test.res\", line 22, characters 5-12", huntGrootCondition2, true); +eq("File \"gpr_2608_test.res\", line 24, characters 5-12", huntGrootCondition2, true); Mt.from_pair_suites("Gpr_2608_test", suites.contents); diff --git a/jscomp/test/gpr_2608_test.res b/jscomp/test/gpr_2608_test.res index 65c23d0e56..a6f7947381 100644 --- a/jscomp/test/gpr_2608_test.res +++ b/jscomp/test/gpr_2608_test.res @@ -1,3 +1,5 @@ +open Belt + let suites: ref = ref(list{}) let test_id = ref(0) let eq = (loc, x, y) => Mt.eq_suites(~test_id, ~suites, loc, x, y) @@ -7,13 +9,13 @@ let nearestGroots = list{} let oppHeroes = list{0} let huntGrootCondition = List.length(nearestGroots) > 0 && { - let x = List.filter(h => List.hd(nearestGroots) <= 1000, oppHeroes) + let x = oppHeroes->List.filter(h => List.headExn(nearestGroots) <= 1000) List.length(x) == 0 } let huntGrootCondition2 = List.length(nearestGroots) >= 0 || { - let x = List.filter(h => List.hd(nearestGroots) <= 1000, oppHeroes) + let x = oppHeroes->List.filter(h => List.headExn(nearestGroots) <= 1000) List.length(x) == 0 } diff --git a/jscomp/test/gpr_2614_test.js b/jscomp/test/gpr_2614_test.js index 81a8745f08..124002d319 100644 --- a/jscomp/test/gpr_2614_test.js +++ b/jscomp/test/gpr_2614_test.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); let v = { "Content-Type": 3, @@ -25,7 +25,7 @@ function h0(param) { hi: 2 }; if (partial_arg !== undefined) { - tmp["lo-x"] = Caml_option.valFromOption(partial_arg); + tmp["lo-x"] = Primitive_option.valFromOption(partial_arg); } return tmp; } @@ -41,7 +41,7 @@ let h2 = { function hh(x) { x["lo-x"] = "3"; - return Caml_option.undefined_to_opt(x["lo-x"]); + return Primitive_option.fromUndefined(x["lo-x"]); } function hh2(x) { diff --git a/jscomp/test/gpr_3154_test.js b/jscomp/test/gpr_3154_test.js index c0967f09a3..a2d5ca722a 100644 --- a/jscomp/test/gpr_3154_test.js +++ b/jscomp/test/gpr_3154_test.js @@ -3,7 +3,7 @@ let Mt = require("./mt.js"); let Js_dict = require("../../lib/js/js_dict.js"); -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); let suites = { contents: /* [] */0 @@ -27,7 +27,7 @@ d["foo"] = undefined; let match = Js_dict.get(d, "foo"); -if (match !== undefined && Caml_option.valFromOption(match) === undefined) { +if (match !== undefined && Primitive_option.valFromOption(match) === undefined) { b("File \"gpr_3154_test.res\", line 12, characters 20-27", true); } else { b("File \"gpr_3154_test.res\", line 13, characters 11-18", false); @@ -37,7 +37,7 @@ let d0 = {}; d0["foo"] = undefined; -eq("File \"gpr_3154_test.res\", line 20, characters 5-12", Js_dict.get(d0, "foo"), Caml_option.some(undefined)); +eq("File \"gpr_3154_test.res\", line 20, characters 5-12", Js_dict.get(d0, "foo"), Primitive_option.some(undefined)); Mt.from_pair_suites("Gpr_3154_test", suites.contents); diff --git a/jscomp/test/gpr_3566_drive_test.js b/jscomp/test/gpr_3566_drive_test.js index 8ed48f0e0f..0fbb9cedce 100644 --- a/jscomp/test/gpr_3566_drive_test.js +++ b/jscomp/test/gpr_3566_drive_test.js @@ -2,8 +2,8 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_option = require("../../lib/js/caml_option.js"); let Gpr_3566_test = require("./gpr_3566_test.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); let suites = { contents: /* [] */0 @@ -21,10 +21,10 @@ let H = Gpr_3566_test.Test({}); eq("File \"gpr_3566_drive_test.res\", line 7, characters 12-19", H.b, true); -let Caml_option$1 = {}; +let Caml_option = {}; function f(x) { - return Caml_option.some(x); + return Primitive_option.some(x); } Mt.from_pair_suites("gpr_3566_drive_test.res", suites.contents); @@ -33,6 +33,6 @@ exports.suites = suites; exports.test_id = test_id; exports.eq = eq; exports.H = H; -exports.Caml_option = Caml_option$1; +exports.Caml_option = Caml_option; exports.f = f; /* H Not a pure module */ diff --git a/jscomp/test/gpr_3566_test.js b/jscomp/test/gpr_3566_test.js index aab0570a8a..371c900f04 100644 --- a/jscomp/test/gpr_3566_test.js +++ b/jscomp/test/gpr_3566_test.js @@ -1,8 +1,8 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_obj = require("../../lib/js/caml_obj.js"); -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); function eq_A(x, y) { if (x.TAG === "A" && y.TAG === "A") { @@ -57,37 +57,37 @@ function f(i, y) { } function Test3($star) { - let f = Caml_obj.equal; - let Caml_obj$1 = {}; + let f = Primitive_object.equal; + let Caml_obj = {}; return { f: f, - Caml_obj: Caml_obj$1 + Caml_obj: Caml_obj }; } function Test4($star) { - let Caml_obj$1 = {}; - let f = Caml_obj.equal; + let Caml_obj = {}; + let f = Primitive_object.equal; return { - Caml_obj: Caml_obj$1, + Caml_obj: Caml_obj, f: f }; } function Test5($star) { - let f = x => Caml_option.some(x); - let Caml_option$1 = {}; + let f = x => Primitive_option.some(x); + let Caml_option = {}; return { f: f, - Caml_option: Caml_option$1 + Caml_option: Caml_option }; } function Test6($star) { - let Caml_option$1 = {}; - let f = x => Caml_option.some(x); + let Caml_option = {}; + let f = x => Primitive_option.some(x); return { - Caml_option: Caml_option$1, + Caml_option: Caml_option, f: f }; } diff --git a/jscomp/test/gpr_3697_test.js b/jscomp/test/gpr_3697_test.js index c2bae67104..574c6a4087 100644 --- a/jscomp/test/gpr_3697_test.js +++ b/jscomp/test/gpr_3697_test.js @@ -1,19 +1,19 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let CamlinternalLazy = require("../../lib/js/camlinternalLazy.js"); +let Lazy = require("../../lib/js/lazy.js"); function fix() { return { TAG: "Fix", - _0: CamlinternalLazy.from_fun(() => fix()) + _0: Lazy.from_fun(fix) }; } function unfixLeak(_f) { while (true) { let f = _f; - _f = CamlinternalLazy.force(f._0); + _f = Lazy.force(f._0); continue; }; } @@ -21,7 +21,7 @@ function unfixLeak(_f) { function unfix(p) { while (true) { let h = p.contents; - p.contents = CamlinternalLazy.force(h._0); + p.contents = Lazy.force(h._0); }; } diff --git a/jscomp/test/gpr_3697_test.res b/jscomp/test/gpr_3697_test.res index 0c11967c4d..22ff1d684e 100644 --- a/jscomp/test/gpr_3697_test.res +++ b/jscomp/test/gpr_3697_test.res @@ -1,4 +1,4 @@ -type rec t<'a> = Fix(lazy_t>) +type rec t<'a> = Fix(Lazy.t>) let rec fix = () => Fix(Lazy.from_fun(fix)) diff --git a/jscomp/test/gpr_3770_test.js b/jscomp/test/gpr_3770_test.js index 6c9bf03c73..57b77c7a3d 100644 --- a/jscomp/test/gpr_3770_test.js +++ b/jscomp/test/gpr_3770_test.js @@ -7,7 +7,7 @@ function show(x) { if (a === 0 && x._1 === 0 && x._2 === 0) { return "zeroes"; } - return String(a) + String(x._1); + return a.toString() + x._1.toString(); } exports.show = show; diff --git a/jscomp/test/gpr_3770_test.res b/jscomp/test/gpr_3770_test.res index 095a00d651..ed085bc046 100644 --- a/jscomp/test/gpr_3770_test.res +++ b/jscomp/test/gpr_3770_test.res @@ -3,5 +3,5 @@ type t = Foo(int, int, int) let show = x => switch x { | Foo(0, 0, 0) => "zeroes" - | Foo(a, b, _) => string_of_int(a) ++ string_of_int(b) + | Foo(a, b, _) => Js.Int.toString(a) ++ Js.Int.toString(b) } diff --git a/jscomp/test/gpr_3931_test.js b/jscomp/test/gpr_3931_test.js index cba2beac9b..d5a9083bbe 100644 --- a/jscomp/test/gpr_3931_test.js +++ b/jscomp/test/gpr_3931_test.js @@ -1,10 +1,10 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let $$Array = require("../../lib/js/array.js"); -let Caml_module = require("../../lib/js/caml_module.js"); +let Belt_Array = require("../../lib/js/belt_Array.js"); +let Primitive_module = require("../../lib/js/primitive_module.js"); -let PA = Caml_module.init_mod([ +let PA = Primitive_module.init([ "gpr_3931_test.res", 3, 4 @@ -16,7 +16,7 @@ let PA = Caml_module.init_mod([ ]] }); -let P = Caml_module.init_mod([ +let P = Primitive_module.init([ "gpr_3931_test.res", 12, 4 @@ -29,10 +29,10 @@ let P = Caml_module.init_mod([ }); function print(a) { - $$Array.iter(P.print, a); + Belt_Array.forEach(a, P.print); } -Caml_module.update_mod({ +Primitive_module.update({ TAG: "Module", _0: [[ "Function", @@ -43,10 +43,10 @@ Caml_module.update_mod({ }); function print$1(i) { - console.log(String(i)); + console.log("%d", i); } -Caml_module.update_mod({ +Primitive_module.update({ TAG: "Module", _0: [[ "Function", diff --git a/jscomp/test/gpr_3931_test.res b/jscomp/test/gpr_3931_test.res index 80ce54c134..a18788f197 100644 --- a/jscomp/test/gpr_3931_test.res +++ b/jscomp/test/gpr_3931_test.res @@ -3,14 +3,14 @@ module rec PA: { } = { /* let () = P.print 3 */ let print = { - let iter = Array.iter(P.print, ...) + let iter = Belt.Array.forEach(_, P.print) a => iter(a) } } and P: { let print: int => unit } = { - let print = i => print_endline(string_of_int(i)) + let print = i => Js.log2("%d", i) } let () = PA.print([1, 2]) diff --git a/jscomp/test/gpr_4025_test.res b/jscomp/test/gpr_4025_test.res index c87d546f17..0981bff720 100644 --- a/jscomp/test/gpr_4025_test.res +++ b/jscomp/test/gpr_4025_test.res @@ -3,7 +3,7 @@ type u = {mutable x: int} {x: 3}.x = { - print_endline("hi") + Js.log("hi") 2 } @@ -12,7 +12,7 @@ let f = x => {x: x}.x = x + 1 let f = x => { x: { - print_endline("hi") + Js.log("hi") x }, }.x = x + 1 diff --git a/jscomp/test/gpr_405_test.js b/jscomp/test/gpr_405_test.js deleted file mode 100644 index 07aa61fba2..0000000000 --- a/jscomp/test/gpr_405_test.js +++ /dev/null @@ -1,122 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Caml = require("../../lib/js/caml.js"); -let Hashtbl = require("../../lib/js/hashtbl.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); - -function Make(funarg) { - let $$let = funarg.V; - let H = Hashtbl.Make({ - equal: $$let.equal, - hash: $$let.hash - }); - let find_default = (htbl, x) => { - try { - return H.find(htbl, x); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - return false; - } - throw exn; - } - }; - let min_cutset = (gr, first_node) => { - let n_labels = H.create(97); - let l_labels = H.create(97); - let already_processed = H.create(97); - let on_the_stack = H.create(97); - let cut_set = { - contents: /* [] */0 - }; - let counter = { - contents: 1 - }; - let step2 = (top, rest_of_stack) => { - if (find_default(already_processed, top)) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "gpr_405_test.res", - 40, - 6 - ], - Error: new Error() - }; - } - if (find_default(on_the_stack, top)) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "gpr_405_test.res", - 41, - 6 - ], - Error: new Error() - }; - } - H.add(on_the_stack, top, true); - H.add(n_labels, top, counter.contents); - counter.contents = counter.contents + 1 | 0; - H.add(l_labels, top, 0); - H.add(already_processed, top, true); - let _successors = funarg.succ(gr, top); - let _top = top; - let _rest_of_stack = rest_of_stack; - while (true) { - let rest_of_stack$1 = _rest_of_stack; - let top$1 = _top; - let successors = _successors; - if (successors) { - let successor = successors.hd; - if (!find_default(already_processed, successor)) { - return step2(successor, { - hd: [ - top$1, - successors - ], - tl: rest_of_stack$1 - }); - } - let x = find_default(on_the_stack, successor) ? H.find(n_labels, successor) : H.find(l_labels, successor); - H.add(l_labels, top$1, Caml.int_max(H.find(l_labels, top$1), x)); - _successors = successors.tl; - continue; - } - if (H.find(l_labels, top$1) === H.find(n_labels, top$1)) { - cut_set.contents = { - hd: top$1, - tl: cut_set.contents - }; - H.add(l_labels, top$1, 0); - } - if (H.find(l_labels, top$1) > H.find(n_labels, top$1)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Graph.Mincut: graph not reducible", - Error: new Error() - }; - } - if (!rest_of_stack$1) { - return cut_set.contents; - } - let match = rest_of_stack$1.hd; - let new_top = match[0]; - H.add(on_the_stack, top$1, false); - H.add(l_labels, new_top, Caml.int_max(H.find(l_labels, top$1), H.find(l_labels, new_top))); - _rest_of_stack = rest_of_stack$1.tl; - _top = new_top; - _successors = match[1]; - continue; - }; - }; - return step2(first_node, /* [] */0); - }; - return { - min_cutset: min_cutset - }; -} - -exports.Make = Make; -/* No side effect */ diff --git a/jscomp/test/gpr_405_test.res b/jscomp/test/gpr_405_test.res deleted file mode 100644 index f779235afd..0000000000 --- a/jscomp/test/gpr_405_test.res +++ /dev/null @@ -1,94 +0,0 @@ -module type G = { - type t - module V: { - /*** Vertices are {!COMPARABLE}. */ - - type t - - let compare: (t, t) => int - let hash: t => int - let equal: (t, t) => bool - - type label - let create: label => t - let label: t => label - } - let succ: (t, V.t) => list -} - -module Make = (G: G) => { - module H = Hashtbl.Make(G.V) - - let find_default = (htbl, x) => - try H.find(htbl, x) catch { - | Not_found => false - } - - let min_cutset = (gr, first_node) => { - let n_labels = H.create(97) - let l_labels = H.create(97) - - let already_processed = H.create(97) - let is_already_processed = x => find_default(already_processed, x) - - let on_the_stack = H.create(97) - let is_on_the_stack = x => find_default(on_the_stack, x) - let cut_set = ref(list{}) - let counter = ref(1) - - let rec step2 = (top, rest_of_stack) => { - assert(!is_already_processed(top)) - assert(!is_on_the_stack(top)) - H.add(on_the_stack, top, true) - H.add(n_labels, top, counter.contents) - counter := counter.contents + 1 - H.add(l_labels, top, 0) - H.add(already_processed, top, true) - step3(G.succ(gr, top), top, rest_of_stack) - } - - and step3 = (successors, top, rest_of_stack) => - switch successors { - | list{successor, ...other_successors} => - if !is_already_processed(successor) { - /* step 4 */ - step2(successor, list{(top, successors), ...rest_of_stack}) - } else { - /* step 5 */ - - let x = if is_on_the_stack(successor) { - H.find(n_labels, successor) - } else { - H.find(l_labels, successor) - } - - H.add(l_labels, top, max(H.find(l_labels, top), x)) - step3(other_successors, top, rest_of_stack) - } - - | list{} => - /* step 7 */ - if H.find(l_labels, top) == H.find(n_labels, top) { - cut_set := list{top, ...cut_set.contents} - H.add(l_labels, top, 0) - } - - /* check added between algorithms C and D */ - if H.find(l_labels, top) > H.find(n_labels, top) { - raise(Invalid_argument("Graph.Mincut: graph not reducible")) - } else { - /* step 8 */ - switch rest_of_stack { - | list{} => cut_set.contents /* SUCCESS */ - | list{(new_top, new_successors), ...new_tail} => - H.add(on_the_stack, top, false) - H.add(l_labels, new_top, max(H.find(l_labels, top), H.find(l_labels, new_top))) - step3(new_successors, new_top, new_tail) - } - } - } - - /* step 2 */ - step2(first_node, list{}) - } -} diff --git a/jscomp/test/gpr_405_test.resi b/jscomp/test/gpr_405_test.resi deleted file mode 100644 index 9167fc839c..0000000000 --- a/jscomp/test/gpr_405_test.resi +++ /dev/null @@ -1,22 +0,0 @@ -module type G = { - type t - module V: { - /*** Vertices are {!COMPARABLE}. */ - - type t - - let compare: (t, t) => int - let hash: t => int - let equal: (t, t) => bool - - type label - let create: label => t - let label: t => label - } - let succ: (t, V.t) => list -} - -module Make: (G: G) => -{ - let min_cutset: (G.t, G.V.t) => list -} diff --git a/jscomp/test/gpr_459_test.js b/jscomp/test/gpr_459_test.js index c43d1267f6..26b66b39e2 100644 --- a/jscomp/test/gpr_459_test.js +++ b/jscomp/test/gpr_459_test.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -38,9 +38,9 @@ let uu2 = { let hh = uu["_'x"]; -eq("File \"gpr_459_test.res\", line 23, characters 12-19", hh, 3); +eq("File \"gpr_459_test.res\", line 26, characters 12-19", hh, 3); -eq("File \"gpr_459_test.res\", line 25, characters 12-19", [ +eq("File \"gpr_459_test.res\", line 28, characters 12-19", [ 1, 2, 3 diff --git a/jscomp/test/gpr_459_test.res b/jscomp/test/gpr_459_test.res index e4e51bda81..60e5826a68 100644 --- a/jscomp/test/gpr_459_test.res +++ b/jscomp/test/gpr_459_test.res @@ -5,7 +5,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let uu = { diff --git a/jscomp/test/gpr_904_test.js b/jscomp/test/gpr_904_test.js index 7f1380b73f..fab6f9fcb6 100644 --- a/jscomp/test/gpr_904_test.js +++ b/jscomp/test/gpr_904_test.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -46,12 +46,12 @@ function f(check) { } } -eq("File \"gpr_904_test.res\", line 16, characters 12-19", f({ +eq("File \"gpr_904_test.res\", line 19, characters 12-19", f({ x: true, y: false }), false); -eq("File \"gpr_904_test.res\", line 18, characters 12-19", check_healty({ +eq("File \"gpr_904_test.res\", line 21, characters 12-19", check_healty({ a: false, b: false, c: true diff --git a/jscomp/test/gpr_904_test.res b/jscomp/test/gpr_904_test.res index fcf72b15e1..65f58fcc37 100644 --- a/jscomp/test/gpr_904_test.res +++ b/jscomp/test/gpr_904_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let check_healty = check => !check["a"] && (!check["b"] && !check["c"]) diff --git a/jscomp/test/gpr_974_test.js b/jscomp/test/gpr_974_test.js index 97b799e72a..c3f79db781 100644 --- a/jscomp/test/gpr_974_test.js +++ b/jscomp/test/gpr_974_test.js @@ -1,10 +1,10 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_obj = require("../../lib/js/caml_obj.js"); -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); -if (!Caml_obj.equal(Caml_option.nullable_to_opt(""), "")) { +if (!Primitive_object.equal(Primitive_option.fromNullable(""), "")) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -16,7 +16,7 @@ if (!Caml_obj.equal(Caml_option.nullable_to_opt(""), "")) { }; } -if (!Caml_obj.equal(Caml_option.undefined_to_opt(""), "")) { +if (!Primitive_object.equal(Primitive_option.fromUndefined(""), "")) { throw { RE_EXN_ID: "Assert_failure", _1: [ @@ -28,7 +28,7 @@ if (!Caml_obj.equal(Caml_option.undefined_to_opt(""), "")) { }; } -if (!Caml_obj.equal(Caml_option.null_to_opt(""), "")) { +if (!Primitive_object.equal(Primitive_option.fromNull(""), "")) { throw { RE_EXN_ID: "Assert_failure", _1: [ diff --git a/jscomp/test/gpr_977_test.js b/jscomp/test/gpr_977_test.js index aa765405f2..dfbbb13700 100644 --- a/jscomp/test/gpr_977_test.js +++ b/jscomp/test/gpr_977_test.js @@ -2,7 +2,6 @@ 'use strict'; let Mt = require("./mt.js"); -let Int32 = require("../../lib/js/int32.js"); let suites = { contents: /* [] */0 @@ -16,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -34,18 +33,9 @@ function f(x) { return -x | 0; } -function int32_f(x) { - for (let i = 0; i <= 100; ++i) { - console.log("."); - } - return -x | 0; -} - let u = f(-2147483648); -eq("File \"gpr_977_test.res\", line 33, characters 5-12", -2147483648, u); - -eq("File \"gpr_977_test.res\", line 34, characters 5-12", Int32.min_int, int32_f(Int32.min_int)); +eq("File \"gpr_977_test.res\", line 23, characters 5-12", -2147483648, u); Mt.from_pair_suites("Gpr_977_test", suites.contents); @@ -55,7 +45,6 @@ exports.suites = suites; exports.test_id = test_id; exports.eq = eq; exports.f = f; -exports.int32_f = int32_f; exports.min_32_int = min_32_int; exports.u = u; /* u Not a pure module */ diff --git a/jscomp/test/gpr_977_test.res b/jscomp/test/gpr_977_test.res index 882fe3690e..836e650425 100644 --- a/jscomp/test/gpr_977_test.res +++ b/jscomp/test/gpr_977_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let f = x => { @@ -13,25 +16,10 @@ let f = x => { -x } -let int32_f = x => { - for i in 0 to 100 { - Js.log(".") /* prevent optimization */ - } - Int32.neg(x) -} - -/* let nint32_f x = - for i = 0 to 100 do - Js.log "." ; (* prevent optimization*) - done; - Nativeint.neg x */ - let min_32_int = -2147483648 let u = f(min_32_int) let () = { eq(__LOC__, min_32_int, u) - eq(__LOC__, Int32.min_int, int32_f(Int32.min_int)) } -/* eq __LOC__ (nint32_f (-2147483648n)) (2147483648n) */ let () = Mt.from_pair_suites(__MODULE__, suites.contents) diff --git a/jscomp/test/gray_code_test.js b/jscomp/test/gray_code_test.js index 1e3a14edcd..a07c7bb844 100644 --- a/jscomp/test/gray_code_test.js +++ b/jscomp/test/gray_code_test.js @@ -1,8 +1,6 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Bytes = require("../../lib/js/bytes.js"); -let Caml_bytes = require("../../lib/js/caml_bytes.js"); function gray_encode(b) { return b ^ (b >>> 1); @@ -23,25 +21,6 @@ function gray_decode(n) { }; } -function bool_string(len, n) { - let s = Bytes.make(len, /* '0' */48); - let _i = len - 1 | 0; - let _n = n; - while (true) { - let n$1 = _n; - let i = _i; - if ((n$1 & 1) === 1) { - Caml_bytes.set(s, i, /* '1' */49); - } - if (i <= 0) { - return s; - } - _n = (n$1 >>> 1); - _i = i - 1 | 0; - continue; - }; -} - function next_power(v) { let v$1 = v - 1 | 0; let v$2 = (v$1 >>> 1) | v$1; @@ -54,6 +33,5 @@ function next_power(v) { exports.gray_encode = gray_encode; exports.gray_decode = gray_decode; -exports.bool_string = bool_string; exports.next_power = next_power; /* No side effect */ diff --git a/jscomp/test/gray_code_test.res b/jscomp/test/gray_code_test.res index 8131da4345..6f7fa87576 100644 --- a/jscomp/test/gray_code_test.res +++ b/jscomp/test/gray_code_test.res @@ -11,22 +11,6 @@ let gray_decode = n => { aux(n, lsr(n, 1)) } -let bool_string = (len, n) => { - let s = Bytes.make(len, '0') - let rec aux = (i, n) => { - if land(n, 1) == 1 { - Bytes.set(s, i, '1') - } - if i <= 0 { - s - } else { - aux(pred(i), lsr(n, 1)) - } - } - - aux(pred(len), n) -} - let next_power = v => { let v = v - 1 let v = lor(lsr(v, 1), v) diff --git a/jscomp/test/hash_test.js b/jscomp/test/hash_test.js index aebfabff04..e5aab10f8b 100644 --- a/jscomp/test/hash_test.js +++ b/jscomp/test/hash_test.js @@ -2,11 +2,9 @@ 'use strict'; let Mt = require("./mt.js"); -let Char = require("../../lib/js/char.js"); -let $$Array = require("../../lib/js/array.js"); let Hashtbl = require("../../lib/js/hashtbl.js"); let Mt_global = require("./mt_global.js"); -let Caml_string = require("../../lib/js/caml_string.js"); +let Belt_Array = require("../../lib/js/belt_Array.js"); let suites = { contents: /* [] */0 @@ -20,7 +18,7 @@ function eq(f, x, y) { Mt_global.collect_eq(test_id, suites, f, x, y); } -let test_strings = $$Array.init(32, i => Caml_string.make(i, Char.chr(i))); +let test_strings = Belt_Array.init(32, i => String.fromCodePoint(i).repeat(i)); let test_strings_hash_results = [ 0, @@ -65,13 +63,13 @@ function caml_hash(x) { return Hashtbl.hash(x) & 1073741823; } -eq("File \"hash_test.res\", line 44, characters 12-19", $$Array.map(caml_hash, test_strings), test_strings_hash_results); +eq("File \"hash_test.res\", line 46, characters 12-19", Belt_Array.map(test_strings, caml_hash), test_strings_hash_results); -eq("File \"hash_test.res\", line 46, characters 12-19", Hashtbl.hash(0) & 1073741823, 129913994); +eq("File \"hash_test.res\", line 48, characters 12-19", Hashtbl.hash(0) & 1073741823, 129913994); -eq("File \"hash_test.res\", line 48, characters 12-19", Hashtbl.hash("x") & 1073741823, 780510073); +eq("File \"hash_test.res\", line 50, characters 12-19", Hashtbl.hash("x") & 1073741823, 780510073); -eq("File \"hash_test.res\", line 50, characters 12-19", Hashtbl.hash("xy") & 1073741823, 194127723); +eq("File \"hash_test.res\", line 52, characters 12-19", Hashtbl.hash("xy") & 1073741823, 194127723); Mt.from_pair_suites("Hash_test", suites.contents); diff --git a/jscomp/test/hash_test.res b/jscomp/test/hash_test.res index 8771d12a7c..ba578bbb28 100644 --- a/jscomp/test/hash_test.res +++ b/jscomp/test/hash_test.res @@ -1,8 +1,10 @@ +open Belt + let suites: ref = ref(list{}) let test_id = ref(0) let eq = (f, x, y) => Mt_global.collect_eq(test_id, suites, f, x, y) -let test_strings = Array.init(32, i => String.make(i, Char.chr(i))) +let test_strings = Array.init(32, i => Js.String2.fromCodePoint(i)->Js.String2.repeat(i)) let test_strings_hash_results = [ 0, @@ -41,7 +43,7 @@ let test_strings_hash_results = [ let normalize = x => land(x, 0x3FFFFFFF) let caml_hash = x => normalize(Hashtbl.hash(x)) -let () = eq(__LOC__, Array.map(caml_hash, test_strings), test_strings_hash_results) +let () = eq(__LOC__, test_strings->Array.map(caml_hash), test_strings_hash_results) let () = eq(__LOC__, normalize(Hashtbl.hash(0)), 129913994) diff --git a/jscomp/test/hashtbl_test.js b/jscomp/test/hashtbl_test.js deleted file mode 100644 index a4b95c66f8..0000000000 --- a/jscomp/test/hashtbl_test.js +++ /dev/null @@ -1,102 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let Caml = require("../../lib/js/caml.js"); -let List = require("../../lib/js/list.js"); -let $$Array = require("../../lib/js/array.js"); -let Hashtbl = require("../../lib/js/hashtbl.js"); -let MoreLabels = require("../../lib/js/moreLabels.js"); - -function to_list(tbl) { - return Hashtbl.fold((k, v, acc) => ({ - hd: [ - k, - v - ], - tl: acc - }), tbl, /* [] */0); -} - -function f() { - let tbl = Hashtbl.create(undefined, 17); - Hashtbl.add(tbl, 1, /* '1' */49); - Hashtbl.add(tbl, 2, /* '2' */50); - let extra = to_list(tbl); - return List.sort((param, param$1) => Caml.int_compare(param[0], param$1[0]), extra); -} - -function g(count) { - let tbl = Hashtbl.create(undefined, 17); - for (let i = 0; i <= count; ++i) { - Hashtbl.replace(tbl, (i << 1), String(i)); - } - for (let i$1 = 0; i$1 <= count; ++i$1) { - Hashtbl.replace(tbl, (i$1 << 1), String(i$1)); - } - let v = to_list(tbl); - return $$Array.of_list(List.sort((param, param$1) => Caml.int_compare(param[0], param$1[0]), v)); -} - -let suites_0 = [ - "simple", - param => ({ - TAG: "Eq", - _0: { - hd: [ - 1, - /* '1' */49 - ], - tl: { - hd: [ - 2, - /* '2' */50 - ], - tl: /* [] */0 - } - }, - _1: f() - }) -]; - -let suites_1 = { - hd: [ - "more_iterations", - param => ({ - TAG: "Eq", - _0: $$Array.init(1001, i => [ - (i << 1), - String(i) - ]), - _1: g(1000) - }) - ], - tl: { - hd: [ - "More_labels_regressionfix_374", - param => { - let tbl = MoreLabels.Hashtbl.create(undefined, 30); - Hashtbl.add(tbl, 3, 3); - return { - TAG: "Eq", - _0: tbl.size, - _1: 1 - }; - } - ], - tl: /* [] */0 - } -}; - -let suites = { - hd: suites_0, - tl: suites_1 -}; - -Mt.from_pair_suites("Hashtbl_test", suites); - -exports.to_list = to_list; -exports.f = f; -exports.g = g; -exports.suites = suites; -/* Not a pure module */ diff --git a/jscomp/test/hashtbl_test.res b/jscomp/test/hashtbl_test.res deleted file mode 100644 index bb18f6015a..0000000000 --- a/jscomp/test/hashtbl_test.res +++ /dev/null @@ -1,47 +0,0 @@ -open Hashtbl - -let to_list = tbl => fold((k, v, acc) => list{(k, v), ...acc}, tbl, list{}) - -let f = () => { - let tbl = Hashtbl.create(17) - add(tbl, 1, '1') - add(tbl, 2, '2') - \"@@"(List.sort(((a: int, _), (b, _)) => compare(a, b), ...), to_list(tbl)) -} - -let g = count => { - let tbl = Hashtbl.create(17) - for i in 0 to count { - replace(tbl, i * 2, string_of_int(i)) - } - for i in 0 to count { - replace(tbl, i * 2, string_of_int(i)) - } - let v = to_list(tbl) - let v = \"@@"(List.sort(((x, _), (y: int, _)) => compare(x, y), ...), v) - Array.of_list(v) -} - -let suites = { - open Mt - list{ - ("simple", _ => Eq(list{(1, '1'), (2, '2')}, f())), - ( - "more_iterations", - _ => { - let count = 1000 - Eq(Array.init(count + 1, i => (2 * i, string_of_int(i))), g(count)) - }, - ), - ( - "More_labels_regressionfix_374", - _ => { - let tbl: Hashtbl.t = MoreLabels.Hashtbl.create(30) - Hashtbl.add(tbl, 3, 3) - Eq(Hashtbl.length(tbl), 1) - }, - ), - } -} - -Mt.from_pair_suites(__MODULE__, suites) diff --git a/jscomp/test/hello_res.js b/jscomp/test/hello_res.js index ee2ced30c1..1f2f16ad5a 100644 --- a/jscomp/test/hello_res.js +++ b/jscomp/test/hello_res.js @@ -1,9 +1,9 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); -let b = List.length({ +let b = Belt_List.length({ hd: 1, tl: { hd: 2, @@ -18,7 +18,7 @@ let a = b - 1 | 0; console.log("hello, res"); -List.length({ +Belt_List.length({ hd: 1, tl: { hd: 2, diff --git a/jscomp/test/hello_res.res b/jscomp/test/hello_res.res index e1e7fc96bb..040bdfaf48 100644 --- a/jscomp/test/hello_res.res +++ b/jscomp/test/hello_res.res @@ -4,6 +4,8 @@ ], }) +open Belt + let b = List.length(list{1, 2, 3}) let a = b - 1 Js.log("hello, res") @@ -17,13 +19,13 @@ let u: t = {"x": 3} let h = u["x"] -%%private(let {length, cons} = module(List)) +%%private(let {length, add} = module(List)) -%%private(let {length, cons} = module(List)) +%%private(let {length, add} = module(List)) %%private(let (a, b) = (1, 2)) -let {length: len, cons: c} = module(List) +let {length: len, add: c} = module(List) module H = { module H1 = { @@ -31,8 +33,8 @@ module H = { } } let u = { - let {length: l, cons} = module(List) - cons(l(list{1, 2, 3}), list{}) + let {length: l, add} = module(List) + list{}->add(l(list{1, 2, 3})) } let h = { diff --git a/jscomp/test/ignore_test.js b/jscomp/test/ignore_test.js index dc2915a59f..26b2a6a3d9 100644 --- a/jscomp/test/ignore_test.js +++ b/jscomp/test/ignore_test.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -34,7 +34,7 @@ function ff(x) { console.log(x); } -eq("File \"ignore_test.res\", line 13, characters 12-19", undefined, undefined); +eq("File \"ignore_test.res\", line 16, characters 12-19", undefined, undefined); Mt.from_pair_suites("Ignore_test", suites.contents); diff --git a/jscomp/test/ignore_test.res b/jscomp/test/ignore_test.res index f93bb61683..d4354e5a27 100644 --- a/jscomp/test/ignore_test.res +++ b/jscomp/test/ignore_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let f = x => ignore(x) diff --git a/jscomp/test/inline_const.res b/jscomp/test/inline_const.res index d7c9e42cba..e1e770c219 100644 --- a/jscomp/test/inline_const.res +++ b/jscomp/test/inline_const.res @@ -34,11 +34,4 @@ let (a, b, c, d, e) = (f, f1, f2, f3, f4) @inline let f6 = 1 -@inline let f7 = 1L - -@inline let f9 = 100L - -@inline let v = 100L -@inline let u = 1L - let () = Js.log((xx, xx0)) diff --git a/jscomp/test/inline_const.resi b/jscomp/test/inline_const.resi index c6d16dfea1..e1698148a6 100644 --- a/jscomp/test/inline_const.resi +++ b/jscomp/test/inline_const.resi @@ -22,8 +22,3 @@ let hh: string @inline(true) let f5: bool @inline(1) let f6: int - -/* val f7 : bool [@@inline 1L] */ - -@inline(100L) let v: int64 -@inline(1L) let u: int64 diff --git a/jscomp/test/inline_const_test.js b/jscomp/test/inline_const_test.js index 7170b94e74..62db03c4f0 100644 --- a/jscomp/test/inline_const_test.js +++ b/jscomp/test/inline_const_test.js @@ -2,8 +2,6 @@ 'use strict'; let Mt = require("./mt.js"); -let Int64 = require("../../lib/js/int64.js"); -let Caml_int64 = require("../../lib/js/caml_int64.js"); let Inline_const = require("./inline_const.js"); let suites = { @@ -46,12 +44,7 @@ eq("File \"inline_const_test.res\", line 19, characters 5-12", 1, 1); eq("File \"inline_const_test.res\", line 20, characters 5-12", 3e-6, 0.000003); -let h = Caml_int64.add(Caml_int64.add([ - 0, - 100 -], Int64.one), Caml_int64.one); - -Mt.from_pair_suites("File \"inline_const_test.res\", line 28, characters 29-36", suites.contents); +Mt.from_pair_suites("File \"inline_const_test.res\", line 23, characters 29-36", suites.contents); let f5 = true; @@ -71,5 +64,4 @@ exports.f4 = f4; exports.f5 = f5; exports.f6 = f6; exports.f7 = f7; -exports.h = h; /* Not a pure module */ diff --git a/jscomp/test/inline_const_test.res b/jscomp/test/inline_const_test.res index 64ca4c3579..1addffbd37 100644 --- a/jscomp/test/inline_const_test.res +++ b/jscomp/test/inline_const_test.res @@ -20,9 +20,4 @@ let () = { eq(__LOC__, f7, 0.000003) } -let h = { - open Inline_const - Int64.add(Int64.add(v, Int64.one), u) -} - let () = Mt.from_pair_suites(__LOC__, suites.contents) diff --git a/jscomp/test/inline_map2_test.js b/jscomp/test/inline_map2_test.js index 663e15c663..f144e15067 100644 --- a/jscomp/test/inline_map2_test.js +++ b/jscomp/test/inline_map2_test.js @@ -2,9 +2,10 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml = require("../../lib/js/caml.js"); -let List = require("../../lib/js/list.js"); -let Caml_option = require("../../lib/js/caml_option.js"); +let Belt_List = require("../../lib/js/belt_List.js"); +let Primitive_int = require("../../lib/js/primitive_int.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); +let Primitive_string = require("../../lib/js/primitive_string.js"); function Make(Ord) { let height = x => { @@ -376,7 +377,7 @@ function Make(Ord) { }; let concat_or_join = (t1, v, d, t2) => { if (d !== undefined) { - return join(t1, v, Caml_option.valFromOption(d), t2); + return join(t1, v, Primitive_option.valFromOption(d), t2); } else { return concat(t1, t2); } @@ -397,7 +398,7 @@ function Make(Ord) { if (c === 0) { return [ l, - Caml_option.some(d), + Primitive_option.some(d), r ]; } @@ -426,7 +427,7 @@ function Make(Ord) { let v1 = s1._1; if (s1._4 >= height(s2)) { let match = split(v1, s2); - return concat_or_join(merge(f, s1._0, match[0]), v1, f(v1, Caml_option.some(s1._2), match[1]), merge(f, s1._3, match[2])); + return concat_or_join(merge(f, s1._0, match[0]), v1, f(v1, Primitive_option.some(s1._2), match[1]), merge(f, s1._3, match[2])); } } @@ -443,7 +444,7 @@ function Make(Ord) { } let v2 = s2._1; let match$1 = split(v2, s1); - return concat_or_join(merge(f, match$1[0], s2._0), v2, f(v2, match$1[1], Caml_option.some(s2._2)), merge(f, match$1[2], s2._3)); + return concat_or_join(merge(f, match$1[0], s2._0), v2, f(v2, match$1[1], Primitive_option.some(s2._2)), merge(f, match$1[2], s2._3)); }; let filter = (p, x) => { if (typeof x !== "object") { @@ -745,7 +746,7 @@ function add(x, data, x_) { let d = x_._2; let v = x_._1; let l = x_._0; - let c = Caml.int_compare(x, v); + let c = Primitive_int.compare(x, v); if (c === 0) { return { TAG: "Node", @@ -771,7 +772,7 @@ function find(x, _x_) { Error: new Error() }; } - let c = Caml.int_compare(x, x_._1); + let c = Primitive_int.compare(x, x_._1); if (c === 0) { return x_._2; } @@ -786,7 +787,7 @@ function mem(x, _x_) { if (typeof x_ !== "object") { return false; } - let c = Caml.int_compare(x, x_._1); + let c = Primitive_int.compare(x, x_._1); if (c === 0) { return true; } @@ -861,7 +862,7 @@ function remove(x, x_) { let d = x_._2; let v = x_._1; let l = x_._0; - let c = Caml.int_compare(x, v); + let c = Primitive_int.compare(x, v); if (c === 0) { if (typeof l !== "object") { return r; @@ -1020,7 +1021,7 @@ function concat(t1, t2) { function concat_or_join(t1, v, d, t2) { if (d !== undefined) { - return join(t1, v, Caml_option.valFromOption(d), t2); + return join(t1, v, Primitive_option.valFromOption(d), t2); } else { return concat(t1, t2); } @@ -1038,11 +1039,11 @@ function split(x, x_) { let d = x_._2; let v = x_._1; let l = x_._0; - let c = Caml.int_compare(x, v); + let c = Primitive_int.compare(x, v); if (c === 0) { return [ l, - Caml_option.some(d), + Primitive_option.some(d), r ]; } @@ -1072,7 +1073,7 @@ function merge(f, s1, s2) { let v1 = s1._1; if (s1._4 >= height(s2)) { let match = split(v1, s2); - return concat_or_join(merge(f, s1._0, match[0]), v1, f(v1, Caml_option.some(s1._2), match[1]), merge(f, s1._3, match[2])); + return concat_or_join(merge(f, s1._0, match[0]), v1, f(v1, Primitive_option.some(s1._2), match[1]), merge(f, s1._3, match[2])); } } @@ -1089,7 +1090,7 @@ function merge(f, s1, s2) { } let v2 = s2._1; let match$1 = split(v2, s1); - return concat_or_join(merge(f, match$1[0], s2._0), v2, f(v2, match$1[1], Caml_option.some(s2._2)), merge(f, match$1[2], s2._3)); + return concat_or_join(merge(f, match$1[0], s2._0), v2, f(v2, match$1[1], Primitive_option.some(s2._2)), merge(f, match$1[2], s2._3)); } function filter(p, x) { @@ -1172,7 +1173,7 @@ function compare(cmp, m1, m2) { if (typeof e2 !== "object") { return 1; } - let c = Caml.int_compare(e1._0, e2._0); + let c = Primitive_int.compare(e1._0, e2._0); if (c !== 0) { return c; } @@ -1283,7 +1284,7 @@ let IntMap = { choose: min_binding }; -let m = List.fold_left((acc, param) => add(param[0], param[1], acc), "Empty", { +let m = Belt_List.reduceReverse({ hd: [ 10, /* 'a' */97 @@ -1307,7 +1308,7 @@ let m = List.fold_left((acc, param) => add(param[0], param[1], acc), "Empty", { } } } -}); +}, "Empty", (acc, param) => add(param[0], param[1], acc)); function height$1(x) { if (typeof x !== "object") { @@ -1427,7 +1428,7 @@ function add$1(x, data, x_) { let d = x_._2; let v = x_._1; let l = x_._0; - let c = Caml.string_compare(x, v); + let c = Primitive_string.compare(x, v); if (c === 0) { return { TAG: "Node", @@ -1453,7 +1454,7 @@ function find$1(x, _x_) { Error: new Error() }; } - let c = Caml.string_compare(x, x_._1); + let c = Primitive_string.compare(x, x_._1); if (c === 0) { return x_._2; } @@ -1468,7 +1469,7 @@ function mem$1(x, _x_) { if (typeof x_ !== "object") { return false; } - let c = Caml.string_compare(x, x_._1); + let c = Primitive_string.compare(x, x_._1); if (c === 0) { return true; } @@ -1543,7 +1544,7 @@ function remove$1(x, x_) { let d = x_._2; let v = x_._1; let l = x_._0; - let c = Caml.string_compare(x, v); + let c = Primitive_string.compare(x, v); if (c === 0) { if (typeof l !== "object") { return r; @@ -1702,7 +1703,7 @@ function concat$1(t1, t2) { function concat_or_join$1(t1, v, d, t2) { if (d !== undefined) { - return join$1(t1, v, Caml_option.valFromOption(d), t2); + return join$1(t1, v, Primitive_option.valFromOption(d), t2); } else { return concat$1(t1, t2); } @@ -1720,11 +1721,11 @@ function split$1(x, x_) { let d = x_._2; let v = x_._1; let l = x_._0; - let c = Caml.string_compare(x, v); + let c = Primitive_string.compare(x, v); if (c === 0) { return [ l, - Caml_option.some(d), + Primitive_option.some(d), r ]; } @@ -1754,7 +1755,7 @@ function merge$1(f, s1, s2) { let v1 = s1._1; if (s1._4 >= height$1(s2)) { let match = split$1(v1, s2); - return concat_or_join$1(merge$1(f, s1._0, match[0]), v1, f(v1, Caml_option.some(s1._2), match[1]), merge$1(f, s1._3, match[2])); + return concat_or_join$1(merge$1(f, s1._0, match[0]), v1, f(v1, Primitive_option.some(s1._2), match[1]), merge$1(f, s1._3, match[2])); } } @@ -1771,7 +1772,7 @@ function merge$1(f, s1, s2) { } let v2 = s2._1; let match$1 = split$1(v2, s1); - return concat_or_join$1(merge$1(f, match$1[0], s2._0), v2, f(v2, match$1[1], Caml_option.some(s2._2)), merge$1(f, match$1[2], s2._3)); + return concat_or_join$1(merge$1(f, match$1[0], s2._0), v2, f(v2, match$1[1], Primitive_option.some(s2._2)), merge$1(f, match$1[2], s2._3)); } function filter$1(p, x) { @@ -1854,7 +1855,7 @@ function compare$1(cmp, m1, m2) { if (typeof e2 !== "object") { return 1; } - let c = Caml.string_compare(e1._0, e2._0); + let c = Primitive_string.compare(e1._0, e2._0); if (c !== 0) { return c; } @@ -1884,7 +1885,7 @@ function equal$1(cmp, m1, m2) { if (typeof e2 !== "object") { return false; } - if (Caml.string_compare(e1._0, e2._0) !== 0) { + if (e1._0 !== e2._0) { return false; } if (!cmp(e1._1, e2._1)) { @@ -1965,7 +1966,7 @@ let SMap = { choose: min_binding$1 }; -let s = List.fold_left((acc, param) => add$1(param[0], param[1], acc), "Empty", { +let s = Belt_List.reduceReverse({ hd: [ "10", /* 'a' */97 @@ -1989,7 +1990,7 @@ let s = List.fold_left((acc, param) => add$1(param[0], param[1], acc), "Empty", } } } -}); +}, "Empty", (acc, param) => add$1(param[0], param[1], acc)); Mt.from_pair_suites("Inline_map2_test", { hd: [ diff --git a/jscomp/test/inline_map2_test.res b/jscomp/test/inline_map2_test.res index b9e0dcda19..ce07a4b912 100644 --- a/jscomp/test/inline_map2_test.res +++ b/jscomp/test/inline_map2_test.res @@ -455,21 +455,20 @@ module IntMap = Make({ let empty = IntMap.empty -let m = List.fold_left( - (acc, (k, v)) => IntMap.add(k, v, acc), - empty, - list{(10, 'a'), (3, 'b'), (7, 'c'), (20, 'd')}, -) +let m = Belt.List.reduceReverse(list{(10, 'a'), (3, 'b'), (7, 'c'), (20, 'd')}, empty, ( + acc, + (k, v), +) => IntMap.add(k, v, acc)) module SMap = Make({ type t = string let compare = (x: t, y) => compare(x, y) }) -let s = List.fold_left( - (acc, (k, v)) => SMap.add(k, v, acc), - SMap.empty, +let s = Belt.List.reduceReverse( list{("10", 'a'), ("3", 'b'), ("7", 'c'), ("20", 'd')}, + SMap.empty, + (acc, (k, v)) => SMap.add(k, v, acc), ) @val("console.log") external log: 'a => unit = "" diff --git a/jscomp/test/inline_map_demo.js b/jscomp/test/inline_map_demo.js index cfdd7e8fff..c966423eb6 100644 --- a/jscomp/test/inline_map_demo.js +++ b/jscomp/test/inline_map_demo.js @@ -2,8 +2,8 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml = require("../../lib/js/caml.js"); -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); +let Primitive_int = require("../../lib/js/primitive_int.js"); function height(x) { if (typeof x !== "object") { @@ -120,7 +120,7 @@ function add(x, data, tree) { let d = tree._2; let v = tree._1; let l = tree._0; - let c = Caml.int_compare(x, v); + let c = Primitive_int.compare(x, v); if (c === 0) { return { TAG: "Node", @@ -137,7 +137,7 @@ function add(x, data, tree) { } } -let m = List.fold_left((acc, param) => add(param[0], param[1], acc), "Empty", { +let m = Belt_List.reduceReverse({ hd: [ 10, /* 'a' */97 @@ -161,7 +161,7 @@ let m = List.fold_left((acc, param) => add(param[0], param[1], acc), "Empty", { } } } -}); +}, "Empty", (acc, param) => add(param[0], param[1], acc)); function find(px, _x) { while (true) { @@ -172,7 +172,7 @@ function find(px, _x) { Error: new Error() }; } - let c = Caml.int_compare(px, x._1); + let c = Primitive_int.compare(px, x._1); if (c === 0) { return x._2; } diff --git a/jscomp/test/inline_map_demo.res b/jscomp/test/inline_map_demo.res index 9360771940..78877b5bc3 100644 --- a/jscomp/test/inline_map_demo.res +++ b/jscomp/test/inline_map_demo.res @@ -111,11 +111,10 @@ let empty = Empty No assumption on the heights of l and r. */ /* end */ -let m = List.fold_left( - (acc, (k, v)) => add(k, v, acc), - empty, - list{(10, 'a'), (3, 'b'), (7, 'c'), (20, 'd')}, -) +let m = Belt.List.reduceReverse(list{(10, 'a'), (3, 'b'), (7, 'c'), (20, 'd')}, empty, ( + acc, + (k, v), +) => add(k, v, acc)) let rec find = (px, x) => switch x { diff --git a/jscomp/test/inline_map_test.js b/jscomp/test/inline_map_test.js index 2685f057f3..3dfa9a390e 100644 --- a/jscomp/test/inline_map_test.js +++ b/jscomp/test/inline_map_test.js @@ -2,8 +2,8 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml = require("../../lib/js/caml.js"); -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); +let Primitive_int = require("../../lib/js/primitive_int.js"); function height(x) { if (typeof x !== "object") { @@ -104,7 +104,7 @@ function add(x, data, x_) { let d = x_._2; let v = x_._1; let l = x_._0; - let c = Caml.int_compare(x, v); + let c = Primitive_int.compare(x, v); if (c === 0) { return { TAG: "Node", @@ -130,7 +130,7 @@ function find(x, _x_) { Error: new Error() }; } - let c = Caml.int_compare(x, x_._1); + let c = Primitive_int.compare(x, x_._1); if (c === 0) { return x_._2; } @@ -139,7 +139,7 @@ function find(x, _x_) { }; } -let m = List.fold_left((acc, param) => add(param[0], param[1], acc), "Empty", { +let m = Belt_List.reduceReverse({ hd: [ 10, /* 'a' */97 @@ -163,7 +163,7 @@ let m = List.fold_left((acc, param) => add(param[0], param[1], acc), "Empty", { } } } -}); +}, "Empty", (acc, param) => add(param[0], param[1], acc)); Mt.from_pair_suites("Inline_map_test", { hd: [ diff --git a/jscomp/test/inline_map_test.res b/jscomp/test/inline_map_test.res index 01368d7500..927babcfe3 100644 --- a/jscomp/test/inline_map_test.res +++ b/jscomp/test/inline_map_test.res @@ -405,11 +405,10 @@ let bindings = s => bindings_aux(list{}, s) let choose = min_binding /* end */ -let m = List.fold_left( - (acc, (k, v)) => add(k, v, acc), - empty, - list{(10, 'a'), (3, 'b'), (7, 'c'), (20, 'd')}, -) +let m = Belt.List.reduceReverse(list{(10, 'a'), (3, 'b'), (7, 'c'), (20, 'd')}, empty, ( + acc, + (k, v), +) => add(k, v, acc)) @val("console.log") external log: 'a => unit = "" diff --git a/jscomp/test/inline_record_test.js b/jscomp/test/inline_record_test.js index 9346f7a9f7..09e84b8a80 100644 --- a/jscomp/test/inline_record_test.js +++ b/jscomp/test/inline_record_test.js @@ -2,8 +2,8 @@ 'use strict'; let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); +let Belt_List = require("../../lib/js/belt_List.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); let suites = { contents: /* [] */0 @@ -36,9 +36,9 @@ let v1 = { function f(x) { if (x.TAG === "A0") { - return List.fold_left((prim0, prim1) => prim0 + prim1 | 0, x.lbl, x.more); + return Belt_List.reduceReverse(x.more, x.lbl, (prim0, prim1) => prim0 + prim1 | 0); } else { - return List.fold_left((prim0, prim1) => prim0 + prim1 | 0, 0, x.more); + return Belt_List.reduceReverse(x.more, 0, (prim0, prim1) => prim0 + prim1 | 0); } } @@ -50,7 +50,7 @@ console.log(f(v)); console.log(f(v1)); -let A0 = /* @__PURE__ */Caml_exceptions.create("Inline_record_test.A0"); +let A0 = /* @__PURE__ */Primitive_exceptions.create("Inline_record_test.A0"); let v3 = { RE_EXN_ID: A0, @@ -137,7 +137,7 @@ tmp$2 = v5.z; eq("File \"inline_record_test.res\", line 80, characters 2-9", tmp$2, 22); -let A4 = /* @__PURE__ */Caml_exceptions.create("Inline_record_test.A4"); +let A4 = /* @__PURE__ */Primitive_exceptions.create("Inline_record_test.A4"); let v6 = { RE_EXN_ID: A4, diff --git a/jscomp/test/inline_record_test.res b/jscomp/test/inline_record_test.res index cfc5b2430c..26e8a9d594 100644 --- a/jscomp/test/inline_record_test.res +++ b/jscomp/test/inline_record_test.res @@ -13,8 +13,8 @@ let v1 = A1({more: list{1, 2}}) let f = (x: t0) => switch x { - | A0({lbl, more}) => List.fold_left(\"+", lbl, more) - | A1({more}) => List.fold_left(\"+", 0, more) + | A0({lbl, more}) => more->Belt.List.reduceReverse(lbl, \"+") + | A1({more}) => more->Belt.List.reduceReverse(0, \"+") } eq(__LOC__, f(v), 3) eq(__LOC__, f(v1), 3) diff --git a/jscomp/test/inline_regression_test.js b/jscomp/test/inline_regression_test.js index a1ca7bdd55..60abed5b40 100644 --- a/jscomp/test/inline_regression_test.js +++ b/jscomp/test/inline_regression_test.js @@ -2,9 +2,6 @@ 'use strict'; let Mt = require("./mt.js"); -let $$String = require("../../lib/js/string.js"); -let Filename = require("../../lib/js/filename.js"); -let Caml_string = require("../../lib/js/caml_string.js"); function generic_basename(is_dir_sep, current_dir_name, name) { if (name === "") { @@ -14,7 +11,7 @@ function generic_basename(is_dir_sep, current_dir_name, name) { while (true) { let n = _n; if (n < 0) { - return $$String.sub(name, 0, 1); + return name.substr(0, 1); } if (!is_dir_sep(name, n)) { let _n$1 = n; @@ -22,10 +19,10 @@ function generic_basename(is_dir_sep, current_dir_name, name) { while (true) { let n$1 = _n$1; if (n$1 < 0) { - return $$String.sub(name, 0, p); + return name.substr(0, p); } if (is_dir_sep(name, n$1)) { - return $$String.sub(name, n$1 + 1 | 0, (p - n$1 | 0) - 1 | 0); + return name.substr(n$1 + 1 | 0, (p - n$1 | 0) - 1 | 0); } _n$1 = n$1 - 1 | 0; continue; @@ -38,7 +35,7 @@ function generic_basename(is_dir_sep, current_dir_name, name) { } function basename(extra) { - return generic_basename((s, i) => Caml_string.get(s, i) === /* '/' */47, Filename.current_dir_name, extra); + return generic_basename((s, i) => s.codePointAt(i) === /* '/' */47, "", extra); } let suites_0 = [ diff --git a/jscomp/test/inline_regression_test.res b/jscomp/test/inline_regression_test.res index 01aa7dd40d..4b197bf34b 100644 --- a/jscomp/test/inline_regression_test.res +++ b/jscomp/test/inline_regression_test.res @@ -1,7 +1,7 @@ let generic_basename = (is_dir_sep, current_dir_name, name) => { let rec find_end = n => if n < 0 { - String.sub(name, 0, 1) + Js.String2.substrAtMost(name, ~from=0, ~length=1) } else if is_dir_sep(name, n) { find_end(n - 1) } else { @@ -9,9 +9,9 @@ let generic_basename = (is_dir_sep, current_dir_name, name) => { } and find_beg = (n, p) => if n < 0 { - String.sub(name, 0, p) + Js.String2.substrAtMost(name, ~from=0, ~length=p) } else if is_dir_sep(name, n) { - String.sub(name, n + 1, p - n - 1) + Js.String2.substrAtMost(name, ~from=n + 1, ~length=p - n - 1) } else { find_beg(n - 1, p) } @@ -19,11 +19,11 @@ let generic_basename = (is_dir_sep, current_dir_name, name) => { if name == "" { current_dir_name } else { - find_end(String.length(name) - 1) + find_end(Js.String2.length(name) - 1) } } -let basename = generic_basename((s, i) => String.get(s, i) == '/', Filename.current_dir_name, ...) +let basename = generic_basename((s, i) => String.get(s, i) == '/', "", ...) let suites = { open Mt diff --git a/jscomp/test/inner_unused.js b/jscomp/test/inner_unused.js index 9f4fb403b8..b938658dc5 100644 --- a/jscomp/test/inner_unused.js +++ b/jscomp/test/inner_unused.js @@ -6,7 +6,7 @@ function f(x) { return x + 3 | 0; } -function M(S) { +function M(Id) { let f = x => x; return { f: f diff --git a/jscomp/test/inner_unused.res b/jscomp/test/inner_unused.res index 5c70a3aab0..75c8dfd985 100644 --- a/jscomp/test/inner_unused.res +++ b/jscomp/test/inner_unused.res @@ -7,7 +7,7 @@ let f = x => { x + 3 } -module M = (S: Set.S): { +module M = (Id: Belt.Id.Comparable): { let f: int => int } => { let f = x => x diff --git a/jscomp/test/installation_test.js b/jscomp/test/installation_test.js index 0c84e4c34b..17e63f6ae5 100644 --- a/jscomp/test/installation_test.js +++ b/jscomp/test/installation_test.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, diff --git a/jscomp/test/installation_test.res b/jscomp/test/installation_test.res index f404ebd2c5..ae96cb5b6a 100644 --- a/jscomp/test/installation_test.res +++ b/jscomp/test/installation_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let () = Mt.from_pair_suites(__MODULE__, suites.contents) diff --git a/jscomp/test/int32_test.js b/jscomp/test/int32_test.js deleted file mode 100644 index d22572f2f9..0000000000 --- a/jscomp/test/int32_test.js +++ /dev/null @@ -1,219 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let $$Array = require("../../lib/js/array.js"); -let Int32 = require("../../lib/js/int32.js"); -let Caml_float = require("../../lib/js/caml_float.js"); -let Pervasives = require("../../lib/js/pervasives.js"); -let Ext_array_test = require("./ext_array_test.js"); - -function f(x) { - return [ - x, - (x >>> 1), - (x >>> 2) - ]; -} - -let shift_right_logical_tests_0 = $$Array.map(x => (-1 >>> x) | 0, Ext_array_test.range(0, 31)); - -let shift_right_logical_tests_1 = [ - -1, - 2147483647, - 1073741823, - 536870911, - 268435455, - 134217727, - 67108863, - 33554431, - 16777215, - 8388607, - 4194303, - 2097151, - 1048575, - 524287, - 262143, - 131071, - 65535, - 32767, - 16383, - 8191, - 4095, - 2047, - 1023, - 511, - 255, - 127, - 63, - 31, - 15, - 7, - 3, - 1 -]; - -let shift_right_logical_tests = [ - shift_right_logical_tests_0, - shift_right_logical_tests_1 -]; - -let shift_right_tests_0 = $$Array.map(x => (Int32.min_int >> x), Ext_array_test.range(0, 31)); - -let shift_right_tests_1 = [ - -2147483648, - -1073741824, - -536870912, - -268435456, - -134217728, - -67108864, - -33554432, - -16777216, - -8388608, - -4194304, - -2097152, - -1048576, - -524288, - -262144, - -131072, - -65536, - -32768, - -16384, - -8192, - -4096, - -2048, - -1024, - -512, - -256, - -128, - -64, - -32, - -16, - -8, - -4, - -2, - -1 -]; - -let shift_right_tests = [ - shift_right_tests_0, - shift_right_tests_1 -]; - -let shift_left_tests_0 = $$Array.map(x => (1 << x), Ext_array_test.range(0, 31)); - -let shift_left_tests_1 = [ - 1, - 2, - 4, - 8, - 16, - 32, - 64, - 128, - 256, - 512, - 1024, - 2048, - 4096, - 8192, - 16384, - 32768, - 65536, - 131072, - 262144, - 524288, - 1048576, - 2097152, - 4194304, - 8388608, - 16777216, - 33554432, - 67108864, - 134217728, - 268435456, - 536870912, - 1073741824, - -2147483648 -]; - -let shift_left_tests = [ - shift_left_tests_0, - shift_left_tests_1 -]; - -function $star$tilde(prim0, prim1) { - return Math.imul(prim0, prim1); -} - -let suites = { - contents: Pervasives.$at({ - hd: [ - "File \"int32_test.res\", line 131, characters 9-16", - () => ({ - TAG: "Eq", - _0: 1, - _1: 1 - }) - ], - tl: { - hd: [ - "File \"int32_test.res\", line 132, characters 9-16", - () => ({ - TAG: "Eq", - _0: -2147483647, - _1: -2147483647 - }) - ], - tl: /* [] */0 - } - }, Pervasives.$at($$Array.to_list(Ext_array_test.map2i((i, a, b) => [ - "shift_right_logical_cases " + i, - () => ({ - TAG: "Eq", - _0: a, - _1: b - }) - ], shift_right_logical_tests_0, shift_right_logical_tests_1)), Pervasives.$at($$Array.to_list(Ext_array_test.map2i((i, a, b) => [ - "shift_right_cases " + i, - () => ({ - TAG: "Eq", - _0: a, - _1: b - }) - ], shift_right_tests_0, shift_right_tests_1)), $$Array.to_list(Ext_array_test.map2i((i, a, b) => [ - "shift_left_cases " + i, - () => ({ - TAG: "Eq", - _0: a, - _1: b - }) - ], shift_left_tests_0, shift_left_tests_1))))) -}; - -let test_id = { - contents: 0 -}; - -function eq(loc, x, y) { - Mt.eq_suites(test_id, suites, loc, x, y); -} - -eq("File \"int32_test.res\", line 176, characters 5-12", Caml_float.int_bits_of_float(0.3), 1050253722); - -eq("File \"int32_test.res\", line 177, characters 5-12", Caml_float.int_float_of_bits(1050253722), 0.300000011920928955); - -Mt.from_pair_suites("Int32_test", suites.contents); - -let test_div = 30; - -exports.f = f; -exports.shift_right_logical_tests = shift_right_logical_tests; -exports.shift_right_tests = shift_right_tests; -exports.shift_left_tests = shift_left_tests; -exports.test_div = test_div; -exports.$star$tilde = $star$tilde; -exports.suites = suites; -exports.test_id = test_id; -exports.eq = eq; -/* shift_right_logical_tests Not a pure module */ diff --git a/jscomp/test/int32_test.res b/jscomp/test/int32_test.res deleted file mode 100644 index 71380264a8..0000000000 --- a/jscomp/test/int32_test.res +++ /dev/null @@ -1,179 +0,0 @@ -let f = x => Int32.logor(Int32.logor(x, 0l), 0l) - -let f = x => ( - Int32.shift_right_logical(x, 0), - Int32.shift_right_logical(x, 1), - Int32.shift_right_logical(x, 2), -) - -let shift_right_logical_tests = ( - Array.map(x => Int32.shift_right_logical(-1l, x), Ext_array_test.range(0, 31)), - [ - -1l, - 2147483647l, - 1073741823l, - 536870911l, - 268435455l, - 134217727l, - 67108863l, - 33554431l, - 16777215l, - 8388607l, - 4194303l, - 2097151l, - 1048575l, - 524287l, - 262143l, - 131071l, - 65535l, - 32767l, - 16383l, - 8191l, - 4095l, - 2047l, - 1023l, - 511l, - 255l, - 127l, - 63l, - 31l, - 15l, - 7l, - 3l, - 1l, - ], -) - -let shift_right_tests = ( - Array.map(x => Int32.shift_right(Int32.min_int, x), Ext_array_test.range(0, 31)), - [ - -2147483648l, - -1073741824l, - -536870912l, - -268435456l, - -134217728l, - -67108864l, - -33554432l, - -16777216l, - -8388608l, - -4194304l, - -2097152l, - -1048576l, - -524288l, - -262144l, - -131072l, - -65536l, - -32768l, - -16384l, - -8192l, - -4096l, - -2048l, - -1024l, - -512l, - -256l, - -128l, - -64l, - -32l, - -16l, - -8l, - -4l, - -2l, - -1l, - ], -) - -let shift_left_tests = ( - Array.map(x => Int32.shift_left(1l, x), Ext_array_test.range(0, 31)), - [ - 1l, - 2l, - 4l, - 8l, - 16l, - 32l, - 64l, - 128l, - 256l, - 512l, - 1024l, - 2048l, - 4096l, - 8192l, - 16384l, - 32768l, - 65536l, - 131072l, - 262144l, - 524288l, - 1048576l, - 2097152l, - 4194304l, - 8388608l, - 16777216l, - 33554432l, - 67108864l, - 134217728l, - 268435456l, - 536870912l, - 1073741824l, - -2147483648l, - ], -) - -let test_div = 61 / 2 - -let \"*~" = Int32.mul -let suites = ref( - \"@"( - { - open Mt - list{ - (__LOC__, _ => Eq(\"*~"(0xffff_ffffl, 0xffff_ffffl), 1l)), - (__LOC__, _ => Eq(\"*~"(0xffff_ffffl, 0x7fff_ffffl), -2147483647l)), - } - }, - \"@"( - { - let (a, b) = shift_right_logical_tests - Array.to_list( - Ext_array_test.map2i( - (i, a, b) => ("shift_right_logical_cases " ++ __unsafe_cast(i), _ => Mt.Eq(a, b)), - a, - b, - ), - ) - }, - \"@"( - { - let (a, b) = shift_right_tests - Array.to_list( - Ext_array_test.map2i( - (i, a, b) => ("shift_right_cases " ++ __unsafe_cast(i), _ => Mt.Eq(a, b)), - a, - b, - ), - ) - }, - { - let (a, b) = shift_left_tests - Array.to_list( - Ext_array_test.map2i( - (i, a, b) => ("shift_left_cases " ++ __unsafe_cast(i), _ => Mt.Eq(a, b)), - a, - b, - ), - ) - }, - ), - ), - ), -) - -let test_id = ref(0) -let eq = (loc, x, y) => Mt.eq_suites(~test_id, ~suites, loc, x, y) - -let () = { - eq(__LOC__, Int32.bits_of_float(0.3), 1050253722l) - eq(__LOC__, Int32.float_of_bits(1050253722l), 0.300000011920928955) -} -Mt.from_pair_suites(__MODULE__, suites.contents) diff --git a/jscomp/test/int64_mul_div_test.js b/jscomp/test/int64_mul_div_test.js deleted file mode 100644 index ffb2920e65..0000000000 --- a/jscomp/test/int64_mul_div_test.js +++ /dev/null @@ -1,1672 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); -let $$Array = require("../../lib/js/array.js"); -let Int64 = require("../../lib/js/int64.js"); -let Caml_int64 = require("../../lib/js/caml_int64.js"); -let Pervasives = require("../../lib/js/pervasives.js"); - -function commutative_mul(result, a, b) { - return { - TAG: "Eq", - _0: [ - result, - result - ], - _1: [ - Caml_int64.mul(a, b), - Caml_int64.mul(b, a) - ] - }; -} - -let pairs = [ - [ - [ - -1482940033, - 2541785568 - ], - [ - 1831202545, - 525340320 - ], - [ - 165328154, - 634982515 - ] - ], - [ - [ - 2086642202, - 4249709544 - ], - [ - 1756378018, - 3051843660 - ], - [ - 1129387921, - 4132619358 - ] - ], - [ - [ - -2133087767, - 1358520104 - ], - [ - 209351581, - 3480263932 - ], - [ - 2047885301, - 2699186102 - ] - ], - [ - [ - 781938191, - 3733162556 - ], - [ - 1243995318, - 3630533041 - ], - [ - 965315102, - 2542797052 - ] - ], - [ - [ - -1526298485, - 3121533040 - ], - [ - 806837349, - 4053728232 - ], - [ - 973509509, - 2421939110 - ] - ], - [ - [ - -1053250751, - 2477426938 - ], - [ - 297218479, - 3467715454 - ], - [ - 1353404045, - 1639039171 - ] - ], - [ - [ - -1614556777, - 1100802137 - ], - [ - 1812737275, - 732603925 - ], - [ - 1686007471, - 1587408437 - ] - ], - [ - [ - 166521361, - 3339161296 - ], - [ - 585926665, - 2485045435 - ], - [ - 1193284387, - 2883446640 - ] - ], - [ - [ - -1556851713, - 2199030589 - ], - [ - 563693579, - 3317959669 - ], - [ - 1423006973, - 700349737 - ] - ], - [ - [ - 2096650716, - 2212704850 - ], - [ - 1413202597, - 4019257153 - ], - [ - 495794945, - 3451719634 - ] - ], - [ - [ - 1149398987, - 1313884544 - ], - [ - 556147957, - 255480485 - ], - [ - 1711350082, - 929852288 - ] - ], - [ - [ - 908394614, - 2507458775 - ], - [ - 1053216964, - 725956947 - ], - [ - 2145390454, - 3984887277 - ] - ], - [ - [ - 962684198, - 1441406688 - ], - [ - 1528894622, - 468792198 - ], - [ - 1893431833, - 3919858640 - ] - ], - [ - [ - -603570361, - 3328354720 - ], - [ - 1842921977, - 1999781536 - ], - [ - 1854314037, - 3255494393 - ] - ], - [ - [ - 1827458543, - 1187405920 - ], - [ - 1066436782, - 2505967328 - ], - [ - 1004254249, - 2020291989 - ] - ], - [ - [ - -1818789533, - 1878451246 - ], - [ - 247021097, - 1999625579 - ], - [ - 1434621550, - 2370451978 - ] - ], - [ - [ - 1714915951, - 2103538455 - ], - [ - 1071186049, - 45872671 - ], - [ - 911777108, - 2638787593 - ] - ], - [ - [ - 365880810, - 3950734524 - ], - [ - 1215123423, - 1477626470 - ], - [ - 1155052099, - 1816687658 - ] - ], - [ - [ - -1590309406, - 1713682280 - ], - [ - 1236324221, - 2330256524 - ], - [ - 871497139, - 1538765150 - ] - ], - [ - [ - -1335640207, - 1074580892 - ], - [ - 153491040, - 2295578284 - ], - [ - 469100620, - 1001897781 - ] - ] -]; - -function from_pairs(prefix, pairs) { - return $$Array.to_list($$Array.mapi((i, param) => { - let b = param[2]; - let a = param[1]; - let result = param[0]; - return [ - prefix + "_" + i, - param => commutative_mul(result, a, b) - ]; - }, pairs)); -} - -let small_pairs = [ - [ - [ - 0, - 121 - ], - [ - 0, - 11 - ], - [ - 0, - 11 - ] - ], - [ - [ - 0, - 126736 - ], - [ - 0, - 356 - ], - [ - 0, - 356 - ] - ], - [ - [ - 0, - 137176406 - ], - [ - 0, - 12346 - ], - [ - 0, - 11111 - ] - ], - [ - [ - 268435455, - 4293918720 - ], - [ - 255, - 4294967295 - ], - [ - 0, - 1048576 - ] - ], - [ - [ - -268435456, - 1048576 - ], - [ - -256, - 1 - ], - [ - 0, - 1048576 - ] - ], - [ - [ - -639559543, - 1275262484 - ], - [ - 1209011959, - 3147693253 - ], - [ - 1831626934, - 242558724 - ] - ] -]; - -let to_floats = [ - [ - Caml_int64.one, - 1 - ], - [ - [ - 0, - 2 - ], - 2 - ], - [ - [ - 0, - 4 - ], - 4 - ], - [ - [ - 0, - 8 - ], - 8 - ], - [ - [ - 0, - 16 - ], - 16 - ], - [ - [ - 0, - 32 - ], - 32 - ], - [ - [ - 0, - 64 - ], - 64 - ], - [ - [ - 0, - 128 - ], - 128 - ], - [ - [ - 0, - 256 - ], - 256 - ], - [ - [ - 0, - 512 - ], - 512 - ], - [ - [ - 0, - 1024 - ], - 1024 - ], - [ - [ - 0, - 2048 - ], - 2048 - ], - [ - [ - 0, - 4096 - ], - 4096 - ], - [ - [ - 0, - 8192 - ], - 8192 - ], - [ - [ - 0, - 16384 - ], - 16384 - ], - [ - [ - 0, - 32768 - ], - 32768 - ], - [ - [ - 0, - 65536 - ], - 65536 - ], - [ - [ - 0, - 131072 - ], - 131072 - ], - [ - [ - 0, - 262144 - ], - 262144 - ], - [ - [ - 0, - 524288 - ], - 524288 - ], - [ - [ - 0, - 1048576 - ], - 1048576 - ], - [ - [ - 0, - 2097152 - ], - 2097152 - ], - [ - [ - 0, - 4194304 - ], - 4194304 - ], - [ - [ - 0, - 8388608 - ], - 8388608 - ], - [ - [ - 0, - 16777216 - ], - 16777216 - ], - [ - [ - 0, - 33554432 - ], - 33554432 - ], - [ - [ - 0, - 67108864 - ], - 67108864 - ], - [ - [ - 0, - 134217728 - ], - 134217728 - ], - [ - [ - 0, - 268435456 - ], - 268435456 - ], - [ - [ - 0, - 536870912 - ], - 536870912 - ], - [ - [ - 0, - 1073741824 - ], - 1073741824 - ], - [ - [ - 0, - 2147483648 - ], - 2147483648 - ], - [ - [ - 1, - 0 - ], - 4294967296 - ], - [ - [ - 2, - 0 - ], - 8589934592 - ], - [ - [ - 4, - 0 - ], - 17179869184 - ], - [ - [ - 8, - 0 - ], - 34359738368 - ], - [ - [ - 16, - 0 - ], - 68719476736 - ], - [ - [ - 32, - 0 - ], - 137438953472 - ], - [ - [ - 64, - 0 - ], - 274877906944 - ], - [ - [ - 128, - 0 - ], - 549755813888 - ], - [ - [ - 256, - 0 - ], - 1099511627776 - ], - [ - [ - 512, - 0 - ], - 2199023255552 - ], - [ - [ - 1024, - 0 - ], - 4398046511104 - ], - [ - [ - 2048, - 0 - ], - 8796093022208 - ], - [ - [ - 4096, - 0 - ], - 17592186044416 - ], - [ - [ - 8192, - 0 - ], - 35184372088832 - ], - [ - [ - 16384, - 0 - ], - 70368744177664 - ], - [ - [ - 32768, - 0 - ], - 140737488355328 - ], - [ - [ - 65536, - 0 - ], - 281474976710656 - ], - [ - [ - 131072, - 0 - ], - 562949953421312 - ], - [ - [ - 262144, - 0 - ], - 1125899906842624 - ], - [ - [ - 524288, - 0 - ], - 2251799813685248 - ], - [ - [ - 1048576, - 0 - ], - 4503599627370496 - ], - [ - [ - 2097152, - 0 - ], - 9007199254740992 - ], - [ - [ - 4194304, - 0 - ], - 18014398509481984 - ], - [ - [ - 8388608, - 0 - ], - 36028797018963968 - ], - [ - [ - 16777216, - 0 - ], - 72057594037927936 - ], - [ - [ - 33554432, - 0 - ], - 144115188075855872 - ], - [ - [ - 67108864, - 0 - ], - 288230376151711744 - ], - [ - [ - 134217728, - 0 - ], - 576460752303423488 - ], - [ - [ - 268435456, - 0 - ], - 1.15292150460684698e+18 - ], - [ - [ - 536870912, - 0 - ], - 2.30584300921369395e+18 - ], - [ - [ - 1073741824, - 0 - ], - 4.6116860184273879e+18 - ], - [ - Caml_int64.min_int, - -9.22337203685477581e+18 - ] -]; - -let check_complete_compare = [ - true, - true, - true, - true, - true, - true, - true, - true -]; - -let of_float_pairs = [ - [ - 6853066956871844, - [ - 1595603, - 4254472356 - ] - ], - [ - -8507688874782117, - [ - -1980851, - 1388466779 - ] - ], - [ - 4083117349607451, - [ - 950674, - 3610449947 - ] - ], - [ - -4860723193745655, - [ - -1131726, - 2964287241 - ] - ], - [ - 7820020192255542, - [ - 1820740, - 1437736502 - ] - ], - [ - -4908619721514532, - [ - -1142878, - 3911803356 - ] - ], - [ - 5.67685864687671e+15, - [ - 1321746, - 2803257894 - ] - ], - [ - -703696191048023, - [ - -163843, - 4135630505 - ] - ], - [ - 1123586534990153.88, - [ - 261605, - 1615520073 - ] - ], - [ - -4.29886533981922e+15, - [ - -1000908, - 1786485548 - ] - ], - [ - 2.43885138012066e+15, - [ - 567839, - 1445727316 - ] - ], - [ - -8011538689499494, - [ - -1865332, - 1246682778 - ] - ], - [ - 2710072285421155, - [ - 630987, - 3756220003 - ] - ], - [ - -2541457347159789.5, - [ - -591730, - 3650902291 - ] - ], - [ - 5012932793576708, - [ - 1167164, - 1584508164 - ] - ], - [ - -943066847413899.125, - [ - -219575, - 596605301 - ] - ], - [ - 5440257518642004, - [ - 1266658, - 2833425236 - ] - ], - [ - -7750676773453898, - [ - -1804596, - 4029038518 - ] - ], - [ - 8911999221747713, - [ - 2074986, - 2212089857 - ] - ], - [ - -1443906702582204.25, - [ - -336186, - 1172790852 - ] - ], - [ - 659345820712164.875, - [ - 153515, - 3916266724 - ] - ], - [ - -3284023713149006.5, - [ - -764622, - 2770653106 - ] - ], - [ - 5062818438579988, - [ - 1178779, - 1184368404 - ] - ], - [ - -8904450004162331, - [ - -2073229, - 747956453 - ] - ], - [ - 848261089308786, - [ - 197501, - 753381490 - ] - ], - [ - -6376579516657391, - [ - -1484664, - 3808891153 - ] - ], - [ - 1337907592605664.25, - [ - 311505, - 3805065184 - ] - ], - [ - -8.54733738833896e+15, - [ - -1990083, - 4012986608 - ] - ], - [ - 2345417644172927, - [ - 546085, - 428336767 - ] - ], - [ - -2587460670129294.5, - [ - -602441, - 3722640242 - ] - ], - [ - 4580431718597436, - [ - 1066464, - 3716236092 - ] - ], - [ - -1460576044874256.25, - [ - -340067, - 598574576 - ] - ], - [ - 3403657978343579.5, - [ - 792475, - 3770445979 - ] - ], - [ - -7.89068917321888e+15, - [ - -1837195, - 3268155840 - ] - ], - [ - 1683098350604788.5, - [ - 391876, - 3746517492 - ] - ], - [ - -3966538891560174.5, - [ - -923532, - 845249298 - ] - ], - [ - 6726025288963652, - [ - 1566024, - 3424212548 - ] - ], - [ - -4790410747298403, - [ - -1115355, - 2501131677 - ] - ], - [ - 1985858071337706.25, - [ - 462368, - 2632620778 - ] - ], - [ - -5281733497873409, - [ - -1229750, - 2534382591 - ] - ] -]; - -let simple_divs = [ - [ - [ - 0, - 6 - ], - [ - 0, - 3 - ], - [ - 0, - 2 - ], - Caml_int64.zero - ], - [ - [ - 0, - 120 - ], - [ - 0, - 11 - ], - [ - 0, - 10 - ], - [ - 0, - 10 - ] - ], - [ - Caml_int64.min_int, - [ - 0, - 2 - ], - [ - -1073741824, - 0 - ], - Caml_int64.zero - ], - [ - [ - 1112580415, - 4131866785 - ], - [ - 2013350321, - 2605406679 - ], - Caml_int64.zero, - [ - 1112580415, - 4131866785 - ] - ], - [ - [ - 983582600, - 1414064366 - ], - [ - 1027627185, - 720592487 - ], - Caml_int64.zero, - [ - 983582600, - 1414064366 - ] - ], - [ - [ - 707587463, - 4050792578 - ], - [ - 457824592, - 2852982217 - ], - Caml_int64.one, - [ - 249762871, - 1197810361 - ] - ], - [ - [ - 3696312, - 3842956494 - ], - [ - 303263066, - 1932508180 - ], - Caml_int64.zero, - [ - 3696312, - 3842956494 - ] - ], - [ - [ - 1998955230, - 530108890 - ], - [ - 1876081138, - 2994715702 - ], - Caml_int64.one, - [ - 122874091, - 1830360484 - ] - ], - [ - [ - 1123314058, - 2451991450 - ], - [ - 1077511003, - 2658013162 - ], - Caml_int64.one, - [ - 45803054, - 4088945584 - ] - ], - [ - [ - 772515434, - 3820835012 - ], - [ - 1485983210, - 435807891 - ], - Caml_int64.zero, - [ - 772515434, - 3820835012 - ] - ], - [ - [ - 1437309318, - 1357533220 - ], - [ - 1141241105, - 541080542 - ], - Caml_int64.one, - [ - 296068213, - 816452678 - ] - ], - [ - [ - 1559319564, - 407118687 - ], - [ - 211092740, - 4014353660 - ], - [ - 0, - 7 - ], - [ - 81670377, - 2371414139 - ] - ], - [ - [ - 897058469, - 1054256000 - ], - [ - 57853316, - 661312616 - ], - [ - 0, - 15 - ], - [ - 29258726, - 4019468648 - ] - ], - [ - [ - 1771820319, - 3029842884 - ], - [ - 1113086871, - 222584391 - ], - Caml_int64.one, - [ - 658733448, - 2807258493 - ] - ], - [ - [ - 1699471447, - 2730544778 - ], - [ - 1090632987, - 3896573910 - ], - Caml_int64.one, - [ - 608838459, - 3128938164 - ] - ], - [ - [ - 1300122432, - 837406327 - ], - [ - 349961722, - 3861260410 - ], - [ - 0, - 3 - ], - [ - 250237263, - 2138526985 - ] - ], - [ - [ - 1844919629, - 681013979 - ], - [ - 141654602, - 3894038038 - ], - [ - 0, - 13 - ], - [ - 3409791, - 1598127037 - ] - ], - [ - [ - 876561860, - 3227349399 - ], - [ - 1635137811, - 1118648885 - ], - Caml_int64.zero, - [ - 876561860, - 3227349399 - ] - ], - [ - [ - 1444234022, - 1188873919 - ], - [ - 1506775353, - 2449062589 - ], - Caml_int64.zero, - [ - 1444234022, - 1188873919 - ] - ], - [ - [ - 216713133, - 2955981804 - ], - [ - 840978153, - 478170254 - ], - Caml_int64.zero, - [ - 216713133, - 2955981804 - ] - ], - [ - [ - 311131250, - 2343706662 - ], - [ - 1432032601, - 1397060596 - ], - Caml_int64.zero, - [ - 311131250, - 2343706662 - ] - ], - [ - [ - 702252958, - 2254774319 - ], - [ - 333531300, - 1983179783 - ], - [ - 0, - 2 - ], - [ - 35190357, - 2583382049 - ] - ], - [ - [ - 222120797, - 1357843095 - ], - [ - 1409050141, - 2550433032 - ], - Caml_int64.zero, - [ - 222120797, - 1357843095 - ] - ] -]; - -function from(xs) { - return List.mapi((i, param) => { - let d = param[3]; - let c = param[2]; - let b = param[1]; - let a = param[0]; - return [ - "small_divs " + i, - param => ({ - TAG: "Eq", - _0: [ - c, - d - ], - _1: [ - Caml_int64.div(a, b), - Caml_int64.mod_(a, b) - ] - }) - ]; - }, $$Array.to_list(xs)); -} - -let to_string = [[ - Caml_int64.zero, - "0" - ]]; - -let int64_compare_tests = [ - [ - Caml_int64.one, - [ - 0, - 2 - ], - -1 - ], - [ - [ - 0, - 2 - ], - Caml_int64.one, - 1 - ], - [ - [ - 0, - 2 - ], - Caml_int64.one, - 1 - ] -]; - -function from_compare(xs) { - return List.mapi((i, param) => { - let c = param[2]; - let b = param[1]; - let a = param[0]; - return [ - "int64_compare " + i, - param => ({ - TAG: "Eq", - _0: c, - _1: Caml_int64.compare(a, b) - }) - ]; - }, $$Array.to_list(xs)); -} - -function from_to_string(xs) { - return List.mapi((i, param) => { - let str_a = param[1]; - let a = param[0]; - return [ - "to_string " + i, - param => ({ - TAG: "Eq", - _0: str_a, - _1: Caml_int64.to_string(a) - }) - ]; - }, $$Array.to_list(xs)); -} - -Mt.from_pair_suites("Int64_mul_div_test", Pervasives.$at(from_pairs("random", pairs), Pervasives.$at(from_pairs("small", small_pairs), Pervasives.$at(List.mapi((i, param) => { - let f = param[1]; - let i64 = param[0]; - return [ - "to_float_" + i, - () => ({ - TAG: "Eq", - _0: Caml_int64.to_float(i64), - _1: f - }) - ]; -}, $$Array.to_list(to_floats)), Pervasives.$at(List.mapi((i, param) => { - let i64 = param[1]; - let f = param[0]; - return [ - "of_float_" + i, - () => ({ - TAG: "Eq", - _0: Caml_int64.of_float(f), - _1: i64 - }) - ]; -}, $$Array.to_list(of_float_pairs)), Pervasives.$at({ - hd: [ - "compare_check_complete", - () => ({ - TAG: "Eq", - _0: $$Array.map(param => true, check_complete_compare), - _1: check_complete_compare - }) - ], - tl: /* [] */0 -}, Pervasives.$at(from(simple_divs), Pervasives.$at(from_compare(int64_compare_tests), { - hd: [ - "div_rem_0", - () => ({ - TAG: "Eq", - _0: Caml_int64.zero, - _1: Caml_int64.zero - }) - ], - tl: { - hd: [ - "div_rem_1", - () => ({ - TAG: "Eq", - _0: Caml_int64.neg_one, - _1: Caml_int64.neg_one - }) - ], - tl: { - hd: [ - "File \"int64_mul_div_test.res\", line 256, characters 19-26", - () => ({ - TAG: "Eq", - _0: Caml_int64.to_float(Int64.max_int), - _1: 9.22337203685477581e+18 - }) - ], - tl: /* [] */0 - } - } -})))))))); - -exports.commutative_mul = commutative_mul; -exports.pairs = pairs; -exports.from_pairs = from_pairs; -exports.small_pairs = small_pairs; -exports.to_floats = to_floats; -exports.check_complete_compare = check_complete_compare; -exports.of_float_pairs = of_float_pairs; -exports.simple_divs = simple_divs; -exports.from = from; -exports.to_string = to_string; -exports.int64_compare_tests = int64_compare_tests; -exports.from_compare = from_compare; -exports.from_to_string = from_to_string; -/* Not a pure module */ diff --git a/jscomp/test/int64_mul_div_test.res b/jscomp/test/int64_mul_div_test.res deleted file mode 100644 index cc8e914b65..0000000000 --- a/jscomp/test/int64_mul_div_test.res +++ /dev/null @@ -1,282 +0,0 @@ -open Int64 - -let commutative_mul = (result, a, b) => Mt.Eq((result, result), (mul(a, b), mul(b, a))) - -let pairs = [ - (-6369178941122375200L, 7864955043652308640L, 710079015173034099L), - (8962060020293135336L, 7543586149775142988L, 4850684189325050974L), - (-9161542197404147928L, 899158197241158908L, 8795600396453302198L), - (3358398961571564092L, 5342919210817653169L, 4145996795967701244L), - (-6555402073887813520L, 3465340031200066536L, 4181191505921956774L), - (-4523677527555012358L, 1276543650539578238L, 5812826113188151491L), - (-6934468553649362855L, 7785647313097762325L, 7241346950344076853L), - (715203802919571152L, 2516535866514393275L, 5125117419875854192L), - (-6686627189857547459L, 2421045490088152053L, 6111768411715304745L), - (9005046258567688786L, 6069658940756524865L, 2129423077748838354L), - (4936631060534413696L, 2388637287307694757L, 7350192635126770560L), - (3901525161500002519L, 4523532416698366291L, 9214381841065479661L), - (4134697148227395296L, 6566552400989074310L, 8132227803860192208L), - (-2592314958001559136L, 7915289622294445728L, 7964218148684228345L), - (7848874678168215648L, 4580311104447448800L, 4313239158344332693L), - (-7811641560663661522L, 1060947535036669291L, 6161652641757280778L), - (7365507927037276951L, 4600709048432326175L, 3916052862740247561L), - (1571446117134724284L, 5218915363866200678L, 4960910992197841962L), - (-6830326887577503896L, 5309972098777932940L, 3743051712101331294L), - (-5736531007213089380L, 659238999324606124L, 2014771822435221301L), -] - -let from_pairs = (prefix, pairs) => - \"@@"( - Array.to_list, - Array.mapi( - (i, (result, a, b)) => ( - "" ++ prefix ++ "_" ++ __unsafe_cast(i), - _ => commutative_mul(result, a, b), - ), - pairs, - ), - ) - -let small_pairs = [ - (121L, 11L, 11L), - (126736L, 356L, 356L), - (137176406L, 12346L, 11111L), - (0xffff_ffff_ff_00000L, 0xffff_ffff_ffL, 0x1_00000L), - (-0xffff_ffff_ff_00000L, -0xffff_ffff_ffL, 0x1_00000L), - (0xd9e118894c02f614L, 0x4_8100_ef7b_b9df_cc5L, 0x6d2c_68b6_0e75_2704L), -] - -let to_floats = [ - (1L, 1.), - (2L, 2.), - (4L, 4.), - (8L, 8.), - (16L, 16.), - (32L, 32.), - (64L, 64.), - (128L, 128.), - (256L, 256.), - (512L, 512.), - (1024L, 1024.), - (2048L, 2048.), - (4096L, 4096.), - (8192L, 8192.), - (16384L, 16384.), - (32768L, 32768.), - (65536L, 65536.), - (131072L, 131072.), - (262144L, 262144.), - (524288L, 524288.), - (1048576L, 1048576.), - (2097152L, 2097152.), - (4194304L, 4194304.), - (8388608L, 8388608.), - (16777216L, 16777216.), - (33554432L, 33554432.), - (67108864L, 67108864.), - (134217728L, 134217728.), - (268435456L, 268435456.), - (536870912L, 536870912.), - (1073741824L, 1073741824.), - (2147483648L, 2147483648.), - (4294967296L, 4294967296.), - (8589934592L, 8589934592.), - (17179869184L, 17179869184.), - (34359738368L, 34359738368.), - (68719476736L, 68719476736.), - (137438953472L, 137438953472.), - (274877906944L, 274877906944.), - (549755813888L, 549755813888.), - (1099511627776L, 1099511627776.), - (2199023255552L, 2199023255552.), - (4398046511104L, 4398046511104.), - (8796093022208L, 8796093022208.), - (17592186044416L, 17592186044416.), - (35184372088832L, 35184372088832.), - (70368744177664L, 70368744177664.), - (140737488355328L, 140737488355328.), - (281474976710656L, 281474976710656.), - (562949953421312L, 562949953421312.), - (1125899906842624L, 1125899906842624.), - (2251799813685248L, 2251799813685248.), - (4503599627370496L, 4503599627370496.), - (9007199254740992L, 9007199254740992.), - (18014398509481984L, 18014398509481984.), - (36028797018963968L, 36028797018963968.), - (72057594037927936L, 72057594037927936.), - (144115188075855872L, 144115188075855872.), - (288230376151711744L, 288230376151711744.), - (576460752303423488L, 576460752303423488.), - (1152921504606846976L, 1.15292150460684698e+18), - (2305843009213693952L, 2.30584300921369395e+18), - (4611686018427387904L, 4.6116860184273879e+18), - (-9223372036854775808L, -9.22337203685477581e+18), -] - -let check_complete_compare = [ - 3L >= 2L, - 3L >= 3L, - 3L == 3L, - 2L == 2L, - 2L < 3L, - 3L > 2L, - 2L <= 3L, - 3L <= 3L, -] -/* let f () = Random.float (2. ** 53. -. 1.);; */ -/* Array.init 40 (fun i -> let v = if i mod 2 = 0 then f () else -. f() in v, of_float v);; */ -let of_float_pairs = [ - (6853066956871844., 6853066956871844L), - (-8507688874782117., -8507688874782117L), - (4083117349607451., 4083117349607451L), - (-4860723193745655., -4860723193745655L), - (7820020192255542., 7820020192255542L), - (-4908619721514532., -4908619721514532L), - (5.67685864687671e+15, 5676858646876710L), - (-703696191048023., -703696191048023L), - (1123586534990153.88, 1123586534990153L), - (-4.29886533981922e+15, -4298865339819220L), - (2.43885138012066e+15, 2438851380120660L), - (-8011538689499494., -8011538689499494L), - (2710072285421155., 2710072285421155L), - (-2541457347159789.5, -2541457347159789L), - (5012932793576708., 5012932793576708L), - (-943066847413899.125, -943066847413899L), - (5440257518642004., 5440257518642004L), - (-7750676773453898., -7750676773453898L), - (8911999221747713., 8911999221747713L), - (-1443906702582204.25, -1443906702582204L), - (659345820712164.875, 659345820712164L), - (-3284023713149006.5, -3284023713149006L), - (5062818438579988., 5062818438579988L), - (-8904450004162331., -8904450004162331L), - (848261089308786., 848261089308786L), - (-6376579516657391., -6376579516657391L), - (1337907592605664.25, 1337907592605664L), - (-8.54733738833896e+15, -8547337388338960L), - (2345417644172927., 2345417644172927L), - (-2587460670129294.5, -2587460670129294L), - (4580431718597436., 4580431718597436L), - (-1460576044874256.25, -1460576044874256L), - (3403657978343579.5, 3403657978343579L), - (-7.89068917321888e+15, -7890689173218880L), - (1683098350604788.5, 1683098350604788L), - (-3966538891560174.5, -3966538891560174L), - (6726025288963652., 6726025288963652L), - (-4790410747298403., -4790410747298403L), - (1985858071337706.25, 1985858071337706L), - (-5281733497873409., -5281733497873409L), -] - -let simple_divs = [ - (6L, 3L, 2L, 0L), - (120L, 11L, 10L, 10L), - (-9223372036854775808L, 2L, -4611686018427387904L, 0L), - /* (-9223372036854775808L, 1L, -9223372036854775808L, 0L); */ - /* (-9223372036854775808L, -1L, -9223372036854775808L, 0L); */ - - (4778496500726974625L, 8647273786691508695L, 0L, 4778496500726974625L), - (4224455101328713966L, 4413625152776134247L, 0L, 4224455101328713966L), - (3039065016695402626L, 1966341652797525449L, 1L, 1072723363897877177L), - (15875542998768846L, 1302504952487197716L, 0L, 15875542998768846L), - (8585447339548266970L, 8057707135347178550L, 1L, 527740204201088420L), - (4824597144699038618L, 4627874521623171050L, 1L, 196722623075867568L), - (3317928528506081476L, 6382249289790908051L, 0L, 3317928528506081476L), - (6173196516403597348L, 4901593223366982622L, 1L, 1271603293036614726L), - (6697226531800097631L, 906636418737384700L, 7L, 350771600638404731L), - (3852836788009085824L, 248478100846466152L, 15L, 125665275312093544L), - (7609910327523130308L, 4780671708774555207L, 1L, 2829238618748575101L), - (7299174288081342090L, 4684233015000367062L, 1L, 2614941273080975028L), - (5583983327073390199L, 1503074154703104122L, 3L, 1074760862964077833L), - (7923869470984467163L, 608401886811934230L, 13L, 14644942429322173L), - (3764804524848279959L, 7022863423816677941L, 0L, 3764804524848279959L), - (6202937893449418431L, 6471550866002918077L, 0L, 6202937893449418431L), - (930775821804680172L, 3611973664263654542L, 0L, 930775821804680172L), - (1336298545857306662L, 6150533189497877492L, 0L, 1336298545857306662L), - (3016153490384035887L, 1432506027675544583L, 2L, 151141435032946721L), - (954001560234298007L, 6051824276569621768L, 0L, 954001560234298007L), -] -/* let f a b = a,b, div a b, rem a b;; */ - -let from = xs => - List.mapi( - (i, (a, b, c, d)) => ( - "small_divs " ++ __unsafe_cast(i), - _ => Mt.Eq((c, d), (Int64.div(a, b), Int64.rem(a, b))), - ), - Array.to_list(xs), - ) -let to_string = [(0L, "0")] - -let int64_compare_tests = [(1L, 2L, -1), (2L, 1L, 1), (2L, 1L, 1)] - -let from_compare = xs => - List.mapi( - (i, (a, b, c)) => ("int64_compare " ++ __unsafe_cast(i), _ => Mt.Eq(c, Int64.compare(a, b))), - Array.to_list(xs), - ) - -let from_to_string = xs => - List.mapi( - (i, (a, str_a)) => ("to_string " ++ __unsafe_cast(i), _ => Mt.Eq(str_a, Int64.to_string(a))), - Array.to_list(xs), - ) - -\"@@"( - Mt.from_pair_suites(__MODULE__, ...), - \"@"( - from_pairs("random", pairs), - \"@"( - from_pairs("small", small_pairs), - \"@"( - List.mapi( - (i, (i64, f)) => ("to_float_" ++ __unsafe_cast(i), _ => Mt.Eq(Int64.to_float(i64), f)), - Array.to_list(to_floats), - ), - \"@"( - List.mapi( - (i, (f, i64)) => ("of_float_" ++ __unsafe_cast(i), _ => Mt.Eq(Int64.of_float(f), i64)), - Array.to_list(of_float_pairs), - ), - \"@"( - list{ - ( - "compare_check_complete", - _ => Mt.Eq(Array.map(_ => true, check_complete_compare), check_complete_compare), - ), - }, - \"@"( - from(simple_divs), - \"@"( - from_compare(int64_compare_tests), - list{ - ("div_rem_0", _ => Eq(Int64.div(-1L, 16L), 0L)), - ("div_rem_1", _ => Eq(Int64.rem(-1L, 16L), -1L)), - /* __LOC__, (fun _ -> Eq(Int64.of_float 2e65, -9223372036854775808L)) */ - (__LOC__, _ => Eq(Int64.to_float(Int64.max_int), 9.22337203685477581e+18)), - }, - ), - ), - ), - ), - ), - ), - ) -) -/* - Undefined behaviorJ - - (* Note in ocaml [Int64.of_float] is weird - {[ - Int64.of_float 2.e65;; - - : int64 = -9223372036854775808L - ]} - - - {[ - Int64.of_float (Int64.to_float (Int64.sub Int64.max_int 1L));; - - : int64 = -9223372036854775808L - ]} - both overflow -*) -*/ diff --git a/jscomp/test/int64_string_bench.js b/jscomp/test/int64_string_bench.js deleted file mode 100644 index aba68c3263..0000000000 --- a/jscomp/test/int64_string_bench.js +++ /dev/null @@ -1,52 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Int64 = require("../../lib/js/int64.js"); -let Caml_int64 = require("../../lib/js/caml_int64.js"); - -console.time("Int64.to_string"); - -let u = Caml_int64.sub(Int64.max_int, [ - 0, - 200000 -]); - -for (let i = 0; i <= 100000; ++i) { - Caml_int64.to_string(u); -} - -console.timeEnd("Int64.to_string"); - -console.log(Caml_int64.to_string(u)); - -console.time("Int64.to_string"); - -let u$1 = [ - 0, - 30000000 -]; - -for (let i$1 = 0; i$1 <= 100000; ++i$1) { - Caml_int64.to_string(u$1); -} - -console.timeEnd("Int64.to_string"); - -console.log(Caml_int64.to_string(u$1)); - -console.time("Int64.to_string"); - -let u$2 = Caml_int64.add(Int64.min_int, [ - 0, - 100 -]); - -for (let i$2 = 0; i$2 <= 100000; ++i$2) { - Caml_int64.to_string(u$2); -} - -console.timeEnd("Int64.to_string"); - -console.log(Caml_int64.to_string(u$2)); - -/* Not a pure module */ diff --git a/jscomp/test/int64_string_bench.res b/jscomp/test/int64_string_bench.res deleted file mode 100644 index f383178686..0000000000 --- a/jscomp/test/int64_string_bench.res +++ /dev/null @@ -1,35 +0,0 @@ -let () = { - Js.Console.timeStart("Int64.to_string") - let u = { - open Int64 - max_int->sub(200_000L) - } - /* let u = 3L in */ - for i in 0 to 1_00_000 { - ignore(Int64.to_string(u)) - } - Js.Console.timeEnd("Int64.to_string") - Js.log(Int64.to_string(u)) -} -let () = { - Js.Console.timeStart("Int64.to_string") - let u = 30_000_000L - for i in 0 to 1_00_000 { - ignore(Int64.to_string(u)) - } - Js.Console.timeEnd("Int64.to_string") - Js.log(Int64.to_string(u)) -} - -let () = { - Js.Console.timeStart("Int64.to_string") - let u = { - open Int64 - min_int->add(100L) - } - for i in 0 to 1_00_000 { - ignore(Int64.to_string(u)) - } - Js.Console.timeEnd("Int64.to_string") - Js.log(Int64.to_string(u)) -} diff --git a/jscomp/test/int64_string_test.js b/jscomp/test/int64_string_test.js deleted file mode 100644 index 306f2c2b00..0000000000 --- a/jscomp/test/int64_string_test.js +++ /dev/null @@ -1,1354 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let Int64 = require("../../lib/js/int64.js"); -let Belt_List = require("../../lib/js/belt_List.js"); -let Caml_int64 = require("../../lib/js/caml_int64.js"); - -let suites = { - contents: /* [] */0 -}; - -let test_id = { - contents: 0 -}; - -function eq(loc, x, y) { - Mt.eq_suites(test_id, suites, loc, x, y); -} - -let v = Caml_int64.to_string(Int64.max_int); - -eq("File \"int64_string_test.res\", line 6, characters 3-10", v, "9223372036854775807"); - -function f(a, b) { - eq("File \"int64_string_test.res\", line 7, characters 21-28", Caml_int64.to_string(a), b); -} - -let hh = Caml_int64.add(Int64.min_int, [ - 0, - 100 -]); - -eq("File \"int64_string_test.res\", line 14, characters 3-10", hh, [ - -2147483648, - 100 -]); - -f([ - -1, - 4294967263 -], "-33"); - -f([ - 0, - 33 -], "33"); - -f(Int64.min_int, "-9223372036854775808"); - -f(hh, "-9223372036854775708"); - -f([ - 232830, - 2764472320 -], "1000000000000000"); - -for (let i = 0; i <= 8; ++i) { - eq("File \"int64_string_test.res\", line 22, characters 4-11", Caml_int64.to_string(Caml_int64.add(Int64.min_int, Caml_int64.of_int32(i))), "-922337203685477580" + String(8 - i | 0)); -} - -for (let i$1 = 0; i$1 <= 8; ++i$1) { - eq("File \"int64_string_test.res\", line 32, characters 4-11", Caml_int64.to_string(Caml_int64.add(Int64.min_int, Caml_int64.of_int32(100 + i$1 | 0))), "-922337203685477570" + String(8 - i$1 | 0)); -} - -for (let i$2 = 0; i$2 <= 8; ++i$2) { - eq("File \"int64_string_test.res\", line 42, characters 4-11", Caml_int64.to_string(Caml_int64.add(Int64.min_int, Caml_int64.of_int32(1000000 + i$2 | 0))), "-922337203685377580" + String(8 - i$2 | 0)); -} - -let u = [ - 2097151, - 4294957295 -]; - -for (let i$3 = 0; i$3 <= 6; ++i$3) { - eq("File \"int64_string_test.res\", line 56, characters 4-11", Caml_int64.to_string(Caml_int64.add(u, Caml_int64.of_int32(Math.imul(i$3, 10000)))), "90071992547" + (String(3 + i$3 | 0) + "0991")); -} - -let v$1 = [ - -2097153, - 4294917297 -]; - -for (let i$4 = 0; i$4 <= 9; ++i$4) { - eq("File \"int64_string_test.res\", line 67, characters 4-11", Caml_int64.to_string(Caml_int64.add(v$1, Caml_int64.of_int32(Math.imul(i$4, 10000)))), "-90071992547" + (String(9 - i$4 | 0) + "0991")); -} - -eq("File \"int64_string_test.res\", line 73, characters 3-10", Caml_int64.to_string([ - 2097151, - 4294967295 -]), "9007199254740991"); - -eq("File \"int64_string_test.res\", line 74, characters 3-10", Caml_int64.to_string([ - -2097152, - 1 -]), "-9007199254740991"); - -eq("File \"int64_string_test.res\", line 75, characters 3-10", Caml_int64.to_string([ - -1, - 4294967063 -]), "-233"); - -eq("File \"int64_string_test.res\", line 77, characters 2-9", Caml_int64.to_string(Caml_int64.max_int), "9223372036854775807"); - -let random_data = { - hd: { - hd: [ - [ - 2147226018, - 2371765545 - ], - "9222265526802072873" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2147226019, - 1923201751 - ], - "-9222265526802072873" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 1923105645, - 2649378864 - ], - "8259675854677364784" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -1923105646, - 1645588432 - ], - "-8259675854677364784" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2057149268, - 2297424218 - ], - "8835388831347763546" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2057149269, - 1997543078 - ], - "-8835388831347763546" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 1963412104, - 2782957513 - ], - "8432790778033508297" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -1963412105, - 1512009783 - ], - "-8432790778033508297" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2049795191, - 4094053847 - ], - "8803803312937127383" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2049795192, - 200913449 - ], - "-8803803312937127383" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 1991682107, - 3848914476 - ], - "8554209517442287148" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -1991682108, - 446052820 - ], - "-8554209517442287148" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2055313051, - 3635531172 - ], - "8827502340722511268" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2055313052, - 659436124 - ], - "-8827502340722511268" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2086148291, - 3665585993 - ], - "8959938688116877129" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2086148292, - 629381303 - ], - "-8959938688116877129" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 1950036541, - 3885629083 - ], - "8375343173485592219" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -1950036542, - 409338213 - ], - "-8375343173485592219" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 1920197492, - 3902751793 - ], - "8247185433903973425" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -1920197493, - 392215503 - ], - "-8247185433903973425" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2066884723, - 2562066076 - ], - "8877202292449085084" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2066884724, - 1732901220 - ], - "-8877202292449085084" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2028895352, - 86646639 - ], - "8714039183933054831" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2028895353, - 4208320657 - ], - "-8714039183933054831" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2068232680, - 1417923479 - ], - "8882991722536356759" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2068232681, - 2877043817 - ], - "-8882991722536356759" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 1940466044, - 2146167188 - ], - "8334238200124664212" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -1940466045, - 2148800108 - ], - "-8334238200124664212" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2139021480, - 2844915322 - ], - "9187027304886433402" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2139021481, - 1450051974 - ], - "-9187027304886433402" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2126455706, - 3857675610 - ], - "9133057717520266586" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2126455707, - 437291686 - ], - "-9133057717520266586" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2134212194, - 608162909 - ], - "9166371576562570333" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2134212195, - 3686804387 - ], - "-9166371576562570333" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2014956425, - 1403654222 - ], - "8654171949643731022" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2014956426, - 2891313074 - ], - "-8654171949643731022" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2103588109, - 1237787861 - ], - "9034842133647271125" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2103588110, - 3057179435 - ], - "-9034842133647271125" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2004341376, - 3161072855 - ], - "8608580663100712151" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2004341377, - 1133894441 - ], - "-8608580663100712151" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2053733102, - 4142388780 - ], - "8820716511945020972" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2053733103, - 152578516 - ], - "-8820716511945020972" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2131986077, - 1979926511 - ], - "9156810478222264303" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2131986078, - 2315040785 - ], - "-9156810478222264303" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2038531675, - 609814957 - ], - "8755426876594915757" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2038531676, - 3685152339 - ], - "-8755426876594915757" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2043028138, - 1830468673 - ], - "8774739039348243521" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2043028139, - 2464498623 - ], - "-8774739039348243521" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2113110666, - 2304115509 - ], - "9075741205602894645" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2113110667, - 1990851787 - ], - "-9075741205602894645" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2045703976, - 62815435 - ], - "8786231674279984331" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2045703977, - 4232151861 - ], - "-8786231674279984331" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2083606415, - 1641712918 - ], - "8949021411802516758" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2083606416, - 2653254378 - ], - "-8949021411802516758" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 1984816802, - 385116562 - ], - "8524723253526423954" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -1984816803, - 3909850734 - ], - "-8524723253526423954" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 1982155493, - 3659984780 - ], - "8513293021681741708" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -1982155494, - 634982516 - ], - "-8513293021681741708" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 1960775672, - 1953231192 - ], - "8421467387985654104" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -1960775673, - 2341736104 - ], - "-8421467387985654104" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 1957806908, - 2805808029 - ], - "8408716644548688797" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -1957806909, - 1489159267 - ], - "-8408716644548688797" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2035600198, - 3721695148 - ], - "8742836281862819756" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2035600199, - 573272148 - ], - "-8742836281862819756" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 1979020711, - 2587734081 - ], - "8499829234439401537" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -1979020712, - 1707233215 - ], - "-8499829234439401537" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 1938132066, - 814703363 - ], - "8324213839613616899" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -1938132067, - 3480263933 - ], - "-8324213839613616899" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2121879728, - 100663039 - ], - "9113404037906038527" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2121879729, - 4194304257 - ], - "-9113404037906038527" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2078127307, - 1821275721 - ], - "8925488822310827593" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2078127308, - 2473691575 - ], - "-8925488822310827593" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2113685321, - 221520981 - ], - "9078209327951782997" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2113685322, - 4073446315 - ], - "-9078209327951782997" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2045429685, - 76350484 - ], - "8785053603418932244" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2045429686, - 4218616812 - ], - "-8785053603418932244" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 1968718580, - 3812769591 - ], - "8455581919940329271" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -1968718581, - 482197705 - ], - "-8455581919940329271" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2085192963, - 3635600512 - ], - "8955835585569938560" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2085192964, - 659366784 - ], - "-8955835585569938560" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2105970746, - 891163075 - ], - "9045075481293885891" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2105970747, - 3403804221 - ], - "-9045075481293885891" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 1979240942, - 1745967587 - ], - "8500775118540200419" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -1979240943, - 2548999709 - ], - "-8500775118540200419" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2128838238, - 2568362122 - ], - "9143290613252626570" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2128838239, - 1726605174 - ], - "-9143290613252626570" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2031412573, - 3131651906 - ], - "8724850568849864514" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2031412574, - 1163315390 - ], - "-8724850568849864514" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2134043448, - 3264840400 - ], - "9165646820667917008" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2134043449, - 1030126896 - ], - "-9165646820667917008" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2053645659, - 2298737672 - ], - "8820340945276105736" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2053645660, - 1996229624 - ], - "-8820340945276105736" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2121544293, - 2164977707 - ], - "9111963357615419435" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2121544294, - 2129989589 - ], - "-9111963357615419435" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2143847823, - 4240900280 - ], - "9207756291626696888" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2143847824, - 54067016 - ], - "-9207756291626696888" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2080628135, - 1548719224 - ], - "8936229796511192184" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2080628136, - 2746248072 - ], - "-8936229796511192184" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - 2061191282, - 1066249560 - ], - "8852749148056563032" - ], - tl: /* [] */0 - }, - tl: { - hd: { - hd: [ - [ - -2061191283, - 3228717736 - ], - "-8852749148056563032" - ], - tl: /* [] */0 - }, - tl: /* [] */0 - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } -}; - -Belt_List.forEach(random_data, u => { - if (u) { - if (u.tl) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "int64_string_test.res", - 191, - 9 - ], - Error: new Error() - }; - } - let match = u.hd; - return eq("File \"int64_string_test.res\", line 190, characters 25-32", Caml_int64.to_string(match[0]), match[1]); - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "int64_string_test.res", - 191, - 9 - ], - Error: new Error() - }; -}); - -eq("File \"int64_string_test.res\", line 195, characters 3-10", Caml_int64.to_string([ - -2097152, - 1 -]), "-9007199254740991"); - -eq("File \"int64_string_test.res\", line 196, characters 3-10", Caml_int64.to_string([ - -2097152, - 0 -]), "-9007199254740992"); - -Mt.from_pair_suites("File \"int64_string_test.res\", line 197, characters 20-27", suites.contents); - -exports.suites = suites; -exports.test_id = test_id; -exports.eq = eq; -exports.f = f; -exports.hh = hh; -exports.u = u; -exports.v = v$1; -exports.random_data = random_data; -/* v Not a pure module */ diff --git a/jscomp/test/int64_string_test.res b/jscomp/test/int64_string_test.res deleted file mode 100644 index 804eb3bfcb..0000000000 --- a/jscomp/test/int64_string_test.res +++ /dev/null @@ -1,197 +0,0 @@ -let suites: ref = ref(list{}) -let test_id = ref(0) -let eq = (loc, x, y) => Mt.eq_suites(~test_id, ~suites, loc, x, y) - -let v = Int64.to_string(Int64.max_int) -eq(__LOC__, v, "9223372036854775807") -let f = (a, b) => eq(__LOC__, Int64.to_string(a), b) - -let hh = { - open Int64 - add(min_int, 100L) -} - -eq(__LOC__, hh, -9223372036854775708L) -f(-33L, "-33") -f(33L, "33") -f(Int64.min_int, "-9223372036854775808") -f(hh, "-9223372036854775708") -f(1_000_000_000_000_000L, "1000000000000000") -for i in 0 to 8 { - eq( - __LOC__, - { - open Int64 - to_string(add(min_int, of_int(i))) - }, - "-922337203685477580" ++ string_of_int(8 - i), - ) -} -for i in 0 to 8 { - eq( - __LOC__, - { - open Int64 - to_string(add(min_int, \"@@"(of_int, 100 + i))) - }, - "-922337203685477570" ++ string_of_int(8 - i), - ) -} -for i in 0 to 8 { - eq( - __LOC__, - { - open Int64 - to_string(add(min_int, \"@@"(of_int, 1_000_000 + i))) - }, - "-922337203685377580" ++ string_of_int(8 - i), - ) -} - -let u = 9007199254730991L -/* + 100 */ -for i in 0 to 6 { - open Int64 - eq( - __LOC__, - u->add((i * 100_00)->of_int)->to_string, - "90071992547" ++ (string_of_int(3 + i) ++ "0991"), - ) -} - -let v = -9007199254790991L - -for i in 0 to 9 { - open Int64 - eq( - __LOC__, - v->add((i * 100_00)->of_int)->to_string, - "-90071992547" ++ (string_of_int(9 - i) ++ "0991"), - ) -} - -eq(__LOC__, 9007199254740991L->Int64.to_string, "9007199254740991") -eq(__LOC__, -9007199254740991L->Int64.to_string, "-9007199254740991") -eq(__LOC__, Int64.to_string(-233L), "-233") -eq( - __LOC__, - { - open Int64 - to_string(9223372036854775807L) - }, - "9223372036854775807", -) - -let random_data = list{ - list{(9222265526802072873L, "9222265526802072873")}, - list{(-9222265526802072873L, "-9222265526802072873")}, - list{(8259675854677364784L, "8259675854677364784")}, - list{(-8259675854677364784L, "-8259675854677364784")}, - list{(8835388831347763546L, "8835388831347763546")}, - list{(-8835388831347763546L, "-8835388831347763546")}, - list{(8432790778033508297L, "8432790778033508297")}, - list{(-8432790778033508297L, "-8432790778033508297")}, - list{(8803803312937127383L, "8803803312937127383")}, - list{(-8803803312937127383L, "-8803803312937127383")}, - list{(8554209517442287148L, "8554209517442287148")}, - list{(-8554209517442287148L, "-8554209517442287148")}, - list{(8827502340722511268L, "8827502340722511268")}, - list{(-8827502340722511268L, "-8827502340722511268")}, - list{(8959938688116877129L, "8959938688116877129")}, - list{(-8959938688116877129L, "-8959938688116877129")}, - list{(8375343173485592219L, "8375343173485592219")}, - list{(-8375343173485592219L, "-8375343173485592219")}, - list{(8247185433903973425L, "8247185433903973425")}, - list{(-8247185433903973425L, "-8247185433903973425")}, - list{(8877202292449085084L, "8877202292449085084")}, - list{(-8877202292449085084L, "-8877202292449085084")}, - list{(8714039183933054831L, "8714039183933054831")}, - list{(-8714039183933054831L, "-8714039183933054831")}, - list{(8882991722536356759L, "8882991722536356759")}, - list{(-8882991722536356759L, "-8882991722536356759")}, - list{(8334238200124664212L, "8334238200124664212")}, - list{(-8334238200124664212L, "-8334238200124664212")}, - list{(9187027304886433402L, "9187027304886433402")}, - list{(-9187027304886433402L, "-9187027304886433402")}, - list{(9133057717520266586L, "9133057717520266586")}, - list{(-9133057717520266586L, "-9133057717520266586")}, - list{(9166371576562570333L, "9166371576562570333")}, - list{(-9166371576562570333L, "-9166371576562570333")}, - list{(8654171949643731022L, "8654171949643731022")}, - list{(-8654171949643731022L, "-8654171949643731022")}, - list{(9034842133647271125L, "9034842133647271125")}, - list{(-9034842133647271125L, "-9034842133647271125")}, - list{(8608580663100712151L, "8608580663100712151")}, - list{(-8608580663100712151L, "-8608580663100712151")}, - list{(8820716511945020972L, "8820716511945020972")}, - list{(-8820716511945020972L, "-8820716511945020972")}, - list{(9156810478222264303L, "9156810478222264303")}, - list{(-9156810478222264303L, "-9156810478222264303")}, - list{(8755426876594915757L, "8755426876594915757")}, - list{(-8755426876594915757L, "-8755426876594915757")}, - list{(8774739039348243521L, "8774739039348243521")}, - list{(-8774739039348243521L, "-8774739039348243521")}, - list{(9075741205602894645L, "9075741205602894645")}, - list{(-9075741205602894645L, "-9075741205602894645")}, - list{(8786231674279984331L, "8786231674279984331")}, - list{(-8786231674279984331L, "-8786231674279984331")}, - list{(8949021411802516758L, "8949021411802516758")}, - list{(-8949021411802516758L, "-8949021411802516758")}, - list{(8524723253526423954L, "8524723253526423954")}, - list{(-8524723253526423954L, "-8524723253526423954")}, - list{(8513293021681741708L, "8513293021681741708")}, - list{(-8513293021681741708L, "-8513293021681741708")}, - list{(8421467387985654104L, "8421467387985654104")}, - list{(-8421467387985654104L, "-8421467387985654104")}, - list{(8408716644548688797L, "8408716644548688797")}, - list{(-8408716644548688797L, "-8408716644548688797")}, - list{(8742836281862819756L, "8742836281862819756")}, - list{(-8742836281862819756L, "-8742836281862819756")}, - list{(8499829234439401537L, "8499829234439401537")}, - list{(-8499829234439401537L, "-8499829234439401537")}, - list{(8324213839613616899L, "8324213839613616899")}, - list{(-8324213839613616899L, "-8324213839613616899")}, - list{(9113404037906038527L, "9113404037906038527")}, - list{(-9113404037906038527L, "-9113404037906038527")}, - list{(8925488822310827593L, "8925488822310827593")}, - list{(-8925488822310827593L, "-8925488822310827593")}, - list{(9078209327951782997L, "9078209327951782997")}, - list{(-9078209327951782997L, "-9078209327951782997")}, - list{(8785053603418932244L, "8785053603418932244")}, - list{(-8785053603418932244L, "-8785053603418932244")}, - list{(8455581919940329271L, "8455581919940329271")}, - list{(-8455581919940329271L, "-8455581919940329271")}, - list{(8955835585569938560L, "8955835585569938560")}, - list{(-8955835585569938560L, "-8955835585569938560")}, - list{(9045075481293885891L, "9045075481293885891")}, - list{(-9045075481293885891L, "-9045075481293885891")}, - list{(8500775118540200419L, "8500775118540200419")}, - list{(-8500775118540200419L, "-8500775118540200419")}, - list{(9143290613252626570L, "9143290613252626570")}, - list{(-9143290613252626570L, "-9143290613252626570")}, - list{(8724850568849864514L, "8724850568849864514")}, - list{(-8724850568849864514L, "-8724850568849864514")}, - list{(9165646820667917008L, "9165646820667917008")}, - list{(-9165646820667917008L, "-9165646820667917008")}, - list{(8820340945276105736L, "8820340945276105736")}, - list{(-8820340945276105736L, "-8820340945276105736")}, - list{(9111963357615419435L, "9111963357615419435")}, - list{(-9111963357615419435L, "-9111963357615419435")}, - list{(9207756291626696888L, "9207756291626696888")}, - list{(-9207756291626696888L, "-9207756291626696888")}, - list{(8936229796511192184L, "8936229796511192184")}, - list{(-8936229796511192184L, "-8936229796511192184")}, - list{(8852749148056563032L, "8852749148056563032")}, - list{(-8852749148056563032L, "-8852749148056563032")}, -} - -Belt_List.forEach(random_data, u => - switch u { - | list{(v, str)} => eq(__LOC__, Int64.to_string(v), str) - | _ => assert(false) - } -) - -eq(__LOC__, Int64.to_string(-9007199254740991L), "-9007199254740991") -eq(__LOC__, Int64.to_string(-9007199254740992L), "-9007199254740992") -Mt.from_pair_suites(__LOC__, suites.contents) diff --git a/jscomp/test/int64_test.js b/jscomp/test/int64_test.js deleted file mode 100644 index fb275fde6f..0000000000 --- a/jscomp/test/int64_test.js +++ /dev/null @@ -1,2140 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let $$Array = require("../../lib/js/array.js"); -let Int32 = require("../../lib/js/int32.js"); -let Int64 = require("../../lib/js/int64.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); -let Caml_int64 = require("../../lib/js/caml_int64.js"); -let Pervasives = require("../../lib/js/pervasives.js"); -let Ext_array_test = require("./ext_array_test.js"); - -let v = Caml_int64.add(Caml_int64.of_int32(Int32.max_int), Int64.one); - -let h = Caml_int64.neg(v); - -let a = [ - 0, - 2147483647 -]; - -function commutative_add(result, a, b) { - return { - TAG: "Eq", - _0: [ - result, - result - ], - _1: [ - Caml_int64.add(a, b), - Caml_int64.add(b, a) - ] - }; -} - -let generic_compare = Caml_obj.compare; - -let shift_left_tests_0 = $$Array.map(i => Caml_int64.lsl_(Caml_int64.one, i), Ext_array_test.range(0, 63)); - -let shift_left_tests_1 = [ - Caml_int64.one, - [ - 0, - 2 - ], - [ - 0, - 4 - ], - [ - 0, - 8 - ], - [ - 0, - 16 - ], - [ - 0, - 32 - ], - [ - 0, - 64 - ], - [ - 0, - 128 - ], - [ - 0, - 256 - ], - [ - 0, - 512 - ], - [ - 0, - 1024 - ], - [ - 0, - 2048 - ], - [ - 0, - 4096 - ], - [ - 0, - 8192 - ], - [ - 0, - 16384 - ], - [ - 0, - 32768 - ], - [ - 0, - 65536 - ], - [ - 0, - 131072 - ], - [ - 0, - 262144 - ], - [ - 0, - 524288 - ], - [ - 0, - 1048576 - ], - [ - 0, - 2097152 - ], - [ - 0, - 4194304 - ], - [ - 0, - 8388608 - ], - [ - 0, - 16777216 - ], - [ - 0, - 33554432 - ], - [ - 0, - 67108864 - ], - [ - 0, - 134217728 - ], - [ - 0, - 268435456 - ], - [ - 0, - 536870912 - ], - [ - 0, - 1073741824 - ], - [ - 0, - 2147483648 - ], - [ - 1, - 0 - ], - [ - 2, - 0 - ], - [ - 4, - 0 - ], - [ - 8, - 0 - ], - [ - 16, - 0 - ], - [ - 32, - 0 - ], - [ - 64, - 0 - ], - [ - 128, - 0 - ], - [ - 256, - 0 - ], - [ - 512, - 0 - ], - [ - 1024, - 0 - ], - [ - 2048, - 0 - ], - [ - 4096, - 0 - ], - [ - 8192, - 0 - ], - [ - 16384, - 0 - ], - [ - 32768, - 0 - ], - [ - 65536, - 0 - ], - [ - 131072, - 0 - ], - [ - 262144, - 0 - ], - [ - 524288, - 0 - ], - [ - 1048576, - 0 - ], - [ - 2097152, - 0 - ], - [ - 4194304, - 0 - ], - [ - 8388608, - 0 - ], - [ - 16777216, - 0 - ], - [ - 33554432, - 0 - ], - [ - 67108864, - 0 - ], - [ - 134217728, - 0 - ], - [ - 268435456, - 0 - ], - [ - 536870912, - 0 - ], - [ - 1073741824, - 0 - ], - Caml_int64.min_int -]; - -let shift_left_tests = [ - shift_left_tests_0, - shift_left_tests_1 -]; - -let shift_right_tests_0 = $$Array.map(i => Caml_int64.asr_(Caml_int64.min_int, i), Ext_array_test.range(0, 63)); - -let shift_right_tests_1 = [ - Caml_int64.min_int, - [ - -1073741824, - 0 - ], - [ - -536870912, - 0 - ], - [ - -268435456, - 0 - ], - [ - -134217728, - 0 - ], - [ - -67108864, - 0 - ], - [ - -33554432, - 0 - ], - [ - -16777216, - 0 - ], - [ - -8388608, - 0 - ], - [ - -4194304, - 0 - ], - [ - -2097152, - 0 - ], - [ - -1048576, - 0 - ], - [ - -524288, - 0 - ], - [ - -262144, - 0 - ], - [ - -131072, - 0 - ], - [ - -65536, - 0 - ], - [ - -32768, - 0 - ], - [ - -16384, - 0 - ], - [ - -8192, - 0 - ], - [ - -4096, - 0 - ], - [ - -2048, - 0 - ], - [ - -1024, - 0 - ], - [ - -512, - 0 - ], - [ - -256, - 0 - ], - [ - -128, - 0 - ], - [ - -64, - 0 - ], - [ - -32, - 0 - ], - [ - -16, - 0 - ], - [ - -8, - 0 - ], - [ - -4, - 0 - ], - [ - -2, - 0 - ], - [ - -1, - 0 - ], - [ - -1, - 2147483648 - ], - [ - -1, - 3221225472 - ], - [ - -1, - 3758096384 - ], - [ - -1, - 4026531840 - ], - [ - -1, - 4160749568 - ], - [ - -1, - 4227858432 - ], - [ - -1, - 4261412864 - ], - [ - -1, - 4278190080 - ], - [ - -1, - 4286578688 - ], - [ - -1, - 4290772992 - ], - [ - -1, - 4292870144 - ], - [ - -1, - 4293918720 - ], - [ - -1, - 4294443008 - ], - [ - -1, - 4294705152 - ], - [ - -1, - 4294836224 - ], - [ - -1, - 4294901760 - ], - [ - -1, - 4294934528 - ], - [ - -1, - 4294950912 - ], - [ - -1, - 4294959104 - ], - [ - -1, - 4294963200 - ], - [ - -1, - 4294965248 - ], - [ - -1, - 4294966272 - ], - [ - -1, - 4294966784 - ], - [ - -1, - 4294967040 - ], - [ - -1, - 4294967168 - ], - [ - -1, - 4294967232 - ], - [ - -1, - 4294967264 - ], - [ - -1, - 4294967280 - ], - [ - -1, - 4294967288 - ], - [ - -1, - 4294967292 - ], - [ - -1, - 4294967294 - ], - Caml_int64.neg_one -]; - -let shift_right_tests = [ - shift_right_tests_0, - shift_right_tests_1 -]; - -let shift_right_logical_suites_0 = $$Array.map(i => Caml_int64.lsr_(Caml_int64.min_int, i), Ext_array_test.range(0, 63)); - -let shift_right_logical_suites_1 = [ - Caml_int64.min_int, - [ - 1073741824, - 0 - ], - [ - 536870912, - 0 - ], - [ - 268435456, - 0 - ], - [ - 134217728, - 0 - ], - [ - 67108864, - 0 - ], - [ - 33554432, - 0 - ], - [ - 16777216, - 0 - ], - [ - 8388608, - 0 - ], - [ - 4194304, - 0 - ], - [ - 2097152, - 0 - ], - [ - 1048576, - 0 - ], - [ - 524288, - 0 - ], - [ - 262144, - 0 - ], - [ - 131072, - 0 - ], - [ - 65536, - 0 - ], - [ - 32768, - 0 - ], - [ - 16384, - 0 - ], - [ - 8192, - 0 - ], - [ - 4096, - 0 - ], - [ - 2048, - 0 - ], - [ - 1024, - 0 - ], - [ - 512, - 0 - ], - [ - 256, - 0 - ], - [ - 128, - 0 - ], - [ - 64, - 0 - ], - [ - 32, - 0 - ], - [ - 16, - 0 - ], - [ - 8, - 0 - ], - [ - 4, - 0 - ], - [ - 2, - 0 - ], - [ - 1, - 0 - ], - [ - 0, - 2147483648 - ], - [ - 0, - 1073741824 - ], - [ - 0, - 536870912 - ], - [ - 0, - 268435456 - ], - [ - 0, - 134217728 - ], - [ - 0, - 67108864 - ], - [ - 0, - 33554432 - ], - [ - 0, - 16777216 - ], - [ - 0, - 8388608 - ], - [ - 0, - 4194304 - ], - [ - 0, - 2097152 - ], - [ - 0, - 1048576 - ], - [ - 0, - 524288 - ], - [ - 0, - 262144 - ], - [ - 0, - 131072 - ], - [ - 0, - 65536 - ], - [ - 0, - 32768 - ], - [ - 0, - 16384 - ], - [ - 0, - 8192 - ], - [ - 0, - 4096 - ], - [ - 0, - 2048 - ], - [ - 0, - 1024 - ], - [ - 0, - 512 - ], - [ - 0, - 256 - ], - [ - 0, - 128 - ], - [ - 0, - 64 - ], - [ - 0, - 32 - ], - [ - 0, - 16 - ], - [ - 0, - 8 - ], - [ - 0, - 4 - ], - [ - 0, - 2 - ], - Caml_int64.one -]; - -let shift_right_logical_suites = [ - shift_right_logical_suites_0, - shift_right_logical_suites_1 -]; - -function fib(_n, _a, _b) { - while (true) { - let b = _b; - let a = _a; - let n = _n; - if (n === 0) { - return a; - } - _b = Caml_int64.add(a, b); - _a = b; - _n = n - 1 | 0; - continue; - }; -} - -function fac(_n, _acc) { - while (true) { - let acc = _acc; - let n = _n; - if (n === 0) { - return acc; - } - _acc = Caml_int64.mul(acc, Caml_int64.of_int32(n)); - _n = n - 1 | 0; - continue; - }; -} - -let suites = Pervasives.$at({ - hd: [ - "add_one", - () => ({ - TAG: "Eq", - _0: v, - _1: [ - 0, - 2147483648 - ] - }) - ], - tl: { - hd: [ - "add_2", - () => ({ - TAG: "Eq", - _0: [ - 0, - 4294967294 - ], - _1: Caml_int64.add(a, a) - }) - ], - tl: { - hd: [ - "add_3", - () => ({ - TAG: "Eq", - _0: Caml_int64.zero, - _1: Caml_int64.zero - }) - ], - tl: { - hd: [ - "add_4", - () => commutative_add([ - -1, - 4294967294 - ], [ - -1, - 4294967293 - ], Caml_int64.one) - ], - tl: { - hd: [ - "add_5", - () => commutative_add([ - -1, - 4294967293 - ], [ - -1, - 4294967293 - ], Caml_int64.zero) - ], - tl: { - hd: [ - "add_6", - () => commutative_add([ - 0, - 4 - ], [ - -1, - 4294967293 - ], [ - 0, - 7 - ]) - ], - tl: { - hd: [ - "add_7", - () => commutative_add([ - 1, - 0 - ], [ - 0, - 2147483648 - ], [ - 0, - 2147483648 - ]) - ], - tl: { - hd: [ - "add_8", - () => commutative_add([ - 1, - 0 - ], [ - 0, - 4294967295 - ], Caml_int64.one) - ], - tl: { - hd: [ - "add_9", - () => commutative_add([ - 0, - 4294967295 - ], [ - 0, - 2147483648 - ], [ - 0, - 2147483647 - ]) - ], - tl: { - hd: [ - "add_10", - () => commutative_add([ - 0, - 2147483648 - ], [ - 0, - 2147483648 - ], Caml_int64.zero) - ], - tl: { - hd: [ - "add_11", - () => commutative_add([ - 0, - 4294967295 - ], [ - 0, - 4294967295 - ], Caml_int64.zero) - ], - tl: { - hd: [ - "to_int32", - () => ({ - TAG: "Eq", - _0: 3, - _1: Caml_int64.to_int32([ - 0, - 3 - ]) - }) - ], - tl: { - hd: [ - "to_int", - () => ({ - TAG: "Eq", - _0: 3, - _1: Caml_int64.to_int32([ - 0, - 3 - ]) - }) - ], - tl: { - hd: [ - "of_int", - () => ({ - TAG: "Eq", - _0: [ - 0, - 3 - ], - _1: [ - 0, - 3 - ] - }) - ], - tl: { - hd: [ - "lognot", - () => ({ - TAG: "Eq", - _0: [ - -1, - 4294967293 - ], - _1: [ - -1, - 4294967293 - ] - }) - ], - tl: { - hd: [ - "neg", - () => ({ - TAG: "Eq", - _0: [ - -1, - 4294967294 - ], - _1: [ - -1, - 4294967294 - ] - }) - ], - tl: { - hd: [ - "File \"int64_test.res\", line 275, characters 7-14", - () => ({ - TAG: "Eq", - _0: Int64.min_int, - _1: Caml_int64.neg(Int64.min_int) - }) - ], - tl: { - hd: [ - "File \"int64_test.res\", line 277, characters 8-15", - () => ({ - TAG: "Eq", - _0: Int64.max_int, - _1: Caml_int64.neg(Caml_int64.add(Int64.min_int, Caml_int64.one)) - }) - ], - tl: { - hd: [ - "sub1", - () => ({ - TAG: "Eq", - _0: [ - 0, - 2 - ], - _1: [ - 0, - 2 - ] - }) - ], - tl: { - hd: [ - "xor1", - () => ({ - TAG: "Eq", - _0: [ - [ - 0, - 286331153 - ], - Caml_int64.xor(a, [ - 0, - 4009750271 - ]) - ], - _1: [ - [ - 0, - 286331153 - ], - [ - 0, - 2432700672 - ] - ] - }) - ], - tl: { - hd: [ - "or", - () => ({ - TAG: "Eq", - _0: [ - 0, - 4294967295 - ], - _1: [ - 0, - 4294967295 - ] - }) - ], - tl: { - hd: [ - "and", - () => ({ - TAG: "Eq", - _0: [ - 0, - 4008636142 - ], - _1: [ - 0, - 4008636142 - ] - }) - ], - tl: { - hd: [ - "lsl", - () => ({ - TAG: "Eq", - _0: $$Array.map(x => Caml_int64.lsl_(Caml_int64.one, x), $$Array.init(64, i => i)), - _1: [ - Caml_int64.one, - [ - 0, - 2 - ], - [ - 0, - 4 - ], - [ - 0, - 8 - ], - [ - 0, - 16 - ], - [ - 0, - 32 - ], - [ - 0, - 64 - ], - [ - 0, - 128 - ], - [ - 0, - 256 - ], - [ - 0, - 512 - ], - [ - 0, - 1024 - ], - [ - 0, - 2048 - ], - [ - 0, - 4096 - ], - [ - 0, - 8192 - ], - [ - 0, - 16384 - ], - [ - 0, - 32768 - ], - [ - 0, - 65536 - ], - [ - 0, - 131072 - ], - [ - 0, - 262144 - ], - [ - 0, - 524288 - ], - [ - 0, - 1048576 - ], - [ - 0, - 2097152 - ], - [ - 0, - 4194304 - ], - [ - 0, - 8388608 - ], - [ - 0, - 16777216 - ], - [ - 0, - 33554432 - ], - [ - 0, - 67108864 - ], - [ - 0, - 134217728 - ], - [ - 0, - 268435456 - ], - [ - 0, - 536870912 - ], - [ - 0, - 1073741824 - ], - [ - 0, - 2147483648 - ], - [ - 1, - 0 - ], - [ - 2, - 0 - ], - [ - 4, - 0 - ], - [ - 8, - 0 - ], - [ - 16, - 0 - ], - [ - 32, - 0 - ], - [ - 64, - 0 - ], - [ - 128, - 0 - ], - [ - 256, - 0 - ], - [ - 512, - 0 - ], - [ - 1024, - 0 - ], - [ - 2048, - 0 - ], - [ - 4096, - 0 - ], - [ - 8192, - 0 - ], - [ - 16384, - 0 - ], - [ - 32768, - 0 - ], - [ - 65536, - 0 - ], - [ - 131072, - 0 - ], - [ - 262144, - 0 - ], - [ - 524288, - 0 - ], - [ - 1048576, - 0 - ], - [ - 2097152, - 0 - ], - [ - 4194304, - 0 - ], - [ - 8388608, - 0 - ], - [ - 16777216, - 0 - ], - [ - 33554432, - 0 - ], - [ - 67108864, - 0 - ], - [ - 134217728, - 0 - ], - [ - 268435456, - 0 - ], - [ - 536870912, - 0 - ], - [ - 1073741824, - 0 - ], - Caml_int64.min_int - ] - }) - ], - tl: { - hd: [ - "lsr", - () => ({ - TAG: "Eq", - _0: $$Array.map(x => Caml_int64.lsr_(Caml_int64.neg_one, x), $$Array.init(64, i => i)), - _1: [ - Caml_int64.neg_one, - Caml_int64.max_int, - [ - 1073741823, - 4294967295 - ], - [ - 536870911, - 4294967295 - ], - [ - 268435455, - 4294967295 - ], - [ - 134217727, - 4294967295 - ], - [ - 67108863, - 4294967295 - ], - [ - 33554431, - 4294967295 - ], - [ - 16777215, - 4294967295 - ], - [ - 8388607, - 4294967295 - ], - [ - 4194303, - 4294967295 - ], - [ - 2097151, - 4294967295 - ], - [ - 1048575, - 4294967295 - ], - [ - 524287, - 4294967295 - ], - [ - 262143, - 4294967295 - ], - [ - 131071, - 4294967295 - ], - [ - 65535, - 4294967295 - ], - [ - 32767, - 4294967295 - ], - [ - 16383, - 4294967295 - ], - [ - 8191, - 4294967295 - ], - [ - 4095, - 4294967295 - ], - [ - 2047, - 4294967295 - ], - [ - 1023, - 4294967295 - ], - [ - 511, - 4294967295 - ], - [ - 255, - 4294967295 - ], - [ - 127, - 4294967295 - ], - [ - 63, - 4294967295 - ], - [ - 31, - 4294967295 - ], - [ - 15, - 4294967295 - ], - [ - 7, - 4294967295 - ], - [ - 3, - 4294967295 - ], - [ - 1, - 4294967295 - ], - [ - 0, - 4294967295 - ], - [ - 0, - 2147483647 - ], - [ - 0, - 1073741823 - ], - [ - 0, - 536870911 - ], - [ - 0, - 268435455 - ], - [ - 0, - 134217727 - ], - [ - 0, - 67108863 - ], - [ - 0, - 33554431 - ], - [ - 0, - 16777215 - ], - [ - 0, - 8388607 - ], - [ - 0, - 4194303 - ], - [ - 0, - 2097151 - ], - [ - 0, - 1048575 - ], - [ - 0, - 524287 - ], - [ - 0, - 262143 - ], - [ - 0, - 131071 - ], - [ - 0, - 65535 - ], - [ - 0, - 32767 - ], - [ - 0, - 16383 - ], - [ - 0, - 8191 - ], - [ - 0, - 4095 - ], - [ - 0, - 2047 - ], - [ - 0, - 1023 - ], - [ - 0, - 511 - ], - [ - 0, - 255 - ], - [ - 0, - 127 - ], - [ - 0, - 63 - ], - [ - 0, - 31 - ], - [ - 0, - 15 - ], - [ - 0, - 7 - ], - [ - 0, - 3 - ], - Caml_int64.one - ] - }) - ], - tl: { - hd: [ - "asr", - () => ({ - TAG: "Eq", - _0: $$Array.map(x => Caml_int64.asr_(Caml_int64.neg_one, x), $$Array.init(64, i => i)), - _1: [ - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one, - Caml_int64.neg_one - ] - }) - ], - tl: { - hd: [ - "mul simple", - () => ({ - TAG: "Eq", - _0: [ - 0, - 6 - ], - _1: [ - 0, - 6 - ] - }) - ], - tl: { - hd: [ - "of_int32", - () => ({ - TAG: "Eq", - _0: $$Array.map(Caml_int64.of_int32, [ - 0, - -2147483648 - ]), - _1: [ - Caml_int64.zero, - [ - -1, - 2147483648 - ] - ] - }) - ], - tl: { - hd: [ - "of_int32_singleton", - () => ({ - TAG: "Eq", - _0: [ - -1, - 4294967293 - ], - _1: [ - -1, - 4294967293 - ] - }) - ], - tl: { - hd: [ - "File \"int64_test.res\", line 524, characters 7-14", - () => ({ - TAG: "Eq", - _0: [ - 0, - 3 - ], - _1: [ - 0, - 3 - ] - }) - ], - tl: { - hd: [ - "to_int32", - () => ({ - TAG: "Eq", - _0: $$Array.map(Caml_int64.to_int32, [ - Caml_int64.zero, - [ - 0, - 2147483648 - ] - ]), - _1: [ - 0, - -2147483648 - ] - }) - ], - tl: { - hd: [ - "discard_sign", - () => ({ - TAG: "Eq", - _0: Caml_int64.discard_sign(Caml_int64.neg_one), - _1: Caml_int64.max_int - }) - ], - tl: { - hd: [ - "div_mod", - () => ({ - TAG: "Eq", - _0: Caml_int64.div_mod([ - 0, - 7 - ], [ - 0, - 3 - ]), - _1: [ - [ - 0, - 2 - ], - Caml_int64.one - ] - }) - ], - tl: { - hd: [ - "to_hex", - () => ({ - TAG: "Eq", - _0: Caml_int64.to_hex(Caml_int64.neg_one), - _1: "ffffffffffffffff" - }) - ], - tl: { - hd: [ - "generic_compare", - () => ({ - TAG: "Eq", - _0: Caml_obj.compare([ - 1, - 0 - ], Caml_int64.one) > 0, - _1: true - }) - ], - tl: { - hd: [ - "test_compier_literal", - () => ({ - TAG: "Eq", - _0: [ - 0, - 4294967295 - ], - _1: [ - 0, - 4294967295 - ] - }) - ], - tl: { - hd: [ - "generic_compare2", - () => ({ - TAG: "Eq", - _0: Caml_obj.compare([ - 0, - 2147483648 - ], Caml_int64.one) > 0, - _1: true - }) - ], - tl: { - hd: [ - "shift_left", - () => ({ - TAG: "Eq", - _0: [ - 0, - 4294967040 - ], - _1: [ - 0, - 4294967040 - ] - }) - ], - tl: { - hd: [ - "fib_int64", - () => ({ - TAG: "Eq", - _0: fib(1000, Caml_int64.one, [ - 0, - 2 - ]), - _1: [ - -1990564327, - 2874523960 - ] - }) - ], - tl: { - hd: [ - "fac_int64", - () => ({ - TAG: "Eq", - _0: fac(30, Caml_int64.one), - _1: [ - -2040662563, - 1409286144 - ] - }) - ], - tl: { - hd: [ - "File \"int64_test.res\", line 551, characters 8-15", - () => ({ - TAG: "Eq", - _0: Caml_int64.add(Int64.max_int, Int64.max_int), - _1: [ - -1, - 4294967294 - ] - }) - ], - tl: { - hd: [ - "File \"int64_test.res\", line 561, characters 8-15", - () => ({ - TAG: "Eq", - _0: Caml_int64.add(Int64.min_int, Int64.min_int), - _1: Caml_int64.zero - }) - ], - tl: { - hd: [ - "File \"int64_test.res\", line 571, characters 8-15", - () => ({ - TAG: "Eq", - _0: Caml_int64.neg_one, - _1: Caml_int64.neg_one - }) - ], - tl: /* [] */0 - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } -}, Pervasives.$at($$Array.to_list(Ext_array_test.map2i((i, a, b) => [ - "shift_left_cases " + i, - () => ({ - TAG: "Eq", - _0: a, - _1: b - }) -], shift_left_tests_0, shift_left_tests_1)), Pervasives.$at($$Array.to_list(Ext_array_test.map2i((i, a, b) => [ - "shift_right_cases " + i, - () => ({ - TAG: "Eq", - _0: a, - _1: b - }) -], shift_right_tests_0, shift_right_tests_1)), $$Array.to_list(Ext_array_test.map2i((i, a, b) => [ - "shift_right_logical_cases " + i, - () => ({ - TAG: "Eq", - _0: a, - _1: b - }) -], shift_right_logical_suites_0, shift_right_logical_suites_1))))); - -let suites$1 = { - contents: suites -}; - -let test_id = { - contents: 0 -}; - -function eq(loc, x, y) { - Mt.eq_suites(test_id, suites$1, loc, x, y); -} - -function id(loc, x) { - let float_value = Caml_int64.float_of_bits(x); - let match = Pervasives.classify_float(float_value); - if (match === "FP_nan") { - return; - } else { - return eq(loc, Caml_int64.bits_of_float(float_value), x); - } -} - -eq("File \"int64_test.res\", line 633, characters 5-12", Caml_int64.bits_of_float(0.3), [ - 1070805811, - 858993459 -]); - -eq("File \"int64_test.res\", line 634, characters 5-12", Caml_int64.float_of_bits([ - 1070805811, - 858993459 -]), 0.3); - -id("File \"int64_test.res\", line 635, characters 5-12", Caml_int64.neg_one); - -id("File \"int64_test.res\", line 636, characters 5-12", [ - -1, - 4294967196 -]); - -id("File \"int64_test.res\", line 637, characters 5-12", [ - 0, - 4294967295 -]); - -id("File \"int64_test.res\", line 638, characters 5-12", [ - 0, - 536870911 -]); - -id("File \"int64_test.res\", line 639, characters 5-12", [ - 0, - 536870655 -]); - -eq("File \"int64_test.res\", line 641, characters 4-11", Caml_int64.div(Int64.min_int, [ - 0, - 10 -]), [ - -214748365, - 858993460 -]); - -eq("File \"int64_test.res\", line 649, characters 4-11", Caml_int64.to_string(Caml_int64.div(Int64.min_int, [ - 0, - 10 -])), "-922337203685477580"); - -eq("File \"int64_test.res\", line 657, characters 4-11", Caml_int64.mul(Int64.min_int, [ - 0, - 10 -]), Caml_int64.zero); - -eq("File \"int64_test.res\", line 665, characters 4-11", Caml_int64.mul([ - 0, - 10 -], Int64.min_int), Caml_int64.zero); - -eq("File \"int64_test.res\", line 673, characters 4-11", Caml_int64.mul(Caml_int64.one, Int64.min_int), Int64.min_int); - -eq("File \"int64_test.res\", line 681, characters 4-11", Caml_int64.mul(Int64.max_int, [ - 0, - 10 -]), [ - -1, - 4294967286 -]); - -eq("File \"int64_test.res\", line 689, characters 4-11", Caml_int64.succ(Int64.max_int), Int64.min_int); - -eq("File \"int64_test.res\", line 697, characters 4-11", Caml_int64.succ(Int64.min_int), [ - -2147483648, - 1 -]); - -eq("File \"int64_test.res\", line 704, characters 5-12", Caml_int64.succ([ - 0, - 4294967295 -]), [ - 1, - 0 -]); - -Mt.from_pair_suites("Int64_test", suites$1.contents); - -exports.v = v; -exports.h = h; -exports.a = a; -exports.commutative_add = commutative_add; -exports.generic_compare = generic_compare; -exports.shift_left_tests = shift_left_tests; -exports.shift_right_tests = shift_right_tests; -exports.shift_right_logical_suites = shift_right_logical_suites; -exports.fib = fib; -exports.fac = fac; -exports.suites = suites$1; -exports.test_id = test_id; -exports.eq = eq; -exports.id = id; -/* shift_left_tests Not a pure module */ diff --git a/jscomp/test/int64_test.res b/jscomp/test/int64_test.res deleted file mode 100644 index b52d223946..0000000000 --- a/jscomp/test/int64_test.res +++ /dev/null @@ -1,706 +0,0 @@ -/* module Mt = Mock_mt */ - -let v = Int64.add(Int64.of_int32(Int32.max_int), Int64.one) -let h = Int64.neg(v) -let a = Int64.of_int32(2147483647l) - -open Int64 - -let commutative_add = (result, a, b) => Mt.Eq((result, result), (add(a, b), add(b, a))) -let generic_compare = Pervasives.compare - -let shift_left_tests = ( - Array.map(i => Int64.shift_left(1L, i), Ext_array_test.range(0, 63)), - [ - 1L, - 2L, - 4L, - 8L, - 16L, - 32L, - 64L, - 128L, - 256L, - 512L, - 1024L, - 2048L, - 4096L, - 8192L, - 16384L, - 32768L, - 65536L, - 131072L, - 262144L, - 524288L, - 1048576L, - 2097152L, - 4194304L, - 8388608L, - 16777216L, - 33554432L, - 67108864L, - 134217728L, - 268435456L, - 536870912L, - 1073741824L, - 2147483648L, - 4294967296L, - 8589934592L, - 17179869184L, - 34359738368L, - 68719476736L, - 137438953472L, - 274877906944L, - 549755813888L, - 1099511627776L, - 2199023255552L, - 4398046511104L, - 8796093022208L, - 17592186044416L, - 35184372088832L, - 70368744177664L, - 140737488355328L, - 281474976710656L, - 562949953421312L, - 1125899906842624L, - 2251799813685248L, - 4503599627370496L, - 9007199254740992L, - 18014398509481984L, - 36028797018963968L, - 72057594037927936L, - 144115188075855872L, - 288230376151711744L, - 576460752303423488L, - 1152921504606846976L, - 2305843009213693952L, - 4611686018427387904L, - -9223372036854775808L, - ], -) - -let shift_right_tests = ( - Array.map(i => Int64.shift_right(0x8000_0000_0000_0000L, i), Ext_array_test.range(0, 63)), - [ - -9223372036854775808L, - -4611686018427387904L, - -2305843009213693952L, - -1152921504606846976L, - -576460752303423488L, - -288230376151711744L, - -144115188075855872L, - -72057594037927936L, - -36028797018963968L, - -18014398509481984L, - -9007199254740992L, - -4503599627370496L, - -2251799813685248L, - -1125899906842624L, - -562949953421312L, - -281474976710656L, - -140737488355328L, - -70368744177664L, - -35184372088832L, - -17592186044416L, - -8796093022208L, - -4398046511104L, - -2199023255552L, - -1099511627776L, - -549755813888L, - -274877906944L, - -137438953472L, - -68719476736L, - -34359738368L, - -17179869184L, - -8589934592L, - -4294967296L, - -2147483648L, - -1073741824L, - -536870912L, - -268435456L, - -134217728L, - -67108864L, - -33554432L, - -16777216L, - -8388608L, - -4194304L, - -2097152L, - -1048576L, - -524288L, - -262144L, - -131072L, - -65536L, - -32768L, - -16384L, - -8192L, - -4096L, - -2048L, - -1024L, - -512L, - -256L, - -128L, - -64L, - -32L, - -16L, - -8L, - -4L, - -2L, - -1L, - ], -) - -let shift_right_logical_suites = ( - Array.map(i => Int64.shift_right_logical(0x8000_0000_0000_0000L, i), Ext_array_test.range(0, 63)), - [ - -9223372036854775808L, - 4611686018427387904L, - 2305843009213693952L, - 1152921504606846976L, - 576460752303423488L, - 288230376151711744L, - 144115188075855872L, - 72057594037927936L, - 36028797018963968L, - 18014398509481984L, - 9007199254740992L, - 4503599627370496L, - 2251799813685248L, - 1125899906842624L, - 562949953421312L, - 281474976710656L, - 140737488355328L, - 70368744177664L, - 35184372088832L, - 17592186044416L, - 8796093022208L, - 4398046511104L, - 2199023255552L, - 1099511627776L, - 549755813888L, - 274877906944L, - 137438953472L, - 68719476736L, - 34359738368L, - 17179869184L, - 8589934592L, - 4294967296L, - 2147483648L, - 1073741824L, - 536870912L, - 268435456L, - 134217728L, - 67108864L, - 33554432L, - 16777216L, - 8388608L, - 4194304L, - 2097152L, - 1048576L, - 524288L, - 262144L, - 131072L, - 65536L, - 32768L, - 16384L, - 8192L, - 4096L, - 2048L, - 1024L, - 512L, - 256L, - 128L, - 64L, - 32L, - 16L, - 8L, - 4L, - 2L, - 1L, - ], -) -let rec fib = (n, a, b) => - if n == 0 { - a - } else { - fib(n - 1, b, Int64.add(a, b)) - } -let rec fac = (n, acc) => - if n == 0 { - acc - } else { - fac(n - 1, Int64.mul(acc, Int64.of_int(n))) - } -let suites: Mt.pair_suites = /* "shift_right",(fun _ -> - Eq(Nativeint.shift_right_logical 0xffff_ffffn 0, 0xffff_ffffn) - ); */ - -\"@"( - { - open Mt - list{ - ("add_one", _ => Eq(v, 2147483648L)), - ( - "add_2", - _ => Eq( - 4294967294L, - { - open Int64 - add(a, a) - }, - ), - ), - ( - "add_3", - _ => Eq( - 0L, - { - open Int64 - add(0L, 0L) - }, - ), - ), - ("add_4", _ => commutative_add(-2L, -3L, 1L)), - ("add_5", _ => commutative_add(-3L, -3L, 0L)), - ("add_6", _ => commutative_add(4L, -3L, 7L)), - ("add_7", _ => commutative_add(0x100000000L, 0x80000000L, 0x80000000L)), - ("add_8", _ => commutative_add(0x100000000L, 0xffffffffL, 1L)), - ("add_9", _ => commutative_add(0xffffffffL, 0x80000000L, 0x7fffffffL)), - ("add_10", _ => commutative_add(0x80000000L, 0x80000000L, 0L)), - ("add_11", _ => commutative_add(0xffffffffL, 0xffffffffL, 0L)), - ("to_int32", _ => Eq(3l, Int64.to_int32(3L))), - ("to_int", _ => Eq(3, Int64.to_int(3L))), - ("of_int", _ => Eq(3L, Int64.of_int(3))), - ("lognot", _ => Eq(-3L, Int64.lognot(2L))), - ("neg", _ => Eq(-2L, Int64.neg(2L))), - (__LOC__, _ => Eq(Int64.min_int, Int64.neg(Int64.min_int))), - ( - __LOC__, - _ => Eq( - Int64.max_int, - Int64.neg({ - open Int64 - add(min_int, 1L) - }), - ), - ), - ( - "sub1", - _ => Eq( - 2L, - { - open Int64 - sub(3L, 1L) - }, - ), - ), - ( - "xor1", - _ => Eq( - (logxor(0xEEFFEEFFL, 0xFFEEFFEEL), logxor(a, 0xEEFFEEFFL)), - (286331153L, 2432700672L), - ), - ), - ("or", _ => Eq(logor(0xEEFFEEFFL, 0xFFEEFFEEL), 4294967295L)), - ("and", _ => Eq(logand(0xEEFFEEFFL, 0xFFEEFFEEL), 4008636142L)), - ( - "lsl", - _ => Eq( - Array.map(x => shift_left(1L, x), Array.init(64, i => i)), - [ - 1L, - 2L, - 4L, - 8L, - 16L, - 32L, - 64L, - 128L, - 256L, - 512L, - 1024L, - 2048L, - 4096L, - 8192L, - 16384L, - 32768L, - 65536L, - 131072L, - 262144L, - 524288L, - 1048576L, - 2097152L, - 4194304L, - 8388608L, - 16777216L, - 33554432L, - 67108864L, - 134217728L, - 268435456L, - 536870912L, - 1073741824L, - 2147483648L, - 4294967296L, - 8589934592L, - 17179869184L, - 34359738368L, - 68719476736L, - 137438953472L, - 274877906944L, - 549755813888L, - 1099511627776L, - 2199023255552L, - 4398046511104L, - 8796093022208L, - 17592186044416L, - 35184372088832L, - 70368744177664L, - 140737488355328L, - 281474976710656L, - 562949953421312L, - 1125899906842624L, - 2251799813685248L, - 4503599627370496L, - 9007199254740992L, - 18014398509481984L, - 36028797018963968L, - 72057594037927936L, - 144115188075855872L, - 288230376151711744L, - 576460752303423488L, - 1152921504606846976L, - 2305843009213693952L, - 4611686018427387904L, - -9223372036854775808L, - ], - ), - ), - ( - "lsr", - _ => Eq( - Array.map(x => shift_right_logical(-1L, x), Array.init(64, i => i)), - [ - -1L, - 9223372036854775807L, - 4611686018427387903L, - 2305843009213693951L, - 1152921504606846975L, - 576460752303423487L, - 288230376151711743L, - 144115188075855871L, - 72057594037927935L, - 36028797018963967L, - 18014398509481983L, - 9007199254740991L, - 4503599627370495L, - 2251799813685247L, - 1125899906842623L, - 562949953421311L, - 281474976710655L, - 140737488355327L, - 70368744177663L, - 35184372088831L, - 17592186044415L, - 8796093022207L, - 4398046511103L, - 2199023255551L, - 1099511627775L, - 549755813887L, - 274877906943L, - 137438953471L, - 68719476735L, - 34359738367L, - 17179869183L, - 8589934591L, - 4294967295L, - 2147483647L, - 1073741823L, - 536870911L, - 268435455L, - 134217727L, - 67108863L, - 33554431L, - 16777215L, - 8388607L, - 4194303L, - 2097151L, - 1048575L, - 524287L, - 262143L, - 131071L, - 65535L, - 32767L, - 16383L, - 8191L, - 4095L, - 2047L, - 1023L, - 511L, - 255L, - 127L, - 63L, - 31L, - 15L, - 7L, - 3L, - 1L, - ], - ), - ), - ( - "asr", - _ => Eq( - Array.map(x => shift_right(-1L, x), Array.init(64, i => i)), - [ - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - -1L, - ], - ), - ), - ("mul simple", _ => Eq(6L, mul(3L, 2L))), - ("of_int32", _ => Eq(Array.map(Int64.of_int32, [0l, -2147483648l]), [0L, -2147483648L])), - ("of_int32_singleton", _ => Eq(Int64.of_int32(-3l), -3L)), - (__LOC__, _ => Eq(Int64.of_int32(3l), 3L)), - ( - "to_int32", - _ => Eq(Array.map(Int64.to_int32, [0L, 0x0000_0000_8000_0000L]), [0l, -2147483648l]), - ), - ("discard_sign", _ => Eq(Caml_int64.discard_sign(-1L), 0x7fff_ffff_ffff_ffffL)), - ("div_mod", _ => Eq(Caml_int64.div_mod(7L, 3L), (2L, 1L))), - ("to_hex", _ => Eq(Caml_int64.to_hex(-1L), "ffffffffffffffff")), - ( - "generic_compare", - _ => Eq(generic_compare(0x0000_0001_0000_0000L, 0x0000_0000_0000_0001L) > 0, true), - ), - ( - "test_compier_literal", - _ => Eq( - 0x0000_0000_ffff_ffffL, - Int64.add(Int64.add(0x0000_0000_7fff_ffffL, 0x0000_0000_7fff_ffffL), 1L), - ), - ), - ( - "generic_compare2", - _ => Eq(generic_compare(0x0000_0000_8000_0000L, 0x0000_0000_0000_0001L) > 0, true), - ), - ("shift_left", _ => Eq(Int64.shift_left(0x00ff_ffffL, 8), 0xffff_ff00L)), - ("fib_int64", _ => Eq(fib(1000, 1L, 2L), -8549408682174725832L)), - ("fac_int64", _ => Eq(fac(30, 1L), -8764578968847253504L)), - ( - __LOC__, - _ => Eq( - { - open Int64 - add(max_int, max_int) - }, - -2L, - ), - ), - ( - __LOC__, - _ => Eq( - { - open Int64 - add(min_int, min_int) - }, - 0L, - ), - ), - ( - __LOC__, - _ => Eq( - { - open Int64 - add(0x1111_1111_1111_1111L, 0xeeee_eeee_eeee_eeeeL) - }, - -1L, - ), - ), - } - }, - \"@"( - { - let (a, b) = shift_left_tests - Array.to_list( - Ext_array_test.map2i( - (i, a, b) => ("shift_left_cases " ++ __unsafe_cast(i), _ => Mt.Eq(a, b)), - a, - b, - ), - ) - }, - \"@"( - { - let (a, b) = shift_right_tests - Array.to_list( - Ext_array_test.map2i( - (i, a, b) => ("shift_right_cases " ++ __unsafe_cast(i), _ => Mt.Eq(a, b)), - a, - b, - ), - ) - }, - { - let (a, b) = shift_right_logical_suites - Array.to_list( - Ext_array_test.map2i( - (i, a, b) => ("shift_right_logical_cases " ++ __unsafe_cast(i), _ => Mt.Eq(a, b)), - a, - b, - ), - ) - }, - ), - ), -) - -let suites = ref(suites) -let test_id = ref(0) -let eq = (loc, x, y) => Mt.eq_suites(~test_id, ~suites, loc, x, y) - -let id = (loc, x: int64) => { - /* This is not a round trip, since NaN is not distinguishable in JS */ - let float_value = Int64.float_of_bits(x) - switch classify_float(float_value) { - | FP_nan => () - | _ => eq(loc, Int64.bits_of_float(float_value), x) - } -} - -let () = { - open Int64 - eq(__LOC__, Int64.bits_of_float(0.3), 4599075939470750515L) - eq(__LOC__, Int64.float_of_bits(4599075939470750515L), 0.3) - id(__LOC__, -1L) - id(__LOC__, -100L) - id(__LOC__, 0xff_ff_ff_ffL) - id(__LOC__, 0x1f_ff_ff_ffL) - id(__LOC__, 0x1f_ff_fe_ffL) - eq( - __LOC__, - { - open Int64 - div(min_int, 10L) - }, - -922337203685477580L, - ) - eq( - __LOC__, - { - open Int64 - to_string(div(min_int, 10L)) - }, - "-922337203685477580", - ) - eq( - __LOC__, - { - open Int64 - mul(min_int, 10L) - }, - 0L, - ) - eq( - __LOC__, - { - open Int64 - mul(10L, min_int) - }, - 0L, - ) - eq( - __LOC__, - { - open Int64 - mul(1L, min_int) - }, - min_int, - ) - eq( - __LOC__, - { - open Int64 - mul(max_int, 10L) - }, - -10L, - ) - eq( - __LOC__, - { - open Int64 - succ(max_int) - }, - min_int, - ) - eq( - __LOC__, - { - open Int64 - succ(min_int) - }, - -9223372036854775807L, - ) - eq(__LOC__, succ(0xffff_ffffL), 0x1_0000_0000L) -} -Mt.from_pair_suites(__MODULE__, suites.contents) diff --git a/jscomp/test/int_hashtbl_test.js b/jscomp/test/int_hashtbl_test.js deleted file mode 100644 index 27976bf186..0000000000 --- a/jscomp/test/int_hashtbl_test.js +++ /dev/null @@ -1,100 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let Caml = require("../../lib/js/caml.js"); -let List = require("../../lib/js/list.js"); -let $$Array = require("../../lib/js/array.js"); -let Hashtbl = require("../../lib/js/hashtbl.js"); - -function f(H) { - let tbl = H.create(17); - H.add(tbl, 1, /* '1' */49); - H.add(tbl, 2, /* '2' */50); - let extra = H.fold((k, v, acc) => ({ - hd: [ - k, - v - ], - tl: acc - }), tbl, /* [] */0); - return List.sort((param, param$1) => Caml.int_compare(param[0], param$1[0]), extra); -} - -function g(H, count) { - let tbl = H.create(17); - for (let i = 0; i <= count; ++i) { - H.replace(tbl, (i << 1), String(i)); - } - for (let i$1 = 0; i$1 <= count; ++i$1) { - H.replace(tbl, (i$1 << 1), String(i$1)); - } - let v = H.fold((k, v, acc) => ({ - hd: [ - k, - v - ], - tl: acc - }), tbl, /* [] */0); - return $$Array.of_list(List.sort((param, param$1) => Caml.int_compare(param[0], param$1[0]), v)); -} - -let hash = Hashtbl.hash; - -function equal(x, y) { - return x === y; -} - -let Int_hash = Hashtbl.Make({ - equal: equal, - hash: hash -}); - -let suites_0 = [ - "simple", - param => ({ - TAG: "Eq", - _0: { - hd: [ - 1, - /* '1' */49 - ], - tl: { - hd: [ - 2, - /* '2' */50 - ], - tl: /* [] */0 - } - }, - _1: f(Int_hash) - }) -]; - -let suites_1 = { - hd: [ - "more_iterations", - param => ({ - TAG: "Eq", - _0: $$Array.init(1001, i => [ - (i << 1), - String(i) - ]), - _1: g(Int_hash, 1000) - }) - ], - tl: /* [] */0 -}; - -let suites = { - hd: suites_0, - tl: suites_1 -}; - -Mt.from_pair_suites("Int_hashtbl_test", suites); - -exports.f = f; -exports.g = g; -exports.Int_hash = Int_hash; -exports.suites = suites; -/* Int_hash Not a pure module */ diff --git a/jscomp/test/int_hashtbl_test.res b/jscomp/test/int_hashtbl_test.res deleted file mode 100644 index 73f8e04b3d..0000000000 --- a/jscomp/test/int_hashtbl_test.res +++ /dev/null @@ -1,54 +0,0 @@ -open Hashtbl - -module type S = Hashtbl.S with type key = int - -/* -let to_list (module H : S) (tbl : 'a H.t) = - H.fold (fun k v acc -> (k,v)::acc) tbl [] -*/ - -let f = (module(H: Hashtbl.S with type key = int)) => { - /* let module Hashtbl = (val Hashtbl) in */ - let tbl = H.create(17) - H.add(tbl, 1, '1') - H.add(tbl, 2, '2') - \"@@"( - List.sort(((a: int, _), (b, _)) => compare(a, b), ...), - H.fold((k, v, acc) => list{(k, v), ...acc}, tbl, list{}) - ) -} - -let g = (module(H: S), count) => { - let tbl = H.create(17) - for i in 0 to count { - H.replace(tbl, i * 2, string_of_int(i)) - } - for i in 0 to count { - H.replace(tbl, i * 2, string_of_int(i)) - } - let v = H.fold((k, v, acc) => list{(k, v), ...acc}, tbl, list{}) - let v = \"@@"(List.sort(((x, _), (y: int, _)) => compare(x, y), ...), v) - Array.of_list(v) -} - -module Int_hash = Hashtbl.Make({ - type t = int - let hash = x => Hashtbl.hash(x) - let equal = (x: int, y) => x == y -}) - -let suites = { - open Mt - list{ - ("simple", _ => Eq(list{(1, '1'), (2, '2')}, f(module(Int_hash)))), - ( - "more_iterations", - _ => { - let count = 1000 - Eq(Array.init(count + 1, i => (2 * i, string_of_int(i))), g(module(Int_hash), count)) - }, - ), - } -} - -Mt.from_pair_suites(__MODULE__, suites) diff --git a/jscomp/test/int_map.js b/jscomp/test/int_map.js index 23f88f7c66..a7d43f7c06 100644 --- a/jscomp/test/int_map.js +++ b/jscomp/test/int_map.js @@ -1,993 +1,24 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml = require("../../lib/js/caml.js"); -let Caml_option = require("../../lib/js/caml_option.js"); +let Belt_Map = require("../../lib/js/belt_Map.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); -function height(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} +let cmp = Primitive_object.compare; -function create(l, x, d, r) { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} +let IntCmp = { + cmp: cmp +}; -function singleton(x, d) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: d, - r: "Empty", - h: 1 - }; -} +let m_cmp = IntCmp.cmp; -function bal(l, x, d, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; -} +let m = { + cmp: m_cmp, + data: undefined +}; -function is_empty(param) { - if (typeof param !== "object") { - return true; - } else { - return false; - } -} +let m$1 = Belt_Map.set(m, 0, "test"); -function add(x, data, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml.int_compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function find(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let c = Caml.int_compare(x, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function find_first(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_first_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_last(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_last_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_opt(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let c = Caml.int_compare(x, param.v); - if (c === 0) { - return Caml_option.some(param.d); - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function mem(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = Caml.int_compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function min_binding(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; -} - -function min_binding_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; -} - -function max_binding(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; -} - -function max_binding_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; -} - -function remove_min_binding(param) { - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.remove_min_elt", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_binding(l), param.v, param.d, param.r); - } -} - -function merge(t1, t2) { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return bal(t1, match[0], match[1], remove_min_binding(t2)); -} - -function remove(x, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml.int_compare(x, v); - if (c === 0) { - return merge(l, r); - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function update(x, f, param) { - if (typeof param !== "object") { - let data = f(undefined); - if (data !== undefined) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: Caml_option.valFromOption(data), - r: "Empty", - h: 1 - }; - } else { - return "Empty"; - } - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml.int_compare(x, v); - if (c === 0) { - let data$1 = f(Caml_option.some(d)); - if (data$1 === undefined) { - return merge(l, r); - } - let data$2 = Caml_option.valFromOption(data$1); - if (d === data$2) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data$2, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = update(x, f, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = update(x, f, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function iter(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v, param.d); - _param = param.r; - continue; - }; -} - -function map(f, param) { - if (typeof param !== "object") { - return "Empty"; - } - let l$p = map(f, param.l); - let d$p = f(param.d); - let r$p = map(f, param.r); - return { - TAG: "Node", - l: l$p, - v: param.v, - d: d$p, - r: r$p, - h: param.h - }; -} - -function mapi(f, param) { - if (typeof param !== "object") { - return "Empty"; - } - let v = param.v; - let l$p = mapi(f, param.l); - let d$p = f(v, param.d); - let r$p = mapi(f, param.r); - return { - TAG: "Node", - l: l$p, - v: v, - d: d$p, - r: r$p, - h: param.h - }; -} - -function fold(f, _m, _accu) { - while (true) { - let accu = _accu; - let m = _m; - if (typeof m !== "object") { - return accu; - } - _accu = f(m.v, m.d, fold(f, m.l, accu)); - _m = m.r; - continue; - }; -} - -function for_all(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v, param.d)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; -} - -function exists(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v, param.d)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; -} - -function add_min_binding(k, x, param) { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(add_min_binding(k, x, param.l), param.v, param.d, param.r); - } -} - -function add_max_binding(k, x, param) { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(param.l, param.v, param.d, add_max_binding(k, x, param.r)); - } -} - -function join(l, v, d, r) { - if (typeof l !== "object") { - return add_min_binding(v, d, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_binding(v, d, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, l.d, join(l.r, v, d, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, d, r.l), r.v, r.d, r.r); - } else { - return create(l, v, d, r); - } -} - -function concat(t1, t2) { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return join(t1, match[0], match[1], remove_min_binding(t2)); -} - -function concat_or_join(t1, v, d, t2) { - if (d !== undefined) { - return join(t1, v, Caml_option.valFromOption(d), t2); - } else { - return concat(t1, t2); - } -} - -function split(x, param) { - if (typeof param !== "object") { - return [ - "Empty", - undefined, - "Empty" - ]; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml.int_compare(x, v); - if (c === 0) { - return [ - l, - Caml_option.some(d), - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, d, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, d, match$1[0]), - match$1[1], - match$1[2] - ]; -} - -function merge$1(f, s1, s2) { - if (typeof s1 !== "object") { - if (typeof s2 !== "object") { - return "Empty"; - } - - } else { - let v1 = s1.v; - if (s1.h >= height(s2)) { - let match = split(v1, s2); - return concat_or_join(merge$1(f, s1.l, match[0]), v1, f(v1, Caml_option.some(s1.d), match[1]), merge$1(f, s1.r, match[2])); - } - - } - if (typeof s2 !== "object") { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "map.res", - 552, - 11 - ], - Error: new Error() - }; - } - let v2 = s2.v; - let match$1 = split(v2, s1); - return concat_or_join(merge$1(f, match$1[0], s2.l), v2, f(v2, match$1[1], Caml_option.some(s2.d)), merge$1(f, match$1[2], s2.r)); -} - -function union(f, s1, s2) { - if (typeof s1 !== "object") { - return s2; - } - let d1 = s1.d; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let d2 = s2.d; - let v2 = s2.v; - if (s1.h >= s2.h) { - let match = split(v1, s2); - let d2$1 = match[1]; - let l = union(f, s1.l, match[0]); - let r = union(f, s1.r, match[2]); - if (d2$1 !== undefined) { - return concat_or_join(l, v1, f(v1, d1, Caml_option.valFromOption(d2$1)), r); - } else { - return join(l, v1, d1, r); - } - } - let match$1 = split(v2, s1); - let d1$1 = match$1[1]; - let l$1 = union(f, match$1[0], s2.l); - let r$1 = union(f, match$1[2], s2.r); - if (d1$1 !== undefined) { - return concat_or_join(l$1, v2, f(v2, Caml_option.valFromOption(d1$1), d2), r$1); - } else { - return join(l$1, v2, d2, r$1); - } -} - -function filter(p, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pvd = p(v, d); - let r$p = filter(p, r); - if (pvd) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, d, r$p); - } - } else { - return concat(l$p, r$p); - } -} - -function partition(p, param) { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let d = param.d; - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pvd = p(v, d); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pvd) { - return [ - join(lt, v, d, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, d, rf) - ]; - } -} - -function cons_enum(_m, _e) { - while (true) { - let e = _e; - let m = _m; - if (typeof m !== "object") { - return e; - } - _e = { - TAG: "More", - _0: m.v, - _1: m.d, - _2: m.r, - _3: e - }; - _m = m.l; - continue; - }; -} - -function compare(cmp, m1, m2) { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = Caml.int_compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - let c$1 = cmp(e1._1, e2._1); - if (c$1 !== 0) { - return c$1; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; -} - -function equal(cmp, m1, m2) { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return true; - } else { - return false; - } - } - if (typeof e2 !== "object") { - return false; - } - if (e1._0 !== e2._0) { - return false; - } - if (!cmp(e1._1, e2._1)) { - return false; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; -} - -function cardinal(param) { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } -} - -function bindings_aux(_accu, _param) { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: [ - param.v, - param.d - ], - tl: bindings_aux(accu, param.r) - }; - continue; - }; -} - -function bindings(s) { - return bindings_aux(/* [] */0, s); -} - -let empty = "Empty"; - -let choose = min_binding; - -let choose_opt = min_binding_opt; - -exports.empty = empty; -exports.is_empty = is_empty; -exports.mem = mem; -exports.add = add; -exports.update = update; -exports.singleton = singleton; -exports.remove = remove; -exports.merge = merge$1; -exports.union = union; -exports.compare = compare; -exports.equal = equal; -exports.iter = iter; -exports.fold = fold; -exports.for_all = for_all; -exports.exists = exists; -exports.filter = filter; -exports.partition = partition; -exports.cardinal = cardinal; -exports.bindings = bindings; -exports.min_binding = min_binding; -exports.min_binding_opt = min_binding_opt; -exports.max_binding = max_binding; -exports.max_binding_opt = max_binding_opt; -exports.choose = choose; -exports.choose_opt = choose_opt; -exports.split = split; -exports.find = find; -exports.find_opt = find_opt; -exports.find_first = find_first; -exports.find_first_opt = find_first_opt; -exports.find_last = find_last; -exports.find_last_opt = find_last_opt; -exports.map = map; -exports.mapi = mapi; -/* No side effect */ +exports.IntCmp = IntCmp; +exports.m = m$1; +/* IntCmp Not a pure module */ diff --git a/jscomp/test/int_map.res b/jscomp/test/int_map.res index 223b4797b4..a3834063f3 100644 --- a/jscomp/test/int_map.res +++ b/jscomp/test/int_map.res @@ -1,4 +1,7 @@ -include Map.Make({ +module IntCmp = Belt.Id.MakeComparable({ type t = int - let compare = (x: int, y) => compare(x, y) + let cmp = (a, b) => Pervasives.compare(a, b) }) + +let m = Belt.Map.make(~id=module(IntCmp)) +let m = m->Belt.Map.set(0, "test") diff --git a/jscomp/test/int_overflow_test.js b/jscomp/test/int_overflow_test.js index 5b5bd932d0..68ae7452db 100644 --- a/jscomp/test/int_overflow_test.js +++ b/jscomp/test/int_overflow_test.js @@ -2,13 +2,11 @@ 'use strict'; let Mt = require("./mt.js"); -let Int32 = require("../../lib/js/int32.js"); -let Caml_string = require("../../lib/js/caml_string.js"); function hash_variant(s) { let accu = 0; for (let i = 0, i_finish = s.length; i < i_finish; ++i) { - accu = Math.imul(223, accu) + Caml_string.get(s, i) & 2147483647; + accu = Math.imul(223, accu) + s.codePointAt(i) & 2147483647; } if (accu > 1073741823) { return accu - -2147483648 | 0; @@ -20,7 +18,7 @@ function hash_variant(s) { function hash_variant2(s) { let accu = 0; for (let i = 0, i_finish = s.length; i < i_finish; ++i) { - accu = Math.imul(223, accu) + Caml_string.get(s, i) | 0; + accu = Math.imul(223, accu) + s.codePointAt(i) | 0; } accu = accu & 2147483647; if (accu > 1073741823) { @@ -44,7 +42,7 @@ Mt.from_pair_suites("Int_overflow_test", { () => ({ TAG: "Eq", _0: true, - _1: (Int32.max_int + 1 | 0) === Int32.min_int + _1: true }) ], tl: { @@ -53,7 +51,7 @@ Mt.from_pair_suites("Int_overflow_test", { () => ({ TAG: "Eq", _0: true, - _1: (Int32.min_int - Int32.one | 0) === Int32.max_int + _1: true }) ], tl: { @@ -62,7 +60,7 @@ Mt.from_pair_suites("Int_overflow_test", { () => ({ TAG: "Eq", _0: 2147483646, - _1: (Int32.max_int + Int32.max_int | 0) + Int32.min_int | 0 + _1: 2147483646 }) ], tl: { @@ -71,7 +69,7 @@ Mt.from_pair_suites("Int_overflow_test", { () => ({ TAG: "Eq", _0: -2, - _1: Int32.max_int + Int32.max_int | 0 + _1: -2 }) ], tl: { @@ -94,7 +92,7 @@ Mt.from_pair_suites("Int_overflow_test", { ], tl: { hd: [ - "File \"int_overflow_test.res\", line 88, characters 5-12", + "File \"int_overflow_test.res\", line 72, characters 5-12", () => ({ TAG: "Eq", _0: hash_variant2("xxyyzzuuxxzzyy00112233"), @@ -103,7 +101,7 @@ Mt.from_pair_suites("Int_overflow_test", { ], tl: { hd: [ - "File \"int_overflow_test.res\", line 89, characters 5-12", + "File \"int_overflow_test.res\", line 73, characters 5-12", () => ({ TAG: "Eq", _0: hash_variant2("xxyyzxzzyy"), @@ -130,43 +128,23 @@ Mt.from_pair_suites("Int_overflow_test", { ], tl: { hd: [ - "int_literal_flow3", + "File \"int_overflow_test.res\", line 76, characters 5-12", () => ({ TAG: "Eq", - _0: -1, - _1: -1 + _0: Number("3") | 0, + _1: 3 }) ], tl: { hd: [ - "int32_mul", + "File \"int_overflow_test.res\", line 78, characters 5-12", () => ({ TAG: "Eq", - _0: -33554431, - _1: -33554431 + _0: Number("3.2") | 0, + _1: 3 }) ], - tl: { - hd: [ - "File \"int_overflow_test.res\", line 94, characters 5-12", - () => ({ - TAG: "Eq", - _0: Number("3") | 0, - _1: 3 - }) - ], - tl: { - hd: [ - "File \"int_overflow_test.res\", line 96, characters 5-12", - () => ({ - TAG: "Eq", - _0: Number("3.2") | 0, - _1: 3 - }) - ], - tl: /* [] */0 - } - } + tl: /* [] */0 } } } @@ -180,6 +158,12 @@ Mt.from_pair_suites("Int_overflow_test", { } }); +let max_int = 2147483647; + +let min_int = -2147483648; + +exports.max_int = max_int; +exports.min_int = min_int; exports.hash_variant = hash_variant; exports.hash_variant2 = hash_variant2; exports.fib = fib; diff --git a/jscomp/test/int_overflow_test.res b/jscomp/test/int_overflow_test.res index 598e060ffe..018a004720 100644 --- a/jscomp/test/int_overflow_test.res +++ b/jscomp/test/int_overflow_test.res @@ -1,4 +1,8 @@ @@warning("-107") + +let max_int = 2147483647 // 0x80000000 +let min_int = -2147483648 // 0x7FFFFFFF + let hash_variant = s => { let accu = ref(0) for i in 0 to String.length(s) - 1 { @@ -36,50 +40,30 @@ let hash_variant2 = s => { let rec fib = x => switch x { - | 0l | 1l => 1l - | n => Int32.add(fib(Int32.sub(n, 1l)), fib(Int32.sub(n, 2l))) + | 0 | 1 => 1 + | n => fib(n - 1l) + fib(n - 2) } Mt.from_pair_suites( __MODULE__, list{ - ( - "plus_overflow", - _ => Eq( - true, - { - open Int32 - add(max_int, 1l) - } == Int32.min_int, - ), - ), - ( - "minus_overflow", - _ => Eq( - true, - { - open Int32 - sub(min_int, one) - } == Int32.max_int, - ), - ), + ("plus_overflow", _ => Eq(true, max_int + 1 == min_int)), + ("minus_overflow", _ => Eq(true, min_int - 1 == max_int)), ( "flow_again", _ => Eq( - 2147483646l, + 2147483646, { - open Int32 - add(add(max_int, max_int), min_int) + max_int + max_int + min_int }, ), ), ( "flow_again", _ => Eq( - -2l, + -2, { - open Int32 - add(max_int, max_int) + max_int + max_int }, ), ), @@ -88,9 +72,7 @@ Mt.from_pair_suites( (__LOC__, _ => Eq(hash_variant2("xxyyzzuuxxzzyy00112233"), 544087776)), (__LOC__, _ => Eq(hash_variant2("xxyyzxzzyy"), -449896130)), ("int_literal_flow", _ => Eq(-1, 0xffffffff)), - ("int_literal_flow2", _ => Eq(-1l, Int32.of_int(0xffffffff))), - ("int_literal_flow3", _ => Eq(-1l, Int32.of_int(0xfffffffff))), - ("int32_mul", _ => Eq(-33554431l, Int32.mul(0xffffffl, 0xffffffl))), + ("int_literal_flow2", _ => Eq(-1, 0xfffffffff)), (__LOC__, _ => Eq(\"@@"(int_of_float, Js.Float.fromString("3")), 3)), /* FIXME */ (__LOC__, _ => Eq(\"@@"(int_of_float, Js.Float.fromString("3.2")), 3)), diff --git a/jscomp/test/int_poly_var.js b/jscomp/test/int_poly_var.js index 6fa3335c9d..2b8b98f150 100644 --- a/jscomp/test/int_poly_var.js +++ b/jscomp/test/int_poly_var.js @@ -165,7 +165,7 @@ function f(x) { if (x.NAME === 1) { return x.VAL; } else { - return String(x.VAL); + return x.VAL.toString(); } } diff --git a/jscomp/test/int_poly_var.res b/jscomp/test/int_poly_var.res index 351fc0ee99..25d3b9a5ba 100644 --- a/jscomp/test/int_poly_var.res +++ b/jscomp/test/int_poly_var.res @@ -94,7 +94,7 @@ type u = [#0(int) | #1(string)] let f = (x: u) => { switch x { - | #0(x) => string_of_int(x) + | #0(x) => Js.Int.toString(x) | #1(x) => x } } diff --git a/jscomp/test/internal_unused_test.js b/jscomp/test/internal_unused_test.js index 222fa625c9..8a3d3d5a46 100644 --- a/jscomp/test/internal_unused_test.js +++ b/jscomp/test/internal_unused_test.js @@ -1,11 +1,11 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); console.log(3); -let A = /* @__PURE__ */Caml_exceptions.create("Internal_unused_test.P1.A"); +let A = /* @__PURE__ */Primitive_exceptions.create("Internal_unused_test.P1.A"); function f() { throw { diff --git a/jscomp/test/io_test.js b/jscomp/test/io_test.js deleted file mode 100644 index d7fdad7cbe..0000000000 --- a/jscomp/test/io_test.js +++ /dev/null @@ -1,13 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - - -function f() { - console.error("x"); - console.log(); - console.log("hi"); - console.log(); -} - -exports.f = f; -/* No side effect */ diff --git a/jscomp/test/io_test.res b/jscomp/test/io_test.res deleted file mode 100644 index 7fa509444a..0000000000 --- a/jscomp/test/io_test.res +++ /dev/null @@ -1,6 +0,0 @@ -let f = () => { - let v = prerr_endline("x") - Js.log(v) - let u = print_endline("hi") - Js.log(u) -} diff --git a/jscomp/test/js_array_test.js b/jscomp/test/js_array_test.js index fa7a168a30..a4b2cad155 100644 --- a/jscomp/test/js_array_test.js +++ b/jscomp/test/js_array_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); let suites_0 = [ "isArray_array", @@ -155,7 +155,7 @@ let suites_1 = { param => ({ TAG: "Eq", _0: 3, - _1: Caml_option.undefined_to_opt([ + _1: Primitive_option.fromUndefined([ 1, 2, 3 @@ -168,7 +168,7 @@ let suites_1 = { param => ({ TAG: "Eq", _0: undefined, - _1: Caml_option.undefined_to_opt([].pop()) + _1: Primitive_option.fromUndefined([].pop()) }) ], tl: { @@ -220,7 +220,7 @@ let suites_1 = { param => ({ TAG: "Eq", _0: 1, - _1: Caml_option.undefined_to_opt([ + _1: Primitive_option.fromUndefined([ 1, 2, 3 @@ -233,7 +233,7 @@ let suites_1 = { param => ({ TAG: "Eq", _0: undefined, - _1: Caml_option.undefined_to_opt([].shift()) + _1: Primitive_option.fromUndefined([].shift()) }) ], tl: { @@ -694,7 +694,7 @@ let suites_1 = { param => ({ TAG: "Eq", _0: 2, - _1: Caml_option.undefined_to_opt([ + _1: Primitive_option.fromUndefined([ 1, 2, 3, @@ -708,7 +708,7 @@ let suites_1 = { param => ({ TAG: "Eq", _0: undefined, - _1: Caml_option.undefined_to_opt([ + _1: Primitive_option.fromUndefined([ 1, 2, 3, @@ -722,7 +722,7 @@ let suites_1 = { param => ({ TAG: "Eq", _0: 1, - _1: Caml_option.undefined_to_opt([ + _1: Primitive_option.fromUndefined([ 1, 2, 3, @@ -736,7 +736,7 @@ let suites_1 = { param => ({ TAG: "Eq", _0: undefined, - _1: Caml_option.undefined_to_opt([ + _1: Primitive_option.fromUndefined([ 1, 2, 3, diff --git a/jscomp/test/js_cast_test.js b/jscomp/test/js_cast_test.js index c392fd4587..f4730c7c66 100644 --- a/jscomp/test/js_cast_test.js +++ b/jscomp/test/js_cast_test.js @@ -13,7 +13,7 @@ let counter = { function add_test(loc, test) { counter.contents = counter.contents + 1 | 0; - let id = loc + (" id " + String(counter.contents)); + let id = loc + (" id " + counter.contents.toString()); suites.contents = { hd: [ id, diff --git a/jscomp/test/js_cast_test.res b/jscomp/test/js_cast_test.res index 8ac03da11e..b38c6ea5b2 100644 --- a/jscomp/test/js_cast_test.res +++ b/jscomp/test/js_cast_test.res @@ -4,7 +4,7 @@ let add_test = { let counter = ref(0) (loc, test) => { incr(counter) - let id = loc ++ (" id " ++ string_of_int(counter.contents)) + let id = loc ++ (" id " ++ Js.Int.toString(counter.contents)) suites := list{(id, test), ...suites.contents} } } diff --git a/jscomp/test/js_date_test.js b/jscomp/test/js_date_test.js index eb79311a2c..486b0065df 100644 --- a/jscomp/test/js_date_test.js +++ b/jscomp/test/js_date_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); function date() { return new Date("1976-03-08T12:34:56.789+01:23"); @@ -971,7 +971,7 @@ let suites_1 = { let c = new Date("2013-03-01T01:10:01"); return { TAG: "Ok", - _0: Caml_obj.equal(a, b) && Caml_obj.notequal(b, c) && Caml_obj.greaterthan(c, b) + _0: Primitive_object.equal(a, b) && Primitive_object.notequal(b, c) && Primitive_object.greaterthan(c, b) }; } ], diff --git a/jscomp/test/js_dict_test.js b/jscomp/test/js_dict_test.js index 231646783a..0e1500c1d8 100644 --- a/jscomp/test/js_dict_test.js +++ b/jscomp/test/js_dict_test.js @@ -207,7 +207,7 @@ let suites_1 = { foo: "43", bar: "86" }, - _1: Js_dict.map(i => String(i), { + _1: Js_dict.map(i => i.toString(), { foo: 43, bar: 86 }) diff --git a/jscomp/test/js_dict_test.res b/jscomp/test/js_dict_test.res index e1e1716c7c..de04f49b66 100644 --- a/jscomp/test/js_dict_test.res +++ b/jscomp/test/js_dict_test.res @@ -24,7 +24,7 @@ let suites = { ("fromList", _ => Eq([("x", 23), ("y", 46)], entries(fromList(list{("x", 23), ("y", 46)})))), ("fromArray - []", _ => Eq(empty(), fromArray([]))), ("fromArray", _ => Eq([("x", 23), ("y", 46)], entries(fromArray([("x", 23), ("y", 46)])))), - ("map", _ => Eq(Obj.magic({"foo": "43", "bar": "86"}), map(i => string_of_int(i), obj()))), + ("map", _ => Eq(Obj.magic({"foo": "43", "bar": "86"}), map(i => Js.Int.toString(i), obj()))), } } Mt.from_pair_suites(__MODULE__, suites) diff --git a/jscomp/test/js_exception_catch_test.js b/jscomp/test/js_exception_catch_test.js index 7bdbb1b6b4..93adab1fc8 100644 --- a/jscomp/test/js_exception_catch_test.js +++ b/jscomp/test/js_exception_catch_test.js @@ -3,8 +3,7 @@ let Mt = require("./mt.js"); let Js_exn = require("../../lib/js/js_exn.js"); -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); let suites = { contents: /* [] */0 @@ -16,7 +15,7 @@ let counter = { function add_test(loc, test) { counter.contents = counter.contents + 1 | 0; - let id = loc + (" id " + String(counter.contents)); + let id = loc + (" id " + counter.contents.toString()); suites.contents = { hd: [ id, @@ -56,7 +55,7 @@ try { e = JSON.parse(" {\"x\"}"); exit = 1; } catch (raw_x) { - let x = Caml_js_exceptions.internalToOCamlException(raw_x); + let x = Primitive_exceptions.internalToException(raw_x); if (x.RE_EXN_ID === Js_exn.$$Error) { add_test("File \"js_exception_catch_test.res\", line 18, characters 37-44", () => ({ TAG: "Ok", @@ -74,18 +73,18 @@ if (exit === 1) { })); } -let A = /* @__PURE__ */Caml_exceptions.create("Js_exception_catch_test.A"); +let A = /* @__PURE__ */Primitive_exceptions.create("Js_exception_catch_test.A"); -let B = /* @__PURE__ */Caml_exceptions.create("Js_exception_catch_test.B"); +let B = /* @__PURE__ */Primitive_exceptions.create("Js_exception_catch_test.B"); -let C = /* @__PURE__ */Caml_exceptions.create("Js_exception_catch_test.C"); +let C = /* @__PURE__ */Primitive_exceptions.create("Js_exception_catch_test.C"); function test(f) { try { f(); return "No_error"; } catch (raw_e) { - let e = Caml_js_exceptions.internalToOCamlException(raw_e); + let e = Primitive_exceptions.internalToException(raw_e); if (e.RE_EXN_ID === "Not_found") { return "Not_found"; } else if (e.RE_EXN_ID === "Invalid_argument") { diff --git a/jscomp/test/js_exception_catch_test.res b/jscomp/test/js_exception_catch_test.res index 899a4f84f2..ee05cb00d6 100644 --- a/jscomp/test/js_exception_catch_test.res +++ b/jscomp/test/js_exception_catch_test.res @@ -4,7 +4,7 @@ let add_test = { let counter = ref(0) (loc, test) => { incr(counter) - let id = loc ++ (" id " ++ string_of_int(counter.contents)) + let id = loc ++ (" id " ++ Js.Int.toString(counter.contents)) suites := list{(id, test), ...suites.contents} } } diff --git a/jscomp/test/js_json_test.js b/jscomp/test/js_json_test.js index 54f2384053..08721785fa 100644 --- a/jscomp/test/js_json_test.js +++ b/jscomp/test/js_json_test.js @@ -2,13 +2,12 @@ 'use strict'; let Mt = require("./mt.js"); -let $$Array = require("../../lib/js/array.js"); let Js_dict = require("../../lib/js/js_dict.js"); let Js_json = require("../../lib/js/js_json.js"); let Belt_List = require("../../lib/js/belt_List.js"); let Belt_Array = require("../../lib/js/belt_Array.js"); -let Caml_array = require("../../lib/js/caml_array.js"); -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_array = require("../../lib/js/primitive_array.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); let suites = { contents: /* [] */0 @@ -20,7 +19,7 @@ let counter = { function add_test(loc, test) { counter.contents = counter.contents + 1 | 0; - let id = loc + (" id " + String(counter.contents)); + let id = loc + (" id " + counter.contents.toString()); suites.contents = { hd: [ id, @@ -231,7 +230,7 @@ test(false); function option_get(x) { if (x !== undefined) { - return Caml_option.valFromOption(x); + return Primitive_option.valFromOption(x); } throw { RE_EXN_ID: "Assert_failure", @@ -321,7 +320,7 @@ function eq_at_i(loc, json, i, kind, expected) { _0: false })); } - let ty$1 = Js_json.classify(Caml_array.get(ty._0, i)); + let ty$1 = Js_json.classify(Primitive_array.get(ty._0, i)); switch (kind) { case "String" : if (typeof ty$1 !== "object") { @@ -419,11 +418,11 @@ function eq_at_i(loc, json, i, kind, expected) { } } -let json$5 = JSON.parse(JSON.stringify($$Array.map(prim => prim, [ +let json$5 = JSON.parse(JSON.stringify(Belt_Array.map([ "string 0", "string 1", "string 2" -]))); +], prim => prim))); eq_at_i("File \"js_json_test.res\", line 198, characters 10-17", json$5, 0, "String", "string 0"); @@ -451,11 +450,11 @@ let a = [ let json$7 = JSON.parse(JSON.stringify(a)); -eq_at_i("File \"js_json_test.res\", line 218, characters 10-17", json$7, 0, "Number", Caml_array.get(a, 0)); +eq_at_i("File \"js_json_test.res\", line 218, characters 10-17", json$7, 0, "Number", Primitive_array.get(a, 0)); -eq_at_i("File \"js_json_test.res\", line 219, characters 10-17", json$7, 1, "Number", Caml_array.get(a, 1)); +eq_at_i("File \"js_json_test.res\", line 219, characters 10-17", json$7, 1, "Number", Primitive_array.get(a, 1)); -eq_at_i("File \"js_json_test.res\", line 220, characters 10-17", json$7, 2, "Number", Caml_array.get(a, 2)); +eq_at_i("File \"js_json_test.res\", line 220, characters 10-17", json$7, 2, "Number", Primitive_array.get(a, 2)); let a$1 = [ 0, @@ -463,13 +462,13 @@ let a$1 = [ -268391749 ]; -let json$8 = JSON.parse(JSON.stringify($$Array.map(prim => prim, a$1))); +let json$8 = JSON.parse(JSON.stringify(Belt_Array.map(a$1, prim => prim))); -eq_at_i("File \"js_json_test.res\", line 229, characters 10-17", json$8, 0, "Number", Caml_array.get(a$1, 0)); +eq_at_i("File \"js_json_test.res\", line 229, characters 10-17", json$8, 0, "Number", Primitive_array.get(a$1, 0)); -eq_at_i("File \"js_json_test.res\", line 230, characters 10-17", json$8, 1, "Number", Caml_array.get(a$1, 1)); +eq_at_i("File \"js_json_test.res\", line 230, characters 10-17", json$8, 1, "Number", Primitive_array.get(a$1, 1)); -eq_at_i("File \"js_json_test.res\", line 231, characters 10-17", json$8, 2, "Number", Caml_array.get(a$1, 2)); +eq_at_i("File \"js_json_test.res\", line 231, characters 10-17", json$8, 2, "Number", Primitive_array.get(a$1, 2)); let a$2 = [ true, @@ -479,11 +478,11 @@ let a$2 = [ let json$9 = JSON.parse(JSON.stringify(a$2)); -eq_at_i("File \"js_json_test.res\", line 240, characters 10-17", json$9, 0, "Boolean", Caml_array.get(a$2, 0)); +eq_at_i("File \"js_json_test.res\", line 240, characters 10-17", json$9, 0, "Boolean", Primitive_array.get(a$2, 0)); -eq_at_i("File \"js_json_test.res\", line 241, characters 10-17", json$9, 1, "Boolean", Caml_array.get(a$2, 1)); +eq_at_i("File \"js_json_test.res\", line 241, characters 10-17", json$9, 1, "Boolean", Primitive_array.get(a$2, 1)); -eq_at_i("File \"js_json_test.res\", line 242, characters 10-17", json$9, 2, "Boolean", Caml_array.get(a$2, 2)); +eq_at_i("File \"js_json_test.res\", line 242, characters 10-17", json$9, 2, "Boolean", Primitive_array.get(a$2, 2)); function make_d(s, i) { let d = {}; @@ -507,7 +506,7 @@ if (typeof ty$6 !== "object") { _0: false })); } else if (ty$6.TAG === "JSONArray") { - let ty$7 = Js_json.classify(Caml_array.get(ty$6._0, 1)); + let ty$7 = Js_json.classify(Primitive_array.get(ty$6._0, 1)); if (typeof ty$7 !== "object") { add_test("File \"js_json_test.res\", line 268, characters 18-25", () => ({ TAG: "Ok", diff --git a/jscomp/test/js_json_test.res b/jscomp/test/js_json_test.res index 2d0891af31..58e03d5e80 100644 --- a/jscomp/test/js_json_test.res +++ b/jscomp/test/js_json_test.res @@ -5,7 +5,7 @@ let add_test = { let counter = ref(0) (loc, test) => { incr(counter) - let id = loc ++ (" id " ++ string_of_int(counter.contents)) + let id = loc ++ (" id " ++ Js.Int.toString(counter.contents)) suites := list{(id, test), ...suites.contents} } } @@ -192,7 +192,7 @@ let eq_at_i = (type a, loc: string, json: J.t, i: int, kind: J.Kind.t, expect let () = { let json = J.parseExn( - J.stringify(J.array(Array.map(J.string, ["string 0", "string 1", "string 2"]))), + J.stringify(J.array(Belt.Array.map(["string 0", "string 1", "string 2"], J.string))), ) eq_at_i(__LOC__, json, 0, J.Kind.String, "string 0") @@ -223,7 +223,7 @@ let () = { let () = { let a = [0, 0xAFAFAFAF, 0xF000AABB] - let json = J.parseExn(J.stringify(J.numberArray(Array.map(float_of_int, a)))) + let json = J.parseExn(J.stringify(J.numberArray(a->Belt.Array.map(float_of_int)))) /* Loop is unrolled to keep relevant location information */ eq_at_i(__LOC__, json, 0, J.Kind.Number, float_of_int(a[0])) diff --git a/jscomp/test/js_null_test.js b/jscomp/test/js_null_test.js index abcceec261..9d6c11bc03 100644 --- a/jscomp/test/js_null_test.js +++ b/jscomp/test/js_null_test.js @@ -3,7 +3,7 @@ let Mt = require("./mt.js"); let Js_null = require("../../lib/js/js_null.js"); -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); let suites_0 = [ "toOption - empty", @@ -19,8 +19,8 @@ let suites_1 = { "toOption - 'a", param => ({ TAG: "Eq", - _0: Caml_option.some(undefined), - _1: Caml_option.some() + _0: Primitive_option.some(undefined), + _1: Primitive_option.some() }) ], tl: { @@ -29,7 +29,7 @@ let suites_1 = { param => ({ TAG: "Eq", _0: "something", - _1: Caml_option.null_to_opt("something") + _1: Primitive_option.fromNull("something") }) ], tl: { diff --git a/jscomp/test/js_null_undefined_test.js b/jscomp/test/js_null_undefined_test.js index b57628e898..bfbb6e7223 100644 --- a/jscomp/test/js_null_undefined_test.js +++ b/jscomp/test/js_null_undefined_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); let Js_null_undefined = require("../../lib/js/js_null_undefined.js"); let suites_0 = [ @@ -38,7 +38,7 @@ let suites_1 = { param => ({ TAG: "Eq", _0: "foo", - _1: Caml_option.nullable_to_opt("foo") + _1: Primitive_option.fromNullable("foo") }) ], tl: { @@ -47,7 +47,7 @@ let suites_1 = { param => ({ TAG: "Eq", _0: "something", - _1: Caml_option.nullable_to_opt("something") + _1: Primitive_option.fromNullable("something") }) ], tl: { diff --git a/jscomp/test/js_nullable_test.js b/jscomp/test/js_nullable_test.js index 15f396e862..1fe258c0b8 100644 --- a/jscomp/test/js_nullable_test.js +++ b/jscomp/test/js_nullable_test.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -41,13 +41,13 @@ function f(x, y) { return x + y | 0; } -eq("File \"js_nullable_test.res\", line 28, characters 3-10", false, false); +eq("File \"js_nullable_test.res\", line 31, characters 3-10", false, false); -eq("File \"js_nullable_test.res\", line 30, characters 3-10", (f(1, 2) == null), false); +eq("File \"js_nullable_test.res\", line 33, characters 3-10", (f(1, 2) == null), false); -eq("File \"js_nullable_test.res\", line 32, characters 3-10", (null == null), true); +eq("File \"js_nullable_test.res\", line 35, characters 3-10", (null == null), true); -eq("File \"js_nullable_test.res\", line 37, characters 5-12", false, false); +eq("File \"js_nullable_test.res\", line 40, characters 5-12", false, false); Mt.from_pair_suites("Js_nullable_test", suites.contents); diff --git a/jscomp/test/js_nullable_test.res b/jscomp/test/js_nullable_test.res index 114ea2e721..f60f58c69c 100644 --- a/jscomp/test/js_nullable_test.res +++ b/jscomp/test/js_nullable_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } type element diff --git a/jscomp/test/js_obj_test.res b/jscomp/test/js_obj_test.res index 8787d2f367..985ebe6fb2 100644 --- a/jscomp/test/js_obj_test.res +++ b/jscomp/test/js_obj_test.res @@ -5,7 +5,7 @@ type x = {"say": int => int} let suites = { open Mt list{ - ("empty", _ => Eq(0, Array.length(keys(empty())))), + ("empty", _ => Eq(0, Belt.Array.length(keys(empty())))), ("assign", _ => Eq({"a": 1}, assign(empty(), {"a": 1}))), } } diff --git a/jscomp/test/js_re_test.js b/jscomp/test/js_re_test.js index 2fdc4f2d08..f5c422c961 100644 --- a/jscomp/test/js_re_test.js +++ b/jscomp/test/js_re_test.js @@ -2,8 +2,8 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_array = require("../../lib/js/caml_array.js"); -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_array = require("../../lib/js/primitive_array.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); let suites_0 = [ "captures", @@ -16,8 +16,8 @@ let suites_0 = [ _0: undefined }; } - let defined = Caml_array.get(result, 1); - let $$undefined = Caml_array.get(result, 2); + let defined = Primitive_array.get(result, 1); + let $$undefined = Primitive_array.get(result, 2); return { TAG: "Eq", _0: [ @@ -37,9 +37,9 @@ let suites_1 = { "fromString", param => { let contentOf = (tag, xmlString) => { - let x = Caml_option.null_to_opt(new RegExp("<" + (tag + (">(.*?)<\\/" + (tag + ">")))).exec(xmlString)); + let x = Primitive_option.fromNull(new RegExp("<" + (tag + (">(.*?)<\\/" + (tag + ">")))).exec(xmlString)); if (x !== undefined) { - return Caml_option.nullable_to_opt(Caml_array.get(Caml_option.valFromOption(x), 1)); + return Primitive_option.fromNullable(Primitive_array.get(Primitive_option.valFromOption(x), 1)); } }; @@ -59,7 +59,7 @@ let suites_1 = { return { TAG: "Eq", _0: "http://xxx", - _1: Caml_array.get(res, 0) + _1: Primitive_array.get(res, 0) }; } else { return { diff --git a/jscomp/test/js_string_test.js b/jscomp/test/js_string_test.js index d5b774d8e8..071c564cd2 100644 --- a/jscomp/test/js_string_test.js +++ b/jscomp/test/js_string_test.js @@ -3,7 +3,7 @@ let Mt = require("./mt.js"); let Belt_Option = require("../../lib/js/belt_Option.js"); -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); let suites_0 = [ "make", @@ -212,7 +212,7 @@ let suites_1 = { "na", "na" ], - _1: Caml_option.null_to_opt("banana".match(/na+/g)) + _1: Primitive_option.fromNull("banana".match(/na+/g)) }) ], tl: { @@ -221,7 +221,7 @@ let suites_1 = { param => ({ TAG: "Eq", _0: undefined, - _1: Caml_option.null_to_opt("banana".match(/nanana+/g)) + _1: Primitive_option.fromNull("banana".match(/nanana+/g)) }) ], tl: { @@ -233,7 +233,7 @@ let suites_1 = { "hello ", undefined ], - _1: Belt_Option.map(Caml_option.null_to_opt("hello word".match(/hello (world)?/)), prim => prim.slice()) + _1: Belt_Option.map(Primitive_option.fromNull("hello word".match(/hello (world)?/)), prim => prim.slice()) }) ], tl: { diff --git a/jscomp/test/js_undefined_test.js b/jscomp/test/js_undefined_test.js index 9f424779e2..7b239df178 100644 --- a/jscomp/test/js_undefined_test.js +++ b/jscomp/test/js_undefined_test.js @@ -2,8 +2,8 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_option = require("../../lib/js/caml_option.js"); let Js_undefined = require("../../lib/js/js_undefined.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); let suites_0 = [ "toOption - empty", @@ -29,7 +29,7 @@ let suites_1 = { param => ({ TAG: "Eq", _0: "something", - _1: Caml_option.undefined_to_opt("something") + _1: Primitive_option.fromUndefined("something") }) ], tl: { diff --git a/jscomp/test/jsoo_400_test.js b/jscomp/test/jsoo_400_test.js index 12c78d9f5e..79823bda7d 100644 --- a/jscomp/test/jsoo_400_test.js +++ b/jscomp/test/jsoo_400_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_int32 = require("../../lib/js/caml_int32.js"); +let Primitive_int = require("../../lib/js/primitive_int.js"); function u() { let n; @@ -11,7 +11,7 @@ function u() { } catch (exn) { return 42; } - return Caml_int32.div(3, 0); + return Primitive_int.div(3, 0); } Mt.from_pair_suites("Jsoo_400_test", { diff --git a/jscomp/test/key_word_property_plus_test.js b/jscomp/test/key_word_property_plus_test.js index db5fb4114d..24d7c9e106 100644 --- a/jscomp/test/key_word_property_plus_test.js +++ b/jscomp/test/key_word_property_plus_test.js @@ -16,7 +16,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -27,7 +27,7 @@ function eq(loc, x, y) { }; } -eq("File \"key_word_property_plus_test.res\", line 10, characters 2-9", [ +eq("File \"key_word_property_plus_test.res\", line 13, characters 2-9", [ 1, 2, 3, diff --git a/jscomp/test/key_word_property_plus_test.res b/jscomp/test/key_word_property_plus_test.res index 88adb2f22b..9dc07bac19 100644 --- a/jscomp/test/key_word_property_plus_test.res +++ b/jscomp/test/key_word_property_plus_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let () = eq( diff --git a/jscomp/test/label_uncurry.js b/jscomp/test/label_uncurry.js index fcfa996b3e..b0db10bae2 100644 --- a/jscomp/test/label_uncurry.js +++ b/jscomp/test/label_uncurry.js @@ -1,14 +1,18 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_format = require("../../lib/js/caml_format.js"); +let Belt_Int = require("../../lib/js/belt_Int.js"); function f(x) { return x; } function u(x, y) { - return x + Caml_format.int_of_string(y) | 0; + let y$1 = Belt_Int.fromString(y); + if (y$1 !== undefined) { + return x + y$1 | 0; + } + } function u1(f) { diff --git a/jscomp/test/label_uncurry.res b/jscomp/test/label_uncurry.res index 0cb0f00920..a784fac5ec 100644 --- a/jscomp/test/label_uncurry.res +++ b/jscomp/test/label_uncurry.res @@ -1,10 +1,14 @@ -type t = (~x: int, ~y: string) => int +type t = (~x: int, ~y: string) => option -type u = (~x: int, ~y: string) => int +type u = (~x: int, ~y: string) => option let f = (x: t): u => x -let u: u = (~x, ~y) => x + int_of_string(y) +let u: u = (~x, ~y) => + switch Belt.Int.fromString(y) { + | Some(y) => Some(x + y) + | None => None + } let u1 = (f: u) => { f(~y="x", ~x=2)->Js.log diff --git a/jscomp/test/large_record_duplication_test.js b/jscomp/test/large_record_duplication_test.js index 23d4643887..7ece62f23f 100644 --- a/jscomp/test/large_record_duplication_test.js +++ b/jscomp/test/large_record_duplication_test.js @@ -2,8 +2,8 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); let suites = { contents: /* [] */0 @@ -23,7 +23,7 @@ function f0(x) { return newrecord; } -let Small = /* @__PURE__ */Caml_exceptions.create("Large_record_duplication_test.Small"); +let Small = /* @__PURE__ */Primitive_exceptions.create("Large_record_duplication_test.Small"); function f_small(x) { if (x.RE_EXN_ID === Small) { @@ -51,7 +51,7 @@ eq("File \"large_record_duplication_test.res\", line 70, characters 3-10", f_sma y: "" }); -eq("File \"large_record_duplication_test.res\", line 72, characters 3-10", Caml_obj.equal(h, { +eq("File \"large_record_duplication_test.res\", line 72, characters 3-10", Primitive_object.equal(h, { RE_EXN_ID: Small, x: 2, y: "" @@ -148,7 +148,7 @@ function f2(x) { eq("File \"large_record_duplication_test.res\", line 208, characters 3-10", get_x0$1(f2(v2)), 1); -let A0 = /* @__PURE__ */Caml_exceptions.create("Large_record_duplication_test.A0"); +let A0 = /* @__PURE__ */Primitive_exceptions.create("Large_record_duplication_test.A0"); function f3(x) { if (x.RE_EXN_ID !== A0) { diff --git a/jscomp/test/lazy_demo.js b/jscomp/test/lazy_demo.js index 03915b1d78..ade08bad00 100644 --- a/jscomp/test/lazy_demo.js +++ b/jscomp/test/lazy_demo.js @@ -1,20 +1,20 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let CamlinternalLazy = require("../../lib/js/camlinternalLazy.js"); +let Lazy = require("../../lib/js/lazy.js"); -let lazy1 = CamlinternalLazy.from_fun(() => { +let lazy1 = Lazy.from_fun(() => { console.log("Hello, lazy"); return 1; }); -let lazy2 = CamlinternalLazy.from_fun(() => 3); +let lazy2 = Lazy.from_fun(() => 3); console.log(lazy1, lazy2); -let la = CamlinternalLazy.force(lazy1); +let la = Lazy.force(lazy1); -let lb = CamlinternalLazy.force(lazy2); +let lb = Lazy.force(lazy2); console.log(la, lb); diff --git a/jscomp/test/lazy_test.js b/jscomp/test/lazy_test.js index 4a346c49b4..0fe29f53be 100644 --- a/jscomp/test/lazy_test.js +++ b/jscomp/test/lazy_test.js @@ -3,19 +3,18 @@ let Mt = require("./mt.js"); let Lazy = require("../../lib/js/lazy.js"); -let CamlinternalLazy = require("../../lib/js/camlinternalLazy.js"); let u = { contents: 3 }; -let v = CamlinternalLazy.from_fun(() => { +let v = Lazy.from_fun(() => { u.contents = 32; }); function lazy_test() { let h = u.contents; - CamlinternalLazy.force(v); + Lazy.force(v); let g = u.contents; return [ h, @@ -27,58 +26,54 @@ let u_v = { contents: 0 }; -let u$1 = CamlinternalLazy.from_fun(() => { +let u$1 = Lazy.from_fun(() => { u_v.contents = 2; }); -CamlinternalLazy.force(u$1); +Lazy.force(u$1); -let exotic = CamlinternalLazy.force; +let exotic = Lazy.force; -let l_from_fun = CamlinternalLazy.from_fun(() => 3); +let l_from_fun = Lazy.from_fun(() => 3); -function f() { +let forward_test = Lazy.from_fun(() => { let u = 3; u = u + 1 | 0; return u; -} - -let forward_test = CamlinternalLazy.from_fun(() => f()); +}); -let f005 = CamlinternalLazy.from_fun(() => 6); +let f005 = Lazy.from_fun(() => 6); -let f006 = CamlinternalLazy.from_fun(() => (() => 3)); +let f006 = Lazy.from_fun(() => (() => 3)); -let f007 = CamlinternalLazy.from_fun(() => { +let f007 = Lazy.from_fun(() => { throw { RE_EXN_ID: "Not_found", Error: new Error() }; }); -function f$1() { +let f008 = Lazy.from_fun(() => { console.log("hi"); throw { RE_EXN_ID: "Not_found", Error: new Error() }; -} - -let f008 = CamlinternalLazy.from_fun(() => f$1()); +}); -let a2 = CamlinternalLazy.from_val; +let a2 = Lazy.from_val; -let a3 = CamlinternalLazy.from_val(3); +let a3 = Lazy.from_val(3); -let a4 = CamlinternalLazy.from_val(3); +let a4 = Lazy.from_val(3); -let a5 = CamlinternalLazy.from_val(undefined); +let a5 = Lazy.from_val(undefined); -let a6 = CamlinternalLazy.from_val(); +let a6 = Lazy.from_val(); -let a7 = CamlinternalLazy.force(a5); +let a7 = Lazy.force(a5); -let a8 = CamlinternalLazy.force(a6); +let a8 = Lazy.force(a6); Mt.from_pair_suites("Lazy_test", { hd: [ @@ -106,7 +101,7 @@ Mt.from_pair_suites("Lazy_test", { "lazy_from_fun", () => ({ TAG: "Eq", - _0: CamlinternalLazy.force(l_from_fun), + _0: Lazy.force(l_from_fun), _1: 3 }) ], @@ -115,7 +110,7 @@ Mt.from_pair_suites("Lazy_test", { "lazy_from_val", () => ({ TAG: "Eq", - _0: CamlinternalLazy.force(CamlinternalLazy.from_val(3)), + _0: Lazy.force(Lazy.from_val(3)), _1: 3 }) ], @@ -124,7 +119,7 @@ Mt.from_pair_suites("Lazy_test", { "lazy_from_val2", () => ({ TAG: "Eq", - _0: CamlinternalLazy.force(CamlinternalLazy.force(CamlinternalLazy.from_val(CamlinternalLazy.from_fun(() => 3)))), + _0: Lazy.force(Lazy.force(Lazy.from_val(Lazy.from_fun(() => 3)))), _1: 3 }) ], @@ -135,7 +130,7 @@ Mt.from_pair_suites("Lazy_test", { debugger; return { TAG: "Eq", - _0: CamlinternalLazy.force(CamlinternalLazy.force(CamlinternalLazy.from_val(forward_test))), + _0: Lazy.force(Lazy.force(Lazy.from_val(forward_test))), _1: 4 }; } @@ -172,7 +167,7 @@ Mt.from_pair_suites("Lazy_test", { "File \"lazy_test.res\", line 98, characters 7-14", () => ({ TAG: "Ok", - _0: Lazy.is_val(CamlinternalLazy.from_val(3)) + _0: Lazy.is_val(Lazy.from_val(3)) }) ], tl: { @@ -180,7 +175,7 @@ Mt.from_pair_suites("Lazy_test", { "File \"lazy_test.res\", line 99, characters 7-14", () => ({ TAG: "Ok", - _0: !Lazy.is_val(CamlinternalLazy.from_fun(() => { + _0: !Lazy.is_val(Lazy.from_fun(() => { throw { RE_EXN_ID: "Not_found", Error: new Error() diff --git a/jscomp/test/lazy_test.res b/jscomp/test/lazy_test.res index 755af29dd8..9129a1745a 100644 --- a/jscomp/test/lazy_test.res +++ b/jscomp/test/lazy_test.res @@ -47,14 +47,14 @@ let forward_test = Lazy.from_fun(() => { let f005 = Lazy.from_fun(() => 1 + 2 + 3) -let f006: lazy_t int> = Lazy.from_fun(() => { +let f006: Lazy.t int> = Lazy.from_fun(() => { let x = 3 _ => x }) let f007 = Lazy.from_fun(() => raise(Not_found)) let f008 = Lazy.from_fun(() => { - print_endline("hi") + Js.log("hi") raise(Not_found) }) diff --git a/jscomp/test/libarg_test.js b/jscomp/test/libarg_test.js deleted file mode 100644 index 42a1457b86..0000000000 --- a/jscomp/test/libarg_test.js +++ /dev/null @@ -1,411 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let Arg = require("../../lib/js/arg.js"); -let List = require("../../lib/js/list.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); - -let current = { - contents: 0 -}; - -let accum = { - contents: /* [] */0 -}; - -function record(fmt) { - accum.contents = { - hd: fmt, - tl: accum.contents - }; -} - -function f_unit() { - record("unit()"); -} - -function f_bool(b) { - record("bool(" + b + ")"); -} - -let r_set = { - contents: false -}; - -let r_clear = { - contents: true -}; - -function f_string(s) { - record("string(" + s + ")"); -} - -let r_string = { - contents: "" -}; - -function f_int(i) { - record("int(" + i + ")"); -} - -let r_int = { - contents: 0 -}; - -function f_float(f) { - record("float(" + f + ")"); -} - -let r_float = { - contents: 0.0 -}; - -function f_symbol(s) { - record("symbol(" + s + ")"); -} - -function f_rest(s) { - record("rest(" + s + ")"); -} - -function f_anon(s) { - record("anon(" + s + ")"); -} - -let spec_0 = [ - "-u", - { - TAG: "Unit", - _0: f_unit - }, - "Unit (0)" -]; - -let spec_1 = { - hd: [ - "-b", - { - TAG: "Bool", - _0: f_bool - }, - "Bool (1)" - ], - tl: { - hd: [ - "-s", - { - TAG: "Set", - _0: r_set - }, - "Set (0)" - ], - tl: { - hd: [ - "-c", - { - TAG: "Clear", - _0: r_clear - }, - "Clear (0)" - ], - tl: { - hd: [ - "-str", - { - TAG: "String", - _0: f_string - }, - "String (1)" - ], - tl: { - hd: [ - "-sstr", - { - TAG: "Set_string", - _0: r_string - }, - "Set_string (1)" - ], - tl: { - hd: [ - "-i", - { - TAG: "Int", - _0: f_int - }, - "Int (1)" - ], - tl: { - hd: [ - "-si", - { - TAG: "Set_int", - _0: r_int - }, - "Set_int (1)" - ], - tl: { - hd: [ - "-f", - { - TAG: "Float", - _0: f_float - }, - "Float (1)" - ], - tl: { - hd: [ - "-sf", - { - TAG: "Set_float", - _0: r_float - }, - "Set_float (1)" - ], - tl: { - hd: [ - "-t", - { - TAG: "Tuple", - _0: { - hd: { - TAG: "Bool", - _0: f_bool - }, - tl: { - hd: { - TAG: "String", - _0: f_string - }, - tl: { - hd: { - TAG: "Int", - _0: f_int - }, - tl: /* [] */0 - } - } - } - }, - "Tuple (3)" - ], - tl: { - hd: [ - "-sym", - { - TAG: "Symbol", - _0: { - hd: "a", - tl: { - hd: "b", - tl: { - hd: "c", - tl: /* [] */0 - } - } - }, - _1: f_symbol - }, - "Symbol (1)" - ], - tl: { - hd: [ - "-rest", - { - TAG: "Rest", - _0: f_rest - }, - "Rest (*)" - ], - tl: /* [] */0 - } - } - } - } - } - } - } - } - } - } - } -}; - -let spec = { - hd: spec_0, - tl: spec_1 -}; - -let args1 = [ - "prog", - "anon1", - "-u", - "-b", - "true", - "-s", - "anon2", - "-c", - "-str", - "foo", - "-sstr", - "bar", - "-i", - "19", - "-si", - "42", - "-f", - "3.14", - "-sf", - "2.72", - "anon3", - "-t", - "false", - "gee", - "1436", - "-sym", - "c", - "anon4", - "-rest", - "r1", - "r2" -]; - -let args2 = [ - "prog", - "anon1", - "-u", - "-b=true", - "-s", - "anon2", - "-c", - "-str=foo", - "-sstr=bar", - "-i=19", - "-si=42", - "-f=3.14", - "-sf=2.72", - "anon3", - "-t", - "false", - "gee", - "1436", - "-sym=c", - "anon4", - "-rest", - "r1", - "r2" -]; - -function error(s) { - console.log("error (" + (s + ")")); -} - -function check(r, v, msg) { - if (Caml_obj.notequal(r.contents, v)) { - return error(msg); - } - -} - -function test(argv) { - current.contents = 0; - r_set.contents = false; - r_clear.contents = true; - r_string.contents = ""; - r_int.contents = 0; - r_float.contents = 0.0; - accum.contents = /* [] */0; - Arg.parse_argv(current, argv, spec, f_anon, "usage"); - let result = List.rev(accum.contents); - let reference = { - hd: "anon(anon1)", - tl: { - hd: "unit()", - tl: { - hd: "bool(true)", - tl: { - hd: "anon(anon2)", - tl: { - hd: "string(foo)", - tl: { - hd: "int(19)", - tl: { - hd: "float(3.14)", - tl: { - hd: "anon(anon3)", - tl: { - hd: "bool(false)", - tl: { - hd: "string(gee)", - tl: { - hd: "int(1436)", - tl: { - hd: "symbol(c)", - tl: { - hd: "anon(anon4)", - tl: { - hd: "rest(r1)", - tl: { - hd: "rest(r2)", - tl: /* [] */0 - } - } - } - } - } - } - } - } - } - } - } - } - } - } - }; - if (Caml_obj.notequal(result, reference)) { - let f = (x, y) => { - console.log(x, y); - }; - List.iter2(f, result, reference); - } - check(r_set, true, "Set"); - check(r_clear, false, "Clear"); - check(r_string, "bar", "Set_string"); - check(r_int, 42, "Set_int"); - check(r_float, 2.72, "Set_float"); -} - -test(args1); - -test(args2); - -Mt.from_pair_suites("Libarg_test", /* [] */0); - -let suites = /* [] */0; - -exports.current = current; -exports.accum = accum; -exports.record = record; -exports.f_unit = f_unit; -exports.f_bool = f_bool; -exports.r_set = r_set; -exports.r_clear = r_clear; -exports.f_string = f_string; -exports.r_string = r_string; -exports.f_int = f_int; -exports.r_int = r_int; -exports.f_float = f_float; -exports.r_float = r_float; -exports.f_symbol = f_symbol; -exports.f_rest = f_rest; -exports.f_anon = f_anon; -exports.spec = spec; -exports.args1 = args1; -exports.args2 = args2; -exports.error = error; -exports.check = check; -exports.test = test; -exports.suites = suites; -/* Not a pure module */ diff --git a/jscomp/test/libarg_test.res b/jscomp/test/libarg_test.res deleted file mode 100644 index 5c92ff299f..0000000000 --- a/jscomp/test/libarg_test.res +++ /dev/null @@ -1,151 +0,0 @@ -let current = ref(0) - -let accum = ref(list{}) - -let record = fmt /* args */ => accum := list{fmt, ...accum.contents} - -let f_unit = () => record("unit()") -let f_bool = b => record("bool(" ++ __unsafe_cast(b) ++ ")") -let r_set = ref(false) -let r_clear = ref(true) -let f_string = s => record("string(" ++ s ++ ")") -let r_string = ref("") -let f_int = i => record("int(" ++ __unsafe_cast(i) ++ ")") -let r_int = ref(0) -let f_float = f => record("float(" ++ __unsafe_cast(f) ++ ")") -let r_float = ref(0.0) -let f_symbol = s => record("symbol(" ++ s ++ ")") -let f_rest = s => record("rest(" ++ s ++ ")") -let f_anon = s => record("anon(" ++ s ++ ")") - -let spec = { - open Arg - list{ - ("-u", Unit(f_unit), "Unit (0)"), - ("-b", Bool(f_bool), "Bool (1)"), - ("-s", Set(r_set), "Set (0)"), - ("-c", Clear(r_clear), "Clear (0)"), - ("-str", String(f_string), "String (1)"), - ("-sstr", Set_string(r_string), "Set_string (1)"), - ("-i", Int(f_int), "Int (1)"), - ("-si", Set_int(r_int), "Set_int (1)"), - ("-f", Float(f_float), "Float (1)"), - ("-sf", Set_float(r_float), "Set_float (1)"), - ("-t", Tuple(list{Bool(f_bool), String(f_string), Int(f_int)}), "Tuple (3)"), - ("-sym", Symbol(list{"a", "b", "c"}, f_symbol), "Symbol (1)"), - ("-rest", Rest(f_rest), "Rest (*)"), - } -} - -let args1 = [ - "prog", - "anon1", - "-u", - "-b", - "true", - "-s", - "anon2", - "-c", - "-str", - "foo", - "-sstr", - "bar", - "-i", - "19", - "-si", - "42", - "-f", - "3.14", - "-sf", - "2.72", - "anon3", - "-t", - "false", - "gee", - "1436", - "-sym", - "c", - "anon4", - "-rest", - "r1", - "r2", -] - -let args2 = [ - "prog", - "anon1", - "-u", - "-b=true", - "-s", - "anon2", - "-c", - "-str=foo", - "-sstr=bar", - "-i=19", - "-si=42", - "-f=3.14", - "-sf=2.72", - "anon3", - "-t", - "false", - "gee", - "1436", - "-sym=c", - "anon4", - "-rest", - "r1", - "r2", -] - -let error = s => Js.log("error (" ++ (s ++ ")")) -let check = (r, v, msg) => - if r.contents != v { - error(msg) - } - -let test = argv => { - current := 0 - r_set := false - r_clear := true - r_string := "" - r_int := 0 - r_float := 0.0 - accum := list{} - Arg.parse_argv(~current, argv, spec, f_anon, "usage") - let result = List.rev(accum.contents) - let reference = list{ - "anon(anon1)", - "unit()", - "bool(true)", - "anon(anon2)", - "string(foo)", - "int(19)", - "float(3.14)", - "anon(anon3)", - "bool(false)", - "string(gee)", - "int(1436)", - "symbol(c)", - "anon(anon4)", - "rest(r1)", - "rest(r2)", - } - - if result != reference { - let f = (x, y) => Js.log2(x, y) - - List.iter2(f, result, reference) - } - check(r_set, true, "Set") - check(r_clear, false, "Clear") - check(r_string, "bar", "Set_string") - check(r_int, 42, "Set_int") - check(r_float, 2.72, "Set_float") -} - -test(args1) - -test(args2) -let suites = list{} - -let () = Mt.from_pair_suites(__MODULE__, suites) diff --git a/jscomp/test/libqueue_test.js b/jscomp/test/libqueue_test.js deleted file mode 100644 index 11819ab771..0000000000 --- a/jscomp/test/libqueue_test.js +++ /dev/null @@ -1,1388 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let List = require("../../lib/js/list.js"); -let Queue = require("../../lib/js/queue.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); - -function to_list(q) { - return List.rev(Queue.fold((l, x) => ({ - hd: x, - tl: l - }), /* [] */0, q)); -} - -let Q = { - Empty: Queue.Empty, - create: Queue.create, - add: Queue.add, - push: Queue.push, - take: Queue.take, - pop: Queue.pop, - peek: Queue.peek, - top: Queue.top, - clear: Queue.clear, - copy: Queue.copy, - is_empty: Queue.is_empty, - length: Queue.length, - iter: Queue.iter, - fold: Queue.fold, - transfer: Queue.transfer, - to_list: to_list -}; - -function does_raise(f, q) { - try { - f(q); - return false; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === Queue.Empty) { - return true; - } - throw exn; - } -} - -let q = { - length: 0, - first: "Nil", - last: "Nil" -}; - -if (!(to_list(q) === /* [] */0 && q.length === 0)) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 30, - 2 - ], - Error: new Error() - }; -} - -Queue.add(1, q); - -if (!(Caml_obj.equal(to_list(q), { - hd: 1, - tl: /* [] */0 - }) && q.length === 1)) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 32, - 2 - ], - Error: new Error() - }; -} - -Queue.add(2, q); - -if (!(Caml_obj.equal(to_list(q), { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }) && q.length === 2)) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 34, - 2 - ], - Error: new Error() - }; -} - -Queue.add(3, q); - -if (!(Caml_obj.equal(to_list(q), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }) && q.length === 3)) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 36, - 2 - ], - Error: new Error() - }; -} - -Queue.add(4, q); - -if (!(Caml_obj.equal(to_list(q), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }) && q.length === 4)) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 38, - 2 - ], - Error: new Error() - }; -} - -if (Queue.take(q) !== 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 39, - 2 - ], - Error: new Error() - }; -} - -if (!(Caml_obj.equal(to_list(q), { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - }) && q.length === 3)) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 40, - 2 - ], - Error: new Error() - }; -} - -if (Queue.take(q) !== 2) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 41, - 2 - ], - Error: new Error() - }; -} - -if (!(Caml_obj.equal(to_list(q), { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - }) && q.length === 2)) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 42, - 2 - ], - Error: new Error() - }; -} - -if (Queue.take(q) !== 3) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 43, - 2 - ], - Error: new Error() - }; -} - -if (!(Caml_obj.equal(to_list(q), { - hd: 4, - tl: /* [] */0 - }) && q.length === 1)) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 44, - 2 - ], - Error: new Error() - }; -} - -if (Queue.take(q) !== 4) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 45, - 2 - ], - Error: new Error() - }; -} - -if (!(to_list(q) === /* [] */0 && q.length === 0)) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 46, - 2 - ], - Error: new Error() - }; -} - -if (!does_raise(Queue.take, q)) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 47, - 2 - ], - Error: new Error() - }; -} - -let q$1 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -Queue.add(1, q$1); - -if (Queue.take(q$1) !== 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 53, - 2 - ], - Error: new Error() - }; -} - -if (!does_raise(Queue.take, q$1)) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 54, - 2 - ], - Error: new Error() - }; -} - -Queue.add(2, q$1); - -if (Queue.take(q$1) !== 2) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 56, - 2 - ], - Error: new Error() - }; -} - -if (!does_raise(Queue.take, q$1)) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 57, - 2 - ], - Error: new Error() - }; -} - -if (q$1.length !== 0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 58, - 2 - ], - Error: new Error() - }; -} - -let q$2 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -Queue.add(1, q$2); - -if (Queue.peek(q$2) !== 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 64, - 2 - ], - Error: new Error() - }; -} - -Queue.add(2, q$2); - -if (Queue.peek(q$2) !== 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 66, - 2 - ], - Error: new Error() - }; -} - -Queue.add(3, q$2); - -if (Queue.peek(q$2) !== 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 68, - 2 - ], - Error: new Error() - }; -} - -if (Queue.peek(q$2) !== 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 69, - 2 - ], - Error: new Error() - }; -} - -if (Queue.take(q$2) !== 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 70, - 2 - ], - Error: new Error() - }; -} - -if (Queue.peek(q$2) !== 2) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 71, - 2 - ], - Error: new Error() - }; -} - -if (Queue.take(q$2) !== 2) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 72, - 2 - ], - Error: new Error() - }; -} - -if (Queue.peek(q$2) !== 3) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 73, - 2 - ], - Error: new Error() - }; -} - -if (Queue.take(q$2) !== 3) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 74, - 2 - ], - Error: new Error() - }; -} - -if (!does_raise(Queue.peek, q$2)) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 75, - 2 - ], - Error: new Error() - }; -} - -if (!does_raise(Queue.peek, q$2)) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 76, - 2 - ], - Error: new Error() - }; -} - -let q$3 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -for (let i = 1; i <= 10; ++i) { - Queue.add(i, q$3); -} - -Queue.clear(q$3); - -if (q$3.length !== 0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 85, - 2 - ], - Error: new Error() - }; -} - -if (!does_raise(Queue.take, q$3)) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 86, - 2 - ], - Error: new Error() - }; -} - -if (!Caml_obj.equal(q$3, { - length: 0, - first: "Nil", - last: "Nil" - })) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 87, - 2 - ], - Error: new Error() - }; -} - -Queue.add(42, q$3); - -if (Queue.take(q$3) !== 42) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 89, - 2 - ], - Error: new Error() - }; -} - -let q1 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -for (let i$1 = 1; i$1 <= 10; ++i$1) { - Queue.add(i$1, q1); -} - -let q2 = Queue.copy(q1); - -if (!Caml_obj.equal(to_list(q1), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: { - hd: 6, - tl: { - hd: 7, - tl: { - hd: 8, - tl: { - hd: 9, - tl: { - hd: 10, - tl: /* [] */0 - } - } - } - } - } - } - } - } - } - })) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 98, - 2 - ], - Error: new Error() - }; -} - -if (!Caml_obj.equal(to_list(q2), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: { - hd: 6, - tl: { - hd: 7, - tl: { - hd: 8, - tl: { - hd: 9, - tl: { - hd: 10, - tl: /* [] */0 - } - } - } - } - } - } - } - } - } - })) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 99, - 2 - ], - Error: new Error() - }; -} - -if (q1.length !== 10) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 100, - 2 - ], - Error: new Error() - }; -} - -if (q2.length !== 10) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 101, - 2 - ], - Error: new Error() - }; -} - -for (let i$2 = 1; i$2 <= 10; ++i$2) { - if (Queue.take(q1) !== i$2) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 103, - 4 - ], - Error: new Error() - }; - } - -} - -for (let i$3 = 1; i$3 <= 10; ++i$3) { - if (Queue.take(q2) !== i$3) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 106, - 4 - ], - Error: new Error() - }; - } - -} - -let q$4 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -if (q$4.length !== 0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 112, - 2 - ], - Error: new Error() - }; -} - -for (let i$4 = 1; i$4 <= 10; ++i$4) { - Queue.add(i$4, q$4); - if (q$4.length !== i$4) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 115, - 4 - ], - Error: new Error() - }; - } - if (q$4.length === 0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 116, - 4 - ], - Error: new Error() - }; - } - -} - -for (let i$5 = 10; i$5 >= 1; --i$5) { - if (q$4.length !== i$5) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 119, - 4 - ], - Error: new Error() - }; - } - if (q$4.length === 0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 120, - 4 - ], - Error: new Error() - }; - } - Queue.take(q$4); -} - -if (q$4.length !== 0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 123, - 2 - ], - Error: new Error() - }; -} - -if (q$4.length !== 0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 124, - 2 - ], - Error: new Error() - }; -} - -let q$5 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -for (let i$6 = 1; i$6 <= 10; ++i$6) { - Queue.add(i$6, q$5); -} - -let i$7 = { - contents: 1 -}; - -Queue.iter(j => { - if (i$7.contents !== j) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 134, - 4 - ], - Error: new Error() - }; - } - i$7.contents = i$7.contents + 1 | 0; -}, q$5); - -let q1$1 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -let q2$1 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -if (q1$1.length !== 0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 141, - 2 - ], - Error: new Error() - }; -} - -if (to_list(q1$1) !== /* [] */0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 142, - 2 - ], - Error: new Error() - }; -} - -if (q2$1.length !== 0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 143, - 2 - ], - Error: new Error() - }; -} - -if (to_list(q2$1) !== /* [] */0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 144, - 2 - ], - Error: new Error() - }; -} - -Queue.transfer(q1$1, q2$1); - -if (q1$1.length !== 0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 146, - 2 - ], - Error: new Error() - }; -} - -if (to_list(q1$1) !== /* [] */0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 147, - 2 - ], - Error: new Error() - }; -} - -if (q2$1.length !== 0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 148, - 2 - ], - Error: new Error() - }; -} - -if (to_list(q2$1) !== /* [] */0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 149, - 2 - ], - Error: new Error() - }; -} - -let q1$2 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -let q2$2 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -for (let i$8 = 1; i$8 <= 4; ++i$8) { - Queue.add(i$8, q1$2); -} - -if (q1$2.length !== 4) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 157, - 2 - ], - Error: new Error() - }; -} - -if (!Caml_obj.equal(to_list(q1$2), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - })) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 158, - 2 - ], - Error: new Error() - }; -} - -if (q2$2.length !== 0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 159, - 2 - ], - Error: new Error() - }; -} - -if (to_list(q2$2) !== /* [] */0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 160, - 2 - ], - Error: new Error() - }; -} - -Queue.transfer(q1$2, q2$2); - -if (q1$2.length !== 0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 162, - 2 - ], - Error: new Error() - }; -} - -if (to_list(q1$2) !== /* [] */0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 163, - 2 - ], - Error: new Error() - }; -} - -if (q2$2.length !== 4) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 164, - 2 - ], - Error: new Error() - }; -} - -if (!Caml_obj.equal(to_list(q2$2), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - })) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 165, - 2 - ], - Error: new Error() - }; -} - -let q1$3 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -let q2$3 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -for (let i$9 = 5; i$9 <= 8; ++i$9) { - Queue.add(i$9, q2$3); -} - -if (q1$3.length !== 0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 173, - 2 - ], - Error: new Error() - }; -} - -if (to_list(q1$3) !== /* [] */0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 174, - 2 - ], - Error: new Error() - }; -} - -if (q2$3.length !== 4) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 175, - 2 - ], - Error: new Error() - }; -} - -if (!Caml_obj.equal(to_list(q2$3), { - hd: 5, - tl: { - hd: 6, - tl: { - hd: 7, - tl: { - hd: 8, - tl: /* [] */0 - } - } - } - })) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 176, - 2 - ], - Error: new Error() - }; -} - -Queue.transfer(q1$3, q2$3); - -if (q1$3.length !== 0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 178, - 2 - ], - Error: new Error() - }; -} - -if (to_list(q1$3) !== /* [] */0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 179, - 2 - ], - Error: new Error() - }; -} - -if (q2$3.length !== 4) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 180, - 2 - ], - Error: new Error() - }; -} - -if (!Caml_obj.equal(to_list(q2$3), { - hd: 5, - tl: { - hd: 6, - tl: { - hd: 7, - tl: { - hd: 8, - tl: /* [] */0 - } - } - } - })) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 181, - 2 - ], - Error: new Error() - }; -} - -let q1$4 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -let q2$4 = { - length: 0, - first: "Nil", - last: "Nil" -}; - -for (let i$10 = 1; i$10 <= 4; ++i$10) { - Queue.add(i$10, q1$4); -} - -for (let i$11 = 5; i$11 <= 8; ++i$11) { - Queue.add(i$11, q2$4); -} - -if (q1$4.length !== 4) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 192, - 2 - ], - Error: new Error() - }; -} - -if (!Caml_obj.equal(to_list(q1$4), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - })) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 193, - 2 - ], - Error: new Error() - }; -} - -if (q2$4.length !== 4) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 194, - 2 - ], - Error: new Error() - }; -} - -if (!Caml_obj.equal(to_list(q2$4), { - hd: 5, - tl: { - hd: 6, - tl: { - hd: 7, - tl: { - hd: 8, - tl: /* [] */0 - } - } - } - })) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 195, - 2 - ], - Error: new Error() - }; -} - -Queue.transfer(q1$4, q2$4); - -if (q1$4.length !== 0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 197, - 2 - ], - Error: new Error() - }; -} - -if (to_list(q1$4) !== /* [] */0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 198, - 2 - ], - Error: new Error() - }; -} - -if (q2$4.length !== 8) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 199, - 2 - ], - Error: new Error() - }; -} - -if (!Caml_obj.equal(to_list(q2$4), { - hd: 5, - tl: { - hd: 6, - tl: { - hd: 7, - tl: { - hd: 8, - tl: { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - } - } - } - } - })) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "libqueue_test.res", - 200, - 2 - ], - Error: new Error() - }; -} - -console.log("OK"); - -exports.Q = Q; -exports.does_raise = does_raise; -/* q Not a pure module */ diff --git a/jscomp/test/libqueue_test.res b/jscomp/test/libqueue_test.res deleted file mode 100644 index 528c28b515..0000000000 --- a/jscomp/test/libqueue_test.res +++ /dev/null @@ -1,203 +0,0 @@ -/* ********************************************************************* */ -/* */ -/* OCaml */ -/* */ -/* Jeremie Dimino, Jane Street Europe */ -/* */ -/* Copyright 2015 Institut National de Recherche en Informatique et */ -/* en Automatique. All rights reserved. This file is distributed */ -/* under the terms of the Q Public License version 1.0. */ -/* */ -/* ********************************************************************* */ - -module Q = { - include Queue - - let to_list = q => List.rev(fold((l, x) => list{x, ...l}, list{}, q)) -} - -let does_raise = (f, q) => - try { - ignore((f(q): int)) - false - } catch { - | Q.Empty => true - } - -let () = { - let q = Q.create() - () - assert(Q.to_list(q) == list{} && Q.length(q) == 0) - Q.add(1, q) - assert(Q.to_list(q) == list{1} && Q.length(q) == 1) - Q.add(2, q) - assert(Q.to_list(q) == list{1, 2} && Q.length(q) == 2) - Q.add(3, q) - assert(Q.to_list(q) == list{1, 2, 3} && Q.length(q) == 3) - Q.add(4, q) - assert(Q.to_list(q) == list{1, 2, 3, 4} && Q.length(q) == 4) - assert(Q.take(q) == 1) - assert(Q.to_list(q) == list{2, 3, 4} && Q.length(q) == 3) - assert(Q.take(q) == 2) - assert(Q.to_list(q) == list{3, 4} && Q.length(q) == 2) - assert(Q.take(q) == 3) - assert(Q.to_list(q) == list{4} && Q.length(q) == 1) - assert(Q.take(q) == 4) - assert(Q.to_list(q) == list{} && Q.length(q) == 0) - assert(does_raise(Q.take, q)) -} - -let () = { - let q = Q.create() - Q.add(1, q) - assert(Q.take(q) == 1) - assert(does_raise(Q.take, q)) - Q.add(2, q) - assert(Q.take(q) == 2) - assert(does_raise(Q.take, q)) - assert(Q.length(q) == 0) -} - -let () = { - let q = Q.create() - Q.add(1, q) - assert(Q.peek(q) == 1) - Q.add(2, q) - assert(Q.peek(q) == 1) - Q.add(3, q) - assert(Q.peek(q) == 1) - assert(Q.peek(q) == 1) - assert(Q.take(q) == 1) - assert(Q.peek(q) == 2) - assert(Q.take(q) == 2) - assert(Q.peek(q) == 3) - assert(Q.take(q) == 3) - assert(does_raise(Q.peek, q)) - assert(does_raise(Q.peek, q)) -} - -let () = { - let q = Q.create() - for i in 1 to 10 { - Q.add(i, q) - } - Q.clear(q) - assert(Q.length(q) == 0) - assert(does_raise(Q.take, q)) - assert(q == Q.create()) - Q.add(42, q) - assert(Q.take(q) == 42) -} - -let () = { - let q1 = Q.create() - for i in 1 to 10 { - Q.add(i, q1) - } - let q2 = Q.copy(q1) - assert(Q.to_list(q1) == list{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) - assert(Q.to_list(q2) == list{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) - assert(Q.length(q1) == 10) - assert(Q.length(q2) == 10) - for i in 1 to 10 { - assert(Q.take(q1) == i) - } - for i in 1 to 10 { - assert(Q.take(q2) == i) - } -} - -let () = { - let q = Q.create() - assert(Q.is_empty(q)) - for i in 1 to 10 { - Q.add(i, q) - assert(Q.length(q) == i) - assert(!Q.is_empty(q)) - } - for i in 10 downto 1 { - assert(Q.length(q) == i) - assert(!Q.is_empty(q)) - ignore((Q.take(q): int)) - } - assert(Q.length(q) == 0) - assert(Q.is_empty(q)) -} - -let () = { - let q = Q.create() - for i in 1 to 10 { - Q.add(i, q) - } - let i = ref(1) - Q.iter(j => { - assert(i.contents == j) - incr(i) - }, q) -} - -let () = { - let q1 = Q.create() and q2 = Q.create() - assert(Q.length(q1) == 0) - assert(Q.to_list(q1) == list{}) - assert(Q.length(q2) == 0) - assert(Q.to_list(q2) == list{}) - Q.transfer(q1, q2) - assert(Q.length(q1) == 0) - assert(Q.to_list(q1) == list{}) - assert(Q.length(q2) == 0) - assert(Q.to_list(q2) == list{}) -} - -let () = { - let q1 = Q.create() and q2 = Q.create() - for i in 1 to 4 { - Q.add(i, q1) - } - assert(Q.length(q1) == 4) - assert(Q.to_list(q1) == list{1, 2, 3, 4}) - assert(Q.length(q2) == 0) - assert(Q.to_list(q2) == list{}) - Q.transfer(q1, q2) - assert(Q.length(q1) == 0) - assert(Q.to_list(q1) == list{}) - assert(Q.length(q2) == 4) - assert(Q.to_list(q2) == list{1, 2, 3, 4}) -} - -let () = { - let q1 = Q.create() and q2 = Q.create() - for i in 5 to 8 { - Q.add(i, q2) - } - assert(Q.length(q1) == 0) - assert(Q.to_list(q1) == list{}) - assert(Q.length(q2) == 4) - assert(Q.to_list(q2) == list{5, 6, 7, 8}) - Q.transfer(q1, q2) - assert(Q.length(q1) == 0) - assert(Q.to_list(q1) == list{}) - assert(Q.length(q2) == 4) - assert(Q.to_list(q2) == list{5, 6, 7, 8}) -} - -let () = { - let q1 = Q.create() and q2 = Q.create() - for i in 1 to 4 { - Q.add(i, q1) - } - for i in 5 to 8 { - Q.add(i, q2) - } - assert(Q.length(q1) == 4) - assert(Q.to_list(q1) == list{1, 2, 3, 4}) - assert(Q.length(q2) == 4) - assert(Q.to_list(q2) == list{5, 6, 7, 8}) - Q.transfer(q1, q2) - assert(Q.length(q1) == 0) - assert(Q.to_list(q1) == list{}) - assert(Q.length(q2) == 8) - assert(Q.to_list(q2) == list{5, 6, 7, 8, 1, 2, 3, 4}) -} - -let () = print_endline("OK") diff --git a/jscomp/test/limits_test.js b/jscomp/test/limits_test.js index f760da7ef1..c3b23fca77 100644 --- a/jscomp/test/limits_test.js +++ b/jscomp/test/limits_test.js @@ -2,7 +2,6 @@ 'use strict'; let Mt = require("./mt.js"); -let Int32 = require("../../lib/js/int32.js"); let Pervasives = require("../../lib/js/pervasives.js"); let suites = { @@ -17,7 +16,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -28,13 +27,9 @@ function eq(loc, x, y) { }; } -eq("File \"limits_test.res\", line 10, characters 5-12", Pervasives.max_int, 2147483647); +eq("File \"limits_test.res\", line 13, characters 5-12", Pervasives.max_int, 2147483647); -eq("File \"limits_test.res\", line 11, characters 5-12", Pervasives.min_int, -2147483648); - -eq("File \"limits_test.res\", line 12, characters 5-12", Int32.max_int, 2147483647); - -eq("File \"limits_test.res\", line 13, characters 5-12", Int32.min_int, -2147483648); +eq("File \"limits_test.res\", line 14, characters 5-12", Pervasives.min_int, -2147483648); Mt.from_pair_suites("Limits_test", suites.contents); diff --git a/jscomp/test/limits_test.res b/jscomp/test/limits_test.res index 5297c0a39c..a2d3da6ab7 100644 --- a/jscomp/test/limits_test.res +++ b/jscomp/test/limits_test.res @@ -3,14 +3,15 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let () = { eq(__LOC__, max_int, %raw("2147483647")) eq(__LOC__, min_int, %raw("-2147483648")) - eq(__LOC__, Int32.max_int, %raw("2147483647")) - eq(__LOC__, Int32.min_int, %raw("-2147483648")) } let () = Mt.from_pair_suites(__MODULE__, suites.contents) diff --git a/jscomp/test/list_stack.js b/jscomp/test/list_stack.js deleted file mode 100644 index 23e5faacef..0000000000 --- a/jscomp/test/list_stack.js +++ /dev/null @@ -1,8 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let List = require("../../lib/js/list.js"); - -List.find(x => x > 3, /* [] */0); - -/* Not a pure module */ diff --git a/jscomp/test/list_stack.res b/jscomp/test/list_stack.res deleted file mode 100644 index 483e4b0908..0000000000 --- a/jscomp/test/list_stack.res +++ /dev/null @@ -1 +0,0 @@ -List.find(x => x > 3, list{})->ignore diff --git a/jscomp/test/list_test.js b/jscomp/test/list_test.js index ac05021476..1558f00a75 100644 --- a/jscomp/test/list_test.js +++ b/jscomp/test/list_test.js @@ -2,16 +2,19 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml = require("../../lib/js/caml.js"); -let List = require("../../lib/js/list.js"); -let $$Array = require("../../lib/js/array.js"); +let Belt_List = require("../../lib/js/belt_List.js"); +let Belt_Array = require("../../lib/js/belt_Array.js"); +let Primitive_int = require("../../lib/js/primitive_int.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); + +let eq = Primitive_object.equal; let list_suites_0 = [ "length", param => ({ TAG: "Eq", _0: 1, - _1: List.length({ + _1: Belt_List.length({ hd: [ 0, 1, @@ -30,7 +33,7 @@ let list_suites_1 = { param => ({ TAG: "Eq", _0: 5, - _1: List.length({ + _1: Belt_List.length({ hd: 0, tl: { hd: 1, @@ -54,7 +57,7 @@ let list_suites_1 = { param => ({ TAG: "Eq", _0: 30000, - _1: List.length($$Array.to_list($$Array.init(30000, param => 0))) + _1: Belt_List.length(Belt_List.fromArray(Belt_Array.init(30000, param => 0))) }) ], tl: { @@ -62,7 +65,7 @@ let list_suites_1 = { "sort", param => ({ TAG: "Eq", - _0: List.sort(Caml.int_compare, { + _0: Belt_List.sort({ hd: 4, tl: { hd: 1, @@ -74,7 +77,7 @@ let list_suites_1 = { } } } - }), + }, Primitive_int.compare), _1: { hd: 1, tl: { @@ -92,11 +95,11 @@ let list_suites_1 = { ], tl: { hd: [ - "File \"list_test.res\", line 20, characters 5-12", + "File \"list_test.res\", line 23, characters 5-12", param => ({ TAG: "Eq", _0: true, - _1: List.mem(3, { + _1: Belt_List.has({ hd: 1, tl: { hd: 2, @@ -105,16 +108,16 @@ let list_suites_1 = { tl: /* [] */0 } } - }) + }, 3, eq) }) ], tl: { hd: [ - "File \"list_test.res\", line 21, characters 5-12", + "File \"list_test.res\", line 24, characters 5-12", param => ({ TAG: "Eq", _0: false, - _1: List.mem(4, { + _1: Belt_List.has({ hd: 1, tl: { hd: 2, @@ -123,16 +126,16 @@ let list_suites_1 = { tl: /* [] */0 } } - }) + }, 4, eq) }) ], tl: { hd: [ - "File \"list_test.res\", line 22, characters 5-12", + "File \"list_test.res\", line 25, characters 5-12", param => ({ TAG: "Eq", _0: 9, - _1: List.assoc(4, { + _1: Belt_List.getAssoc({ hd: [ 1, 2 @@ -144,7 +147,7 @@ let list_suites_1 = { ], tl: /* [] */0 } - }) + }, 4, eq) }) ], tl: /* [] */0 diff --git a/jscomp/test/list_test.res b/jscomp/test/list_test.res index 1febc6413f..2ce33df3b2 100644 --- a/jscomp/test/list_test.res +++ b/jscomp/test/list_test.res @@ -1,5 +1,8 @@ +open Belt + let list_suites = { open Mt + let eq = (a, b) => a == b list{ ("length", _ => Eq(1, List.length(list{(0, 1, 2, 3, 4)})) /* This is tuple haha */), ("length2", _ => Eq(5, List.length(list{0, 1, 2, 3, 4})) /* This is tuple haha */), @@ -7,19 +10,19 @@ let list_suites = { "long_length", _ => { let v = 30_000 - Eq(v, List.length(Array.to_list(Array.init(v, _ => 0)))) + Eq(v, List.length(List.fromArray(Array.init(v, _ => 0)))) }, ), ( "sort", _ => Eq( - List.sort((x: int, y) => Pervasives.compare(x, y), list{4, 1, 2, 3}), + list{4, 1, 2, 3}->List.sort((x: int, y) => Pervasives.compare(x, y)), list{1, 2, 3, 4}, ), ), - (__LOC__, _ => Eq(true, List.mem(3, list{1, 2, 3}))), - (__LOC__, _ => Eq(false, List.mem(4, list{1, 2, 3}))), - (__LOC__, _ => Eq(9, List.assoc(4, list{(1, 2), (4, 9)}))), + (__LOC__, _ => Eq(true, List.has(list{1, 2, 3}, 3, eq))), + (__LOC__, _ => Eq(false, List.has(list{1, 2, 3}, 4, eq))), + (__LOC__, _ => Eq(Some(9), List.getAssoc(list{(1, 2), (4, 9)}, 4, eq))), } } diff --git a/jscomp/test/local_exception_test.js b/jscomp/test/local_exception_test.js index 702e86d985..5954f2c2fa 100644 --- a/jscomp/test/local_exception_test.js +++ b/jscomp/test/local_exception_test.js @@ -1,9 +1,9 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); -let A = /* @__PURE__ */Caml_exceptions.create("Local_exception_test.A"); +let A = /* @__PURE__ */Primitive_exceptions.create("Local_exception_test.A"); let v = { RE_EXN_ID: A, @@ -11,13 +11,13 @@ let v = { _2: true }; -let B = /* @__PURE__ */Caml_exceptions.create("Local_exception_test.B"); +let B = /* @__PURE__ */Primitive_exceptions.create("Local_exception_test.B"); let u = { RE_EXN_ID: B }; -let D = /* @__PURE__ */Caml_exceptions.create("Local_exception_test.D"); +let D = /* @__PURE__ */Primitive_exceptions.create("Local_exception_test.D"); let d = { RE_EXN_ID: D, diff --git a/jscomp/test/map_find_test.js b/jscomp/test/map_find_test.js index 584e25c7e1..3cd748cb7a 100644 --- a/jscomp/test/map_find_test.js +++ b/jscomp/test/map_find_test.js @@ -2,158 +2,11 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml = require("../../lib/js/caml.js"); -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); +let Belt_MapInt = require("../../lib/js/belt_MapInt.js"); +let Belt_MapString = require("../../lib/js/belt_MapString.js"); -function height(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} - -function create(l, x, d, r) { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} - -function bal(l, x, d, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; -} - -function add(x, data, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml.int_compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function find(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let c = Caml.int_compare(x, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -let m = List.fold_left((acc, param) => add(param[0], param[1], acc), "Empty", { +let m = Belt_List.reduceReverse({ hd: [ 10, /* 'a' */97 @@ -177,157 +30,9 @@ let m = List.fold_left((acc, param) => add(param[0], param[1], acc), "Empty", { } } } -}); - -function height$1(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} - -function create$1(l, x, d, r) { - let hl = height$1(l); - let hr = height$1(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} - -function bal$1(l, x, d, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height$1(ll) >= height$1(lr)) { - return create$1(ll, lv, ld, create$1(lr, x, d, r)); - } - if (typeof lr === "object") { - return create$1(create$1(ll, lv, ld, lr.l), lr.v, lr.d, create$1(lr.r, x, d, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height$1(rr) >= height$1(rl)) { - return create$1(create$1(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create$1(create$1(l, x, d, rl.l), rl.v, rl.d, create$1(rl.r, rv, rd, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; -} +}, undefined, (acc, param) => Belt_MapInt.set(acc, param[0], param[1])); -function add$1(x, data, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml.string_compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add$1(x, data, l); - if (l === ll) { - return param; - } else { - return bal$1(ll, v, d, r); - } - } - let rr = add$1(x, data, r); - if (r === rr) { - return param; - } else { - return bal$1(l, v, d, rr); - } -} - -function find$1(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let c = Caml.string_compare(x, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -let s = List.fold_left((acc, param) => add$1(param[0], param[1], acc), "Empty", { +let s = Belt_List.reduceReverse({ hd: [ "10", /* 'a' */97 @@ -351,14 +56,14 @@ let s = List.fold_left((acc, param) => add$1(param[0], param[1], acc), "Empty", } } } -}); +}, undefined, (acc, param) => Belt_MapString.set(acc, param[0], param[1])); Mt.from_pair_suites("Map_find_test", { hd: [ "int", () => ({ TAG: "Eq", - _0: find(10, m), + _0: Belt_MapInt.get(m, 10), _1: /* 'a' */97 }) ], @@ -367,7 +72,7 @@ Mt.from_pair_suites("Map_find_test", { "string", () => ({ TAG: "Eq", - _0: find$1("10", s), + _0: Belt_MapString.get(s, "10"), _1: /* 'a' */97 }) ], diff --git a/jscomp/test/map_find_test.res b/jscomp/test/map_find_test.res index 43cf4300f8..0f5c367623 100644 --- a/jscomp/test/map_find_test.res +++ b/jscomp/test/map_find_test.res @@ -1,33 +1,30 @@ +open Belt + include ( { - module IntMap = Map.Make({ - type t = int - let compare = (x: t, y) => compare(x, y) - }) + module IntMap = Map.Int let empty = IntMap.empty - let m = List.fold_left( - (acc, (k, v)) => IntMap.add(k, v, acc), - empty, - list{(10, 'a'), (3, 'b'), (7, 'c'), (20, 'd')}, - ) + let m = List.reduceReverse(list{(10, 'a'), (3, 'b'), (7, 'c'), (20, 'd')}, empty, ( + acc, + (k, v), + ) => acc->IntMap.set(k, v)) - module SMap = Map.Make({ - type t = string - let compare = (x: t, y) => compare(x, y) - }) + module SMap = Map.String - let s = List.fold_left( - (acc, (k, v)) => SMap.add(k, v, acc), - SMap.empty, - list{("10", 'a'), ("3", 'b'), ("7", 'c'), ("20", 'd')}, - ) + let s = List.reduceReverse(list{("10", 'a'), ("3", 'b'), ("7", 'c'), ("20", 'd')}, SMap.empty, ( + acc, + (k, v), + ) => acc->SMap.set(k, v)) @val("console.log") external log: 'a => unit = "" \"@@"( Mt.from_pair_suites(__MODULE__, ...), - list{("int", _ => Eq(IntMap.find(10, m), 'a')), ("string", _ => Eq(SMap.find("10", s), 'a'))} + list{ + ("int", _ => Eq(IntMap.get(m, 10), Some('a'))), + ("string", _ => Eq(SMap.get(s, "10"), Some('a'))), + } ) }: {} ) diff --git a/jscomp/test/map_test.js b/jscomp/test/map_test.js deleted file mode 100644 index 72a78eeacc..0000000000 --- a/jscomp/test/map_test.js +++ /dev/null @@ -1,2152 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let Caml = require("../../lib/js/caml.js"); -let List = require("../../lib/js/list.js"); -let Caml_option = require("../../lib/js/caml_option.js"); - -let compare = Caml.int_compare; - -let Int = { - compare: compare -}; - -function height(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} - -function create(l, x, d, r) { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} - -function singleton(x, d) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: d, - r: "Empty", - h: 1 - }; -} - -function bal(l, x, d, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; -} - -function is_empty(param) { - if (typeof param !== "object") { - return true; - } else { - return false; - } -} - -function add(x, data, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml.int_compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function find(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let c = Caml.int_compare(x, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function find_first(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_first_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_last(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_last_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_opt(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let c = Caml.int_compare(x, param.v); - if (c === 0) { - return Caml_option.some(param.d); - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function mem(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = Caml.int_compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function min_binding(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; -} - -function min_binding_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; -} - -function max_binding(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; -} - -function max_binding_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; -} - -function remove_min_binding(param) { - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.remove_min_elt", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_binding(l), param.v, param.d, param.r); - } -} - -function merge(t1, t2) { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return bal(t1, match[0], match[1], remove_min_binding(t2)); -} - -function remove(x, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml.int_compare(x, v); - if (c === 0) { - return merge(l, r); - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function update(x, f, param) { - if (typeof param !== "object") { - let data = f(undefined); - if (data !== undefined) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: Caml_option.valFromOption(data), - r: "Empty", - h: 1 - }; - } else { - return "Empty"; - } - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml.int_compare(x, v); - if (c === 0) { - let data$1 = f(Caml_option.some(d)); - if (data$1 === undefined) { - return merge(l, r); - } - let data$2 = Caml_option.valFromOption(data$1); - if (d === data$2) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data$2, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = update(x, f, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = update(x, f, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function iter(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v, param.d); - _param = param.r; - continue; - }; -} - -function map(f, param) { - if (typeof param !== "object") { - return "Empty"; - } - let l$p = map(f, param.l); - let d$p = f(param.d); - let r$p = map(f, param.r); - return { - TAG: "Node", - l: l$p, - v: param.v, - d: d$p, - r: r$p, - h: param.h - }; -} - -function mapi(f, param) { - if (typeof param !== "object") { - return "Empty"; - } - let v = param.v; - let l$p = mapi(f, param.l); - let d$p = f(v, param.d); - let r$p = mapi(f, param.r); - return { - TAG: "Node", - l: l$p, - v: v, - d: d$p, - r: r$p, - h: param.h - }; -} - -function fold(f, _m, _accu) { - while (true) { - let accu = _accu; - let m = _m; - if (typeof m !== "object") { - return accu; - } - _accu = f(m.v, m.d, fold(f, m.l, accu)); - _m = m.r; - continue; - }; -} - -function for_all(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v, param.d)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; -} - -function exists(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v, param.d)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; -} - -function add_min_binding(k, x, param) { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(add_min_binding(k, x, param.l), param.v, param.d, param.r); - } -} - -function add_max_binding(k, x, param) { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(param.l, param.v, param.d, add_max_binding(k, x, param.r)); - } -} - -function join(l, v, d, r) { - if (typeof l !== "object") { - return add_min_binding(v, d, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_binding(v, d, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, l.d, join(l.r, v, d, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, d, r.l), r.v, r.d, r.r); - } else { - return create(l, v, d, r); - } -} - -function concat(t1, t2) { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return join(t1, match[0], match[1], remove_min_binding(t2)); -} - -function concat_or_join(t1, v, d, t2) { - if (d !== undefined) { - return join(t1, v, Caml_option.valFromOption(d), t2); - } else { - return concat(t1, t2); - } -} - -function split(x, param) { - if (typeof param !== "object") { - return [ - "Empty", - undefined, - "Empty" - ]; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml.int_compare(x, v); - if (c === 0) { - return [ - l, - Caml_option.some(d), - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, d, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, d, match$1[0]), - match$1[1], - match$1[2] - ]; -} - -function merge$1(f, s1, s2) { - if (typeof s1 !== "object") { - if (typeof s2 !== "object") { - return "Empty"; - } - - } else { - let v1 = s1.v; - if (s1.h >= height(s2)) { - let match = split(v1, s2); - return concat_or_join(merge$1(f, s1.l, match[0]), v1, f(v1, Caml_option.some(s1.d), match[1]), merge$1(f, s1.r, match[2])); - } - - } - if (typeof s2 !== "object") { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "map.res", - 552, - 11 - ], - Error: new Error() - }; - } - let v2 = s2.v; - let match$1 = split(v2, s1); - return concat_or_join(merge$1(f, match$1[0], s2.l), v2, f(v2, match$1[1], Caml_option.some(s2.d)), merge$1(f, match$1[2], s2.r)); -} - -function union(f, s1, s2) { - if (typeof s1 !== "object") { - return s2; - } - let d1 = s1.d; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let d2 = s2.d; - let v2 = s2.v; - if (s1.h >= s2.h) { - let match = split(v1, s2); - let d2$1 = match[1]; - let l = union(f, s1.l, match[0]); - let r = union(f, s1.r, match[2]); - if (d2$1 !== undefined) { - return concat_or_join(l, v1, f(v1, d1, Caml_option.valFromOption(d2$1)), r); - } else { - return join(l, v1, d1, r); - } - } - let match$1 = split(v2, s1); - let d1$1 = match$1[1]; - let l$1 = union(f, match$1[0], s2.l); - let r$1 = union(f, match$1[2], s2.r); - if (d1$1 !== undefined) { - return concat_or_join(l$1, v2, f(v2, Caml_option.valFromOption(d1$1), d2), r$1); - } else { - return join(l$1, v2, d2, r$1); - } -} - -function filter(p, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pvd = p(v, d); - let r$p = filter(p, r); - if (pvd) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, d, r$p); - } - } else { - return concat(l$p, r$p); - } -} - -function partition(p, param) { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let d = param.d; - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pvd = p(v, d); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pvd) { - return [ - join(lt, v, d, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, d, rf) - ]; - } -} - -function cons_enum(_m, _e) { - while (true) { - let e = _e; - let m = _m; - if (typeof m !== "object") { - return e; - } - _e = { - TAG: "More", - _0: m.v, - _1: m.d, - _2: m.r, - _3: e - }; - _m = m.l; - continue; - }; -} - -function compare$1(cmp, m1, m2) { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = Caml.int_compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - let c$1 = cmp(e1._1, e2._1); - if (c$1 !== 0) { - return c$1; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; -} - -function equal(cmp, m1, m2) { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return true; - } else { - return false; - } - } - if (typeof e2 !== "object") { - return false; - } - if (e1._0 !== e2._0) { - return false; - } - if (!cmp(e1._1, e2._1)) { - return false; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; -} - -function cardinal(param) { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } -} - -function bindings_aux(_accu, _param) { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: [ - param.v, - param.d - ], - tl: bindings_aux(accu, param.r) - }; - continue; - }; -} - -function bindings(s) { - return bindings_aux(/* [] */0, s); -} - -let Int_map = { - empty: "Empty", - is_empty: is_empty, - mem: mem, - add: add, - update: update, - singleton: singleton, - remove: remove, - merge: merge$1, - union: union, - compare: compare$1, - equal: equal, - iter: iter, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - bindings: bindings, - min_binding: min_binding, - min_binding_opt: min_binding_opt, - max_binding: max_binding, - max_binding_opt: max_binding_opt, - choose: min_binding, - choose_opt: min_binding_opt, - split: split, - find: find, - find_opt: find_opt, - find_first: find_first, - find_first_opt: find_first_opt, - find_last: find_last, - find_last_opt: find_last_opt, - map: map, - mapi: mapi -}; - -function height$1(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} - -function create$1(l, x, d, r) { - let hl = height$1(l); - let hr = height$1(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} - -function singleton$1(x, d) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: d, - r: "Empty", - h: 1 - }; -} - -function bal$1(l, x, d, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height$1(ll) >= height$1(lr)) { - return create$1(ll, lv, ld, create$1(lr, x, d, r)); - } - if (typeof lr === "object") { - return create$1(create$1(ll, lv, ld, lr.l), lr.v, lr.d, create$1(lr.r, x, d, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height$1(rr) >= height$1(rl)) { - return create$1(create$1(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create$1(create$1(l, x, d, rl.l), rl.v, rl.d, create$1(rl.r, rv, rd, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; -} - -function is_empty$1(param) { - if (typeof param !== "object") { - return true; - } else { - return false; - } -} - -function add$1(x, data, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml.string_compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add$1(x, data, l); - if (l === ll) { - return param; - } else { - return bal$1(ll, v, d, r); - } - } - let rr = add$1(x, data, r); - if (r === rr) { - return param; - } else { - return bal$1(l, v, d, rr); - } -} - -function find$1(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let c = Caml.string_compare(x, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function find_first$1(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_first_opt$1(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_last$1(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_last_opt$1(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_opt$1(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let c = Caml.string_compare(x, param.v); - if (c === 0) { - return Caml_option.some(param.d); - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function mem$1(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = Caml.string_compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function min_binding$1(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; -} - -function min_binding_opt$1(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; -} - -function max_binding$1(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; -} - -function max_binding_opt$1(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; -} - -function remove_min_binding$1(param) { - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.remove_min_elt", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal$1(remove_min_binding$1(l), param.v, param.d, param.r); - } -} - -function merge$2(t1, t2) { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding$1(t2); - return bal$1(t1, match[0], match[1], remove_min_binding$1(t2)); -} - -function remove$1(x, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml.string_compare(x, v); - if (c === 0) { - return merge$2(l, r); - } - if (c < 0) { - let ll = remove$1(x, l); - if (l === ll) { - return param; - } else { - return bal$1(ll, v, d, r); - } - } - let rr = remove$1(x, r); - if (r === rr) { - return param; - } else { - return bal$1(l, v, d, rr); - } -} - -function update$1(x, f, param) { - if (typeof param !== "object") { - let data = f(undefined); - if (data !== undefined) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: Caml_option.valFromOption(data), - r: "Empty", - h: 1 - }; - } else { - return "Empty"; - } - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml.string_compare(x, v); - if (c === 0) { - let data$1 = f(Caml_option.some(d)); - if (data$1 === undefined) { - return merge$2(l, r); - } - let data$2 = Caml_option.valFromOption(data$1); - if (d === data$2) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data$2, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = update$1(x, f, l); - if (l === ll) { - return param; - } else { - return bal$1(ll, v, d, r); - } - } - let rr = update$1(x, f, r); - if (r === rr) { - return param; - } else { - return bal$1(l, v, d, rr); - } -} - -function iter$1(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter$1(f, param.l); - f(param.v, param.d); - _param = param.r; - continue; - }; -} - -function map$1(f, param) { - if (typeof param !== "object") { - return "Empty"; - } - let l$p = map$1(f, param.l); - let d$p = f(param.d); - let r$p = map$1(f, param.r); - return { - TAG: "Node", - l: l$p, - v: param.v, - d: d$p, - r: r$p, - h: param.h - }; -} - -function mapi$1(f, param) { - if (typeof param !== "object") { - return "Empty"; - } - let v = param.v; - let l$p = mapi$1(f, param.l); - let d$p = f(v, param.d); - let r$p = mapi$1(f, param.r); - return { - TAG: "Node", - l: l$p, - v: v, - d: d$p, - r: r$p, - h: param.h - }; -} - -function fold$1(f, _m, _accu) { - while (true) { - let accu = _accu; - let m = _m; - if (typeof m !== "object") { - return accu; - } - _accu = f(m.v, m.d, fold$1(f, m.l, accu)); - _m = m.r; - continue; - }; -} - -function for_all$1(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v, param.d)) { - return false; - } - if (!for_all$1(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; -} - -function exists$1(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v, param.d)) { - return true; - } - if (exists$1(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; -} - -function add_min_binding$1(k, x, param) { - if (typeof param !== "object") { - return singleton$1(k, x); - } else { - return bal$1(add_min_binding$1(k, x, param.l), param.v, param.d, param.r); - } -} - -function add_max_binding$1(k, x, param) { - if (typeof param !== "object") { - return singleton$1(k, x); - } else { - return bal$1(param.l, param.v, param.d, add_max_binding$1(k, x, param.r)); - } -} - -function join$1(l, v, d, r) { - if (typeof l !== "object") { - return add_min_binding$1(v, d, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_binding$1(v, d, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal$1(l.l, l.v, l.d, join$1(l.r, v, d, r)); - } else if (rh > (lh + 2 | 0)) { - return bal$1(join$1(l, v, d, r.l), r.v, r.d, r.r); - } else { - return create$1(l, v, d, r); - } -} - -function concat$1(t1, t2) { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding$1(t2); - return join$1(t1, match[0], match[1], remove_min_binding$1(t2)); -} - -function concat_or_join$1(t1, v, d, t2) { - if (d !== undefined) { - return join$1(t1, v, Caml_option.valFromOption(d), t2); - } else { - return concat$1(t1, t2); - } -} - -function split$1(x, param) { - if (typeof param !== "object") { - return [ - "Empty", - undefined, - "Empty" - ]; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml.string_compare(x, v); - if (c === 0) { - return [ - l, - Caml_option.some(d), - r - ]; - } - if (c < 0) { - let match = split$1(x, l); - return [ - match[0], - match[1], - join$1(match[2], v, d, r) - ]; - } - let match$1 = split$1(x, r); - return [ - join$1(l, v, d, match$1[0]), - match$1[1], - match$1[2] - ]; -} - -function merge$3(f, s1, s2) { - if (typeof s1 !== "object") { - if (typeof s2 !== "object") { - return "Empty"; - } - - } else { - let v1 = s1.v; - if (s1.h >= height$1(s2)) { - let match = split$1(v1, s2); - return concat_or_join$1(merge$3(f, s1.l, match[0]), v1, f(v1, Caml_option.some(s1.d), match[1]), merge$3(f, s1.r, match[2])); - } - - } - if (typeof s2 !== "object") { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "map.res", - 552, - 11 - ], - Error: new Error() - }; - } - let v2 = s2.v; - let match$1 = split$1(v2, s1); - return concat_or_join$1(merge$3(f, match$1[0], s2.l), v2, f(v2, match$1[1], Caml_option.some(s2.d)), merge$3(f, match$1[2], s2.r)); -} - -function union$1(f, s1, s2) { - if (typeof s1 !== "object") { - return s2; - } - let d1 = s1.d; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let d2 = s2.d; - let v2 = s2.v; - if (s1.h >= s2.h) { - let match = split$1(v1, s2); - let d2$1 = match[1]; - let l = union$1(f, s1.l, match[0]); - let r = union$1(f, s1.r, match[2]); - if (d2$1 !== undefined) { - return concat_or_join$1(l, v1, f(v1, d1, Caml_option.valFromOption(d2$1)), r); - } else { - return join$1(l, v1, d1, r); - } - } - let match$1 = split$1(v2, s1); - let d1$1 = match$1[1]; - let l$1 = union$1(f, match$1[0], s2.l); - let r$1 = union$1(f, match$1[2], s2.r); - if (d1$1 !== undefined) { - return concat_or_join$1(l$1, v2, f(v2, Caml_option.valFromOption(d1$1), d2), r$1); - } else { - return join$1(l$1, v2, d2, r$1); - } -} - -function filter$1(p, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let l$p = filter$1(p, l); - let pvd = p(v, d); - let r$p = filter$1(p, r); - if (pvd) { - if (l === l$p && r === r$p) { - return param; - } else { - return join$1(l$p, v, d, r$p); - } - } else { - return concat$1(l$p, r$p); - } -} - -function partition$1(p, param) { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let d = param.d; - let v = param.v; - let match = partition$1(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pvd = p(v, d); - let match$1 = partition$1(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pvd) { - return [ - join$1(lt, v, d, rt), - concat$1(lf, rf) - ]; - } else { - return [ - concat$1(lt, rt), - join$1(lf, v, d, rf) - ]; - } -} - -function cons_enum$1(_m, _e) { - while (true) { - let e = _e; - let m = _m; - if (typeof m !== "object") { - return e; - } - _e = { - TAG: "More", - _0: m.v, - _1: m.d, - _2: m.r, - _3: e - }; - _m = m.l; - continue; - }; -} - -function compare$2(cmp, m1, m2) { - let _e1 = cons_enum$1(m1, "End"); - let _e2 = cons_enum$1(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = Caml.string_compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - let c$1 = cmp(e1._1, e2._1); - if (c$1 !== 0) { - return c$1; - } - _e2 = cons_enum$1(e2._2, e2._3); - _e1 = cons_enum$1(e1._2, e1._3); - continue; - }; -} - -function equal$1(cmp, m1, m2) { - let _e1 = cons_enum$1(m1, "End"); - let _e2 = cons_enum$1(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return true; - } else { - return false; - } - } - if (typeof e2 !== "object") { - return false; - } - if (Caml.string_compare(e1._0, e2._0) !== 0) { - return false; - } - if (!cmp(e1._1, e2._1)) { - return false; - } - _e2 = cons_enum$1(e2._2, e2._3); - _e1 = cons_enum$1(e1._2, e1._3); - continue; - }; -} - -function cardinal$1(param) { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal$1(param.l) + 1 | 0) + cardinal$1(param.r) | 0; - } -} - -function bindings_aux$1(_accu, _param) { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: [ - param.v, - param.d - ], - tl: bindings_aux$1(accu, param.r) - }; - continue; - }; -} - -function bindings$1(s) { - return bindings_aux$1(/* [] */0, s); -} - -let String_map = { - empty: "Empty", - is_empty: is_empty$1, - mem: mem$1, - add: add$1, - update: update$1, - singleton: singleton$1, - remove: remove$1, - merge: merge$3, - union: union$1, - compare: compare$2, - equal: equal$1, - iter: iter$1, - fold: fold$1, - for_all: for_all$1, - exists: exists$1, - filter: filter$1, - partition: partition$1, - cardinal: cardinal$1, - bindings: bindings$1, - min_binding: min_binding$1, - min_binding_opt: min_binding_opt$1, - max_binding: max_binding$1, - max_binding_opt: max_binding_opt$1, - choose: min_binding$1, - choose_opt: min_binding_opt$1, - split: split$1, - find: find$1, - find_opt: find_opt$1, - find_first: find_first$1, - find_first_opt: find_first_opt$1, - find_last: find_last$1, - find_last_opt: find_last_opt$1, - map: map$1, - mapi: mapi$1 -}; - -function of_list(kvs) { - return List.fold_left((acc, param) => add(param[0], param[1], acc), "Empty", kvs); -} - -let int_map_suites_0 = [ - "add", - param => { - let v = of_list({ - hd: [ - 1, - /* '1' */49 - ], - tl: { - hd: [ - 2, - /* '3' */51 - ], - tl: { - hd: [ - 3, - /* '4' */52 - ], - tl: /* [] */0 - } - } - }); - return { - TAG: "Eq", - _0: cardinal(v), - _1: 3 - }; - } -]; - -let int_map_suites_1 = { - hd: [ - "equal", - param => { - let v = of_list({ - hd: [ - 1, - /* '1' */49 - ], - tl: { - hd: [ - 2, - /* '3' */51 - ], - tl: { - hd: [ - 3, - /* '4' */52 - ], - tl: /* [] */0 - } - } - }); - let u = of_list({ - hd: [ - 2, - /* '3' */51 - ], - tl: { - hd: [ - 3, - /* '4' */52 - ], - tl: { - hd: [ - 1, - /* '1' */49 - ], - tl: /* [] */0 - } - } - }); - return { - TAG: "Eq", - _0: compare$1(Caml.int_compare, u, v), - _1: 0 - }; - } - ], - tl: { - hd: [ - "equal2", - param => { - let v = of_list({ - hd: [ - 1, - /* '1' */49 - ], - tl: { - hd: [ - 2, - /* '3' */51 - ], - tl: { - hd: [ - 3, - /* '4' */52 - ], - tl: /* [] */0 - } - } - }); - let u = of_list({ - hd: [ - 2, - /* '3' */51 - ], - tl: { - hd: [ - 3, - /* '4' */52 - ], - tl: { - hd: [ - 1, - /* '1' */49 - ], - tl: /* [] */0 - } - } - }); - return { - TAG: "Eq", - _0: true, - _1: equal((x, y) => x === y, u, v) - }; - } - ], - tl: { - hd: [ - "iteration", - param => { - let m = "Empty"; - for (let i = 0; i <= 10000; ++i) { - m = add$1(String(i), String(i), m); - } - let v = -1; - for (let i$1 = 0; i$1 <= 10000; ++i$1) { - if (find$1(String(i$1), m) !== String(i$1)) { - v = i$1; - } - - } - return { - TAG: "Eq", - _0: v, - _1: -1 - }; - } - ], - tl: /* [] */0 - } - } -}; - -let int_map_suites = { - hd: int_map_suites_0, - tl: int_map_suites_1 -}; - -Mt.from_pair_suites("Map_test", int_map_suites); - -exports.Int = Int; -exports.Int_map = Int_map; -exports.String_map = String_map; -exports.of_list = of_list; -exports.int_map_suites = int_map_suites; -/* Not a pure module */ diff --git a/jscomp/test/map_test.res b/jscomp/test/map_test.res deleted file mode 100644 index ee6d432686..0000000000 --- a/jscomp/test/map_test.res +++ /dev/null @@ -1,57 +0,0 @@ -open Mt -module Int = { - type t = int - let compare = (x: int, y: int) => Pervasives.compare(x, y) -} -module Int_map = Map.Make(Int) -module String_map = Map.Make(String) - -let of_list = kvs => List.fold_left((acc, (k, v)) => Int_map.add(k, v, acc), Int_map.empty, kvs) - -let int_map_suites = { - open Mt - open Int_map - list{ - ( - "add", - _ => { - let v = of_list(list{(1, '1'), (2, '3'), (3, '4')}) - Eq(cardinal(v), 3) - }, - ), - ( - "equal", - _ => { - let v = of_list(list{(1, '1'), (2, '3'), (3, '4')}) - let u = of_list(list{(2, '3'), (3, '4'), (1, '1')}) - Eq(compare(Pervasives.compare, u, v), 0) - }, - ), - ( - "equal2", - _ => { - let v = of_list(list{(1, '1'), (2, '3'), (3, '4')}) - let u = of_list(list{(2, '3'), (3, '4'), (1, '1')}) - Eq(true, equal((x, y) => x == y, u, v)) - }, - ), - ( - "iteration", - _ => { - let m = ref(String_map.empty) - let count = 1_0000 - for i in 0 to count { - m := String_map.add(string_of_int(i), string_of_int(i), m.contents) - } - let v = ref(-1) - for i in 0 to count { - if String_map.find(string_of_int(i), m.contents) !== string_of_int(i) { - v := i - } - } - Eq(v.contents, -1) - }, - ), - } -} -Mt.from_pair_suites(__MODULE__, int_map_suites) diff --git a/jscomp/test/mario_game.js b/jscomp/test/mario_game.js index 778211b4a8..cc97f07907 100644 --- a/jscomp/test/mario_game.js +++ b/jscomp/test/mario_game.js @@ -1,13 +1,26 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml = require("../../lib/js/caml.js"); -let List = require("../../lib/js/list.js"); -let Random = require("../../lib/js/random.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); -let Caml_int32 = require("../../lib/js/caml_int32.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let Pervasives = require("../../lib/js/pervasives.js"); -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_int = require("../../lib/js/primitive_int.js"); +let Primitive_bool = require("../../lib/js/primitive_bool.js"); +let Primitive_float = require("../../lib/js/primitive_float.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); + +function self_init() { + +} + +let int = ((max) => { + return ((Math.random() * 100) | 0) % max; + }); + +let Random = { + self_init: self_init, + int: int +}; let Actors = {}; @@ -23,7 +36,7 @@ function setup_sprite(loopOpt, bbox_offsetOpt, bbox_sizeOpt, img_src, max_frames 0, 0 ]; - let bbox_size$1 = Caml_obj.equal(bbox_size, [ + let bbox_size$1 = Primitive_object.equal(bbox_size, [ 0, 0 ]) ? frame_size : bbox_size; @@ -662,7 +675,7 @@ function update_animation(spr) { if (curr_ticks >= spr.params.max_ticks) { spr.ticks.contents = 0; if (spr.params.loop) { - spr.frame.contents = Caml_int32.mod_(spr.frame.contents + 1 | 0, spr.params.max_frames); + spr.frame.contents = Primitive_int.mod_(spr.frame.contents + 1 | 0, spr.params.max_frames); return; } else { return; @@ -836,7 +849,7 @@ function new_id() { } function make$2($staropt$star, $staropt$star$1, spawnable, context, param) { - let id = $staropt$star !== undefined ? Caml_option.valFromOption($staropt$star) : undefined; + let id = $staropt$star !== undefined ? Primitive_option.valFromOption($staropt$star) : undefined; let dir = $staropt$star$1 !== undefined ? $staropt$star$1 : "Left"; let spr = make(spawnable, dir, context); let params = make_type$2(spawnable); @@ -948,7 +961,7 @@ function update_player(player, keys, context) { let prev_jumping = player.jumping; let prev_dir = player.dir; let prev_vx = Math.abs(player.vel.x); - List.iter(extra => { + Belt_List.forEach(keys, extra => { let lr_acc = player.vel.x * 0.2; switch (extra) { case "CLeft" : @@ -975,7 +988,7 @@ function update_player(player, keys, context) { if (!player.jumping && player.grounded) { player.jumping = true; player.grounded = false; - player.vel.y = Caml.float_max(player.vel.y - (5.7 + Math.abs(player.vel.x) * 0.25), -6); + player.vel.y = Primitive_bool.max(player.vel.y - (5.7 + Math.abs(player.vel.x) * 0.25), -6); return; } else { return; @@ -988,7 +1001,7 @@ function update_player(player, keys, context) { return; } } - }, keys); + }); let v = player.vel.x * 0.9; let vel_damped = Math.abs(v) < 0.1 ? 0 : v; player.vel.x = vel_damped; @@ -1048,7 +1061,7 @@ function update_vel$1(obj) { obj.vel.y = 0; return; } else if (obj.params.has_gravity) { - obj.vel.y = Caml.float_min(obj.vel.y + 0.2 + Math.abs(obj.vel.y) * 0.01, 4.5); + obj.vel.y = Primitive_float.min(obj.vel.y + 0.2 + Math.abs(obj.vel.y) * 0.01, 4.5); return; } else { return; @@ -1463,8 +1476,8 @@ function clear_canvas(canvas) { } function hud(canvas, score, coins) { - let score_string = String(score); - let coin_string = String(coins); + let score_string = score.toString(); + let coin_string = coins.toString(); let context = canvas.getContext("2d"); context.font = "10px 'Press Start 2P'"; context.fillText("Score: " + score_string, canvas.width - 140, 18); @@ -1472,7 +1485,7 @@ function hud(canvas, score, coins) { } function fps(canvas, fps_val) { - let fps_str = String(fps_val | 0); + let fps_str = fps_val.toFixed(); let context = canvas.getContext("2d"); context.fillText(fps_str, 10, 18); } @@ -1535,7 +1548,7 @@ function make$3(param, param$1) { function calc_viewport_point(cc, vc, mc) { let vc_half = vc / 2; - return Caml.float_min(Caml.float_max(cc - vc_half, 0), Caml.float_min(mc - vc, Math.abs(cc - vc_half))); + return Primitive_float.min(Primitive_bool.max(cc - vc_half, 0), Primitive_float.min(mc - vc, Math.abs(cc - vc_half))); } function in_viewport(v, pos) { @@ -2083,13 +2096,13 @@ function process_collision(dir, c1, c2, state) { function broad_phase(collid, all_collids, state) { let obj = collid._2; - return List.filter(c => { + return Belt_List.filter(all_collids, c => { if (in_viewport(state.vpt, obj.pos) || is_player(collid)) { return true; } else { return out_of_viewport_below(state.vpt, obj.pos.y); } - }, all_collids); + }); } function check_collisions(collid, all_collids, state) { @@ -2203,7 +2216,7 @@ function translate_keys() { hd: ctrls_0, tl: ctrls_1 }; - return List.fold_left((a, x) => { + return Belt_List.reduceReverse(ctrls, /* [] */0, (a, x) => { if (x[0]) { return { hd: x[1], @@ -2212,7 +2225,7 @@ function translate_keys() { } else { return a; } - }, /* [] */0, ctrls); + }); } function run_update_collid(state, collid, all_collids) { @@ -2282,7 +2295,7 @@ function update_loop(canvas, param, map_dim) { clear_canvas(canvas); let vpos_x_int = state.vpt.pos.x / 5 | 0; let bgd_width = state.bgd.params.frame_size[0] | 0; - draw_bgd(state.bgd, Caml_int32.mod_(vpos_x_int, bgd_width)); + draw_bgd(state.bgd, Primitive_int.mod_(vpos_x_int, bgd_width)); let player$1 = run_update_collid(state, player, objs); if (player$1._2.kill === true) { return game_loss(state.ctx); @@ -2297,10 +2310,10 @@ function update_loop(canvas, param, map_dim) { multiplier: state.multiplier, game_over: state.game_over }; - List.iter(obj => { + Belt_List.forEach(objs, obj => { run_update_collid(state$1, obj, objs); - }, objs); - List.iter(part => { + }); + Belt_List.forEach(parts, part => { process(part); let x = part.pos.x - state$1.vpt.pos.x; let y = part.pos.y - state$1.vpt.pos.y; @@ -2316,7 +2329,7 @@ function update_loop(canvas, param, map_dim) { return; } - }, parts); + }); fps(canvas, fps$1); hud(canvas, state$1.score, state$1.coins); requestAnimationFrame(t => update_helper(t, state$1, player$1, collid_objs.contents, particles.contents)); @@ -2428,7 +2441,7 @@ function mem_loc(checkloc, _loclist) { if (!loclist) { return false; } - if (Caml_obj.equal(checkloc, loclist.hd[1])) { + if (Primitive_object.equal(checkloc, loclist.hd[1])) { return true; } _loclist = loclist.tl; @@ -2556,7 +2569,7 @@ function generate_clouds(cbx, cby, typ, num) { function generate_coins(_block_coord) { while (true) { let block_coord = _block_coord; - let place_coin = Random.int(2); + let place_coin = int(2); if (!block_coord) { return /* [] */0; } @@ -2585,9 +2598,9 @@ function choose_block_pattern(blockw, blockh, cbx, cby, prob) { if (cbx > blockw || cby > blockh) { return /* [] */0; } - let block_typ = Random.int(4); - let stair_typ = Random.int(2); - let life_block_chance = Random.int(5); + let block_typ = int(4); + let stair_typ = int(2); + let life_block_chance = int(5); let middle_block = life_block_chance === 0 ? 3 : stair_typ; switch (prob) { case 0 : @@ -2653,7 +2666,7 @@ function choose_block_pattern(blockw, blockh, cbx, cby, prob) { }; } case 1 : - let num_clouds = Random.int(5) + 5 | 0; + let num_clouds = int(5) + 5 | 0; if (cby < 5) { return generate_clouds(cbx, cby, 2, num_clouds); } else { @@ -3028,7 +3041,7 @@ function generate_enemies(blockw, blockh, _cbx, _cby, acc) { _cby = cby + 1; continue; } - let prob = Random.int(30); + let prob = int(30); if (prob < 3 && blockh - 1 === cby) { let enemy_0 = [ prob, @@ -3051,8 +3064,8 @@ function generate_enemies(blockw, blockh, _cbx, _cby, acc) { function generate_block_enemies(_block_coord) { while (true) { let block_coord = _block_coord; - let place_enemy = Random.int(20); - let enemy_typ = Random.int(3); + let place_enemy = int(20); + let enemy_typ = int(3); if (!block_coord) { return /* [] */0; } @@ -3097,7 +3110,7 @@ function generate_block_locs(blockw, blockh, _cbx, _cby, _acc) { _cby = cby + 1; continue; } - let prob = Random.int(100); + let prob = int(100); if (prob < 5) { let newacc = choose_block_pattern(blockw, blockh, cbx, cby, prob); let undup_lst = avoid_overlap(newacc, acc); @@ -3129,7 +3142,7 @@ function generate_ground(blockw, blockh, _inc, _acc) { return acc; } if (inc > 10) { - let skip = Random.int(10); + let skip = int(10); let newacc = Pervasives.$at(acc, { hd: [ 4, @@ -3253,7 +3266,7 @@ function generate(w, h, context) { } function init() { - Random.self_init(); + } let Procedural_generator = { @@ -3266,7 +3279,6 @@ let loadCount = { }; function load(param) { - Random.self_init(); let canvas_id = "canvas"; let el = document.getElementById(canvas_id); let canvas; @@ -3283,7 +3295,6 @@ function load(param) { let context = canvas.getContext("2d"); document.addEventListener("keydown", keydown, true); document.addEventListener("keyup", keyup, true); - Random.self_init(); update_loop(canvas, generate(2400, 256, context), [ 2400, 256 @@ -3300,15 +3311,7 @@ function inc_counter(param) { } function preload(param) { - return List.map(img_src => { - let img_src$1 = "sprites/" + img_src; - let img = document.createElement("img"); - img.src = img_src$1; - img.addEventListener("load", ev => { - inc_counter(); - return true; - }, true); - }, { + return Belt_List.map({ hd: "blocks.png", tl: { hd: "items.png", @@ -3320,6 +3323,14 @@ function preload(param) { } } } + }, img_src => { + let img_src$1 = "sprites/" + img_src; + let img = document.createElement("img"); + img.src = img_src$1; + img.addEventListener("load", ev => { + inc_counter(); + return true; + }, true); }); } @@ -3340,6 +3351,7 @@ let Main = { preload: preload }; +exports.Random = Random; exports.Actors = Actors; exports.Dom_html = Dom_html; exports.Sprite = Sprite; diff --git a/jscomp/test/mario_game.res b/jscomp/test/mario_game.res index 1b355f7c9b..28916eb705 100644 --- a/jscomp/test/mario_game.res +++ b/jscomp/test/mario_game.res @@ -1,5 +1,15 @@ @@config({flags: ["-w", "a", "-bs-no-bin-annot"]}) +open Belt + +module Random = { + let self_init = () => () + + let int: int => int = %raw(`(max) => { + return ((Math.random() * 100) | 0) % max; + }`) +} + module Actors: { type dir_1d = Left | Right type dir_2d = North | South | East | West @@ -1101,7 +1111,7 @@ module Object: { let update_player = (player, keys, context) => { let prev_jumping = player.jumping let prev_dir = player.dir and prev_vx = abs_float(player.vel.x) - List.iter(update_player_keys(player, ...), keys) + keys->List.forEach(update_player_keys(player, ...)) let v = player.vel.x *. friction let vel_damped = if abs_float(v) < 0.1 { 0. @@ -1426,7 +1436,7 @@ module Draw: { let (dx, dy) = (posx, posy) let (dw, dh) = sprite.params.frame_size let sx = sx +. float_of_int(sprite.frame.contents) *. sw - /* print_endline (string_of_int !(sprite.frame)); */ + /* Js.log(sprite.frame) */ /* context##clearRect(0.,0.,sw, sh); */ context["drawImage"](sprite.img, sx, sy, sw, sh, dx, dy, dw, dh) } @@ -1450,8 +1460,8 @@ module Draw: { /* Displays the text for score and coins. */ let hud = (canvas, score, coins) => { - let score_string = string_of_int(score) - let coin_string = string_of_int(coins) + let score_string = Js.Int.toString(score) + let coin_string = Js.Int.toString(coins) let canvas = Dom_html.canvasElementToJsObj(canvas) let context = Dom_html.canvasRenderingContext2DToJsObj(canvas["getContext"]("2d")) \"@@"(ignore, context["font"] = "10px 'Press Start 2P'") @@ -1464,7 +1474,7 @@ module Draw: { /* Displays the fps. */ let fps = (canvas, fps_val) => { - let fps_str = string_of_int(int_of_float(fps_val)) + let fps_str = fps_val->Js.Float.toFixed let canvas = Dom_html.canvasElementToJsObj(canvas) let context = Dom_html.canvasRenderingContext2DToJsObj(canvas["getContext"]("2d")) \"@@"(ignore, context["fillText"](fps_str, 10., 18.)) @@ -1741,16 +1751,12 @@ module Director: { let obj_at_pos = (dir, pos: xy, collids: list): list => switch dir { | Left => - List.filter( - (col: Object.collidable) => - get_obj(col).pos.y == pos.y && get_obj(col).pos.x == pos.x -. 16., - collids, + collids->List.filter((col: Object.collidable) => + get_obj(col).pos.y == pos.y && get_obj(col).pos.x == pos.x -. 16. ) | _ => - List.filter( - (col: Object.collidable) => - get_obj(col).pos.y == pos.y && get_obj(col).pos.x == pos.x +. 16., - collids, + collids->List.filter((col: Object.collidable) => + get_obj(col).pos.y == pos.y && get_obj(col).pos.x == pos.x +. 16. ) } @@ -1886,12 +1892,10 @@ module Director: { /* Run the broad phase object filtering */ let broad_phase = (collid, all_collids, state) => { let obj = get_obj(collid) - List.filter( - c => - in_viewport(state.vpt, obj.pos) || - (is_player(collid) || - out_of_viewport_below(state.vpt, obj.pos.y)), - all_collids, + all_collids->List.filter(c => + in_viewport(state.vpt, obj.pos) || + (is_player(collid) || + out_of_viewport_below(state.vpt, obj.pos.y)) ) } @@ -1999,13 +2003,13 @@ module Director: { let translate_keys = () => { let k = pressed_keys let ctrls = list{(k.left, CLeft), (k.right, CRight), (k.up, CUp), (k.down, CDown)} - List.fold_left((a, x) => + ctrls->List.reduceReverse(list{}, (a, x) => if fst(x) { list{snd(x), ...a} } else { a } - , list{}, ctrls) + ) } /* run_update is used to update all of the collidables at once. Primarily used @@ -2096,8 +2100,8 @@ module Director: { ...state, vpt: Viewport.update(state.vpt, get_obj(player).pos), } - List.iter(obj => ignore(run_update_collid(state, obj, objs)), objs) - List.iter(part => run_update_particle(state, part), parts) + objs->List.forEach(obj => ignore(run_update_collid(state, obj, objs))) + parts->List.forEach(part => run_update_particle(state, part)) Draw.fps(canvas, fps) Draw.hud(canvas, state.score, state.coins) \"@@"( @@ -2600,7 +2604,7 @@ module Main = { Pg.generate(level_width, level_height, context), (level_width, level_height), ) - print_endline("asd") + Js.log("asd") () } @@ -2617,7 +2621,7 @@ module Main = { let preload = _ => { let root_dir = "sprites/" let imgs = list{"blocks.png", "items.png", "enemies.png", "mario-small.png"} - List.map(img_src => { + imgs->List.map(img_src => { let img_src = root_dir ++ img_src let img = Html.createImg(Dom_html.document) Dom_html.imageElementToJsObj(img)["src"] = img_src @@ -2632,7 +2636,7 @@ module Main = { true, ), ) - }, imgs) + }) } let _ = Dom_html.windowToJsObj(Dom_html.window)["onload"] = _ => { diff --git a/jscomp/test/method_name_test.js b/jscomp/test/method_name_test.js index 16e1e0db93..3d9d32b3c4 100644 --- a/jscomp/test/method_name_test.js +++ b/jscomp/test/method_name_test.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -54,7 +54,7 @@ function hg(x) { return x._open + x._end | 0; } -eq("File \"method_name_test.res\", line 39, characters 12-19", 35, hg(h)); +eq("File \"method_name_test.res\", line 42, characters 12-19", 35, hg(h)); Mt.from_pair_suites("Method_name_test", suites.contents); diff --git a/jscomp/test/method_name_test.res b/jscomp/test/method_name_test.res index defaf8f54b..5001992658 100644 --- a/jscomp/test/method_name_test.res +++ b/jscomp/test/method_name_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let f = (x, i, file, v) => { diff --git a/jscomp/test/mock_mt.js b/jscomp/test/mock_mt.js index 0858be78e9..f542db05c8 100644 --- a/jscomp/test/mock_mt.js +++ b/jscomp/test/mock_mt.js @@ -1,14 +1,14 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); function from_pair_suites(name, suites) { console.log([ name, "testing" ]); - List.iter(param => { + Belt_List.forEach(suites, param => { let name = param[0]; let fn = param[1](); switch (fn.TAG) { @@ -79,7 +79,7 @@ function from_pair_suites(name, suites) { console.log("failed: " + fn._0); return; } - }, suites); + }); } exports.from_pair_suites = from_pair_suites; diff --git a/jscomp/test/mock_mt.res b/jscomp/test/mock_mt.res index 1c4819957c..83042f8cab 100644 --- a/jscomp/test/mock_mt.res +++ b/jscomp/test/mock_mt.res @@ -13,7 +13,7 @@ type pair_suites = list<(string, unit => eq)> let from_pair_suites = (name: string, suites: pair_suites) => { Js.log((name, "testing")) - List.iter(((name, code)) => + suites->Belt.List.forEach(((name, code)) => switch code() { | Eq(a, b) => Js.log((name, a, "eq?", b)) | Neq(a, b) => Js.log((name, a, "neq?", b)) @@ -26,5 +26,5 @@ let from_pair_suites = (name: string, suites: pair_suites) => { | FailWith(msg) => Js.log("failed: " ++ msg) | Ok(a) => Js.log((name, a, "ok?")) } - , suites) + ) } diff --git a/jscomp/test/module_alias_test.js b/jscomp/test/module_alias_test.js index c65e0a81c6..990dc43023 100644 --- a/jscomp/test/module_alias_test.js +++ b/jscomp/test/module_alias_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let suites = { contents: /* [] */0 @@ -16,7 +16,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -29,8 +29,8 @@ function eq(loc, x, y) { function f(x) { console.log(x); - console.log(List.length(x)); - return List; + console.log(Belt_List.length(x)); + return Belt_List; } let h = f(/* [] */0); @@ -46,7 +46,7 @@ let a = h.length({ } }); -eq("File \"module_alias_test.res\", line 30, characters 3-10", a, 3); +eq("File \"module_alias_test.res\", line 35, characters 3-10", a, 3); Mt.from_pair_suites("Module_alias_test", suites.contents); diff --git a/jscomp/test/module_alias_test.res b/jscomp/test/module_alias_test.res index 136194ac82..718adc897a 100644 --- a/jscomp/test/module_alias_test.res +++ b/jscomp/test/module_alias_test.res @@ -1,9 +1,14 @@ +open Belt + let suites: ref = ref(list{}) let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } module N = List diff --git a/jscomp/test/module_missing_conversion.js b/jscomp/test/module_missing_conversion.js index 7ff3d52b5e..71af1b0e1b 100644 --- a/jscomp/test/module_missing_conversion.js +++ b/jscomp/test/module_missing_conversion.js @@ -1,54 +1,97 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let $$Array = require("../../lib/js/array.js"); let $$String = require("../../lib/js/string.js"); -let MoreLabels = require("../../lib/js/moreLabels.js"); +let Belt_Array = require("../../lib/js/belt_Array.js"); +let Primitive_array = require("../../lib/js/primitive_array.js"); function f(x) { return x; } let XX = { - make_float: $$Array.make_float, - init: $$Array.init, - make_matrix: $$Array.make_matrix, - create_matrix: $$Array.create_matrix, - append: $$Array.append, - concat: $$Array.concat, - sub: $$Array.sub, - copy: $$Array.copy, - fill: $$Array.fill, - blit: $$Array.blit, - to_list: $$Array.to_list, - of_list: $$Array.of_list, - iter: $$Array.iter, - iteri: $$Array.iteri, - map: $$Array.map, - mapi: $$Array.mapi, - fold_left: $$Array.fold_left, - fold_right: $$Array.fold_right, - iter2: $$Array.iter2, - map2: $$Array.map2, - for_all: $$Array.for_all, - exists: $$Array.exists, - mem: $$Array.mem, - memq: $$Array.memq, - sort: $$Array.sort, - stable_sort: $$Array.stable_sort, - fast_sort: $$Array.fast_sort, - Floatarray: $$Array.Floatarray, + get: Belt_Array.get, + getExn: Belt_Array.getExn, + set: Belt_Array.set, + setExn: Belt_Array.setExn, + shuffleInPlace: Belt_Array.shuffleInPlace, + shuffle: Belt_Array.shuffle, + reverseInPlace: Belt_Array.reverseInPlace, + reverse: Belt_Array.reverse, + make: Belt_Array.make, + range: Belt_Array.range, + rangeBy: Belt_Array.rangeBy, + makeByU: Belt_Array.makeByU, + makeBy: Belt_Array.makeBy, + makeByAndShuffleU: Belt_Array.makeByAndShuffleU, + makeByAndShuffle: Belt_Array.makeByAndShuffle, + zip: Belt_Array.zip, + zipByU: Belt_Array.zipByU, + zipBy: Belt_Array.zipBy, + unzip: Belt_Array.unzip, + concat: Belt_Array.concat, + concatMany: Belt_Array.concatMany, + slice: Belt_Array.slice, + sliceToEnd: Belt_Array.sliceToEnd, + fill: Belt_Array.fill, + blit: Belt_Array.blit, + blitUnsafe: Belt_Array.blitUnsafe, + forEachU: Belt_Array.forEachU, + forEach: Belt_Array.forEach, + mapU: Belt_Array.mapU, + map: Belt_Array.map, + flatMapU: Belt_Array.flatMapU, + flatMap: Belt_Array.flatMap, + getByU: Belt_Array.getByU, + getBy: Belt_Array.getBy, + getIndexByU: Belt_Array.getIndexByU, + getIndexBy: Belt_Array.getIndexBy, + keepU: Belt_Array.keepU, + keep: Belt_Array.keep, + keepWithIndexU: Belt_Array.keepWithIndexU, + keepWithIndex: Belt_Array.keepWithIndex, + keepMapU: Belt_Array.keepMapU, + keepMap: Belt_Array.keepMap, + forEachWithIndexU: Belt_Array.forEachWithIndexU, + forEachWithIndex: Belt_Array.forEachWithIndex, + mapWithIndexU: Belt_Array.mapWithIndexU, + mapWithIndex: Belt_Array.mapWithIndex, + partitionU: Belt_Array.partitionU, + partition: Belt_Array.partition, + reduceU: Belt_Array.reduceU, + reduce: Belt_Array.reduce, + reduceReverseU: Belt_Array.reduceReverseU, + reduceReverse: Belt_Array.reduceReverse, + reduceReverse2U: Belt_Array.reduceReverse2U, + reduceReverse2: Belt_Array.reduceReverse2, + reduceWithIndexU: Belt_Array.reduceWithIndexU, + reduceWithIndex: Belt_Array.reduceWithIndex, + joinWithU: Belt_Array.joinWithU, + joinWith: Belt_Array.joinWith, + someU: Belt_Array.someU, + some: Belt_Array.some, + everyU: Belt_Array.everyU, + every: Belt_Array.every, + every2U: Belt_Array.every2U, + every2: Belt_Array.every2, + some2U: Belt_Array.some2U, + some2: Belt_Array.some2, + cmpU: Belt_Array.cmpU, + cmp: Belt_Array.cmp, + eqU: Belt_Array.eqU, + eq: Belt_Array.eq, + initU: Belt_Array.initU, + init: Belt_Array.init, f: f }; let u = [$$String]; -let hh = "x".length; +let $$String$1 = Primitive_array.get(u, 0); -let ghh = MoreLabels.Hashtbl.create(undefined, 30); +let hh = $$String$1.length("x"); exports.XX = XX; exports.u = u; exports.hh = hh; -exports.ghh = ghh; -/* ghh Not a pure module */ +/* hh Not a pure module */ diff --git a/jscomp/test/module_missing_conversion.res b/jscomp/test/module_missing_conversion.res index 6ffe760c1f..840637ee29 100644 --- a/jscomp/test/module_missing_conversion.res +++ b/jscomp/test/module_missing_conversion.res @@ -1,7 +1,7 @@ module type S = module type of String module XX = { - include Array + include Belt.Array let f = x => x } let u = [module(String: S)] @@ -10,5 +10,3 @@ let hh = { let module(String: S) = u[0] String.length("x") } - -let ghh: Hashtbl.t = MoreLabels.Hashtbl.create(30) diff --git a/jscomp/test/module_parameter_test.js b/jscomp/test/module_parameter_test.js index aaab7e92b9..411ccb2790 100644 --- a/jscomp/test/module_parameter_test.js +++ b/jscomp/test/module_parameter_test.js @@ -14,10 +14,10 @@ let N = { s: s }; -let v0 = "x".length; +let v0 = s.length("x"); function v(x) { - return x.length; + return s.length(x); } let suites_0 = [ @@ -53,4 +53,4 @@ exports.N = N; exports.v0 = v0; exports.v = v; exports.suites = suites; -/* Not a pure module */ +/* v0 Not a pure module */ diff --git a/jscomp/test/module_splice_test.js b/jscomp/test/module_splice_test.js index 4ac8920689..efe83b456d 100644 --- a/jscomp/test/module_splice_test.js +++ b/jscomp/test/module_splice_test.js @@ -18,7 +18,7 @@ function eq(loc, param) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -42,7 +42,7 @@ let pair = [ console.log(pair); -eq("File \"module_splice_test.res\", line 16, characters 5-12", pair); +eq("File \"module_splice_test.res\", line 19, characters 5-12", pair); Mt.from_pair_suites("Module_splice_test", suites.contents); diff --git a/jscomp/test/module_splice_test.res b/jscomp/test/module_splice_test.res index b50a80e081..3a34e52f80 100644 --- a/jscomp/test/module_splice_test.res +++ b/jscomp/test/module_splice_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, (x, y)) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } @module @variadic external joinClasses: array => int = "./joinClasses" diff --git a/jscomp/test/mpr_6033_test.js b/jscomp/test/mpr_6033_test.js index d082011a65..8eaf159797 100644 --- a/jscomp/test/mpr_6033_test.js +++ b/jscomp/test/mpr_6033_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let CamlinternalLazy = require("../../lib/js/camlinternalLazy.js"); +let Lazy = require("../../lib/js/lazy.js"); let suites = { contents: /* [] */0 @@ -16,7 +16,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -28,16 +28,16 @@ function eq(loc, x, y) { } function f(x) { - return CamlinternalLazy.force(x) + "abc"; + return Lazy.force(x) + "abc"; } -let x = CamlinternalLazy.from_fun(() => "def"); +let x = Lazy.from_fun(() => "def"); -CamlinternalLazy.force(x); +Lazy.force(x); -let u = CamlinternalLazy.force(x) + "abc"; +let u = Lazy.force(x) + "abc"; -eq("File \"mpr_6033_test.res\", line 20, characters 3-10", u, "defabc"); +eq("File \"mpr_6033_test.res\", line 23, characters 3-10", u, "defabc"); Mt.from_pair_suites("Mpr_6033_test", suites.contents); diff --git a/jscomp/test/mpr_6033_test.res b/jscomp/test/mpr_6033_test.res index e363b65b55..dffaa74957 100644 --- a/jscomp/test/mpr_6033_test.res +++ b/jscomp/test/mpr_6033_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let f = x => diff --git a/jscomp/test/mt.js b/jscomp/test/mt.js index 39789af3cf..fb9f189cb0 100644 --- a/jscomp/test/mt.js +++ b/jscomp/test/mt.js @@ -1,18 +1,17 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); let Path = require("path"); -let $$Array = require("../../lib/js/array.js"); let Assert = require("assert"); let Process = require("process"); +let Belt_List = require("../../lib/js/belt_List.js"); function assert_fail(msg) { Assert.fail(undefined, undefined, msg, ""); } function is_mocha() { - let match = $$Array.to_list(Process.argv); + let match = Belt_List.fromArray(Process.argv); if (!match) { return false; } @@ -28,16 +27,16 @@ function is_mocha() { } } -let from_suites = (function from_suites(name, suite) { - var match = $$Array.to_list(Process.argv); +let from_suites = (function from_suites(name, suites) { + var match = Belt_List.fromArray(Process.argv); if (match && is_mocha(undefined)) { describe(name, (function () { - return List.iter((function (param) { + return Belt_List.forEach(suites, (function (param) { var partial_arg = param[1]; it(param[0], (function () { return partial_arg(undefined); })); - }), suite); + })); })); return ; } @@ -95,16 +94,16 @@ function handleCode(spec) { } let from_pair_suites = (function from_pair_suites(name, suites) { - var match = $$Array.to_list(Process.argv); + var match = Belt_List.fromArray(Process.argv); if (match) { if (is_mocha(undefined)) { describe(name, (function () { - return List.iter((function (param) { + return Belt_List.forEach(suites, (function (param) { var code = param[1]; it(param[0], (function () { return handleCode(code(undefined)); })); - }), suites); + })); })); return ; } else { @@ -112,7 +111,7 @@ let from_pair_suites = (function from_pair_suites(name, suites) { name, "testing" ]); - return List.iter((function (param) { + return Belt_List.forEach(suites, (function (param) { var name = param[0]; var fn = param[1](undefined); switch (fn.TAG) { @@ -184,7 +183,7 @@ let from_pair_suites = (function from_pair_suites(name, suites) { return ; } - }), suites); + })); } } @@ -193,11 +192,11 @@ let from_pair_suites = (function from_pair_suites(name, suites) { let val_unit = Promise.resolve(); let from_promise_suites = (function from_promise_suites(name, suites) { - var match = $$Array.to_list(Process.argv); + var match = Belt_List.fromArray(Process.argv); if (match) { if (is_mocha(undefined)) { describe(name, (function () { - return List.iter((function (param) { + return Belt_List.forEach(suites, (function (param) { var code = param[1]; it(param[0], (function () { var arg1 = function (x) { @@ -206,7 +205,7 @@ let from_promise_suites = (function from_promise_suites(name, suites) { }; return code.then(arg1); })); - }), suites); + })); })); } else { console.log("promise suites"); @@ -217,16 +216,16 @@ let from_promise_suites = (function from_promise_suites(name, suites) { }); function old_from_promise_suites_donotuse(name, suites) { - let match = $$Array.to_list(Process.argv); + let match = Belt_List.fromArray(Process.argv); if (match) { if (is_mocha()) { - describe(name, () => List.iter(param => { + describe(name, () => Belt_List.forEach(suites, param => { let code = param[1]; it(param[0], () => code.then(x => { handleCode(x); return val_unit; })); - }, suites)); + })); } else { console.log("promise suites"); } @@ -239,7 +238,7 @@ function eq_suites(test_id, suites, loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), param => ({ TAG: "Eq", _0: x, @@ -254,7 +253,7 @@ function bool_suites(test_id, suites, loc, x) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), param => ({ TAG: "Ok", _0: x @@ -268,7 +267,7 @@ function throw_suites(test_id, suites, loc, x) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), param => ({ TAG: "ThrowAny", _0: x diff --git a/jscomp/test/mt.res b/jscomp/test/mt.res index 86224cc2c2..73f9da5a1b 100644 --- a/jscomp/test/mt.res +++ b/jscomp/test/mt.res @@ -34,7 +34,7 @@ let assert_fail = msg => fail((), (), Js.Undefined.return(msg), "") @module("path") external basename: string => string = "basename" let is_mocha = () => - switch Array.to_list(argv) { + switch Belt.List.fromArray(argv) { | list{_node, mocha, ..._} => let exec = basename(mocha) exec == "mocha" || exec == "_mocha" @@ -44,16 +44,16 @@ let is_mocha = () => */ let from_suites = %raw(` -function from_suites(name, suite) { - var match = $$Array.to_list(Process.argv); +function from_suites(name, suites) { + var match = Belt_List.fromArray(Process.argv); if (match && is_mocha(undefined)) { describe(name, (function () { - return List.iter((function (param) { + return Belt_List.forEach(suites, (function (param) { var partial_arg = param[1]; it(param[0], (function () { return partial_arg(undefined); })); - }), suite); + })); })); return ; } @@ -80,7 +80,7 @@ let close_enough = (~threshold=0.0000001 /* epsilon_float */, a, b) => abs_float let node_from_pair_suites = (name: string, suites: pair_suites) => { Js.log((name, "testing")) - List.iter(((name, code)) => + suites->Belt.List.forEach(((name, code)) => switch code() { | Eq(a, b) => Js.log((name, a, "eq?", b)) | Neq(a, b) => Js.log((name, a, "neq?", b)) @@ -93,7 +93,7 @@ let node_from_pair_suites = (name: string, suites: pair_suites) => { | FailWith(msg) => Js.log("failed: " ++ msg) | Ok(a) => Js.log((name, a, "ok?")) } - , suites) + ) } let handleCode = spec => @@ -118,16 +118,16 @@ let handleCode = spec => let from_pair_suites = %raw(` function from_pair_suites(name, suites) { - var match = $$Array.to_list(Process.argv); + var match = Belt_List.fromArray(Process.argv); if (match) { if (is_mocha(undefined)) { describe(name, (function () { - return List.iter((function (param) { + return Belt_List.forEach(suites, (function (param) { var code = param[1]; it(param[0], (function () { return handleCode(code(undefined)); })); - }), suites); + })); })); return ; } else { @@ -135,7 +135,7 @@ function from_pair_suites(name, suites) { name, "testing" ]); - return List.iter((function (param) { + return Belt_List.forEach(suites, (function (param) { var name = param[0]; var fn = param[1](undefined); switch (fn.TAG) { @@ -207,7 +207,7 @@ function from_pair_suites(name, suites) { return ; } - }), suites); + })); } } @@ -218,11 +218,11 @@ let val_unit = Js.Promise.resolve() let from_promise_suites = %raw(` function from_promise_suites(name, suites) { - var match = $$Array.to_list(Process.argv); + var match = Belt_List.fromArray(Process.argv); if (match) { if (is_mocha(undefined)) { describe(name, (function () { - return List.iter((function (param) { + return Belt_List.forEach(suites, (function (param) { var code = param[1]; it(param[0], (function () { var arg1 = function (x) { @@ -231,7 +231,7 @@ function from_promise_suites(name, suites) { }; return code.then(arg1); })); - }), suites); + })); })); } else { console.log("promise suites"); @@ -243,10 +243,11 @@ function from_promise_suites(name, suites) { `) let old_from_promise_suites_donotuse = (name, suites: list<(string, Js.Promise.t<_>)>) => - switch Array.to_list(argv) { + switch Belt.List.fromArray(argv) { | list{cmd, ..._} => if is_mocha() { - describe(name, () => List.iter(((name, code)) => + describe(name, () => + suites->Belt.List.forEach(((name, code)) => it_promise( name, _ => @@ -258,7 +259,8 @@ let old_from_promise_suites_donotuse = (name, suites: list<(string, Js.Promise.t code, ), ) - , suites)) + ) + ) } else { Js.log("promise suites") } /* TODO */ @@ -289,17 +291,20 @@ let from_pair_suites_non_top name suites = let eq_suites = (~test_id, ~suites, loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Eq(x, y)), ...suites.contents} + list{(loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Eq(x, y)), ...suites.contents} } let bool_suites = (~test_id, ~suites, loc, x) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Ok(x)), ...suites.contents} + list{(loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Ok(x)), ...suites.contents} } let throw_suites = (~test_id, ~suites, loc, x) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => ThrowAny(x)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => ThrowAny(x)), + ...suites.contents, + } } diff --git a/jscomp/test/mt_global.js b/jscomp/test/mt_global.js index 77c1aa2db3..e3d0bb4f70 100644 --- a/jscomp/test/mt_global.js +++ b/jscomp/test/mt_global.js @@ -6,7 +6,7 @@ function collect_eq(test_id, suites, loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), param => ({ TAG: "Eq", _0: x, @@ -21,7 +21,7 @@ function collect_neq(test_id, suites, loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), param => ({ TAG: "Neq", _0: x, @@ -36,7 +36,7 @@ function collect_approx(test_id, suites, loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), param => ({ TAG: "Approx", _0: x, diff --git a/jscomp/test/mt_global.res b/jscomp/test/mt_global.res index ac492afa88..2bde48848c 100644 --- a/jscomp/test/mt_global.res +++ b/jscomp/test/mt_global.res @@ -1,13 +1,16 @@ let collect_eq = (test_id, suites, loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let collect_neq = (test_id, suites, loc, x, y) => { incr(test_id) suites := list{ - (loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Neq(x, y)), + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Neq(x, y)), ...suites.contents, } } @@ -16,7 +19,7 @@ let collect_approx = (test_id, suites, loc, x, y) => { incr(test_id) suites := list{ - (loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Approx(x, y)), + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Approx(x, y)), ...suites.contents, } } diff --git a/jscomp/test/mutable_uncurry_test.js b/jscomp/test/mutable_uncurry_test.js index 8aa2107971..17e6a615e0 100644 --- a/jscomp/test/mutable_uncurry_test.js +++ b/jscomp/test/mutable_uncurry_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); let suites = { contents: /* [] */0 @@ -24,7 +24,7 @@ function eq(param, param$1) { function eq2(x, param) { let y = param.contents; - return Caml_obj.equal(x.contents, y); + return Primitive_object.equal(x.contents, y); } eqs("File \"mutable_uncurry_test.res\", line 15, characters 4-11", false, eq({ diff --git a/jscomp/test/name_mangle_test.js b/jscomp/test/name_mangle_test.js index 82e3e3bcb2..e7fc9f8d0c 100644 --- a/jscomp/test/name_mangle_test.js +++ b/jscomp/test/name_mangle_test.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -104,33 +104,33 @@ function f12(x) { return x.____; } -eq("File \"name_mangle_test.res\", line 94, characters 5-12", f0({_open:0}), 1); +eq("File \"name_mangle_test.res\", line 97, characters 5-12", f0({_open:0}), 1); -eq("File \"name_mangle_test.res\", line 95, characters 5-12", f1({_in:0}), 1); +eq("File \"name_mangle_test.res\", line 98, characters 5-12", f1({_in:0}), 1); -eq("File \"name_mangle_test.res\", line 96, characters 5-12", f2({_MAX_LENGTH:0}), 1); +eq("File \"name_mangle_test.res\", line 99, characters 5-12", f2({_MAX_LENGTH:0}), 1); -eq("File \"name_mangle_test.res\", line 97, characters 5-12", f3({_Capital:0}), 1); +eq("File \"name_mangle_test.res\", line 100, characters 5-12", f3({_Capital:0}), 1); -eq("File \"name_mangle_test.res\", line 98, characters 5-12", f4({_open__:0}), 1); +eq("File \"name_mangle_test.res\", line 101, characters 5-12", f4({_open__:0}), 1); -eq("File \"name_mangle_test.res\", line 99, characters 5-12", f5({open__:0}), 1); +eq("File \"name_mangle_test.res\", line 102, characters 5-12", f5({open__:0}), 1); -eq("File \"name_mangle_test.res\", line 100, characters 5-12", f6({ "_'x" :0}), 1); +eq("File \"name_mangle_test.res\", line 103, characters 5-12", f6({ "_'x" :0}), 1); -eq("File \"name_mangle_test.res\", line 101, characters 5-12", f7({_Capital__:0}), 1); +eq("File \"name_mangle_test.res\", line 104, characters 5-12", f7({_Capital__:0}), 1); -eq("File \"name_mangle_test.res\", line 102, characters 5-12", f8({_MAX__:0}), 1); +eq("File \"name_mangle_test.res\", line 105, characters 5-12", f8({_MAX__:0}), 1); -eq("File \"name_mangle_test.res\", line 103, characters 5-12", f9({__:0}), 1); +eq("File \"name_mangle_test.res\", line 106, characters 5-12", f9({__:0}), 1); -eq("File \"name_mangle_test.res\", line 104, characters 5-12", f10({__x:0}), 1); +eq("File \"name_mangle_test.res\", line 107, characters 5-12", f10({__x:0}), 1); -eq("File \"name_mangle_test.res\", line 105, characters 5-12", f11({___:0}), 1); +eq("File \"name_mangle_test.res\", line 108, characters 5-12", f11({___:0}), 1); -eq("File \"name_mangle_test.res\", line 106, characters 5-12", f12({____:0}), 1); +eq("File \"name_mangle_test.res\", line 109, characters 5-12", f12({____:0}), 1); -Mt.from_pair_suites("File \"name_mangle_test.res\", line 109, characters 20-27", suites.contents); +Mt.from_pair_suites("File \"name_mangle_test.res\", line 112, characters 20-27", suites.contents); exports.suites = suites; exports.test_id = test_id; diff --git a/jscomp/test/name_mangle_test.res b/jscomp/test/name_mangle_test.res index 15ae63f98c..d9824be730 100644 --- a/jscomp/test/name_mangle_test.res +++ b/jscomp/test/name_mangle_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } /* FIXME: paren needed here diff --git a/jscomp/test/nested_module_alias.js b/jscomp/test/nested_module_alias.js index b55b38f628..ec02b53c36 100644 --- a/jscomp/test/nested_module_alias.js +++ b/jscomp/test/nested_module_alias.js @@ -1,12 +1,12 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); function v(x) { return [ - List.length(x), - List.length(x) + Belt_List.length(x), + Belt_List.length(x) ]; } diff --git a/jscomp/test/nested_module_alias.res b/jscomp/test/nested_module_alias.res index 56992831fd..38010d1b57 100644 --- a/jscomp/test/nested_module_alias.res +++ b/jscomp/test/nested_module_alias.res @@ -1,7 +1,7 @@ -module L = List +module L = Belt.List let v = x => { - module H = List + module H = Belt.List module U = L (H.length(x), U.length(x)) } diff --git a/jscomp/test/number_lexer.js b/jscomp/test/number_lexer.js deleted file mode 100644 index 3d5a297fb1..0000000000 --- a/jscomp/test/number_lexer.js +++ /dev/null @@ -1,184 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Lexing = require("../../lib/js/lexing.js"); - -function l(prim) { - console.log(prim); -} - -let __ocaml_lex_tables = { - lex_base: "\x00\x00\xf6\xff\xf7\xff\xf8\xff\xf9\xff\xfa\xff\xfb\xff\xfc\xff\ - \x3a\x00\x85\x00\xff\xff", - lex_backtrk: "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \x02\x00\x01\x00\xff\xff", - lex_default: "\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \xff\xff\xff\xff\x00\x00", - lex_trans: "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x0a\x00\x0a\x00\x00\x00\x00\x00\x0a\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x03\x00\x02\x00\x05\x00\x07\x00\x00\x00\x06\x00\x00\x00\x04\x00\ - \x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\ - \x09\x00\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x09\x00\x09\x00\x09\x00\ - \x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", - lex_check: "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\xff\xff\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x09\x00\x09\x00\x09\x00\ - \x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", - lex_base_code: "", - lex_backtrk_code: "", - lex_default_code: "", - lex_trans_code: "", - lex_check_code: "", - lex_code: "" -}; - -function __ocaml_lex_token_rec(l, lexbuf, ___ocaml_lex_state) { - while (true) { - let __ocaml_lex_state = ___ocaml_lex_state; - let __ocaml_lex_state$1 = Lexing.engine(__ocaml_lex_tables, __ocaml_lex_state, lexbuf); - switch (__ocaml_lex_state$1) { - case 0 : - l("new line"); - ___ocaml_lex_state = 0; - continue; - case 1 : - l("number"); - l(Lexing.lexeme(lexbuf)); - ___ocaml_lex_state = 0; - continue; - case 2 : - l("ident"); - l(Lexing.lexeme(lexbuf)); - ___ocaml_lex_state = 0; - continue; - case 3 : - l("+"); - ___ocaml_lex_state = 0; - continue; - case 4 : - l("-"); - ___ocaml_lex_state = 0; - continue; - case 5 : - l("*"); - ___ocaml_lex_state = 0; - continue; - case 6 : - l("/"); - ___ocaml_lex_state = 0; - continue; - case 7 : - l("("); - ___ocaml_lex_state = 0; - continue; - case 8 : - l(")"); - ___ocaml_lex_state = 0; - continue; - case 9 : - return l("eof"); - default: - lexbuf.refill_buff(lexbuf); - ___ocaml_lex_state = __ocaml_lex_state$1; - continue; - } - }; -} - -function token(l, lexbuf) { - __ocaml_lex_token_rec(l, lexbuf, 0); -} - -exports.l = l; -exports.__ocaml_lex_tables = __ocaml_lex_tables; -exports.token = token; -exports.__ocaml_lex_token_rec = __ocaml_lex_token_rec; -/* No side effect */ diff --git a/jscomp/test/number_lexer.res b/jscomp/test/number_lexer.res deleted file mode 100644 index 25ae7eaa4a..0000000000 --- a/jscomp/test/number_lexer.res +++ /dev/null @@ -1,164 +0,0 @@ -@val("console.log") external log: string => unit = "caml_alloc_dummy" -let l = log - -let __ocaml_lex_tables = { - Lexing.lex_base: "\x00\x00\xf6\xff\xf7\xff\xf8\xff\xf9\xff\xfa\xff\xfb\xff\xfc\xff\ - \x3a\x00\x85\x00\xff\xff", - Lexing.lex_backtrk: "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \x02\x00\x01\x00\xff\xff", - Lexing.lex_default: "\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \xff\xff\xff\xff\x00\x00", - Lexing.lex_trans: "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x0a\x00\x0a\x00\x00\x00\x00\x00\x0a\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x03\x00\x02\x00\x05\x00\x07\x00\x00\x00\x06\x00\x00\x00\x04\x00\ - \x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\ - \x09\x00\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x09\x00\x09\x00\x09\x00\ - \x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", - Lexing.lex_check: "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\xff\xff\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ - \x00\x00\x00\x00\x00\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\ - \x08\x00\x08\x00\x08\x00\x08\x00\x08\x00\x09\x00\x09\x00\x09\x00\ - \x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\x09\x00\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\ - \xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff", - Lexing.lex_base_code: "", - Lexing.lex_backtrk_code: "", - Lexing.lex_default_code: "", - Lexing.lex_trans_code: "", - Lexing.lex_check_code: "", - Lexing.lex_code: "", -} - -let rec token = (l, lexbuf) => __ocaml_lex_token_rec(l, lexbuf, 0) -and __ocaml_lex_token_rec = (l, lexbuf, __ocaml_lex_state) => - switch Lexing.engine(__ocaml_lex_tables, __ocaml_lex_state, lexbuf) { - | 0 => - l("new line") - token(l, lexbuf) - - | 1 => - l("number") - l(Lexing.lexeme(lexbuf)) - token(l, lexbuf) - - | 2 => - l("ident") - l(Lexing.lexeme(lexbuf)) - token(l, lexbuf) - - | 3 => - l("+") - token(l, lexbuf) - - | 4 => - l("-") - token(l, lexbuf) - - | 5 => - l("*") - token(l, lexbuf) - - | 6 => - l("/") - token(l, lexbuf) - - | 7 => - l("(") - token(l, lexbuf) - - | 8 => - l(")") - token(l, lexbuf) - - | 9 => l("eof") - - | __ocaml_lex_state => - lexbuf.Lexing.refill_buff(lexbuf) - __ocaml_lex_token_rec(l, lexbuf, __ocaml_lex_state) - } /* token l (Lexing.from_string "32 + 32 ( ) * / ") */ -/* token (Lexing.from_string "32") */ diff --git a/jscomp/test/obj_literal_ppx.res b/jscomp/test/obj_literal_ppx.res index 50b30a939b..16487495d8 100644 --- a/jscomp/test/obj_literal_ppx.res +++ b/jscomp/test/obj_literal_ppx.res @@ -2,7 +2,7 @@ let a = {"x": 3, "y": [1]} let b = {"x": 3, "y": [1], "z": 3, "u": (x, y) => x + y} -let f = obj => obj["x"] + Array.length(obj["y"]) +let f = obj => obj["x"] + Belt.Array.length(obj["y"]) let u = f(a) diff --git a/jscomp/test/obj_magic_test.js b/jscomp/test/obj_magic_test.js index 7e6071f1f2..3485e5f0f1 100644 --- a/jscomp/test/obj_magic_test.js +++ b/jscomp/test/obj_magic_test.js @@ -12,7 +12,7 @@ let suites_0 = [ param => ({ TAG: "Eq", _0: false, - _1: "number" !== "number" + _1: is_block(3) }) ]; @@ -22,10 +22,10 @@ let suites_1 = { param => ({ TAG: "Eq", _0: true, - _1: typeof ({ + _1: is_block({ hd: 3, tl: /* [] */0 - }) !== "number" + }) }) ], tl: { @@ -34,7 +34,7 @@ let suites_1 = { param => ({ TAG: "Eq", _0: true, - _1: "string" !== "number" + _1: is_block("x") }) ], tl: { @@ -43,7 +43,7 @@ let suites_1 = { param => ({ TAG: "Eq", _0: false, - _1: "number" !== "number" + _1: is_block(3.0) }) ], tl: /* [] */0 diff --git a/jscomp/test/ocaml_re_test.js b/jscomp/test/ocaml_re_test.js deleted file mode 100644 index 1493e8b236..0000000000 --- a/jscomp/test/ocaml_re_test.js +++ /dev/null @@ -1,4135 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let Caml = require("../../lib/js/caml.js"); -let Char = require("../../lib/js/char.js"); -let List = require("../../lib/js/list.js"); -let $$Array = require("../../lib/js/array.js"); -let Bytes = require("../../lib/js/bytes.js"); -let $$String = require("../../lib/js/string.js"); -let Hashtbl = require("../../lib/js/hashtbl.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); -let Caml_array = require("../../lib/js/caml_array.js"); -let Caml_bytes = require("../../lib/js/caml_bytes.js"); -let Pervasives = require("../../lib/js/pervasives.js"); -let Caml_option = require("../../lib/js/caml_option.js"); -let Caml_string = require("../../lib/js/caml_string.js"); -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); - -let suites = { - contents: /* [] */0 -}; - -let test_id = { - contents: 0 -}; - -function eq(loc, x, y) { - test_id.contents = test_id.contents + 1 | 0; - suites.contents = { - hd: [ - loc + (" id " + String(test_id.contents)), - () => ({ - TAG: "Eq", - _0: x, - _1: y - }) - ], - tl: suites.contents - }; -} - -function union(_l, _l$p) { - while (true) { - let l$p = _l$p; - let l = _l; - if (!l$p) { - return l; - } - if (!l) { - return l$p; - } - let r$p = l$p.tl; - let match = l$p.hd; - let c2$p = match[1]; - let c1$p = match[0]; - let r = l.tl; - let match$1 = l.hd; - let c2 = match$1[1]; - let c1 = match$1[0]; - if ((c2 + 1 | 0) < c1$p) { - return { - hd: [ - c1, - c2 - ], - tl: union(r, l$p) - }; - } - if ((c2$p + 1 | 0) < c1) { - return { - hd: [ - c1$p, - c2$p - ], - tl: union(l, r$p) - }; - } - if (c2 < c2$p) { - _l$p = { - hd: [ - c1 < c1$p ? c1 : c1$p, - c2$p - ], - tl: r$p - }; - _l = r; - continue; - } - _l$p = r$p; - _l = { - hd: [ - c1 < c1$p ? c1 : c1$p, - c2 - ], - tl: r - }; - continue; - }; -} - -function inter(_l, _l$p) { - while (true) { - let l$p = _l$p; - let l = _l; - if (!l$p) { - return /* [] */0; - } - if (!l) { - return /* [] */0; - } - let r$p = l$p.tl; - let match = l$p.hd; - let c2$p = match[1]; - let c1$p = match[0]; - let r = l.tl; - let match$1 = l.hd; - let c2 = match$1[1]; - let c1 = match$1[0]; - if (Caml_obj.lessthan(c2, c1$p)) { - _l = r; - continue; - } - if (!Caml_obj.lessthan(c2$p, c1)) { - if (Caml_obj.lessthan(c2, c2$p)) { - return { - hd: [ - Caml_obj.max(c1, c1$p), - c2 - ], - tl: inter(r, l$p) - }; - } else { - return { - hd: [ - Caml_obj.max(c1, c1$p), - c2$p - ], - tl: inter(l, r$p) - }; - } - } - _l$p = r$p; - continue; - }; -} - -function diff(_l, _l$p) { - while (true) { - let l$p = _l$p; - let l = _l; - if (!l$p) { - return l; - } - if (!l) { - return /* [] */0; - } - let r$p = l$p.tl; - let match = l$p.hd; - let c2$p = match[1]; - let c1$p = match[0]; - let r = l.tl; - let match$1 = l.hd; - let c2 = match$1[1]; - let c1 = match$1[0]; - if (c2 < c1$p) { - return { - hd: [ - c1, - c2 - ], - tl: diff(r, l$p) - }; - } - if (c2$p < c1) { - _l$p = r$p; - continue; - } - let r$p$p = c2$p < c2 ? ({ - hd: [ - c2$p + 1 | 0, - c2 - ], - tl: r - }) : r; - if (c1 < c1$p) { - return { - hd: [ - c1, - c1$p - 1 | 0 - ], - tl: diff(r$p$p, r$p) - }; - } - _l$p = r$p; - _l = r$p$p; - continue; - }; -} - -function single(c) { - return { - hd: [ - c, - c - ], - tl: /* [] */0 - }; -} - -function seq(c, c$p) { - if (Caml_obj.lessequal(c, c$p)) { - return { - hd: [ - c, - c$p - ], - tl: /* [] */0 - }; - } else { - return { - hd: [ - c$p, - c - ], - tl: /* [] */0 - }; - } -} - -function offset(o, l) { - if (!l) { - return /* [] */0; - } - let match = l.hd; - return { - hd: [ - match[0] + o | 0, - match[1] + o | 0 - ], - tl: offset(o, l.tl) - }; -} - -function mem(c, _s) { - while (true) { - let s = _s; - if (!s) { - return false; - } - let match = s.hd; - if (c <= match[1]) { - return c >= match[0]; - } - _s = s.tl; - continue; - }; -} - -function hash_rec(x) { - if (!x) { - return 0; - } - let match = x.hd; - return (match[0] + Math.imul(13, match[1]) | 0) + Math.imul(257, hash_rec(x.tl)) | 0; -} - -function one_char(x) { - if (!x) { - return; - } - if (x.tl) { - return; - } - let match = x.hd; - let i = match[0]; - if (Caml_obj.equal(i, match[1])) { - return Caml_option.some(i); - } - -} - -function compare(param, param$1) { - let c = Caml_obj.compare(param[0], param$1[0]); - if (c !== 0) { - return c; - } else { - return Caml_obj.compare(param[1], param$1[1]); - } -} - -function height(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} - -function create(l, x, d, r) { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} - -function bal(l, x, d, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; -} - -function add(x, data, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -let cany = { - hd: [ - 0, - 255 - ], - tl: /* [] */0 -}; - -function intersect(x, y) { - return (x & y) !== 0; -} - -function $plus$plus(x, y) { - return x | y; -} - -function from_char(x) { - if (x >= 170) { - if (x >= 192) { - if (x > 255 || x < 216) { - if (x >= 215) { - return 4; - } else { - return 2; - } - } else if (x !== 247) { - return 2; - } else { - return 4; - } - } else if (x > 185 || x < 171) { - if (x >= 187) { - return 4; - } else { - return 2; - } - } else if (x !== 181) { - return 4; - } else { - return 2; - } - } else if (x >= 65) { - if (x > 96 || x < 91) { - if (x >= 123) { - return 4; - } else { - return 2; - } - } else if (x !== 95) { - return 4; - } else { - return 2; - } - } else if (x >= 48) { - if (x >= 58) { - return 4; - } else { - return 2; - } - } else if (x !== 10) { - return 4; - } else { - return 12; - } -} - -function height$1(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} - -function create$1(l, v, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} - -function bal$1(l, v, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - let lr = l.r; - let lv = l.v; - let ll = l.l; - if (height$1(ll) >= height$1(lr)) { - return create$1(ll, lv, create$1(lr, v, r)); - } - if (typeof lr === "object") { - return create$1(create$1(ll, lv, lr.l), lr.v, create$1(lr.r, v, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - let rr = r.r; - let rv = r.v; - let rl = r.l; - if (height$1(rr) >= height$1(rl)) { - return create$1(create$1(l, v, rl), rv, rr); - } - if (typeof rl === "object") { - return create$1(create$1(l, v, rl.l), rl.v, create$1(rl.r, rv, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; -} - -function add$1(x, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = Caml.int_compare(x, v); - if (c === 0) { - return param; - } - if (c < 0) { - let ll = add$1(x, l); - if (l === ll) { - return param; - } else { - return bal$1(ll, v, r); - } - } - let rr = add$1(x, r); - if (r === rr) { - return param; - } else { - return bal$1(l, v, rr); - } -} - -function hash_combine(h, accu) { - return Math.imul(accu, 65599) + h | 0; -} - -let empty = { - marks: /* [] */0, - pmarks: "Empty" -}; - -function hash(m, accu) { - let _l = m.marks; - let _accu = hash_combine(Hashtbl.hash(m.pmarks), accu); - while (true) { - let accu$1 = _accu; - let l = _l; - if (!l) { - return accu$1; - } - let match = l.hd; - _accu = hash_combine(match[0], hash_combine(match[1], accu$1)); - _l = l.tl; - continue; - }; -} - -function marks_set_idx(idx, x) { - if (!x) { - return x; - } - let match = x.hd; - if (match[1] !== -1) { - return x; - } else { - return { - hd: [ - match[0], - idx - ], - tl: marks_set_idx(idx, x.tl) - }; - } -} - -function marks_set_idx$1(marks, idx) { - return { - marks: marks_set_idx(idx, marks.marks), - pmarks: marks.pmarks - }; -} - -function first(f, _x) { - while (true) { - let x = _x; - if (!x) { - return; - } - let res = f(x.hd); - if (res !== undefined) { - return res; - } - _x = x.tl; - continue; - }; -} - -let eps_expr = { - id: 0, - def: "Eps" -}; - -function mk_expr(ids, def) { - ids.contents = ids.contents + 1 | 0; - return { - id: ids.contents, - def: def - }; -} - -function cst(ids, s) { - if (s ? false : true) { - return mk_expr(ids, { - TAG: "Alt", - _0: /* [] */0 - }); - } else { - return mk_expr(ids, { - TAG: "Cst", - _0: s - }); - } -} - -function alt(ids, x) { - if (x) { - if (x.tl) { - return mk_expr(ids, { - TAG: "Alt", - _0: x - }); - } else { - return x.hd; - } - } else { - return mk_expr(ids, { - TAG: "Alt", - _0: /* [] */0 - }); - } -} - -function seq$1(ids, kind, x, y) { - let match = x.def; - let match$1 = y.def; - let exit = 0; - if (typeof match !== "object") { - return y; - } - if (match.TAG === "Alt") { - if (!match._0) { - return x; - } - exit = 2; - } else { - exit = 2; - } - if (exit === 2) { - if (typeof match$1 !== "object") { - if (kind === "First") { - return x; - } - - } else if (match$1.TAG === "Alt" && !match$1._0) { - return y; - } - - } - return mk_expr(ids, { - TAG: "Seq", - _0: kind, - _1: x, - _2: y - }); -} - -function is_eps(expr) { - let match = expr.def; - if (typeof match !== "object") { - return true; - } else { - return false; - } -} - -function rep(ids, kind, sem, x) { - return mk_expr(ids, { - TAG: "Rep", - _0: kind, - _1: sem, - _2: x - }); -} - -function erase(ids, m, m$p) { - return mk_expr(ids, { - TAG: "Erase", - _0: m, - _1: m$p - }); -} - -function rename(ids, x) { - let l = x.def; - if (typeof l !== "object") { - return mk_expr(ids, x.def); - } - switch (l.TAG) { - case "Alt" : - return mk_expr(ids, { - TAG: "Alt", - _0: List.map(extra => rename(ids, extra), l._0) - }); - case "Seq" : - return mk_expr(ids, { - TAG: "Seq", - _0: l._0, - _1: rename(ids, l._1), - _2: rename(ids, l._2) - }); - case "Rep" : - return mk_expr(ids, { - TAG: "Rep", - _0: l._0, - _1: l._1, - _2: rename(ids, l._2) - }); - default: - return mk_expr(ids, x.def); - } -} - -function equal(_l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (!l1) { - if (l2) { - return false; - } else { - return true; - } - } - let marks1 = l1.hd; - switch (marks1.TAG) { - case "TSeq" : - if (!l2) { - return false; - } - let match = l2.hd; - switch (match.TAG) { - case "TSeq" : - if (marks1._1.id !== match._1.id) { - return false; - } - if (!equal(marks1._0, match._0)) { - return false; - } - _l2 = l2.tl; - _l1 = l1.tl; - continue; - case "TExp" : - case "TMatch" : - return false; - } - case "TExp" : - if (!l2) { - return false; - } - let match$1 = l2.hd; - switch (match$1.TAG) { - case "TExp" : - if (marks1._1.id !== match$1._1.id) { - return false; - } - if (!Caml_obj.equal(marks1._0, match$1._0)) { - return false; - } - _l2 = l2.tl; - _l1 = l1.tl; - continue; - case "TSeq" : - case "TMatch" : - return false; - } - case "TMatch" : - if (!l2) { - return false; - } - let marks2 = l2.hd; - switch (marks2.TAG) { - case "TSeq" : - case "TExp" : - return false; - case "TMatch" : - if (!Caml_obj.equal(marks1._0, marks2._0)) { - return false; - } - _l2 = l2.tl; - _l1 = l1.tl; - continue; - } - } - }; -} - -function hash$1(_l, _accu) { - while (true) { - let accu = _accu; - let l = _l; - if (!l) { - return accu; - } - let marks = l.hd; - switch (marks.TAG) { - case "TSeq" : - _accu = hash_combine(388635598, hash_combine(marks._1.id, hash$1(marks._0, accu))); - _l = l.tl; - continue; - case "TExp" : - _accu = hash_combine(726404471, hash_combine(marks._1.id, hash(marks._0, accu))); - _l = l.tl; - continue; - case "TMatch" : - _accu = hash_combine(471882453, hash(marks._0, accu)); - _l = l.tl; - continue; - } - }; -} - -function tseq(kind, x, y, rem) { - if (!x) { - return rem; - } - let match = x.hd; - switch (match.TAG) { - case "TExp" : - let tmp = match._1.def; - if (typeof tmp !== "object" && !x.tl) { - return { - hd: { - TAG: "TExp", - _0: match._0, - _1: y - }, - tl: rem - }; - } - break; - case "TSeq" : - case "TMatch" : - break; - } - return { - hd: { - TAG: "TSeq", - _0: x, - _1: y, - _2: kind - }, - tl: rem - }; -} - -let dummy = { - idx: -1, - category: -1, - desc: /* [] */0, - status: undefined, - hash: -1 -}; - -function hash$2(idx, cat, desc) { - return hash$1(desc, hash_combine(idx, hash_combine(cat, 0))) & 1073741823; -} - -function mk(idx, cat, desc) { - return { - idx: idx, - category: cat, - desc: desc, - status: undefined, - hash: hash$2(idx, cat, desc) - }; -} - -function create$2(cat, e) { - return mk(0, cat, { - hd: { - TAG: "TExp", - _0: empty, - _1: e - }, - tl: /* [] */0 - }); -} - -function equal$1(x, y) { - if (x.hash === y.hash && x.idx === y.idx && x.category === y.category) { - return equal(x.desc, y.desc); - } else { - return false; - } -} - -function hash$3(t) { - return t.hash; -} - -let Table = Hashtbl.Make({ - equal: equal$1, - hash: hash$3 -}); - -function reset_table(a) { - $$Array.fill(a, 0, a.length, false); -} - -function mark_used_indices(tbl) { - return extra => List.iter(x => { - switch (x.TAG) { - case "TSeq" : - return mark_used_indices(tbl)(x._0); - case "TExp" : - case "TMatch" : - break; - } - List.iter(param => { - let i = param[1]; - if (i >= 0) { - return Caml_array.set(tbl, i, true); - } - - }, x._0.marks); - }, extra); -} - -function find_free(tbl, _idx, len) { - while (true) { - let idx = _idx; - if (idx === len || !Caml_array.get(tbl, idx)) { - return idx; - } - _idx = idx + 1 | 0; - continue; - }; -} - -function free_index(tbl_ref, l) { - let tbl = tbl_ref.contents; - reset_table(tbl); - mark_used_indices(tbl)(l); - let len = tbl.length; - let idx = find_free(tbl, 0, len); - if (idx === len) { - tbl_ref.contents = Caml_array.make((len << 1), false); - } - return idx; -} - -function remove_matches(extra) { - return List.filter(x => { - switch (x.TAG) { - case "TSeq" : - case "TExp" : - return true; - case "TMatch" : - return false; - } - }, extra); -} - -function split_at_match_rec(_l$p, _x) { - while (true) { - let x = _x; - let l$p = _l$p; - if (x) { - let x$1 = x.hd; - switch (x$1.TAG) { - case "TSeq" : - case "TExp" : - _x = x.tl; - _l$p = { - hd: x$1, - tl: l$p - }; - continue; - case "TMatch" : - return [ - List.rev(l$p), - remove_matches(x.tl) - ]; - } - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "ocaml_re_test.res", - 815, - 16 - ], - Error: new Error() - }; - } - }; -} - -function remove_duplicates(prev, _l, y) { - while (true) { - let l = _l; - if (!l) { - return [ - /* [] */0, - prev - ]; - } - let x = l.hd; - switch (x.TAG) { - case "TSeq" : - let x$1 = x._1; - let match = remove_duplicates(prev, x._0, x$1); - let match$1 = remove_duplicates(match[1], l.tl, y); - return [ - tseq(x._2, match[0], x$1, match$1[0]), - match$1[1] - ]; - case "TExp" : - let x$2 = x._1; - let tmp = x$2.def; - if (typeof tmp !== "object") { - let r = l.tl; - if (List.memq(y.id, prev)) { - _l = r; - continue; - } - let match$2 = remove_duplicates({ - hd: y.id, - tl: prev - }, r, y); - return [ - { - hd: x, - tl: match$2[0] - }, - match$2[1] - ]; - } - let r$1 = l.tl; - if (List.memq(x$2.id, prev)) { - _l = r$1; - continue; - } - let match$3 = remove_duplicates({ - hd: x$2.id, - tl: prev - }, r$1, y); - return [ - { - hd: x, - tl: match$3[0] - }, - match$3[1] - ]; - case "TMatch" : - return [ - { - hd: x, - tl: /* [] */0 - }, - prev - ]; - } - }; -} - -function set_idx(idx, x) { - if (!x) { - return /* [] */0; - } - let marks = x.hd; - switch (marks.TAG) { - case "TSeq" : - return { - hd: { - TAG: "TSeq", - _0: set_idx(idx, marks._0), - _1: marks._1, - _2: marks._2 - }, - tl: set_idx(idx, x.tl) - }; - case "TExp" : - return { - hd: { - TAG: "TExp", - _0: marks_set_idx$1(marks._0, idx), - _1: marks._1 - }, - tl: set_idx(idx, x.tl) - }; - case "TMatch" : - return { - hd: { - TAG: "TMatch", - _0: marks_set_idx$1(marks._0, idx) - }, - tl: set_idx(idx, x.tl) - }; - } -} - -function filter_marks(b, e, marks) { - return { - marks: List.filter(param => { - let i = param[0]; - if (i < b) { - return true; - } else { - return i > e; - } - }, marks.marks), - pmarks: marks.pmarks - }; -} - -function delta_1(marks, c, next_cat, prev_cat, x, rem) { - let s = x.def; - if (typeof s !== "object") { - return { - hd: { - TAG: "TMatch", - _0: marks - }, - tl: rem - }; - } - switch (s.TAG) { - case "Cst" : - if (mem(c, s._0)) { - return { - hd: { - TAG: "TExp", - _0: marks, - _1: eps_expr - }, - tl: rem - }; - } else { - return rem; - } - case "Alt" : - return delta_2(marks, c, next_cat, prev_cat, s._0, rem); - case "Seq" : - let y$p = delta_1(marks, c, next_cat, prev_cat, s._1, /* [] */0); - return delta_seq(c, next_cat, prev_cat, s._0, y$p, s._2, rem); - case "Rep" : - let kind = s._1; - let y$p$1 = delta_1(marks, c, next_cat, prev_cat, s._2, /* [] */0); - let marks$p = first(x => { - switch (x.TAG) { - case "TSeq" : - case "TExp" : - return; - case "TMatch" : - return x._0; - } - }, y$p$1); - let match = marks$p !== undefined ? [ - remove_matches(y$p$1), - marks$p - ] : [ - y$p$1, - marks - ]; - let y$p$p = match[0]; - if (s._0 === "Non_greedy") { - return { - hd: { - TAG: "TMatch", - _0: marks - }, - tl: tseq(kind, y$p$p, x, rem) - }; - } else { - return tseq(kind, y$p$p, x, { - hd: { - TAG: "TMatch", - _0: match[1] - }, - tl: rem - }); - } - case "Mark" : - let i = s._0; - let marks_marks = { - hd: [ - i, - -1 - ], - tl: List.remove_assq(i, marks.marks) - }; - let marks_pmarks = marks.pmarks; - let marks$1 = { - marks: marks_marks, - pmarks: marks_pmarks - }; - return { - hd: { - TAG: "TMatch", - _0: marks$1 - }, - tl: rem - }; - case "Erase" : - return { - hd: { - TAG: "TMatch", - _0: filter_marks(s._0, s._1, marks) - }, - tl: rem - }; - case "Before" : - if (intersect(next_cat, s._0)) { - return { - hd: { - TAG: "TMatch", - _0: marks - }, - tl: rem - }; - } else { - return rem; - } - case "After" : - if (intersect(prev_cat, s._0)) { - return { - hd: { - TAG: "TMatch", - _0: marks - }, - tl: rem - }; - } else { - return rem; - } - case "Pmark" : - let marks_marks$1 = marks.marks; - let marks_pmarks$1 = add$1(s._0, marks.pmarks); - let marks$2 = { - marks: marks_marks$1, - pmarks: marks_pmarks$1 - }; - return { - hd: { - TAG: "TMatch", - _0: marks$2 - }, - tl: rem - }; - } -} - -function delta_2(marks, c, next_cat, prev_cat, l, rem) { - if (l) { - return delta_1(marks, c, next_cat, prev_cat, l.hd, delta_2(marks, c, next_cat, prev_cat, l.tl, rem)); - } else { - return rem; - } -} - -function delta_seq(c, next_cat, prev_cat, kind, y, z, rem) { - let marks = first(x => { - switch (x.TAG) { - case "TSeq" : - case "TExp" : - return; - case "TMatch" : - return x._0; - } - }, y); - if (marks === undefined) { - return tseq(kind, y, z, rem); - } - if (kind === "Longest") { - return tseq(kind, remove_matches(y), z, delta_1(marks, c, next_cat, prev_cat, z, rem)); - } - if (kind !== "First") { - return delta_1(marks, c, next_cat, prev_cat, z, tseq(kind, remove_matches(y), z, rem)); - } - let match = split_at_match_rec(/* [] */0, y); - return tseq(kind, match[0], z, delta_1(marks, c, next_cat, prev_cat, z, tseq(kind, match[1], z, rem))); -} - -function delta_4(c, next_cat, prev_cat, l, rem) { - if (l) { - let x = l.hd; - let rem$1 = delta_4(c, next_cat, prev_cat, l.tl, rem); - switch (x.TAG) { - case "TSeq" : - let y$p = delta_4(c, next_cat, prev_cat, x._0, /* [] */0); - return delta_seq(c, next_cat, prev_cat, x._2, y$p, x._1, rem$1); - case "TExp" : - return delta_1(x._0, c, next_cat, prev_cat, x._1, rem$1); - case "TMatch" : - return { - hd: x, - tl: rem$1 - }; - } - } else { - return rem; - } -} - -function delta(tbl_ref, next_cat, char, st) { - let prev_cat = st.category; - let match = remove_duplicates(/* [] */0, delta_4(char, next_cat, prev_cat, st.desc, /* [] */0), eps_expr); - let expr$p = match[0]; - let idx = free_index(tbl_ref, expr$p); - let expr$p$p = set_idx(idx, expr$p); - return mk(idx, next_cat, expr$p$p); -} - -function flatten_match(m) { - let ma = List.fold_left((ma, param) => Caml.int_max(ma, param[0]), -1, m); - let res = Caml_array.make(ma + 1 | 0, -1); - List.iter(param => Caml_array.set(res, param[0], param[1]), m); - return res; -} - -function status(s) { - let st = s.status; - if (st !== undefined) { - return st; - } - let match = s.desc; - let st$1; - if (match) { - let m = match.hd; - switch (m.TAG) { - case "TSeq" : - case "TExp" : - st$1 = "Running"; - break; - case "TMatch" : - let m$1 = m._0; - st$1 = { - TAG: "Match", - _0: flatten_match(m$1.marks), - _1: m$1.pmarks - }; - break; - } - } else { - st$1 = "Failed"; - } - s.status = st$1; - return st$1; -} - -let Re_automata_Category = { - $plus$plus: $plus$plus, - from_char: from_char, - inexistant: 1, - letter: 2, - not_letter: 4, - newline: 8, - lastnewline: 16, - search_boundary: 32 -}; - -let Re_automata_State = { - dummy: dummy, - create: create$2, - Table: Table -}; - -function iter(_n, f, _v) { - while (true) { - let v = _v; - let n = _n; - if (n === 0) { - return v; - } - _v = f(v); - _n = n - 1 | 0; - continue; - }; -} - -function category(re, c) { - if (c === -1) { - return Re_automata_Category.inexistant; - } else if (c === re.lnl) { - return Re_automata_Category.$plus$plus(Re_automata_Category.$plus$plus(Re_automata_Category.lastnewline, Re_automata_Category.newline), Re_automata_Category.not_letter); - } else { - return Re_automata_Category.from_char(Caml_bytes.get(re.col_repr, c)); - } -} - -let dummy_next = []; - -let unknown_state = { - idx: -2, - real_idx: 0, - next: dummy_next, - final: /* [] */0, - desc: Re_automata_State.dummy -}; - -function mk_state(ncol, desc) { - let match = status(desc); - let break_state; - break_state = typeof match !== "object" && match !== "Failed" ? false : true; - return { - idx: break_state ? -3 : desc.idx, - real_idx: desc.idx, - next: break_state ? dummy_next : Caml_array.make(ncol, unknown_state), - final: /* [] */0, - desc: desc - }; -} - -function find_state(re, desc) { - try { - return Re_automata_State.Table.find(re.states, desc); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - let st = mk_state(re.ncol, desc); - Re_automata_State.Table.add(re.states, desc, st); - return st; - } - throw exn; - } -} - -function delta$1(info, cat, c, st) { - let desc = delta(info.re.tbl, cat, c, st.desc); - let len = info.positions.length; - if (desc.idx === len && len > 0) { - let pos = info.positions; - info.positions = Caml_array.make((len << 1), 0); - $$Array.blit(pos, 0, info.positions, 0, len); - } - return desc; -} - -function validate(info, s, pos, st) { - let c = Caml_bytes.get(info.i_cols, Caml_string.get(s, pos)); - let cat = category(info.re, c); - let desc$p = delta$1(info, cat, c, st); - let st$p = find_state(info.re, desc$p); - Caml_array.set(st.next, c, st$p); -} - -function loop(info, s, pos, st) { - if (pos >= info.last) { - return st; - } - let st$p = Caml_array.get(st.next, Caml_bytes.get(info.i_cols, Caml_string.get(s, pos))); - let _pos = pos; - let _st = st; - let _st$p = st$p; - while (true) { - let st$p$1 = _st$p; - let st$1 = _st; - let pos$1 = _pos; - if (st$p$1.idx < 0) { - if (st$p$1.idx === -3) { - Caml_array.set(info.positions, st$p$1.real_idx, pos$1 + 1 | 0); - return st$p$1; - } else { - validate(info, s, pos$1, st$1); - return loop(info, s, pos$1, st$1); - } - } - let pos$2 = pos$1 + 1 | 0; - if (pos$2 < info.last) { - let st$p$p = Caml_array.get(st$p$1.next, Caml_bytes.get(info.i_cols, Caml_string.get(s, pos$2))); - Caml_array.set(info.positions, st$p$1.idx, pos$2); - _st$p = st$p$p; - _st = st$p$1; - _pos = pos$2; - continue; - } - Caml_array.set(info.positions, st$p$1.idx, pos$2); - return st$p$1; - }; -} - -function final(info, st, cat) { - try { - return List.assq(cat, st.final); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - let st$p = delta$1(info, cat, -1, st); - let res_0 = st$p.idx; - let res_1 = status(st$p); - let res = [ - res_0, - res_1 - ]; - st.final = { - hd: [ - cat, - res - ], - tl: st.final - }; - return res; - } - throw exn; - } -} - -function find_initial_state(re, cat) { - try { - return List.assq(cat, re.initial_states); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - let st = find_state(re, Re_automata_State.create(cat, re.initial)); - re.initial_states = { - hd: [ - cat, - st - ], - tl: re.initial_states - }; - return st; - } - throw exn; - } -} - -function get_color(re, s, pos) { - if (pos < 0) { - return -1; - } - let slen = s.length; - if (pos >= slen) { - return -1; - } else if (pos === (slen - 1 | 0) && re.lnl !== -1 && Caml_string.get(s, pos) === /* '\n' */10) { - return re.lnl; - } else { - return Caml_bytes.get(re.cols, Caml_string.get(s, pos)); - } -} - -function scan_str(info, s, initial_state, groups) { - let pos = info.pos; - let last = info.last; - if (!(last === s.length && info.re.lnl !== -1 && last > pos && Caml_string.get(s, last - 1 | 0) === /* '\n' */10)) { - if (groups) { - return loop(info, s, pos, initial_state); - } else { - let _pos = pos; - let _st = initial_state; - while (true) { - let st = _st; - let pos$1 = _pos; - if (pos$1 >= last) { - return st; - } - let st$p = Caml_array.get(st.next, Caml_bytes.get(info.i_cols, Caml_string.get(s, pos$1))); - if (st$p.idx >= 0) { - _st = st$p; - _pos = pos$1 + 1 | 0; - continue; - } - if (st$p.idx === -3) { - return st$p; - } - validate(info, s, pos$1, st); - continue; - }; - } - } - let info$1 = { - re: info.re, - i_cols: info.i_cols, - positions: info.positions, - pos: info.pos, - last: last - 1 | 0 - }; - let st$1 = scan_str(info$1, s, initial_state, groups); - if (st$1.idx === -3) { - return st$1; - } else { - let pos$2 = last - 1 | 0; - while (true) { - let st$p$1 = Caml_array.get(st$1.next, info$1.re.lnl); - if (st$p$1.idx >= 0) { - if (groups) { - Caml_array.set(info$1.positions, st$p$1.idx, pos$2 + 1 | 0); - } - return st$p$1; - } - if (st$p$1.idx === -3) { - if (groups) { - Caml_array.set(info$1.positions, st$p$1.real_idx, pos$2 + 1 | 0); - } - return st$p$1; - } - let c = info$1.re.lnl; - let real_c = Caml_bytes.get(info$1.i_cols, /* '\n' */10); - let cat = category(info$1.re, c); - let desc$p = delta$1(info$1, cat, real_c, st$1); - let st$p$2 = find_state(info$1.re, desc$p); - Caml_array.set(st$1.next, c, st$p$2); - continue; - }; - } -} - -function cadd(c, s) { - return union(single(c), s); -} - -function trans_set(cache, cm, s) { - let i = one_char(s); - if (i !== undefined) { - return single(Caml_bytes.get(cm, i)); - } - let v_0 = hash_rec(s); - let v = [ - v_0, - s - ]; - try { - let _param = cache.contents; - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let c = compare(v, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - let l = List.fold_right((param, l) => union(seq(Caml_bytes.get(cm, param[0]), Caml_bytes.get(cm, param[1])), l), s, /* [] */0); - cache.contents = add(v, l, cache.contents); - return l; - } - throw exn; - } -} - -function is_charset(_x) { - while (true) { - let x = _x; - if (typeof x !== "object") { - return false; - } - switch (x.TAG) { - case "Set" : - return true; - case "Sem" : - case "Sem_greedy" : - _x = x._1; - continue; - case "No_group" : - case "Case" : - case "No_case" : - _x = x._0; - continue; - case "Alternative" : - case "Intersection" : - case "Complement" : - return List.for_all(is_charset, x._0); - case "Difference" : - if (!is_charset(x._0)) { - return false; - } - _x = x._1; - continue; - default: - return false; - } - }; -} - -function split(s, cm) { - let _t = s; - let f = (i, j) => { - Caml_bytes.set(cm, i, /* '\001' */1); - Caml_bytes.set(cm, j + 1 | 0, /* '\001' */1); - }; - while (true) { - let t = _t; - if (!t) { - return; - } - let match = t.hd; - f(match[0], match[1]); - _t = t.tl; - continue; - }; -} - -let cupper = union(seq(/* 'A' */65, /* 'Z' */90), union(seq(/* '\192' */192, /* '\214' */214), seq(/* '\216' */216, /* '\222' */222))); - -let clower = offset(32, cupper); - -let calpha = List.fold_right(cadd, { - hd: /* '\170' */170, - tl: { - hd: /* '\181' */181, - tl: { - hd: /* '\186' */186, - tl: { - hd: /* '\223' */223, - tl: { - hd: /* '\255' */255, - tl: /* [] */0 - } - } - } - } -}, union(clower, cupper)); - -let cdigit = seq(/* '0' */48, /* '9' */57); - -let calnum = union(calpha, cdigit); - -let cword = union({ - hd: [ - /* '_' */95, - /* '_' */95 - ], - tl: /* [] */0 -}, calnum); - -function colorize(c, regexp) { - let lnl = { - contents: false - }; - let colorize$1 = _regexp => { - while (true) { - let regexp = _regexp; - if (typeof regexp !== "object") { - switch (regexp) { - case "Beg_of_line" : - case "End_of_line" : - return split({ - hd: [ - /* '\n' */10, - /* '\n' */10 - ], - tl: /* [] */0 - }, c); - case "Beg_of_word" : - case "End_of_word" : - case "Not_bound" : - return split(cword, c); - case "Last_end_of_line" : - lnl.contents = true; - return; - case "Beg_of_str" : - case "End_of_str" : - case "Start" : - case "Stop" : - return; - } - } else { - switch (regexp.TAG) { - case "Set" : - return split(regexp._0, c); - case "Sequence" : - case "Alternative" : - return List.iter(colorize$1, regexp._0); - case "Repeat" : - case "Group" : - case "No_group" : - case "Nest" : - _regexp = regexp._0; - continue; - case "Sem" : - case "Sem_greedy" : - case "Pmark" : - _regexp = regexp._1; - continue; - default: - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "ocaml_re_test.res", - 2168, - 8 - ], - Error: new Error() - }; - } - } - }; - }; - colorize$1(regexp); - return lnl.contents; -} - -function flatten_cmap(cm) { - let c = Caml_bytes.create(256); - let col_repr = Caml_bytes.create(256); - let v = 0; - Caml_bytes.set(c, 0, /* '\000' */0); - Caml_bytes.set(col_repr, 0, /* '\000' */0); - for (let i = 1; i <= 255; ++i) { - if (Caml_bytes.get(cm, i) !== /* '\000' */0) { - v = v + 1 | 0; - } - Caml_bytes.set(c, i, Char.chr(v)); - Caml_bytes.set(col_repr, v, Char.chr(i)); - } - return [ - c, - Bytes.sub(col_repr, 0, v + 1 | 0), - v + 1 | 0 - ]; -} - -function equal$2(_x1, _x2) { - while (true) { - let x2 = _x2; - let x1 = _x1; - if (typeof x1 !== "object") { - switch (x1) { - case "Beg_of_line" : - if (typeof x2 !== "object" && x2 === "Beg_of_line") { - return true; - } else { - return false; - } - case "End_of_line" : - if (typeof x2 !== "object" && x2 === "End_of_line") { - return true; - } else { - return false; - } - case "Beg_of_word" : - if (typeof x2 !== "object" && x2 === "Beg_of_word") { - return true; - } else { - return false; - } - case "End_of_word" : - if (typeof x2 !== "object" && x2 === "End_of_word") { - return true; - } else { - return false; - } - case "Not_bound" : - if (typeof x2 !== "object" && x2 === "Not_bound") { - return true; - } else { - return false; - } - case "Beg_of_str" : - if (typeof x2 !== "object" && x2 === "Beg_of_str") { - return true; - } else { - return false; - } - case "End_of_str" : - if (typeof x2 !== "object" && x2 === "End_of_str") { - return true; - } else { - return false; - } - case "Last_end_of_line" : - if (typeof x2 !== "object" && x2 === "Last_end_of_line") { - return true; - } else { - return false; - } - case "Start" : - if (typeof x2 !== "object" && x2 === "Start") { - return true; - } else { - return false; - } - case "Stop" : - if (typeof x2 !== "object" && x2 === "Stop") { - return true; - } else { - return false; - } - } - } else { - switch (x1.TAG) { - case "Set" : - if (typeof x2 !== "object" || x2.TAG !== "Set") { - return false; - } else { - return Caml_obj.equal(x1._0, x2._0); - } - case "Sequence" : - if (typeof x2 !== "object" || x2.TAG !== "Sequence") { - return false; - } else { - return eq_list(x1._0, x2._0); - } - case "Alternative" : - if (typeof x2 !== "object" || x2.TAG !== "Alternative") { - return false; - } else { - return eq_list(x1._0, x2._0); - } - case "Repeat" : - if (typeof x2 !== "object") { - return false; - } - if (x2.TAG !== "Repeat") { - return false; - } - if (x1._1 !== x2._1) { - return false; - } - if (!Caml_obj.equal(x1._2, x2._2)) { - return false; - } - _x2 = x2._0; - _x1 = x1._0; - continue; - case "Sem" : - if (typeof x2 !== "object") { - return false; - } - if (x2.TAG !== "Sem") { - return false; - } - if (x1._0 !== x2._0) { - return false; - } - _x2 = x2._1; - _x1 = x1._1; - continue; - case "Sem_greedy" : - if (typeof x2 !== "object") { - return false; - } - if (x2.TAG !== "Sem_greedy") { - return false; - } - if (x1._0 !== x2._0) { - return false; - } - _x2 = x2._1; - _x1 = x1._1; - continue; - case "Group" : - return false; - case "No_group" : - if (typeof x2 !== "object") { - return false; - } - if (x2.TAG !== "No_group") { - return false; - } - _x2 = x2._0; - _x1 = x1._0; - continue; - case "Nest" : - if (typeof x2 !== "object") { - return false; - } - if (x2.TAG !== "Nest") { - return false; - } - _x2 = x2._0; - _x1 = x1._0; - continue; - case "Case" : - if (typeof x2 !== "object") { - return false; - } - if (x2.TAG !== "Case") { - return false; - } - _x2 = x2._0; - _x1 = x1._0; - continue; - case "No_case" : - if (typeof x2 !== "object") { - return false; - } - if (x2.TAG !== "No_case") { - return false; - } - _x2 = x2._0; - _x1 = x1._0; - continue; - case "Intersection" : - if (typeof x2 !== "object" || x2.TAG !== "Intersection") { - return false; - } else { - return eq_list(x1._0, x2._0); - } - case "Complement" : - if (typeof x2 !== "object" || x2.TAG !== "Complement") { - return false; - } else { - return eq_list(x1._0, x2._0); - } - case "Difference" : - if (typeof x2 !== "object") { - return false; - } - if (x2.TAG !== "Difference") { - return false; - } - if (!equal$2(x1._0, x2._0)) { - return false; - } - _x2 = x2._1; - _x1 = x1._1; - continue; - case "Pmark" : - if (typeof x2 !== "object") { - return false; - } - if (x2.TAG !== "Pmark") { - return false; - } - if (x1._0 !== x2._0) { - return false; - } - _x2 = x2._1; - _x1 = x1._1; - continue; - } - } - }; -} - -function eq_list(_l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (!l1) { - if (l2) { - return false; - } else { - return true; - } - } - if (!l2) { - return false; - } - if (!equal$2(l1.hd, l2.hd)) { - return false; - } - _l2 = l2.tl; - _l1 = l1.tl; - continue; - }; -} - -function sequence(x) { - if (x && !x.tl) { - return x.hd; - } else { - return { - TAG: "Sequence", - _0: x - }; - } -} - -function merge_sequences(_x) { - while (true) { - let x = _x; - if (!x) { - return /* [] */0; - } - let l$p = x.hd; - if (typeof l$p === "object") { - switch (l$p.TAG) { - case "Sequence" : - let match = l$p._0; - if (match) { - let y = match.tl; - let x$1 = match.hd; - let r$p = merge_sequences(x.tl); - let exit = 0; - if (r$p) { - let match$1 = r$p.hd; - if (typeof match$1 !== "object" || match$1.TAG !== "Sequence") { - exit = 2; - } else { - let match$2 = match$1._0; - if (match$2) { - if (equal$2(x$1, match$2.hd)) { - return { - hd: { - TAG: "Sequence", - _0: { - hd: x$1, - tl: { - hd: { - TAG: "Alternative", - _0: { - hd: sequence(y), - tl: { - hd: sequence(match$2.tl), - tl: /* [] */0 - } - } - }, - tl: /* [] */0 - } - } - }, - tl: r$p.tl - }; - } - exit = 2; - } else { - exit = 2; - } - } - } else { - exit = 2; - } - if (exit === 2) { - return { - hd: { - TAG: "Sequence", - _0: { - hd: x$1, - tl: y - } - }, - tl: r$p - }; - } - - } - break; - case "Alternative" : - _x = Pervasives.$at(l$p._0, x.tl); - continue; - } - } - return { - hd: l$p, - tl: merge_sequences(x.tl) - }; - }; -} - -function enforce_kind(ids, kind, kind$p, cr) { - if (kind === "First" && kind$p !== "First") { - return seq$1(ids, kind$p, cr, mk_expr(ids, "Eps")); - } else { - return cr; - } -} - -function translate(ids, kind, _ign_group, ign_case, _greedy, pos, cache, c, _x) { - while (true) { - let x = _x; - let greedy = _greedy; - let ign_group = _ign_group; - if (typeof x !== "object") { - switch (x) { - case "Beg_of_line" : - let c$1 = Re_automata_Category.$plus$plus(Re_automata_Category.inexistant, Re_automata_Category.newline); - return [ - mk_expr(ids, { - TAG: "After", - _0: c$1 - }), - kind - ]; - case "End_of_line" : - let c$2 = Re_automata_Category.$plus$plus(Re_automata_Category.inexistant, Re_automata_Category.newline); - return [ - mk_expr(ids, { - TAG: "Before", - _0: c$2 - }), - kind - ]; - case "Beg_of_word" : - let c$3 = Re_automata_Category.$plus$plus(Re_automata_Category.inexistant, Re_automata_Category.not_letter); - let c$4 = Re_automata_Category.$plus$plus(Re_automata_Category.inexistant, Re_automata_Category.letter); - return [ - seq$1(ids, "First", mk_expr(ids, { - TAG: "After", - _0: c$3 - }), mk_expr(ids, { - TAG: "Before", - _0: c$4 - })), - kind - ]; - case "End_of_word" : - let c$5 = Re_automata_Category.$plus$plus(Re_automata_Category.inexistant, Re_automata_Category.letter); - let c$6 = Re_automata_Category.$plus$plus(Re_automata_Category.inexistant, Re_automata_Category.not_letter); - return [ - seq$1(ids, "First", mk_expr(ids, { - TAG: "After", - _0: c$5 - }), mk_expr(ids, { - TAG: "Before", - _0: c$6 - })), - kind - ]; - case "Not_bound" : - return [ - alt(ids, { - hd: seq$1(ids, "First", mk_expr(ids, { - TAG: "After", - _0: Re_automata_Category.letter - }), mk_expr(ids, { - TAG: "Before", - _0: Re_automata_Category.letter - })), - tl: { - hd: seq$1(ids, "First", mk_expr(ids, { - TAG: "After", - _0: Re_automata_Category.letter - }), mk_expr(ids, { - TAG: "Before", - _0: Re_automata_Category.letter - })), - tl: /* [] */0 - } - }), - kind - ]; - case "Beg_of_str" : - return [ - mk_expr(ids, { - TAG: "After", - _0: Re_automata_Category.inexistant - }), - kind - ]; - case "End_of_str" : - return [ - mk_expr(ids, { - TAG: "Before", - _0: Re_automata_Category.inexistant - }), - kind - ]; - case "Last_end_of_line" : - let c$7 = Re_automata_Category.$plus$plus(Re_automata_Category.inexistant, Re_automata_Category.lastnewline); - return [ - mk_expr(ids, { - TAG: "Before", - _0: c$7 - }), - kind - ]; - case "Start" : - return [ - mk_expr(ids, { - TAG: "After", - _0: Re_automata_Category.search_boundary - }), - kind - ]; - case "Stop" : - return [ - mk_expr(ids, { - TAG: "Before", - _0: Re_automata_Category.search_boundary - }), - kind - ]; - } - } else { - switch (x.TAG) { - case "Set" : - return [ - cst(ids, trans_set(cache, c, x._0)), - kind - ]; - case "Sequence" : - return [ - trans_seq(ids, kind, ign_group, ign_case, greedy, pos, cache, c, x._0), - kind - ]; - case "Alternative" : - let merged_sequences = merge_sequences(x._0); - if (merged_sequences && !merged_sequences.tl) { - let match = translate(ids, kind, ign_group, ign_case, greedy, pos, cache, c, merged_sequences.hd); - return [ - enforce_kind(ids, kind, match[1], match[0]), - kind - ]; - } - return [ - alt(ids, List.map(r$p => { - let match = translate(ids, kind, ign_group, ign_case, greedy, pos, cache, c, r$p); - return enforce_kind(ids, kind, match[1], match[0]); - }, merged_sequences)), - kind - ]; - case "Repeat" : - let j = x._2; - let i = x._1; - let match$1 = translate(ids, kind, ign_group, ign_case, greedy, pos, cache, c, x._0); - let kind$p = match$1[1]; - let cr = match$1[0]; - let rem; - if (j !== undefined) { - let f = greedy === "Non_greedy" ? rem => alt(ids, { - hd: mk_expr(ids, "Eps"), - tl: { - hd: seq$1(ids, kind$p, rename(ids, cr), rem), - tl: /* [] */0 - } - }) : rem => alt(ids, { - hd: seq$1(ids, kind$p, rename(ids, cr), rem), - tl: { - hd: mk_expr(ids, "Eps"), - tl: /* [] */0 - } - }); - rem = iter(j - i | 0, f, mk_expr(ids, "Eps")); - } else { - rem = rep(ids, greedy, kind$p, cr); - } - return [ - iter(i, rem => seq$1(ids, kind$p, rename(ids, cr), rem), rem), - kind - ]; - case "Sem" : - let kind$p$1 = x._0; - let match$2 = translate(ids, kind$p$1, ign_group, ign_case, greedy, pos, cache, c, x._1); - return [ - enforce_kind(ids, kind$p$1, match$2[1], match$2[0]), - kind$p$1 - ]; - case "Sem_greedy" : - _x = x._1; - _greedy = x._0; - continue; - case "Group" : - let r$p = x._0; - if (ign_group) { - _x = r$p; - continue; - } - let p = pos.contents; - pos.contents = pos.contents + 2 | 0; - let match$3 = translate(ids, kind, ign_group, ign_case, greedy, pos, cache, c, r$p); - return [ - seq$1(ids, "First", mk_expr(ids, { - TAG: "Mark", - _0: p - }), seq$1(ids, "First", match$3[0], mk_expr(ids, { - TAG: "Mark", - _0: p + 1 | 0 - }))), - match$3[1] - ]; - case "No_group" : - _x = x._0; - _ign_group = true; - continue; - case "Nest" : - let b = pos.contents; - let match$4 = translate(ids, kind, ign_group, ign_case, greedy, pos, cache, c, x._0); - let kind$p$2 = match$4[1]; - let cr$1 = match$4[0]; - let e = pos.contents - 1 | 0; - if (e < b) { - return [ - cr$1, - kind$p$2 - ]; - } else { - return [ - seq$1(ids, "First", erase(ids, b, e), cr$1), - kind$p$2 - ]; - } - case "Pmark" : - let match$5 = translate(ids, kind, ign_group, ign_case, greedy, pos, cache, c, x._1); - return [ - seq$1(ids, "First", mk_expr(ids, { - TAG: "Pmark", - _0: x._0 - }), match$5[0]), - match$5[1] - ]; - default: - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "ocaml_re_test.res", - 2402, - 80 - ], - Error: new Error() - }; - } - } - }; -} - -function trans_seq(ids, kind, ign_group, ign_case, greedy, pos, cache, c, x) { - if (!x) { - return mk_expr(ids, "Eps"); - } - let rem = x.tl; - let r = x.hd; - if (rem) { - let match = translate(ids, kind, ign_group, ign_case, greedy, pos, cache, c, r); - let cr$p = match[0]; - let cr$p$p = trans_seq(ids, kind, ign_group, ign_case, greedy, pos, cache, c, rem); - if (is_eps(cr$p$p)) { - return cr$p; - } else if (is_eps(cr$p)) { - return cr$p$p; - } else { - return seq$1(ids, match[1], cr$p, cr$p$p); - } - } - let match$1 = translate(ids, kind, ign_group, ign_case, greedy, pos, cache, c, r); - return enforce_kind(ids, kind, match$1[1], match$1[0]); -} - -function case_insens(s) { - return union(s, union(offset(32, inter(s, cupper)), offset(-32, inter(s, clower)))); -} - -function as_set(x) { - if (typeof x !== "object") { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "ocaml_re_test.res", - 2437, - 11 - ], - Error: new Error() - }; - } - if (x.TAG === "Set") { - return x._0; - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "ocaml_re_test.res", - 2437, - 11 - ], - Error: new Error() - }; -} - -function handle_case(_ign_case, _x) { - while (true) { - let x = _x; - let ign_case = _ign_case; - if (typeof x !== "object") { - return x; - } - switch (x.TAG) { - case "Set" : - let s = x._0; - return { - TAG: "Set", - _0: ign_case ? case_insens(s) : s - }; - case "Sequence" : - return { - TAG: "Sequence", - _0: List.map(extra => handle_case(ign_case, extra), x._0) - }; - case "Alternative" : - let l$p = List.map(extra => handle_case(ign_case, extra), x._0); - if (is_charset({ - TAG: "Alternative", - _0: l$p - })) { - return { - TAG: "Set", - _0: List.fold_left((s, r) => union(s, as_set(r)), /* [] */0, l$p) - }; - } else { - return { - TAG: "Alternative", - _0: l$p - }; - } - case "Repeat" : - return { - TAG: "Repeat", - _0: handle_case(ign_case, x._0), - _1: x._1, - _2: x._2 - }; - case "Sem" : - let r$p = handle_case(ign_case, x._1); - if (is_charset(r$p)) { - return r$p; - } else { - return { - TAG: "Sem", - _0: x._0, - _1: r$p - }; - } - case "Sem_greedy" : - let r$p$1 = handle_case(ign_case, x._1); - if (is_charset(r$p$1)) { - return r$p$1; - } else { - return { - TAG: "Sem_greedy", - _0: x._0, - _1: r$p$1 - }; - } - case "Group" : - return { - TAG: "Group", - _0: handle_case(ign_case, x._0) - }; - case "No_group" : - let r$p$2 = handle_case(ign_case, x._0); - if (is_charset(r$p$2)) { - return r$p$2; - } else { - return { - TAG: "No_group", - _0: r$p$2 - }; - } - case "Nest" : - let r$p$3 = handle_case(ign_case, x._0); - if (is_charset(r$p$3)) { - return r$p$3; - } else { - return { - TAG: "Nest", - _0: r$p$3 - }; - } - case "Case" : - _x = x._0; - _ign_case = false; - continue; - case "No_case" : - _x = x._0; - _ign_case = true; - continue; - case "Intersection" : - let l$p$1 = List.map(r => handle_case(ign_case, r), x._0); - return { - TAG: "Set", - _0: List.fold_left((s, r) => inter(s, as_set(r)), cany, l$p$1) - }; - case "Complement" : - let l$p$2 = List.map(r => handle_case(ign_case, r), x._0); - return { - TAG: "Set", - _0: diff(cany, List.fold_left((s, r) => union(s, as_set(r)), /* [] */0, l$p$2)) - }; - case "Difference" : - return { - TAG: "Set", - _0: inter(as_set(handle_case(ign_case, x._0)), diff(cany, as_set(handle_case(ign_case, x._1)))) - }; - case "Pmark" : - return { - TAG: "Pmark", - _0: x._0, - _1: handle_case(ign_case, x._1) - }; - } - }; -} - -function anchored(_x) { - while (true) { - let x = _x; - if (typeof x !== "object") { - switch (x) { - case "Beg_of_str" : - case "Start" : - return true; - default: - return false; - } - } else { - switch (x.TAG) { - case "Sequence" : - return List.exists(anchored, x._0); - case "Alternative" : - return List.for_all(anchored, x._0); - case "Repeat" : - if (x._1 <= 0) { - return false; - } - _x = x._0; - continue; - case "Group" : - case "No_group" : - case "Nest" : - case "Case" : - case "No_case" : - _x = x._0; - continue; - case "Sem" : - case "Sem_greedy" : - case "Pmark" : - _x = x._1; - continue; - default: - return false; - } - } - }; -} - -function alt$1(x) { - if (x && !x.tl) { - return x.hd; - } else { - return { - TAG: "Alternative", - _0: x - }; - } -} - -function seq$2(x) { - if (x && !x.tl) { - return x.hd; - } else { - return { - TAG: "Sequence", - _0: x - }; - } -} - -let epsilon = { - TAG: "Sequence", - _0: /* [] */0 -}; - -function repn(r, i, j) { - if (i < 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Re.repn", - Error: new Error() - }; - } - if (j !== undefined && j < i) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Re.repn", - Error: new Error() - }; - } - return { - TAG: "Repeat", - _0: r, - _1: i, - _2: j - }; -} - -function set(str) { - let s = /* [] */0; - for (let i = 0, i_finish = str.length; i < i_finish; ++i) { - s = union(single(Caml_string.get(str, i)), s); - } - return { - TAG: "Set", - _0: s - }; -} - -function compl(l) { - let r = { - TAG: "Complement", - _0: l - }; - if (is_charset(r)) { - return r; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Re.compl", - Error: new Error() - }; -} - -let any = { - TAG: "Set", - _0: cany -}; - -let notnl = { - TAG: "Set", - _0: diff(cany, { - hd: [ - /* '\n' */10, - /* '\n' */10 - ], - tl: /* [] */0 - }) -}; - -let lower = alt$1({ - hd: { - TAG: "Set", - _0: seq(/* 'a' */97, /* 'z' */122) - }, - tl: { - hd: { - TAG: "Set", - _0: { - hd: [ - /* '\181' */181, - /* '\181' */181 - ], - tl: /* [] */0 - } - }, - tl: { - hd: { - TAG: "Set", - _0: seq(/* '\223' */223, /* '\246' */246) - }, - tl: { - hd: { - TAG: "Set", - _0: seq(/* '\248' */248, /* '\255' */255) - }, - tl: /* [] */0 - } - } - } -}); - -let upper = alt$1({ - hd: { - TAG: "Set", - _0: seq(/* 'A' */65, /* 'Z' */90) - }, - tl: { - hd: { - TAG: "Set", - _0: seq(/* '\192' */192, /* '\214' */214) - }, - tl: { - hd: { - TAG: "Set", - _0: seq(/* '\216' */216, /* '\222' */222) - }, - tl: /* [] */0 - } - } -}); - -let alpha = alt$1({ - hd: lower, - tl: { - hd: upper, - tl: { - hd: { - TAG: "Set", - _0: { - hd: [ - /* '\170' */170, - /* '\170' */170 - ], - tl: /* [] */0 - } - }, - tl: { - hd: { - TAG: "Set", - _0: { - hd: [ - /* '\186' */186, - /* '\186' */186 - ], - tl: /* [] */0 - } - }, - tl: /* [] */0 - } - } - } -}); - -let digit = { - TAG: "Set", - _0: seq(/* '0' */48, /* '9' */57) -}; - -let alnum = alt$1({ - hd: alpha, - tl: { - hd: digit, - tl: /* [] */0 - } -}); - -let wordc = alt$1({ - hd: alnum, - tl: { - hd: { - TAG: "Set", - _0: { - hd: [ - /* '_' */95, - /* '_' */95 - ], - tl: /* [] */0 - } - }, - tl: /* [] */0 - } -}); - -let ascii = { - TAG: "Set", - _0: seq(/* '\000' */0, /* '\127' */127) -}; - -let blank = set("\t "); - -let cntrl = alt$1({ - hd: { - TAG: "Set", - _0: seq(/* '\000' */0, /* '\031' */31) - }, - tl: { - hd: { - TAG: "Set", - _0: seq(/* '\127' */127, /* '\159' */159) - }, - tl: /* [] */0 - } -}); - -let graph = alt$1({ - hd: { - TAG: "Set", - _0: seq(/* '!' */33, /* '~' */126) - }, - tl: { - hd: { - TAG: "Set", - _0: seq(/* '\160' */160, /* '\255' */255) - }, - tl: /* [] */0 - } -}); - -let print = alt$1({ - hd: { - TAG: "Set", - _0: seq(/* ' ' */32, /* '~' */126) - }, - tl: { - hd: { - TAG: "Set", - _0: seq(/* '\160' */160, /* '\255' */255) - }, - tl: /* [] */0 - } -}); - -let punct = alt$1({ - hd: { - TAG: "Set", - _0: seq(/* '!' */33, /* '/' */47) - }, - tl: { - hd: { - TAG: "Set", - _0: seq(/* ':' */58, /* '@' */64) - }, - tl: { - hd: { - TAG: "Set", - _0: seq(/* '[' */91, /* '`' */96) - }, - tl: { - hd: { - TAG: "Set", - _0: seq(/* '{' */123, /* '~' */126) - }, - tl: { - hd: { - TAG: "Set", - _0: seq(/* '\160' */160, /* '\169' */169) - }, - tl: { - hd: { - TAG: "Set", - _0: seq(/* '\171' */171, /* '\180' */180) - }, - tl: { - hd: { - TAG: "Set", - _0: seq(/* '\182' */182, /* '\185' */185) - }, - tl: { - hd: { - TAG: "Set", - _0: seq(/* '\187' */187, /* '\191' */191) - }, - tl: { - hd: { - TAG: "Set", - _0: { - hd: [ - /* '\215' */215, - /* '\215' */215 - ], - tl: /* [] */0 - } - }, - tl: { - hd: { - TAG: "Set", - _0: { - hd: [ - /* '\247' */247, - /* '\247' */247 - ], - tl: /* [] */0 - } - }, - tl: /* [] */0 - } - } - } - } - } - } - } - } - } -}); - -let space = alt$1({ - hd: { - TAG: "Set", - _0: { - hd: [ - /* ' ' */32, - /* ' ' */32 - ], - tl: /* [] */0 - } - }, - tl: { - hd: { - TAG: "Set", - _0: seq(/* '\t' */9, /* '\r' */13) - }, - tl: /* [] */0 - } -}); - -let xdigit = alt$1({ - hd: digit, - tl: { - hd: { - TAG: "Set", - _0: seq(/* 'a' */97, /* 'f' */102) - }, - tl: { - hd: { - TAG: "Set", - _0: seq(/* 'A' */65, /* 'F' */70) - }, - tl: /* [] */0 - } - } -}); - -function compile(r) { - let regexp = anchored(r) ? ({ - TAG: "Group", - _0: r - }) : seq$2({ - hd: { - TAG: "Sem", - _0: "Shortest", - _1: repn(any, 0, undefined) - }, - tl: { - hd: { - TAG: "Group", - _0: r - }, - tl: /* [] */0 - } - }); - let regexp$1 = handle_case(false, regexp); - let c = Bytes.make(257, /* '\000' */0); - let need_lnl = colorize(c, regexp$1); - let match = flatten_cmap(c); - let ncol = match[2]; - let col = match[0]; - let lnl = need_lnl ? ncol : -1; - let ncol$1 = need_lnl ? ncol + 1 | 0 : ncol; - let ids = { - contents: 0 - }; - let pos = { - contents: 0 - }; - let match$1 = translate(ids, "First", false, false, "Greedy", pos, { - contents: "Empty" - }, col, regexp$1); - let r$1 = enforce_kind(ids, "First", match$1[1], match$1[0]); - let col_repr = match[1]; - let group_count = pos.contents / 2 | 0; - return { - initial: r$1, - initial_states: /* [] */0, - cols: col, - col_repr: col_repr, - ncol: ncol$1, - lnl: lnl, - tbl: { - contents: [false] - }, - states: Re_automata_State.Table.create(97), - group_count: group_count - }; -} - -function exec_internal(name, posOpt, lenOpt, groups, re, s) { - let pos = posOpt !== undefined ? posOpt : 0; - let len = lenOpt !== undefined ? lenOpt : -1; - if (pos < 0 || len < -1 || (pos + len | 0) > s.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: name, - Error: new Error() - }; - } - let partial = false; - let slen = s.length; - let last = len === -1 ? slen : pos + len | 0; - let tmp; - if (groups) { - let n = re.tbl.contents.length + 1 | 0; - tmp = n <= 10 ? [ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ] : Caml_array.make(n, 0); - } else { - tmp = []; - } - let info = { - re: re, - i_cols: re.cols, - positions: tmp, - pos: pos, - last: last - }; - let initial_cat = pos === 0 ? Re_automata_Category.$plus$plus(Re_automata_Category.search_boundary, Re_automata_Category.inexistant) : Re_automata_Category.$plus$plus(Re_automata_Category.search_boundary, category(re, get_color(re, s, pos - 1 | 0))); - let initial_state = find_initial_state(re, initial_cat); - let st = scan_str(info, s, initial_state, groups); - let res; - if (st.idx === -3 || partial) { - res = status(st.desc); - } else { - let final_cat = last === slen ? Re_automata_Category.$plus$plus(Re_automata_Category.search_boundary, Re_automata_Category.inexistant) : Re_automata_Category.$plus$plus(Re_automata_Category.search_boundary, category(re, get_color(re, s, last))); - let match = final(info, st, final_cat); - if (groups) { - Caml_array.set(info.positions, match[0], last + 1 | 0); - } - res = match[1]; - } - if (typeof res !== "object") { - if (res === "Failed") { - return "Failed"; - } else { - return "Running"; - } - } else { - return { - TAG: "Match", - _0: { - s: s, - marks: res._0, - pmarks: res._1, - gpos: info.positions, - gcount: re.group_count - } - }; - } -} - -function offset$1(t, i) { - if (((i << 1) + 1 | 0) >= t.marks.length) { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let m1 = Caml_array.get(t.marks, (i << 1)); - if (m1 === -1) { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let p1 = Caml_array.get(t.gpos, m1) - 1 | 0; - let p2 = Caml_array.get(t.gpos, Caml_array.get(t.marks, (i << 1) + 1 | 0)) - 1 | 0; - return [ - p1, - p2 - ]; -} - -function get(t, i) { - let match = offset$1(t, i); - let p1 = match[0]; - return $$String.sub(t.s, p1, match[1] - p1 | 0); -} - -let Parse_error = /* @__PURE__ */Caml_exceptions.create("Parse_error"); - -let Not_supported = /* @__PURE__ */Caml_exceptions.create("Not_supported"); - -function posix_class_of_string(x) { - switch (x) { - case "alnum" : - return alnum; - case "ascii" : - return ascii; - case "blank" : - return blank; - case "cntrl" : - return cntrl; - case "digit" : - return digit; - case "graph" : - return graph; - case "lower" : - return lower; - case "print" : - return print; - case "punct" : - return punct; - case "space" : - return space; - case "upper" : - return upper; - case "word" : - return wordc; - case "xdigit" : - return xdigit; - default: - let s = "Invalid pcre class: " + x; - throw { - RE_EXN_ID: "Invalid_argument", - _1: s, - Error: new Error() - }; - } -} - -function parse(multiline, dollar_endonly, dotall, ungreedy, s) { - let i = { - contents: 0 - }; - let l = s.length; - let test = c => { - if (i.contents !== l) { - return Caml_string.get(s, i.contents) === c; - } else { - return false; - } - }; - let accept = c => { - let r = test(c); - if (r) { - i.contents = i.contents + 1 | 0; - } - return r; - }; - let accept_s = s$p => { - let len = s$p.length; - try { - for (let j = 0; j < len; ++j) { - try { - if (Caml_string.get(s$p, j) !== Caml_string.get(s, i.contents + j | 0)) { - throw { - RE_EXN_ID: Pervasives.Exit, - Error: new Error() - }; - } - - } catch (exn) { - throw { - RE_EXN_ID: Pervasives.Exit, - Error: new Error() - }; - } - } - i.contents = i.contents + len | 0; - return true; - } catch (raw_exn) { - let exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn$1.RE_EXN_ID === Pervasives.Exit) { - return false; - } - throw exn$1; - } - }; - let get = () => { - let r = Caml_string.get(s, i.contents); - i.contents = i.contents + 1 | 0; - return r; - }; - let greedy_mod = r => { - let gr = accept(/* '?' */63); - let gr$1 = ungreedy ? !gr : gr; - if (gr$1) { - return { - TAG: "Sem_greedy", - _0: "Non_greedy", - _1: r - }; - } else { - return { - TAG: "Sem_greedy", - _0: "Greedy", - _1: r - }; - } - }; - let regexp$p = _left => { - while (true) { - let left = _left; - if (!accept(/* '|' */124)) { - return left; - } - _left = alt$1({ - hd: left, - tl: { - hd: branch$p(/* [] */0), - tl: /* [] */0 - } - }); - continue; - }; - }; - let branch$p = _left => { - while (true) { - let left = _left; - if (i.contents === l || test(/* '|' */124) || test(/* ')' */41)) { - return seq$2(List.rev(left)); - } - _left = { - hd: piece(), - tl: left - }; - continue; - }; - }; - let atom = () => { - if (accept(/* '.' */46)) { - if (dotall) { - return any; - } else { - return notnl; - } - } - if (accept(/* '(' */40)) { - if (accept(/* '?' */63)) { - if (accept(/* ':' */58)) { - let r = regexp$p(branch()); - if (!accept(/* ')' */41)) { - throw { - RE_EXN_ID: Parse_error, - Error: new Error() - }; - } - return r; - } - if (accept(/* '#' */35)) { - return comment(); - } - throw { - RE_EXN_ID: Parse_error, - Error: new Error() - }; - } - let r$1 = regexp$p(branch()); - if (!accept(/* ')' */41)) { - throw { - RE_EXN_ID: Parse_error, - Error: new Error() - }; - } - return { - TAG: "Group", - _0: r$1 - }; - } - if (accept(/* '^' */94)) { - if (multiline) { - return "Beg_of_line"; - } else { - return "Beg_of_str"; - } - } - if (accept(/* '$' */36)) { - if (multiline) { - return "End_of_line"; - } else if (dollar_endonly) { - return "Last_end_of_line"; - } else { - return "End_of_str"; - } - } - if (accept(/* '[' */91)) { - if (accept(/* '^' */94)) { - return compl(bracket(/* [] */0)); - } else { - return alt$1(bracket(/* [] */0)); - } - } - if (accept(/* '\\' */92)) { - if (i.contents === l) { - throw { - RE_EXN_ID: Parse_error, - Error: new Error() - }; - } - let c = get(); - switch (c) { - case 48 : - case 49 : - case 50 : - case 51 : - case 52 : - case 53 : - case 54 : - case 55 : - case 56 : - case 57 : - throw { - RE_EXN_ID: Not_supported, - Error: new Error() - }; - case 65 : - return "Beg_of_str"; - case 66 : - return "Not_bound"; - case 68 : - return compl({ - hd: digit, - tl: /* [] */0 - }); - case 71 : - return "Start"; - case 83 : - return compl({ - hd: space, - tl: /* [] */0 - }); - case 87 : - return compl({ - hd: alnum, - tl: { - hd: { - TAG: "Set", - _0: { - hd: [ - /* '_' */95, - /* '_' */95 - ], - tl: /* [] */0 - } - }, - tl: /* [] */0 - } - }); - case 90 : - return "Last_end_of_line"; - case 98 : - return alt$1({ - hd: "Beg_of_word", - tl: { - hd: "End_of_word", - tl: /* [] */0 - } - }); - case 100 : - return digit; - case 115 : - return space; - case 119 : - return alt$1({ - hd: alnum, - tl: { - hd: { - TAG: "Set", - _0: { - hd: [ - /* '_' */95, - /* '_' */95 - ], - tl: /* [] */0 - } - }, - tl: /* [] */0 - } - }); - case 67 : - case 69 : - case 70 : - case 72 : - case 73 : - case 74 : - case 75 : - case 76 : - case 77 : - case 78 : - case 79 : - case 80 : - case 81 : - case 82 : - case 84 : - case 85 : - case 86 : - case 88 : - case 89 : - case 97 : - case 99 : - case 101 : - case 102 : - case 103 : - case 104 : - case 105 : - case 106 : - case 107 : - case 108 : - case 109 : - case 110 : - case 111 : - case 112 : - case 113 : - case 114 : - case 116 : - case 117 : - case 118 : - case 120 : - case 121 : - throw { - RE_EXN_ID: Parse_error, - Error: new Error() - }; - case 122 : - return "End_of_str"; - default: - return { - TAG: "Set", - _0: single(c) - }; - } - } else { - if (i.contents === l) { - throw { - RE_EXN_ID: Parse_error, - Error: new Error() - }; - } - let c$1 = get(); - if (c$1 >= 64) { - if (c$1 !== 92) { - if (c$1 !== 123) { - return { - TAG: "Set", - _0: single(c$1) - }; - } - throw { - RE_EXN_ID: Parse_error, - Error: new Error() - }; - } - throw { - RE_EXN_ID: Parse_error, - Error: new Error() - }; - } - if (c$1 >= 44) { - if (c$1 >= 63) { - throw { - RE_EXN_ID: Parse_error, - Error: new Error() - }; - } - return { - TAG: "Set", - _0: single(c$1) - }; - } - if (c$1 >= 42) { - throw { - RE_EXN_ID: Parse_error, - Error: new Error() - }; - } - return { - TAG: "Set", - _0: single(c$1) - }; - } - }; - let integer = () => { - if (i.contents === l) { - return; - } - let d = get(); - if (d > 57 || d < 48) { - i.contents = i.contents - 1 | 0; - return; - } else { - let _i = d - /* '0' */48 | 0; - while (true) { - let i$1 = _i; - if (i.contents === l) { - return i$1; - } - let d$1 = get(); - if (d$1 > 57 || d$1 < 48) { - i.contents = i.contents - 1 | 0; - return i$1; - } - let i$p = Math.imul(10, i$1) + (d$1 - /* '0' */48 | 0) | 0; - if (i$p < i$1) { - throw { - RE_EXN_ID: Parse_error, - Error: new Error() - }; - } - _i = i$p; - continue; - }; - } - }; - let piece = () => { - let r = atom(); - if (accept(/* '*' */42)) { - return greedy_mod(repn(r, 0, undefined)); - } - if (accept(/* '+' */43)) { - return greedy_mod(repn(r, 1, undefined)); - } - if (accept(/* '?' */63)) { - return greedy_mod(repn(r, 0, 1)); - } - if (!accept(/* '{' */123)) { - return r; - } - let i$1 = integer(); - if (i$1 !== undefined) { - let j = accept(/* ',' */44) ? integer() : i$1; - if (!accept(/* '}' */125)) { - throw { - RE_EXN_ID: Parse_error, - Error: new Error() - }; - } - if (j !== undefined && j < i$1) { - throw { - RE_EXN_ID: Parse_error, - Error: new Error() - }; - } - return greedy_mod(repn(r, i$1, j)); - } - i.contents = i.contents - 1 | 0; - return r; - }; - let char = () => { - if (i.contents === l) { - throw { - RE_EXN_ID: Parse_error, - Error: new Error() - }; - } - let c = get(); - if (c === /* '[' */91) { - if (accept(/* '=' */61)) { - throw { - RE_EXN_ID: Not_supported, - Error: new Error() - }; - } - if (accept(/* ':' */58)) { - let compl$1 = accept(/* '^' */94); - let cls; - try { - cls = List.find(accept_s, { - hd: "alnum", - tl: { - hd: "ascii", - tl: { - hd: "blank", - tl: { - hd: "cntrl", - tl: { - hd: "digit", - tl: { - hd: "lower", - tl: { - hd: "print", - tl: { - hd: "space", - tl: { - hd: "upper", - tl: { - hd: "word", - tl: { - hd: "punct", - tl: { - hd: "graph", - tl: { - hd: "xdigit", - tl: /* [] */0 - } - } - } - } - } - } - } - } - } - } - } - } - }); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - throw { - RE_EXN_ID: Parse_error, - Error: new Error() - }; - } - throw exn; - } - if (!accept_s(":]")) { - throw { - RE_EXN_ID: Parse_error, - Error: new Error() - }; - } - let posix_class = posix_class_of_string(cls); - let re = compl$1 ? compl({ - hd: posix_class, - tl: /* [] */0 - }) : posix_class; - return { - NAME: "Set", - VAL: re - }; - } - if (!accept(/* '.' */46)) { - return { - NAME: "Char", - VAL: c - }; - } - if (i.contents === l) { - throw { - RE_EXN_ID: Parse_error, - Error: new Error() - }; - } - let c$1 = get(); - if (!accept(/* '.' */46)) { - throw { - RE_EXN_ID: Not_supported, - Error: new Error() - }; - } - if (!accept(/* ']' */93)) { - throw { - RE_EXN_ID: Parse_error, - Error: new Error() - }; - } - return { - NAME: "Char", - VAL: c$1 - }; - } - if (c !== /* '\\' */92) { - return { - NAME: "Char", - VAL: c - }; - } - let c$2 = get(); - if (c$2 >= 58) { - if (c$2 >= 123) { - return { - NAME: "Char", - VAL: c$2 - }; - } - switch (c$2) { - case 68 : - return { - NAME: "Set", - VAL: compl({ - hd: digit, - tl: /* [] */0 - }) - }; - case 83 : - return { - NAME: "Set", - VAL: compl({ - hd: space, - tl: /* [] */0 - }) - }; - case 87 : - return { - NAME: "Set", - VAL: compl({ - hd: alnum, - tl: { - hd: { - TAG: "Set", - _0: { - hd: [ - /* '_' */95, - /* '_' */95 - ], - tl: /* [] */0 - } - }, - tl: /* [] */0 - } - }) - }; - case 58 : - case 59 : - case 60 : - case 61 : - case 62 : - case 63 : - case 64 : - case 91 : - case 92 : - case 93 : - case 94 : - case 95 : - case 96 : - return { - NAME: "Char", - VAL: c$2 - }; - case 98 : - return { - NAME: "Char", - VAL: /* '\b' */8 - }; - case 100 : - return { - NAME: "Set", - VAL: digit - }; - case 110 : - return { - NAME: "Char", - VAL: /* '\n' */10 - }; - case 114 : - return { - NAME: "Char", - VAL: /* '\r' */13 - }; - case 115 : - return { - NAME: "Set", - VAL: space - }; - case 116 : - return { - NAME: "Char", - VAL: /* '\t' */9 - }; - case 119 : - return { - NAME: "Set", - VAL: alt$1({ - hd: alnum, - tl: { - hd: { - TAG: "Set", - _0: { - hd: [ - /* '_' */95, - /* '_' */95 - ], - tl: /* [] */0 - } - }, - tl: /* [] */0 - } - }) - }; - case 65 : - case 66 : - case 67 : - case 69 : - case 70 : - case 71 : - case 72 : - case 73 : - case 74 : - case 75 : - case 76 : - case 77 : - case 78 : - case 79 : - case 80 : - case 81 : - case 82 : - case 84 : - case 85 : - case 86 : - case 88 : - case 89 : - case 90 : - case 97 : - case 99 : - case 101 : - case 102 : - case 103 : - case 104 : - case 105 : - case 106 : - case 107 : - case 108 : - case 109 : - case 111 : - case 112 : - case 113 : - case 117 : - case 118 : - case 120 : - case 121 : - case 122 : - throw { - RE_EXN_ID: Parse_error, - Error: new Error() - }; - } - } else { - if (c$2 >= 48) { - throw { - RE_EXN_ID: Not_supported, - Error: new Error() - }; - } - return { - NAME: "Char", - VAL: c$2 - }; - } - }; - let bracket = _s => { - while (true) { - let s = _s; - if (s !== /* [] */0 && accept(/* ']' */93)) { - return s; - } - let match = char(); - if (match.NAME === "Char") { - let c = match.VAL; - if (accept(/* '-' */45)) { - if (accept(/* ']' */93)) { - return { - hd: { - TAG: "Set", - _0: single(c) - }, - tl: { - hd: { - TAG: "Set", - _0: { - hd: [ - /* '-' */45, - /* '-' */45 - ], - tl: /* [] */0 - } - }, - tl: s - } - }; - } - let match$1 = char(); - if (match$1.NAME !== "Char") { - return { - hd: { - TAG: "Set", - _0: single(c) - }, - tl: { - hd: { - TAG: "Set", - _0: { - hd: [ - /* '-' */45, - /* '-' */45 - ], - tl: /* [] */0 - } - }, - tl: { - hd: match$1.VAL, - tl: s - } - } - }; - } - _s = { - hd: { - TAG: "Set", - _0: seq(c, match$1.VAL) - }, - tl: s - }; - continue; - } - _s = { - hd: { - TAG: "Set", - _0: single(c) - }, - tl: s - }; - continue; - } - _s = { - hd: match.VAL, - tl: s - }; - continue; - }; - }; - let branch = () => branch$p(/* [] */0); - let comment = () => { - while (true) { - if (accept(/* ')' */41)) { - return epsilon; - } - i.contents = i.contents + 1 | 0; - continue; - }; - }; - let res = regexp$p(branch()); - if (i.contents !== l) { - throw { - RE_EXN_ID: Parse_error, - Error: new Error() - }; - } - return res; -} - -function re(flagsOpt, pat) { - let flags = flagsOpt !== undefined ? flagsOpt : /* [] */0; - let opts = List.map(x => { - if (x === "CASELESS") { - return "Caseless"; - } else if (x === "ANCHORED") { - return "Anchored"; - } else { - return "Multiline"; - } - }, flags); - let optsOpt = opts; - let opts$1 = optsOpt !== undefined ? optsOpt : /* [] */0; - let r = parse(List.memq("Multiline", opts$1), List.memq("Dollar_endonly", opts$1), List.memq("Dotall", opts$1), List.memq("Ungreedy", opts$1), pat); - let r$1 = List.memq("Anchored", opts$1) ? seq$2({ - hd: "Start", - tl: { - hd: r, - tl: /* [] */0 - } - }) : r; - if (List.memq("Caseless", opts$1)) { - return { - TAG: "No_case", - _0: r$1 - }; - } else { - return r$1; - } -} - -function exec(rex, pos, s) { - let len; - let substr = exec_internal("Re.exec", pos, len, true, rex, s); - if (typeof substr === "object") { - return substr._0; - } - if (substr === "Failed") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; -} - -let s = "a".repeat(1048575) + "b"; - -eq("File \"ocaml_re_test.res\", line 3842, characters 7-14", get(exec(compile(re(undefined, "aa?b")), undefined, s), 0), "aab"); - -Mt.from_pair_suites("Ocaml_re_test", suites.contents); - -/* Table Not a pure module */ diff --git a/jscomp/test/ocaml_re_test.res b/jscomp/test/ocaml_re_test.res deleted file mode 100644 index 39f07bb0b2..0000000000 --- a/jscomp/test/ocaml_re_test.res +++ /dev/null @@ -1,3846 +0,0 @@ -@@config({flags: ["-w", "a", "-bs-no-bin-annot"], no_export}) -let suites: ref = ref(list{}) -let test_id = ref(0) -let eq = (loc, x, y) => { - incr(test_id) - suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} -} - -module Re_cset: { - /* - RE - A regular expression library - - Copyright (C) 2001 Jerome Vouillon - email: Jerome.Vouillon@pps.jussieu.fr - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation, with - linking exception; either version 2.1 of the License, or (at - your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - - /* Character sets, represented as sorted list of intervals */ - - type c = int - type t - - let iter: (t, ~f: (c, c) => unit) => unit - - let union: (t, t) => t - let inter: (t, t) => t - let diff: (t, t) => t - let offset: (int, t) => t - - let empty: t - let single: c => t - let seq: (c, c) => t - let add: (c, t) => t - - let mem: (c, t) => bool - - type hash - let hash: t => hash - - let one_char: t => option - - let fold_right: (t, ~init: 'acc, ~f: ((c, c), 'acc) => 'acc) => 'acc - - let hash_rec: t => int - - module CSetMap: Map.S with type key = (int, t) - - let cany: t - - let csingle: char => t - - let is_empty: t => bool - - let prepend: (t, list<'a>, list<(t, list<'a>)>) => list<(t, list<'a>)> - - let pick: t => c -} = { - /* - RE - A regular expression library - - Copyright (C) 2001 Jerome Vouillon - email: Jerome.Vouillon@pps.jussieu.fr - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation, with - linking exception; either version 2.1 of the License, or (at - your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - - type c = int - type t = list<(c, c)> - - let rec union = (l, l') => - switch (l, l') { - | (_, list{}) => l - | (list{}, _) => l' - | (list{(c1, c2), ...r}, list{(c1', c2'), ...r'}) => - if c2 + 1 < c1' { - list{(c1, c2), ...union(r, l')} - } else if c2' + 1 < c1 { - list{(c1', c2'), ...union(l, r')} - } else if c2 < c2' { - union(r, list{(min(c1, c1'), c2'), ...r'}) - } else { - union(list{(min(c1, c1'), c2), ...r}, r') - } - } - - let rec inter = (l, l') => - switch (l, l') { - | (_, list{}) => list{} - | (list{}, _) => list{} - | (list{(c1, c2), ...r}, list{(c1', c2'), ...r'}) => - if c2 < c1' { - inter(r, l') - } else if c2' < c1 { - inter(l, r') - } else if c2 < c2' { - list{(max(c1, c1'), c2), ...inter(r, l')} - } else { - list{(max(c1, c1'), c2'), ...inter(l, r')} - } - } - - let rec diff = (l, l') => - switch (l, l') { - | (_, list{}) => l - | (list{}, _) => list{} - | (list{(c1, c2), ...r}, list{(c1', c2'), ...r'}) => - if c2 < c1' { - list{(c1, c2), ...diff(r, l')} - } else if c2' < c1 { - diff(l, r') - } else { - let r'' = if c2' < c2 { - list{(c2' + 1, c2), ...r} - } else { - r - } - if c1 < c1' { - list{(c1, c1' - 1), ...diff(r'', r')} - } else { - diff(r'', r') - } - } - } - - let single = c => list{(c, c)} - - let add = (c, l) => union(single(c), l) - - let seq = (c, c') => - if c <= c' { - list{(c, c')} - } else { - list{(c', c)} - } - - let rec offset = (o, l) => - switch l { - | list{} => list{} - | list{(c1, c2), ...r} => list{(c1 + o, c2 + o), ...offset(o, r)} - } - - let empty = list{} - - let rec mem = (c: int, s) => - switch s { - | list{} => false - | list{(c1, c2), ...rem} => - if c <= c2 { - c >= c1 - } else { - mem(c, rem) - } - } - - /* ** */ - - type hash = int - - let rec hash_rec = x => - switch x { - | list{} => 0 - | list{(i, j), ...r} => i + 13 * j + 257 * hash_rec(r) - } - let hash = l => land(hash_rec(l), 0x3FFFFFFF) - - /* ** */ - - /* let%ignore pp = Re_fmt.list print_one */ - - let rec iter = (t, ~f) => - switch t { - | list{} => () - | list{(x, y), ...xs} => - f(x, y) - iter(xs, ~f) - } - - let one_char = x => - switch x { - | list{(i, j)} if i == j => Some(i) - | _ => None - } - - module CSetMap = Map.Make({ - type t = (int, list<(int, int)>) - let compare = ((i, u), (j, v)) => { - let c = compare(i, j) - if c != 0 { - c - } else { - compare(u, v) - } - } - }) - - let fold_right = (t, ~init, ~f) => List.fold_right(f, t, init) - - let csingle = c => single(Char.code(c)) - - let cany = list{(0, 255)} - - let is_empty = x => - switch x { - | list{} => true - | _ => false - } - - let rec prepend = (s, x, l) => - switch (s, l) { - | (list{}, _) => l - | (_r, list{}) => list{} - | (list{(_c, c'), ...r}, list{(list{(d, _d')}, _x'), ..._r'}) if c' < d => prepend(r, x, l) - | (list{(c, c'), ...r}, list{(list{(d, d')}, x'), ...r'}) => - if c <= d { - if c' < d' { - list{ - (list{(d, c')}, \"@"(x, x')), - ...prepend(r, x, list{(list{(c' + 1, d')}, x'), ...r'}), - } - } else { - list{(list{(d, d')}, \"@"(x, x')), ...prepend(s, x, r')} - } - } else if c > d' { - list{(list{(d, d')}, x'), ...prepend(s, x, r')} - } else { - list{(list{(d, c - 1)}, x'), ...prepend(s, x, list{(list{(c, d')}, x'), ...r'})} - } - | _ => assert(false) - } - - let pick = x => - switch x { - | list{} => invalid_arg("Re_cset.pick") - | list{(x, _), ..._} => x - } -} -module Re_automata: { - /* - RE - A regular expression library - - Copyright (C) 2001 Jerome Vouillon - email: Jerome.Vouillon@pps.jussieu.fr - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation, with - linking exception; either version 2.1 of the License, or (at - your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - - /* Regular expressions */ - - @ocaml.doc(" Categories represent the various kinds of characters that can be tested - by look-ahead and look-behind operations. - - This is more restricted than Cset, but faster. -") - module Category: { - type t - let \"++": (t, t) => t - let from_char: char => t - - let inexistant: t - let letter: t - let not_letter: t - let newline: t - let lastnewline: t - let search_boundary: t - } - - type mark = int - - type sem = [#Longest | #Shortest | #First] - type rep_kind = [#Greedy | #Non_greedy] - - module Pmark: { - type t = private int - let equal: (t, t) => bool - let compare: (t, t) => int - let gen: unit => t - } - - type expr - let is_eps: expr => bool - - type ids - let create_ids: unit => ids - - let cst: (ids, Re_cset.t) => expr - let empty: ids => expr - let alt: (ids, list) => expr - let seq: (ids, sem, expr, expr) => expr - let eps: ids => expr - let rep: (ids, rep_kind, sem, expr) => expr - let mark: (ids, mark) => expr - let pmark: (ids, Pmark.t) => expr - let erase: (ids, mark, mark) => expr - let before: (ids, Category.t) => expr - let after: (ids, Category.t) => expr - - let rename: (ids, expr) => expr - - /* ** */ - - module PmarkSet: Set.S with type elt = Pmark.t - - /* States of the automata */ - - type idx = int - module Marks: { - type t = { - marks: list<(mark, idx)>, - pmarks: PmarkSet.t, - } - } - - module E: { - type t - } - - type hash - type mark_infos = array - type status = Failed | Match(mark_infos, PmarkSet.t) | Running - - module State: { - type t = { - idx: idx, - category: Category.t, - desc: list, - mutable status: option, - hash: hash, - } - let dummy: t - let create: (Category.t, expr) => t - module Table: Hashtbl.S with type key = t - } - - /* ** */ - - /* Computation of the states following a given state */ - - type working_area - let create_working_area: unit => working_area - let index_count: working_area => int - - let delta: (working_area, Category.t, Re_cset.c, State.t) => State.t - let deriv: ( - working_area, - Re_cset.t, - list<(Category.t, Re_cset.t)>, - State.t, - ) => list<(Re_cset.t, State.t)> - - /* ** */ - - let status: State.t => status -} = { - /* - RE - A regular expression library - - Copyright (C) 2001 Jerome Vouillon - email: Jerome.Vouillon@pps.jussieu.fr - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation, with - linking exception; either version 2.1 of the License, or (at - your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - - module Cset = Re_cset - - type sem = [#Longest | #Shortest | #First] - - type rep_kind = [#Greedy | #Non_greedy] - - module Category: { - type t - let equal: (t, t) => bool - let compare: (t, t) => int - - let to_int: t => int - - let intersect: (t, t) => bool - let \"++": (t, t) => t - let from_char: char => t - - let dummy: t - let inexistant: t - let letter: t - let not_letter: t - let newline: t - let lastnewline: t - let search_boundary: t - } = { - type t = int - let equal = (x: int, y: int) => x == y - let compare = (x: int, y: int) => compare(x, y) - let to_int = x => x - - let intersect = (x, y) => land(x, y) != 0 - let \"++" = (x, y) => lor(x, y) - - let dummy = -1 - let inexistant = 1 - let letter = 2 - let not_letter = 4 - let newline = 8 - let lastnewline = 16 - let search_boundary = 32 - - let from_char = x => - /* Should match [cword] definition */ - switch x { - | 'a' .. 'z' - | 'A' .. 'Z' - | '0' .. '9' - | '_' - | 'ª' - | 'µ' - | 'º' - | 'À' .. 'Ö' - | 'Ø' .. 'ö' - | 'ø' .. 'ÿ' => letter - | '\n' => \"++"(not_letter, newline) - | _ => not_letter - } - } - - type mark = int - type idx = int - - module Pmark: { - type t = private int - let equal: (t, t) => bool - let compare: (t, t) => int - let gen: unit => t - } = { - type t = int - let equal = (x: int, y: int) => x == y - let compare = (x: int, y: int) => compare(x, y) - let r = ref(0) - let gen = () => { - incr(r) - r.contents - } - } - - type rec expr = {id: int, def: def} - - and def = - | Cst(Cset.t) - | Alt(list) - | Seq(sem, expr, expr) - | Eps - | Rep(rep_kind, sem, expr) - | Mark(int) - | Erase(int, int) - | Before(Category.t) - | After(Category.t) - | Pmark(Pmark.t) - - module PmarkSet = Set.Make(Pmark) - - let hash_combine = (h, accu) => accu * 65599 + h - - module Marks = { - type t = { - marks: list<(int, int)>, - pmarks: PmarkSet.t, - } - - let empty = {marks: list{}, pmarks: PmarkSet.empty} - - let rec merge_marks_offset = (old, x) => - switch x { - | list{} => old - | list{(i, v), ...rem} => - let nw' = merge_marks_offset(List.remove_assq(i, old), rem) - if v == -2 { - nw' - } else { - list{(i, v), ...nw'} - } - } - - let merge = (old, nw) => { - marks: merge_marks_offset(old.marks, nw.marks), - pmarks: PmarkSet.union(old.pmarks, nw.pmarks), - } - - let rec hash_marks_offset = (l, accu) => - switch l { - | list{} => accu - | list{(a, i), ...r} => hash_marks_offset(r, hash_combine(a, hash_combine(i, accu))) - } - - let hash = (m, accu) => hash_marks_offset(m.marks, hash_combine(Hashtbl.hash(m.pmarks), accu)) - - let rec marks_set_idx = (idx, x) => - switch x { - | list{(a, -1), ...rem} => list{(a, idx), ...marks_set_idx(idx, rem)} - | marks => marks - } - - let marks_set_idx = (marks, idx) => {...marks, marks: marks_set_idx(idx, marks.marks)} - } - - /* ** */ - - /* let%ignore rec pp ch e = - let open Re_fmt in - match e.def with - Cst l -> - sexp ch "cst" Cset.pp l; - | Alt l -> - sexp ch "alt" (list pp) l - | Seq (k, e, e') -> - sexp ch "seq" (triple pp_sem pp pp) (k, e, e') - | Eps -> - str ch "eps" - | Rep (_rk, k, e) -> - sexp ch "rep" (pair pp_sem pp) (k, e) - | Mark i -> - sexp ch "mark" int i - | Pmark i -> - sexp ch "pmark" int (i :> int) - | Erase (b, e) -> - sexp ch "erase" (pair int int) (b, e) - | Before c -> - sexp ch "before" Category.pp c - | After c -> - sexp ch "after" Category.pp c - - */ - /* ** */ - - let rec first = (f, x) => - switch x { - | list{} => None - | list{x, ...r} => - switch f(x) { - | None => first(f, r) - | Some(_) as res => res - } - } - - /* ** */ - - type ids = ref - let create_ids = () => ref(0) - - let eps_expr = {id: 0, def: Eps} - - let mk_expr = (ids, def) => { - incr(ids) - {id: ids.contents, def} - } - - let empty = ids => mk_expr(ids, Alt(list{})) - - let cst = (ids, s) => - if Re_cset.is_empty(s) { - empty(ids) - } else { - mk_expr(ids, Cst(s)) - } - - let alt = (ids, x) => - switch x { - | list{} => empty(ids) - | list{c} => c - | l => mk_expr(ids, Alt(l)) - } - - let seq = (ids, kind, x, y) => - switch (x.def, y.def) { - | (Alt(list{}), _) => x - | (_, Alt(list{})) => y - | (Eps, _) => y - | (_, Eps) if kind == #First => x - | _ => mk_expr(ids, Seq(kind, x, y)) - } - - let is_eps = expr => - switch expr.def { - | Eps => true - | _ => false - } - - let eps = ids => mk_expr(ids, Eps) - - let rep = (ids, kind, sem, x) => mk_expr(ids, Rep(kind, sem, x)) - - let mark = (ids, m) => mk_expr(ids, Mark(m)) - - let pmark = (ids, i) => mk_expr(ids, Pmark(i)) - - let erase = (ids, m, m') => mk_expr(ids, Erase(m, m')) - - let before = (ids, c) => mk_expr(ids, Before(c)) - - let after = (ids, c) => mk_expr(ids, After(c)) - - /* ** */ - - let rec rename = (ids, x) => - switch x.def { - | Cst(_) | Eps | Mark(_) | Pmark(_) | Erase(_) | Before(_) | After(_) => mk_expr(ids, x.def) - | Alt(l) => mk_expr(ids, Alt(List.map(rename(ids, ...), l))) - | Seq(k, y, z) => mk_expr(ids, Seq(k, rename(ids, y), rename(ids, z))) - | Rep(g, k, y) => mk_expr(ids, Rep(g, k, rename(ids, y))) - } - - /* ** */ - - type hash = int - type mark_infos = array - type status = Failed | Match(mark_infos, PmarkSet.t) | Running - - module E = { - type rec t = - | TSeq(list, expr, sem) - | TExp(Marks.t, expr) - | TMatch(Marks.t) - - let rec equal = (l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => true - | (list{TSeq(l1', e1, _), ...r1}, list{TSeq(l2', e2, _), ...r2}) => - e1.id == e2.id && (equal(l1', l2') && equal(r1, r2)) - | (list{TExp(marks1, e1), ...r1}, list{TExp(marks2, e2), ...r2}) => - e1.id == e2.id && (marks1 == marks2 && equal(r1, r2)) - | (list{TMatch(marks1), ...r1}, list{TMatch(marks2), ...r2}) => - marks1 == marks2 && equal(r1, r2) - | _ => false - } - - let rec hash = (l, accu) => - switch l { - | list{} => accu - | list{TSeq(l', e, _), ...r} => - hash(r, hash_combine(0x172a1bce, hash_combine(e.id, hash(l', accu)))) - | list{TExp(marks, e), ...r} => - hash(r, hash_combine(0x2b4c0d77, hash_combine(e.id, Marks.hash(marks, accu)))) - | list{TMatch(marks), ...r} => hash(r, hash_combine(0x1c205ad5, Marks.hash(marks, accu))) - } - - let texp = (marks, x) => TExp(marks, x) - - let tseq = (kind, x, y, rem) => - switch x { - | list{} => rem - | list{TExp(marks, {def: Eps, _})} => list{TExp(marks, y), ...rem} - | _ => list{TSeq(x, y, kind), ...rem} - } - } - - module State = { - type t = { - idx: idx, - category: Category.t, - desc: list, - mutable status: option, - hash: hash, - } - - let dummy = { - idx: -1, - category: Category.dummy, - desc: list{}, - status: None, - hash: -1, - } - - let hash = (idx, cat, desc) => - land(E.hash(desc, hash_combine(idx, hash_combine(Category.to_int(cat), 0))), 0x3FFFFFFF) - - let mk = (idx, cat, desc) => { - idx, - category: cat, - desc, - status: None, - hash: hash(idx, cat, desc), - } - - let create = (cat, e) => mk(0, cat, list{E.TExp(Marks.empty, e)}) - - let equal = (x, y) => - (x.hash: int) == y.hash && - ((x.idx: int) == y.idx && - (Category.equal(x.category, y.category) && E.equal(x.desc, y.desc))) - - let compare = (x, y) => { - let c = compare((x.hash: int), y.hash) - if c != 0 { - c - } else { - let c = Category.compare(x.category, y.category) - if c != 0 { - c - } else { - compare(x.desc, y.desc) - } - } - } - - type t' = t - module Table = Hashtbl.Make({ - type t = t' - let equal = equal - let hash = t => t.hash - }) - } - - /* *** Find a free index *** */ - - type working_area = ref> - - let create_working_area = () => ref([false]) - - let index_count = w => Array.length(w.contents) - - let reset_table = a => Array.fill(a, 0, Array.length(a), false) - - let rec mark_used_indices = tbl => List.iter(x => - switch x { - | E.TSeq(l, _, _) => mark_used_indices(tbl)(l) - | E.TExp(marks, _) - | E.TMatch(marks) => - List.iter(((_, i)) => - if i >= 0 { - tbl[i] = true - } - , marks.Marks.marks) - } - , ...) - - let rec find_free = (tbl, idx, len) => - if idx == len || !tbl[idx] { - idx - } else { - find_free(tbl, idx + 1, len) - } - - let free_index = (tbl_ref, l) => { - let tbl = tbl_ref.contents - reset_table(tbl) - mark_used_indices(tbl)(l) - let len = Array.length(tbl) - let idx = find_free(tbl, 0, len) - if idx == len { - tbl_ref := Array.make(2 * len, false) - } - idx - } - - /* *** Computation of the next state *** */ - - let remove_matches = List.filter(x => - switch x { - | E.TMatch(_) => false - | _ => true - } - , ...) - - let rec split_at_match_rec = (l', x) => - switch x { - | list{} => assert(false) - | list{E.TMatch(_), ...r} => (List.rev(l'), remove_matches(r)) - | list{x, ...r} => split_at_match_rec(list{x, ...l'}, r) - } - - let split_at_match = l => split_at_match_rec(list{}, l) - - let rec remove_duplicates = (prev, l, y) => - switch l { - | list{} => (list{}, prev) - | list{E.TMatch(_) as x, ..._} => /* Truncate after first match */ - (list{x}, prev) - | list{E.TSeq(l', x, kind), ...r} => - let (l'', prev') = remove_duplicates(prev, l', x) - let (r', prev'') = remove_duplicates(prev', r, y) - (E.tseq(kind, l'', x, r'), prev'') - | list{E.TExp(_marks, {def: Eps, _}) as e, ...r} => - if List.memq(y.id, prev) { - remove_duplicates(prev, r, y) - } else { - let (r', prev') = remove_duplicates(list{y.id, ...prev}, r, y) - (list{e, ...r'}, prev') - } - | list{E.TExp(_marks, x) as e, ...r} => - if List.memq(x.id, prev) { - remove_duplicates(prev, r, y) - } else { - let (r', prev') = remove_duplicates(list{x.id, ...prev}, r, y) - (list{e, ...r'}, prev') - } - } - - let rec set_idx = (idx, x) => - switch x { - | list{} => list{} - | list{E.TMatch(marks), ...r} => - list{E.TMatch(Marks.marks_set_idx(marks, idx)), ...set_idx(idx, r)} - | list{E.TSeq(l', x, kind), ...r} => list{E.TSeq(set_idx(idx, l'), x, kind), ...set_idx(idx, r)} - | list{E.TExp(marks, x), ...r} => - list{E.TExp(Marks.marks_set_idx(marks, idx), x), ...set_idx(idx, r)} - } - - let filter_marks = (b, e, marks) => { - ...marks, - Marks.marks: List.filter(((i, _)) => i < b || i > e, marks.Marks.marks), - } - - let rec delta_1 = (marks, c, ~next_cat, ~prev_cat, x, rem) => - switch x.def { - | Cst(s) => - if Cset.mem(c, s) { - list{E.texp(marks, eps_expr), ...rem} - } else { - rem - } - | Alt(l) => delta_2(marks, c, ~next_cat, ~prev_cat, l, rem) - | Seq(kind, y, z) => - let y' = delta_1(marks, c, ~next_cat, ~prev_cat, y, list{}) - delta_seq(c, ~next_cat, ~prev_cat, kind, y', z, rem) - | Rep(rep_kind, kind, y) => - let y' = delta_1(marks, c, ~next_cat, ~prev_cat, y, list{}) - let (y'', marks') = switch first(x => - switch x { - | E.TMatch(marks) => Some(marks) - | _ => None - } - , y') { - | None => (y', marks) - | Some(marks') => (remove_matches(y'), marks') - } - - switch rep_kind { - | #Greedy => E.tseq(kind, y'', x, list{E.TMatch(marks'), ...rem}) - | #Non_greedy => list{E.TMatch(marks), ...E.tseq(kind, y'', x, rem)} - } - | Eps => list{E.TMatch(marks), ...rem} - | Mark(i) => - let marks = {...marks, Marks.marks: list{(i, -1), ...List.remove_assq(i, marks.Marks.marks)}} - list{E.TMatch(marks), ...rem} - | Pmark(i) => - let marks = {...marks, Marks.pmarks: PmarkSet.add(i, marks.Marks.pmarks)} - list{E.TMatch(marks), ...rem} - | Erase(b, e) => list{E.TMatch(filter_marks(b, e, marks)), ...rem} - | Before(cat'') => - if Category.intersect(next_cat, cat'') { - list{E.TMatch(marks), ...rem} - } else { - rem - } - | After(cat'') => - if Category.intersect(prev_cat, cat'') { - list{E.TMatch(marks), ...rem} - } else { - rem - } - } - - and delta_2 = (marks, c, ~next_cat, ~prev_cat, l, rem) => - switch l { - | list{} => rem - | list{y, ...r} => - delta_1(marks, c, ~next_cat, ~prev_cat, y, delta_2(marks, c, ~next_cat, ~prev_cat, r, rem)) - } - - and delta_seq = (c, ~next_cat, ~prev_cat, kind, y, z, rem) => - switch first(x => - switch x { - | E.TMatch(marks) => Some(marks) - | _ => None - } - , y) { - | None => E.tseq(kind, y, z, rem) - | Some(marks) => - switch kind { - | #Longest => - E.tseq(kind, remove_matches(y), z, delta_1(marks, c, ~next_cat, ~prev_cat, z, rem)) - | #Shortest => - delta_1(marks, c, ~next_cat, ~prev_cat, z, E.tseq(kind, remove_matches(y), z, rem)) - | #First => - let (y', y'') = split_at_match(y) - E.tseq(kind, y', z, delta_1(marks, c, ~next_cat, ~prev_cat, z, E.tseq(kind, y'', z, rem))) - } - } - - let rec delta_3 = (c, ~next_cat, ~prev_cat, x, rem) => - switch x { - | E.TSeq(y, z, kind) => - let y' = delta_4(c, ~next_cat, ~prev_cat, y, list{}) - delta_seq(c, ~next_cat, ~prev_cat, kind, y', z, rem) - | E.TExp(marks, e) => delta_1(marks, c, ~next_cat, ~prev_cat, e, rem) - | E.TMatch(_) => list{x, ...rem} - } - - and delta_4 = (c, ~next_cat, ~prev_cat, l, rem) => - switch l { - | list{} => rem - | list{y, ...r} => delta_3(c, ~next_cat, ~prev_cat, y, delta_4(c, ~next_cat, ~prev_cat, r, rem)) - } - - let delta = (tbl_ref, next_cat, char, st) => { - let prev_cat = st.State.category - let (expr', _) = remove_duplicates( - list{}, - delta_4(char, ~next_cat, ~prev_cat, st.State.desc, list{}), - eps_expr, - ) - let idx = free_index(tbl_ref, expr') - let expr'' = set_idx(idx, expr') - State.mk(idx, next_cat, expr'') - } - - /* ** */ - - let rec red_tr = x => - switch x { - | (list{} | list{_}) as l => l - | list{(s1, st1) as tr1, (s2, st2) as tr2, ...rem} => - if State.equal(st1, st2) { - red_tr(list{(Cset.union(s1, s2), st1), ...rem}) - } else { - list{tr1, ...red_tr(list{tr2, ...rem})} - } - } - - let simpl_tr = l => - List.sort( - ((s1, _), (s2, _)) => compare(s1, s2), - red_tr(List.sort(((_, st1), (_, st2)) => State.compare(st1, st2), l)), - ) - - /* ** */ - - let prepend_deriv = List.fold_right(((s, x), l) => Cset.prepend(s, x, l), ...) - - let rec restrict = (s, x) => - switch x { - | list{} => list{} - | list{(s', x'), ...rem} => - let s'' = Cset.inter(s, s') - if Cset.is_empty(s'') { - restrict(s, rem) - } else { - list{(s'', x'), ...restrict(s, rem)} - } - } - - let rec remove_marks = (b, e, rem) => - if b > e { - rem - } else { - remove_marks(b, e - 1, list{(e, -2), ...rem}) - } - - let rec prepend_marks_expr = (m, x) => - switch x { - | E.TSeq(l, e', s) => E.TSeq(prepend_marks_expr_lst(m, l), e', s) - | E.TExp(m', e') => E.TExp(Marks.merge(m, m'), e') - | E.TMatch(m') => E.TMatch(Marks.merge(m, m')) - } - - and prepend_marks_expr_lst = (m, l) => List.map(prepend_marks_expr(m, ...), l) - - let prepend_marks = m => List.map(((s, x)) => (s, prepend_marks_expr_lst(m, x)), ...) - - let rec deriv_1 = (all_chars, categories, marks, cat, x, rem) => - switch x.def { - | Cst(s) => Cset.prepend(s, list{E.texp(marks, eps_expr)}, rem) - | Alt(l) => deriv_2(all_chars, categories, marks, cat, l, rem) - | Seq(kind, y, z) => - let y' = deriv_1(all_chars, categories, marks, cat, y, list{(all_chars, list{})}) - deriv_seq(all_chars, categories, cat, kind, y', z, rem) - | Rep(rep_kind, kind, y) => - let y' = deriv_1(all_chars, categories, marks, cat, y, list{(all_chars, list{})}) - List.fold_right(((s, z), rem) => { - let (z', marks') = switch first(x => - switch x { - | E.TMatch(marks) => Some(marks) - | _ => None - } - , z) { - | None => (z, marks) - | Some(marks') => (remove_matches(z), marks') - } - - Cset.prepend( - s, - switch rep_kind { - | #Greedy => E.tseq(kind, z', x, list{E.TMatch(marks')}) - | #Non_greedy => list{E.TMatch(marks), ...E.tseq(kind, z', x, list{})} - }, - rem, - ) - }, y', rem) - | Eps => Cset.prepend(all_chars, list{E.TMatch(marks)}, rem) - | Mark(i) => - Cset.prepend( - all_chars, - list{ - E.TMatch({ - ...marks, - Marks.marks: list{(i, -1), ...List.remove_assq(i, marks.Marks.marks)}, - }), - }, - rem, - ) - | Pmark(_) => Cset.prepend(all_chars, list{E.TMatch(marks)}, rem) - | Erase(b, e) => - Cset.prepend( - all_chars, - list{ - E.TMatch({ - ...marks, - Marks.marks: remove_marks(b, e, filter_marks(b, e, marks).Marks.marks), - }), - }, - rem, - ) - | Before(cat') => Cset.prepend(List.assq(cat', categories), list{E.TMatch(marks)}, rem) - | After(cat') => - if Category.intersect(cat, cat') { - Cset.prepend(all_chars, list{E.TMatch(marks)}, rem) - } else { - rem - } - } - - and deriv_2 = (all_chars, categories, marks, cat, l, rem) => - switch l { - | list{} => rem - | list{y, ...r} => - deriv_1( - all_chars, - categories, - marks, - cat, - y, - deriv_2(all_chars, categories, marks, cat, r, rem), - ) - } - - and deriv_seq = (all_chars, categories, cat, kind, y, z, rem) => - if List.exists(((_s, xl)) => List.exists(x => - switch x { - | E.TMatch(_) => true - | _ => false - } - , xl), y) { - let z' = deriv_1(all_chars, categories, Marks.empty, cat, z, list{(all_chars, list{})}) - List.fold_right(((s, y), rem) => - switch first(x => - switch x { - | E.TMatch(marks) => Some(marks) - | _ => None - } - , y) { - | None => Cset.prepend(s, E.tseq(kind, y, z, list{}), rem) - | Some(marks) => - let z'' = prepend_marks(marks)(z') - switch kind { - | #Longest => - Cset.prepend( - s, - E.tseq(kind, remove_matches(y), z, list{}), - prepend_deriv(restrict(s, z''), rem), - ) - | #Shortest => - prepend_deriv( - restrict(s, z''), - Cset.prepend(s, E.tseq(kind, remove_matches(y), z, list{}), rem), - ) - | #First => - let (y', y'') = split_at_match(y) - Cset.prepend( - s, - E.tseq(kind, y', z, list{}), - prepend_deriv(restrict(s, z''), Cset.prepend(s, E.tseq(kind, y'', z, list{}), rem)), - ) - } - } - , y, rem) - } else { - List.fold_right(((s, xl), rem) => Cset.prepend(s, E.tseq(kind, xl, z, list{}), rem), y, rem) - } - - let rec deriv_3 = (all_chars, categories, cat, x, rem) => - switch x { - | E.TSeq(y, z, kind) => - let y' = deriv_4(all_chars, categories, cat, y, list{(all_chars, list{})}) - deriv_seq(all_chars, categories, cat, kind, y', z, rem) - | E.TExp(marks, e) => deriv_1(all_chars, categories, marks, cat, e, rem) - | E.TMatch(_) => Cset.prepend(all_chars, list{x}, rem) - } - - and deriv_4 = (all_chars, categories, cat, l, rem) => - switch l { - | list{} => rem - | list{y, ...r} => - deriv_3(all_chars, categories, cat, y, deriv_4(all_chars, categories, cat, r, rem)) - } - - let deriv = (tbl_ref, all_chars, categories, st) => { - let der = deriv_4( - all_chars, - categories, - st.State.category, - st.State.desc, - list{(all_chars, list{})}, - ) - simpl_tr(List.fold_right(((s, expr), rem) => { - let (expr', _) = remove_duplicates(list{}, expr, eps_expr) - let idx = free_index(tbl_ref, expr') - let expr'' = set_idx(idx, expr') - List.fold_right(((cat', s'), rem) => { - let s'' = Cset.inter(s, s') - if Cset.is_empty(s'') { - rem - } else { - list{(s'', State.mk(idx, cat', expr'')), ...rem} - } - }, categories, rem) - }, der, list{})) - } - - /* ** */ - - let flatten_match = m => { - let ma = List.fold_left((ma, (i, _)) => max(ma, i), -1, m) - let res = Array.make(ma + 1, -1) - List.iter(((i, v)) => res[i] = v, m) - res - } - - let status = s => - switch s.State.status { - | Some(st) => st - | None => - let st = switch s.State.desc { - | list{} => Failed - | list{E.TMatch(m), ..._} => Match(flatten_match(m.Marks.marks), m.Marks.pmarks) - | _ => Running - } - - s.State.status = Some(st) - st - } -} -module Re: { - @@ocaml.text( - /* - RE - A regular expression library - - Copyright (C) 2001 Jerome Vouillon - email: Jerome.Vouillon@pps.jussieu.fr - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation, with - linking exception; either version 2.1 of the License, or (at - your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - - " Module [Re]: regular expressions commons " - ) - - @ocaml.doc(" Regular expression ") - type t - - @ocaml.doc(" Compiled regular expression ") - type re - - @ocaml.doc(" Information about groups in a match. ") - type groups - - @@ocaml.text(" {2 Compilation and execution of a regular expression} ") - - @ocaml.doc(" Compile a regular expression into an executable version that can be - used to match strings, e.g. with {!exec}. ") - let compile: t => re - - @ocaml.doc(" [exec re str] matches [str] against the compiled expression [re], - and returns the matched groups if any. - @param pos optional beginning of the string (default 0) - @param len length of the substring of [str] that can be matched (default [-1], - meaning to the end of the string - @raise Not_found if the regular expression can't be found in [str] -") - let exec: ( - ~pos: int=? /* Default: 0 */, - ~len: int=? /* Default: -1 (until end of string) */, - re, - string, - ) => groups - - @ocaml.doc(" Similar to {!exec}, but returns an option instead of using an exception. ") - let exec_opt: ( - ~pos: int=? /* Default: 0 */, - ~len: int=? /* Default: -1 (until end of string) */, - re, - string, - ) => option - - @ocaml.doc(" Similar to {!exec}, but returns [true] if the expression matches, - and [false] if it doesn't ") - let execp: ( - ~pos: int=? /* Default: 0 */, - ~len: int=? /* Default: -1 (until end of string) */, - re, - string, - ) => bool - - @ocaml.doc(" More detailed version of {!exec_p} ") - let exec_partial: ( - ~pos: int=? /* Default: 0 */, - ~len: int=? /* Default: -1 (until end of string) */, - re, - string, - ) => [#Full | #Partial | #Mismatch] - - @ocaml.doc(" Manipulate matching groups. ") - module Group: { - @ocaml.doc(" Information about groups in a match. ") - type t = groups - - @ocaml.doc(" Raise [Not_found] if the group did not match ") - let get: (t, int) => string - - @ocaml.doc(" Raise [Not_found] if the group did not match ") - let offset: (t, int) => (int, int) - - @ocaml.doc(" Return the start of the match. Raise [Not_found] if the group did not match. ") - let start: (t, int) => int - - @ocaml.doc(" Return the end of the match. Raise [Not_found] if the group did not match. ") - let stop: (t, int) => int - - @ocaml.doc(" Return the empty string for each group which did not match ") - let all: t => array - - @ocaml.doc(" Return [(-1,-1)] for each group which did not match ") - let all_offset: t => array<(int, int)> - - @ocaml.doc(" Test whether a group matched ") - let test: (t, int) => bool - - @ocaml.doc(" Returns the total number of groups defined - matched or not. - This function is experimental. ") - let nb_groups: t => int - - /* val pp : Format.formatter -> t -> unit */ - } - - @ocaml.doc(" Marks ") - module Mark: { - @ocaml.doc(" Mark id ") - type t - - @ocaml.doc(" Tell if a mark was matched. ") - let test: (Group.t, t) => bool - - module Set: Set.S with type elt = t - - @ocaml.doc(" Return all the mark matched. ") - let all: Group.t => Set.t - - let equal: (t, t) => bool - let compare: (t, t) => int - } - - @@ocaml.text(" {2 High Level Operations} ") - - type gen<'a> = unit => option<'a> - - @ocaml.doc(" Repeatedly calls {!exec} on the given string, starting at given - position and length.") - let all: (~pos: int=?, ~len: int=?, re, string) => list - - @ocaml.doc(" Same as {!all} but returns a generator ") - let all_gen: (~pos: int=?, ~len: int=?, re, string) => gen - - @ocaml.doc(" Same as {!all}, but extracts the matched substring rather than - returning the whole group. This basically iterates over matched - strings ") - let matches: (~pos: int=?, ~len: int=?, re, string) => list - - @ocaml.doc(" Same as {!matches}, but returns a generator. ") - let matches_gen: (~pos: int=?, ~len: int=?, re, string) => gen - - @ocaml.doc(" [split re s] splits [s] into chunks separated by [re]. It yields - the chunks themselves, not the separator. For instance - this can be used with a whitespace-matching re such as [\"[\t ]+\"]. ") - let split: (~pos: int=?, ~len: int=?, re, string) => list - - let split_gen: (~pos: int=?, ~len: int=?, re, string) => gen - - type split_token = [ - | @ocaml.doc(" Text between delimiters ") #Text(string) - | @ocaml.doc(" Delimiter ") #Delim(Group.t) - ] - - let split_full: (~pos: int=?, ~len: int=?, re, string) => list - - let split_full_gen: (~pos: int=?, ~len: int=?, re, string) => gen - - @ocaml.doc(" [replace ~all re ~f s] iterates on [s], and replaces every occurrence - of [re] with [f substring] where [substring] is the current match. - If [all = false], then only the first occurrence of [re] is replaced. ") - let replace: ( - ~pos: int=?, - ~len: int=?, - ~all: bool=?, - re, - ~f: Group.t => string /* how to replace */, - string, - ) => string - - @ocaml.doc(" [replace_string ~all re ~by s] iterates on [s], and replaces every - occurrence of [re] with [by]. If [all = false], then only the first - occurrence of [re] is replaced. ") - let replace_string: (~pos: int=?, ~len: int=?, ~all: bool=?, re, ~by: string, string) => string - - @@ocaml.text(" {2 String expressions (literal match)} ") - - let str: string => t - let char: char => t - - @@ocaml.text(" {2 Basic operations on regular expressions} ") - - @ocaml.doc(" Alternative ") - let alt: list => t - - @ocaml.doc(" Sequence ") - let seq: list => t - - @ocaml.doc(" Match nothing ") - let empty: t - - @ocaml.doc(" Empty word ") - let epsilon: t - - @ocaml.doc(" 0 or more matches ") - let rep: t => t - - @ocaml.doc(" 1 or more matches ") - let rep1: t => t - - @ocaml.doc(" [repn re i j] matches [re] at least [i] times - and at most [j] times, bounds included. - [j = None] means no upper bound. -") - let repn: (t, int, option) => t - - @ocaml.doc(" 0 or 1 matches ") - let opt: t => t - - @@ocaml.text(" {2 String, line, word} ") - - @ocaml.doc(" Beginning of line ") - let bol: t - - @ocaml.doc(" End of line ") - let eol: t - - @ocaml.doc(" Beginning of word ") - let bow: t - - @ocaml.doc(" End of word ") - let eow: t - - @ocaml.doc(" Beginning of string ") - let bos: t - - @ocaml.doc(" End of string ") - let eos: t - - @ocaml.doc(" Last end of line or end of string ") - let leol: t - - @ocaml.doc(" Initial position ") - let start: t - - @ocaml.doc(" Final position ") - let stop: t - - @ocaml.doc(" Word ") - let word: t => t - - @ocaml.doc(" Not at a word boundary ") - let not_boundary: t - - @ocaml.doc(" Only matches the whole string ") - let whole_string: t => t - - @@ocaml.text(" {2 Match semantics} ") - - @ocaml.doc(" Longest match ") - let longest: t => t - - @ocaml.doc(" Shortest match ") - let shortest: t => t - - @ocaml.doc(" First match ") - let first: t => t - - @@ocaml.text(" {2 Repeated match modifiers} ") - - @ocaml.doc(" Greedy ") - let greedy: t => t - - @ocaml.doc(" Non-greedy ") - let non_greedy: t => t - - @@ocaml.text(" {2 Groups (or submatches)} ") - - @ocaml.doc(" Delimit a group ") - let group: t => t - - @ocaml.doc(" Remove all groups ") - let no_group: t => t - - @ocaml.doc(" when matching against [nest e], only the group matching in the - last match of e will be considered as matching ") - let nest: t => t - - @ocaml.doc(" Mark a regexp. the markid can then be used to know if this regexp was used. ") - let mark: t => (Mark.t, t) - - @@ocaml.text(" {2 Character sets} ") - - @ocaml.doc(" Any character of the string ") - let set: string => t - - @ocaml.doc(" Character ranges ") - let rg: (char, char) => t - - @ocaml.doc(" Intersection of character sets ") - let inter: list => t - - @ocaml.doc(" Difference of character sets ") - let diff: (t, t) => t - - @ocaml.doc(" Complement of union ") - let compl: list => t - - @@ocaml.text(" {2 Predefined character sets} ") - - @ocaml.doc(" Any character ") - let any: t - - @ocaml.doc(" Any character but a newline ") - let notnl: t - - let alnum: t - let wordc: t - let alpha: t - let ascii: t - let blank: t - let cntrl: t - let digit: t - let graph: t - let lower: t - let print: t - let punct: t - let space: t - let upper: t - let xdigit: t - - @@ocaml.text(" {2 Case modifiers} ") - - @ocaml.doc(" Case sensitive matching ") - let case: t => t - - @ocaml.doc(" Case insensitive matching ") - let no_case: t => t - - @@ocaml.text( - /* ** */ - - " {2 Internal debugging} " - ) - - @@ocaml.text( - /* val pp : Format.formatter -> t -> unit */ - - /* val pp_re : Format.formatter -> re -> unit */ - - " Alias for {!pp_re}. Deprecated " - ) - @@ocaml.text( - /* val print_re : Format.formatter -> re -> unit */ - - " {2 Experimental functions}. " - ) - - @ocaml.doc(" [witness r] generates a string [s] such that [execp (compile r) s] is - true ") - let witness: t => string - - @@ocaml.text(" {2 Deprecated functions} ") - - @ocaml.doc(" Alias for {!Group.t}. Deprecated ") - type substrings = Group.t - - @ocaml.doc(" Same as {!Group.get}. Deprecated ") - let get: (Group.t, int) => string - - @ocaml.doc(" Same as {!Group.offset}. Deprecated ") - let get_ofs: (Group.t, int) => (int, int) - - @ocaml.doc(" Same as {!Group.all}. Deprecated ") - let get_all: Group.t => array - - @ocaml.doc(" Same as {!Group.all_offset}. Deprecated ") - let get_all_ofs: Group.t => array<(int, int)> - - @ocaml.doc(" Same as {!Group.test}. Deprecated ") - let test: (Group.t, int) => bool - - @ocaml.doc(" Alias for {!Mark.t}. Deprecated ") - type markid = Mark.t - - @ocaml.doc(" Same as {!Mark.test}. Deprecated ") - let marked: (Group.t, Mark.t) => bool - - @ocaml.doc(" Same as {!Mark.all}. Deprecated ") - let mark_set: Group.t => Mark.Set.t -} = { - /* - RE - A regular expression library - - Copyright (C) 2001 Jerome Vouillon - email: Jerome.Vouillon@pps.jussieu.fr - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation, with - linking exception; either version 2.1 of the License, or (at - your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - - module Cset = Re_cset - module Automata = Re_automata - module MarkSet = Automata.PmarkSet - module Category = Automata.Category - - let rec iter = (n, f, v) => - if n == 0 { - v - } else { - iter(n - 1, f, f(v)) - } - - /* ** */ - - let unknown = -2 - let break = -3 - - /* Result of a successful match. */ - type groups = { - s: string, - /* Input string. Matched strings are substrings of s */ - marks: Automata.mark_infos, - /* Mapping from group indices to positions in gpos. group i has positions 2*i - - 1, 2*i + 1 in gpos. If the group wasn't matched, then its corresponding - values in marks will be -1,-1 */ - pmarks: MarkSet.t, - /* Marks positions. i.e. those marks created with Re.marks */ - gpos: array, - /* Group positions. Adjacent elements are (start, stop) of group match. - indexed by the values in marks. So group i in an re would be the substring: - - start = t.gpos.(marks.(2*i)) - 1 - stop = t.gpos.(marks.(2*i + 1)) - 1 */ - gcount: int, - /* Number of groups the regular expression contains. Matched or not */ - } - - type match_info = - | Match(groups) - | Failed - | Running - - type rec state = { - idx: int, - /* Index of the current position in the position table. - Not yet computed transitions point to a dummy state where - [idx] is set to [unknown]; - If [idx] is set to [break] for states that either always - succeed or always fail. */ - real_idx: int, - /* The real index, in case [idx] is set to [break] */ - next: array, - /* Transition table, indexed by color */ - mutable final: list<(Category.t, (Automata.idx, Automata.status))>, - /* Mapping from the category of the next character to - - the index where the next position should be saved - - possibly, the list of marks (and the corresponding indices) - corresponding to the best match */ - desc: Automata.State.t, - /* Description of this state of the automata */ - } - - /* Automata (compiled regular expression) */ - type re = { - initial: Automata.expr, - /* The whole regular expression */ - mutable initial_states: list<(Category.t, state)>, - /* Initial states, indexed by initial category */ - cols: Bytes.t, - /* Color table */ - col_repr: Bytes.t, - /* Table from colors to one character of this color */ - ncol: int, - /* Number of colors. */ - lnl: int, - /* Color of the last newline */ - tbl: Automata.working_area, - /* Temporary table used to compute the first available index - when computing a new state */ - states: Automata.State.Table.t, - /* States of the deterministic automata */ - group_count: int, - /* Number of groups in the regular expression */ - } - - /* let print_re = pp_re */ - - /* Information used during matching */ - type info = { - re: re, - /* The automata */ - i_cols: Bytes.t, - /* Color table ([x.i_cols = x.re.cols]) - Shortcut used for performance reasons */ - mutable positions: array, - /* Array of mark positions - The mark are off by one for performance reasons */ - pos: int, - /* Position where the match is started */ - last: int, - /* Position where the match should stop */ - } - - /* ** */ - - let category = (re, c) => - if c == -1 { - Category.inexistant - } /* Special category for the last newline */ - else if c == re.lnl { - open Category - \"++"(\"++"(lastnewline, newline), not_letter) - } else { - Category.from_char(Bytes.get(re.col_repr, c)) - } - - /* ** */ - - let dummy_next = [] - - let unknown_state = { - idx: unknown, - real_idx: 0, - next: dummy_next, - final: list{}, - desc: Automata.State.dummy, - } - - let mk_state = (ncol, desc) => { - let break_state = switch Automata.status(desc) { - | Automata.Running => false - | Automata.Failed - | Automata.Match(_) => true - } - - { - idx: if break_state { - break - } else { - desc.Automata.State.idx - }, - real_idx: desc.Automata.State.idx, - next: if break_state { - dummy_next - } else { - Array.make(ncol, unknown_state) - }, - final: list{}, - desc, - } - } - - let find_state = (re, desc) => - try Automata.State.Table.find(re.states, desc) catch { - | Not_found => - let st = mk_state(re.ncol, desc) - Automata.State.Table.add(re.states, desc, st) - st - } - - /* *** Match with marks *** */ - - let delta = (info, cat, c, st) => { - let desc = Automata.delta(info.re.tbl, cat, c, st.desc) - let len = Array.length(info.positions) - if desc.Automata.State.idx == len && len > 0 { - let pos = info.positions - info.positions = Array.make(2 * len, 0) - Array.blit(pos, 0, info.positions, 0, len) - } - desc - } - - let validate = (info, s: string, pos, st) => { - let c = Char.code(Bytes.get(info.i_cols, Char.code(String.get(s, pos)))) - let cat = category(info.re, c) - let desc' = delta(info, cat, c, st) - let st' = find_state(info.re, desc') - st.next[c] = st' - } - - /* -let rec loop info s pos st = - if pos < info.last then - let st' = st.next.(Char.code info.i_cols.[Char.code s.[pos]]) in - let idx = st'.idx in - if idx >= 0 then begin - info.positions.(idx) <- pos; - loop info s (pos + 1) st' - end else if idx = break then begin - info.positions.(st'.real_idx) <- pos; - st' - end else begin (* Unknown *) - validate info s pos st; - loop info s pos st - end - else - st -*/ - - let rec loop = (info, s: string, pos, st) => - if pos < info.last { - let st' = st.next[Char.code(Bytes.get(info.i_cols, Char.code(String.get(s, pos))))] - loop2(info, s, pos, st, st') - } else { - st - } - - and loop2 = (info, s, pos, st, st') => - if st'.idx >= 0 { - let pos = pos + 1 - if pos < info.last { - /* It is important to place these reads before the write */ - /* But then, we don't have enough registers left to store the - right position. So, we store the position plus one. */ - let st'' = st'.next[Char.code(Bytes.get(info.i_cols, Char.code(String.get(s, pos))))] - info.positions[st'.idx] = pos - loop2(info, s, pos, st', st'') - } else { - info.positions[st'.idx] = pos - st' - } - } else if st'.idx == break { - info.positions[st'.real_idx] = pos + 1 - st' - } else { - /* Unknown */ - validate(info, s, pos, st) - loop(info, s, pos, st) - } - - let rec loop_no_mark = (info, s, pos, last, st) => - if pos < last { - let st' = st.next[Char.code(Bytes.get(info.i_cols, Char.code(String.get(s, pos))))] - if st'.idx >= 0 { - loop_no_mark(info, s, pos + 1, last, st') - } else if st'.idx == break { - st' - } else { - /* Unknown */ - validate(info, s, pos, st) - loop_no_mark(info, s, pos, last, st) - } - } else { - st - } - - let final = (info, st, cat) => - try List.assq(cat, st.final) catch { - | Not_found => - let st' = delta(info, cat, -1, st) - let res = (st'.Automata.State.idx, Automata.status(st')) - st.final = list{(cat, res), ...st.final} - res - } - - let find_initial_state = (re, cat) => - try List.assq(cat, re.initial_states) catch { - | Not_found => - let st = find_state(re, Automata.State.create(cat, re.initial)) - re.initial_states = list{(cat, st), ...re.initial_states} - st - } - - let get_color = (re, s: string, pos) => - if pos < 0 { - -1 - } else { - let slen = String.length(s) - if pos >= slen { - -1 - } else if pos == slen - 1 && (re.lnl != -1 && String.get(s, pos) == '\n') { - /* Special case for the last newline */ - re.lnl - } else { - Char.code(Bytes.get(re.cols, Char.code(String.get(s, pos)))) - } - } - - let rec handle_last_newline = (info, pos, st, groups) => { - let st' = st.next[info.re.lnl] - if st'.idx >= 0 { - if groups { - info.positions[st'.idx] = pos + 1 - } - st' - } else if st'.idx == break { - if groups { - info.positions[st'.real_idx] = pos + 1 - } - st' - } else { - /* Unknown */ - let c = info.re.lnl - let real_c = Char.code(Bytes.get(info.i_cols, Char.code('\n'))) - let cat = category(info.re, c) - let desc' = delta(info, cat, real_c, st) - let st' = find_state(info.re, desc') - st.next[c] = st' - handle_last_newline(info, pos, st, groups) - } - } - - let rec scan_str = (info, s: string, initial_state, groups) => { - let pos = info.pos - let last = info.last - if ( - last == String.length(s) && - (info.re.lnl != -1 && - (last > pos && String.get(s, last - 1) == '\n')) - ) { - let info = {...info, last: last - 1} - let st = scan_str(info, s, initial_state, groups) - if st.idx == break { - st - } else { - handle_last_newline(info, last - 1, st, groups) - } - } else if groups { - loop(info, s, pos, initial_state) - } else { - loop_no_mark(info, s, pos, last, initial_state) - } - } - - let match_str = (~groups, ~partial, re, s, ~pos, ~len) => { - let slen = String.length(s) - let last = if len == -1 { - slen - } else { - pos + len - } - let info = { - re, - i_cols: re.cols, - pos, - last, - positions: if groups { - let n = Automata.index_count(re.tbl) + 1 - if n <= 10 { - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] - } else { - Array.make(n, 0) - } - } else { - [] - }, - } - - let initial_cat = if pos == 0 { - open Category - \"++"(search_boundary, inexistant) - } else { - open Category - \"++"(search_boundary, category(re, get_color(re, s, pos - 1))) - } - let initial_state = find_initial_state(re, initial_cat) - let st = scan_str(info, s, initial_state, groups) - let res = if st.idx == break || partial { - Automata.status(st.desc) - } else { - let final_cat = if last == slen { - open Category - \"++"(search_boundary, inexistant) - } else { - open Category - \"++"(search_boundary, category(re, get_color(re, s, last))) - } - let (idx, res) = final(info, st, final_cat) - if groups { - info.positions[idx] = last + 1 - } - res - } - - switch res { - | Automata.Match(marks, pmarks) => - Match({s, marks, pmarks, gpos: info.positions, gcount: re.group_count}) - | Automata.Failed => Failed - | Automata.Running => Running - } - } - - let mk_re = (init, cols, col_repr, ncol, lnl, group_count) => { - initial: init, - initial_states: list{}, - cols, - col_repr, - ncol, - lnl, - tbl: Automata.create_working_area(), - states: Automata.State.Table.create(97), - group_count, - } - - /* *** Character sets *** */ - - let cseq = (c, c') => Cset.seq(Char.code(c), Char.code(c')) - let cadd = (c, s) => Cset.add(Char.code(c), s) - - let trans_set = (cache, cm, s) => - switch Cset.one_char(s) { - | Some(i) => Cset.csingle(Bytes.get(cm, i)) - | None => - let v = (Cset.hash_rec(s), s) - try Cset.CSetMap.find(v, cache.contents) catch { - | Not_found => - let l = Cset.fold_right( - s, - ~f=((i, j), l) => Cset.union(cseq(Bytes.get(cm, i), Bytes.get(cm, j)), l), - ~init=Cset.empty, - ) - - cache := Cset.CSetMap.add(v, l, cache.contents) - l - } - } - - /* ** */ - - type rec regexp = - | Set(Cset.t) - | Sequence(list) - | Alternative(list) - | Repeat(regexp, int, option) - | Beg_of_line - | End_of_line - | Beg_of_word - | End_of_word - | Not_bound - | Beg_of_str - | End_of_str - | Last_end_of_line - | Start - | Stop - | Sem(Automata.sem, regexp) - | Sem_greedy(Automata.rep_kind, regexp) - | Group(regexp) - | No_group(regexp) - | Nest(regexp) - | Case(regexp) - | No_case(regexp) - | Intersection(list) - | Complement(list) - | Difference(regexp, regexp) - | Pmark(Automata.Pmark.t, regexp) - - /* let %ignore rec pp fmt t = - let open Re_fmt in - let var s re = sexp fmt s pp re in - let seq s rel = sexp fmt s (list pp) rel in - match t with - | Set s -> sexp fmt "Set" Cset.pp s - | Sequence sq -> seq "Sequence" sq - | Alternative alt -> seq "Alternative" alt - | Repeat (re, start, stop) -> - let pp' fmt () = fprintf fmt "%a@ %d%a" pp re start optint stop in - sexp fmt "Repeat" pp' () - | Beg_of_line -> str fmt "Beg_of_line" - | End_of_line -> str fmt "End_of_line" - | Beg_of_word -> str fmt "Beg_of_word" - | End_of_word -> str fmt "End_of_word" - | Not_bound -> str fmt "Not_bound" - | Beg_of_str -> str fmt "Beg_of_str" - | End_of_str -> str fmt "End_of_str" - | Last_end_of_line -> str fmt "Last_end_of_line" - | Start -> str fmt "Start" - | Stop -> str fmt "Stop" - | Sem (sem, re) -> - sexp fmt "Sem" (pair Automata.pp_sem pp) (sem, re) - | Sem_greedy (k, re) -> - sexp fmt "Sem_greedy" (pair Automata.pp_rep_kind pp) (k, re) - | Group c -> var "Group" c - | No_group c -> var "No_group" c - | Nest c -> var "Nest" c - | Case c -> var "Case" c - | No_case c -> var "No_case" c - | Intersection c -> seq "Intersection" c - | Complement c -> seq "Complement" c - | Difference (a, b) -> sexp fmt "Difference" (pair pp pp) (a, b) - | Pmark (m, r) -> sexp fmt "Pmark" (pair Automata.Pmark.pp pp) (m, r) - */ - let rec is_charset = x => - switch x { - | Set(_) => true - | Alternative(l) | Intersection(l) | Complement(l) => List.for_all(is_charset, l) - | Difference(r, r') => is_charset(r) && is_charset(r') - | Sem(_, r) - | Sem_greedy(_, r) - | No_group(r) - | Case(r) - | No_case(r) => - is_charset(r) - | Sequence(_) - | Repeat(_) - | Beg_of_line - | End_of_line - | Beg_of_word - | End_of_word - | Beg_of_str - | End_of_str - | Not_bound - | Last_end_of_line - | Start - | Stop - | Group(_) - | Nest(_) - | Pmark(_, _) => false - } - - /* *** Colormap *** */ - - /* XXX Use a better algorithm allowing non-contiguous regions? */ - let split = (s, cm) => - Re_cset.iter(s, ~f=(i, j) => { - Bytes.set(cm, i, '') - Bytes.set(cm, j + 1, '') - }) - - let cupper = Cset.union(cseq('A', 'Z'), Cset.union(cseq('À', 'Ö'), cseq('Ø', 'Þ'))) - let clower = Cset.offset(32, cupper) - let calpha = List.fold_right(cadd, list{'ª', 'µ', 'º', 'ß', 'ÿ'}, Cset.union(clower, cupper)) - let cdigit = cseq('0', '9') - let calnum = Cset.union(calpha, cdigit) - let cword = cadd('_', calnum) - - let colorize = (c, regexp) => { - let lnl = ref(false) - let rec colorize = regexp => - switch regexp { - | Set(s) => split(s, c) - | Sequence(l) => List.iter(colorize, l) - | Alternative(l) => List.iter(colorize, l) - | Repeat(r, _, _) => colorize(r) - | Beg_of_line | End_of_line => split(Cset.csingle('\n'), c) - | Beg_of_word - | End_of_word - | Not_bound => - split(cword, c) - | Beg_of_str - | End_of_str - | Start - | Stop => () - | Last_end_of_line => lnl := true - | Sem(_, r) - | Sem_greedy(_, r) - | Group(r) - | No_group(r) - | Nest(r) - | Pmark(_, r) => - colorize(r) - | Case(_) - | No_case(_) - | Intersection(_) - | Complement(_) - | Difference(_) => - assert(false) - } - - colorize(regexp) - lnl.contents - } - - let make_cmap = () => Bytes.make(257, '') - - let flatten_cmap = cm => { - let c = Bytes.create(256) - let col_repr = Bytes.create(256) - let v = ref(0) - Bytes.set(c, 0, '') - Bytes.set(col_repr, 0, '') - for i in 1 to 255 { - if Bytes.get(cm, i) != '' { - incr(v) - } - Bytes.set(c, i, Char.chr(v.contents)) - Bytes.set(col_repr, v.contents, Char.chr(i)) - } - (c, Bytes.sub(col_repr, 0, v.contents + 1), v.contents + 1) - } - - /* *** Compilation *** */ - - let rec equal = (x1, x2) => - switch (x1, x2) { - | (Set(s1), Set(s2)) => s1 == s2 - | (Sequence(l1), Sequence(l2)) => eq_list(l1, l2) - | (Alternative(l1), Alternative(l2)) => eq_list(l1, l2) - | (Repeat(x1', i1, j1), Repeat(x2', i2, j2)) => i1 == i2 && (j1 == j2 && equal(x1', x2')) - | (Beg_of_line, Beg_of_line) - | (End_of_line, End_of_line) - | (Beg_of_word, Beg_of_word) - | (End_of_word, End_of_word) - | (Not_bound, Not_bound) - | (Beg_of_str, Beg_of_str) - | (End_of_str, End_of_str) - | (Last_end_of_line, Last_end_of_line) - | (Start, Start) - | (Stop, Stop) => true - | (Sem(sem1, x1'), Sem(sem2, x2')) => sem1 == sem2 && equal(x1', x2') - | (Sem_greedy(k1, x1'), Sem_greedy(k2, x2')) => k1 == k2 && equal(x1', x2') - | (Group(_), Group(_)) => /* Do not merge groups! */ - false - | (No_group(x1'), No_group(x2')) => equal(x1', x2') - | (Nest(x1'), Nest(x2')) => equal(x1', x2') - | (Case(x1'), Case(x2')) => equal(x1', x2') - | (No_case(x1'), No_case(x2')) => equal(x1', x2') - | (Intersection(l1), Intersection(l2)) => eq_list(l1, l2) - | (Complement(l1), Complement(l2)) => eq_list(l1, l2) - | (Difference(x1', x1''), Difference(x2', x2'')) => equal(x1', x2') && equal(x1'', x2'') - | (Pmark(m1, r1), Pmark(m2, r2)) => Automata.Pmark.equal(m1, m2) && equal(r1, r2) - | _ => false - } - - and eq_list = (l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => true - | (list{x1, ...r1}, list{x2, ...r2}) => equal(x1, x2) && eq_list(r1, r2) - | _ => false - } - - let sequence = x => - switch x { - | list{x} => x - | l => Sequence(l) - } - - let rec merge_sequences = x => - switch x { - | list{} => list{} - | list{Alternative(l'), ...r} => merge_sequences(\"@"(l', r)) - | list{Sequence(list{x, ...y}), ...r} => - switch merge_sequences(r) { - | list{Sequence(list{x', ...y'}), ...r'} if equal(x, x') => - list{Sequence(list{x, Alternative(list{sequence(y), sequence(y')})}), ...r'} - | r' => list{Sequence(list{x, ...y}), ...r'} - } - | list{x, ...r} => list{x, ...merge_sequences(r)} - } - - module A = Automata - - let enforce_kind = (ids, kind, kind', cr) => - switch (kind, kind') { - | (#First, #First) => cr - | (#First, k) => A.seq(ids, k, cr, A.eps(ids)) - | _ => cr - } - - /* XXX should probably compute a category mask */ - let rec translate = (ids, kind, ign_group, ign_case, greedy, pos, cache, c, x) => - switch x { - | Set(s) => (A.cst(ids, trans_set(cache, c, s)), kind) - | Sequence(l) => (trans_seq(ids, kind, ign_group, ign_case, greedy, pos, cache, c, l), kind) - | Alternative(l) => - switch merge_sequences(l) { - | list{r'} => - let (cr, kind') = translate(ids, kind, ign_group, ign_case, greedy, pos, cache, c, r') - (enforce_kind(ids, kind, kind', cr), kind) - | merged_sequences => (A.alt(ids, List.map(r' => { - let (cr, kind') = translate(ids, kind, ign_group, ign_case, greedy, pos, cache, c, r') - enforce_kind(ids, kind, kind', cr) - }, merged_sequences)), kind) - } - | Repeat(r', i, j) => - let (cr, kind') = translate(ids, kind, ign_group, ign_case, greedy, pos, cache, c, r') - let rem = switch j { - | None => A.rep(ids, greedy, kind', cr) - | Some(j) => - let f = switch greedy { - | #Greedy => rem => A.alt(ids, list{A.seq(ids, kind', A.rename(ids, cr), rem), A.eps(ids)}) - | #Non_greedy => - rem => A.alt(ids, list{A.eps(ids), A.seq(ids, kind', A.rename(ids, cr), rem)}) - } - - iter(j - i, f, A.eps(ids)) - } - - (iter(i, rem => A.seq(ids, kind', A.rename(ids, cr), rem), rem), kind) - | Beg_of_line => ( - A.after( - ids, - { - open Category - \"++"(inexistant, newline) - }, - ), - kind, - ) - | End_of_line => ( - A.before( - ids, - { - open Category - \"++"(inexistant, newline) - }, - ), - kind, - ) - | Beg_of_word => ( - A.seq( - ids, - #First, - A.after( - ids, - { - open Category - \"++"(inexistant, not_letter) - }, - ), - A.before( - ids, - { - open Category - \"++"(inexistant, letter) - }, - ), - ), - kind, - ) - | End_of_word => ( - A.seq( - ids, - #First, - A.after( - ids, - { - open Category - \"++"(inexistant, letter) - }, - ), - A.before( - ids, - { - open Category - \"++"(inexistant, not_letter) - }, - ), - ), - kind, - ) - | Not_bound => ( - A.alt( - ids, - list{ - A.seq(ids, #First, A.after(ids, Category.letter), A.before(ids, Category.letter)), - A.seq(ids, #First, A.after(ids, Category.letter), A.before(ids, Category.letter)), - }, - ), - kind, - ) - | Beg_of_str => (A.after(ids, Category.inexistant), kind) - | End_of_str => (A.before(ids, Category.inexistant), kind) - | Last_end_of_line => ( - A.before( - ids, - { - open Category - \"++"(inexistant, lastnewline) - }, - ), - kind, - ) - | Start => (A.after(ids, Category.search_boundary), kind) - | Stop => (A.before(ids, Category.search_boundary), kind) - | Sem(kind', r') => - let (cr, kind'') = translate(ids, kind', ign_group, ign_case, greedy, pos, cache, c, r') - (enforce_kind(ids, kind', kind'', cr), kind') - | Sem_greedy(greedy', r') => - translate(ids, kind, ign_group, ign_case, greedy', pos, cache, c, r') - | Group(r') => - if ign_group { - translate(ids, kind, ign_group, ign_case, greedy, pos, cache, c, r') - } else { - let p = pos.contents - pos := pos.contents + 2 - let (cr, kind') = translate(ids, kind, ign_group, ign_case, greedy, pos, cache, c, r') - (A.seq(ids, #First, A.mark(ids, p), A.seq(ids, #First, cr, A.mark(ids, p + 1))), kind') - } - | No_group(r') => translate(ids, kind, true, ign_case, greedy, pos, cache, c, r') - | Nest(r') => - let b = pos.contents - let (cr, kind') = translate(ids, kind, ign_group, ign_case, greedy, pos, cache, c, r') - - let e = pos.contents - 1 - if e < b { - (cr, kind') - } else { - (A.seq(ids, #First, A.erase(ids, b, e), cr), kind') - } - | Difference(_) | Complement(_) | Intersection(_) | No_case(_) | Case(_) => assert(false) - | Pmark(i, r') => - let (cr, kind') = translate(ids, kind, ign_group, ign_case, greedy, pos, cache, c, r') - (A.seq(ids, #First, A.pmark(ids, i), cr), kind') - } - - and trans_seq = (ids, kind, ign_group, ign_case, greedy, pos, cache, c, x) => - switch x { - | list{} => A.eps(ids) - | list{r} => - let (cr', kind') = translate(ids, kind, ign_group, ign_case, greedy, pos, cache, c, r) - enforce_kind(ids, kind, kind', cr') - | list{r, ...rem} => - let (cr', kind') = translate(ids, kind, ign_group, ign_case, greedy, pos, cache, c, r) - let cr'' = trans_seq(ids, kind, ign_group, ign_case, greedy, pos, cache, c, rem) - if A.is_eps(cr'') { - cr' - } else if A.is_eps(cr') { - cr'' - } else { - A.seq(ids, kind', cr', cr'') - } - } - - /* *** Case *** */ - - let case_insens = s => - Cset.union( - s, - Cset.union(Cset.offset(32, Cset.inter(s, cupper)), Cset.offset(-32, Cset.inter(s, clower))), - ) - - let as_set = x => - switch x { - | Set(s) => s - | _ => assert(false) - } - - /* XXX Should split alternatives into (1) charsets and (2) more - complex regular expressions; alternative should therefore probably - be flatten here */ - let rec handle_case = (ign_case, x) => - switch x { - | Set(s) => - Set( - if ign_case { - case_insens(s) - } else { - s - }, - ) - | Sequence(l) => Sequence(List.map(handle_case(ign_case, ...), l)) - | Alternative(l) => - let l' = List.map(handle_case(ign_case, ...), l) - if is_charset(Alternative(l')) { - Set(List.fold_left((s, r) => Cset.union(s, as_set(r)), Cset.empty, l')) - } else { - Alternative(l') - } - | Repeat(r, i, j) => Repeat(handle_case(ign_case, r), i, j) - | (Beg_of_line - | End_of_line - | Beg_of_word - | End_of_word - | Not_bound - | Beg_of_str - | End_of_str - | Last_end_of_line - | Start - | Stop) as r => r - | Sem(k, r) => - let r' = handle_case(ign_case, r) - if is_charset(r') { - r' - } else { - Sem(k, r') - } - | Sem_greedy(k, r) => - let r' = handle_case(ign_case, r) - if is_charset(r') { - r' - } else { - Sem_greedy(k, r') - } - | Group(r) => Group(handle_case(ign_case, r)) - | No_group(r) => - let r' = handle_case(ign_case, r) - if is_charset(r') { - r' - } else { - No_group(r') - } - | Nest(r) => - let r' = handle_case(ign_case, r) - if is_charset(r') { - r' - } else { - Nest(r') - } - | Case(r) => handle_case(false, r) - | No_case(r) => handle_case(true, r) - | Intersection(l) => - let l' = List.map(r => handle_case(ign_case, r), l) - Set(List.fold_left((s, r) => Cset.inter(s, as_set(r)), Cset.cany, l')) - | Complement(l) => - let l' = List.map(r => handle_case(ign_case, r), l) - Set(Cset.diff(Cset.cany, List.fold_left((s, r) => Cset.union(s, as_set(r)), Cset.empty, l'))) - | Difference(r, r') => - Set( - Cset.inter( - as_set(handle_case(ign_case, r)), - Cset.diff(Cset.cany, as_set(handle_case(ign_case, r'))), - ), - ) - | Pmark(i, r) => Pmark(i, handle_case(ign_case, r)) - } - - /* ** */ - - let compile_1 = regexp => { - let regexp = handle_case(false, regexp) - let c = make_cmap() - let need_lnl = colorize(c, regexp) - let (col, col_repr, ncol) = flatten_cmap(c) - let lnl = if need_lnl { - ncol - } else { - -1 - } - let ncol = if need_lnl { - ncol + 1 - } else { - ncol - } - let ids = A.create_ids() - let pos = ref(0) - let (r, kind) = translate( - ids, - #First, - false, - false, - #Greedy, - pos, - ref(Cset.CSetMap.empty), - col, - regexp, - ) - let r = enforce_kind(ids, #First, kind, r) - /* Format.eprintf "<%d %d>@." !ids ncol; */ - mk_re(r, col, col_repr, ncol, lnl, pos.contents / 2) - } - - /* ** */ - - let rec anchored = x => - switch x { - | Sequence(l) => List.exists(anchored, l) - | Alternative(l) => List.for_all(anchored, l) - | Repeat(r, i, _) => i > 0 && anchored(r) - | Set(_) - | Beg_of_line - | End_of_line - | Beg_of_word - | End_of_word - | Not_bound - | End_of_str - | Last_end_of_line - | Stop - | Intersection(_) - | Complement(_) - | Difference(_) => false - | Beg_of_str | Start => true - | Sem(_, r) - | Sem_greedy(_, r) - | Group(r) - | No_group(r) - | Nest(r) - | Case(r) - | No_case(r) - | Pmark(_, r) => - anchored(r) - } - - /* ** */ - - type t = regexp - - let str = s => { - let l = ref(list{}) - for i in String.length(s) - 1 downto 0 { - l := list{Set(Cset.csingle(String.get(s, i))), ...l.contents} - } - Sequence(l.contents) - } - let char = c => Set(Cset.csingle(c)) - - let alt = x => - switch x { - | list{r} => r - | l => Alternative(l) - } - let seq = x => - switch x { - | list{r} => r - | l => Sequence(l) - } - - let empty = alt(list{}) - let epsilon = seq(list{}) - let repn = (r, i, j) => { - if i < 0 { - invalid_arg("Re.repn") - } - switch j { - | Some(j) if j < i => invalid_arg("Re.repn") - | _ => () - } - Repeat(r, i, j) - } - let rep = r => repn(r, 0, None) - let rep1 = r => repn(r, 1, None) - let opt = r => repn(r, 0, Some(1)) - let bol = Beg_of_line - let eol = End_of_line - let bow = Beg_of_word - let eow = End_of_word - let word = r => seq(list{bow, r, eow}) - let not_boundary = Not_bound - let bos = Beg_of_str - let eos = End_of_str - let whole_string = r => seq(list{bos, r, eos}) - let leol = Last_end_of_line - let start = Start - let stop = Stop - let longest = r => Sem(#Longest, r) - let shortest = r => Sem(#Shortest, r) - let first = r => Sem(#First, r) - let greedy = r => Sem_greedy(#Greedy, r) - let non_greedy = r => Sem_greedy(#Non_greedy, r) - let group = r => Group(r) - let no_group = r => No_group(r) - let nest = r => Nest(r) - let mark = r => { - let i = Automata.Pmark.gen() - (i, Pmark(i, r)) - } - - let set = str => { - let s = ref(Cset.empty) - for i in 0 to String.length(str) - 1 { - s := Cset.union(Cset.csingle(String.get(str, i)), s.contents) - } - Set(s.contents) - } - - let rg = (c, c') => Set(cseq(c, c')) - - let inter = l => { - let r = Intersection(l) - if is_charset(r) { - r - } else { - invalid_arg("Re.inter") - } - } - - let compl = l => { - let r = Complement(l) - if is_charset(r) { - r - } else { - invalid_arg("Re.compl") - } - } - - let diff = (r, r') => { - let r'' = Difference(r, r') - if is_charset(r'') { - r'' - } else { - invalid_arg("Re.diff") - } - } - - let any = Set(Cset.cany) - let notnl = Set(Cset.diff(Cset.cany, Cset.csingle('\n'))) - - let lower = alt(list{rg('a', 'z'), char('µ'), rg('ß', 'ö'), rg('ø', 'ÿ')}) - let upper = alt(list{rg('A', 'Z'), rg('À', 'Ö'), rg('Ø', 'Þ')}) - let alpha = alt(list{lower, upper, char('ª'), char('º')}) - let digit = rg('0', '9') - let alnum = alt(list{alpha, digit}) - let wordc = alt(list{alnum, char('_')}) - let ascii = rg('', '') - let blank = set("\t ") - let cntrl = alt(list{rg('', ''), rg('', 'Ÿ')}) - let graph = alt(list{rg('!', '~'), rg(' ', 'ÿ')}) - let print = alt(list{rg(' ', '~'), rg(' ', 'ÿ')}) - let punct = alt(list{ - rg('!', '/'), - rg(':', '@'), - rg('[', '`'), - rg('{', '~'), - rg(' ', '©'), - rg('«', '´'), - rg('¶', '¹'), - rg('»', '¿'), - char('×'), - char('÷'), - }) - let space = alt(list{char(' '), rg('\t', '\r')}) - let xdigit = alt(list{digit, rg('a', 'f'), rg('A', 'F')}) - - let case = r => Case(r) - let no_case = r => No_case(r) - - /* ** */ - - let compile = r => - compile_1( - if anchored(r) { - group(r) - } else { - seq(list{shortest(rep(any)), group(r)}) - }, - ) - - let exec_internal = (name, ~pos=0, ~len=-1, ~groups, re, s) => { - if pos < 0 || (len < -1 || pos + len > String.length(s)) { - invalid_arg(name) - } - match_str(~groups, ~partial=false, re, s, ~pos, ~len) - } - - let exec = (~pos=?, ~len=?, re, s) => - switch exec_internal("Re.exec", ~pos?, ~len?, ~groups=true, re, s) { - | Match(substr) => substr - | _ => raise(Not_found) - } - - let exec_opt = (~pos=?, ~len=?, re, s) => - switch exec_internal("Re.exec_opt", ~pos?, ~len?, ~groups=true, re, s) { - | Match(substr) => Some(substr) - | _ => None - } - - let execp = (~pos=?, ~len=?, re, s) => - switch exec_internal(~groups=false, "Re.execp", ~pos?, ~len?, re, s) { - | Match(_substr) => true - | _ => false - } - - let exec_partial = (~pos=?, ~len=?, re, s) => - switch exec_internal(~groups=false, "Re.exec_partial", ~pos?, ~len?, re, s) { - | Match(_) => #Full - | Running => #Partial - | Failed => #Mismatch - } - - module Group = { - type t = groups - - let offset = (t, i) => { - if 2 * i + 1 >= Array.length(t.marks) { - raise(Not_found) - } - let m1 = t.marks[2 * i] - if m1 == -1 { - raise(Not_found) - } - let p1 = t.gpos[m1] - 1 - let p2 = t.gpos[t.marks[2 * i + 1]] - 1 - (p1, p2) - } - - let get = (t, i) => { - let (p1, p2) = offset(t, i) - String.sub(t.s, p1, p2 - p1) - } - - let start = (subs, i) => fst(offset(subs, i)) - - let stop = (subs, i) => snd(offset(subs, i)) - - let test = (t, i) => - if 2 * i >= Array.length(t.marks) { - false - } else { - let idx = t.marks[2 * i] - idx != -1 - } - - let dummy_offset = (-1, -1) - - let all_offset = t => { - let res = Array.make(t.gcount, dummy_offset) - for i in 0 to Array.length(t.marks) / 2 - 1 { - let m1 = t.marks[2 * i] - if m1 != -1 { - let p1 = t.gpos[m1] - let p2 = t.gpos[t.marks[2 * i + 1]] - res[i] = (p1 - 1, p2 - 1) - } - } - res - } - - let dummy_string = "" - - let all = t => { - let res = Array.make(t.gcount, dummy_string) - for i in 0 to Array.length(t.marks) / 2 - 1 { - let m1 = t.marks[2 * i] - if m1 != -1 { - let p1 = t.gpos[m1] - let p2 = t.gpos[t.marks[2 * i + 1]] - res[i] = String.sub(t.s, p1 - 1, p2 - p1) - } - } - res - } - - /* let%ignore pp fmt t = - let matches = - let offsets = all_offset t in - let strs = all t in - Array.to_list ( - Array.init (Array.length strs) (fun i -> strs.(i), offsets.(i)) - ) in - let open Re_fmt in - let pp_match fmt (str, (start, stop)) = - fprintf fmt "@[(%s (%d %d))@]" str start stop in - sexp fmt "Group" (list pp_match) matches */ - - let nb_groups = t => t.gcount - } - - module Mark = { - type t = Automata.Pmark.t - - let test = ({pmarks, _}, p) => Automata.PmarkSet.mem(p, pmarks) - - let all = s => s.pmarks - - module Set = MarkSet - - let equal = Automata.Pmark.equal - - let compare = Automata.Pmark.compare - } - - type gen<'a> = unit => option<'a> - - let all_gen = (~pos=0, ~len=?, re, s) => { - if pos < 0 { - invalid_arg("Re.all") - } - /* index of the first position we do not consider. - !pos < limit is an invariant */ - let limit = switch len { - | None => String.length(s) - | Some(l) => - if l < 0 || pos + l > String.length(s) { - invalid_arg("Re.all") - } - pos + l - } - - /* iterate on matches. When a match is found, search for the next - one just after its end */ - let pos = ref(pos) - () => - if pos.contents >= limit { - None /* no more matches */ - } else { - switch match_str( - ~groups=true, - ~partial=false, - re, - s, - ~pos=pos.contents, - ~len=limit - pos.contents, - ) { - | Match(substr) => - let (p1, p2) = Group.offset(substr, 0) - pos := if p1 == p2 { - p2 + 1 - } else { - p2 - } - Some(substr) - | Running - | Failed => - None - } - } - } - - let all = (~pos=?, ~len=?, re, s) => { - let l = ref(list{}) - let g = all_gen(~pos?, ~len?, re, s) - let rec iter = () => - switch g() { - | None => List.rev(l.contents) - | Some(sub) => - l := list{sub, ...l.contents} - iter() - } - iter() - } - - let matches_gen = (~pos=?, ~len=?, re, s) => { - let g = all_gen(~pos?, ~len?, re, s) - () => - switch g() { - | None => None - | Some(sub) => Some(Group.get(sub, 0)) - } - } - - let matches = (~pos=?, ~len=?, re, s) => { - let l = ref(list{}) - let g = all_gen(~pos?, ~len?, re, s) - let rec iter = () => - switch g() { - | None => List.rev(l.contents) - | Some(sub) => - l := list{Group.get(sub, 0), ...l.contents} - iter() - } - iter() - } - - type split_token = [ - | #Text(string) - | #Delim(groups) - ] - - let split_full_gen = (~pos=0, ~len=?, re, s) => { - if pos < 0 { - invalid_arg("Re.split") - } - let limit = switch len { - | None => String.length(s) - | Some(l) => - if l < 0 || pos + l > String.length(s) { - invalid_arg("Re.split") - } - pos + l - } - - /* i: start of delimited string - pos: first position after last match of [re] - limit: first index we ignore (!pos < limit is an invariant) */ - let pos0 = pos - let state = ref(#Idle) - let i = ref(pos) and pos = ref(pos) - let next = () => - switch state.contents { - | #Idle if pos.contents >= limit => - if i.contents < limit { - let sub = String.sub(s, i.contents, limit - i.contents) - incr(i) - Some(#Text(sub)) - } else { - None - } - | #Idle => - switch match_str( - ~groups=true, - ~partial=false, - re, - s, - ~pos=pos.contents, - ~len=limit - pos.contents, - ) { - | Match(substr) => - let (p1, p2) = Group.offset(substr, 0) - pos := if p1 == p2 { - p2 + 1 - } else { - p2 - } - let old_i = i.contents - i := p2 - if p1 > pos0 { - /* string does not start by a delimiter */ - let text = String.sub(s, old_i, p1 - old_i) - state := #Yield(#Delim(substr)) - Some(#Text(text)) - } else { - Some(#Delim(substr)) - } - | Running => None - | Failed => - if i.contents < limit { - let text = String.sub(s, i.contents, limit - i.contents) - i := limit - Some(#Text(text)) /* yield last string */ - } else { - None - } - } - | #Yield(x) => - state := #Idle - Some(x) - } - next - } - - let split_full = (~pos=?, ~len=?, re, s) => { - let l = ref(list{}) - let g = split_full_gen(~pos?, ~len?, re, s) - let rec iter = () => - switch g() { - | None => List.rev(l.contents) - | Some(s) => - l := list{s, ...l.contents} - iter() - } - iter() - } - - let split_gen = (~pos=?, ~len=?, re, s) => { - let g = split_full_gen(~pos?, ~len?, re, s) - let rec next = () => - switch g() { - | None => None - | Some(#Delim(_)) => next() - | Some(#Text(s)) => Some(s) - } - next - } - - let split = (~pos=?, ~len=?, re, s) => { - let l = ref(list{}) - let g = split_full_gen(~pos?, ~len?, re, s) - let rec iter = () => - switch g() { - | None => List.rev(l.contents) - | Some(#Delim(_)) => iter() - | Some(#Text(s)) => - l := list{s, ...l.contents} - iter() - } - iter() - } - - let replace = (~pos=0, ~len=?, ~all=true, re, ~f, s) => { - if pos < 0 { - invalid_arg("Re.replace") - } - let limit = switch len { - | None => String.length(s) - | Some(l) => - if l < 0 || pos + l > String.length(s) { - invalid_arg("Re.replace") - } - pos + l - } - - /* buffer into which we write the result */ - let buf = Buffer.create(String.length(s)) - /* iterate on matched substrings. */ - let rec iter = pos => - if pos < limit { - switch match_str(~groups=true, ~partial=false, re, s, ~pos, ~len=limit - pos) { - | Match(substr) => - let (p1, p2) = Group.offset(substr, 0) - /* add string between previous match and current match */ - Buffer.add_substring(buf, s, pos, p1 - pos) - /* what should we replace the matched group with? */ - let replacing = f(substr) - Buffer.add_string(buf, replacing) - if all { - /* if we matched a non-char e.g. ^ we must manually advance by 1 */ - iter( - if p1 == p2 { - /* a non char could be past the end of string. e.g. $ */ - if p2 < limit { - Buffer.add_char(buf, String.get(s, p2)) - } - p2 + 1 - } else { - p2 - }, - ) - } else { - Buffer.add_substring(buf, s, p2, limit - p2) - } - | Running => () - | Failed => Buffer.add_substring(buf, s, pos, limit - pos) - } - } - - iter(pos) - Buffer.contents(buf) - } - - let replace_string = (~pos=?, ~len=?, ~all=?, re, ~by, s) => - replace(~pos?, ~len?, ~all?, re, s, ~f=_ => by) - - let witness = t => { - let rec witness = x => - switch x { - | Set(c) => String.make(1, Char.chr(Cset.pick(c))) - | Sequence(xs) => String.concat("", List.map(witness, xs)) - | Alternative(list{x, ..._}) => witness(x) - | Alternative(list{}) => assert(false) - | Repeat(r, from, _to) => - let w = witness(r) - let b = Buffer.create(String.length(w) * from) - for _i in 1 to from { - Buffer.add_string(b, w) - } - Buffer.contents(b) - | No_case(r) => witness(r) - | Intersection(_) - | Complement(_) - | Difference(_, _) => - assert(false) - | Group(r) - | No_group(r) - | Nest(r) - | Sem(_, r) - | Pmark(_, r) - | Case(r) - | Sem_greedy(_, r) => - witness(r) - | Beg_of_line - | End_of_line - | Beg_of_word - | End_of_word - | Not_bound - | Beg_of_str - | Last_end_of_line - | Start - | Stop - | End_of_str => "" - } - witness(handle_case(false, t)) - } - - @@ocaml.text(" {2 Deprecated functions} ") - - type substrings = groups - - let get = Group.get - let get_ofs = Group.offset - let get_all = Group.all - let get_all_ofs = Group.all_offset - let test = Group.test - - type markid = Mark.t - - let marked = Mark.test - let mark_set = Mark.all - - /* ******************************** */ - - /* -Information about the previous character: -- does not exists -- is a letter -- is not a letter -- is a newline -- is last newline - -Beginning of word: -- previous is not a letter or does not exist -- current is a letter or does not exist - -End of word: -- previous is a letter or does not exist -- current is not a letter or does not exist - -Beginning of line: -- previous is a newline or does not exist - -Beginning of buffer: -- previous does not exist - -End of buffer -- current does not exist - -End of line -- current is a newline or does not exist -*/ - - /* -Rep: e = T,e | () - - semantics of the comma (shortest/longest/first) - - semantics of the union (greedy/non-greedy) - -Bounded repetition - a{0,3} = (a,(a,a?)?)? -*/ -} -module Re_perl: { - @@ocaml.text( - /* - RE - A regular expression library - - Copyright (C) 2001 Jerome Vouillon - email: Jerome.Vouillon@pps.jussieu.fr - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation, with - linking exception; either version 2.1 of the License, or (at - your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - - " Perl-style regular expressions " - ) - - exception Parse_error - @ocaml.doc(" Errors that can be raised during the parsing of the regular expression ") - exception Not_supported - - type opt = [ - | #Ungreedy - | #Dotall - | #Dollar_endonly - | #Multiline - | #Anchored - | #Caseless - ] - - @ocaml.doc(" Parsing of a Perl-style regular expression ") - let re: (~opts: list=?, string) => Re.t - - @ocaml.doc(" Regular expression compilation ") - let compile: Re.t => Re.re - - @ocaml.doc(" (Same as [Re.compile]) ") - let compile_pat: (~opts: list=?, string) => Re.re -} = { - /* - RE - A regular expression library - - Copyright (C) 2001 Jerome Vouillon - email: Jerome.Vouillon@pps.jussieu.fr - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation, with - linking exception; either version 2.1 of the License, or (at - your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - - exception Parse_error - exception Not_supported - - let posix_class_of_string = x => - switch x { - | "alnum" => Re.alnum - | "ascii" => Re.ascii - | "blank" => Re.blank - | "cntrl" => Re.cntrl - | "digit" => Re.digit - | "lower" => Re.lower - | "print" => Re.print - | "space" => Re.space - | "upper" => Re.upper - | "word" => Re.wordc - | "punct" => Re.punct - | "graph" => Re.graph - | "xdigit" => Re.xdigit - | class_ => invalid_arg("Invalid pcre class: " ++ class_) - } - - let posix_class_strings = list{ - "alnum", - "ascii", - "blank", - "cntrl", - "digit", - "lower", - "print", - "space", - "upper", - "word", - "punct", - "graph", - "xdigit", - } - - let parse = (multiline, dollar_endonly, dotall, ungreedy, s) => { - let i = ref(0) - let l = String.length(s) - let eos = () => i.contents == l - let test = c => !eos() && String.get(s, i.contents) == c - let accept = c => { - let r = test(c) - if r { - incr(i) - } - r - } - let accept_s = s' => { - let len = String.length(s') - try { - for j in 0 to len - 1 { - try if String.get(s', j) != String.get(s, i.contents + j) { - raise(Exit) - } catch { - | _ => raise(Exit) - } - } - i := i.contents + len - true - } catch { - | Exit => false - } - } - let get = () => { - let r = String.get(s, i.contents) - incr(i) - r - } - let unget = () => decr(i) - let greedy_mod = r => { - let gr = accept('?') - let gr = if ungreedy { - !gr - } else { - gr - } - if gr { - Re.non_greedy(r) - } else { - Re.greedy(r) - } - } - - let rec regexp = () => regexp'(branch()) - and regexp' = left => - if accept('|') { - regexp'(Re.alt(list{left, branch()})) - } else { - left - } - and branch = () => branch'(list{}) - and branch' = left => - if eos() || (test('|') || test(')')) { - Re.seq(List.rev(left)) - } else { - branch'(list{piece(), ...left}) - } - and piece = () => { - let r = atom() - if accept('*') { - greedy_mod(Re.rep(r)) - } else if accept('+') { - greedy_mod(Re.rep1(r)) - } else if accept('?') { - greedy_mod(Re.opt(r)) - } else if accept('{') { - switch integer() { - | Some(i) => - let j = if accept(',') { - integer() - } else { - Some(i) - } - if !accept('}') { - raise(Parse_error) - } - switch j { - | Some(j) if j < i => raise(Parse_error) - | _ => () - } - greedy_mod(Re.repn(r, i, j)) - | None => - unget() - r - } - } else { - r - } - } - and atom = () => - if accept('.') { - if dotall { - Re.any - } else { - Re.notnl - } - } else if accept('(') { - if accept('?') { - if accept(':') { - let r = regexp() - if !accept(')') { - raise(Parse_error) - } - r - } else if accept('#') { - comment() - } else { - raise(Parse_error) - } - } else { - let r = regexp() - if !accept(')') { - raise(Parse_error) - } - Re.group(r) - } - } else if accept('^') { - if multiline { - Re.bol - } else { - Re.bos - } - } else if accept('$') { - if multiline { - Re.eol - } else if dollar_endonly { - Re.leol - } else { - Re.eos - } - } else if accept('[') { - if accept('^') { - Re.compl(bracket(list{})) - } else { - Re.alt(bracket(list{})) - } - } else if accept('\\') { - /* XXX - - Back-references - - \cx (control-x), \e, \f, \n, \r, \t, \xhh, \ddd -*/ - if eos() { - raise(Parse_error) - } - switch get() { - | 'w' => Re.alt(list{Re.alnum, Re.char('_')}) - | 'W' => Re.compl(list{Re.alnum, Re.char('_')}) - | 's' => Re.space - | 'S' => Re.compl(list{Re.space}) - | 'd' => Re.digit - | 'D' => Re.compl(list{Re.digit}) - | 'b' => Re.alt(list{Re.bow, Re.eow}) - | 'B' => Re.not_boundary - | 'A' => Re.bos - | 'Z' => Re.leol - | 'z' => Re.eos - | 'G' => Re.start - | 'a' .. 'z' | 'A' .. 'Z' => raise(Parse_error) - | '0' .. '9' => raise(Not_supported) - | c => Re.char(c) - } - } else { - if eos() { - raise(Parse_error) - } - switch get() { - | '*' | '+' | '?' | '{' | '\\' => raise(Parse_error) - | c => Re.char(c) - } - } - and integer = () => - if eos() { - None - } else { - switch get() { - | '0' .. '9' as d => integer'(Char.code(d) - Char.code('0')) - | _ => - unget() - None - } - } - and integer' = i => - if eos() { - Some(i) - } else { - switch get() { - | '0' .. '9' as d => - let i' = 10 * i + (Char.code(d) - Char.code('0')) - if i' < i { - raise(Parse_error) - } - integer'(i') - | _ => - unget() - Some(i) - } - } - and bracket = s => - if s != list{} && accept(']') { - s - } else { - switch char() { - | #Char(c) => - if accept('-') { - if accept(']') { - list{Re.char(c), Re.char('-'), ...s} - } else { - switch char() { - | #Char(c') => bracket(list{Re.rg(c, c'), ...s}) - | #Set(st') => list{Re.char(c), Re.char('-'), st', ...s} - } - } - } else { - bracket(list{Re.char(c), ...s}) - } - | #Set(st) => bracket(list{st, ...s}) - } - } - and char = () => { - if eos() { - raise(Parse_error) - } - let c = get() - if c == '[' { - if accept('=') { - raise(Not_supported) - } - if accept(':') { - let compl = accept('^') - let cls = try List.find(accept_s, posix_class_strings) catch { - | Not_found => raise(Parse_error) - } - if !accept_s(":]") { - raise(Parse_error) - } - let re = { - let posix_class = posix_class_of_string(cls) - if compl { - Re.compl(list{posix_class}) - } else { - posix_class - } - } - #Set(re) - } else if accept('.') { - if eos() { - raise(Parse_error) - } - let c = get() - if !accept('.') { - raise(Not_supported) - } - if !accept(']') { - raise(Parse_error) - } - #Char(c) - } else { - #Char(c) - } - } else if c == '\\' { - let c = get() - /* XXX - \127, ... -*/ - switch c { - | 'b' => #Char('\b') - | 'n' => #Char('\n') /* XXX */ - | 'r' => #Char('\r') /* XXX */ - | 't' => #Char('\t') /* XXX */ - | 'w' => #Set(Re.alt(list{Re.alnum, Re.char('_')})) - | 'W' => #Set(Re.compl(list{Re.alnum, Re.char('_')})) - | 's' => #Set(Re.space) - | 'S' => #Set(Re.compl(list{Re.space})) - | 'd' => #Set(Re.digit) - | 'D' => #Set(Re.compl(list{Re.digit})) - | 'a' .. 'z' | 'A' .. 'Z' => raise(Parse_error) - | '0' .. '9' => raise(Not_supported) - | _ => #Char(c) - } - } else { - #Char(c) - } - } - and comment = () => - if accept(')') { - Re.epsilon - } else { - incr(i) - comment() - } - - let res = regexp() - if !eos() { - raise(Parse_error) - } - res - } - - type opt = [ - | #Ungreedy - | #Dotall - | #Dollar_endonly - | #Multiline - | #Anchored - | #Caseless - ] - - let re = (~opts=list{}, s) => { - let r = parse( - List.memq(#Multiline, opts), - List.memq(#Dollar_endonly, opts), - List.memq(#Dotall, opts), - List.memq(#Ungreedy, opts), - s, - ) - - let r = if List.memq(#Anchored, opts) { - Re.seq(list{Re.start, r}) - } else { - r - } - let r = if List.memq(#Caseless, opts) { - Re.no_case(r) - } else { - r - } - r - } - - let compile = Re.compile - let compile_pat = (~opts=list{}, s) => compile(re(~opts, s)) -} -module Re_pcre: { - type regexp = Re.re - - type flag = [#CASELESS | #MULTILINE | #ANCHORED] - - type groups = Re.groups - - @ocaml.doc(" Result of a {!Pcre.full_split} ") - type split_result = - | @ocaml.doc(" Text part of splitted string ") Text(string) - | @ocaml.doc(" Delimiter part of splitted string ") Delim(string) - | @ocaml.doc(" Subgroup of matched delimiter (subgroup_nr, subgroup_str) ") Group(int, string) - | @ocaml.doc(" Unmatched subgroup ") NoGroup - - @ocaml.doc(" [re ~flags s] creates the regexp [s] using the pcre syntax. ") - let re: (~flags: list=?, string) => Re.t - - @ocaml.doc(" [re ~flags s] compiles the regexp [s] using the pcre syntax. ") - let regexp: (~flags: list=?, string) => regexp - - @ocaml.doc(" [extract ~rex s] executes [rex] on [s] and returns the matching groups. ") - let extract: (~rex: regexp, string) => array - - @ocaml.doc(" Equivalent to {!Re.exec}. ") - let exec: (~rex: regexp, ~pos: int=?, string) => groups - - @ocaml.doc(" Equivalent to {!Re.Group.get}. ") - let get_substring: (groups, int) => string - - @ocaml.doc(" Equivalent to {!Re.Group.offset}. ") - let get_substring_ofs: (groups, int) => (int, int) - - @ocaml.doc(" Equivalent to {!Re.execp}. ") - let pmatch: (~rex: regexp, string) => bool - - let substitute: (~rex: Re.re, ~subst: string => string, string) => string - - let full_split: (~max: int=?, ~rex: regexp, string) => list - - let split: (~rex: regexp, string) => list - - let quote: string => string - - @@ocaml.text(" {2 Deprecated} ") - - type substrings = Re.groups -} = { - type regexp = Re.re - - type flag = [#CASELESS | #MULTILINE | #ANCHORED] - - type split_result = - | Text(string) - | Delim(string) - | Group(int, string) - | NoGroup - - type groups = Re.groups - - let re = (~flags=list{}, pat) => { - let opts = List.map(x => - switch x { - | #CASELESS => #Caseless - | #MULTILINE => #Multiline - | #ANCHORED => #Anchored - } - , flags) - Re_perl.re(~opts, pat) - } - - let regexp = (~flags=?, pat) => Re.compile(re(~flags?, pat)) - - let extract = (~rex, s) => Re.Group.all(Re.exec(rex, s)) - - let exec = (~rex, ~pos=?, s) => Re.exec(rex, ~pos?, s) - - let get_substring = (s, i) => Re.Group.get(s, i) - - let get_substring_ofs = (s, i) => Re.Group.offset(s, i) - - let pmatch = (~rex, s) => Re.execp(rex, s) - - let substitute = (~rex, ~subst, str) => { - let b = Buffer.create(1024) - let rec loop = pos => - if pos >= String.length(str) { - Buffer.contents(b) - } else if Re.execp(~pos, rex, str) { - let ss = Re.exec(~pos, rex, str) - let (start, fin) = Re.Group.offset(ss, 0) - let pat = Re.Group.get(ss, 0) - Buffer.add_substring(b, str, pos, start - pos) - Buffer.add_string(b, subst(pat)) - loop(fin) - } else { - Buffer.add_substring(b, str, pos, String.length(str) - pos) - loop(String.length(str)) - } - - loop(0) - } - - let split = (~rex, str) => { - let rec loop = (accu, pos) => - if pos >= String.length(str) { - List.rev(accu) - } else if Re.execp(~pos, rex, str) { - let ss = Re.exec(~pos, rex, str) - let (start, fin) = Re.Group.offset(ss, 0) - let s = String.sub(str, pos, start - pos) - loop(list{s, ...accu}, fin) - } else { - let s = String.sub(str, pos, String.length(str) - pos) - loop(list{s, ...accu}, String.length(str)) - } - loop(list{}, 0) - } - - /* From PCRE */ - let string_unsafe_sub = (s, ofs, len) => { - let r = Bytes.create(len) - Bytes.blit(s, ofs, r, 0, len) - Bytes.unsafe_to_string(r) - } - - let quote = s => { - let len = String.length(s) - let buf = Bytes.create(lsl(len, 1)) - let pos = ref(0) - for i in 0 to len - 1 { - switch String.unsafe_get(s, i) { - | ('\\' - | '^' - | '$' - | '.' - | '[' - | '|' - | '(' - | ')' - | '?' - | '*' - | '+' - | '{') as c => - Bytes.unsafe_set(buf, pos.contents, '\\') - incr(pos) - Bytes.unsafe_set(buf, pos.contents, c) - incr(pos) - | c => - Bytes.unsafe_set(buf, pos.contents, c) - incr(pos) - } - } - string_unsafe_sub(buf, 0, pos.contents) - } - - let full_split = (~max=0, ~rex, s) => - if String.length(s) == 0 { - list{} - } else if max == 1 { - list{Text(s)} - } else { - let results = Re.split_full(rex, s) - let matches = List.map(x => - switch x { - | #Text(s) => list{Text(s)} - | #Delim(d) => - let matches = Re.Group.all_offset(d) - let delim = Re.Group.get(d, 0) - list{ - Delim(delim), - ...{ - let l = ref(list{}) - for i in 1 to Array.length(matches) - 1 { - l := - list{ - if matches[i] == (-1, -1) { - NoGroup - } else { - Group(i, Re.Group.get(d, i)) - }, - ...l.contents, - } - } - List.rev(l.contents) - }, - } - } - , results) - List.concat(matches) - } - - type substrings = Re.groups -} -module Xx = { - let _ = { - let s = String.make(1024 * 1024 - 1, 'a') ++ "b" - - eq(__LOC__, Re.get(Re_pcre.exec(~rex=Re_pcre.regexp("aa?b"), s), 0), "aab") - } -} - -Mt.from_pair_suites(__MODULE__, suites.contents) diff --git a/jscomp/test/of_string_test.js b/jscomp/test/of_string_test.js deleted file mode 100644 index 4eaffc2f4a..0000000000 --- a/jscomp/test/of_string_test.js +++ /dev/null @@ -1,46 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let Pervasives = require("../../lib/js/pervasives.js"); - -let suites_0 = [ - "string_of_float_1", - param => ({ - TAG: "Eq", - _0: "10.", - _1: Pervasives.string_of_float(10) - }) -]; - -let suites_1 = { - hd: [ - "string_of_int", - param => ({ - TAG: "Eq", - _0: "10", - _1: String(10) - }) - ], - tl: { - hd: [ - "valid_float_lexem", - param => ({ - TAG: "Eq", - _0: "10.", - _1: Pervasives.valid_float_lexem("10") - }) - ], - tl: /* [] */0 - } -}; - -let suites = { - hd: suites_0, - tl: suites_1 -}; - -Mt.from_pair_suites("Of_string_test", suites); - -exports.suites = suites; -/* Not a pure module */ diff --git a/jscomp/test/of_string_test.res b/jscomp/test/of_string_test.res deleted file mode 100644 index 48d3bcea0a..0000000000 --- a/jscomp/test/of_string_test.res +++ /dev/null @@ -1,14 +0,0 @@ -let suites = { - open Mt - list{ - ("string_of_float_1", _ => Eq("10.", string_of_float(10.))), - ("string_of_int", _ => Eq("10", string_of_int(10))), - /* Note that - [valid_float_lexem] use Range pattern, so we have to use - char as int now to make it passes the test - */ - ("valid_float_lexem", _ => Eq("10.", valid_float_lexem("10"))), - } -} - -Mt.from_pair_suites(__MODULE__, suites) diff --git a/jscomp/test/offset.js b/jscomp/test/offset.js index 457a8bbe5b..49483f0586 100644 --- a/jscomp/test/offset.js +++ b/jscomp/test/offset.js @@ -1,1006 +1,8 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml = require("../../lib/js/caml.js"); -let List = require("../../lib/js/list.js"); -let $$String = require("../../lib/js/string.js"); -let Caml_option = require("../../lib/js/caml_option.js"); -function height(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} - -function create(l, v, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} - -function bal(l, v, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - let lr = l.r; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, create(lr, v, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, lr.l), lr.v, create(lr.r, v, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - let rr = r.r; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, v, rl), rv, rr); - } - if (typeof rl === "object") { - return create(create(l, v, rl.l), rl.v, create(rl.r, rv, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; -} - -function add(x, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = Caml.string_compare(x, v); - if (c === 0) { - return param; - } - if (c < 0) { - let ll = add(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = add(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } -} - -function singleton(x) { - return { - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }; -} - -function add_min_element(x, param) { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(add_min_element(x, param.l), param.v, param.r); - } -} - -function add_max_element(x, param) { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(param.l, param.v, add_max_element(x, param.r)); - } -} - -function join(l, v, r) { - if (typeof l !== "object") { - return add_min_element(v, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_element(v, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, join(l.r, v, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, r.l), r.v, r.r); - } else { - return create(l, v, r); - } -} - -function min_elt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.v; - } - _param = l; - continue; - }; -} - -function min_elt_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return Caml_option.some(param.v); - } - _param = l; - continue; - }; -} - -function max_elt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let r = param.r; - if (typeof r !== "object") { - return param.v; - } - _param = r; - continue; - }; -} - -function max_elt_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return Caml_option.some(param.v); - } - _param = r; - continue; - }; -} - -function remove_min_elt(param) { - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.remove_min_elt", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_elt(l), param.v, param.r); - } -} - -function concat(t1, t2) { - if (typeof t1 !== "object") { - return t2; - } else if (typeof t2 !== "object") { - return t1; - } else { - return join(t1, min_elt(t2), remove_min_elt(t2)); - } -} - -function split(x, param) { - if (typeof param !== "object") { - return [ - "Empty", - false, - "Empty" - ]; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = Caml.string_compare(x, v); - if (c === 0) { - return [ - l, - true, - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, match$1[0]), - match$1[1], - match$1[2] - ]; -} - -function is_empty(param) { - if (typeof param !== "object") { - return true; - } else { - return false; - } -} - -function mem(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = Caml.string_compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function remove(x, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = Caml.string_compare(x, v); - if (c === 0) { - if (typeof l !== "object") { - return r; - } else if (typeof r !== "object") { - return l; - } else { - return bal(l, min_elt(r), remove_min_elt(r)); - } - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } -} - -function union(s1, s2) { - if (typeof s1 !== "object") { - return s2; - } - let h1 = s1.h; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let h2 = s2.h; - let v2 = s2.v; - if (h1 >= h2) { - if (h2 === 1) { - return add(v2, s1); - } - let match = split(v1, s2); - return join(union(s1.l, match[0]), v1, union(s1.r, match[2])); - } - if (h1 === 1) { - return add(v1, s2); - } - let match$1 = split(v2, s1); - return join(union(match$1[0], s2.l), v2, union(match$1[2], s2.r)); -} - -function inter(s1, s2) { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return "Empty"; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return join(inter(l1, l2), v1, inter(r1, match[2])); - } else { - return concat(inter(l1, l2), inter(r1, match[2])); - } -} - -function diff(s1, s2) { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return s1; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return concat(diff(l1, l2), diff(r1, match[2])); - } else { - return join(diff(l1, l2), v1, diff(r1, match[2])); - } -} - -function cons_enum(_s, _e) { - while (true) { - let e = _e; - let s = _s; - if (typeof s !== "object") { - return e; - } - _e = { - TAG: "More", - _0: s.v, - _1: s.r, - _2: e - }; - _s = s.l; - continue; - }; -} - -function compare(s1, s2) { - let _e1 = cons_enum(s1, "End"); - let _e2 = cons_enum(s2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = Caml.string_compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - _e2 = cons_enum(e2._1, e2._2); - _e1 = cons_enum(e1._1, e1._2); - continue; - }; -} - -function equal(s1, s2) { - return compare(s1, s2) === 0; -} - -function subset(_s1, _s2) { - while (true) { - let s2 = _s2; - let s1 = _s1; - if (typeof s1 !== "object") { - return true; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - if (typeof s2 !== "object") { - return false; - } - let r2 = s2.r; - let l2 = s2.l; - let c = Caml.string_compare(v1, s2.v); - if (c === 0) { - if (!subset(l1, l2)) { - return false; - } - _s2 = r2; - _s1 = r1; - continue; - } - if (c < 0) { - if (!subset({ - TAG: "Node", - l: l1, - v: v1, - r: "Empty", - h: 0 - }, l2)) { - return false; - } - _s1 = r1; - continue; - } - if (!subset({ - TAG: "Node", - l: "Empty", - v: v1, - r: r1, - h: 0 - }, r2)) { - return false; - } - _s1 = l1; - continue; - }; -} - -function iter(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v); - _param = param.r; - continue; - }; -} - -function fold(f, _s, _accu) { - while (true) { - let accu = _accu; - let s = _s; - if (typeof s !== "object") { - return accu; - } - _accu = f(s.v, fold(f, s.l, accu)); - _s = s.r; - continue; - }; -} - -function for_all(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; -} - -function exists(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; -} - -function filter(p, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pv = p(v); - let r$p = filter(p, r); - if (pv) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, r$p); - } - } else { - return concat(l$p, r$p); - } -} - -function partition(p, param) { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pv = p(v); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pv) { - return [ - join(lt, v, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, rf) - ]; - } -} - -function cardinal(param) { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } -} - -function elements_aux(_accu, _param) { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: param.v, - tl: elements_aux(accu, param.r) - }; - continue; - }; -} - -function elements(s) { - return elements_aux(/* [] */0, s); -} - -function find(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - let c = Caml.string_compare(x, v); - if (c === 0) { - return v; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function find_first(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return v0; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_first_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return Caml_option.some(v0); - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_last(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return v0; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_last_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return Caml_option.some(v0); - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_opt(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - let c = Caml.string_compare(x, v); - if (c === 0) { - return Caml_option.some(v); - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function map(f, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = map(f, l); - let v$p = f(v); - let r$p = map(f, r); - if (l === l$p && v === v$p && r === r$p) { - return param; - } else if ((l$p === "Empty" || Caml.string_compare(max_elt(l$p), v$p) < 0) && (r$p === "Empty" || Caml.string_compare(v$p, min_elt(r$p)) < 0)) { - return join(l$p, v$p, r$p); - } else { - return union(l$p, add(v$p, r$p)); - } -} - -function of_list(l) { - if (!l) { - return "Empty"; - } - let match = l.tl; - let x0 = l.hd; - if (!match) { - return singleton(x0); - } - let match$1 = match.tl; - let x1 = match.hd; - if (!match$1) { - return add(x1, singleton(x0)); - } - let match$2 = match$1.tl; - let x2 = match$1.hd; - if (!match$2) { - return add(x2, add(x1, singleton(x0))); - } - let match$3 = match$2.tl; - let x3 = match$2.hd; - if (match$3) { - if (match$3.tl) { - let l$1 = List.sort_uniq($$String.compare, l); - let sub = (n, l) => { - switch (n) { - case 0 : - return [ - "Empty", - l - ]; - case 1 : - if (l) { - return [ - { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - l.tl - ]; - } - break; - case 2 : - if (l) { - let match = l.tl; - if (match) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match.hd, - r: "Empty", - h: 2 - }, - match.tl - ]; - } - - } - break; - case 3 : - if (l) { - let match$1 = l.tl; - if (match$1) { - let match$2 = match$1.tl; - if (match$2) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match$1.hd, - r: { - TAG: "Node", - l: "Empty", - v: match$2.hd, - r: "Empty", - h: 1 - }, - h: 2 - }, - match$2.tl - ]; - } - - } - - } - break; - } - let nl = n / 2 | 0; - let match$3 = sub(nl, l); - let l$1 = match$3[1]; - if (l$1) { - let match$4 = sub((n - nl | 0) - 1 | 0, l$1.tl); - return [ - create(match$3[0], l$1.hd, match$4[0]), - match$4[1] - ]; - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "set.res", - 691, - 20 - ], - Error: new Error() - }; - }; - return sub(List.length(l$1), l$1)[0]; - } else { - return add(match$3.hd, add(x3, add(x2, add(x1, singleton(x0))))); - } - } else { - return add(x3, add(x2, add(x1, singleton(x0)))); - } -} - -let $$Set = { - empty: "Empty", - is_empty: is_empty, - mem: mem, - add: add, - singleton: singleton, - remove: remove, - union: union, - inter: inter, - diff: diff, - compare: compare, - equal: equal, - subset: subset, - iter: iter, - map: map, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - elements: elements, - min_elt: min_elt, - min_elt_opt: min_elt_opt, - max_elt: max_elt, - max_elt_opt: max_elt_opt, - choose: min_elt, - choose_opt: min_elt_opt, - split: split, - find: find, - find_opt: find_opt, - find_first: find_first, - find_first_opt: find_first_opt, - find_last: find_last, - find_last_opt: find_last_opt, - of_list: of_list -}; +let $$Set; let M = { x: 1, diff --git a/jscomp/test/offset.res b/jscomp/test/offset.res index b7753657e1..c6ed1f247b 100644 --- a/jscomp/test/offset.res +++ b/jscomp/test/offset.res @@ -16,7 +16,7 @@ module M = { let x = 0 let x = 1 - module Set = Set.Make(String) + module Set = Belt.Set.String } include M diff --git a/jscomp/test/option_repr_test.js b/jscomp/test/option_repr_test.js index b4435fe07e..fe23de4a84 100644 --- a/jscomp/test/option_repr_test.js +++ b/jscomp/test/option_repr_test.js @@ -2,9 +2,9 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); let Belt_List = require("../../lib/js/belt_List.js"); -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); let suites = { contents: /* [] */0 @@ -73,9 +73,9 @@ function f6(a) { return true; } -let f10 = Caml_option.some(Caml_option.some(Caml_option.some(Caml_option.some(undefined)))); +let f10 = Primitive_option.some(Primitive_option.some(Primitive_option.some(Primitive_option.some(undefined)))); -let f11 = Caml_option.some(f10); +let f11 = Primitive_option.some(f10); let randomized = { contents: false @@ -109,7 +109,7 @@ let length_8_id = Belt_List.makeBy(8, x => x); let length_10_id = Belt_List.makeBy(10, x => x); function f13$1() { - return Caml_obj.equal(Belt_List.take(length_10_id, 8), { + return Primitive_object.equal(Belt_List.take(length_10_id, 8), { hd: 1, tl: { hd: 2, @@ -121,45 +121,45 @@ function f13$1() { }); } -b("File \"option_repr_test.res\", line 93, characters 4-11", Caml_obj.lessthan(undefined, null)); +b("File \"option_repr_test.res\", line 93, characters 4-11", Primitive_object.lessthan(undefined, null)); -b("File \"option_repr_test.res\", line 94, characters 4-11", !Caml_obj.greaterthan(undefined, null)); +b("File \"option_repr_test.res\", line 94, characters 4-11", !Primitive_object.greaterthan(undefined, null)); -b("File \"option_repr_test.res\", line 95, characters 4-11", Caml_obj.greaterthan(null, undefined)); +b("File \"option_repr_test.res\", line 95, characters 4-11", Primitive_object.greaterthan(null, undefined)); -b("File \"option_repr_test.res\", line 96, characters 4-11", Caml_obj.lessthan(undefined, Caml_option.some(undefined))); +b("File \"option_repr_test.res\", line 96, characters 4-11", Primitive_object.lessthan(undefined, Primitive_option.some(undefined))); -b("File \"option_repr_test.res\", line 97, characters 4-11", Caml_obj.greaterthan(Caml_option.some(undefined), undefined)); +b("File \"option_repr_test.res\", line 97, characters 4-11", Primitive_object.greaterthan(Primitive_option.some(undefined), undefined)); console.log(6, undefined); function ltx(a, b) { - if (Caml_obj.lessthan(a, b)) { - return Caml_obj.greaterthan(b, a); + if (Primitive_object.lessthan(a, b)) { + return Primitive_object.greaterthan(b, a); } else { return false; } } function gtx(a, b) { - if (Caml_obj.greaterthan(a, b)) { - return Caml_obj.lessthan(b, a); + if (Primitive_object.greaterthan(a, b)) { + return Primitive_object.lessthan(b, a); } else { return false; } } function eqx(a, b) { - if (Caml_obj.equal(a, b)) { - return Caml_obj.equal(b, a); + if (Primitive_object.equal(a, b)) { + return Primitive_object.equal(b, a); } else { return false; } } function neqx(a, b) { - if (Caml_obj.notequal(a, b)) { - return Caml_obj.notequal(b, a); + if (Primitive_object.notequal(a, b)) { + return Primitive_object.notequal(b, a); } else { return false; } @@ -169,7 +169,7 @@ function all_true(xs) { return Belt_List.every(xs, x => x); } -let xs_0 = gtx(Caml_option.some(null), Caml_option.some(undefined)); +let xs_0 = gtx(Primitive_option.some(null), Primitive_option.some(undefined)); let xs = { hd: xs_0, @@ -178,22 +178,22 @@ let xs = { b("File \"option_repr_test.res\", line 125, characters 8-15", Belt_List.every(xs, x => x)); -let xs_0$1 = ltx(Caml_option.some(undefined), 3); +let xs_0$1 = Primitive_object.lessthan(Primitive_option.some(undefined), 3) && Primitive_object.greaterthan(3, Primitive_option.some(undefined)); let xs_1 = { - hd: ltx(Caml_option.some(undefined), Caml_option.some(Caml_option.some(undefined))), + hd: Primitive_object.lessthan(Primitive_option.some(undefined), Primitive_option.some(Primitive_option.some(undefined))) && Primitive_object.greaterthan(Primitive_option.some(Primitive_option.some(undefined)), Primitive_option.some(undefined)), tl: { - hd: ltx(Caml_option.some(undefined), "3"), + hd: Primitive_object.lessthan(Primitive_option.some(undefined), "3") && Primitive_object.greaterthan("3", Primitive_option.some(undefined)), tl: { - hd: ltx(Caml_option.some(undefined), true), + hd: Primitive_object.lessthan(Primitive_option.some(undefined), true) && Primitive_object.greaterthan(true, Primitive_option.some(undefined)), tl: { - hd: ltx(Caml_option.some(undefined), false), + hd: Primitive_object.lessthan(Primitive_option.some(undefined), false) && Primitive_object.greaterthan(false, Primitive_option.some(undefined)), tl: { - hd: ltx(false, true), + hd: Primitive_object.lessthan(false, true) && Primitive_object.greaterthan(true, false), tl: { - hd: ltx(false, true), + hd: Primitive_object.lessthan(false, true) && Primitive_object.greaterthan(true, false), tl: { - hd: ltx(undefined, Caml_option.some(undefined)), + hd: Primitive_object.lessthan(undefined, Primitive_option.some(undefined)) && Primitive_object.greaterthan(Primitive_option.some(undefined), undefined), tl: { hd: ltx(undefined, null), tl: { @@ -219,16 +219,16 @@ let xs$1 = { b("File \"option_repr_test.res\", line 128, characters 4-11", Belt_List.every(xs$1, x => x)); -let xs_0$2 = eqx(undefined, undefined); +let xs_0$2 = true && true; let xs_1$1 = { hd: neqx(undefined, null), tl: { - hd: eqx(Caml_option.some(undefined), Caml_option.some(undefined)), + hd: Primitive_object.equal(Primitive_option.some(undefined), Primitive_option.some(undefined)) && Primitive_object.equal(Primitive_option.some(undefined), Primitive_option.some(undefined)), tl: { - hd: eqx(Caml_option.some(Caml_option.some(undefined)), Caml_option.some(Caml_option.some(undefined))), + hd: Primitive_object.equal(Primitive_option.some(Primitive_option.some(undefined)), Primitive_option.some(Primitive_option.some(undefined))) && Primitive_object.equal(Primitive_option.some(Primitive_option.some(undefined)), Primitive_option.some(Primitive_option.some(undefined))), tl: { - hd: neqx(Caml_option.some(Caml_option.some(Caml_option.some(undefined))), Caml_option.some(Caml_option.some(undefined))), + hd: Primitive_object.notequal(Primitive_option.some(Primitive_option.some(Primitive_option.some(undefined))), Primitive_option.some(Primitive_option.some(undefined))) && Primitive_object.notequal(Primitive_option.some(Primitive_option.some(undefined)), Primitive_option.some(Primitive_option.some(Primitive_option.some(undefined)))), tl: /* [] */0 } } @@ -259,9 +259,9 @@ Mt.from_pair_suites("Option_repr_test", suites.contents); let f7; -let f8 = Caml_option.some(undefined); +let f8 = Primitive_option.some(undefined); -let f9 = Caml_option.some(Caml_option.some(undefined)); +let f9 = Primitive_option.some(Primitive_option.some(undefined)); let N; diff --git a/jscomp/test/optional_ffi_test.js b/jscomp/test/optional_ffi_test.js index 9b6651b5cc..6090af0dd7 100644 --- a/jscomp/test/optional_ffi_test.js +++ b/jscomp/test/optional_ffi_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); let suites = { contents: /* [] */0 @@ -18,7 +18,7 @@ function eq(loc, param) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -39,7 +39,7 @@ let u = hey(undefined, 3); let z = hey(5, 3); -eq("File \"optional_ffi_test.res\", line 21, characters 12-19", [ +eq("File \"optional_ffi_test.res\", line 24, characters 12-19", [ [ u, z @@ -64,7 +64,7 @@ function bug_to_fix(f, x) { } function bug_to_fix2(f, x) { - return hey(Caml_option.option_get(f(x)), 3); + return hey(Primitive_option.toUndefined(f(x)), 3); } let counter2 = { @@ -110,9 +110,9 @@ let pair2 = [ pair2_1 ]; -eq("File \"optional_ffi_test.res\", line 45, characters 5-12", pair); +eq("File \"optional_ffi_test.res\", line 48, characters 5-12", pair); -eq("File \"optional_ffi_test.res\", line 46, characters 5-12", pair2); +eq("File \"optional_ffi_test.res\", line 49, characters 5-12", pair2); function heystr(x, y) { if (x === void 0) { x = "3"; } @@ -127,7 +127,7 @@ let pair$1 = [ pair_1$1 ]; -eq("File \"optional_ffi_test.res\", line 61, characters 5-12", pair$1); +eq("File \"optional_ffi_test.res\", line 64, characters 5-12", pair$1); Mt.from_pair_suites("Optional_ffi_test", suites.contents); diff --git a/jscomp/test/optional_ffi_test.res b/jscomp/test/optional_ffi_test.res index 938eb24d4f..02a766e1c8 100644 --- a/jscomp/test/optional_ffi_test.res +++ b/jscomp/test/optional_ffi_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, (x, y)) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } %%raw(` diff --git a/jscomp/test/optional_regression_test.js b/jscomp/test/optional_regression_test.js index af956ee879..06e89dab1d 100644 --- a/jscomp/test/optional_regression_test.js +++ b/jscomp/test/optional_regression_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); let suites = { contents: /* [] */0 @@ -19,13 +19,13 @@ function eq(loc, x, y) { function make(s, b, i, param) { let tmp = {}; if (s !== undefined) { - tmp.s = Caml_option.valFromOption(s); + tmp.s = Primitive_option.valFromOption(s); } if (b !== undefined) { - tmp.b = Caml_option.valFromOption(b); + tmp.b = Primitive_option.valFromOption(b); } if (i !== undefined) { - tmp.i = Caml_option.valFromOption(i); + tmp.i = Primitive_option.valFromOption(i); } return tmp; } @@ -36,11 +36,11 @@ let hh = { i: 0 }; -eq("File \"optional_regression_test.res\", line 16, characters 3-10", Caml_option.undefined_to_opt(hh.s), ""); +eq("File \"optional_regression_test.res\", line 16, characters 3-10", Primitive_option.fromUndefined(hh.s), ""); -eq("File \"optional_regression_test.res\", line 17, characters 3-10", Caml_option.undefined_to_opt(hh.b), false); +eq("File \"optional_regression_test.res\", line 17, characters 3-10", Primitive_option.fromUndefined(hh.b), false); -eq("File \"optional_regression_test.res\", line 18, characters 3-10", Caml_option.undefined_to_opt(hh.i), 0); +eq("File \"optional_regression_test.res\", line 18, characters 3-10", Primitive_option.fromUndefined(hh.i), 0); console.log(hh); diff --git a/jscomp/test/pipe_syntax.js b/jscomp/test/pipe_syntax.js index 79f97aeb38..a7a63a7630 100644 --- a/jscomp/test/pipe_syntax.js +++ b/jscomp/test/pipe_syntax.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); function t0(x, f) { return f(f(f(x))); @@ -64,19 +64,19 @@ function f5(a, b, c, d) { } function f6(a) { - return Caml_option.some(a); + return Primitive_option.some(a); } function f7(a) { return [ - Caml_option.some(a), - Caml_option.some(a), - Caml_option.some(a) + Primitive_option.some(a), + Primitive_option.some(a), + Primitive_option.some(a) ]; } function f8(a) { - return Caml_option.some(Caml_option.some(a)); + return Primitive_option.some(Primitive_option.some(a)); } let with_poly = { diff --git a/jscomp/test/poly_variant_test.js b/jscomp/test/poly_variant_test.js index d3333dec35..5c6983b4ea 100644 --- a/jscomp/test/poly_variant_test.js +++ b/jscomp/test/poly_variant_test.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -58,13 +58,13 @@ let vv = [ hey_int(4) ]; -eq("File \"poly_variant_test.res\", line 65, characters 5-12", vv, [ +eq("File \"poly_variant_test.res\", line 68, characters 5-12", vv, [ 3, 0, 4 ]); -eq("File \"poly_variant_test.res\", line 66, characters 5-12", [ +eq("File \"poly_variant_test.res\", line 69, characters 5-12", [ hey_int(5), hey_int(6) ], [ @@ -72,7 +72,7 @@ eq("File \"poly_variant_test.res\", line 66, characters 5-12", [ 6 ]); -eq("File \"poly_variant_test.res\", line 67, characters 5-12", uu, [ +eq("File \"poly_variant_test.res\", line 70, characters 5-12", uu, [ "on_open", "on_closed", "in" @@ -90,9 +90,9 @@ function p_is_int_test(x) { } } -eq("File \"poly_variant_test.res\", line 157, characters 5-12", 2, 2); +eq("File \"poly_variant_test.res\", line 160, characters 5-12", 2, 2); -eq("File \"poly_variant_test.res\", line 158, characters 5-12", 3, p_is_int_test({ +eq("File \"poly_variant_test.res\", line 161, characters 5-12", 3, p_is_int_test({ NAME: "b", VAL: 2 })); diff --git a/jscomp/test/poly_variant_test.res b/jscomp/test/poly_variant_test.res index 05de66f6df..7aa2887a7b 100644 --- a/jscomp/test/poly_variant_test.res +++ b/jscomp/test/poly_variant_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } %%raw(` diff --git a/jscomp/test/polymorphic_raw_test.js b/jscomp/test/polymorphic_raw_test.js index 063688f618..60975b707d 100644 --- a/jscomp/test/polymorphic_raw_test.js +++ b/jscomp/test/polymorphic_raw_test.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -32,9 +32,9 @@ let a = f(3); let b = f("3"); -eq("File \"polymorphic_raw_test.res\", line 18, characters 3-10", a, "number"); +eq("File \"polymorphic_raw_test.res\", line 21, characters 3-10", a, "number"); -eq("File \"polymorphic_raw_test.res\", line 19, characters 3-10", b, "string"); +eq("File \"polymorphic_raw_test.res\", line 22, characters 3-10", b, "string"); Mt.from_pair_suites("polymorphic_raw_test.res", suites.contents); diff --git a/jscomp/test/polymorphic_raw_test.res b/jscomp/test/polymorphic_raw_test.res index 7ab56d6d6c..533d453d7b 100644 --- a/jscomp/test/polymorphic_raw_test.res +++ b/jscomp/test/polymorphic_raw_test.res @@ -7,7 +7,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let f: _ => string = %raw(` (a) => typeof a `) diff --git a/jscomp/test/ppx_apply_test.js b/jscomp/test/ppx_apply_test.js index 43e26e376d..760b0fb5b7 100644 --- a/jscomp/test/ppx_apply_test.js +++ b/jscomp/test/ppx_apply_test.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -38,7 +38,7 @@ function unary(a) { let xx = 6; -eq("File \"ppx_apply_test.res\", line 16, characters 12-19", u, 3); +eq("File \"ppx_apply_test.res\", line 19, characters 12-19", u, 3); function h(a) { return xx(a); diff --git a/jscomp/test/ppx_apply_test.res b/jscomp/test/ppx_apply_test.res index a7f320500c..d021c0f382 100644 --- a/jscomp/test/ppx_apply_test.res +++ b/jscomp/test/ppx_apply_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let u = ((a, b) => a + b)(1, 2) diff --git a/jscomp/test/pq_test.js b/jscomp/test/pq_test.js index ef55e96787..7b95ee232c 100644 --- a/jscomp/test/pq_test.js +++ b/jscomp/test/pq_test.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); function insert(queue, prio, elt) { if (typeof queue !== "object") { @@ -36,7 +36,7 @@ function insert(queue, prio, elt) { } } -let Queue_is_empty = /* @__PURE__ */Caml_exceptions.create("Pq_test.PrioQueue.Queue_is_empty"); +let Queue_is_empty = /* @__PURE__ */Primitive_exceptions.create("Pq_test.PrioQueue.Queue_is_empty"); function remove_top(x) { if (typeof x !== "object") { diff --git a/jscomp/test/prepend_data_ffi.js b/jscomp/test/prepend_data_ffi.js index a2b0584725..4fcb1c6268 100644 --- a/jscomp/test/prepend_data_ffi.js +++ b/jscomp/test/prepend_data_ffi.js @@ -12,13 +12,13 @@ let v2 = { v: 2 }; -process.on("exit", exit_code => String(exit_code)); +process.on("exit", exit_code => exit_code.toString()); process.on(1, param => {}); -process.on(i => String(i), "exit"); +process.on(i => i.toString(), "exit"); -process.on(i => String(i), 1); +process.on(i => i.toString(), 1); xx(3, 3, "xxx", "a", "b"); @@ -39,7 +39,7 @@ function f(x) { } process.on("exit", exit_code => { - console.log("error code: " + String(exit_code)); + console.log("error code: %d", exit_code); }); function register(p) { diff --git a/jscomp/test/prepend_data_ffi.res b/jscomp/test/prepend_data_ffi.res index 13a506b801..68aa73e922 100644 --- a/jscomp/test/prepend_data_ffi.res +++ b/jscomp/test/prepend_data_ffi.res @@ -10,7 +10,7 @@ let v2: config2_expect = config2(~v=2, ()) @val external on_exit: (@as("exit") _, int => string) => unit = "process.on" -let () = on_exit(exit_code => string_of_int(exit_code)) +let () = on_exit(exit_code => Js.Int.toString(exit_code)) @val external on_exit_int: (@as(1) _, int => unit) => unit = "process.on" @@ -18,11 +18,11 @@ let () = on_exit_int(_ => ()) @val external on_exit3: (int => string, @as("exit") _) => unit = "process.on" -let () = on_exit3(i => string_of_int(i)) +let () = on_exit3(i => Js.Int.toString(i)) @val external on_exit4: (int => string, @as(1) _) => unit = "process.on" -let () = on_exit4(i => string_of_int(i)) +let () = on_exit4(i => Js.Int.toString(i)) @val @variadic external on_exit_slice: (int, @as(3) _, @as("xxx") _, array) => unit = "xx" @@ -78,7 +78,7 @@ let f = (x: t) => { @val external process_on_exit: (@as("exit") _, int => unit) => unit = "process.on" -let () = process_on_exit(exit_code => Js.log("error code: " ++ string_of_int(exit_code))) +let () = process_on_exit(exit_code => Js.log2("error code: %d", exit_code)) type process diff --git a/jscomp/test/primitive_reg_test.js b/jscomp/test/primitive_reg_test.js deleted file mode 100644 index c66f7c6acc..0000000000 --- a/jscomp/test/primitive_reg_test.js +++ /dev/null @@ -1,10 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - - -function x(prim0, prim1) { - return prim0 % prim1; -} - -exports.x = x; -/* No side effect */ diff --git a/jscomp/test/primitive_reg_test.res b/jscomp/test/primitive_reg_test.res deleted file mode 100644 index 74b7c26baa..0000000000 --- a/jscomp/test/primitive_reg_test.res +++ /dev/null @@ -1 +0,0 @@ -let x = mod_float diff --git a/jscomp/test/queue_402.js b/jscomp/test/queue_402.js index edbac77196..8645832aa3 100644 --- a/jscomp/test/queue_402.js +++ b/jscomp/test/queue_402.js @@ -1,10 +1,10 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_obj = require("../../lib/js/caml_obj.js"); -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); -let Empty = /* @__PURE__ */Caml_exceptions.create("Queue_402.Empty"); +let Empty = /* @__PURE__ */Primitive_exceptions.create("Queue_402.Empty"); function create() { return { @@ -75,7 +75,7 @@ function copy(q) { } let tail = q.tail; let tail$p = {}; - Caml_obj.update_dummy(tail$p, { + Primitive_object.updateDummy(tail$p, { content: tail.content, next: tail$p }); diff --git a/jscomp/test/queue_test.js b/jscomp/test/queue_test.js deleted file mode 100644 index 84e93e0b06..0000000000 --- a/jscomp/test/queue_test.js +++ /dev/null @@ -1,125 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let $$Array = require("../../lib/js/array.js"); -let Queue = require("../../lib/js/queue.js"); -let Queue_402 = require("./queue_402.js"); -let Caml_array = require("../../lib/js/caml_array.js"); - -function Test(Queue) { - let to_array = q => { - let v = Caml_array.make(Queue.length(q), 0); - Queue.fold((i, e) => { - Caml_array.set(v, i, e); - return i + 1 | 0; - }, 0, q); - return v; - }; - let queue_1 = x => { - let q = Queue.create(); - $$Array.iter(x => Queue.add(x, q), x); - return to_array(q); - }; - return { - to_array: to_array, - queue_1: queue_1 - }; -} - -function to_array(q) { - let v = Caml_array.make(q.length, 0); - Queue.fold((i, e) => { - Caml_array.set(v, i, e); - return i + 1 | 0; - }, 0, q); - return v; -} - -function queue_1(x) { - let q = { - length: 0, - first: "Nil", - last: "Nil" - }; - $$Array.iter(x => Queue.add(x, q), x); - return to_array(q); -} - -let T1 = { - to_array: to_array, - queue_1: queue_1 -}; - -function to_array$1(q) { - let v = Caml_array.make(q.length, 0); - Queue_402.fold((i, e) => { - Caml_array.set(v, i, e); - return i + 1 | 0; - }, 0, q); - return v; -} - -function queue_1$1(x) { - let q = { - length: 0, - tail: undefined - }; - $$Array.iter(x => Queue_402.add(x, q), x); - return to_array$1(q); -} - -let T2 = { - to_array: to_array$1, - queue_1: queue_1$1 -}; - -let suites_0 = [ - "File \"queue_test.res\", line 33, characters 6-13", - param => { - let x = [ - 3, - 4, - 5, - 2 - ]; - return { - TAG: "Eq", - _0: x, - _1: queue_1(x) - }; - } -]; - -let suites_1 = { - hd: [ - "File \"queue_test.res\", line 40, characters 6-13", - param => { - let x = [ - 3, - 4, - 5, - 2 - ]; - return { - TAG: "Eq", - _0: x, - _1: queue_1$1(x) - }; - } - ], - tl: /* [] */0 -}; - -let suites = { - hd: suites_0, - tl: suites_1 -}; - -Mt.from_pair_suites("Queue_test", suites); - -exports.Test = Test; -exports.T1 = T1; -exports.T2 = T2; -exports.suites = suites; -/* Not a pure module */ diff --git a/jscomp/test/queue_test.res b/jscomp/test/queue_test.res deleted file mode 100644 index 022a6ac1a6..0000000000 --- a/jscomp/test/queue_test.res +++ /dev/null @@ -1,49 +0,0 @@ -module Test = (Queue: module type of Queue) => { - let to_array = q => { - let v = Array.make(Queue.length(q), 0) - \"@@"(ignore, Queue.fold((i, e) => { - v[i] = e - i + 1 - }, 0, q)) - v - } - @val("console.log") @variadic external dump: array<'a> => unit = "" - - let queue_1 = x => { - let q = Queue.create() - /* dump [|q|]; */ - Array.iter(x => Queue.add(x, q), x) - /* dump [|q|]; */ - to_array(q) - } - - /* - TODO: Note it needs need recursive values support */ - /* let _ = queue_1 [|38|] */ -} - -module T1 = Test(Queue) -module T2 = Test(Queue_402) -open Mt - -let suites = { - open Mt - list{ - ( - __LOC__, - _ => { - let x = [3, 4, 5, 2] - Eq(x, T1.queue_1(x)) - }, - ), - ( - __LOC__, - _ => { - let x = [3, 4, 5, 2] - Eq(x, T2.queue_1(x)) - }, - ), - } -} - -from_pair_suites(__MODULE__, suites) diff --git a/jscomp/test/random_test.js b/jscomp/test/random_test.js deleted file mode 100644 index fa87f196d2..0000000000 --- a/jscomp/test/random_test.js +++ /dev/null @@ -1,79 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let Int64 = require("../../lib/js/int64.js"); -let Random = require("../../lib/js/random.js"); -let Mt_global = require("./mt_global.js"); -let Caml_array = require("../../lib/js/caml_array.js"); - -let id = { - contents: 0 -}; - -let suites = { - contents: /* [] */0 -}; - -function eq(f) { - return (extra, extra$1) => Mt_global.collect_eq(id, suites, f, extra, extra$1); -} - -function neq(f) { - return (extra, extra$1) => Mt_global.collect_neq(id, suites, f, extra, extra$1); -} - -function approx(f) { - return (extra, extra$1) => Mt_global.collect_approx(id, suites, f, extra, extra$1); -} - -Mt_global.collect_neq(id, suites, "File \"random_test.res\", line 8, characters 13-20", (Random.self_init(), Random.int(10000)), (Random.self_init(), Random.int(1000))); - -Random.init(0); - -let v = Caml_array.make(10, false); - -for (let i = 0; i <= 9; ++i) { - Caml_array.set(v, i, Random.bool()); -} - -Mt_global.collect_eq(id, suites, "File \"random_test.res\", line 27, characters 12-19", v, [ - true, - true, - true, - true, - true, - false, - true, - true, - true, - false -]); - -let f = Random.int64(Int64.max_int); - -let h = Random.int64([ - 0, - 3 -]); - -let vv = Random.bits(); - -let xx = Random.float(3.0); - -let xxx = Random.int32(103); - -Mt.from_pair_suites("Random_test", suites.contents); - -exports.id = id; -exports.suites = suites; -exports.eq = eq; -exports.neq = neq; -exports.approx = approx; -exports.v = v; -exports.f = f; -exports.h = h; -exports.vv = vv; -exports.xx = xx; -exports.xxx = xxx; -/* Not a pure module */ diff --git a/jscomp/test/random_test.res b/jscomp/test/random_test.res deleted file mode 100644 index e48ccdb91a..0000000000 --- a/jscomp/test/random_test.res +++ /dev/null @@ -1,35 +0,0 @@ -let id = ref(0) -let suites = ref(list{}) - -let eq = f => Mt_global.collect_eq(id, suites, f, ...) -let neq = f => Mt_global.collect_neq(id, suites, f, ...) -let approx = f => Mt_global.collect_approx(id, suites, f, ...) - -let () = neq(__LOC__)( - { - Random.self_init() - Random.int(10000) - }, - { - Random.self_init() - Random.int(1000) - }, -) - -/* determinism acutally */ -let v = Random.init(0) - -let v = Array.make(10, false) - -let () = for i in 0 to 9 { - v[i] = Random.bool() -} -let () = eq(__LOC__)(v, [true, true, true, true, true, false, true, true, true, false]) - -let f = Random.int64(Int64.max_int) -let h = Random.int64(3L) -let vv = Random.bits() -let xx = Random.float(3.0) -let xxx = Random.int32(103l) - -let () = Mt.from_pair_suites(__MODULE__, suites.contents) diff --git a/jscomp/test/raw_hash_tbl_bench.js b/jscomp/test/raw_hash_tbl_bench.js deleted file mode 100644 index f8de383cdf..0000000000 --- a/jscomp/test/raw_hash_tbl_bench.js +++ /dev/null @@ -1,36 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Hashtbl = require("../../lib/js/hashtbl.js"); - -function bench() { - let table = Hashtbl.create(undefined, 1000000); - for (let i = 0; i <= 1000000; ++i) { - Hashtbl.add(table, i, i); - } - for (let i$1 = 0; i$1 <= 1000000; ++i$1) { - if (!Hashtbl.mem(table, i$1)) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "raw_hash_tbl_bench.res", - 8, - 4 - ], - Error: new Error() - }; - } - - } - for (let i$2 = 0; i$2 <= 1000000; ++i$2) { - Hashtbl.remove(table, i$2); - } -} - -bench(); - -let count = 1000000; - -exports.count = count; -exports.bench = bench; -/* Not a pure module */ diff --git a/jscomp/test/raw_hash_tbl_bench.res b/jscomp/test/raw_hash_tbl_bench.res deleted file mode 100644 index 0e19e2e2c4..0000000000 --- a/jscomp/test/raw_hash_tbl_bench.res +++ /dev/null @@ -1,15 +0,0 @@ -let count = 1_000_000 -let bench = () => { - let table = Hashtbl.create(1_000_000) - for i in 0 to count { - Hashtbl.add(table, i, i) - } - for i in 0 to count { - assert(Hashtbl.mem(table, i)) - } - for i in 0 to count { - Hashtbl.remove(table, i) - } -} - -bench() diff --git a/jscomp/test/raw_pure_test.js b/jscomp/test/raw_pure_test.js index d25fdd6914..8a2e554ede 100644 --- a/jscomp/test/raw_pure_test.js +++ b/jscomp/test/raw_pure_test.js @@ -5,7 +5,7 @@ // hello 'use strict'; -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let x0 = null; @@ -23,7 +23,7 @@ function f(x) { return x; } -let hh = List.length; +let hh = Belt_List.length; exports.x0 = x0; exports.x2 = x2; diff --git a/jscomp/test/raw_pure_test.res b/jscomp/test/raw_pure_test.res index 4dca38755b..7f5617c6a7 100644 --- a/jscomp/test/raw_pure_test.res +++ b/jscomp/test/raw_pure_test.res @@ -22,7 +22,7 @@ let x3 = %raw(`/ghoghos/`) `) let f = %raw("/*hello*/ 0 ") -let hh = List.length +let hh = Belt.List.length let f = x => { ignore( %raw("//eslint-disable diff --git a/jscomp/test/reactDOMRe.res b/jscomp/test/reactDOMRe.res index 8b9b8bb68c..1b3801d6dd 100644 --- a/jscomp/test/reactDOMRe.res +++ b/jscomp/test/reactDOMRe.res @@ -21,7 +21,7 @@ let renderToElementWithClassName = (reactElement, className) => (className ++ " found in the HTML."), ) - | elements => render(reactElement, Array.unsafe_get(elements, 0)) + | elements => render(reactElement, Belt.Array.getUnsafe(elements, 0)) } let renderToElementWithId = (reactElement, id) => @@ -49,7 +49,7 @@ module Experimental = { (className ++ " found in the HTML."), ) - | elements => Ok(createRoot(Array.unsafe_get(elements, 0))) + | elements => Ok(createRoot(Belt.Array.getUnsafe(elements, 0))) } let createRootWithId = id => @@ -73,7 +73,7 @@ let hydrateToElementWithClassName = (reactElement, className) => (className ++ " found in the HTML."), ) - | elements => hydrate(reactElement, Array.unsafe_get(elements, 0)) + | elements => hydrate(reactElement, Belt.Array.getUnsafe(elements, 0)) } let hydrateToElementWithId = (reactElement, id) => diff --git a/jscomp/test/reactTestUtils.js b/jscomp/test/reactTestUtils.js index 946b17773f..26942dd073 100644 --- a/jscomp/test/reactTestUtils.js +++ b/jscomp/test/reactTestUtils.js @@ -3,7 +3,7 @@ let Belt_Array = require("../../lib/js/belt_Array.js"); let Belt_Option = require("../../lib/js/belt_Option.js"); -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); let TestUtils = require("react-dom/test-utils"); function act(func) { @@ -66,7 +66,7 @@ let DOM = { function prepareContainer(container, param) { let containerElement = document.createElement("div"); Belt_Option.map(document.body, body => body.appendChild(containerElement)); - container.contents = Caml_option.some(containerElement); + container.contents = Primitive_option.some(containerElement); } function cleanupContainer(container, param) { diff --git a/jscomp/test/reasonReact.js b/jscomp/test/reasonReact.js index afbce1d035..daf33e32c8 100644 --- a/jscomp/test/reasonReact.js +++ b/jscomp/test/reasonReact.js @@ -84,7 +84,8 @@ function element(keyOpt, refOpt, component) { } function wrapReasonForJs(component, jsPropsToReason) { - let uncurriedJsPropsToReason = jsProps => jsPropsToReason(jsProps); + let jsPropsToReason$1 = jsPropsToReason; + let uncurriedJsPropsToReason = jsProps => jsPropsToReason$1(jsProps); component.reactClassInternal.prototype.jsPropsToReason = uncurriedJsPropsToReason; return component.reactClassInternal; } diff --git a/jscomp/test/reasonReactRouter.js b/jscomp/test/reasonReactRouter.js index 0c2e3102bc..fb23304d77 100644 --- a/jscomp/test/reasonReactRouter.js +++ b/jscomp/test/reasonReactRouter.js @@ -2,7 +2,7 @@ 'use strict'; let React = require("react"); -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); function safeMakeEvent(eventName) { if (typeof Event === "function") { @@ -18,7 +18,7 @@ function path() { if (window === undefined) { return /* [] */0; } - let raw = Caml_option.valFromOption(window).location.pathname; + let raw = Primitive_option.valFromOption(window).location.pathname; switch (raw) { case "" : case "/" : @@ -51,7 +51,7 @@ function hash() { if (window === undefined) { return ""; } - let raw = Caml_option.valFromOption(window).location.hash; + let raw = Primitive_option.valFromOption(window).location.hash; switch (raw) { case "" : case "#" : @@ -66,7 +66,7 @@ function search() { if (window === undefined) { return ""; } - let raw = Caml_option.valFromOption(window).location.search; + let raw = Primitive_option.valFromOption(window).location.search; switch (raw) { case "" : case "?" : @@ -80,8 +80,8 @@ function push(path) { let match = globalThis.history; let match$1 = globalThis.window; if (match !== undefined && match$1 !== undefined) { - Caml_option.valFromOption(match).pushState(null, "", path); - Caml_option.valFromOption(match$1).dispatchEvent(safeMakeEvent("popstate")); + Primitive_option.valFromOption(match).pushState(null, "", path); + Primitive_option.valFromOption(match$1).dispatchEvent(safeMakeEvent("popstate")); return; } @@ -91,8 +91,8 @@ function replace(path) { let match = globalThis.history; let match$1 = globalThis.window; if (match !== undefined && match$1 !== undefined) { - Caml_option.valFromOption(match).replaceState(null, "", path); - Caml_option.valFromOption(match$1).dispatchEvent(safeMakeEvent("popstate")); + Primitive_option.valFromOption(match).replaceState(null, "", path); + Primitive_option.valFromOption(match$1).dispatchEvent(safeMakeEvent("popstate")); return; } @@ -141,14 +141,14 @@ function watchUrl(callback) { return () => {}; } let watcherID = () => callback(url()); - Caml_option.valFromOption(window).addEventListener("popstate", watcherID); + Primitive_option.valFromOption(window).addEventListener("popstate", watcherID); return watcherID; } function unwatchUrl(watcherID) { let window = globalThis.window; if (window !== undefined) { - Caml_option.valFromOption(window).removeEventListener("popstate", watcherID); + Primitive_option.valFromOption(window).removeEventListener("popstate", watcherID); return; } diff --git a/jscomp/test/reasonReactRouter.res b/jscomp/test/reasonReactRouter.res index 1d60ed77cb..295ab3d413 100644 --- a/jscomp/test/reasonReactRouter.res +++ b/jscomp/test/reasonReactRouter.res @@ -51,11 +51,12 @@ let safeMakeEvent = eventName => /* This is copied from array.ml. We want to cut dependencies for ReasonReact so that it's friendlier to use in size-constrained codebases */ let arrayToList = a => { + open Belt let rec tolist = (i, res) => if i < 0 { res } else { - tolist(i - 1, list{Array.unsafe_get(a, i), ...res}) + tolist(i - 1, list{Array.getUnsafe(a, i), ...res}) } tolist(Array.length(a) - 1, list{}) } diff --git a/jscomp/test/rebind_module.js b/jscomp/test/rebind_module.js index 0c9c8b6925..f3b7a8247b 100644 --- a/jscomp/test/rebind_module.js +++ b/jscomp/test/rebind_module.js @@ -1,11 +1,11 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); -let A = /* @__PURE__ */Caml_exceptions.create("Rebind_module.A"); +let A = /* @__PURE__ */Primitive_exceptions.create("Rebind_module.A"); -let AA = /* @__PURE__ */Caml_exceptions.create("Rebind_module.AA"); +let AA = /* @__PURE__ */Primitive_exceptions.create("Rebind_module.AA"); exports.A = A; exports.AA = AA; diff --git a/jscomp/test/rec_array_test.js b/jscomp/test/rec_array_test.js index 24b46d28c4..d506b66f9c 100644 --- a/jscomp/test/rec_array_test.js +++ b/jscomp/test/rec_array_test.js @@ -1,17 +1,17 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_obj = require("../../lib/js/caml_obj.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); let vicky = {}; let teacher = {}; -Caml_obj.update_dummy(vicky, { +Primitive_object.updateDummy(vicky, { taughtBy: teacher }); -Caml_obj.update_dummy(teacher, { +Primitive_object.updateDummy(teacher, { students: [vicky] }); diff --git a/jscomp/test/rec_fun_test.js b/jscomp/test/rec_fun_test.js index c29dad5067..ef75d908b9 100644 --- a/jscomp/test/rec_fun_test.js +++ b/jscomp/test/rec_fun_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); let suites = { contents: /* [] */0 @@ -16,7 +16,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -40,10 +40,10 @@ function g() { } return i + 1 | 0; }; - Caml_obj.update_dummy(v, { + Primitive_object.updateDummy(v, { contents: next }); - console.log(String(next(0, true))); + console.log(next(0, true).toString()); } g(); @@ -52,17 +52,17 @@ let x = {}; let y = {}; -Caml_obj.update_dummy(x, { +Primitive_object.updateDummy(x, { hd: 1, tl: y }); -Caml_obj.update_dummy(y, { +Primitive_object.updateDummy(y, { hd: 2, tl: x }); -eq("File \"rec_fun_test.res\", line 29, characters 3-10", called.contents, 2); +eq("File \"rec_fun_test.res\", line 32, characters 3-10", called.contents, 2); Mt.from_pair_suites("Rec_fun_test", suites.contents); diff --git a/jscomp/test/rec_fun_test.res b/jscomp/test/rec_fun_test.res index ee57d1d11b..b7b7edf5d4 100644 --- a/jscomp/test/rec_fun_test.res +++ b/jscomp/test/rec_fun_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let called = ref(0) @@ -18,7 +21,7 @@ let g = () => { i + 1 } - print_endline(\"@@"(string_of_int, next(0, true))) + Js.log(\"@@"(Js.Int.toString, next(0, true))) } g() diff --git a/jscomp/test/rec_module_opt.js b/jscomp/test/rec_module_opt.js index 61b06f835b..53bd9e6b65 100644 --- a/jscomp/test/rec_module_opt.js +++ b/jscomp/test/rec_module_opt.js @@ -1,11 +1,12 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let $$Set = require("../../lib/js/set.js"); -let Caml = require("../../lib/js/caml.js"); -let Caml_module = require("../../lib/js/caml_module.js"); +let Obj = require("../../lib/js/obj.js"); +let Belt_Id = require("../../lib/js/belt_Id.js"); +let Primitive_module = require("../../lib/js/primitive_module.js"); +let Primitive_string = require("../../lib/js/primitive_string.js"); -let A = Caml_module.init_mod([ +let A = Primitive_module.init([ "rec_module_opt.res", 15, 4 @@ -13,41 +14,41 @@ let A = Caml_module.init_mod([ TAG: "Module", _0: [[ "Function", - "compare" + "cmp" ]] }); -let ASet = $$Set.Make(A); +let AComparable = Belt_Id.MakeComparable(A); -function compare(t1, t2) { +function cmp(t1, t2) { if (t1.TAG === "Leaf") { if (t2.TAG === "Leaf") { - return Caml.string_compare(t1._0, t2._0); + return Primitive_string.compare(t1._0, t2._0); } else { return 1; } } else if (t2.TAG === "Leaf") { return -1; } else { - return ASet.compare(t1._0, t2._0); + return Obj.magic(AComparable.cmp)(t1._0, t2._0); } } -Caml_module.update_mod({ +Primitive_module.update({ TAG: "Module", _0: [[ "Function", - "compare" + "cmp" ]] }, A, { - compare: compare + cmp: cmp }); let X0 = {}; let Y0 = {}; -let X1 = Caml_module.init_mod([ +let X1 = Primitive_module.init([ "rec_module_opt.res", 44, 19 @@ -59,7 +60,7 @@ let X1 = Caml_module.init_mod([ ]] }); -let Y1 = Caml_module.init_mod([ +let Y1 = Primitive_module.init([ "rec_module_opt.res", 47, 12 @@ -75,7 +76,7 @@ function f(x) { return x + 1 | 0; } -Caml_module.update_mod({ +Primitive_module.update({ TAG: "Module", _0: [[ "Function", @@ -89,7 +90,7 @@ function f$1(x) { return x + 2 | 0; } -Caml_module.update_mod({ +Primitive_module.update({ TAG: "Module", _0: [[ "Function", @@ -102,7 +103,7 @@ Caml_module.update_mod({ let X; exports.A = A; -exports.ASet = ASet; +exports.AComparable = AComparable; exports.X = X; exports.X0 = X0; exports.Y0 = Y0; diff --git a/jscomp/test/rec_module_opt.res b/jscomp/test/rec_module_opt.res index a3e36cdda7..224a66ea6c 100644 --- a/jscomp/test/rec_module_opt.res +++ b/jscomp/test/rec_module_opt.res @@ -10,20 +10,20 @@ }) module rec A: { - type t = Leaf(string) | Node(ASet.t) - let compare: (t, t) => int + type t = Leaf(string) | Node(AComparable.t) + let cmp: (t, t) => int } = { - type t = Leaf(string) | Node(ASet.t) - let compare = (t1, t2) => + type t = Leaf(string) | Node(AComparable.t) + let cmp = (t1, t2) => switch (t1, t2) { | (Leaf(s1), Leaf(s2)) => Pervasives.compare(s1, s2) | (Leaf(_), Node(_)) => 1 | (Node(_), Leaf(_)) => -1 - | (Node(n1), Node(n2)) => ASet.compare(n1, n2) + | (Node(n1), Node(n2)) => Obj.magic(AComparable.cmp)(n1, n2) } let hello = x => x } -and ASet: Set.S with type elt = A.t = Set.Make(A) +and AComparable: Belt.Id.Comparable with type t = A.t = Belt.Id.MakeComparable(A) module rec X: {} = X diff --git a/jscomp/test/rec_module_test.js b/jscomp/test/rec_module_test.js index 93c8ff239d..b69fc9201c 100644 --- a/jscomp/test/rec_module_test.js +++ b/jscomp/test/rec_module_test.js @@ -2,12 +2,9 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml = require("../../lib/js/caml.js"); -let List = require("../../lib/js/list.js"); -let Caml_module = require("../../lib/js/caml_module.js"); -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_module = require("../../lib/js/primitive_module.js"); -let A = Caml_module.init_mod([ +let A = Primitive_module.init([ "rec_module_test.res", 3, 4 @@ -19,7 +16,7 @@ let A = Caml_module.init_mod([ ]] }); -let B = Caml_module.init_mod([ +let B = Primitive_module.init([ "rec_module_test.res", 15, 4 @@ -41,7 +38,7 @@ function even(n) { } } -Caml_module.update_mod({ +Primitive_module.update({ TAG: "Module", _0: [[ "Function", @@ -61,7 +58,7 @@ function odd(n) { } } -Caml_module.update_mod({ +Primitive_module.update({ TAG: "Module", _0: [[ "Function", @@ -71,7 +68,7 @@ Caml_module.update_mod({ odd: odd }); -let AA = Caml_module.init_mod([ +let AA = Primitive_module.init([ "rec_module_test.res", 29, 4 @@ -89,7 +86,7 @@ let AA = Caml_module.init_mod([ ] }); -let BB = Caml_module.init_mod([ +let BB = Primitive_module.init([ "rec_module_test.res", 43, 4 @@ -121,7 +118,7 @@ function x() { return BB.y() + 3 | 0; } -Caml_module.update_mod({ +Primitive_module.update({ TAG: "Module", _0: [ [ @@ -152,7 +149,7 @@ function y() { return 32; } -Caml_module.update_mod({ +Primitive_module.update({ TAG: "Module", _0: [ [ @@ -173,1038 +170,6 @@ let Even = {}; let Odd = {}; -let AAA = Caml_module.init_mod([ - "rec_module_test.res", - 69, - 4 -], { - TAG: "Module", - _0: [[ - "Function", - "compare" - ]] -}); - -function height(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} - -function create(l, v, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} - -function bal(l, v, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - let lr = l.r; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, create(lr, v, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, lr.l), lr.v, create(lr.r, v, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - let rr = r.r; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, v, rl), rv, rr); - } - if (typeof rl === "object") { - return create(create(l, v, rl.l), rl.v, create(rl.r, rv, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; -} - -function add(x, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = AAA.compare(x, v); - if (c === 0) { - return param; - } - if (c < 0) { - let ll = add(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = add(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } -} - -function singleton(x) { - return { - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }; -} - -function add_min_element(x, param) { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(add_min_element(x, param.l), param.v, param.r); - } -} - -function add_max_element(x, param) { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(param.l, param.v, add_max_element(x, param.r)); - } -} - -function join(l, v, r) { - if (typeof l !== "object") { - return add_min_element(v, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_element(v, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, join(l.r, v, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, r.l), r.v, r.r); - } else { - return create(l, v, r); - } -} - -function min_elt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.v; - } - _param = l; - continue; - }; -} - -function min_elt_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return Caml_option.some(param.v); - } - _param = l; - continue; - }; -} - -function max_elt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let r = param.r; - if (typeof r !== "object") { - return param.v; - } - _param = r; - continue; - }; -} - -function max_elt_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return Caml_option.some(param.v); - } - _param = r; - continue; - }; -} - -function remove_min_elt(param) { - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.remove_min_elt", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_elt(l), param.v, param.r); - } -} - -function concat(t1, t2) { - if (typeof t1 !== "object") { - return t2; - } else if (typeof t2 !== "object") { - return t1; - } else { - return join(t1, min_elt(t2), remove_min_elt(t2)); - } -} - -function split(x, param) { - if (typeof param !== "object") { - return [ - "Empty", - false, - "Empty" - ]; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = AAA.compare(x, v); - if (c === 0) { - return [ - l, - true, - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, match$1[0]), - match$1[1], - match$1[2] - ]; -} - -function is_empty(param) { - if (typeof param !== "object") { - return true; - } else { - return false; - } -} - -function mem(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = AAA.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function remove(x, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = AAA.compare(x, v); - if (c === 0) { - if (typeof l !== "object") { - return r; - } else if (typeof r !== "object") { - return l; - } else { - return bal(l, min_elt(r), remove_min_elt(r)); - } - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } -} - -function union(s1, s2) { - if (typeof s1 !== "object") { - return s2; - } - let h1 = s1.h; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let h2 = s2.h; - let v2 = s2.v; - if (h1 >= h2) { - if (h2 === 1) { - return add(v2, s1); - } - let match = split(v1, s2); - return join(union(s1.l, match[0]), v1, union(s1.r, match[2])); - } - if (h1 === 1) { - return add(v1, s2); - } - let match$1 = split(v2, s1); - return join(union(match$1[0], s2.l), v2, union(match$1[2], s2.r)); -} - -function inter(s1, s2) { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return "Empty"; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return join(inter(l1, l2), v1, inter(r1, match[2])); - } else { - return concat(inter(l1, l2), inter(r1, match[2])); - } -} - -function diff(s1, s2) { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return s1; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return concat(diff(l1, l2), diff(r1, match[2])); - } else { - return join(diff(l1, l2), v1, diff(r1, match[2])); - } -} - -function cons_enum(_s, _e) { - while (true) { - let e = _e; - let s = _s; - if (typeof s !== "object") { - return e; - } - _e = { - TAG: "More", - _0: s.v, - _1: s.r, - _2: e - }; - _s = s.l; - continue; - }; -} - -function compare(s1, s2) { - let _e1 = cons_enum(s1, "End"); - let _e2 = cons_enum(s2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = AAA.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - _e2 = cons_enum(e2._1, e2._2); - _e1 = cons_enum(e1._1, e1._2); - continue; - }; -} - -function equal(s1, s2) { - return compare(s1, s2) === 0; -} - -function subset(_s1, _s2) { - while (true) { - let s2 = _s2; - let s1 = _s1; - if (typeof s1 !== "object") { - return true; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - if (typeof s2 !== "object") { - return false; - } - let r2 = s2.r; - let l2 = s2.l; - let c = AAA.compare(v1, s2.v); - if (c === 0) { - if (!subset(l1, l2)) { - return false; - } - _s2 = r2; - _s1 = r1; - continue; - } - if (c < 0) { - if (!subset({ - TAG: "Node", - l: l1, - v: v1, - r: "Empty", - h: 0 - }, l2)) { - return false; - } - _s1 = r1; - continue; - } - if (!subset({ - TAG: "Node", - l: "Empty", - v: v1, - r: r1, - h: 0 - }, r2)) { - return false; - } - _s1 = l1; - continue; - }; -} - -function iter(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v); - _param = param.r; - continue; - }; -} - -function fold(f, _s, _accu) { - while (true) { - let accu = _accu; - let s = _s; - if (typeof s !== "object") { - return accu; - } - _accu = f(s.v, fold(f, s.l, accu)); - _s = s.r; - continue; - }; -} - -function for_all(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; -} - -function exists(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; -} - -function filter(p, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pv = p(v); - let r$p = filter(p, r); - if (pv) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, r$p); - } - } else { - return concat(l$p, r$p); - } -} - -function partition(p, param) { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pv = p(v); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pv) { - return [ - join(lt, v, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, rf) - ]; - } -} - -function cardinal(param) { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } -} - -function elements_aux(_accu, _param) { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: param.v, - tl: elements_aux(accu, param.r) - }; - continue; - }; -} - -function elements(s) { - return elements_aux(/* [] */0, s); -} - -function find(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - let c = AAA.compare(x, v); - if (c === 0) { - return v; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function find_first(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return v0; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_first_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return Caml_option.some(v0); - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_last(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return v0; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_last_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return Caml_option.some(v0); - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_opt(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - let c = AAA.compare(x, v); - if (c === 0) { - return Caml_option.some(v); - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function map(f, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = map(f, l); - let v$p = f(v); - let r$p = map(f, r); - if (l === l$p && v === v$p && r === r$p) { - return param; - } else if ((l$p === "Empty" || AAA.compare(max_elt(l$p), v$p) < 0) && (r$p === "Empty" || AAA.compare(v$p, min_elt(r$p)) < 0)) { - return join(l$p, v$p, r$p); - } else { - return union(l$p, add(v$p, r$p)); - } -} - -function of_list(l) { - if (!l) { - return "Empty"; - } - let match = l.tl; - let x0 = l.hd; - if (!match) { - return singleton(x0); - } - let match$1 = match.tl; - let x1 = match.hd; - if (!match$1) { - return add(x1, singleton(x0)); - } - let match$2 = match$1.tl; - let x2 = match$1.hd; - if (!match$2) { - return add(x2, add(x1, singleton(x0))); - } - let match$3 = match$2.tl; - let x3 = match$2.hd; - if (match$3) { - if (match$3.tl) { - let l$1 = List.sort_uniq(AAA.compare, l); - let sub = (n, l) => { - switch (n) { - case 0 : - return [ - "Empty", - l - ]; - case 1 : - if (l) { - return [ - { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - l.tl - ]; - } - break; - case 2 : - if (l) { - let match = l.tl; - if (match) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match.hd, - r: "Empty", - h: 2 - }, - match.tl - ]; - } - - } - break; - case 3 : - if (l) { - let match$1 = l.tl; - if (match$1) { - let match$2 = match$1.tl; - if (match$2) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match$1.hd, - r: { - TAG: "Node", - l: "Empty", - v: match$2.hd, - r: "Empty", - h: 1 - }, - h: 2 - }, - match$2.tl - ]; - } - - } - - } - break; - } - let nl = n / 2 | 0; - let match$3 = sub(nl, l); - let l$1 = match$3[1]; - if (l$1) { - let match$4 = sub((n - nl | 0) - 1 | 0, l$1.tl); - return [ - create(match$3[0], l$1.hd, match$4[0]), - match$4[1] - ]; - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "set.res", - 691, - 20 - ], - Error: new Error() - }; - }; - return sub(List.length(l$1), l$1)[0]; - } else { - return add(match$3.hd, add(x3, add(x2, add(x1, singleton(x0))))); - } - } else { - return add(x3, add(x2, add(x1, singleton(x0)))); - } -} - -let ASet = { - empty: "Empty", - is_empty: is_empty, - mem: mem, - add: add, - singleton: singleton, - remove: remove, - union: union, - inter: inter, - diff: diff, - compare: compare, - equal: equal, - subset: subset, - iter: iter, - map: map, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - elements: elements, - min_elt: min_elt, - min_elt_opt: min_elt_opt, - max_elt: max_elt, - max_elt_opt: max_elt_opt, - choose: min_elt, - choose_opt: min_elt_opt, - split: split, - find: find, - find_opt: find_opt, - find_first: find_first, - find_first_opt: find_first_opt, - find_last: find_last, - find_last_opt: find_last_opt, - of_list: of_list -}; - -function compare$1(t1, t2) { - if (t1.TAG === "Leaf") { - if (t2.TAG === "Leaf") { - return Caml.string_compare(t1._0, t2._0); - } else { - return 1; - } - } else if (t2.TAG === "Leaf") { - return -1; - } else { - return compare(t1._0, t2._0); - } -} - -Caml_module.update_mod({ - TAG: "Module", - _0: [[ - "Function", - "compare" - ]] -}, AAA, { - compare: compare$1 -}); - let suites_0 = [ "test1", param => ({ @@ -1269,35 +234,7 @@ let suites_1 = { _1: B.odd(2) }) ], - tl: { - hd: [ - "test6", - param => ({ - TAG: "Eq", - _0: 2, - _1: cardinal(of_list({ - hd: { - TAG: "Leaf", - _0: "a" - }, - tl: { - hd: { - TAG: "Leaf", - _0: "b" - }, - tl: { - hd: { - TAG: "Leaf", - _0: "a" - }, - tl: /* [] */0 - } - } - })) - }) - ], - tl: /* [] */0 - } + tl: /* [] */0 } } } @@ -1317,7 +254,5 @@ exports.AA = AA; exports.BB = BB; exports.Even = Even; exports.Odd = Odd; -exports.AAA = AAA; -exports.ASet = ASet; exports.suites = suites; /* A Not a pure module */ diff --git a/jscomp/test/rec_module_test.res b/jscomp/test/rec_module_test.res index d549ac63a7..a66cc7c017 100644 --- a/jscomp/test/rec_module_test.res +++ b/jscomp/test/rec_module_test.res @@ -63,21 +63,6 @@ and Odd: { type t = Succ(Even.t) } -module rec AAA: { - type t = Leaf(string) | Node(ASet.t) - let compare: (t, t) => int -} = { - type t = Leaf(string) | Node(ASet.t) - let compare = (t1, t2) => - switch (t1, t2) { - | (Leaf(s1), Leaf(s2)) => Pervasives.compare(s1, s2) - | (Leaf(_), Node(_)) => 1 - | (Node(_), Leaf(_)) => -1 - | (Node(n1), Node(n2)) => ASet.compare(n1, n2) - } -} -and ASet: Set.S with type elt = AAA.t = Set.Make(AAA) - let suites = { open Mt list{ @@ -87,7 +72,6 @@ let suites = { ("test4", _ => Eq(true, A.even(2))), ("test4", _ => Eq(true, AA.even(4))), ("test5", _ => Eq(false, B.odd(2))), - ("test6", _ => Eq(2, ASet.cardinal(ASet.of_list(list{Leaf("a"), Leaf("b"), Leaf("a")})))), } } diff --git a/jscomp/test/recmodule.js b/jscomp/test/recmodule.js index f500c27bd8..c5a87cdd90 100644 --- a/jscomp/test/recmodule.js +++ b/jscomp/test/recmodule.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_module = require("../../lib/js/caml_module.js"); +let Primitive_module = require("../../lib/js/primitive_module.js"); let Entity = {}; @@ -58,7 +58,7 @@ let Infra = { MakeLayer: MakeLayer$2 }; -let I = Caml_module.init_mod([ +let I = Primitive_module.init([ "recmodule.res", 67, 30 @@ -76,7 +76,7 @@ let I = Caml_module.init_mod([ ] }); -let A = Caml_module.init_mod([ +let A = Primitive_module.init([ "recmodule.res", 68, 25 @@ -94,7 +94,7 @@ let A = Caml_module.init_mod([ ] }); -let U = Caml_module.init_mod([ +let U = Primitive_module.init([ "recmodule.res", 69, 25 @@ -125,7 +125,7 @@ function routes() { ]]; } -Caml_module.update_mod({ +Primitive_module.update({ TAG: "Module", _0: [ [ @@ -150,7 +150,7 @@ function handleGetLight(req) { return U.getLight(req.params.id); } -Caml_module.update_mod({ +Primitive_module.update({ TAG: "Module", _0: [ [ @@ -174,7 +174,7 @@ function getLight(id) { }); } -Caml_module.update_mod({ +Primitive_module.update({ TAG: "Module", _0: [[ "Function", diff --git a/jscomp/test/record_debug_test.js b/jscomp/test/record_debug_test.js index 5440c26437..b7de4bc22c 100644 --- a/jscomp/test/record_debug_test.js +++ b/jscomp/test/record_debug_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); let suites = { contents: /* [] */0 @@ -36,9 +36,9 @@ let u = { b: u_b }; -let A = /* @__PURE__ */Caml_exceptions.create("Record_debug_test.A"); +let A = /* @__PURE__ */Primitive_exceptions.create("Record_debug_test.A"); -let B = /* @__PURE__ */Caml_exceptions.create("Record_debug_test.B"); +let B = /* @__PURE__ */Primitive_exceptions.create("Record_debug_test.B"); let v0 = { RE_EXN_ID: A, diff --git a/jscomp/test/record_extension_test.js b/jscomp/test/record_extension_test.js index 9a01bc12ee..0091bb3cb8 100644 --- a/jscomp/test/record_extension_test.js +++ b/jscomp/test/record_extension_test.js @@ -2,9 +2,8 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_format = require("../../lib/js/caml_format.js"); -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); +let Belt_Int = require("../../lib/js/belt_Int.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); let suites = { contents: /* [] */0 @@ -18,36 +17,46 @@ function eq(loc, x, y) { Mt.eq_suites(test_id, suites, loc, x, y); } -let Inline_record = /* @__PURE__ */Caml_exceptions.create("Record_extension_test.Inline_record"); +let Inline_record = /* @__PURE__ */Primitive_exceptions.create("Record_extension_test.Inline_record"); -let SinglePayload = /* @__PURE__ */Caml_exceptions.create("Record_extension_test.SinglePayload"); +let SinglePayload = /* @__PURE__ */Primitive_exceptions.create("Record_extension_test.SinglePayload"); -let TuplePayload = /* @__PURE__ */Caml_exceptions.create("Record_extension_test.TuplePayload"); +let TuplePayload = /* @__PURE__ */Primitive_exceptions.create("Record_extension_test.TuplePayload"); function f(x) { if (x.RE_EXN_ID === Inline_record) { - return x.x + Caml_format.int_of_string(x.y) | 0; - } else if (x.RE_EXN_ID === SinglePayload) { - return Caml_format.int_of_string(x._1); - } else if (x.RE_EXN_ID === TuplePayload) { - return x._1 + Caml_format.int_of_string(x._2) | 0; - } else { + let y = Belt_Int.fromString(x.y); + if (y !== undefined) { + return x.x + y | 0; + } else { + return; + } + } + if (x.RE_EXN_ID === SinglePayload) { + return Belt_Int.fromString(x._1); + } + if (x.RE_EXN_ID !== TuplePayload) { return; } + let v1 = Belt_Int.fromString(x._2); + if (v1 !== undefined) { + return x._1 + v1 | 0; + } + } -eq("File \"record_extension_test.res\", line 20, characters 3-10", f({ +eq("File \"record_extension_test.res\", line 28, characters 3-10", f({ RE_EXN_ID: Inline_record, x: 3, y: "4" }), 7); -eq("File \"record_extension_test.res\", line 21, characters 3-10", f({ +eq("File \"record_extension_test.res\", line 29, characters 3-10", f({ RE_EXN_ID: SinglePayload, _1: "1" }), 1); -eq("File \"record_extension_test.res\", line 22, characters 3-10", f({ +eq("File \"record_extension_test.res\", line 30, characters 3-10", f({ RE_EXN_ID: TuplePayload, _1: 1, _2: "2" @@ -73,17 +82,17 @@ function f2_with(x) { } } -let A = /* @__PURE__ */Caml_exceptions.create("Record_extension_test.A"); +let A = /* @__PURE__ */Primitive_exceptions.create("Record_extension_test.A"); -let B = /* @__PURE__ */Caml_exceptions.create("Record_extension_test.B"); +let B = /* @__PURE__ */Primitive_exceptions.create("Record_extension_test.B"); -let C = /* @__PURE__ */Caml_exceptions.create("Record_extension_test.C"); +let C = /* @__PURE__ */Primitive_exceptions.create("Record_extension_test.C"); function u(f) { try { return f(); } catch (raw_x) { - let x = Caml_js_exceptions.internalToOCamlException(raw_x); + let x = Primitive_exceptions.internalToException(raw_x); if (x.RE_EXN_ID === A) { return x.name + x.x | 0; } else if (x.RE_EXN_ID === B) { @@ -96,7 +105,7 @@ function u(f) { } } -eq("File \"record_extension_test.res\", line 59, characters 3-10", u(() => { +eq("File \"record_extension_test.res\", line 67, characters 3-10", u(() => { throw { RE_EXN_ID: A, name: 1, @@ -105,7 +114,7 @@ eq("File \"record_extension_test.res\", line 59, characters 3-10", u(() => { }; }), 2); -eq("File \"record_extension_test.res\", line 60, characters 3-10", u(() => { +eq("File \"record_extension_test.res\", line 68, characters 3-10", u(() => { throw { RE_EXN_ID: B, _1: 1, @@ -114,7 +123,7 @@ eq("File \"record_extension_test.res\", line 60, characters 3-10", u(() => { }; }), 3); -eq("File \"record_extension_test.res\", line 61, characters 3-10", u(() => { +eq("File \"record_extension_test.res\", line 69, characters 3-10", u(() => { throw { RE_EXN_ID: C, name: 4, @@ -122,7 +131,7 @@ eq("File \"record_extension_test.res\", line 61, characters 3-10", u(() => { }; }), 4); -Mt.from_pair_suites("File \"record_extension_test.res\", line 63, characters 29-36", suites.contents); +Mt.from_pair_suites("File \"record_extension_test.res\", line 71, characters 29-36", suites.contents); exports.suites = suites; exports.test_id = test_id; diff --git a/jscomp/test/record_extension_test.res b/jscomp/test/record_extension_test.res index 1410d40d8c..c10eb53ee8 100644 --- a/jscomp/test/record_extension_test.res +++ b/jscomp/test/record_extension_test.res @@ -11,9 +11,17 @@ type t0 += SinglePayload(string) | TuplePayload(int, string) let f = x => switch x { - | Inline_record({x, y}) => Some(x + int_of_string(y)) - | SinglePayload(v) => Some(int_of_string(v)) - | TuplePayload(v0, v1) => Some(v0 + int_of_string(v1)) + | Inline_record({x, y}) => + switch Belt.Int.fromString(y) { + | Some(y) => Some(x + y) + | _ => None + } + | SinglePayload(v) => Belt.Int.fromString(v) + | TuplePayload(v0, v1) => + switch Belt.Int.fromString(v1) { + | Some(v1) => Some(v0 + v1) + | _ => None + } | _ => None } diff --git a/jscomp/test/record_regression.js b/jscomp/test/record_regression.js index b734edba54..4d1ccad64c 100644 --- a/jscomp/test/record_regression.js +++ b/jscomp/test/record_regression.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); let f1 = { x: 3, @@ -14,11 +14,11 @@ newrecord.y = 3; let newrecord$1 = {...newrecord}; -newrecord$1.yy = Caml_option.some(undefined); +newrecord$1.yy = Primitive_option.some(undefined); let theseTwoShouldBeIdentical = [ newrecord$1.yy, - Caml_option.some(undefined) + Primitive_option.some(undefined) ]; let v = { diff --git a/jscomp/test/recursive_module.js b/jscomp/test/recursive_module.js index 25f412c863..51423dc9a3 100644 --- a/jscomp/test/recursive_module.js +++ b/jscomp/test/recursive_module.js @@ -3,9 +3,8 @@ let Mt = require("./mt.js"); let Lazy = require("../../lib/js/lazy.js"); -let Caml_module = require("../../lib/js/caml_module.js"); -let CamlinternalLazy = require("../../lib/js/camlinternalLazy.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); +let Primitive_module = require("../../lib/js/primitive_module.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); let suites = { contents: /* [] */0 @@ -23,7 +22,7 @@ let Xx = { f: (prim0, prim1) => hfiehi(prim0, prim1) }; -let Int3 = Caml_module.init_mod([ +let Int3 = Primitive_module.init([ "recursive_module.res", 25, 4 @@ -35,7 +34,7 @@ let Int3 = Caml_module.init_mod([ ]] }); -Caml_module.update_mod({ +Primitive_module.update({ TAG: "Module", _0: [[ "Function", @@ -43,7 +42,7 @@ Caml_module.update_mod({ ]] }, Int3, Int3); -let Inta = Caml_module.init_mod([ +let Inta = Primitive_module.init([ "recursive_module.res", 29, 4 @@ -55,7 +54,7 @@ let Inta = Caml_module.init_mod([ ]] }); -let Intb = Caml_module.init_mod([ +let Intb = Primitive_module.init([ "recursive_module.res", 34, 4 @@ -67,9 +66,9 @@ let Intb = Caml_module.init_mod([ ]] }); -let a = CamlinternalLazy.from_fun(() => CamlinternalLazy.force(Intb.a)); +let a = Lazy.from_fun(() => Lazy.force(Intb.a)); -Caml_module.update_mod({ +Primitive_module.update({ TAG: "Module", _0: [[ "Lazy", @@ -79,9 +78,9 @@ Caml_module.update_mod({ a: a }); -let a$1 = CamlinternalLazy.from_fun(() => CamlinternalLazy.force(Inta.a) + 1 | 0); +let a$1 = Lazy.from_fun(() => Lazy.force(Inta.a) + 1 | 0); -Caml_module.update_mod({ +Primitive_module.update({ TAG: "Module", _0: [[ "Lazy", @@ -94,9 +93,9 @@ Caml_module.update_mod({ let tmp; try { - tmp = CamlinternalLazy.force(Intb.a); + tmp = Lazy.force(Intb.a); } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + let exn = Primitive_exceptions.internalToException(raw_exn); if (exn.RE_EXN_ID === Lazy.Undefined) { tmp = -1; } else { @@ -106,7 +105,7 @@ try { eq("File \"recursive_module.res\", line 39, characters 2-9", -1, tmp); -let Inta$1 = Caml_module.init_mod([ +let Inta$1 = Primitive_module.init([ "recursive_module.res", 49, 6 @@ -118,7 +117,7 @@ let Inta$1 = Caml_module.init_mod([ ]] }); -let Intb$1 = Caml_module.init_mod([ +let Intb$1 = Primitive_module.init([ "recursive_module.res", 54, 6 @@ -130,9 +129,9 @@ let Intb$1 = Caml_module.init_mod([ ]] }); -let a$2 = CamlinternalLazy.from_fun(() => CamlinternalLazy.force(Intb$1.a) + 1 | 0); +let a$2 = Lazy.from_fun(() => Lazy.force(Intb$1.a) + 1 | 0); -Caml_module.update_mod({ +Primitive_module.update({ TAG: "Module", _0: [[ "Lazy", @@ -142,9 +141,9 @@ Caml_module.update_mod({ a: a$2 }); -let a$3 = CamlinternalLazy.from_fun(() => 2); +let a$3 = Lazy.from_fun(() => 2); -Caml_module.update_mod({ +Primitive_module.update({ TAG: "Module", _0: [[ "Lazy", @@ -159,7 +158,7 @@ let A = { Intb: Intb$1 }; -eq("File \"recursive_module.res\", line 59, characters 3-10", CamlinternalLazy.force(Inta$1.a), 3); +eq("File \"recursive_module.res\", line 59, characters 3-10", Lazy.force(Inta$1.a), 3); let tmp$1; @@ -167,7 +166,7 @@ try { Int3.u(3); tmp$1 = 3; } catch (raw_exn$1) { - let exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn$1); + let exn$1 = Primitive_exceptions.internalToException(raw_exn$1); if (exn$1.RE_EXN_ID === "Undefined_recursive_module") { tmp$1 = 4; } else { diff --git a/jscomp/test/recursive_module.res b/jscomp/test/recursive_module.res index 48c4f03e17..4f7f941bea 100644 --- a/jscomp/test/recursive_module.res +++ b/jscomp/test/recursive_module.res @@ -25,12 +25,12 @@ module rec Int3: { } = Int3 module rec Inta: { - let a: lazy_t + let a: Lazy.t } = { let a = Lazy.from_fun(() => Lazy.force(Intb.a)) } and Intb: { - let a: lazy_t + let a: Lazy.t } = { let a = Lazy.from_fun(() => Lazy.force(Inta.a) + 1) } diff --git a/jscomp/test/recursive_module_test.js b/jscomp/test/recursive_module_test.js index e6360c3055..3f378f4b62 100644 --- a/jscomp/test/recursive_module_test.js +++ b/jscomp/test/recursive_module_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_module = require("../../lib/js/caml_module.js"); +let Primitive_module = require("../../lib/js/primitive_module.js"); let suites = { contents: /* [] */0 @@ -16,7 +16,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -34,9 +34,9 @@ function add(suite) { }; } -let Int3 = Caml_module.init_mod([ +let Int3 = Primitive_module.init([ "recursive_module_test.res", - 12, + 15, 4 ], { TAG: "Module", @@ -46,7 +46,7 @@ let Int3 = Caml_module.init_mod([ ]] }); -Caml_module.update_mod({ +Primitive_module.update({ TAG: "Module", _0: [[ "Function", @@ -54,9 +54,9 @@ Caml_module.update_mod({ ]] }, Int3, Int3); -let M = Caml_module.init_mod([ +let M = Primitive_module.init([ "recursive_module_test.res", - 18, + 21, 20 ], { TAG: "Module", @@ -74,7 +74,7 @@ function fact(n) { } } -Caml_module.update_mod({ +Primitive_module.update({ TAG: "Module", _0: [[ "Function", @@ -91,10 +91,10 @@ let Fact = { fact: fact$1 }; -eq("File \"recursive_module_test.res\", line 29, characters 12-19", 120, fact$1(5)); +eq("File \"recursive_module_test.res\", line 32, characters 12-19", 120, fact$1(5)); add([ - "File \"recursive_module_test.res\", line 31, characters 14-21", + "File \"recursive_module_test.res\", line 34, characters 14-21", () => ({ TAG: "ThrowAny", _0: () => { diff --git a/jscomp/test/recursive_module_test.res b/jscomp/test/recursive_module_test.res index 742ff96cf5..1315f128b3 100644 --- a/jscomp/test/recursive_module_test.res +++ b/jscomp/test/recursive_module_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let add = suite => suites := list{suite, ...suites.contents} diff --git a/jscomp/test/recursive_records_test.js b/jscomp/test/recursive_records_test.js index 20b542d691..755fc2e894 100644 --- a/jscomp/test/recursive_records_test.js +++ b/jscomp/test/recursive_records_test.js @@ -2,8 +2,8 @@ 'use strict'; let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); +let Belt_List = require("../../lib/js/belt_List.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); let suites = { contents: /* [] */0 @@ -25,7 +25,7 @@ rec_cell.next = rec_cell; function f0(x) { let rec_cell = {}; - Caml_obj.update_dummy(rec_cell, { + Primitive_object.updateDummy(rec_cell, { content: Math.imul(x, x) - 6 | 0, next: rec_cell }); @@ -48,7 +48,7 @@ rec_cell2.next = rec_cell2; function f2(x) { let rec_cell2 = {}; - Caml_obj.update_dummy(rec_cell2, { + Primitive_object.updateDummy(rec_cell2, { TAG: "Cons", content: Math.imul(x, x) - 6 | 0, next: rec_cell2 @@ -93,18 +93,18 @@ rec_cell3.tl = rec_cell3; function f3(x) { let rec_cell3 = {}; - Caml_obj.update_dummy(rec_cell3, { + Primitive_object.updateDummy(rec_cell3, { hd: Math.imul(x, x) - 6 | 0, tl: rec_cell3 }); return rec_cell3; } -eq("File \"recursive_records_test.res\", line 68, characters 4-11", (List.hd(rec_cell3) + List.hd(List.tl(rec_cell3)) | 0) + List.hd(List.tl(List.tl(rec_cell3))) | 0, 9); +eq("File \"recursive_records_test.res\", line 68, characters 4-11", (Belt_List.headExn(rec_cell3) + Belt_List.headExn(Belt_List.tailExn(rec_cell3)) | 0) + Belt_List.headExn(Belt_List.tailExn(Belt_List.tailExn(rec_cell3))) | 0, 9); let rec_cell3$1 = f3(3); -eq("File \"recursive_records_test.res\", line 77, characters 4-11", (List.hd(rec_cell3$1) + List.hd(List.tl(rec_cell3$1)) | 0) + List.hd(List.tl(List.tl(rec_cell3$1))) | 0, 9); +eq("File \"recursive_records_test.res\", line 78, characters 4-11", (Belt_List.headExn(rec_cell3$1) + Belt_List.headExn(Belt_List.tailExn(rec_cell3$1)) | 0) + Belt_List.headExn(Belt_List.tailExn(Belt_List.tailExn(rec_cell3$1))) | 0, 9); Mt.from_pair_suites("recursive_records_test.res", suites.contents); diff --git a/jscomp/test/recursive_records_test.res b/jscomp/test/recursive_records_test.res index e98f5cc7e9..c7aae2b41e 100644 --- a/jscomp/test/recursive_records_test.res +++ b/jscomp/test/recursive_records_test.res @@ -67,7 +67,8 @@ let () = { eq( __LOC__, { - open List + let hd = Belt.List.headExn + let tl = Belt.List.tailExn hd(rec_cell3) + hd(tl(rec_cell3)) + hd(tl(tl(rec_cell3))) }, 9, @@ -76,7 +77,8 @@ let () = { eq( __LOC__, { - open List + let hd = Belt.List.headExn + let tl = Belt.List.tailExn hd(rec_cell3) + hd(tl(rec_cell3)) + hd(tl(tl(rec_cell3))) }, 9, diff --git a/jscomp/test/recursive_unbound_module_test.js b/jscomp/test/recursive_unbound_module_test.js index 333345ada6..69d6e404c9 100644 --- a/jscomp/test/recursive_unbound_module_test.js +++ b/jscomp/test/recursive_unbound_module_test.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_module = require("../../lib/js/caml_module.js"); +let Primitive_module = require("../../lib/js/primitive_module.js"); function Make(X) { let f = () => {}; @@ -13,7 +13,7 @@ function Make(X) { }; } -let B = Caml_module.init_mod([ +let B = Primitive_module.init([ "recursive_unbound_module_test.res", 14, 11 @@ -39,7 +39,7 @@ let M = { f: f }; -Caml_module.update_mod({ +Primitive_module.update({ TAG: "Module", _0: [[ { diff --git a/jscomp/test/regression_print.res b/jscomp/test/regression_print.res index b652645f72..76abbb043c 100644 --- a/jscomp/test/regression_print.res +++ b/jscomp/test/regression_print.res @@ -1,7 +1,7 @@ include ( { @val external to_str: 'a => string = "JSON.stringify" - let debug = x => print_endline(to_str(x)) + let debug = x => Js.log(to_str(x)) let () = { \"@@"(debug, 2) diff --git a/jscomp/test/res_debug.js b/jscomp/test/res_debug.js index 1f1308b78b..10aa0a5198 100644 --- a/jscomp/test/res_debug.js +++ b/jscomp/test/res_debug.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); function f(window, a, b) { return window.location(a, b); @@ -27,7 +27,7 @@ function testMatch(v) { function optionMap(x, f) { if (x !== undefined) { - return Caml_option.some(f(Caml_option.valFromOption(x))); + return Primitive_option.some(f(Primitive_option.valFromOption(x))); } } diff --git a/jscomp/test/return_check.js b/jscomp/test/return_check.js index b4992c4363..14afe51bc7 100644 --- a/jscomp/test/return_check.js +++ b/jscomp/test/return_check.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); function test(dom) { let elem = dom.getElementById("haha"); @@ -51,7 +51,7 @@ function f_escaped_1(xs, i) { } function f_escaped_2(xs, i) { - console.log(Caml_option.undefined_to_opt(xs[i])); + console.log(Primitive_option.fromUndefined(xs[i])); } function f_null(xs, i) { diff --git a/jscomp/test/set_gen.js b/jscomp/test/set_gen.js index 26eb922993..dbf9786391 100644 --- a/jscomp/test/set_gen.js +++ b/jscomp/test/set_gen.js @@ -1,9 +1,9 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let Pervasives = require("../../lib/js/pervasives.js"); -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); function cons_enum(_s, _e) { while (true) { @@ -194,9 +194,9 @@ function max_int_2(a, b) { } } -let Height_invariant_broken = /* @__PURE__ */Caml_exceptions.create("Set_gen.Height_invariant_broken"); +let Height_invariant_broken = /* @__PURE__ */Primitive_exceptions.create("Set_gen.Height_invariant_broken"); -let Height_diff_borken = /* @__PURE__ */Caml_exceptions.create("Set_gen.Height_diff_borken"); +let Height_diff_borken = /* @__PURE__ */Primitive_exceptions.create("Set_gen.Height_diff_borken"); function check_height_and_diff(x) { if (typeof x !== "object") { @@ -539,7 +539,7 @@ function of_sorted_list(l) { Error: new Error() }; }; - return sub(List.length(l), l)[0]; + return sub(Belt_List.length(l), l)[0]; } function of_sorted_array(l) { diff --git a/jscomp/test/set_gen.res b/jscomp/test/set_gen.res index bd743ec4dd..7665f3291e 100644 --- a/jscomp/test/set_gen.res +++ b/jscomp/test/set_gen.res @@ -451,7 +451,7 @@ let of_sorted_list = l => { } } - fst(sub(List.length(l), l)) + fst(sub(Belt.List.length(l), l)) } let of_sorted_array = l => { @@ -459,27 +459,27 @@ let of_sorted_array = l => { if n == 0 { Empty } else if n == 1 { - let x0 = Array.unsafe_get(l, start) + let x0 = Belt.Array.getUnsafe(l, start) Node(Empty, x0, Empty, 1) } else if n == 2 { - let x0 = Array.unsafe_get(l, start) - let x1 = Array.unsafe_get(l, start + 1) + let x0 = Belt.Array.getUnsafe(l, start) + let x1 = Belt.Array.getUnsafe(l, start + 1) Node(Node(Empty, x0, Empty, 1), x1, Empty, 2) } else if n == 3 { - let x0 = Array.unsafe_get(l, start) - let x1 = Array.unsafe_get(l, start + 1) - let x2 = Array.unsafe_get(l, start + 2) + let x0 = Belt.Array.getUnsafe(l, start) + let x1 = Belt.Array.getUnsafe(l, start + 1) + let x2 = Belt.Array.getUnsafe(l, start + 2) Node(Node(Empty, x0, Empty, 1), x1, Node(Empty, x2, Empty, 1), 2) } else { let nl = n / 2 let left = sub(start, nl, l) let mid = start + nl - let v = Array.unsafe_get(l, mid) + let v = Belt.Array.getUnsafe(l, mid) let right = sub(mid + 1, n - nl - 1, l) create(left, v, right) } - sub(0, Array.length(l), l) + sub(0, Belt.Array.length(l), l) } let is_ordered = (cmp, tree) => { diff --git a/jscomp/test/sexp.js b/jscomp/test/sexp.js deleted file mode 100644 index 92adfe4154..0000000000 --- a/jscomp/test/sexp.js +++ /dev/null @@ -1,533 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let List = require("../../lib/js/list.js"); -let Hashtbl = require("../../lib/js/hashtbl.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); -let Pervasives = require("../../lib/js/pervasives.js"); -let Caml_format = require("../../lib/js/caml_format.js"); -let Caml_option = require("../../lib/js/caml_option.js"); - -let equal = Caml_obj.equal; - -let compare = Caml_obj.compare; - -let hash = Hashtbl.hash; - -function of_int(x) { - return { - NAME: "Atom", - VAL: String(x) - }; -} - -function of_float(x) { - return { - NAME: "Atom", - VAL: Pervasives.string_of_float(x) - }; -} - -function of_bool(x) { - return { - NAME: "Atom", - VAL: x ? "true" : "false" - }; -} - -function atom(x) { - return { - NAME: "Atom", - VAL: x - }; -} - -function of_list(l) { - return { - NAME: "List", - VAL: l - }; -} - -function of_rev_list(l) { - return { - NAME: "List", - VAL: List.rev(l) - }; -} - -function of_pair(param) { - return { - NAME: "List", - VAL: { - hd: param[0], - tl: { - hd: param[1], - tl: /* [] */0 - } - } - }; -} - -function of_triple(param) { - return { - NAME: "List", - VAL: { - hd: param[0], - tl: { - hd: param[1], - tl: { - hd: param[2], - tl: /* [] */0 - } - } - } - }; -} - -function of_quad(param) { - return { - NAME: "List", - VAL: { - hd: param[0], - tl: { - hd: param[1], - tl: { - hd: param[2], - tl: { - hd: param[3], - tl: /* [] */0 - } - } - } - } - }; -} - -function of_variant(name, args) { - return { - NAME: "List", - VAL: { - hd: { - NAME: "Atom", - VAL: name - }, - tl: args - } - }; -} - -function of_field(name, t) { - return { - NAME: "List", - VAL: { - hd: { - NAME: "Atom", - VAL: name - }, - tl: { - hd: t, - tl: /* [] */0 - } - } - }; -} - -function of_record(l) { - return { - NAME: "List", - VAL: List.map(param => of_field(param[0], param[1]), l) - }; -} - -function $$return(x) { - return Caml_option.some(x); -} - -function $great$pipe$eq(e, f) { - if (e !== undefined) { - return Caml_option.some(f(Caml_option.valFromOption(e))); - } - -} - -function $great$great$eq(e, f) { - if (e !== undefined) { - return f(Caml_option.valFromOption(e)); - } - -} - -function map_opt(f, l) { - let _acc = /* [] */0; - let _l = l; - while (true) { - let l$1 = _l; - let acc = _acc; - if (!l$1) { - return List.rev(acc); - } - let y = f(l$1.hd); - if (y === undefined) { - return; - } - _l = l$1.tl; - _acc = { - hd: Caml_option.valFromOption(y), - tl: acc - }; - continue; - }; -} - -function list_any(f, e) { - if (e.NAME === "List") { - let _l = e.VAL; - while (true) { - let l = _l; - if (!l) { - return; - } - let res = f(l.hd); - if (res !== undefined) { - return res; - } - _l = l.tl; - continue; - }; - } - -} - -function list_all(f, e) { - if (e.NAME === "List") { - let _acc = /* [] */0; - let _l = e.VAL; - while (true) { - let l = _l; - let acc = _acc; - if (!l) { - return List.rev(acc); - } - let tl = l.tl; - let y = f(l.hd); - if (y !== undefined) { - _l = tl; - _acc = { - hd: Caml_option.valFromOption(y), - tl: acc - }; - continue; - } - _l = tl; - continue; - }; - } else { - return /* [] */0; - } -} - -function _try_atom(e, f) { - if (e.NAME === "List") { - return; - } - try { - return Caml_option.some(f(e.VAL)); - } catch (exn) { - return; - } -} - -function to_int(e) { - return _try_atom(e, Caml_format.int_of_string); -} - -function to_bool(e) { - return _try_atom(e, Pervasives.bool_of_string); -} - -function to_float(e) { - return _try_atom(e, Caml_format.float_of_string); -} - -function to_string(e) { - return _try_atom(e, x => x); -} - -function to_pair(e) { - if (typeof e !== "object") { - return; - } - if (e.NAME !== "List") { - return; - } - let match = e.VAL; - if (!match) { - return; - } - let match$1 = match.tl; - if (match$1 && !match$1.tl) { - return [ - match.hd, - match$1.hd - ]; - } - -} - -function to_pair_with(f1, f2) { - return e => $great$great$eq(to_pair(e), param => { - let y = param[1]; - return $great$great$eq(f1(param[0]), x => $great$great$eq(f2(y), y => [ - x, - y - ])); - }); -} - -function to_triple(e) { - if (typeof e !== "object") { - return; - } - if (e.NAME !== "List") { - return; - } - let match = e.VAL; - if (!match) { - return; - } - let match$1 = match.tl; - if (!match$1) { - return; - } - let match$2 = match$1.tl; - if (match$2 && !match$2.tl) { - return [ - match.hd, - match$1.hd, - match$2.hd - ]; - } - -} - -function to_triple_with(f1, f2, f3) { - return e => $great$great$eq(to_triple(e), param => { - let z = param[2]; - let y = param[1]; - return $great$great$eq(f1(param[0]), x => $great$great$eq(f2(y), y => $great$great$eq(f3(z), z => [ - x, - y, - z - ]))); - }); -} - -function to_list(e) { - if (e.NAME === "List") { - return Caml_option.some(e.VAL); - } - -} - -function to_list_with(f) { - return e => { - if (e.NAME === "List") { - return map_opt(f, e.VAL); - } - - }; -} - -function get_field(name) { - return e => { - if (e.NAME === "List") { - let _l = e.VAL; - while (true) { - let l = _l; - if (!l) { - return; - } - let match = l.hd; - if (typeof match === "object") { - if (match.NAME === "List") { - let match$1 = match.VAL; - if (match$1) { - let match$2 = match$1.hd; - if (typeof match$2 === "object") { - if (match$2.NAME === "Atom") { - let match$3 = match$1.tl; - if (match$3) { - if (match$3.tl) { - _l = l.tl; - continue; - } - if (Caml_obj.equal(name, match$2.VAL)) { - return match$3.hd; - } - _l = l.tl; - continue; - } - _l = l.tl; - continue; - } - _l = l.tl; - continue; - } - _l = l.tl; - continue; - } - _l = l.tl; - continue; - } - _l = l.tl; - continue; - } - _l = l.tl; - continue; - }; - } - - }; -} - -function field(name, f) { - return e => $great$great$eq(get_field(name)(e), f); -} - -function _get_field_list(name, _l) { - while (true) { - let l = _l; - if (!l) { - return; - } - let match = l.hd; - if (typeof match === "object") { - if (match.NAME === "List") { - let match$1 = match.VAL; - if (match$1) { - let match$2 = match$1.hd; - if (typeof match$2 === "object") { - if (match$2.NAME === "Atom") { - if (Caml_obj.equal(name, match$2.VAL)) { - return match$1.tl; - } - _l = l.tl; - continue; - } - _l = l.tl; - continue; - } - _l = l.tl; - continue; - } - _l = l.tl; - continue; - } - _l = l.tl; - continue; - } - _l = l.tl; - continue; - }; -} - -function field_list(name, f) { - return e => { - if (e.NAME === "List") { - return $great$great$eq(_get_field_list(name, e.VAL), f); - } - - }; -} - -function _get_variant(s, args, _l) { - while (true) { - let l = _l; - if (!l) { - return; - } - let match = l.hd; - if (Caml_obj.equal(s, match[0])) { - return match[1](args); - } - _l = l.tl; - continue; - }; -} - -function get_variant(l) { - return e => { - if (e.NAME !== "List") { - return _get_variant(e.VAL, /* [] */0, l); - } - let match = e.VAL; - if (!match) { - return; - } - let match$1 = match.hd; - if (typeof match$1 === "object" && match$1.NAME === "Atom") { - return _get_variant(match$1.VAL, match.tl, l); - } - - }; -} - -function get_exn(e) { - if (e !== undefined) { - return Caml_option.valFromOption(e); - } - throw { - RE_EXN_ID: "Failure", - _1: "CCSexp.Traverse.get_exn", - Error: new Error() - }; -} - -let of_unit = { - NAME: "List", - VAL: /* [] */0 -}; - -let Traverse = { - map_opt: map_opt, - list_any: list_any, - list_all: list_all, - to_int: to_int, - to_string: to_string, - to_bool: to_bool, - to_float: to_float, - to_list: to_list, - to_list_with: to_list_with, - to_pair: to_pair, - to_pair_with: to_pair_with, - to_triple: to_triple, - to_triple_with: to_triple_with, - get_field: get_field, - field: field, - get_variant: get_variant, - field_list: field_list, - $great$great$eq: $great$great$eq, - $great$pipe$eq: $great$pipe$eq, - $$return: $$return, - get_exn: get_exn -}; - -exports.equal = equal; -exports.compare = compare; -exports.hash = hash; -exports.atom = atom; -exports.of_int = of_int; -exports.of_bool = of_bool; -exports.of_list = of_list; -exports.of_rev_list = of_rev_list; -exports.of_float = of_float; -exports.of_unit = of_unit; -exports.of_pair = of_pair; -exports.of_triple = of_triple; -exports.of_quad = of_quad; -exports.of_variant = of_variant; -exports.of_field = of_field; -exports.of_record = of_record; -exports.Traverse = Traverse; -/* No side effect */ diff --git a/jscomp/test/sexp.res b/jscomp/test/sexp.res deleted file mode 100644 index d6ac2351e4..0000000000 --- a/jscomp/test/sexp.res +++ /dev/null @@ -1,186 +0,0 @@ -/*** {1 Simple S-expression parsing/printing} */ - -type rec t = [ - | #Atom(string) - | #List(list) -] - -let equal = (a, b) => a == b - -let compare = (a, b) => Pervasives.compare(a, b) - -let hash = a => Hashtbl.hash(a) - -let of_int = x => #Atom(string_of_int(x)) -let of_float = x => #Atom(string_of_float(x)) -let of_bool = x => #Atom(string_of_bool(x)) -let atom = x => #Atom(x) -let of_unit = #List(list{}) -let of_list = l => #List(l) -let of_rev_list = l => #List(List.rev(l)) -let of_pair = ((x, y)) => #List(list{x, y}) -let of_triple = ((x, y, z)) => #List(list{x, y, z}) -let of_quad = ((x, y, z, u)) => #List(list{x, y, z, u}) - -let of_variant = (name, args) => #List(list{#Atom(name), ...args}) -let of_field = (name, t) => #List(list{#Atom(name), t}) -let of_record = l => #List(List.map(((n, x)) => of_field(n, x), l)) - -/*** {6 Traversal of S-exp} */ - -module Traverse = { - type conv<'a> = t => option<'a> - - let return = x => Some(x) - - let \">|=" = (e, f) => - switch e { - | None => None - | Some(x) => Some(f(x)) - } - - let \">>=" = (e, f) => - switch e { - | None => None - | Some(x) => f(x) - } - - let map_opt = (f, l) => { - let rec recurse = (acc, l) => - switch l { - | list{} => Some(List.rev(acc)) - | list{x, ...l'} => - switch f(x) { - | None => None - | Some(y) => recurse(list{y, ...acc}, l') - } - } - recurse(list{}, l) - } - - let rec _list_any = (f, l) => - switch l { - | list{} => None - | list{x, ...tl} => - switch f(x) { - | Some(_) as res => res - | None => _list_any(f, tl) - } - } - - let list_any = (f, e) => - switch e { - | #Atom(_) => None - | #List(l) => _list_any(f, l) - } - - let rec _list_all = (f, acc, l) => - switch l { - | list{} => List.rev(acc) - | list{x, ...tl} => - switch f(x) { - | Some(y) => _list_all(f, list{y, ...acc}, tl) - | None => _list_all(f, acc, tl) - } - } - - let list_all = (f, e) => - switch e { - | #Atom(_) => list{} - | #List(l) => _list_all(f, list{}, l) - } - - let _try_atom = (e, f) => - switch e { - | #List(_) => None - | #Atom(x) => - try Some(f(x)) catch { - | _ => None - } - } - - let to_int = e => _try_atom(e, int_of_string) - let to_bool = e => _try_atom(e, bool_of_string) - let to_float = e => _try_atom(e, float_of_string) - let to_string = e => _try_atom(e, x => x) - - let to_pair = e => - switch e { - | #List(list{x, y}) => Some(x, y) - | _ => None - } - - let to_pair_with = (f1, f2) => e => - \">>="(to_pair(e), ((x, y)) => \">>="(f1(x), x => \">>="(f2(y), y => return((x, y))))) - - let to_triple = e => - switch e { - | #List(list{x, y, z}) => Some(x, y, z) - | _ => None - } - - let to_triple_with = (f1, f2, f3) => e => - \">>="(to_triple(e), ((x, y, z)) => - \">>="(f1(x), x => \">>="(f2(y), y => \">>="(f3(z), z => return((x, y, z))))) - ) - - let to_list = e => - switch e { - | #List(l) => Some(l) - | #Atom(_) => None - } - - let to_list_with = f => (e: t) => - switch e { - | #List(l) => map_opt(f, l) - | #Atom(_) => None - } - - let rec _get_field = (name, l) => - switch l { - | list{#List(list{#Atom(n), x}), ..._} if name == n => Some(x) - | list{_, ...tl} => _get_field(name, tl) - | list{} => None - } - - let get_field = name => e => - switch e { - | #List(l) => _get_field(name, l) - | #Atom(_) => None - } - - let field = (name, f) => e => \">>="(get_field(name)(e), f) - - let rec _get_field_list = (name, l) => - switch l { - | list{#List(list{#Atom(n), ...tl}), ..._} if name == n => Some(tl) - | list{_, ...tl} => _get_field_list(name, tl) - | list{} => None - } - - let field_list = (name, f) => e => - switch e { - | #List(l) => \">>="(_get_field_list(name, l), f) - | #Atom(_) => None - } - - let rec _get_variant = (s, args, l) => - switch l { - | list{} => None - | list{(s', f), ..._} if s == s' => f(args) - | list{_, ...tl} => _get_variant(s, args, tl) - } - - let get_variant = l => e => - switch e { - | #List(list{#Atom(s), ...args}) => _get_variant(s, args, l) - | #List(_) => None - | #Atom(s) => _get_variant(s, list{}, l) - } - - let get_exn = e => - switch e { - | None => failwith("CCSexp.Traverse.get_exn") - | Some(x) => x - } -} diff --git a/jscomp/test/sexp.resi b/jscomp/test/sexp.resi deleted file mode 100644 index ffb85e6343..0000000000 --- a/jscomp/test/sexp.resi +++ /dev/null @@ -1,146 +0,0 @@ -/*** {1 Handling S-expressions} - - @since 0.4 - - @since 0.7 - Moved the streaming parser to CCSexpStream -*/ - -/*** {2 Basics} */ - -type rec t = [ - | #Atom(string) - | #List(list) -] - -let equal: (t, t) => bool -let compare: (t, t) => int -let hash: t => int - -/** Build an atom directly from a string */ -let atom: string => t - -let of_int: int => t -let of_bool: bool => t -let of_list: list => t -/** Reverse the list */ -let of_rev_list: list => t -/** Reverse the list */ -let of_float: float => t -let of_unit: t -let of_pair: ((t, t)) => t -let of_triple: ((t, t, t)) => t -let of_quad: ((t, t, t, t)) => t - -/** [of_variant name args] is used to encode algebraic variants - into a S-expr. For instance [of_variant \"some\" [of_int 1]] - represents the value [Some 1] */ -let of_variant: (string, list) => t - -/** Used to represent one record field */ -let of_field: (string, t) => t - -/** Represent a record by its named fields */ -let of_record: list<(string, t)> => t - -/* {6 Traversal of S-exp} - - Example: serializing 2D points - {[ - type pt = {x:int; y:int };; - - let pt_of_sexp e = - Sexp.Traverse.( - field \"x\" to_int e >>= fun x -> - field \"y\" to_int e >>= fun y -> - return {x;y} - );; - - let sexp_of_pt pt = Sexp.(of_record [\"x\", of_int pt.x; \"y\", of_int pt.y]);; - - let l = [{x=1;y=1}; {x=2;y=10}];; - - let sexp = Sexp.(of_list (List.map sexp_of_pt l));; - - Sexp.Traverse.list_all pt_of_sexp sexp;; - ]} - -*/ - -module Traverse: { - /** A converter from S-expressions to 'a is a function [sexp -> 'a option]. - @since 0.4.1 */ - type conv<'a> = t => option<'a> - - /** Map over a list, failing as soon as the function fails on any element - @since 0.4.1 */ - let map_opt: ('a => option<'b>, list<'a>) => option> - - /** [list_any f (List l)] tries [f x] for every element [x] in [List l], - and returns the first non-None result (if any). */ - let list_any: (conv<'a>, t) => option<'a> - - /** [list_all f (List l)] returns the list of all [y] such that [x] in [l] - and [f x = Some y] */ - let list_all: (conv<'a>, t) => list<'a> - - /** Expect an integer */ - let to_int: conv - - /** Expect a string (an atom) */ - let to_string: conv - - /** Expect a boolean */ - let to_bool: conv - - /** Expect a float */ - let to_float: conv - - /** Expect a list */ - let to_list: conv> - - /** Expect a list, applies [f] to all the elements of the list, and succeeds - only if [f] succeeded on every element - @since 0.4.1 */ - let to_list_with: (t => option<'a>) => conv> - - /** Expect a list of two elements */ - let to_pair: conv<(t, t)> - - /** Same as {!to_pair} but applies conversion functions - @since 0.4.1 */ - let to_pair_with: (conv<'a>, conv<'b>) => conv<('a, 'b)> - - let to_triple: conv<(t, t, t)> - - let to_triple_with: (conv<'a>, conv<'b>, conv<'c>) => conv<('a, 'b, 'c)> - /* @since 0.4.1 */ - - /** [get_field name e], when [e = List [(n1,x1); (n2,x2) ... ]], extracts - the [xi] such that [name = ni], if it can find it. */ - let get_field: string => conv - - /** Enriched version of {!get_field}, with a converter as argument */ - let field: (string, conv<'a>) => conv<'a> - - /** [get_variant l e] checks whether [e = List (Atom s :: args)], and - if some pair of [l] is [s, f]. In this case, it calls [f args] - and returns its result, otherwise it returns None. */ - let get_variant: list<(string, list => option<'a>)> => conv<'a> - - /** [field_list name f \"(... (name a b c d) ...record)\"] - will look for a field based on the given [name], and expect it to have a - list of arguments dealt with by [f] (here, \"a b c d\"). - @since 0.4.1 */ - let field_list: (string, list => option<'a>) => conv<'a> - - let \">>=": (option<'a>, 'a => option<'b>) => option<'b> - - let \">|=": (option<'a>, 'a => 'b) => option<'b> - - let return: 'a => option<'a> - - /** Unwrap an option, possibly failing. - @raise Invalid_argument if the argument is [None] */ - let get_exn: option<'a> => 'a -} diff --git a/jscomp/test/sexpm.js b/jscomp/test/sexpm.js deleted file mode 100644 index 23f147a379..0000000000 --- a/jscomp/test/sexpm.js +++ /dev/null @@ -1,534 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Sys = require("../../lib/js/sys.js"); -let Caml = require("../../lib/js/caml.js"); -let Char = require("../../lib/js/char.js"); -let List = require("../../lib/js/list.js"); -let Bytes = require("../../lib/js/bytes.js"); -let Buffer = require("../../lib/js/buffer.js"); -let $$String = require("../../lib/js/string.js"); -let Caml_bytes = require("../../lib/js/caml_bytes.js"); -let Pervasives = require("../../lib/js/pervasives.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); - -function _must_escape(s) { - try { - for (let i = 0, i_finish = s.length; i < i_finish; ++i) { - let c = s.codePointAt(i); - let exit = 0; - if (c >= 42) { - if (c !== 59) { - if (c !== 92) { - exit = 1; - } else { - throw { - RE_EXN_ID: Pervasives.Exit, - Error: new Error() - }; - } - } else { - throw { - RE_EXN_ID: Pervasives.Exit, - Error: new Error() - }; - } - } else if (c >= 11) { - if (c >= 32) { - switch (c) { - case 33 : - case 35 : - case 36 : - case 37 : - case 38 : - case 39 : - exit = 1; - break; - case 32 : - case 34 : - case 40 : - case 41 : - throw { - RE_EXN_ID: Pervasives.Exit, - Error: new Error() - }; - } - } else { - exit = 1; - } - } else { - if (c >= 9) { - throw { - RE_EXN_ID: Pervasives.Exit, - Error: new Error() - }; - } - exit = 1; - } - if (exit === 1 && c > 127) { - throw { - RE_EXN_ID: Pervasives.Exit, - Error: new Error() - }; - } - - } - return false; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === Pervasives.Exit) { - return true; - } - throw exn; - } -} - -function to_buf(b, t) { - if (t.NAME === "List") { - let l = t.VAL; - if (l) { - if (l.tl) { - Buffer.add_char(b, /* '(' */40); - List.iteri((i, t$p) => { - if (i > 0) { - Buffer.add_char(b, /* ' ' */32); - } - to_buf(b, t$p); - }, l); - return Buffer.add_char(b, /* ')' */41); - } else { - Buffer.add_string(b, "("); - to_buf(b, l.hd); - return Buffer.add_string(b, ")"); - } - } else { - return Buffer.add_string(b, "()"); - } - } - let s = t.VAL; - if (_must_escape(s)) { - return Buffer.add_string(b, "\"" + ($$String.escaped(s) + "\"")); - } else { - return Buffer.add_string(b, s); - } -} - -function to_string(t) { - let b = Buffer.create(128); - to_buf(b, t); - return Buffer.contents(b); -} - -function make(bufsizeOpt, refill) { - let bufsize = bufsizeOpt !== undefined ? bufsizeOpt : 1024; - let bufsize$1 = Caml.int_min(bufsize > 16 ? bufsize : 16, Sys.max_string_length); - return { - buf: Caml_bytes.create(bufsize$1), - refill: refill, - atom: Buffer.create(32), - i: 0, - len: 0, - line: 1, - col: 1 - }; -} - -function _is_digit(c) { - if (/* '0' */48 <= c) { - return c <= /* '9' */57; - } else { - return false; - } -} - -function _refill(t, k_succ, k_fail) { - let n = t.refill(t.buf, 0, t.buf.length); - t.i = 0; - t.len = n; - if (n === 0) { - return k_fail(t); - } else { - return k_succ(t); - } -} - -function _get(t) { - if (t.i >= t.len) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "sexpm.res", - 111, - 4 - ], - Error: new Error() - }; - } - let c = Caml_bytes.get(t.buf, t.i); - t.i = t.i + 1 | 0; - if (c === /* '\n' */10) { - t.col = 1; - t.line = t.line + 1 | 0; - } else { - t.col = t.col + 1 | 0; - } - return c; -} - -function _error(param, param$1) { - let line = param.line; - let col = param.col; - let b = Buffer.create(32); - Buffer.add_string(b, "at " + (line + (", " + (col + ": ")))); - Buffer.add_string(b, param$1); - let msg$p = Buffer.contents(b); - return { - NAME: "Error", - VAL: msg$p - }; -} - -function _error_eof(t) { - return _error(t, "unexpected end of input"); -} - -function expr(k, t) { - while (true) { - if (t.i === t.len) { - return _refill(t, extra => expr(k, extra), _error_eof); - } - let c = _get(t); - if (c >= 11) { - if (c !== 32) { - return expr_starting_with(c, k, t); - } - continue; - } - if (c < 9) { - return expr_starting_with(c, k, t); - } - continue; - }; -} - -function expr_starting_with(c, k, t) { - if (c >= 42) { - if (c === 59) { - return skip_comment((param, param$1) => expr(k, t), t); - } - if (c === 92) { - return _error(t, "unexpected '\\'"); - } - - } else if (c >= 11) { - if (c >= 32) { - switch (c) { - case 32 : - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "sexpm.res", - 152, - 27 - ], - Error: new Error() - }; - case 34 : - return quoted(k, t); - case 33 : - case 35 : - case 36 : - case 37 : - case 38 : - case 39 : - break; - case 40 : - return expr_list(/* [] */0, k, t); - case 41 : - return _error(t, "unexpected ')'"); - } - } - - } else if (c >= 9) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "sexpm.res", - 152, - 27 - ], - Error: new Error() - }; - } - Buffer.add_char(t.atom, c); - return atom(k, t); -} - -function expr_list(acc, k, t) { - while (true) { - if (t.i === t.len) { - return _refill(t, extra => expr_list(acc, k, extra), _error_eof); - } - let c = _get(t); - if (c > 32 || c < 9) { - if (c === 41) { - return k(undefined, { - NAME: "List", - VAL: List.rev(acc) - }); - } - - } else if (c > 31 || c < 11) { - continue; - } - return expr_starting_with(c, (last, e) => { - if (last !== undefined) { - if (last !== 40) { - if (last !== 41) { - return expr_list({ - hd: e, - tl: acc - }, k, t); - } else { - return k(undefined, { - NAME: "List", - VAL: List.rev({ - hd: e, - tl: acc - }) - }); - } - } else { - return expr_list(/* [] */0, (param, l) => expr_list({ - hd: l, - tl: acc - }, k, t), t); - } - } else { - return expr_list({ - hd: e, - tl: acc - }, k, t); - } - }, t); - }; -} - -function _return_atom(last, k, t) { - let s = Buffer.contents(t.atom); - t.atom.position = 0; - return k(last, { - NAME: "Atom", - VAL: s - }); -} - -function atom(k, t) { - while (true) { - if (t.i === t.len) { - return _refill(t, extra => atom(k, extra), extra => _return_atom(undefined, k, extra)); - } - let c = _get(t); - let exit = 0; - if (c >= 35) { - if (c >= 42) { - if (c === 92) { - return _error(t, "unexpected '\\' in non-quoted string"); - } - exit = 1; - } else { - exit = c >= 40 ? 2 : 1; - } - } else if (c >= 11) { - if (c >= 32) { - switch (c) { - case 32 : - exit = 2; - break; - case 33 : - exit = 1; - break; - case 34 : - return _error(t, "unexpected '\"' in the middle of an atom"); - } - } else { - exit = 1; - } - } else { - exit = c >= 9 ? 2 : 1; - } - switch (exit) { - case 1 : - Buffer.add_char(t.atom, c); - continue; - case 2 : - return _return_atom(c, k, t); - } - }; -} - -function quoted(k, t) { - while (true) { - if (t.i === t.len) { - return _refill(t, extra => quoted(k, extra), _error_eof); - } - let c = _get(t); - if (c === 34) { - return _return_atom(undefined, k, t); - } - if (c === 92) { - return escaped(c => { - Buffer.add_char(t.atom, c); - return quoted(k, t); - }, t); - } - Buffer.add_char(t.atom, c); - continue; - }; -} - -function escaped(k, t) { - if (t.i === t.len) { - return _refill(t, extra => escaped(k, extra), _error_eof); - } - let c = _get(t); - if (c >= 92) { - if (c < 117) { - switch (c) { - case 92 : - return k(/* '\\' */92); - case 98 : - return k(/* '\b' */8); - case 110 : - return k(/* '\n' */10); - case 114 : - return k(/* '\r' */13); - case 93 : - case 94 : - case 95 : - case 96 : - case 97 : - case 99 : - case 100 : - case 101 : - case 102 : - case 103 : - case 104 : - case 105 : - case 106 : - case 107 : - case 108 : - case 109 : - case 111 : - case 112 : - case 113 : - case 115 : - break; - case 116 : - return k(/* '\t' */9); - } - } - - } else if (c === 34) { - return k(/* '"' */34); - } - if (_is_digit(c)) { - return read2int(c - /* '0' */48 | 0, n => k(Char.chr(n)), t); - } else { - return _error(t, "unexpected escaped char '" + (c + "'")); - } -} - -function read2int(i, k, t) { - if (t.i === t.len) { - return _refill(t, extra => read2int(i, k, extra), _error_eof); - } - let c = _get(t); - if (_is_digit(c)) { - return read1int(Math.imul(10, i) + (c - /* '0' */48 | 0) | 0, k, t); - } else { - return _error(t, "unexpected escaped char '" + (c + "' when reading byte")); - } -} - -function read1int(i, k, t) { - if (t.i === t.len) { - return _refill(t, extra => read1int(i, k, extra), _error_eof); - } - let c = _get(t); - if (_is_digit(c)) { - return k(Math.imul(10, i) + (c - /* '0' */48 | 0) | 0); - } else { - return _error(t, "unexpected escaped char '" + (c + "' when reading byte")); - } -} - -function skip_comment(k, t) { - while (true) { - if (t.i === t.len) { - return _refill(t, extra => skip_comment(k, extra), _error_eof); - } - let match = _get(t); - if (match === 10) { - return k(undefined, undefined); - } - continue; - }; -} - -function expr_or_end(k, t) { - while (true) { - if (t.i === t.len) { - return _refill(t, extra => expr_or_end(k, extra), param => "End"); - } - let c = _get(t); - if (c >= 11) { - if (c !== 32) { - return expr_starting_with(c, k, t); - } - continue; - } - if (c < 9) { - return expr_starting_with(c, k, t); - } - continue; - }; -} - -function next(t) { - return expr_or_end((param, x) => ({ - NAME: "Ok", - VAL: x - }), t); -} - -function parse_string(s) { - let n = s.length; - let stop = { - contents: false - }; - let refill = (bytes, i, _len) => { - if (stop.contents) { - return 0; - } else { - stop.contents = true; - Bytes.blit_string(s, 0, bytes, i, n); - return n; - } - }; - let d = make(n, refill); - let res = next(d); - if (typeof res === "object") { - return res; - } else { - return { - NAME: "Error", - VAL: "unexpected end of file" - }; - } -} - -exports.to_buf = to_buf; -exports.to_string = to_string; -exports.parse_string = parse_string; -/* No side effect */ diff --git a/jscomp/test/sexpm.res b/jscomp/test/sexpm.res deleted file mode 100644 index 81b0c35fc7..0000000000 --- a/jscomp/test/sexpm.res +++ /dev/null @@ -1,323 +0,0 @@ -/* This file is free software, part of containers. See file "license" for more details. */ - -@@warning("a") -type or_error<'a> = [#Ok('a) | #Error(string)] -type sequence<'a> = ('a => unit) => unit -type gen<'a> = unit => option<'a> - -type rec t = [ - | #Atom(string) - | #List(list) -] -type sexp = t - -/* {2 Serialization (encoding)} */ - -/* shall we escape the string because of one of its chars? */ -let _must_escape = s => - try { - for i in 0 to String.length(s) - 1 { - let c = String.unsafe_get(s, i) - switch c { - | ' ' | ';' | ')' | '(' | '"' | '\\' | '\n' | '\t' => raise(Exit) - | _ if Char.code(c) > 127 => raise(Exit) /* non-ascii */ - | _ => () - } - } - false - } catch { - | Exit => true - } - -let rec to_buf = (b, t) => - switch t { - | #Atom(s) if _must_escape(s) => Buffer.add_string(b, "\"" ++ (String.escaped(s) ++ "\"")) - | #Atom(s) => Buffer.add_string(b, s) - | #List(list{}) => Buffer.add_string(b, "()") - | #List(list{x}) => - Buffer.add_string(b, "(") - to_buf(b, x) - Buffer.add_string(b, ")") - | #List(l) => - Buffer.add_char(b, '(') - List.iteri((i, t') => { - if i > 0 { - Buffer.add_char(b, ' ') - } - to_buf(b, t') - }, l) - Buffer.add_char(b, ')') - } - -let to_string = t => { - let b = Buffer.create(128) - to_buf(b, t) - Buffer.contents(b) -} - -/* {2 Deserialization (decoding)} */ - -module type MONAD = { - type t<'a> - let return: 'a => t<'a> - let \">>=": (t<'a>, 'a => t<'b>) => t<'b> -} - -type parse_result<'a> = [or_error<'a> | #End] - -module MakeDecode = (M: MONAD) => { - let \">>=" = M.\">>=" - - type t = { - buf: Bytes.t, - refill: (Bytes.t, int, int) => M.t, - atom: Buffer.t, - mutable i: int /* offset in [buf] */, - mutable len: int /* how many bytes of [buf] are usable */, - mutable line: int, - mutable col: int, - } - - let make = (~bufsize=1024, refill) => { - let bufsize = min(max(bufsize, 16), Sys.max_string_length) - { - buf: Bytes.create(bufsize), - refill, - atom: Buffer.create(32), - i: 0, - len: 0, - line: 1, - col: 1, - } - } - - let _is_digit = c => Char.code('0') <= Char.code(c) && Char.code(c) <= Char.code('9') - let _digit2i = c => Char.code(c) - Char.code('0') - - /* refill buffer. If it works, call k_succ, otherwise call k_fail */ - let _refill = (t, k_succ, k_fail) => - \">>="(t.refill(t.buf, 0, Bytes.length(t.buf)), n => { - t.i = 0 - t.len = n - if n == 0 { - k_fail(t) - } else { - k_succ(t) - } - }) - - /* get next char, assuming t.i < t.len */ - let _get = t => { - assert(t.i < t.len) - let c = Bytes.get(t.buf, t.i) - t.i = t.i + 1 - if c == '\n' { - t.col = 1 - t.line = t.line + 1 - } else { - t.col = t.col + 1 - } - c - } - - /* return an error */ - let _error = ({line, col}, msg: string) => { - let b = Buffer.create(32) - Buffer.add_string(b, "at " ++ (__unsafe_cast(line) ++ (", " ++ (__unsafe_cast(col) ++ ": ")))) - Buffer.add_string(b, msg) - let msg' = Buffer.contents(b) - M.return(#Error(msg')) - } - - let _error_eof = t => _error(t, "unexpected end of input") - - /* The parsers all take a success continuation, and the decoder as - last arguments. The continuation is used to minimize the - number of calls to [>>=] and take two parameters, the next - char (if not consumed), and the returned expression itself */ - - /* read expression */ - let rec expr = (k, t) => - if t.i == t.len { - _refill(t, expr(k, ...), _error_eof) - } else { - switch _get(t) { - | ' ' | '\t' | '\n' => expr(k, t) - | c => expr_starting_with(c, k, t) - } - } - - and expr_starting_with = (c, k, t) => - switch c { - | ' ' | '\t' | '\n' => assert(false) - | ';' => skip_comment((_, ()) => expr(k, t), t) - | '(' => expr_list(list{}, k, t) - | ')' => _error(t, "unexpected ')'") - | '\\' => _error(t, "unexpected '\\'") - | '"' => quoted(k, t) - | c => - Buffer.add_char(t.atom, c) - atom(k, t) - } - - /* parse list */ - and expr_list = (acc, k, t) => - if t.i == t.len { - _refill(t, expr_list(acc, k, ...), _error_eof) - } else { - switch _get(t) { - | ' ' | '\t' | '\n' => expr_list(acc, k, t) - | ')' => k(None, #List(List.rev(acc))) - | c => - expr_starting_with( - c, - (last, e) => - switch last { - | Some('(') => expr_list(list{}, (_, l) => expr_list(list{l, ...acc}, k, t), t) - | Some(')') => k(None, #List(List.rev(list{e, ...acc}))) - | _ => expr_list(list{e, ...acc}, k, t) - }, - t, - ) - } - } - - /* return the current atom (last char: c) */ - and _return_atom = (last, k, t) => { - let s = Buffer.contents(t.atom) - Buffer.clear(t.atom) - k(last, #Atom(s)) - } - - /* parse atom */ - and atom = (k, t) => - if t.i == t.len { - _refill(t, atom(k, ...), _return_atom(None, k, ...)) - } else { - switch _get(t) { - | '\\' => _error(t, "unexpected '\\' in non-quoted string") - | '"' => _error(t, "unexpected '\"' in the middle of an atom") - | (' ' | '\n' | '\t' | '(' | ')') as c => _return_atom(Some(c), k, t) - | c => - Buffer.add_char(t.atom, c) - atom(k, t) - } - } - - /* quoted string */ - and quoted = (k, t) => - if t.i == t.len { - _refill(t, quoted(k, ...), _error_eof) - } else { - switch _get(t) { - | '\\' => - /* read escaped char and continue */ - escaped(c => { - Buffer.add_char(t.atom, c) - quoted(k, t) - }, t) - | '"' => _return_atom(None, k, t) - | c => - Buffer.add_char(t.atom, c) - quoted(k, t) - } - } - - /* read escaped char */ - and escaped = (k, t) => - if t.i == t.len { - _refill(t, escaped(k, ...), _error_eof) - } else { - switch _get(t) { - | 'n' => k('\n') - | 't' => k('\t') - | 'r' => k('\r') - | 'b' => k('\b') - | '\\' => k('\\') - | '"' => k('"') - | c if _is_digit(c) => read2int(_digit2i(c), n => k(Char.chr(n)), t) - | c => _error(t, "unexpected escaped char '" ++ (__unsafe_cast(c) ++ "'")) - } - } - - and read2int = (i, k, t) => - if t.i == t.len { - _refill(t, read2int(i, k, ...), _error_eof) - } else { - switch _get(t) { - | c if _is_digit(c) => read1int(10 * i + _digit2i(c), k, t) - | c => _error(t, "unexpected escaped char '" ++ (__unsafe_cast(c) ++ "' when reading byte")) - } - } - - and read1int = (i, k, t) => - if t.i == t.len { - _refill(t, read1int(i, k, ...), _error_eof) - } else { - switch _get(t) { - | c if _is_digit(c) => k(10 * i + _digit2i(c)) - | c => _error(t, "unexpected escaped char '" ++ (__unsafe_cast(c) ++ "' when reading byte")) - } - } - - /* skip until end of line, then call next() */ - and skip_comment = (k, t) => - if t.i == t.len { - _refill(t, skip_comment(k, ...), _error_eof) - } else { - switch _get(t) { - | '\n' => k(None, ()) - | _ => skip_comment(k, t) - } - } - - /* top-level expression */ - let rec expr_or_end = (k, t) => - if t.i == t.len { - _refill(t, expr_or_end(k, ...), _ => M.return(#End)) - } else { - switch _get(t) { - | ' ' | '\t' | '\n' => expr_or_end(k, t) - | c => expr_starting_with(c, k, t) - } - } - - /* entry point */ - let next = (t): M.t> => expr_or_end((_, x) => M.return(#Ok(x)), t) -} - -module ID_MONAD = { - type t<'a> = 'a - let return = x => x - let \">>=" = (x, f) => f(x) -} - -module D = MakeDecode(ID_MONAD) - -let parse_string = (s): or_error => { - let n = String.length(s) - let stop = ref(false) - let refill = (bytes, i, _len) => - if stop.contents { - 0 - } else { - stop := true - Bytes.blit_string(s, 0, bytes, i, n) - n - } - - let d = D.make(~bufsize=n, refill) - switch D.next(d) { - | #End => #Error("unexpected end of file") - | (#Ok(_) | #Error(_)) as res => res - } -} - -/* $T - CCError.to_opt (parse_string "(abc d/e/f \"hello \\\" () world\" )") <> None - CCError.to_opt (parse_string "(abc ( d e ffff ) \"hello/world\")") <> None -*/ - -/* $Q & ~count:100 - sexp_gen (fun s -> sexp_valid s ==> (to_string s |> parse_string = `Ok s)) -*/ diff --git a/jscomp/test/sexpm.resi b/jscomp/test/sexpm.resi deleted file mode 100644 index 645d0c9ade..0000000000 --- a/jscomp/test/sexpm.resi +++ /dev/null @@ -1,26 +0,0 @@ -/* This file is free software, part of containers. See file "license" for more details. */ - -/* {1 Simple and efficient S-expression parsing/printing} - - @since 0.7 " */ - -type or_error<'a> = [#Ok('a) | #Error(string)] -type sequence<'a> = ('a => unit) => unit -type gen<'a> = unit => option<'a> - -/* {2 Basics} */ - -type rec t = [ - | #Atom(string) - | #List(list) -] -type sexp = t - -/* {2 Serialization (encoding)} */ - -let to_buf: (Buffer.t, t) => unit - -let to_string: t => string - -/** Parse a string */ -let parse_string: string => or_error diff --git a/jscomp/test/sexpm_test.js b/jscomp/test/sexpm_test.js deleted file mode 100644 index 073a85ff9e..0000000000 --- a/jscomp/test/sexpm_test.js +++ /dev/null @@ -1,94 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let Sexpm = require("./sexpm.js"); - -let suites = { - contents: /* [] */0 -}; - -let test_id = { - contents: 0 -}; - -function eq(loc, param) { - let y = param[1]; - let x = param[0]; - test_id.contents = test_id.contents + 1 | 0; - suites.contents = { - hd: [ - loc + (" id " + String(test_id.contents)), - () => ({ - TAG: "Eq", - _0: x, - _1: y - }) - ], - tl: suites.contents - }; -} - -function print_or_error(x) { - if (x.NAME === "Error") { - return "Error:" + x.VAL; - } else { - return "Ok:" + Sexpm.to_string(x.VAL); - } -} - -let a = Sexpm.parse_string("(x x gh 3 3)"); - -eq("File \"sexpm_test.res\", line 17, characters 5-12", [ - { - NAME: "Ok", - VAL: { - NAME: "List", - VAL: { - hd: { - NAME: "Atom", - VAL: "x" - }, - tl: { - hd: { - NAME: "Atom", - VAL: "x" - }, - tl: { - hd: { - NAME: "Atom", - VAL: "gh" - }, - tl: { - hd: { - NAME: "Atom", - VAL: "3" - }, - tl: { - hd: { - NAME: "Atom", - VAL: "3" - }, - tl: /* [] */0 - } - } - } - } - } - } - }, - a -]); - -eq("File \"sexpm_test.res\", line 18, characters 5-12", [ - print_or_error(a).trim(), - "Ok:(x x gh 3 3)\n".trim() -]); - -Mt.from_pair_suites("Sexpm_test", suites.contents); - -exports.suites = suites; -exports.test_id = test_id; -exports.eq = eq; -exports.print_or_error = print_or_error; -/* a Not a pure module */ diff --git a/jscomp/test/sexpm_test.res b/jscomp/test/sexpm_test.res deleted file mode 100644 index 591b402f0a..0000000000 --- a/jscomp/test/sexpm_test.res +++ /dev/null @@ -1,25 +0,0 @@ -let suites: ref = ref(list{}) -let test_id = ref(0) -let eq = (loc, (x, y)) => { - incr(test_id) - suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} -} - -let print_or_error = x => - switch x { - | #Ok(a) => "Ok:" ++ Sexpm.to_string(a) - | #Error(a) => "Error:" ++ a - } - -let () = { - let a = Sexpm.parse_string("(x x gh 3 3)") - eq(__LOC__, (#Ok(#List(list{#Atom("x"), #Atom("x"), #Atom("gh"), #Atom("3"), #Atom("3")})), a)) - eq(__LOC__, (Js.String2.trim(print_or_error(a)), Js.String2.trim("Ok:(x x gh 3 3)\n"))) -} - -let () = Mt.from_pair_suites(__MODULE__, suites.contents) - -/* -[%bs.internal.test ] -*/ diff --git a/jscomp/test/single_module_alias.js b/jscomp/test/single_module_alias.js deleted file mode 100644 index 4b4c50b69f..0000000000 --- a/jscomp/test/single_module_alias.js +++ /dev/null @@ -1,8 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - - -let L; - -exports.L = L; -/* No side effect */ diff --git a/jscomp/test/single_module_alias.res b/jscomp/test/single_module_alias.res deleted file mode 100644 index 9792cc27d5..0000000000 --- a/jscomp/test/single_module_alias.res +++ /dev/null @@ -1 +0,0 @@ -module L = List diff --git a/jscomp/test/splice_test.js b/jscomp/test/splice_test.js index 5bf879221e..12a6befaca 100644 --- a/jscomp/test/splice_test.js +++ b/jscomp/test/splice_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_array = require("../../lib/js/caml_array.js"); +let Belt_Array = require("../../lib/js/belt_Array.js"); let suites = { contents: /* [] */0 @@ -28,7 +28,7 @@ let a = []; a.push(1, 2, 3, 4); -eq("File \"splice_test.res\", line 23, characters 5-12", a, [ +eq("File \"splice_test.res\", line 25, characters 5-12", a, [ 1, 2, 3, @@ -38,13 +38,10 @@ eq("File \"splice_test.res\", line 23, characters 5-12", a, [ function dynamic(arr) { let a = []; a.push(1, ...arr); - eq("File \"splice_test.res\", line 29, characters 5-12", a, Caml_array.concat({ - hd: [1], - tl: { - hd: arr, - tl: /* [] */0 - } - })); + eq("File \"splice_test.res\", line 31, characters 5-12", a, Belt_Array.concatMany([ + [1], + arr + ])); } dynamic([ @@ -63,7 +60,7 @@ dynamic([ let a$1 = new Array(1, 2, 3, 4); -eq("File \"splice_test.res\", line 44, characters 5-12", a$1, [ +eq("File \"splice_test.res\", line 46, characters 5-12", a$1, [ 1, 2, 3, @@ -72,16 +69,13 @@ eq("File \"splice_test.res\", line 44, characters 5-12", a$1, [ function dynamicNew(arr) { let a = new Array(1, 2, ...arr); - eq("File \"splice_test.res\", line 49, characters 5-12", a, Caml_array.concat({ - hd: [ + eq("File \"splice_test.res\", line 51, characters 5-12", a, Belt_Array.concatMany([ + [ 1, 2 ], - tl: { - hd: arr, - tl: /* [] */0 - } - })); + arr + ])); } dynamicNew([ @@ -105,7 +99,7 @@ class Foo { let f = new Foo("a", "b", "c"); -eq("File \"splice_test.res\", line 71, characters 5-12", f.names, [ +eq("File \"splice_test.res\", line 73, characters 5-12", f.names, [ "a", "b", "c" @@ -113,7 +107,7 @@ eq("File \"splice_test.res\", line 71, characters 5-12", f.names, [ function dynamicFoo(arr) { let f = new Foo(...arr); - eq("File \"splice_test.res\", line 76, characters 5-12", f.names, arr); + eq("File \"splice_test.res\", line 78, characters 5-12", f.names, arr); } dynamicFoo([]); @@ -130,7 +124,7 @@ let a$2 = []; a$2.push(1, 2, 3, 4); -eq("File \"splice_test.res\", line 93, characters 7-14", a$2, [ +eq("File \"splice_test.res\", line 95, characters 7-14", a$2, [ 1, 2, 3, @@ -140,13 +134,10 @@ eq("File \"splice_test.res\", line 93, characters 7-14", a$2, [ function dynamic$1(arr) { let a = []; a.push(1, ...arr); - eq("File \"splice_test.res\", line 99, characters 7-14", a, Caml_array.concat({ - hd: [1], - tl: { - hd: arr, - tl: /* [] */0 - } - })); + eq("File \"splice_test.res\", line 101, characters 7-14", a, Belt_Array.concatMany([ + [1], + arr + ])); } dynamic$1([ @@ -171,11 +162,11 @@ function f1(c) { return Math.max(1, ...c); } -eq("File \"splice_test.res\", line 109, characters 3-10", Math.max(1, 2, 3), 3); +eq("File \"splice_test.res\", line 111, characters 3-10", Math.max(1, 2, 3), 3); -eq("File \"splice_test.res\", line 110, characters 3-10", Math.max(1), 1); +eq("File \"splice_test.res\", line 112, characters 3-10", Math.max(1), 1); -eq("File \"splice_test.res\", line 111, characters 3-10", Math.max(1, 1, 2, 3, 4, 5, 2, 3), 5); +eq("File \"splice_test.res\", line 113, characters 3-10", Math.max(1, 1, 2, 3, 4, 5, 2, 3), 5); Mt.from_pair_suites("splice_test.res", suites.contents); diff --git a/jscomp/test/splice_test.res b/jscomp/test/splice_test.res index 447574bfd0..cd568ecce4 100644 --- a/jscomp/test/splice_test.res +++ b/jscomp/test/splice_test.res @@ -1,3 +1,5 @@ +open Belt + let suites: ref = ref(list{}) let test_id = ref(0) let eq = (loc, x, y) => Mt.eq_suites(~test_id, ~suites, loc, x, y) @@ -26,7 +28,7 @@ let () = { let dynamic = arr => { let a = [] a->push(1, arr) - eq(__LOC__, a, Array.concat(list{[1], arr})) + eq(__LOC__, a, Array.concatMany([[1], arr])) } dynamic([2, 3, 4]) @@ -46,7 +48,7 @@ let () = { let dynamicNew = arr => { let a = newArr(1, 2, arr) - eq(__LOC__, a, Array.concat(list{[1, 2], arr})) + eq(__LOC__, a, Array.concatMany([[1, 2], arr])) } dynamicNew([3, 4]) @@ -96,7 +98,7 @@ module Pipe = { let dynamic = arr => { let a = [] a->push(1, arr) - eq(__LOC__, a, Array.concat(list{[1], arr})) + eq(__LOC__, a, Array.concatMany([[1], arr])) } dynamic([2, 3, 4]) diff --git a/jscomp/test/stack_comp_test.js b/jscomp/test/stack_comp_test.js deleted file mode 100644 index 7a41fdc6ec..0000000000 --- a/jscomp/test/stack_comp_test.js +++ /dev/null @@ -1,450 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); -let Stack = require("../../lib/js/stack.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); -let Mt_global = require("./mt_global.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); - -let suites = { - contents: /* [] */0 -}; - -let test_id = { - contents: 0 -}; - -function eq(f, param) { - Mt_global.collect_eq(test_id, suites, f, param[0], param[1]); -} - -function assert_(loc, v) { - eq(loc, [ - v, - true - ]); -} - -function to_list(s) { - let l = { - contents: /* [] */0 - }; - List.iter(x => { - l.contents = { - hd: x, - tl: l.contents - }; - }, s.c); - return l.contents; -} - -let S = { - Empty: Stack.Empty, - create: Stack.create, - push: Stack.push, - pop: Stack.pop, - top: Stack.top, - clear: Stack.clear, - copy: Stack.copy, - is_empty: Stack.is_empty, - length: Stack.length, - iter: Stack.iter, - fold: Stack.fold, - to_list: to_list -}; - -function does_raise(f, s) { - try { - f(s); - return false; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === Stack.Empty) { - return true; - } - throw exn; - } -} - -let s = { - c: /* [] */0, - len: 0 -}; - -assert_("File \"stack_comp_test.res\", line 39, characters 10-17", to_list(s) === /* [] */0 && s.len === 0); - -Stack.push(1, s); - -assert_("File \"stack_comp_test.res\", line 41, characters 10-17", Caml_obj.equal(to_list(s), { - hd: 1, - tl: /* [] */0 -}) && s.len === 1); - -Stack.push(2, s); - -assert_("File \"stack_comp_test.res\", line 43, characters 10-17", Caml_obj.equal(to_list(s), { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } -}) && s.len === 2); - -Stack.push(3, s); - -assert_("File \"stack_comp_test.res\", line 45, characters 10-17", Caml_obj.equal(to_list(s), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } -}) && s.len === 3); - -Stack.push(4, s); - -assert_("File \"stack_comp_test.res\", line 47, characters 10-17", Caml_obj.equal(to_list(s), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } -}) && s.len === 4); - -assert_("File \"stack_comp_test.res\", line 48, characters 10-17", Stack.pop(s) === 4); - -assert_("File \"stack_comp_test.res\", line 49, characters 10-17", Caml_obj.equal(to_list(s), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } -}) && s.len === 3); - -assert_("File \"stack_comp_test.res\", line 50, characters 10-17", Stack.pop(s) === 3); - -assert_("File \"stack_comp_test.res\", line 51, characters 10-17", Caml_obj.equal(to_list(s), { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } -}) && s.len === 2); - -assert_("File \"stack_comp_test.res\", line 52, characters 10-17", Stack.pop(s) === 2); - -assert_("File \"stack_comp_test.res\", line 53, characters 10-17", Caml_obj.equal(to_list(s), { - hd: 1, - tl: /* [] */0 -}) && s.len === 1); - -assert_("File \"stack_comp_test.res\", line 54, characters 10-17", Stack.pop(s) === 1); - -assert_("File \"stack_comp_test.res\", line 55, characters 10-17", to_list(s) === /* [] */0 && s.len === 0); - -assert_("File \"stack_comp_test.res\", line 56, characters 10-17", does_raise(Stack.pop, s)); - -let s$1 = { - c: /* [] */0, - len: 0 -}; - -Stack.push(1, s$1); - -assert_("File \"stack_comp_test.res\", line 62, characters 10-17", Stack.pop(s$1) === 1); - -assert_("File \"stack_comp_test.res\", line 63, characters 10-17", does_raise(Stack.pop, s$1)); - -Stack.push(2, s$1); - -assert_("File \"stack_comp_test.res\", line 65, characters 10-17", Stack.pop(s$1) === 2); - -assert_("File \"stack_comp_test.res\", line 66, characters 10-17", does_raise(Stack.pop, s$1)); - -assert_("File \"stack_comp_test.res\", line 67, characters 10-17", s$1.len === 0); - -let s$2 = { - c: /* [] */0, - len: 0 -}; - -Stack.push(1, s$2); - -assert_("File \"stack_comp_test.res\", line 73, characters 10-17", Stack.top(s$2) === 1); - -Stack.push(2, s$2); - -assert_("File \"stack_comp_test.res\", line 75, characters 10-17", Stack.top(s$2) === 2); - -Stack.push(3, s$2); - -assert_("File \"stack_comp_test.res\", line 77, characters 10-17", Stack.top(s$2) === 3); - -assert_("File \"stack_comp_test.res\", line 78, characters 10-17", Stack.top(s$2) === 3); - -assert_("File \"stack_comp_test.res\", line 79, characters 10-17", Stack.pop(s$2) === 3); - -assert_("File \"stack_comp_test.res\", line 80, characters 10-17", Stack.top(s$2) === 2); - -assert_("File \"stack_comp_test.res\", line 81, characters 10-17", Stack.pop(s$2) === 2); - -assert_("File \"stack_comp_test.res\", line 82, characters 10-17", Stack.top(s$2) === 1); - -assert_("File \"stack_comp_test.res\", line 83, characters 10-17", Stack.pop(s$2) === 1); - -assert_("File \"stack_comp_test.res\", line 84, characters 10-17", does_raise(Stack.top, s$2)); - -assert_("File \"stack_comp_test.res\", line 85, characters 10-17", does_raise(Stack.top, s$2)); - -let s$3 = { - c: /* [] */0, - len: 0 -}; - -for (let i = 1; i <= 10; ++i) { - Stack.push(i, s$3); -} - -Stack.clear(s$3); - -assert_("File \"stack_comp_test.res\", line 94, characters 10-17", s$3.len === 0); - -assert_("File \"stack_comp_test.res\", line 95, characters 10-17", does_raise(Stack.pop, s$3)); - -assert_("File \"stack_comp_test.res\", line 96, characters 10-17", Caml_obj.equal(s$3, { - c: /* [] */0, - len: 0 -})); - -Stack.push(42, s$3); - -assert_("File \"stack_comp_test.res\", line 98, characters 10-17", Stack.pop(s$3) === 42); - -let s1 = { - c: /* [] */0, - len: 0 -}; - -for (let i$1 = 1; i$1 <= 10; ++i$1) { - Stack.push(i$1, s1); -} - -let s2 = Stack.copy(s1); - -assert_("File \"stack_comp_test.res\", line 107, characters 10-17", Caml_obj.equal(to_list(s1), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: { - hd: 6, - tl: { - hd: 7, - tl: { - hd: 8, - tl: { - hd: 9, - tl: { - hd: 10, - tl: /* [] */0 - } - } - } - } - } - } - } - } - } -})); - -assert_("File \"stack_comp_test.res\", line 108, characters 10-17", Caml_obj.equal(to_list(s2), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: { - hd: 6, - tl: { - hd: 7, - tl: { - hd: 8, - tl: { - hd: 9, - tl: { - hd: 10, - tl: /* [] */0 - } - } - } - } - } - } - } - } - } -})); - -assert_("File \"stack_comp_test.res\", line 109, characters 10-17", s1.len === 10); - -assert_("File \"stack_comp_test.res\", line 110, characters 10-17", s2.len === 10); - -for (let i$2 = 10; i$2 >= 1; --i$2) { - assert_("File \"stack_comp_test.res\", line 112, characters 12-19", Stack.pop(s1) === i$2); -} - -for (let i$3 = 10; i$3 >= 1; --i$3) { - assert_("File \"stack_comp_test.res\", line 115, characters 12-19", Stack.pop(s2) === i$3); -} - -let s$4 = { - c: /* [] */0, - len: 0 -}; - -assert_("File \"stack_comp_test.res\", line 121, characters 10-17", s$4.c === /* [] */0); - -for (let i$4 = 1; i$4 <= 10; ++i$4) { - Stack.push(i$4, s$4); - assert_("File \"stack_comp_test.res\", line 124, characters 12-19", s$4.len === i$4); - assert_("File \"stack_comp_test.res\", line 125, characters 12-19", s$4.c !== /* [] */0); -} - -for (let i$5 = 10; i$5 >= 1; --i$5) { - assert_("File \"stack_comp_test.res\", line 128, characters 12-19", s$4.len === i$5); - assert_("File \"stack_comp_test.res\", line 129, characters 12-19", s$4.c !== /* [] */0); - Stack.pop(s$4); -} - -assert_("File \"stack_comp_test.res\", line 132, characters 10-17", s$4.len === 0); - -assert_("File \"stack_comp_test.res\", line 133, characters 10-17", s$4.c === /* [] */0); - -let s$5 = { - c: /* [] */0, - len: 0 -}; - -for (let i$6 = 10; i$6 >= 1; --i$6) { - Stack.push(i$6, s$5); -} - -let i$7 = { - contents: 1 -}; - -List.iter(j => { - assert_("File \"stack_comp_test.res\", line 143, characters 12-19", i$7.contents === j); - i$7.contents = i$7.contents + 1 | 0; -}, s$5.c); - -let s1$1 = { - c: /* [] */0, - len: 0 -}; - -assert_("File \"stack_comp_test.res\", line 150, characters 10-17", s1$1.len === 0); - -assert_("File \"stack_comp_test.res\", line 151, characters 10-17", to_list(s1$1) === /* [] */0); - -let s2$1 = Stack.copy(s1$1); - -assert_("File \"stack_comp_test.res\", line 153, characters 10-17", s1$1.len === 0); - -assert_("File \"stack_comp_test.res\", line 154, characters 10-17", to_list(s1$1) === /* [] */0); - -assert_("File \"stack_comp_test.res\", line 155, characters 10-17", s2$1.len === 0); - -assert_("File \"stack_comp_test.res\", line 156, characters 10-17", to_list(s2$1) === /* [] */0); - -let s1$2 = { - c: /* [] */0, - len: 0 -}; - -for (let i$8 = 1; i$8 <= 4; ++i$8) { - Stack.push(i$8, s1$2); -} - -assert_("File \"stack_comp_test.res\", line 165, characters 10-17", s1$2.len === 4); - -assert_("File \"stack_comp_test.res\", line 166, characters 10-17", Caml_obj.equal(to_list(s1$2), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } -})); - -let s2$2 = Stack.copy(s1$2); - -assert_("File \"stack_comp_test.res\", line 168, characters 10-17", s1$2.len === 4); - -assert_("File \"stack_comp_test.res\", line 169, characters 10-17", Caml_obj.equal(to_list(s1$2), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } -})); - -assert_("File \"stack_comp_test.res\", line 170, characters 10-17", s2$2.len === 4); - -assert_("File \"stack_comp_test.res\", line 171, characters 10-17", Caml_obj.equal(to_list(s2$2), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } -})); - -Mt.from_pair_suites("Stack_comp_test", suites.contents); - -exports.suites = suites; -exports.test_id = test_id; -exports.eq = eq; -exports.assert_ = assert_; -exports.S = S; -exports.does_raise = does_raise; -/* s Not a pure module */ diff --git a/jscomp/test/stack_comp_test.res b/jscomp/test/stack_comp_test.res deleted file mode 100644 index 326af18a38..0000000000 --- a/jscomp/test/stack_comp_test.res +++ /dev/null @@ -1,174 +0,0 @@ -/* ********************************************************************* */ -/* */ -/* OCaml */ -/* */ -/* Jeremie Dimino, Jane Street Europe */ -/* */ -/* Copyright 2015 Institut National de Recherche en Informatique et */ -/* en Automatique. All rights reserved. This file is distributed */ -/* under the terms of the S Public License version 1.0. */ -/* */ -/* ********************************************************************* */ - -let suites: ref = ref(list{}) -let test_id = ref(0) -let eq = (f, (a, b)) => Mt_global.collect_eq(test_id, suites, f, a, b) -let assert_ = (loc, v) => eq(loc, (v, true)) - -module S = { - include Stack - - let to_list = s => { - let l = ref(list{}) - iter(x => l := list{x, ...l.contents}, s) - l.contents - } /* from bottom to top */ -} - -let does_raise = (f, s) => - try { - ignore((f(s): int)) - false - } catch { - | S.Empty => true - } - -let () = { - let s = S.create() - () - assert_(__LOC__, S.to_list(s) == list{} && S.length(s) == 0) - S.push(1, s) - assert_(__LOC__, S.to_list(s) == list{1} && S.length(s) == 1) - S.push(2, s) - assert_(__LOC__, S.to_list(s) == list{1, 2} && S.length(s) == 2) - S.push(3, s) - assert_(__LOC__, S.to_list(s) == list{1, 2, 3} && S.length(s) == 3) - S.push(4, s) - assert_(__LOC__, S.to_list(s) == list{1, 2, 3, 4} && S.length(s) == 4) - assert_(__LOC__, S.pop(s) == 4) - assert_(__LOC__, S.to_list(s) == list{1, 2, 3} && S.length(s) == 3) - assert_(__LOC__, S.pop(s) == 3) - assert_(__LOC__, S.to_list(s) == list{1, 2} && S.length(s) == 2) - assert_(__LOC__, S.pop(s) == 2) - assert_(__LOC__, S.to_list(s) == list{1} && S.length(s) == 1) - assert_(__LOC__, S.pop(s) == 1) - assert_(__LOC__, S.to_list(s) == list{} && S.length(s) == 0) - assert_(__LOC__, does_raise(S.pop, s)) -} - -let () = { - let s = S.create() - S.push(1, s) - assert_(__LOC__, S.pop(s) == 1) - assert_(__LOC__, does_raise(S.pop, s)) - S.push(2, s) - assert_(__LOC__, S.pop(s) == 2) - assert_(__LOC__, does_raise(S.pop, s)) - assert_(__LOC__, S.length(s) == 0) -} - -let () = { - let s = S.create() - S.push(1, s) - assert_(__LOC__, S.top(s) == 1) - S.push(2, s) - assert_(__LOC__, S.top(s) == 2) - S.push(3, s) - assert_(__LOC__, S.top(s) == 3) - assert_(__LOC__, S.top(s) == 3) - assert_(__LOC__, S.pop(s) == 3) - assert_(__LOC__, S.top(s) == 2) - assert_(__LOC__, S.pop(s) == 2) - assert_(__LOC__, S.top(s) == 1) - assert_(__LOC__, S.pop(s) == 1) - assert_(__LOC__, does_raise(S.top, s)) - assert_(__LOC__, does_raise(S.top, s)) -} - -let () = { - let s = S.create() - for i in 1 to 10 { - S.push(i, s) - } - S.clear(s) - assert_(__LOC__, S.length(s) == 0) - assert_(__LOC__, does_raise(S.pop, s)) - assert_(__LOC__, s == S.create()) - S.push(42, s) - assert_(__LOC__, S.pop(s) == 42) -} - -let () = { - let s1 = S.create() - for i in 1 to 10 { - S.push(i, s1) - } - let s2 = S.copy(s1) - assert_(__LOC__, S.to_list(s1) == list{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) - assert_(__LOC__, S.to_list(s2) == list{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) - assert_(__LOC__, S.length(s1) == 10) - assert_(__LOC__, S.length(s2) == 10) - for i in 10 downto 1 { - assert_(__LOC__, S.pop(s1) == i) - } - for i in 10 downto 1 { - assert_(__LOC__, S.pop(s2) == i) - } -} - -let () = { - let s = S.create() - assert_(__LOC__, S.is_empty(s)) - for i in 1 to 10 { - S.push(i, s) - assert_(__LOC__, S.length(s) == i) - assert_(__LOC__, !S.is_empty(s)) - } - for i in 10 downto 1 { - assert_(__LOC__, S.length(s) == i) - assert_(__LOC__, !S.is_empty(s)) - ignore((S.pop(s): int)) - } - assert_(__LOC__, S.length(s) == 0) - assert_(__LOC__, S.is_empty(s)) -} - -let () = { - let s = S.create() - for i in 10 downto 1 { - S.push(i, s) - } - let i = ref(1) - S.iter(j => { - assert_(__LOC__, i.contents == j) - incr(i) - }, s) -} - -let () = { - let s1 = S.create() - assert_(__LOC__, S.length(s1) == 0) - assert_(__LOC__, S.to_list(s1) == list{}) - let s2 = S.copy(s1) - assert_(__LOC__, S.length(s1) == 0) - assert_(__LOC__, S.to_list(s1) == list{}) - assert_(__LOC__, S.length(s2) == 0) - assert_(__LOC__, S.to_list(s2) == list{}) -} - -let () = { - let s1 = S.create() - let _s2 = S.create() - for i in 1 to 4 { - S.push(i, s1) - } - assert_(__LOC__, S.length(s1) == 4) - assert_(__LOC__, S.to_list(s1) == list{1, 2, 3, 4}) - let s2 = S.copy(s1) - assert_(__LOC__, S.length(s1) == 4) - assert_(__LOC__, S.to_list(s1) == list{1, 2, 3, 4}) - assert_(__LOC__, S.length(s2) == 4) - assert_(__LOC__, S.to_list(s2) == list{1, 2, 3, 4}) -} - -let () = Mt.from_pair_suites(__MODULE__, suites.contents) diff --git a/jscomp/test/stack_test.js b/jscomp/test/stack_test.js deleted file mode 100644 index 2dc90165f6..0000000000 --- a/jscomp/test/stack_test.js +++ /dev/null @@ -1,58 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); -let Stack = require("../../lib/js/stack.js"); - -function to_list(v) { - let acc = /* [] */0; - while (v.c !== /* [] */0) { - acc = { - hd: Stack.pop(v), - tl: acc - }; - }; - return List.rev(acc); -} - -function v() { - let v$1 = { - c: /* [] */0, - len: 0 - }; - Stack.push(3, v$1); - Stack.push(4, v$1); - Stack.push(1, v$1); - return to_list(v$1); -} - -let suites_0 = [ - "push_test", - param => ({ - TAG: "Eq", - _0: { - hd: 1, - tl: { - hd: 4, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, - _1: v() - }) -]; - -let suites = { - hd: suites_0, - tl: /* [] */0 -}; - -Mt.from_pair_suites("Stack_test", suites); - -exports.to_list = to_list; -exports.v = v; -exports.suites = suites; -/* Not a pure module */ diff --git a/jscomp/test/stack_test.res b/jscomp/test/stack_test.res deleted file mode 100644 index 48cc753c21..0000000000 --- a/jscomp/test/stack_test.res +++ /dev/null @@ -1,21 +0,0 @@ -open Stack - -let to_list = v => { - let acc = ref(list{}) - while \"@@"(not, is_empty(v)) { - acc := list{pop(v), ...acc.contents} - } - List.rev(acc.contents) -} - -let v = () => { - let v = create() - push(3, v) - push(4, v) - push(1, v) - to_list(v) -} - -let suites = list{("push_test", _ => Mt.Eq(list{1, 4, 3}, v()))} - -Mt.from_pair_suites(__MODULE__, suites) diff --git a/jscomp/test/stream_parser_test.js b/jscomp/test/stream_parser_test.js deleted file mode 100644 index 21d927d1a4..0000000000 --- a/jscomp/test/stream_parser_test.js +++ /dev/null @@ -1,325 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let Queue = require("../../lib/js/queue.js"); -let Genlex = require("../../lib/js/genlex.js"); -let Stream = require("../../lib/js/stream.js"); -let Caml_int32 = require("../../lib/js/caml_int32.js"); -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); - -let Parse_error = /* @__PURE__ */Caml_exceptions.create("Stream_parser_test.Parse_error"); - -function parse(token) { - let look_ahead = { - length: 0, - first: "Nil", - last: "Nil" - }; - let token$1 = () => { - if (look_ahead.length !== 0) { - return Queue.pop(look_ahead); - } - try { - return token(); - } catch (exn) { - return { - TAG: "Kwd", - _0: "==" - }; - } - }; - let parse_atom = () => { - let n = token$1(); - switch (n.TAG) { - case "Kwd" : - if (n._0 === "(") { - let v = parse_expr_aux(parse_term()); - let match = token$1(); - if (match.TAG === "Kwd") { - if (match._0 === ")") { - return v; - } - throw { - RE_EXN_ID: Parse_error, - _1: "Unbalanced parens", - Error: new Error() - }; - } - throw { - RE_EXN_ID: Parse_error, - _1: "Unbalanced parens", - Error: new Error() - }; - } - Queue.push(n, look_ahead); - throw { - RE_EXN_ID: Parse_error, - _1: "unexpected token", - Error: new Error() - }; - case "Int" : - return n._0; - default: - Queue.push(n, look_ahead); - throw { - RE_EXN_ID: Parse_error, - _1: "unexpected token", - Error: new Error() - }; - } - }; - let parse_term = () => parse_term_aux(parse_atom()); - let parse_expr_aux = e1 => { - let e = token$1(); - if (e.TAG === "Kwd") { - switch (e._0) { - case "+" : - return e1 + parse_expr_aux(parse_term()) | 0; - case "-" : - return e1 - parse_expr_aux(parse_term()) | 0; - default: - Queue.push(e, look_ahead); - return e1; - } - } else { - Queue.push(e, look_ahead); - return e1; - } - }; - let parse_term_aux = e1 => { - let e = token$1(); - if (e.TAG === "Kwd") { - switch (e._0) { - case "*" : - return Math.imul(e1, parse_term_aux(parse_atom())); - case "/" : - return Caml_int32.div(e1, parse_term_aux(parse_atom())); - default: - Queue.push(e, look_ahead); - return e1; - } - } else { - Queue.push(e, look_ahead); - return e1; - } - }; - let r = parse_expr_aux(parse_term()); - return [ - r, - Queue.fold((acc, x) => ({ - hd: x, - tl: acc - }), /* [] */0, look_ahead) - ]; -} - -let lexer = Genlex.make_lexer({ - hd: "(", - tl: { - hd: "*", - tl: { - hd: "/", - tl: { - hd: "+", - tl: { - hd: "-", - tl: { - hd: ")", - tl: /* [] */0 - } - } - } - } - } -}); - -function token(chars) { - let strm = lexer(chars); - return () => Stream.next(strm); -} - -function l_parse(token) { - let look_ahead = { - length: 0, - first: "Nil", - last: "Nil" - }; - let token$1 = () => { - if (look_ahead.length !== 0) { - return Queue.pop(look_ahead); - } - try { - return token(); - } catch (exn) { - return { - TAG: "Kwd", - _0: "==" - }; - } - }; - let parse_f = () => { - let i = token$1(); - switch (i.TAG) { - case "Kwd" : - if (i._0 === "(") { - let v = parse_t_aux(parse_t()); - let t = token$1(); - if (t.TAG === "Kwd") { - if (t._0 === ")") { - return v; - } - throw { - RE_EXN_ID: Parse_error, - _1: "Unbalanced )", - Error: new Error() - }; - } - throw { - RE_EXN_ID: Parse_error, - _1: "Unbalanced )", - Error: new Error() - }; - } - throw { - RE_EXN_ID: Parse_error, - _1: "Unexpected token", - Error: new Error() - }; - case "Int" : - return i._0; - default: - throw { - RE_EXN_ID: Parse_error, - _1: "Unexpected token", - Error: new Error() - }; - } - }; - let parse_f_aux = _a => { - while (true) { - let a = _a; - let t = token$1(); - if (t.TAG === "Kwd") { - switch (t._0) { - case "*" : - _a = Math.imul(a, parse_f()); - continue; - case "/" : - _a = Caml_int32.div(a, parse_f()); - continue; - default: - Queue.push(t, look_ahead); - return a; - } - } else { - Queue.push(t, look_ahead); - return a; - } - }; - }; - let parse_t_aux = _a => { - while (true) { - let a = _a; - let t = token$1(); - if (t.TAG === "Kwd") { - switch (t._0) { - case "+" : - _a = a + parse_f_aux(parse_f()) | 0; - continue; - case "-" : - _a = a - parse_f_aux(parse_f()) | 0; - continue; - default: - Queue.push(t, look_ahead); - return a; - } - } else { - Queue.push(t, look_ahead); - return a; - } - }; - }; - let parse_t = () => parse_f_aux(parse_f()); - let r = parse_t_aux(parse_t()); - return [ - r, - Queue.fold((acc, x) => ({ - hd: x, - tl: acc - }), /* [] */0, look_ahead) - ]; -} - -let suites = { - contents: /* [] */0 -}; - -let test_id = { - contents: 0 -}; - -function eq(loc, x, y) { - test_id.contents = test_id.contents + 1 | 0; - suites.contents = { - hd: [ - loc + (" id " + String(test_id.contents)), - () => ({ - TAG: "Eq", - _0: x, - _1: y - }) - ], - tl: suites.contents - }; -} - -let match = parse(token(Stream.of_string("1 + 2 + (3 - 2) * 3 * 3 - 2 a"))); - -eq("File \"stream_parser_test.res\", line 141, characters 5-12", [ - match[0], - match[1] -], [ - 10, - { - hd: { - TAG: "Ident", - _0: "a" - }, - tl: /* [] */0 - } -]); - -eq("File \"stream_parser_test.res\", line 142, characters 5-12", [ - 2, - { - hd: { - TAG: "Kwd", - _0: "==" - }, - tl: /* [] */0 - } -], parse(token(Stream.of_string("3 - 2 - 1")))); - -eq("File \"stream_parser_test.res\", line 143, characters 5-12", [ - 0, - { - hd: { - TAG: "Kwd", - _0: "==" - }, - tl: /* [] */0 - } -], l_parse(token(Stream.of_string("3 - 2 - 1")))); - -Mt.from_pair_suites("Stream_parser_test", suites.contents); - -exports.Parse_error = Parse_error; -exports.parse = parse; -exports.lexer = lexer; -exports.token = token; -exports.l_parse = l_parse; -exports.suites = suites; -exports.test_id = test_id; -exports.eq = eq; -/* lexer Not a pure module */ diff --git a/jscomp/test/stream_parser_test.res b/jscomp/test/stream_parser_test.res deleted file mode 100644 index bf6f82113f..0000000000 --- a/jscomp/test/stream_parser_test.res +++ /dev/null @@ -1,146 +0,0 @@ -exception Parse_error(string) - -/** - -expr -| expr1 expr_aux -expr_aux -| + expr -expr1 -| expr2 expr1_aux -expr1_aux -| * expr1 - -expr2 -| Int -| ( expr ) - -*/ -let parse = (token: unit => Genlex.token) => { - let look_ahead = Queue.create() - let token = () => - if Queue.is_empty(look_ahead) { - try token() catch { - | _ => Kwd("==") - } - } else { - Queue.pop(look_ahead) - } - let push = e => Queue.push(e, look_ahead) - let rec parse_atom = () => - switch token() { - | Int(n) => n - | Kwd("(") => - let v = parse_expr() - switch token() { - | Kwd(")") => v - | _ => raise(Parse_error("Unbalanced parens")) - } - | e => - push(e) - raise(Parse_error("unexpected token")) - } - and parse_term = () => parse_term_aux(parse_atom()) - and parse_term_aux = e1 => - switch token() { - | Kwd("*") => e1 * parse_term() - | Kwd("/") => e1 / parse_term() - | e => - push(e) - e1 - } - and parse_expr = () => parse_expr_aux(parse_term()) - and parse_expr_aux = e1 => - switch token() { - | Kwd("+") => e1 + parse_expr() - | Kwd("-") => e1 - parse_expr() - | e => - /* [%debugger]; */ push(e) - e1 - } - - let r = parse_expr() - (r, Queue.fold((acc, x) => list{x, ...acc}, list{}, look_ahead)) -} -let lexer = Genlex.make_lexer(list{"(", "*", "/", "+", "-", ")"}) -let token = chars => { - let strm = lexer(chars) - () => Stream.next(strm) -} - -/* - -http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm - -E -| T { + T} -T -| F { * F} -F -| Int -| (E) - -*/ - -let l_parse = (token: unit => Genlex.token) => { - let look_ahead = Queue.create() - let token = () => - if Queue.is_empty(look_ahead) { - try token() catch { - | _ => Kwd("==") - } - } else { - Queue.pop(look_ahead) - } - let push = e => Queue.push(e, look_ahead) - let rec parse_e = () => parse_t_aux(parse_t()) - and parse_t_aux = a => - switch token() { - | Kwd("+") => parse_t_aux(a + parse_t()) - | Kwd("-") => parse_t_aux(a - parse_t()) - | t => - push(t) - a - } - and parse_t = () => parse_f_aux(parse_f()) - and parse_f_aux = a => - switch token() { - | Kwd("*") => parse_f_aux(a * parse_f()) - | Kwd("/") => parse_f_aux(a / parse_f()) - | t => - push(t) - a - } - and parse_f = () => - switch token() { - | Int(i) => i - | Kwd("(") => - let v = parse_e() - switch token() { - | Kwd(")") => v - | t => raise(Parse_error("Unbalanced )")) - } - | t => raise(Parse_error("Unexpected token")) - } - - let r = parse_e() - (r, Queue.fold((acc, x) => list{x, ...acc}, list{}, look_ahead)) -} - -let suites: ref = ref(list{}) -let test_id = ref(0) -let eq = (loc, x, y) => { - incr(test_id) - suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} -} - -let () = { - let (a, b) = parse(token(Stream.of_string("1 + 2 + (3 - 2) * 3 * 3 - 2 a"))) - - eq(__LOC__, (a, b), (10, list{Ident("a")})) - eq(__LOC__, (2, list{Genlex.Kwd("==")}), parse(token(Stream.of_string("3 - 2 - 1")))) - eq(__LOC__, (0, list{Genlex.Kwd("==")}), l_parse(token(Stream.of_string("3 - 2 - 1")))) -} - -let () = Mt.from_pair_suites(__MODULE__, suites.contents) diff --git a/jscomp/test/string_bound_get_test.js b/jscomp/test/string_bound_get_test.js index 3cb61d01e2..ce4117cece 100644 --- a/jscomp/test/string_bound_get_test.js +++ b/jscomp/test/string_bound_get_test.js @@ -1,29 +1,19 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_bytes = require("../../lib/js/caml_bytes.js"); -let Caml_string = require("../../lib/js/caml_string.js"); let v = "ghos"; -let u_a = Caml_string.get(v, 0); +let u_a = v.codePointAt(0); function u_b() { - return Caml_string.get(v, -1); + return v.codePointAt(-1); } -let u_c = Caml_string.get("ghos", 0); +let u_c = "ghos".codePointAt(0); function u_d() { - return Caml_string.get("ghos", -1); -} - -let u_e = Caml_bytes.create(32); - -let u_f = Caml_bytes.get(u_e, 0); - -function u_g() { - return Caml_bytes.get(u_e, -1); + return "ghos".codePointAt(-1); } exports.v = v; @@ -31,7 +21,4 @@ exports.u_a = u_a; exports.u_b = u_b; exports.u_c = u_c; exports.u_d = u_d; -exports.u_e = u_e; -exports.u_f = u_f; -exports.u_g = u_g; -/* No side effect */ +/* u_a Not a pure module */ diff --git a/jscomp/test/string_bound_get_test.res b/jscomp/test/string_bound_get_test.res index 6a6b5cc2ea..333ed3dad3 100644 --- a/jscomp/test/string_bound_get_test.res +++ b/jscomp/test/string_bound_get_test.res @@ -6,9 +6,3 @@ let u_b = () => String.get(v, -1) let u_c = String.get("ghos", 0) let u_d = () => String.get("ghos", -1) - -let u_e = Bytes.create(32) - -let u_f = Bytes.get(u_e, 0) - -let u_g = () => Bytes.get(u_e, -1) diff --git a/jscomp/test/string_constant_compare.js b/jscomp/test/string_constant_compare.js index 13b55015df..62e69f6b6a 100644 --- a/jscomp/test/string_constant_compare.js +++ b/jscomp/test/string_constant_compare.js @@ -14,4 +14,4 @@ exports.a1 = a1; exports.a2 = a2; exports.a3 = a3; exports.a4 = a4; -/* a1 Not a pure module */ +/* No side effect */ diff --git a/jscomp/test/string_get_set_test.js b/jscomp/test/string_get_set_test.js deleted file mode 100644 index 11516e7225..0000000000 --- a/jscomp/test/string_get_set_test.js +++ /dev/null @@ -1,19 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let Caml_string = require("../../lib/js/caml_string.js"); - -Mt.from_pair_suites("string_get_set_test.res", { - hd: [ - "File \"string_get_set_test.res\", line 4, characters 36-43", - () => ({ - TAG: "Eq", - _0: Caml_string.get("h", 0), - _1: /* 'h' */104 - }) - ], - tl: /* [] */0 -}); - -/* Not a pure module */ diff --git a/jscomp/test/string_get_set_test.res b/jscomp/test/string_get_set_test.res deleted file mode 100644 index 3e9b4b076a..0000000000 --- a/jscomp/test/string_get_set_test.res +++ /dev/null @@ -1,66 +0,0 @@ -@@config({no_export: no_export}) -let \".%()" = (s: string, i) => String.get(s, i) - -Mt.from_pair_suites(__FILE__, list{(__LOC__, _ => Eq(\".%()"("h", 0), 'h'))}) -/* external caml_string_get_16 : string -> int -> int = "%caml_string_get16" -external caml_string_get_32 : string -> int -> int32 = "%caml_string_get32" -external caml_string_get_64 : string -> int -> int64 = "%caml_string_get64" */ - -/* TODO: endian-aware ? */ -/* ;; Mt.from_pair_suites __MODULE__ Mt.[ - __LOC__ , (fun _ -> Eq (caml_string_get_16 "2\000" 0, 50)); - __LOC__ , (fun _ -> Eq (caml_string_get_16 "20" 0, 12338)); - __LOC__, (fun _ -> Eq(caml_string_get_32 "0123" 0, 858927408l)); - __LOC__, (fun _ -> Eq(caml_string_get_32 "0123" 0, 858927408l)); - __LOC__, (fun _ -> Eq(caml_string_get_32 "3210" 0, 808530483l)); - __LOC__, (fun _ -> Eq(caml_string_get_64 "12345678" 0, 4050765991979987505L)); - __LOC__, (fun _ -> Eq(caml_string_get_64 "87654321" 0, 3544952156018063160L)) -] */ - -/* (\** does not make sense under immutable string setting *\) */ -/* external caml_string_set_16 : string -> int -> int -> unit = */ -/* "%caml_string_set16" */ -/* external caml_string_set_32 : string -> int -> int32 -> unit = */ -/* "%caml_string_set32" */ -/* external caml_string_set_64 : string -> int -> int64 -> unit = */ -/* "%caml_string_set64" */ - -/* let s = String.make 10 '\x00' */ -/* let empty_s = "" */ - -/* let assert_bound_check2 f v1 v2 = */ -/* try */ -/* ignore(f v1 v2); */ -/* assert false */ -/* with */ -/* | Invalid_argument("index out of bounds") -> () */ - -/* let assert_bound_check3 f v1 v2 v3 = */ -/* try */ -/* ignore(f v1 v2 v3); */ -/* assert false */ -/* with */ -/* | Invalid_argument("index out of bounds") -> () */ - -/* let f () = */ -/* assert_bound_check2 caml_string_get_16 s (-1); */ -/* assert_bound_check2 caml_string_get_16 s 9; */ -/* assert_bound_check2 caml_string_get_32 s (-1); */ -/* assert_bound_check2 caml_string_get_32 s 7; */ -/* assert_bound_check2 caml_string_get_64 s (-1); */ -/* assert_bound_check2 caml_string_get_64 s 3; */ - -/* assert_bound_check3 caml_string_set_16 s (-1) 0; */ -/* assert_bound_check3 caml_string_set_16 s 9 0; */ -/* assert_bound_check3 caml_string_set_32 s (-1) 0l; */ -/* assert_bound_check3 caml_string_set_32 s 7 0l; */ -/* assert_bound_check3 caml_string_set_64 s (-1) 0L; */ -/* assert_bound_check3 caml_string_set_64 s 3 0L; */ - -/* assert_bound_check2 caml_string_get_16 empty_s 0; */ -/* assert_bound_check2 caml_string_get_32 empty_s 0; */ -/* assert_bound_check2 caml_string_get_64 empty_s 0; */ - -/* assert_bound_check3 caml_string_set_16 empty_s 0 0; */ -/* assert_bound_check3 caml_string_set_32 empty_s 0 0l; */ -/* assert_bound_check3 caml_string_set_64 empty_s 0 0L */ diff --git a/jscomp/test/string_runtime_test.js b/jscomp/test/string_runtime_test.js deleted file mode 100644 index 29e44751c3..0000000000 --- a/jscomp/test/string_runtime_test.js +++ /dev/null @@ -1,76 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); -let Bytes = require("../../lib/js/bytes.js"); -let Test_char = require("./test_char.js"); -let Caml_bytes = require("../../lib/js/caml_bytes.js"); - -let suites_0 = [ - "?is_printable", - param => ({ - TAG: "Eq", - _0: Test_char.caml_is_printable(/* 'a' */97), - _1: true - }) -]; - -let suites_1 = { - hd: [ - "?string_of_bytes", - param => { - let match = List.split(List.map(x => { - let b = Caml_bytes.create(x); - Bytes.fill(b, 0, x, /* 'c' */99); - return [ - Bytes.to_string(b), - Bytes.unsafe_to_string(Bytes.init(x, param => /* 'c' */99)) - ]; - }, { - hd: 1000, - tl: { - hd: 1024, - tl: { - hd: 1025, - tl: { - hd: 4095, - tl: { - hd: 4096, - tl: { - hd: 5000, - tl: { - hd: 10000, - tl: /* [] */0 - } - } - } - } - } - } - })); - return { - TAG: "Eq", - _0: match[0], - _1: match[1] - }; - } - ], - tl: /* [] */0 -}; - -let suites = { - hd: suites_0, - tl: suites_1 -}; - -Mt.from_pair_suites("String_runtime_test", suites); - -let S; - -let B; - -exports.S = S; -exports.B = B; -exports.suites = suites; -/* Not a pure module */ diff --git a/jscomp/test/string_runtime_test.res b/jscomp/test/string_runtime_test.res deleted file mode 100644 index 112b92acbc..0000000000 --- a/jscomp/test/string_runtime_test.res +++ /dev/null @@ -1,35 +0,0 @@ -module S = Caml_string -/** TODO: performance could be improved, however, - this function is not in critical Path - */ -module B = Caml_bytes - -/** TODO: performance could be improved, however, - this function is not in critical Path - */ -let suites = { - open Mt - list{ - /* "string_of_char_array", (fun _ -> - Eq(S.caml_string_of_char_array [|'a';'b';'c'|], "abc") - ); */ - ("?is_printable", _ => Eq(Test_char.caml_is_printable('a'), true)), - ( - "?string_of_bytes", - _ => { - let f = len => { - let b = Bytes.create(len) - Bytes.fill(b, 0, len, 'c') - (Bytes.to_string(b), String.init(len, _ => 'c')) - } - let (a, b) = \"@@"( - List.split, - List.map(x => f(x), list{1000, 1024, 1025, 4095, 4096, 5000, 10000}), - ) - Eq(a, b) - }, - ), - } -} - -Mt.from_pair_suites(__MODULE__, suites) diff --git a/jscomp/test/string_set.js b/jscomp/test/string_set.js index 13db6739ce..874e8afa73 100644 --- a/jscomp/test/string_set.js +++ b/jscomp/test/string_set.js @@ -1,11 +1,12 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml = require("../../lib/js/caml.js"); -let List = require("../../lib/js/list.js"); -let $$Array = require("../../lib/js/array.js"); -let $$String = require("../../lib/js/string.js"); let Set_gen = require("./set_gen.js"); +let Belt_List = require("../../lib/js/belt_List.js"); +let Belt_Array = require("../../lib/js/belt_Array.js"); +let Primitive_string = require("../../lib/js/primitive_string.js"); + +let compare_elt = Primitive_string.compare; function split(x, tree) { if (typeof tree !== "object") { @@ -18,7 +19,7 @@ function split(x, tree) { let r = tree._2; let v = tree._1; let l = tree._0; - let c = Caml.string_compare(x, v); + let c = Primitive_string.compare(x, v); if (c === 0) { return [ l, @@ -55,7 +56,7 @@ function add(x, tree) { let r = tree._2; let v = tree._1; let l = tree._0; - let c = Caml.string_compare(x, v); + let c = Primitive_string.compare(x, v); if (c === 0) { return tree; } else if (c < 0) { @@ -134,7 +135,7 @@ function mem(x, _tree) { if (typeof tree !== "object") { return false; } - let c = Caml.string_compare(x, tree._1); + let c = Primitive_string.compare(x, tree._1); if (c === 0) { return true; } @@ -150,7 +151,7 @@ function remove(x, tree) { let r = tree._2; let v = tree._1; let l = tree._0; - let c = Caml.string_compare(x, v); + let c = Primitive_string.compare(x, v); if (c === 0) { return Set_gen.internal_merge(l, r); } else if (c < 0) { @@ -161,11 +162,11 @@ function remove(x, tree) { } function compare(s1, s2) { - return Set_gen.compare($$String.compare, s1, s2); + return Set_gen.compare(compare_elt, s1, s2); } function equal(s1, s2) { - return Set_gen.compare($$String.compare, s1, s2) === 0; + return Set_gen.compare(compare_elt, s1, s2) === 0; } function subset(_s1, _s2) { @@ -183,7 +184,7 @@ function subset(_s1, _s2) { } let r2 = s2._2; let l2 = s2._0; - let c = Caml.string_compare(v1, s2._1); + let c = Primitive_string.compare(v1, s2._1); if (c === 0) { if (!subset(l1, l2)) { return false; @@ -229,7 +230,7 @@ function find(x, _tree) { }; } let v = tree._1; - let c = Caml.string_compare(x, v); + let c = Primitive_string.compare(x, v); if (c === 0) { return v; } @@ -261,7 +262,7 @@ function of_list(l) { let x3 = match$2.hd; if (match$3) { if (match$3.tl) { - return Set_gen.of_sorted_list(List.sort_uniq($$String.compare, l)); + return Set_gen.of_sorted_list(Belt_List.sort(l, compare_elt)); } else { return add(match$3.hd, add(x3, add(x2, add(x1, Set_gen.singleton(x0))))); } @@ -271,16 +272,14 @@ function of_list(l) { } function of_array(l) { - return $$Array.fold_left((acc, x) => add(x, acc), "Empty", l); + return Belt_Array.reduceReverse(l, "Empty", (acc, x) => add(x, acc)); } function invariant(t) { Set_gen.check(t); - return Set_gen.is_ordered($$String.compare, t); + return Set_gen.is_ordered(compare_elt, t); } -let compare_elt = $$String.compare; - let empty = "Empty"; let is_empty = Set_gen.is_empty; diff --git a/jscomp/test/string_set.res b/jscomp/test/string_set.res index c8e41c0f5e..493e3aabcd 100644 --- a/jscomp/test/string_set.res +++ b/jscomp/test/string_set.res @@ -192,10 +192,10 @@ let of_list = l => | list{x0, x1, x2} => add(x2, add(x1, singleton(x0))) | list{x0, x1, x2, x3} => add(x3, add(x2, add(x1, singleton(x0)))) | list{x0, x1, x2, x3, x4} => add(x4, add(x3, add(x2, add(x1, singleton(x0))))) - | _ => of_sorted_list(List.sort_uniq(compare_elt, l)) + | _ => of_sorted_list(l->Belt.List.sort(compare_elt)) } -let of_array = l => Array.fold_left((acc, x) => add(x, acc), empty, l) +let of_array = l => l->Belt.Array.reduceReverse(empty, (acc, x) => add(x, acc)) /* also check order */ let invariant = t => { diff --git a/jscomp/test/string_set_test.js b/jscomp/test/string_set_test.js index 09ef35775c..74d8022ecd 100644 --- a/jscomp/test/string_set_test.js +++ b/jscomp/test/string_set_test.js @@ -16,7 +16,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -30,10 +30,10 @@ function eq(loc, x, y) { let s = String_set.empty; for (let i = 0; i <= 99999; ++i) { - s = String_set.add(String(i), s); + s = String_set.add(i.toString(), s); } -eq("File \"string_set_test.res\", line 15, characters 5-12", String_set.cardinal(s), 100000); +eq("File \"string_set_test.res\", line 18, characters 5-12", String_set.cardinal(s), 100000); Mt.from_pair_suites("String_set_test", suites.contents); diff --git a/jscomp/test/string_set_test.res b/jscomp/test/string_set_test.res index d2ca0a4ce7..02e8167bfd 100644 --- a/jscomp/test/string_set_test.res +++ b/jscomp/test/string_set_test.res @@ -3,14 +3,17 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let () = { let number = 1_000_00 let s = ref(String_set.empty) for i in 0 to number - 1 { - s := String_set.add(string_of_int(i), s.contents) + s := String_set.add(Js.Int.toString(i), s.contents) } eq(__LOC__, String_set.cardinal(s.contents), number) } diff --git a/jscomp/test/string_test.js b/jscomp/test/string_test.js deleted file mode 100644 index 5922bf6be3..0000000000 --- a/jscomp/test/string_test.js +++ /dev/null @@ -1,348 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Mt = require("./mt.js"); -let List = require("../../lib/js/list.js"); -let $$Array = require("../../lib/js/array.js"); -let Bytes = require("../../lib/js/bytes.js"); -let $$String = require("../../lib/js/string.js"); -let Ext_string_test = require("./ext_string_test.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); - -function ff(x) { - let a; - switch (x) { - case "0" : - case "1" : - case "2" : - a = 3; - break; - case "3" : - a = 4; - break; - case "4" : - a = 6; - break; - case "7" : - a = 7; - break; - default: - a = 8; - } - return a + 3 | 0; -} - -function gg(x) { - let a; - switch (x) { - case 0 : - case 1 : - case 2 : - a = 3; - break; - case 3 : - a = 4; - break; - case 4 : - a = 6; - break; - case 8 : - a = 7; - break; - default: - a = 8; - } - return a + 3 | 0; -} - -function rev_split_by_char(c, s) { - let loop = (i, l) => { - try { - let i$p = $$String.index_from(s, i, c); - let s$p = $$String.sub(s, i, i$p - i | 0); - return loop(i$p + 1 | 0, s$p === "" ? l : ({ - hd: s$p, - tl: l - })); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - return { - hd: $$String.sub(s, i, s.length - i | 0), - tl: l - }; - } - throw exn; - } - }; - return loop(0, /* [] */0); -} - -function xsplit(delim, s) { - let len = s.length; - if (len !== 0) { - let _l = /* [] */0; - let _x = len; - while (true) { - let x = _x; - let l = _l; - if (x === 0) { - return l; - } - let i$p; - try { - i$p = $$String.rindex_from(s, x - 1 | 0, delim); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - return { - hd: $$String.sub(s, 0, x), - tl: l - }; - } - throw exn; - } - let l_0 = $$String.sub(s, i$p + 1 | 0, (x - i$p | 0) - 1 | 0); - let l$1 = { - hd: l_0, - tl: l - }; - let l$2 = i$p === 0 ? ({ - hd: "", - tl: l$1 - }) : l$1; - _x = i$p; - _l = l$2; - continue; - }; - } else { - return /* [] */0; - } -} - -function string_of_chars(x) { - let xs = List.map(prim => String.fromCharCode(prim), x); - return $$Array.of_list(xs).join(""); -} - -Mt.from_pair_suites("String_test", { - hd: [ - "mutliple switch", - () => ({ - TAG: "Eq", - _0: 9, - _1: ff("4") - }) - ], - tl: { - hd: [ - "int switch", - () => ({ - TAG: "Eq", - _0: 9, - _1: gg(4) - }) - ], - tl: { - hd: [ - "escape_normal", - () => ({ - TAG: "Eq", - _0: "haha", - _1: $$String.escaped("haha") - }) - ], - tl: { - hd: [ - "escape_bytes", - () => ({ - TAG: "Eq", - _0: Bytes.of_string("haha"), - _1: Bytes.escaped(Bytes.of_string("haha")) - }) - ], - tl: { - hd: [ - "escape_quote", - () => ({ - TAG: "Eq", - _0: "\\\"\\\"", - _1: $$String.escaped("\"\"") - }) - ], - tl: { - hd: [ - "rev_split_by_char", - () => ({ - TAG: "Eq", - _0: { - hd: "", - tl: { - hd: "bbbb", - tl: { - hd: "bbbb", - tl: /* [] */0 - } - } - }, - _1: rev_split_by_char(/* 'a' */97, "bbbbabbbba") - }) - ], - tl: { - hd: [ - "File \"string_test.res\", line 86, characters 5-12", - () => ({ - TAG: "Eq", - _0: { - hd: "aaaa", - tl: /* [] */0 - }, - _1: rev_split_by_char(/* ',' */44, "aaaa") - }) - ], - tl: { - hd: [ - "xsplit", - () => ({ - TAG: "Eq", - _0: { - hd: "a", - tl: { - hd: "b", - tl: { - hd: "c", - tl: /* [] */0 - } - } - }, - _1: xsplit(/* '.' */46, "a.b.c") - }) - ], - tl: { - hd: [ - "split_empty", - () => ({ - TAG: "Eq", - _0: /* [] */0, - _1: Ext_string_test.split(undefined, "", /* '_' */95) - }) - ], - tl: { - hd: [ - "split_empty2", - () => ({ - TAG: "Eq", - _0: { - hd: "test_unsafe_obj_ffi_ppx.cmi", - tl: /* [] */0 - }, - _1: Ext_string_test.split(false, " test_unsafe_obj_ffi_ppx.cmi", /* ' ' */32) - }) - ], - tl: { - hd: [ - "rfind", - () => ({ - TAG: "Eq", - _0: 7, - _1: Ext_string_test.rfind("__", "__index__js") - }) - ], - tl: { - hd: [ - "rfind_2", - () => ({ - TAG: "Eq", - _0: 0, - _1: Ext_string_test.rfind("__", "__index_js") - }) - ], - tl: { - hd: [ - "rfind_3", - () => ({ - TAG: "Eq", - _0: -1, - _1: Ext_string_test.rfind("__", "_index_js") - }) - ], - tl: { - hd: [ - "find", - () => ({ - TAG: "Eq", - _0: 0, - _1: Ext_string_test.find(undefined, "__", "__index__js") - }) - ], - tl: { - hd: [ - "find_2", - () => ({ - TAG: "Eq", - _0: 6, - _1: Ext_string_test.find(undefined, "__", "_index__js") - }) - ], - tl: { - hd: [ - "find_3", - () => ({ - TAG: "Eq", - _0: -1, - _1: Ext_string_test.find(undefined, "__", "_index_js") - }) - ], - tl: { - hd: [ - "of_char", - () => ({ - TAG: "Eq", - _0: String.fromCharCode(/* '0' */48), - _1: "0" - }) - ], - tl: { - hd: [ - "of_chars", - () => ({ - TAG: "Eq", - _0: string_of_chars({ - hd: /* '0' */48, - tl: { - hd: /* '1' */49, - tl: { - hd: /* '2' */50, - tl: /* [] */0 - } - } - }), - _1: "012" - }) - ], - tl: /* [] */0 - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } - } -}); - -exports.ff = ff; -exports.gg = gg; -exports.rev_split_by_char = rev_split_by_char; -exports.xsplit = xsplit; -exports.string_of_chars = string_of_chars; -/* Not a pure module */ diff --git a/jscomp/test/string_test.res b/jscomp/test/string_test.res deleted file mode 100644 index de1436571f..0000000000 --- a/jscomp/test/string_test.res +++ /dev/null @@ -1,105 +0,0 @@ -let ff = x => { - let a = switch x { - | "0" - | "1" - | "2" => 3 - | "3" => 4 - | "4" => 6 - | "7" => 7 - | _ => 8 - } - a + 3 -} - -let gg = x => { - let a = switch x { - | 0 - | 1 - | 2 => 3 - | 3 => 4 - | 4 => 6 - | 8 => 7 - | _ => 8 - } - a + 3 -} - -let rev_split_by_char = (c, s) => { - let rec loop = (i, l) => - try { - let i' = String.index_from(s, i, c) - let s' = String.sub(s, i, i' - i) - loop( - i' + 1, - if s' == "" { - l - } else { - list{s', ...l} - }, - ) - } catch { - | Not_found => list{String.sub(s, i, String.length(s) - i), ...l} - } - - loop(0, list{}) -} - -let xsplit = (~delim, s) => { - let rec loop = (l, x) => - switch x { - | 0 => l - | i => - switch String.rindex_from(s, i - 1, delim) { - | i' => - let l = list{String.sub(s, i' + 1, i - i' - 1), ...l} - let l = if i' == 0 { - list{"", ...l} - } else { - l - } - loop(l, i') - | exception Not_found => list{String.sub(s, 0, i), ...l} - } - } - - let len = String.length(s) - switch len { - | 0 => list{} - | _ => loop(list{}, len) - } -} - -@val external string_of_char: char => string = "String.fromCharCode" - -let string_of_chars = x => \"@@"(String.concat("", ...), List.map(string_of_char, x)) - -Mt.from_pair_suites( - __MODULE__, - list{ - ("mutliple switch", _ => Eq(9, ff("4"))), - ("int switch", _ => Eq(9, gg(4))), - ("escape_normal", _ => Eq("haha", String.escaped("haha"))), - ("escape_bytes", _ => Eq(Bytes.of_string("haha"), Bytes.escaped(Bytes.of_string("haha")))), - /* FIXME it used char pattern match */ - ("escape_quote", _ => Eq("\\\"\\\"", String.escaped(`""`))), - ("rev_split_by_char", _ => Eq(list{"", "bbbb", "bbbb"}, rev_split_by_char('a', "bbbbabbbba"))), - (__LOC__, _ => Eq(list{"aaaa"}, rev_split_by_char(',', "aaaa"))), - ("xsplit", _ => Eq(list{"a", "b", "c"}, xsplit(~delim='.', "a.b.c"))), - ("split_empty", _ => Eq(list{}, Ext_string_test.split("", '_'))), - ( - "split_empty2", - _ => Eq( - list{"test_unsafe_obj_ffi_ppx.cmi"}, - Ext_string_test.split(" test_unsafe_obj_ffi_ppx.cmi", ~keep_empty=false, ' '), - ), - ), - ("rfind", _ => Eq(7, Ext_string_test.rfind("__index__js", ~sub="__"))), - ("rfind_2", _ => Eq(0, Ext_string_test.rfind("__index_js", ~sub="__"))), - ("rfind_3", _ => Eq(-1, Ext_string_test.rfind("_index_js", ~sub="__"))), - ("find", _ => Eq(0, Ext_string_test.find("__index__js", ~sub="__"))), - ("find_2", _ => Eq(6, Ext_string_test.find("_index__js", ~sub="__"))), - ("find_3", _ => Eq(-1, Ext_string_test.find("_index_js", ~sub="__"))), - ("of_char", _ => Eq(string_of_char('0'), String.make(1, '0'))), - ("of_chars", _ => Eq(string_of_chars(list{'0', '1', '2'}), "012")), - }, -) diff --git a/jscomp/test/string_unicode_test.js b/jscomp/test/string_unicode_test.js index 9f37cd91b2..3386e50e01 100644 --- a/jscomp/test/string_unicode_test.js +++ b/jscomp/test/string_unicode_test.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -44,11 +44,11 @@ function f(x) { } } -eq("File \"string_unicode_test.res\", line 23, characters 5-12", f(/* '{' */123), 0); +eq("File \"string_unicode_test.res\", line 26, characters 5-12", f(/* '{' */123), 0); -eq("File \"string_unicode_test.res\", line 24, characters 5-12", f(/* 'ō' */333), 2); +eq("File \"string_unicode_test.res\", line 27, characters 5-12", f(/* 'ō' */333), 2); -eq("File \"string_unicode_test.res\", line 25, characters 5-12", f(/* 'Ƽ' */444), 3); +eq("File \"string_unicode_test.res\", line 28, characters 5-12", f(/* 'Ƽ' */444), 3); Mt.from_pair_suites("string_unicode_test.res", suites.contents); diff --git a/jscomp/test/string_unicode_test.res b/jscomp/test/string_unicode_test.res index 6f066c6777..d8a9741986 100644 Binary files a/jscomp/test/string_unicode_test.res and b/jscomp/test/string_unicode_test.res differ diff --git a/jscomp/test/switch_case_test.js b/jscomp/test/switch_case_test.js index 3dfead52d6..434d9e717b 100644 --- a/jscomp/test/switch_case_test.js +++ b/jscomp/test/switch_case_test.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -41,13 +41,13 @@ function f(x) { } } -eq("File \"switch_case_test.res\", line 19, characters 5-12", f("xx'''"), 0); +eq("File \"switch_case_test.res\", line 22, characters 5-12", f("xx'''"), 0); -eq("File \"switch_case_test.res\", line 20, characters 5-12", f("xx\""), 1); +eq("File \"switch_case_test.res\", line 23, characters 5-12", f("xx\""), 1); -eq("File \"switch_case_test.res\", line 21, characters 5-12", f("xx\\\""), 2); +eq("File \"switch_case_test.res\", line 24, characters 5-12", f("xx\\\""), 2); -eq("File \"switch_case_test.res\", line 22, characters 5-12", f("xx\\\"\""), 3); +eq("File \"switch_case_test.res\", line 25, characters 5-12", f("xx\\\"\""), 3); Mt.from_pair_suites("Switch_case_test", suites.contents); diff --git a/jscomp/test/switch_case_test.res b/jscomp/test/switch_case_test.res index ec1c4efa73..744faad567 100644 --- a/jscomp/test/switch_case_test.res +++ b/jscomp/test/switch_case_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } let f = x => diff --git a/jscomp/test/tagged_template_test.js b/jscomp/test/tagged_template_test.js index df3b6e4541..29099d8559 100644 --- a/jscomp/test/tagged_template_test.js +++ b/jscomp/test/tagged_template_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_array = require("../../lib/js/caml_array.js"); +let Primitive_array = require("../../lib/js/primitive_array.js"); let Tagged_template_libJs = require("./tagged_template_lib.js"); function sql(prim0, prim1) { @@ -27,9 +27,9 @@ function foo(strings, values) { let res = ""; let valueCount = values.length; for (let i = 0; i < valueCount; ++i) { - res = res + Caml_array.get(strings, i) + String(Math.imul(Caml_array.get(values, i), 10)); + res = res + Primitive_array.get(strings, i) + Math.imul(Primitive_array.get(values, i), 10).toString(); } - return res + Caml_array.get(strings, valueCount); + return res + Primitive_array.get(strings, valueCount); } let res = foo([ diff --git a/jscomp/test/tagged_template_test.res b/jscomp/test/tagged_template_test.res index dc1cc42d23..6ed29697d4 100644 --- a/jscomp/test/tagged_template_test.res +++ b/jscomp/test/tagged_template_test.res @@ -19,9 +19,9 @@ let length = length`hello ${extraLength} what's the total length? Is it ${3}?` let foo = (strings, values) => { let res = ref("") - let valueCount = Array.length(values) + let valueCount = Belt.Array.length(values) for i in 0 to valueCount - 1 { - res := res.contents ++ strings[i] ++ string_of_int(values[i] * 10) + res := res.contents ++ strings[i] ++ Js.Int.toString(values[i] * 10) } res.contents ++ strings[valueCount] } diff --git a/jscomp/test/tailcall_inline_test.js b/jscomp/test/tailcall_inline_test.js index 7308fc182e..9861af68fa 100644 --- a/jscomp/test/tailcall_inline_test.js +++ b/jscomp/test/tailcall_inline_test.js @@ -2,8 +2,8 @@ 'use strict'; let Mt = require("./mt.js"); -let $$Array = require("../../lib/js/array.js"); -let Caml_array = require("../../lib/js/caml_array.js"); +let Belt_Array = require("../../lib/js/belt_Array.js"); +let Primitive_array = require("../../lib/js/primitive_array.js"); function f() { let f$1 = (_acc, _n) => { @@ -18,9 +18,9 @@ function f() { continue; }; }; - let v = Caml_array.make(10, 0); + let v = Belt_Array.make(10, 0); for (let i = 0; i <= 9; ++i) { - Caml_array.set(v, i, f$1(0, i)); + Primitive_array.set(v, i, f$1(0, i)); } return v; } @@ -45,34 +45,9 @@ let suites_0 = [ }) ]; -let suites_1 = { - hd: [ - "array_to_list", - param => ({ - TAG: "Eq", - _0: { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, - _1: $$Array.to_list([ - 1, - 2, - 3 - ]) - }) - ], - tl: /* [] */0 -}; - let suites = { hd: suites_0, - tl: suites_1 + tl: /* [] */0 }; Mt.from_pair_suites("Tailcall_inline_test", suites); diff --git a/jscomp/test/tailcall_inline_test.res b/jscomp/test/tailcall_inline_test.res index e769c8cf05..646bf97432 100644 --- a/jscomp/test/tailcall_inline_test.res +++ b/jscomp/test/tailcall_inline_test.res @@ -6,7 +6,7 @@ let f = () => { acc } let len = 10 - let v = Array.make(len, 0) + let v = Belt.Array.make(len, 0) for i in 0 to len - 1 { v[i] = f(0, i) } @@ -15,10 +15,7 @@ let f = () => { let suites = { open Mt - list{ - ("acc", _ => Eq(f(), [0, 1, 3, 6, 10, 15, 21, 28, 36, 45])), - ("array_to_list", _ => Eq(list{1, 2, 3}, Array.to_list([1, 2, 3]))), - } + list{("acc", _ => Eq(f(), [0, 1, 3, 6, 10, 15, 21, 28, 36, 45]))} } Mt.from_pair_suites(__MODULE__, suites) diff --git a/jscomp/test/test_alias.js b/jscomp/test/test_alias.js deleted file mode 100644 index fc4679b407..0000000000 --- a/jscomp/test/test_alias.js +++ /dev/null @@ -1,9 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let List = require("../../lib/js/list.js"); - -let v = List.length; - -exports.v = v; -/* No side effect */ diff --git a/jscomp/test/test_alias.res b/jscomp/test/test_alias.res deleted file mode 100644 index 4222ad97ec..0000000000 --- a/jscomp/test/test_alias.res +++ /dev/null @@ -1 +0,0 @@ -let v = Test_global_print.V.length diff --git a/jscomp/test/test_ari.js b/jscomp/test/test_ari.js index 8c25d0ec2b..3fd920ab3b 100644 --- a/jscomp/test/test_ari.js +++ b/jscomp/test/test_ari.js @@ -3,7 +3,7 @@ let U = require("U"); let VV = require("VV"); -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); function f(x, y) { return x + y | 0; @@ -42,109 +42,181 @@ function length_aux(_len, _x) { }; } -let length = List.length; +let length = Belt_List.length; -let compare_lengths = List.compare_lengths; +let size = Belt_List.size; -let compare_length_with = List.compare_length_with; +let head = Belt_List.head; -let cons = List.cons; +let headExn = Belt_List.headExn; -let hd = List.hd; +let tail = Belt_List.tail; -let tl = List.tl; +let tailExn = Belt_List.tailExn; -let nth = List.nth; +let add = Belt_List.add; -let nth_opt = List.nth_opt; +let get = Belt_List.get; -let rev = List.rev; +let getExn = Belt_List.getExn; -let init = List.init; +let make = Belt_List.make; -let append = List.append; +let makeByU = Belt_List.makeByU; -let rev_append = List.rev_append; +let makeBy = Belt_List.makeBy; -let concat = List.concat; +let shuffle = Belt_List.shuffle; -let flatten = List.flatten; +let drop = Belt_List.drop; -let iter = List.iter; +let take = Belt_List.take; -let iteri = List.iteri; +let splitAt = Belt_List.splitAt; -let map = List.map; +let concat = Belt_List.concat; -let mapi = List.mapi; +let concatMany = Belt_List.concatMany; -let rev_map = List.rev_map; +let reverseConcat = Belt_List.reverseConcat; -let fold_left = List.fold_left; +let flatten = Belt_List.flatten; -let fold_right = List.fold_right; +let mapU = Belt_List.mapU; -let iter2 = List.iter2; +let map = Belt_List.map; -let map2 = List.map2; +let zip = Belt_List.zip; -let rev_map2 = List.rev_map2; +let zipByU = Belt_List.zipByU; -let fold_left2 = List.fold_left2; +let zipBy = Belt_List.zipBy; -let fold_right2 = List.fold_right2; +let mapWithIndexU = Belt_List.mapWithIndexU; -let for_all = List.for_all; +let mapWithIndex = Belt_List.mapWithIndex; -let exists = List.exists; +let fromArray = Belt_List.fromArray; -let for_all2 = List.for_all2; +let toArray = Belt_List.toArray; -let exists2 = List.exists2; +let reverse = Belt_List.reverse; -let mem = List.mem; +let mapReverseU = Belt_List.mapReverseU; -let memq = List.memq; +let mapReverse = Belt_List.mapReverse; -let find = List.find; +let forEachU = Belt_List.forEachU; -let find_opt = List.find_opt; +let forEach = Belt_List.forEach; -let filter = List.filter; +let forEachWithIndexU = Belt_List.forEachWithIndexU; -let find_all = List.find_all; +let forEachWithIndex = Belt_List.forEachWithIndex; -let partition = List.partition; +let reduceU = Belt_List.reduceU; -let assoc = List.assoc; +let reduce = Belt_List.reduce; -let assoc_opt = List.assoc_opt; +let reduceWithIndexU = Belt_List.reduceWithIndexU; -let assq = List.assq; +let reduceWithIndex = Belt_List.reduceWithIndex; -let assq_opt = List.assq_opt; +let reduceReverseU = Belt_List.reduceReverseU; -let mem_assoc = List.mem_assoc; +let reduceReverse = Belt_List.reduceReverse; -let mem_assq = List.mem_assq; +let mapReverse2U = Belt_List.mapReverse2U; -let remove_assoc = List.remove_assoc; +let mapReverse2 = Belt_List.mapReverse2; -let remove_assq = List.remove_assq; +let forEach2U = Belt_List.forEach2U; -let split = List.split; +let forEach2 = Belt_List.forEach2; -let combine = List.combine; +let reduce2U = Belt_List.reduce2U; -let sort = List.sort; +let reduce2 = Belt_List.reduce2; -let stable_sort = List.stable_sort; +let reduceReverse2U = Belt_List.reduceReverse2U; -let fast_sort = List.fast_sort; +let reduceReverse2 = Belt_List.reduceReverse2; -let sort_uniq = List.sort_uniq; +let everyU = Belt_List.everyU; -let merge = List.merge; +let every = Belt_List.every; + +let someU = Belt_List.someU; + +let some = Belt_List.some; + +let every2U = Belt_List.every2U; + +let every2 = Belt_List.every2; + +let some2U = Belt_List.some2U; + +let some2 = Belt_List.some2; + +let cmpByLength = Belt_List.cmpByLength; + +let cmpU = Belt_List.cmpU; + +let cmp = Belt_List.cmp; + +let eqU = Belt_List.eqU; + +let eq = Belt_List.eq; + +let hasU = Belt_List.hasU; + +let has = Belt_List.has; + +let getByU = Belt_List.getByU; + +let getBy = Belt_List.getBy; + +let keepU = Belt_List.keepU; + +let keep = Belt_List.keep; + +let filter = Belt_List.filter; + +let keepWithIndexU = Belt_List.keepWithIndexU; + +let keepWithIndex = Belt_List.keepWithIndex; + +let filterWithIndex = Belt_List.filterWithIndex; + +let keepMapU = Belt_List.keepMapU; + +let keepMap = Belt_List.keepMap; + +let partitionU = Belt_List.partitionU; + +let partition = Belt_List.partition; + +let unzip = Belt_List.unzip; + +let getAssocU = Belt_List.getAssocU; + +let getAssoc = Belt_List.getAssoc; + +let hasAssocU = Belt_List.hasAssocU; + +let hasAssoc = Belt_List.hasAssoc; + +let removeAssocU = Belt_List.removeAssocU; + +let removeAssoc = Belt_List.removeAssoc; + +let setAssocU = Belt_List.setAssocU; + +let setAssoc = Belt_List.setAssoc; + +let sortU = Belt_List.sortU; + +let sort = Belt_List.sort; exports.f = f; exports.f1 = f1; @@ -155,55 +227,91 @@ exports.ff = ff; exports.fff = fff; exports.length_aux = length_aux; exports.length = length; -exports.compare_lengths = compare_lengths; -exports.compare_length_with = compare_length_with; -exports.cons = cons; -exports.hd = hd; -exports.tl = tl; -exports.nth = nth; -exports.nth_opt = nth_opt; -exports.rev = rev; -exports.init = init; -exports.append = append; -exports.rev_append = rev_append; +exports.size = size; +exports.head = head; +exports.headExn = headExn; +exports.tail = tail; +exports.tailExn = tailExn; +exports.add = add; +exports.get = get; +exports.getExn = getExn; +exports.make = make; +exports.makeByU = makeByU; +exports.makeBy = makeBy; +exports.shuffle = shuffle; +exports.drop = drop; +exports.take = take; +exports.splitAt = splitAt; exports.concat = concat; +exports.concatMany = concatMany; +exports.reverseConcat = reverseConcat; exports.flatten = flatten; -exports.iter = iter; -exports.iteri = iteri; +exports.mapU = mapU; exports.map = map; -exports.mapi = mapi; -exports.rev_map = rev_map; -exports.fold_left = fold_left; -exports.fold_right = fold_right; -exports.iter2 = iter2; -exports.map2 = map2; -exports.rev_map2 = rev_map2; -exports.fold_left2 = fold_left2; -exports.fold_right2 = fold_right2; -exports.for_all = for_all; -exports.exists = exists; -exports.for_all2 = for_all2; -exports.exists2 = exists2; -exports.mem = mem; -exports.memq = memq; -exports.find = find; -exports.find_opt = find_opt; +exports.zip = zip; +exports.zipByU = zipByU; +exports.zipBy = zipBy; +exports.mapWithIndexU = mapWithIndexU; +exports.mapWithIndex = mapWithIndex; +exports.fromArray = fromArray; +exports.toArray = toArray; +exports.reverse = reverse; +exports.mapReverseU = mapReverseU; +exports.mapReverse = mapReverse; +exports.forEachU = forEachU; +exports.forEach = forEach; +exports.forEachWithIndexU = forEachWithIndexU; +exports.forEachWithIndex = forEachWithIndex; +exports.reduceU = reduceU; +exports.reduce = reduce; +exports.reduceWithIndexU = reduceWithIndexU; +exports.reduceWithIndex = reduceWithIndex; +exports.reduceReverseU = reduceReverseU; +exports.reduceReverse = reduceReverse; +exports.mapReverse2U = mapReverse2U; +exports.mapReverse2 = mapReverse2; +exports.forEach2U = forEach2U; +exports.forEach2 = forEach2; +exports.reduce2U = reduce2U; +exports.reduce2 = reduce2; +exports.reduceReverse2U = reduceReverse2U; +exports.reduceReverse2 = reduceReverse2; +exports.everyU = everyU; +exports.every = every; +exports.someU = someU; +exports.some = some; +exports.every2U = every2U; +exports.every2 = every2; +exports.some2U = some2U; +exports.some2 = some2; +exports.cmpByLength = cmpByLength; +exports.cmpU = cmpU; +exports.cmp = cmp; +exports.eqU = eqU; +exports.eq = eq; +exports.hasU = hasU; +exports.has = has; +exports.getByU = getByU; +exports.getBy = getBy; +exports.keepU = keepU; +exports.keep = keep; exports.filter = filter; -exports.find_all = find_all; +exports.keepWithIndexU = keepWithIndexU; +exports.keepWithIndex = keepWithIndex; +exports.filterWithIndex = filterWithIndex; +exports.keepMapU = keepMapU; +exports.keepMap = keepMap; +exports.partitionU = partitionU; exports.partition = partition; -exports.assoc = assoc; -exports.assoc_opt = assoc_opt; -exports.assq = assq; -exports.assq_opt = assq_opt; -exports.mem_assoc = mem_assoc; -exports.mem_assq = mem_assq; -exports.remove_assoc = remove_assoc; -exports.remove_assq = remove_assq; -exports.split = split; -exports.combine = combine; +exports.unzip = unzip; +exports.getAssocU = getAssocU; +exports.getAssoc = getAssoc; +exports.hasAssocU = hasAssocU; +exports.hasAssoc = hasAssoc; +exports.removeAssocU = removeAssocU; +exports.removeAssoc = removeAssoc; +exports.setAssocU = setAssocU; +exports.setAssoc = setAssoc; +exports.sortU = sortU; exports.sort = sort; -exports.stable_sort = stable_sort; -exports.fast_sort = fast_sort; -exports.sort_uniq = sort_uniq; -exports.merge = merge; /* fff Not a pure module */ diff --git a/jscomp/test/test_ari.res b/jscomp/test/test_ari.res index 6fbf8ef541..8d970ef301 100644 --- a/jscomp/test/test_ari.res +++ b/jscomp/test/test_ari.res @@ -31,4 +31,4 @@ let rec length_aux = (len, x) => | list{a, ...l} => length_aux(len + 1, l) } -include List +include Belt.List diff --git a/jscomp/test/test_array.js b/jscomp/test/test_array.js index 9d93de2e9d..11d30a3f9f 100644 --- a/jscomp/test/test_array.js +++ b/jscomp/test/test_array.js @@ -1,16 +1,13 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let $$Array = require("../../lib/js/array.js"); -let Caml_array = require("../../lib/js/caml_array.js"); +let Belt_Array = require("../../lib/js/belt_Array.js"); -let v = Caml_array.make(6, 5); +let v = Belt_Array.make(6, 5); -Caml_array.make_float(30); +let h = Belt_Array.slice(v, 0, 2); -let h = $$Array.sub(v, 0, 2); - -let hhh = $$Array.append([ +let hhh = Belt_Array.concat([ 1, 2, 3, @@ -22,31 +19,26 @@ let hhh = $$Array.append([ 5 ]); -let u = Caml_array.concat({ - hd: [ +let u = Belt_Array.concatMany([ + [ 1, 2 ], - tl: { - hd: [ - 2, - 3 - ], - tl: { - hd: [ - 3, - 4 - ], - tl: /* [] */0 - } - } -}); + [ + 2, + 3 + ], + [ + 3, + 4 + ] +]); -let hh = $$Array.blit; +let hh = Belt_Array.blit; exports.v = v; exports.h = h; exports.hh = hh; exports.hhh = hhh; exports.u = u; -/* Not a pure module */ +/* v Not a pure module */ diff --git a/jscomp/test/test_array.res b/jscomp/test/test_array.res index dbca25cf68..777ea33350 100644 --- a/jscomp/test/test_array.res +++ b/jscomp/test/test_array.res @@ -1,10 +1,10 @@ +open Belt + let v = Array.make(6, 5) -let u = Array.make_float(30) -let h = Array.sub(v, 0, 2) +let h = Array.slice(v, ~offset=0, ~len=2) let hh = Array.blit -let hhh = Array.append([1, 2, 3, 4], [1, 2, 3, 5]) +let hhh = Array.concat([1, 2, 3, 4], [1, 2, 3, 5]) -let u = Array.concat(list{[1, 2], [2, 3], [3, 4]}) -/* console.log(v ) */ +let u = Array.concatMany([[1, 2], [2, 3], [3, 4]]) diff --git a/jscomp/test/test_array_append.js b/jscomp/test/test_array_append.js index 58cc5d4192..71c58810ff 100644 --- a/jscomp/test/test_array_append.js +++ b/jscomp/test/test_array_append.js @@ -1,9 +1,9 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let $$Array = require("../../lib/js/array.js"); +let Belt_Array = require("../../lib/js/belt_Array.js"); -let const_v = $$Array.append([ +let const_v = Belt_Array.concat([ 1, 2 ], [3]); diff --git a/jscomp/test/test_array_append.res b/jscomp/test/test_array_append.res index 4cf4d58efc..e48887f99a 100644 --- a/jscomp/test/test_array_append.res +++ b/jscomp/test/test_array_append.res @@ -1 +1 @@ -let const_v = Array.append([1, 2], [3]) +let const_v = Belt.Array.concat([1, 2], [3]) diff --git a/jscomp/test/test_array_primitive.js b/jscomp/test/test_array_primitive.js deleted file mode 100644 index a840816333..0000000000 --- a/jscomp/test/test_array_primitive.js +++ /dev/null @@ -1,48 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Caml_array = require("../../lib/js/caml_array.js"); - -function caml_array_sub(x, offset, len) { - let result = new Array(len); - for (let j = 0; j < len; ++j) { - Caml_array.set(result, j, Caml_array.get(x, offset + j | 0)); - } - return result; -} - -function caml_array_set(xs, index, newval) { - if (index < 0 || index >= xs.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "index out of bounds", - Error: new Error() - }; - } - Caml_array.set(xs, index, newval); -} - -function caml_array_get(xs, index) { - if (index < 0 || index >= xs.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "index out of bounds", - Error: new Error() - }; - } - return Caml_array.get(xs, index); -} - -function caml_make_vect(len, init) { - let b = new Array(len); - for (let i = 0; i < len; ++i) { - Caml_array.set(b, i, init); - } - return b; -} - -exports.caml_array_sub = caml_array_sub; -exports.caml_array_set = caml_array_set; -exports.caml_array_get = caml_array_get; -exports.caml_make_vect = caml_make_vect; -/* No side effect */ diff --git a/jscomp/test/test_array_primitive.res b/jscomp/test/test_array_primitive.res deleted file mode 100644 index f971831ef2..0000000000 --- a/jscomp/test/test_array_primitive.res +++ /dev/null @@ -1,40 +0,0 @@ -@new("Array") external new_uninitialized_array: int => array<'a> = "" - -let caml_array_sub = (x: array<'a>, offset: int, len: int) => { - let result = new_uninitialized_array(len) - for j in 0 to len - 1 { - result[j] = x[offset + j] - } - result -} - -/* let rec len l = */ -/* match l with */ -/* | [] -> 0 */ -/* | x::xs -> Array.length x + len xs */ - -/* let caml_array_concat (l : 'a array list) : 'a array = */ -/* let v = len l in */ -/* let result = new_uninitialized_array v in */ - -let caml_array_set = (xs, index, newval) => - if index < 0 || index >= Array.length(xs) { - invalid_arg("index out of bounds") - } else { - xs[index] = newval - } - -let caml_array_get = (xs, index) => - if index < 0 || index >= Array.length(xs) { - invalid_arg("index out of bounds") - } else { - xs[index] - } - -let caml_make_vect = (len, init) => { - let b = new_uninitialized_array(len) - for i in 0 to len - 1 { - b[i] = init - } - b -} diff --git a/jscomp/test/test_bug.js b/jscomp/test/test_bug.js deleted file mode 100644 index 47d483ac4e..0000000000 --- a/jscomp/test/test_bug.js +++ /dev/null @@ -1,109 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Bytes = require("../../lib/js/bytes.js"); -let Test_char = require("./test_char.js"); -let Caml_bytes = require("../../lib/js/caml_bytes.js"); - -function escaped(s) { - let n = 0; - for (let i = 0, i_finish = s.length; i < i_finish; ++i) { - let c = s[i]; - let tmp; - let exit = 0; - if (c >= 14) { - if (c !== 34 && c !== 92) { - exit = 1; - } else { - tmp = 2; - } - } else if (c >= 11) { - if (c >= 13) { - tmp = 2; - } else { - exit = 1; - } - } else if (c >= 8) { - tmp = 2; - } else { - exit = 1; - } - if (exit === 1) { - tmp = Test_char.caml_is_printable(c) ? 1 : 4; - } - n = n + tmp | 0; - } - if (n === s.length) { - return Bytes.copy(s); - } - let s$p = Caml_bytes.create(n); - n = 0; - for (let i$1 = 0, i_finish$1 = s.length; i$1 < i_finish$1; ++i$1) { - let c$1 = s[i$1]; - let exit$1 = 0; - if (c$1 > 92 || c$1 < 34) { - if (c$1 >= 14) { - exit$1 = 1; - } else { - switch (c$1) { - case 8 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 'b' */98; - break; - case 9 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 't' */116; - break; - case 10 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 'n' */110; - break; - case 0 : - case 1 : - case 2 : - case 3 : - case 4 : - case 5 : - case 6 : - case 7 : - case 11 : - case 12 : - exit$1 = 1; - break; - case 13 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 'r' */114; - break; - } - } - } else if (c$1 > 91 || c$1 < 35) { - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = c$1; - } else { - exit$1 = 1; - } - if (exit$1 === 1) { - if (Test_char.caml_is_printable(c$1)) { - s$p[n] = c$1; - } else { - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = 48 + (c$1 / 100 | 0) | 0; - n = n + 1 | 0; - s$p[n] = 48 + (c$1 / 10 | 0) % 10 | 0; - n = n + 1 | 0; - s$p[n] = 48 + c$1 % 10 | 0; - } - } - n = n + 1 | 0; - } - return s$p; -} - -exports.escaped = escaped; -/* No side effect */ diff --git a/jscomp/test/test_bug.res b/jscomp/test/test_bug.res deleted file mode 100644 index c24452d5eb..0000000000 --- a/jscomp/test/test_bug.res +++ /dev/null @@ -1,67 +0,0 @@ -external string_length: string => int = "%string_length" -external unsafe_blit_string: (string, int, bytes, int, int) => unit = "?blit_string" - -external char_code: char => int = "%identity" -external char_chr: int => char = "%identity" -open Bytes -let escaped = s => { - let n = ref(0) - for i in 0 to length(s) - 1 { - n := - n.contents + - switch unsafe_get(s, i) { - | '"' | '\\' | '\n' | '\t' | '\r' | '\b' => 2 - | c => - if Test_char.caml_is_printable(c) { - 1 - } else { - 4 - } - } - } - if n.contents == length(s) { - copy(s) - } else { - let s' = create(n.contents) - n := 0 - for i in 0 to length(s) - 1 { - switch unsafe_get(s, i) { - | ('"' | '\\') as c => - unsafe_set(s', n.contents, '\\') - incr(n) - unsafe_set(s', n.contents, c) - | '\n' => - unsafe_set(s', n.contents, '\\') - incr(n) - unsafe_set(s', n.contents, 'n') - | '\t' => - unsafe_set(s', n.contents, '\\') - incr(n) - unsafe_set(s', n.contents, 't') - | '\r' => - unsafe_set(s', n.contents, '\\') - incr(n) - unsafe_set(s', n.contents, 'r') - | '\b' => - unsafe_set(s', n.contents, '\\') - incr(n) - unsafe_set(s', n.contents, 'b') - | c => - if Test_char.caml_is_printable(c) { - unsafe_set(s', n.contents, c) - } else { - let a = char_code(c) - unsafe_set(s', n.contents, '\\') - incr(n) - unsafe_set(s', n.contents, char_chr(48 + a / 100)) - incr(n) - unsafe_set(s', n.contents, char_chr(48 + mod(a / 10, 10))) - incr(n) - unsafe_set(s', n.contents, char_chr(48 + mod(a, 10))) - } - } - incr(n) - } - s' - } -} diff --git a/jscomp/test/test_bytes.js b/jscomp/test/test_bytes.js deleted file mode 100644 index 9d625d0f65..0000000000 --- a/jscomp/test/test_bytes.js +++ /dev/null @@ -1,12 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Bytes = require("../../lib/js/bytes.js"); - -let f = Bytes.unsafe_to_string; - -let ff = Bytes.to_string; - -exports.f = f; -exports.ff = ff; -/* No side effect */ diff --git a/jscomp/test/test_bytes.res b/jscomp/test/test_bytes.res deleted file mode 100644 index b9d8ca2294..0000000000 --- a/jscomp/test/test_bytes.res +++ /dev/null @@ -1,4 +0,0 @@ -let f = v => Bytes.unsafe_to_string(v) - -external uu: bytes => string = "%bytes_to_string" -let ff = v => uu(v) diff --git a/jscomp/test/test_closure.js b/jscomp/test/test_closure.js index 2ab72395e4..d5914da135 100644 --- a/jscomp/test/test_closure.js +++ b/jscomp/test/test_closure.js @@ -1,17 +1,17 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let $$Array = require("../../lib/js/array.js"); -let Caml_array = require("../../lib/js/caml_array.js"); +let Belt_Array = require("../../lib/js/belt_Array.js"); +let Primitive_array = require("../../lib/js/primitive_array.js"); let v = { contents: 0 }; function f() { - let arr = Caml_array.make(10, param => {}); + let arr = Belt_Array.make(10, param => {}); for (let i = 0; i <= 9; ++i) { - Caml_array.set(arr, i, param => { + Primitive_array.set(arr, i, param => { v.contents = v.contents + i | 0; }); } @@ -20,7 +20,7 @@ function f() { let u = f(); -$$Array.iter(x => x(), u); +Belt_Array.forEach(u, x => x()); if (v.contents !== 45) { throw { diff --git a/jscomp/test/test_closure.res b/jscomp/test/test_closure.res index 1c2f3e9bbb..240102d95e 100644 --- a/jscomp/test/test_closure.res +++ b/jscomp/test/test_closure.res @@ -39,7 +39,7 @@ This means inline is tricky in javascript, here we try to inline [_loop]? */ let f = () => { let n = 10 - let arr = Array.make(10, _ => ()) + let arr = Belt.Array.make(10, _ => ()) for i in 0 to n - 1 { arr[i] = _ => v := v.contents + i } @@ -48,6 +48,6 @@ let f = () => { let () = { let u = f() - Array.iter(x => x(), u) + u->Belt.Array.forEach(x => x()) assert(v.contents == 45) } diff --git a/jscomp/test/test_common.js b/jscomp/test/test_common.js index f6ff2cfe10..61bfae36d4 100644 --- a/jscomp/test/test_common.js +++ b/jscomp/test/test_common.js @@ -1,11 +1,11 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); -let U = /* @__PURE__ */Caml_exceptions.create("Test_common.U"); +let U = /* @__PURE__ */Primitive_exceptions.create("Test_common.U"); -let H = /* @__PURE__ */Caml_exceptions.create("Test_common.H"); +let H = /* @__PURE__ */Primitive_exceptions.create("Test_common.H"); exports.U = U; exports.H = H; diff --git a/jscomp/test/test_cpp.js b/jscomp/test/test_cpp.js index 47db685670..4b4e5d4d9b 100644 --- a/jscomp/test/test_cpp.js +++ b/jscomp/test/test_cpp.js @@ -1,9 +1,9 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml = require("../../lib/js/caml.js"); +let Primitive_int = require("../../lib/js/primitive_int.js"); -let f = Caml.int_compare; +let f = Primitive_int.compare; exports.f = f; /* No side effect */ diff --git a/jscomp/test/test_cps.js b/jscomp/test/test_cps.js index 89fb5b1893..e901dd1985 100644 --- a/jscomp/test/test_cps.js +++ b/jscomp/test/test_cps.js @@ -1,7 +1,8 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_array = require("../../lib/js/caml_array.js"); +let Belt_Array = require("../../lib/js/belt_Array.js"); +let Primitive_array = require("../../lib/js/primitive_array.js"); function f(_n, _acc) { while (true) { @@ -11,7 +12,7 @@ function f(_n, _acc) { return acc(); } _acc = () => { - console.log(String(n)); + console.log(n.toString()); return acc(); }; _n = n - 1 | 0; @@ -20,9 +21,9 @@ function f(_n, _acc) { } function test_closure() { - let arr = Caml_array.make(6, x => x); + let arr = Belt_Array.make(6, x => x); for (let i = 0; i <= 6; ++i) { - Caml_array.set(arr, i, param => i); + Primitive_array.set(arr, i, param => i); } return arr; } diff --git a/jscomp/test/test_cps.res b/jscomp/test/test_cps.res index c7eb46f664..bb9c78d5ca 100644 --- a/jscomp/test/test_cps.res +++ b/jscomp/test/test_cps.res @@ -14,7 +14,7 @@ {n=n-1; acc= function() - {console.log(Pervasives.string_of_int(n)); + {console.log(Pervasives.Js.Int.toString(n)); return acc(/* () */0);}; continue f_tailcall_0001;}};}; @@ -32,7 +32,7 @@ {n=n-1; acc= function() - {console.log(Pervasives.string_of_int(n)); + {console.log(Pervasives.Js.Int.toString(n)); return acc(/* () */0);}; continue f_tailcall_0001;}}(n,acc)) };}; ]} @@ -54,7 +54,7 @@ var acc1 = acc ; var n1 = n; return function() { - console.log(Pervasives.string_of_int(n1)); + console.log(Pervasives.Js.Int.toString(n1)); return acc1(/* () */0);} }()); n=n-1; @@ -70,7 +70,7 @@ let rec f = (n, acc) => acc() } else { f(n - 1, _ => { - print_endline(string_of_int(n)) + n->Js.Int.toString->Js.log acc() }) } @@ -90,7 +90,7 @@ let rec f = (n, acc) => */ let test_closure = () => { let n = 6 - let arr = Array.make(n, x => x) + let arr = Belt.Array.make(n, x => x) for i in 0 to n { arr[i] = _ => i } diff --git a/jscomp/test/test_demo.js b/jscomp/test/test_demo.js index f3100bae74..3e473e9cc1 100644 --- a/jscomp/test/test_demo.js +++ b/jscomp/test/test_demo.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); function fib(x) { if (x === 2 || x === 1) { @@ -64,7 +64,7 @@ function v(extra) { let nil = "Nil"; -let len = List.length; +let len = Belt_List.length; exports.fib = fib; exports.nil = nil; diff --git a/jscomp/test/test_demo.res b/jscomp/test/test_demo.res index f8928f11a3..17e9930d5d 100644 --- a/jscomp/test/test_demo.res +++ b/jscomp/test/test_demo.res @@ -26,7 +26,7 @@ let sum = n => { v.contents } -let len = List.length +let len = Belt.List.length let f = (g, x) => { let u = switch g(x) { @@ -52,7 +52,7 @@ let v = (a, ()): unit => ignore(true) a(3) } { - ignore(print_int(3)) + ignore(Js.log(3)) } type cxt = diff --git a/jscomp/test/test_exception.js b/jscomp/test/test_exception.js index c987a027fc..97601fab36 100644 --- a/jscomp/test/test_exception.js +++ b/jscomp/test/test_exception.js @@ -2,9 +2,9 @@ 'use strict'; let Test_common = require("./test_common.js"); -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); -let Local = /* @__PURE__ */Caml_exceptions.create("Test_exception.Local"); +let Local = /* @__PURE__ */Primitive_exceptions.create("Test_exception.Local"); function f() { throw { @@ -44,7 +44,7 @@ function xx() { }; } -let Nullary = /* @__PURE__ */Caml_exceptions.create("Test_exception.Nullary"); +let Nullary = /* @__PURE__ */Primitive_exceptions.create("Test_exception.Nullary"); let a = { RE_EXN_ID: Nullary diff --git a/jscomp/test/test_exception_escape.js b/jscomp/test/test_exception_escape.js index b1fee39246..80b5b69bdb 100644 --- a/jscomp/test/test_exception_escape.js +++ b/jscomp/test/test_exception_escape.js @@ -1,9 +1,9 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); -let A = /* @__PURE__ */Caml_exceptions.create("Test_exception_escape.N.A"); +let A = /* @__PURE__ */Primitive_exceptions.create("Test_exception_escape.N.A"); let f; diff --git a/jscomp/test/test_filename.js b/jscomp/test/test_filename.js deleted file mode 100644 index 018404e0ba..0000000000 --- a/jscomp/test/test_filename.js +++ /dev/null @@ -1,13 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let List = require("../../lib/js/list.js"); -let Filename = require("../../lib/js/filename.js"); - -let u = Filename.chop_extension; - -let v = List.length; - -exports.u = u; -exports.v = v; -/* Filename Not a pure module */ diff --git a/jscomp/test/test_filename.res b/jscomp/test/test_filename.res deleted file mode 100644 index fe3fb8da68..0000000000 --- a/jscomp/test/test_filename.res +++ /dev/null @@ -1,7 +0,0 @@ -open Filename - -let v = chop_extension - -let u = v -open List -let v = List.length diff --git a/jscomp/test/test_for_loop.js b/jscomp/test/test_for_loop.js index 0f6d8cfd28..49bd328a26 100644 --- a/jscomp/test/test_for_loop.js +++ b/jscomp/test/test_for_loop.js @@ -1,18 +1,18 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let $$Array = require("../../lib/js/array.js"); -let Caml_array = require("../../lib/js/caml_array.js"); +let Belt_Array = require("../../lib/js/belt_Array.js"); +let Primitive_array = require("../../lib/js/primitive_array.js"); function for_(x) { for (let i = 0, i_finish = (console.log("hi"), x.length); i <= i_finish; ++i) { - console.log(Caml_array.get(x, i)); + console.log(Primitive_array.get(x, i)); } } function for_2(x) { for (let i = 0, i_finish = x.length; i <= i_finish; ++i) { - console.log(Caml_array.get(x, i)); + console.log(Primitive_array.get(x, i)); } } @@ -20,14 +20,14 @@ function for_3(x) { let v = { contents: 0 }; - let arr = $$Array.map(param => (() => {}), x); + let arr = Belt_Array.map(x, param => (() => {})); for (let i = 0, i_finish = x.length; i <= i_finish; ++i) { let j = (i << 1); - Caml_array.set(arr, i, () => { + Primitive_array.set(arr, i, () => { v.contents = v.contents + j | 0; }); } - $$Array.iter(x => x(), arr); + Belt_Array.forEach(arr, x => x()); return v.contents; } @@ -35,15 +35,15 @@ function for_4(x) { let v = { contents: 0 }; - let arr = $$Array.map(param => (() => {}), x); + let arr = Belt_Array.map(x, param => (() => {})); for (let i = 0, i_finish = x.length; i <= i_finish; ++i) { let j = (i << 1); let k = (j << 1); - Caml_array.set(arr, i, () => { + Primitive_array.set(arr, i, () => { v.contents = v.contents + k | 0; }); } - $$Array.iter(x => x(), arr); + Belt_Array.forEach(arr, x => x()); return v.contents; } @@ -51,14 +51,14 @@ function for_5(x, u) { let v = { contents: 0 }; - let arr = $$Array.map(param => (() => {}), x); + let arr = Belt_Array.map(x, param => (() => {})); for (let i = 0, i_finish = x.length; i <= i_finish; ++i) { let k = Math.imul((u << 1), u); - Caml_array.set(arr, i, () => { + Primitive_array.set(arr, i, () => { v.contents = v.contents + k | 0; }); } - $$Array.iter(x => x(), arr); + Belt_Array.forEach(arr, x => x()); return v.contents; } @@ -66,7 +66,7 @@ function for_6(x, u) { let v = { contents: 0 }; - let arr = $$Array.map(param => (() => {}), x); + let arr = Belt_Array.map(x, param => (() => {})); let v4 = { contents: 0 }; @@ -83,12 +83,12 @@ function for_6(x, u) { let k = Math.imul((u << 1), u); let h = (v5.contents << 1); v2.contents = v2.contents + 1 | 0; - Caml_array.set(arr, i, () => { + Primitive_array.set(arr, i, () => { v.contents = (((((v.contents + k | 0) + v2.contents | 0) + u | 0) + v4.contents | 0) + v5.contents | 0) + h | 0; }); } } - $$Array.iter(x => x(), arr); + Belt_Array.forEach(arr, x => x()); return v.contents; } diff --git a/jscomp/test/test_for_loop.res b/jscomp/test/test_for_loop.res index 358e0f96c0..a0e95e4607 100644 --- a/jscomp/test/test_for_loop.res +++ b/jscomp/test/test_for_loop.res @@ -1,55 +1,55 @@ let for_ = x => for i in 0 to { - print_endline("hi") + Js.log("hi") ignore(3) - Array.length(x) + Belt.Array.length(x) } { - print_endline(x[i]) + Js.log(x[i]) } let for_2 = x => - for i in 0 to Array.length(x) { - print_endline(x[i]) + for i in 0 to Belt.Array.length(x) { + Js.log(x[i]) } let for_3 = x => { let v = ref(0) - let arr = Array.map(_ => _ => (), x) - for i in 0 to Array.length(x) { + let arr = x->Belt.Array.map(_ => _ => ()) + for i in 0 to Belt.Array.length(x) { let j = i * 2 arr[i] = _ => v := v.contents + j } - Array.iter(x => x(), arr) + arr->Belt.Array.forEach(x => x()) v.contents } let for_4 = x => { let v = ref(0) - let arr = Array.map(_ => _ => (), x) - for i in 0 to Array.length(x) { + let arr = x->Belt.Array.map(_ => _ => ()) + for i in 0 to Belt.Array.length(x) { let j = i * 2 let k = 2 * j arr[i] = _ => v := v.contents + k } - Array.iter(x => x(), arr) + arr->Belt.Array.forEach(x => x()) v.contents } let for_5 = (x, u) => { let v = ref(0) - let arr = Array.map(_ => _ => (), x) - for i in 0 to Array.length(x) { + let arr = x->Belt.Array.map(_ => _ => ()) + for i in 0 to Belt.Array.length(x) { let _j = i * 2 let k = 2 * u * u arr[i] = _ => v := v.contents + k } - Array.iter(x => x(), arr) + arr->Belt.Array.forEach(x => x()) v.contents } let for_6 = (x, u) => { let v = ref(0) - let arr = Array.map(_ => _ => (), x) + let arr = x->Belt.Array.map(_ => _ => ()) let v4 = ref(0) let v5 = ref(0) incr(v4) @@ -57,7 +57,7 @@ let for_6 = (x, u) => { incr(v5) let v2 = ref(0) let v3 = u - for i in 0 to Array.length(x) { + for i in 0 to Belt.Array.length(x) { let _j = i * 2 let k = 2 * u * u let h = 2 * v5.contents @@ -65,6 +65,6 @@ let for_6 = (x, u) => { arr[i] = _ => v := v.contents + k + v2.contents + v3 + v4.contents + v5.contents + h } } - Array.iter(x => x(), arr) + arr->Belt.Array.forEach(x => x()) v.contents } diff --git a/jscomp/test/test_for_map.js b/jscomp/test/test_for_map.js index 58761a235a..e2e11189ea 100644 --- a/jscomp/test/test_for_map.js +++ b/jscomp/test/test_for_map.js @@ -1,1002 +1,20 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml = require("../../lib/js/caml.js"); -let Caml_option = require("../../lib/js/caml_option.js"); - -function height(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} - -function create(l, x, d, r) { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} - -function singleton(x, d) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: d, - r: "Empty", - h: 1 - }; -} - -function bal(l, x, d, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; -} - -function is_empty(param) { - if (typeof param !== "object") { - return true; - } else { - return false; - } -} - -function add(x, data, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml.int_compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function find(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let c = Caml.int_compare(x, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function find_first(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_first_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_last(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_last_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_opt(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let c = Caml.int_compare(x, param.v); - if (c === 0) { - return Caml_option.some(param.d); - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function mem(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = Caml.int_compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function min_binding(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; -} - -function min_binding_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; -} - -function max_binding(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; -} - -function max_binding_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; -} - -function remove_min_binding(param) { - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.remove_min_elt", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_binding(l), param.v, param.d, param.r); - } -} - -function merge(t1, t2) { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return bal(t1, match[0], match[1], remove_min_binding(t2)); -} - -function remove(x, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml.int_compare(x, v); - if (c === 0) { - return merge(l, r); - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function update(x, f, param) { - if (typeof param !== "object") { - let data = f(undefined); - if (data !== undefined) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: Caml_option.valFromOption(data), - r: "Empty", - h: 1 - }; - } else { - return "Empty"; - } - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml.int_compare(x, v); - if (c === 0) { - let data$1 = f(Caml_option.some(d)); - if (data$1 === undefined) { - return merge(l, r); - } - let data$2 = Caml_option.valFromOption(data$1); - if (d === data$2) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data$2, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = update(x, f, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = update(x, f, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function iter(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v, param.d); - _param = param.r; - continue; - }; -} - -function map(f, param) { - if (typeof param !== "object") { - return "Empty"; - } - let l$p = map(f, param.l); - let d$p = f(param.d); - let r$p = map(f, param.r); - return { - TAG: "Node", - l: l$p, - v: param.v, - d: d$p, - r: r$p, - h: param.h - }; -} - -function mapi(f, param) { - if (typeof param !== "object") { - return "Empty"; - } - let v = param.v; - let l$p = mapi(f, param.l); - let d$p = f(v, param.d); - let r$p = mapi(f, param.r); - return { - TAG: "Node", - l: l$p, - v: v, - d: d$p, - r: r$p, - h: param.h - }; -} - -function fold(f, _m, _accu) { - while (true) { - let accu = _accu; - let m = _m; - if (typeof m !== "object") { - return accu; - } - _accu = f(m.v, m.d, fold(f, m.l, accu)); - _m = m.r; - continue; - }; -} - -function for_all(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v, param.d)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; -} - -function exists(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v, param.d)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; -} - -function add_min_binding(k, x, param) { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(add_min_binding(k, x, param.l), param.v, param.d, param.r); - } -} - -function add_max_binding(k, x, param) { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(param.l, param.v, param.d, add_max_binding(k, x, param.r)); - } -} - -function join(l, v, d, r) { - if (typeof l !== "object") { - return add_min_binding(v, d, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_binding(v, d, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, l.d, join(l.r, v, d, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, d, r.l), r.v, r.d, r.r); - } else { - return create(l, v, d, r); - } -} - -function concat(t1, t2) { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return join(t1, match[0], match[1], remove_min_binding(t2)); -} - -function concat_or_join(t1, v, d, t2) { - if (d !== undefined) { - return join(t1, v, Caml_option.valFromOption(d), t2); - } else { - return concat(t1, t2); - } -} - -function split(x, param) { - if (typeof param !== "object") { - return [ - "Empty", - undefined, - "Empty" - ]; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml.int_compare(x, v); - if (c === 0) { - return [ - l, - Caml_option.some(d), - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, d, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, d, match$1[0]), - match$1[1], - match$1[2] - ]; -} - -function merge$1(f, s1, s2) { - if (typeof s1 !== "object") { - if (typeof s2 !== "object") { - return "Empty"; - } - - } else { - let v1 = s1.v; - if (s1.h >= height(s2)) { - let match = split(v1, s2); - return concat_or_join(merge$1(f, s1.l, match[0]), v1, f(v1, Caml_option.some(s1.d), match[1]), merge$1(f, s1.r, match[2])); - } - - } - if (typeof s2 !== "object") { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "map.res", - 552, - 11 - ], - Error: new Error() - }; - } - let v2 = s2.v; - let match$1 = split(v2, s1); - return concat_or_join(merge$1(f, match$1[0], s2.l), v2, f(v2, match$1[1], Caml_option.some(s2.d)), merge$1(f, match$1[2], s2.r)); -} - -function union(f, s1, s2) { - if (typeof s1 !== "object") { - return s2; - } - let d1 = s1.d; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let d2 = s2.d; - let v2 = s2.v; - if (s1.h >= s2.h) { - let match = split(v1, s2); - let d2$1 = match[1]; - let l = union(f, s1.l, match[0]); - let r = union(f, s1.r, match[2]); - if (d2$1 !== undefined) { - return concat_or_join(l, v1, f(v1, d1, Caml_option.valFromOption(d2$1)), r); - } else { - return join(l, v1, d1, r); - } - } - let match$1 = split(v2, s1); - let d1$1 = match$1[1]; - let l$1 = union(f, match$1[0], s2.l); - let r$1 = union(f, match$1[2], s2.r); - if (d1$1 !== undefined) { - return concat_or_join(l$1, v2, f(v2, Caml_option.valFromOption(d1$1), d2), r$1); - } else { - return join(l$1, v2, d2, r$1); - } -} - -function filter(p, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pvd = p(v, d); - let r$p = filter(p, r); - if (pvd) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, d, r$p); - } - } else { - return concat(l$p, r$p); - } -} - -function partition(p, param) { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let d = param.d; - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pvd = p(v, d); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pvd) { - return [ - join(lt, v, d, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, d, rf) - ]; - } -} - -function cons_enum(_m, _e) { - while (true) { - let e = _e; - let m = _m; - if (typeof m !== "object") { - return e; - } - _e = { - TAG: "More", - _0: m.v, - _1: m.d, - _2: m.r, - _3: e - }; - _m = m.l; - continue; - }; -} - -function compare(cmp, m1, m2) { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = Caml.int_compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - let c$1 = cmp(e1._1, e2._1); - if (c$1 !== 0) { - return c$1; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; -} - -function equal(cmp, m1, m2) { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return true; - } else { - return false; - } - } - if (typeof e2 !== "object") { - return false; - } - if (e1._0 !== e2._0) { - return false; - } - if (!cmp(e1._1, e2._1)) { - return false; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; -} - -function cardinal(param) { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } -} - -function bindings_aux(_accu, _param) { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: [ - param.v, - param.d - ], - tl: bindings_aux(accu, param.r) - }; - continue; - }; -} - -function bindings(s) { - return bindings_aux(/* [] */0, s); -} - -let IntMap = { - empty: "Empty", - is_empty: is_empty, - mem: mem, - add: add, - update: update, - singleton: singleton, - remove: remove, - merge: merge$1, - union: union, - compare: compare, - equal: equal, - iter: iter, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - bindings: bindings, - min_binding: min_binding, - min_binding_opt: min_binding_opt, - max_binding: max_binding, - max_binding_opt: max_binding_opt, - choose: min_binding, - choose_opt: min_binding_opt, - split: split, - find: find, - find_opt: find_opt, - find_first: find_first, - find_first_opt: find_first_opt, - find_last: find_last, - find_last_opt: find_last_opt, - map: map, - mapi: mapi -}; +let Belt_MapInt = require("../../lib/js/belt_MapInt.js"); function assertion_test() { - let m = "Empty"; + let m; for (let i = 0; i <= 1000000; ++i) { - m = add(i, i, m); + m = Belt_MapInt.set(m, i, i); } for (let i$1 = 0; i$1 <= 1000000; ++i$1) { - find(i$1, m); + Belt_MapInt.get(m, i$1); } } +let IntMap; + exports.IntMap = IntMap; exports.assertion_test = assertion_test; /* No side effect */ diff --git a/jscomp/test/test_for_map.res b/jscomp/test/test_for_map.res index f0c651c806..3af916caf9 100644 --- a/jscomp/test/test_for_map.res +++ b/jscomp/test/test_for_map.res @@ -1,15 +1,12 @@ -module IntMap = Map.Make({ - type t = int - let compare = (x: int, y) => compare(x, y) -}) +module IntMap = Belt.Map.Int let assertion_test = () => { let m = ref(IntMap.empty) let count = 1000000 for i in 0 to count { - m := IntMap.add(i, i, m.contents) + m := m.contents->IntMap.set(i, i) } for i in 0 to count { - ignore(IntMap.find(i, m.contents)) + m.contents->IntMap.get(i)->ignore } } diff --git a/jscomp/test/test_for_map2.js b/jscomp/test/test_for_map2.js index ff20587c02..285ab94576 100644 --- a/jscomp/test/test_for_map2.js +++ b/jscomp/test/test_for_map2.js @@ -1,17 +1,20 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Int_map = require("./int_map.js"); +let Belt_MapInt = require("../../lib/js/belt_MapInt.js"); function assertion_test() { - let m = "Empty"; + let m; for (let i = 0; i <= 1000000; ++i) { - m = Int_map.add(i, i, m); + m = Belt_MapInt.set(m, i, i); } for (let i$1 = 0; i$1 <= 1000000; ++i$1) { - Int_map.find(i$1, m); + Belt_MapInt.get(m, i$1); } } +let Int_map; + +exports.Int_map = Int_map; exports.assertion_test = assertion_test; /* No side effect */ diff --git a/jscomp/test/test_for_map2.res b/jscomp/test/test_for_map2.res index 775b8ea461..88376a438b 100644 --- a/jscomp/test/test_for_map2.res +++ b/jscomp/test/test_for_map2.res @@ -1,10 +1,12 @@ +module Int_map = Belt.Map.Int + let assertion_test = () => { let m = ref(Int_map.empty) let count = 1000000 for i in 0 to count { - m := Int_map.add(i, i, m.contents) + m := m.contents->Int_map.set(i, i) } for i in 0 to count { - ignore(Int_map.find(i, m.contents)) + m.contents->Int_map.get(i)->ignore } } diff --git a/jscomp/test/test_functor_dead_code.js b/jscomp/test/test_functor_dead_code.js index 4e308ce038..ce4c3e5ee1 100644 --- a/jscomp/test/test_functor_dead_code.js +++ b/jscomp/test/test_functor_dead_code.js @@ -1,8 +1,9 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +let Belt_MapString = require("../../lib/js/belt_MapString.js"); -let v = true; +let v = Belt_MapString.isEmpty(undefined); exports.v = v; -/* No side effect */ +/* v Not a pure module */ diff --git a/jscomp/test/test_functor_dead_code.res b/jscomp/test/test_functor_dead_code.res index c127b6be98..70ccee01c5 100644 --- a/jscomp/test/test_functor_dead_code.res +++ b/jscomp/test/test_functor_dead_code.res @@ -1,7 +1,7 @@ include ( { - module M = Map.Make(String) - let v = M.is_empty(M.empty) + module M = Belt.Map.String + let v = M.isEmpty(M.empty) }: { let v: bool } diff --git a/jscomp/test/test_global_print.js b/jscomp/test/test_global_print.js deleted file mode 100644 index 61ef2a3e26..0000000000 --- a/jscomp/test/test_global_print.js +++ /dev/null @@ -1,20 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - - -let List = { - u: 3 -}; - -let X = { - List: List -}; - -let Hashtbl; - -let V; - -exports.X = X; -exports.Hashtbl = Hashtbl; -exports.V = V; -/* No side effect */ diff --git a/jscomp/test/test_global_print.res b/jscomp/test/test_global_print.res deleted file mode 100644 index e987681451..0000000000 --- a/jscomp/test/test_global_print.res +++ /dev/null @@ -1,7 +0,0 @@ -module X = { - module List = { - let u = 3 - } -} -module Hashtbl = Hashtbl -module V = List diff --git a/jscomp/test/test_google_closure.js b/jscomp/test/test_google_closure.js index 7bcdc1a2f9..de79266090 100644 --- a/jscomp/test/test_google_closure.js +++ b/jscomp/test/test_google_closure.js @@ -1,8 +1,8 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let $$Array = require("../../lib/js/array.js"); -let Caml_array = require("../../lib/js/caml_array.js"); +let Belt_Array = require("../../lib/js/belt_Array.js"); +let Primitive_array = require("../../lib/js/primitive_array.js"); function f(a, b, param) { return a + b | 0; @@ -12,7 +12,7 @@ function f2(a) { return extra => a + 1 | 0; } -let a = String(3); +let a = (3).toString(); function f3(extra) { return 101; @@ -20,11 +20,11 @@ function f3(extra) { let b = f3(2); -let arr = $$Array.init(2, param => 0); +let arr = Belt_Array.init(2, param => 0); for (let i = 0; i <= 1; ++i) { let f3$1 = extra => i + 1 | 0; - Caml_array.set(arr, i, f3$1(2)); + Primitive_array.set(arr, i, f3$1(2)); } console.log([ diff --git a/jscomp/test/test_google_closure.res b/jscomp/test/test_google_closure.res index 80f8480950..5e016273a9 100644 --- a/jscomp/test/test_google_closure.res +++ b/jscomp/test/test_google_closure.res @@ -3,13 +3,13 @@ let f = (a, b, _) => a + b let f2 = a => f(a, 1, ...) let (a, b, c) = ( - string_of_int(f(1, 2, 3)), + Js.Int.toString(f(1, 2, 3)), { let f3 = f2(100) f3(2) }, { - let arr = Array.init(2, _ => 0) + let arr = Belt.Array.init(2, _ => 0) for i in 0 to 1 { let f3 = f2(i) arr[i] = f3(2) diff --git a/jscomp/test/test_include.js b/jscomp/test/test_include.js index 5c1bb8b227..be35df145d 100644 --- a/jscomp/test/test_include.js +++ b/jscomp/test/test_include.js @@ -1,31 +1,22 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); -let $$String = require("../../lib/js/string.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let Test_order = require("./test_order.js"); function Make(U) { - let compare = U.compare; return { - compare: compare, - v: compare + v: U.compare }; } -let X = { - compare: $$String.compare, - v: $$String.compare -}; - let U = { - compare: Test_order.compare, v: Test_order.compare }; let N; -let v = List.length; +let v = Belt_List.length; let N0; @@ -41,114 +32,185 @@ let N5; let N6; -let length = List.length; +let length = Belt_List.length; + +let size = Belt_List.size; + +let head = Belt_List.head; + +let headExn = Belt_List.headExn; + +let tail = Belt_List.tail; + +let tailExn = Belt_List.tailExn; + +let add = Belt_List.add; + +let get = Belt_List.get; + +let getExn = Belt_List.getExn; + +let make = Belt_List.make; + +let makeByU = Belt_List.makeByU; + +let makeBy = Belt_List.makeBy; + +let shuffle = Belt_List.shuffle; + +let drop = Belt_List.drop; + +let take = Belt_List.take; + +let splitAt = Belt_List.splitAt; + +let concat = Belt_List.concat; + +let concatMany = Belt_List.concatMany; + +let reverseConcat = Belt_List.reverseConcat; + +let flatten = Belt_List.flatten; + +let mapU = Belt_List.mapU; + +let map = Belt_List.map; + +let zip = Belt_List.zip; + +let zipByU = Belt_List.zipByU; + +let zipBy = Belt_List.zipBy; + +let mapWithIndexU = Belt_List.mapWithIndexU; + +let mapWithIndex = Belt_List.mapWithIndex; + +let fromArray = Belt_List.fromArray; + +let toArray = Belt_List.toArray; + +let reverse = Belt_List.reverse; + +let mapReverseU = Belt_List.mapReverseU; + +let mapReverse = Belt_List.mapReverse; + +let forEachU = Belt_List.forEachU; + +let forEach = Belt_List.forEach; + +let forEachWithIndexU = Belt_List.forEachWithIndexU; + +let forEachWithIndex = Belt_List.forEachWithIndex; + +let reduceU = Belt_List.reduceU; -let compare_lengths = List.compare_lengths; +let reduce = Belt_List.reduce; -let compare_length_with = List.compare_length_with; +let reduceWithIndexU = Belt_List.reduceWithIndexU; -let cons = List.cons; +let reduceWithIndex = Belt_List.reduceWithIndex; -let hd = List.hd; +let reduceReverseU = Belt_List.reduceReverseU; -let tl = List.tl; +let reduceReverse = Belt_List.reduceReverse; -let nth = List.nth; +let mapReverse2U = Belt_List.mapReverse2U; -let nth_opt = List.nth_opt; +let mapReverse2 = Belt_List.mapReverse2; -let rev = List.rev; +let forEach2U = Belt_List.forEach2U; -let init = List.init; +let forEach2 = Belt_List.forEach2; -let append = List.append; +let reduce2U = Belt_List.reduce2U; -let rev_append = List.rev_append; +let reduce2 = Belt_List.reduce2; -let concat = List.concat; +let reduceReverse2U = Belt_List.reduceReverse2U; -let flatten = List.flatten; +let reduceReverse2 = Belt_List.reduceReverse2; -let iter = List.iter; +let everyU = Belt_List.everyU; -let iteri = List.iteri; +let every = Belt_List.every; -let map = List.map; +let someU = Belt_List.someU; -let mapi = List.mapi; +let some = Belt_List.some; -let rev_map = List.rev_map; +let every2U = Belt_List.every2U; -let fold_left = List.fold_left; +let every2 = Belt_List.every2; -let fold_right = List.fold_right; +let some2U = Belt_List.some2U; -let iter2 = List.iter2; +let some2 = Belt_List.some2; -let map2 = List.map2; +let cmpByLength = Belt_List.cmpByLength; -let rev_map2 = List.rev_map2; +let cmpU = Belt_List.cmpU; -let fold_left2 = List.fold_left2; +let cmp = Belt_List.cmp; -let fold_right2 = List.fold_right2; +let eqU = Belt_List.eqU; -let for_all = List.for_all; +let eq = Belt_List.eq; -let exists = List.exists; +let hasU = Belt_List.hasU; -let for_all2 = List.for_all2; +let has = Belt_List.has; -let exists2 = List.exists2; +let getByU = Belt_List.getByU; -let mem = List.mem; +let getBy = Belt_List.getBy; -let memq = List.memq; +let keepU = Belt_List.keepU; -let find = List.find; +let keep = Belt_List.keep; -let find_opt = List.find_opt; +let filter = Belt_List.filter; -let filter = List.filter; +let keepWithIndexU = Belt_List.keepWithIndexU; -let find_all = List.find_all; +let keepWithIndex = Belt_List.keepWithIndex; -let partition = List.partition; +let filterWithIndex = Belt_List.filterWithIndex; -let assoc = List.assoc; +let keepMapU = Belt_List.keepMapU; -let assoc_opt = List.assoc_opt; +let keepMap = Belt_List.keepMap; -let assq = List.assq; +let partitionU = Belt_List.partitionU; -let assq_opt = List.assq_opt; +let partition = Belt_List.partition; -let mem_assoc = List.mem_assoc; +let unzip = Belt_List.unzip; -let mem_assq = List.mem_assq; +let getAssocU = Belt_List.getAssocU; -let remove_assoc = List.remove_assoc; +let getAssoc = Belt_List.getAssoc; -let remove_assq = List.remove_assq; +let hasAssocU = Belt_List.hasAssocU; -let split = List.split; +let hasAssoc = Belt_List.hasAssoc; -let combine = List.combine; +let removeAssocU = Belt_List.removeAssocU; -let sort = List.sort; +let removeAssoc = Belt_List.removeAssoc; -let stable_sort = List.stable_sort; +let setAssocU = Belt_List.setAssocU; -let fast_sort = List.fast_sort; +let setAssoc = Belt_List.setAssoc; -let sort_uniq = List.sort_uniq; +let sortU = Belt_List.sortU; -let merge = List.merge; +let sort = Belt_List.sort; exports.N = N; exports.v = v; exports.Make = Make; -exports.X = X; exports.U = U; exports.N0 = N0; exports.N1 = N1; @@ -158,55 +220,91 @@ exports.N4 = N4; exports.N5 = N5; exports.N6 = N6; exports.length = length; -exports.compare_lengths = compare_lengths; -exports.compare_length_with = compare_length_with; -exports.cons = cons; -exports.hd = hd; -exports.tl = tl; -exports.nth = nth; -exports.nth_opt = nth_opt; -exports.rev = rev; -exports.init = init; -exports.append = append; -exports.rev_append = rev_append; +exports.size = size; +exports.head = head; +exports.headExn = headExn; +exports.tail = tail; +exports.tailExn = tailExn; +exports.add = add; +exports.get = get; +exports.getExn = getExn; +exports.make = make; +exports.makeByU = makeByU; +exports.makeBy = makeBy; +exports.shuffle = shuffle; +exports.drop = drop; +exports.take = take; +exports.splitAt = splitAt; exports.concat = concat; +exports.concatMany = concatMany; +exports.reverseConcat = reverseConcat; exports.flatten = flatten; -exports.iter = iter; -exports.iteri = iteri; +exports.mapU = mapU; exports.map = map; -exports.mapi = mapi; -exports.rev_map = rev_map; -exports.fold_left = fold_left; -exports.fold_right = fold_right; -exports.iter2 = iter2; -exports.map2 = map2; -exports.rev_map2 = rev_map2; -exports.fold_left2 = fold_left2; -exports.fold_right2 = fold_right2; -exports.for_all = for_all; -exports.exists = exists; -exports.for_all2 = for_all2; -exports.exists2 = exists2; -exports.mem = mem; -exports.memq = memq; -exports.find = find; -exports.find_opt = find_opt; +exports.zip = zip; +exports.zipByU = zipByU; +exports.zipBy = zipBy; +exports.mapWithIndexU = mapWithIndexU; +exports.mapWithIndex = mapWithIndex; +exports.fromArray = fromArray; +exports.toArray = toArray; +exports.reverse = reverse; +exports.mapReverseU = mapReverseU; +exports.mapReverse = mapReverse; +exports.forEachU = forEachU; +exports.forEach = forEach; +exports.forEachWithIndexU = forEachWithIndexU; +exports.forEachWithIndex = forEachWithIndex; +exports.reduceU = reduceU; +exports.reduce = reduce; +exports.reduceWithIndexU = reduceWithIndexU; +exports.reduceWithIndex = reduceWithIndex; +exports.reduceReverseU = reduceReverseU; +exports.reduceReverse = reduceReverse; +exports.mapReverse2U = mapReverse2U; +exports.mapReverse2 = mapReverse2; +exports.forEach2U = forEach2U; +exports.forEach2 = forEach2; +exports.reduce2U = reduce2U; +exports.reduce2 = reduce2; +exports.reduceReverse2U = reduceReverse2U; +exports.reduceReverse2 = reduceReverse2; +exports.everyU = everyU; +exports.every = every; +exports.someU = someU; +exports.some = some; +exports.every2U = every2U; +exports.every2 = every2; +exports.some2U = some2U; +exports.some2 = some2; +exports.cmpByLength = cmpByLength; +exports.cmpU = cmpU; +exports.cmp = cmp; +exports.eqU = eqU; +exports.eq = eq; +exports.hasU = hasU; +exports.has = has; +exports.getByU = getByU; +exports.getBy = getBy; +exports.keepU = keepU; +exports.keep = keep; exports.filter = filter; -exports.find_all = find_all; +exports.keepWithIndexU = keepWithIndexU; +exports.keepWithIndex = keepWithIndex; +exports.filterWithIndex = filterWithIndex; +exports.keepMapU = keepMapU; +exports.keepMap = keepMap; +exports.partitionU = partitionU; exports.partition = partition; -exports.assoc = assoc; -exports.assoc_opt = assoc_opt; -exports.assq = assq; -exports.assq_opt = assq_opt; -exports.mem_assoc = mem_assoc; -exports.mem_assq = mem_assq; -exports.remove_assoc = remove_assoc; -exports.remove_assq = remove_assq; -exports.split = split; -exports.combine = combine; +exports.unzip = unzip; +exports.getAssocU = getAssocU; +exports.getAssoc = getAssoc; +exports.hasAssocU = hasAssocU; +exports.hasAssoc = hasAssoc; +exports.removeAssocU = removeAssocU; +exports.removeAssoc = removeAssoc; +exports.setAssocU = setAssocU; +exports.setAssoc = setAssoc; +exports.sortU = sortU; exports.sort = sort; -exports.stable_sort = stable_sort; -exports.fast_sort = fast_sort; -exports.sort_uniq = sort_uniq; -exports.merge = merge; /* No side effect */ diff --git a/jscomp/test/test_include.res b/jscomp/test/test_include.res index 118142503d..632975fee3 100644 --- a/jscomp/test/test_include.res +++ b/jscomp/test/test_include.res @@ -1,20 +1,18 @@ -/** luckily we have module alias - so global module alias is fine -*/ -include List -module N = List +open Belt + +module N = Belt.List let v = N.length -module Make = (U: Set.OrderedType) => { - include U - let v = compare +module type OrderedType = { + type t + let compare: (t, t) => int +} + +module Make = (U: OrderedType) => { + let v = U.compare } -/* var $$let=$$String; */ -module X = Make(String) module U = Make(Test_order) -/* var X=Make([0,$$let[25]]); */ -include N /* Missing optimization alias to a number could also be removed, especially 0 diff --git a/jscomp/test/test_int_map_find.js b/jscomp/test/test_int_map_find.js index 98227ccb29..d6b87b488c 100644 --- a/jscomp/test/test_int_map_find.js +++ b/jscomp/test/test_int_map_find.js @@ -1,140 +1,10 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml = require("../../lib/js/caml.js"); -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); +let Belt_MapInt = require("../../lib/js/belt_MapInt.js"); -function height(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} - -function create(l, x, d, r) { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} - -function bal(l, x, d, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; -} - -function add(x, data, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml.int_compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -List.fold_left((acc, param) => add(param[0], param[1], acc), "Empty", { +Belt_List.reduceReverse({ hd: [ 10, /* 'a' */97 @@ -158,6 +28,6 @@ List.fold_left((acc, param) => add(param[0], param[1], acc), "Empty", { } } } -}); +}, undefined, (acc, param) => Belt_MapInt.set(acc, param[0], param[1])); /* Not a pure module */ diff --git a/jscomp/test/test_int_map_find.res b/jscomp/test/test_int_map_find.res index df1ba9ab83..8f2da1cb9b 100644 --- a/jscomp/test/test_int_map_find.res +++ b/jscomp/test/test_int_map_find.res @@ -1,27 +1,25 @@ +open Belt + include ( { - module IntMap = Map.Make({ - type t = int - let compare = (x: t, y) => compare(x, y) - }) + module IntMap = Map.Int let empty = IntMap.empty - let m = List.fold_left( - (acc, (k, v)) => IntMap.add(k, v, acc), - empty, - list{(10, 'a'), (3, 'b'), (7, 'c'), (20, 'd')}, - ) + let m = List.reduceReverse(list{(10, 'a'), (3, 'b'), (7, 'c'), (20, 'd')}, empty, ( + acc, + (k, v), + ) => acc->IntMap.set(k, v)) /* external log : 'a -> unit = "" [@@val "console.log"] */ let assert_test = () => - if IntMap.find(10, m) == 'a' { - prerr_endline("hi") + if m->IntMap.get(10) == Some('a') { + Js.log("hi") } else { /* log ('a', "succeed") */ - prerr_endline("hi") + Js.log("hi") } }: {} ) diff --git a/jscomp/test/test_js_ffi.js b/jscomp/test/test_js_ffi.js index 896eb7957f..b441d700a9 100644 --- a/jscomp/test/test_js_ffi.js +++ b/jscomp/test/test_js_ffi.js @@ -1,19 +1,17 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let $$String = require("../../lib/js/string.js"); +let Test_order = require("./test_order.js"); function v(u) { - t({ - compare: $$String.compare - }); + t(Test_order); } function u(v) { return v; } -let s = $$String; +let s = Test_order; exports.v = v; exports.u = u; diff --git a/jscomp/test/test_js_ffi.res b/jscomp/test/test_js_ffi.res index 80bbbe1565..80e87e3688 100644 --- a/jscomp/test/test_js_ffi.res +++ b/jscomp/test/test_js_ffi.res @@ -1,19 +1,24 @@ @val("console.log") /** we should also allow js function call from an external js module */ -external log: 'a => unit = "?ignore" +external log: 'a => unit = "%ignore" let v = u => { log(u) u } -@val("t") external test_f: module(Set.OrderedType) => unit = "?update_dummy" +module type OrderedType = { + type t + let compare: (t, t) => int +} + +@val("t") external test_f: module(OrderedType) => unit = "update_dummy" -let v = u => test_f(module(String)) +let v = u => test_f(module(Test_order)) -module type X = module type of String +module type X = module type of Test_order let u = (v: module(X)) => v -let s = u(module(String)) +let s = u(module(Test_order)) diff --git a/jscomp/test/test_let.js b/jscomp/test/test_let.js index 18822f9a11..8ed1d482bc 100644 --- a/jscomp/test/test_let.js +++ b/jscomp/test/test_let.js @@ -2,7 +2,7 @@ 'use strict'; -console.log(String(3)); +console.log(3); let b = 3; diff --git a/jscomp/test/test_let.res b/jscomp/test/test_let.res index 04a968cd98..6eb181c79c 100644 --- a/jscomp/test/test_let.res +++ b/jscomp/test/test_let.res @@ -1,5 +1,5 @@ { let a = 3 - print_int(a) + Js.log(a) } let b = 3 diff --git a/jscomp/test/test_list.js b/jscomp/test/test_list.js index fb1b9ac5d4..fe3331cba8 100644 --- a/jscomp/test/test_list.js +++ b/jscomp/test/test_list.js @@ -1,8 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let Pervasives = require("../../lib/js/pervasives.js"); function length_aux(_len, _x) { @@ -426,7 +425,7 @@ function mem(x, _x_) { if (!x_) { return false; } - if (Caml_obj.equal(x_.hd, x)) { + if (x_.hd === x) { return true; } _x_ = x_.tl; @@ -453,7 +452,7 @@ function assoc(x, _x_) { let x_ = _x_; if (x_) { let match = x_.hd; - if (Caml_obj.equal(match[0], x)) { + if (match[0] === x) { return match[1]; } _x_ = x_.tl; @@ -490,7 +489,7 @@ function mem_assoc(x, _x_) { if (!x_) { return false; } - if (Caml_obj.equal(x_.hd[0], x)) { + if (x_.hd[0] === x) { return true; } _x_ = x_.tl; @@ -518,7 +517,7 @@ function remove_assoc(x, x_) { } let l = x_.tl; let pair = x_.hd; - if (Caml_obj.equal(pair[0], x)) { + if (pair[0] === x) { return l; } else { return { @@ -1487,7 +1486,7 @@ function sort_uniq(cmp, l) { } } -let u = List.length; +let u = Belt_List.length; let append = Pervasives.$at; diff --git a/jscomp/test/test_list.res b/jscomp/test/test_list.res index c4bfeb3804..915566e571 100644 --- a/jscomp/test/test_list.res +++ b/jscomp/test/test_list.res @@ -13,7 +13,7 @@ /* List operations */ -let u = List.length +let u = Belt.List.length let rec length_aux = (len, x) => switch x { | list{} => len diff --git a/jscomp/test/test_literal.js b/jscomp/test/test_literal.js index d83f67d7df..2e5a627097 100644 --- a/jscomp/test/test_literal.js +++ b/jscomp/test/test_literal.js @@ -1,9 +1,9 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); -let Custom_inline = /* @__PURE__ */Caml_exceptions.create("Test_literal.Custom_inline"); +let Custom_inline = /* @__PURE__ */Primitive_exceptions.create("Test_literal.Custom_inline"); let v = { RE_EXN_ID: Custom_inline, diff --git a/jscomp/test/test_match_exception.js b/jscomp/test/test_match_exception.js index ee79886634..dcabf74e0b 100644 --- a/jscomp/test/test_match_exception.js +++ b/jscomp/test/test_match_exception.js @@ -1,13 +1,13 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); function f(g, x) { try { return g(x); } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + let exn = Primitive_exceptions.internalToException(raw_exn); if (exn.RE_EXN_ID === "Not_found") { return 3; } diff --git a/jscomp/test/test_mutliple.js b/jscomp/test/test_mutliple.js deleted file mode 100644 index 404f57bca2..0000000000 --- a/jscomp/test/test_mutliple.js +++ /dev/null @@ -1,9 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let List = require("../../lib/js/list.js"); - -let f = List.length(/* [] */0); - -exports.f = f; -/* f Not a pure module */ diff --git a/jscomp/test/test_mutliple.res b/jscomp/test/test_mutliple.res deleted file mode 100644 index 6550ffcb49..0000000000 --- a/jscomp/test/test_mutliple.res +++ /dev/null @@ -1 +0,0 @@ -let f = List.length(list{}) diff --git a/jscomp/test/test_nat64.js b/jscomp/test/test_nat64.js deleted file mode 100644 index a09273ff76..0000000000 --- a/jscomp/test/test_nat64.js +++ /dev/null @@ -1,9 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let Caml_int64 = require("../../lib/js/caml_int64.js"); - -let v = Caml_int64.zero; - -exports.v = v; -/* No side effect */ diff --git a/jscomp/test/test_nat64.res b/jscomp/test/test_nat64.res deleted file mode 100644 index f66884382f..0000000000 --- a/jscomp/test/test_nat64.res +++ /dev/null @@ -1 +0,0 @@ -let v = 0L diff --git a/jscomp/test/test_non_export.js b/jscomp/test/test_non_export.js index d856702bfe..d5f7e2fcca 100644 --- a/jscomp/test/test_non_export.js +++ b/jscomp/test/test_non_export.js @@ -1,2 +1,10 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ +'use strict'; + + +function Make(U) { + return U; +} + +exports.Make = Make; +/* No side effect */ diff --git a/jscomp/test/test_non_export.res b/jscomp/test/test_non_export.res index 964cbd93da..9a920dac82 100644 --- a/jscomp/test/test_non_export.res +++ b/jscomp/test/test_non_export.res @@ -1,20 +1,28 @@ +module type OrderedType = { + type t + let compare: (t, t) => int +} + +module Make = (U: OrderedType) => { + include U +} + include ( { - module V = String + module V = Test_order module U = V - let u = U.make - let v = module(U: Set.OrderedType) + let v = module(U: OrderedType) let pack = h => { - module U = unpack(h: Set.OrderedType) - module V = Set.Make(U) - module(V: Set.S) + module U = unpack(h: OrderedType) + module V = Make(U) + module(V: OrderedType) } let g = pack(v) - let gg = pack(module(String)) - module N = Set.Make(U) - module NN = Set.Make(String) + let gg = pack(module(Test_order)) + module N = Make(U) + module NN = Make(Test_order) }: {} ) diff --git a/jscomp/test/test_nullary.res b/jscomp/test/test_nullary.res index 4ae890b8af..01388a0306 100644 --- a/jscomp/test/test_nullary.res +++ b/jscomp/test/test_nullary.res @@ -1 +1 @@ -let f = _ => print_endline("hey") +let f = _ => Js.log("hey") diff --git a/jscomp/test/test_order.js b/jscomp/test/test_order.js index 802634ad67..8bd95c7637 100644 --- a/jscomp/test/test_order.js +++ b/jscomp/test/test_order.js @@ -1,9 +1,9 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml = require("../../lib/js/caml.js"); +let Primitive_int = require("../../lib/js/primitive_int.js"); -let compare = Caml.int_compare; +let compare = Primitive_int.compare; exports.compare = compare; /* No side effect */ diff --git a/jscomp/test/test_order_tailcall.res b/jscomp/test/test_order_tailcall.res index 1a4ac646c3..b1a76700b8 100644 --- a/jscomp/test/test_order_tailcall.res +++ b/jscomp/test/test_order_tailcall.res @@ -1,7 +1,7 @@ let rec f = (x, y) => f(y, x) let rec f1 = (x, y, z) => { - print_endline(z) + Js.log(z) f1(y, z, x) } diff --git a/jscomp/test/test_per.js b/jscomp/test/test_per.js index 2932670776..d9dbf52f23 100644 --- a/jscomp/test/test_per.js +++ b/jscomp/test/test_per.js @@ -1,10 +1,8 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_obj = require("../../lib/js/caml_obj.js"); -let Caml_bytes = require("../../lib/js/caml_bytes.js"); -let Caml_int64 = require("../../lib/js/caml_int64.js"); -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); function failwith(s) { throw { @@ -22,10 +20,10 @@ function invalid_arg(s) { }; } -let Exit = /* @__PURE__ */Caml_exceptions.create("Test_per.Exit"); +let Exit = /* @__PURE__ */Primitive_exceptions.create("Test_per.Exit"); function min(x, y) { - if (Caml_obj.lessequal(x, y)) { + if (Primitive_object.lessequal(x, y)) { return x; } else { return y; @@ -33,7 +31,7 @@ function min(x, y) { } function max(x, y) { - if (Caml_obj.greaterequal(x, y)) { + if (Primitive_object.greaterequal(x, y)) { return x; } else { return y; @@ -54,45 +52,6 @@ function lnot(x) { let min_int = -2147483648; -let infinity = Caml_int64.float_of_bits([ - 2146435072, - 0 -]); - -let neg_infinity = Caml_int64.float_of_bits([ - -1048576, - 0 -]); - -let nan = Caml_int64.float_of_bits([ - 2146435072, - 1 -]); - -let max_float = Caml_int64.float_of_bits([ - 2146435071, - 4294967295 -]); - -let min_float = Caml_int64.float_of_bits([ - 1048576, - 0 -]); - -let epsilon_float = Caml_int64.float_of_bits([ - 1018167296, - 0 -]); - -function $caret(s1, s2) { - let l1 = s1.length; - let l2 = s2.length; - let s = Caml_bytes.create(l1 + l2 | 0); - blit_string(s1, 0, s, 0, l1); - blit_string(s2, 0, s, l1, l2); - return s; -} - function char_of_int(n) { if (n < 0 || n > 255) { throw { @@ -115,12 +74,5 @@ exports.abs = abs; exports.lnot = lnot; exports.max_int = max_int; exports.min_int = min_int; -exports.infinity = infinity; -exports.neg_infinity = neg_infinity; -exports.nan = nan; -exports.max_float = max_float; -exports.min_float = min_float; -exports.epsilon_float = epsilon_float; -exports.$caret = $caret; exports.char_of_int = char_of_int; /* No side effect */ diff --git a/jscomp/test/test_per.res b/jscomp/test/test_per.res index f7ecd86b2d..1ecbd2f262 100644 --- a/jscomp/test/test_per.res +++ b/jscomp/test/test_per.res @@ -121,7 +121,7 @@ external ceil: float => float = "?ceil_float" external floor: float => float = "?floor_float" external abs_float: float => float = "%absfloat" external copysign: (float, float) => float = "?copysign_float" -external mod_float: (float, float) => float = "?fmod_float" +external mod_float: (float, float) => float = "%modfloat" external frexp: float => (float, int) = "?frexp_float" external ldexp: (float, int) => float = "?ldexp_float" external modf: float => (float, float) = "?modf_float" @@ -129,13 +129,6 @@ external float: int => float = "%floatofint" external float_of_int: int => float = "%floatofint" external truncate: float => int = "%intoffloat" external int_of_float: float => int = "%intoffloat" -external float_of_bits: int64 => float = "?int64_float_of_bits" -let infinity = float_of_bits(0x7F_F0_00_00_00_00_00_00L) -let neg_infinity = float_of_bits(0xFF_F0_00_00_00_00_00_00L) -let nan = float_of_bits(0x7F_F0_00_00_00_00_00_01L) -let max_float = float_of_bits(0x7F_EF_FF_FF_FF_FF_FF_FFL) -let min_float = float_of_bits(0x00_10_00_00_00_00_00_00L) -let epsilon_float = float_of_bits(0x3C_B0_00_00_00_00_00_00L) type fpclass = | FP_normal @@ -145,23 +138,7 @@ type fpclass = | FP_nan external classify_float: float => fpclass = "?classify_float" -/* String and byte sequence operations -- more in modules String and Bytes */ - external string_length: string => int = "%string_length" -external bytes_length: bytes => int = "%string_length" -external bytes_create: int => bytes = "?create_bytes" -external string_blit: (string, int, bytes, int, int) => unit = "blit_string" -external bytes_blit: (bytes, int, bytes, int, int) => unit = "blit_string" -external bytes_unsafe_to_string: bytes => string = "%identity" -external bytes_unsafe_of_string: string => bytes = "%identity" - -let \"^" = (s1, s2) => { - let l1 = string_length(s1) and l2 = string_length(s2) - let s = bytes_create(l1 + l2) - string_blit(s1, 0, s, 0, l1) - string_blit(s2, 0, s, l1, l2) - bytes_unsafe_to_string(s) -} /* Character operations -- more in module Char */ @@ -186,8 +163,8 @@ external snd: (('a, 'b)) => 'b = "%field1" /* References */ type ref<'a> = {mutable contents: 'a} -external ref: 'a => ref<'a> = "%makemutable" -external \"!": ref<'a> => 'a = "%bs_ref_field0" -external \":=": (ref<'a>, 'a) => unit = "%bs_ref_setfield0" +external ref: 'a => ref<'a> = "%makeref" +external \"!": ref<'a> => 'a = "%refget" +external \":=": (ref<'a>, 'a) => unit = "%refset" external incr: ref => unit = "%incr" external decr: ref => unit = "%decr" diff --git a/jscomp/test/test_pervasive.js b/jscomp/test/test_pervasive.js index b2c2d895ee..33533da172 100644 --- a/jscomp/test/test_pervasive.js +++ b/jscomp/test/test_pervasive.js @@ -1,91 +1,155 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let Pervasives = require("../../lib/js/pervasives.js"); +let $at = Pervasives.Pervasives.$at; + +let Pervasives_failwith = Pervasives.Pervasives.failwith; + +let Pervasives_invalid_arg = Pervasives.Pervasives.invalid_arg; + +let Pervasives_Exit = Pervasives.Pervasives.Exit; + +let Pervasives_abs = Pervasives.Pervasives.abs; + +let Pervasives_lnot = Pervasives.Pervasives.lnot; + +let Pervasives_max_int = Pervasives.Pervasives.max_int; + +let Pervasives_min_int = Pervasives.Pervasives.min_int; + +let Pervasives_infinity = Pervasives.Pervasives.infinity; + +let Pervasives_neg_infinity = Pervasives.Pervasives.neg_infinity; + +let Pervasives_max_float = Pervasives.Pervasives.max_float; + +let Pervasives_min_float = Pervasives.Pervasives.min_float; + +let Pervasives_epsilon_float = Pervasives.Pervasives.epsilon_float; + +let Pervasives_classify_float = Pervasives.Pervasives.classify_float; + +let Pervasives_char_of_int = Pervasives.Pervasives.char_of_int; + +let Pervasives_string_of_bool = Pervasives.Pervasives.string_of_bool; + +let Pervasives_bool_of_string = Pervasives.Pervasives.bool_of_string; + +let Pervasives_bool_of_string_opt = Pervasives.Pervasives.bool_of_string_opt; + +let Pervasives_int_of_string_opt = Pervasives.Pervasives.int_of_string_opt; + let Pervasives$1 = { - length: List.length, - compare_lengths: List.compare_lengths, - compare_length_with: List.compare_length_with, - cons: List.cons, - hd: List.hd, - tl: List.tl, - nth: List.nth, - nth_opt: List.nth_opt, - rev: List.rev, - init: List.init, - append: List.append, - rev_append: List.rev_append, - concat: List.concat, - flatten: List.flatten, - iter: List.iter, - iteri: List.iteri, - map: List.map, - mapi: List.mapi, - rev_map: List.rev_map, - fold_left: List.fold_left, - fold_right: List.fold_right, - iter2: List.iter2, - map2: List.map2, - rev_map2: List.rev_map2, - fold_left2: List.fold_left2, - fold_right2: List.fold_right2, - for_all: List.for_all, - exists: List.exists, - for_all2: List.for_all2, - exists2: List.exists2, - mem: List.mem, - memq: List.memq, - find: List.find, - find_opt: List.find_opt, - filter: List.filter, - find_all: List.find_all, - partition: List.partition, - assoc: List.assoc, - assoc_opt: List.assoc_opt, - assq: List.assq, - assq_opt: List.assq_opt, - mem_assoc: List.mem_assoc, - mem_assq: List.mem_assq, - remove_assoc: List.remove_assoc, - remove_assq: List.remove_assq, - split: List.split, - combine: List.combine, - sort: List.sort, - stable_sort: List.stable_sort, - fast_sort: List.fast_sort, - sort_uniq: List.sort_uniq, - merge: List.merge, - invalid_arg: Pervasives.invalid_arg, - failwith: Pervasives.failwith, - Exit: Pervasives.Exit, - abs: Pervasives.abs, - max_int: Pervasives.max_int, - min_int: Pervasives.min_int, - lnot: Pervasives.lnot, - infinity: Pervasives.infinity, - neg_infinity: Pervasives.neg_infinity, - max_float: Pervasives.max_float, - min_float: Pervasives.min_float, - epsilon_float: Pervasives.epsilon_float, - classify_float: Pervasives.classify_float, - char_of_int: Pervasives.char_of_int, - string_of_bool: Pervasives.string_of_bool, - bool_of_string: Pervasives.bool_of_string, - bool_of_string_opt: Pervasives.bool_of_string_opt, - int_of_string_opt: Pervasives.int_of_string_opt, - string_of_float: Pervasives.string_of_float, - float_of_string_opt: Pervasives.float_of_string_opt, - $at: Pervasives.$at, - print_string: Pervasives.print_string, - print_int: Pervasives.print_int, - print_float: Pervasives.print_float, - print_newline: Pervasives.print_newline, - prerr_newline: Pervasives.prerr_newline, - exit: Pervasives.exit, - at_exit: Pervasives.at_exit, - valid_float_lexem: Pervasives.valid_float_lexem + length: Belt_List.length, + size: Belt_List.size, + head: Belt_List.head, + headExn: Belt_List.headExn, + tail: Belt_List.tail, + tailExn: Belt_List.tailExn, + add: Belt_List.add, + get: Belt_List.get, + getExn: Belt_List.getExn, + make: Belt_List.make, + makeByU: Belt_List.makeByU, + makeBy: Belt_List.makeBy, + shuffle: Belt_List.shuffle, + drop: Belt_List.drop, + take: Belt_List.take, + splitAt: Belt_List.splitAt, + concat: Belt_List.concat, + concatMany: Belt_List.concatMany, + reverseConcat: Belt_List.reverseConcat, + flatten: Belt_List.flatten, + mapU: Belt_List.mapU, + map: Belt_List.map, + zip: Belt_List.zip, + zipByU: Belt_List.zipByU, + zipBy: Belt_List.zipBy, + mapWithIndexU: Belt_List.mapWithIndexU, + mapWithIndex: Belt_List.mapWithIndex, + fromArray: Belt_List.fromArray, + toArray: Belt_List.toArray, + reverse: Belt_List.reverse, + mapReverseU: Belt_List.mapReverseU, + mapReverse: Belt_List.mapReverse, + forEachU: Belt_List.forEachU, + forEach: Belt_List.forEach, + forEachWithIndexU: Belt_List.forEachWithIndexU, + forEachWithIndex: Belt_List.forEachWithIndex, + reduceU: Belt_List.reduceU, + reduce: Belt_List.reduce, + reduceWithIndexU: Belt_List.reduceWithIndexU, + reduceWithIndex: Belt_List.reduceWithIndex, + reduceReverseU: Belt_List.reduceReverseU, + reduceReverse: Belt_List.reduceReverse, + mapReverse2U: Belt_List.mapReverse2U, + mapReverse2: Belt_List.mapReverse2, + forEach2U: Belt_List.forEach2U, + forEach2: Belt_List.forEach2, + reduce2U: Belt_List.reduce2U, + reduce2: Belt_List.reduce2, + reduceReverse2U: Belt_List.reduceReverse2U, + reduceReverse2: Belt_List.reduceReverse2, + everyU: Belt_List.everyU, + every: Belt_List.every, + someU: Belt_List.someU, + some: Belt_List.some, + every2U: Belt_List.every2U, + every2: Belt_List.every2, + some2U: Belt_List.some2U, + some2: Belt_List.some2, + cmpByLength: Belt_List.cmpByLength, + cmpU: Belt_List.cmpU, + cmp: Belt_List.cmp, + eqU: Belt_List.eqU, + eq: Belt_List.eq, + hasU: Belt_List.hasU, + has: Belt_List.has, + getByU: Belt_List.getByU, + getBy: Belt_List.getBy, + keepU: Belt_List.keepU, + keep: Belt_List.keep, + filter: Belt_List.filter, + keepWithIndexU: Belt_List.keepWithIndexU, + keepWithIndex: Belt_List.keepWithIndex, + filterWithIndex: Belt_List.filterWithIndex, + keepMapU: Belt_List.keepMapU, + keepMap: Belt_List.keepMap, + partitionU: Belt_List.partitionU, + partition: Belt_List.partition, + unzip: Belt_List.unzip, + getAssocU: Belt_List.getAssocU, + getAssoc: Belt_List.getAssoc, + hasAssocU: Belt_List.hasAssocU, + hasAssoc: Belt_List.hasAssoc, + removeAssocU: Belt_List.removeAssocU, + removeAssoc: Belt_List.removeAssoc, + setAssocU: Belt_List.setAssocU, + setAssoc: Belt_List.setAssoc, + sortU: Belt_List.sortU, + sort: Belt_List.sort, + failwith: Pervasives_failwith, + invalid_arg: Pervasives_invalid_arg, + Exit: Pervasives_Exit, + abs: Pervasives_abs, + lnot: Pervasives_lnot, + max_int: Pervasives_max_int, + min_int: Pervasives_min_int, + infinity: Pervasives_infinity, + neg_infinity: Pervasives_neg_infinity, + max_float: Pervasives_max_float, + min_float: Pervasives_min_float, + epsilon_float: Pervasives_epsilon_float, + classify_float: Pervasives_classify_float, + char_of_int: Pervasives_char_of_int, + string_of_bool: Pervasives_string_of_bool, + bool_of_string: Pervasives_bool_of_string, + bool_of_string_opt: Pervasives_bool_of_string_opt, + int_of_string_opt: Pervasives_int_of_string_opt, + $at: $at }; function a0(prim) { @@ -164,7 +228,7 @@ function a18(prim0, prim1) { return Math.pow(prim0, prim1); } -let f = Pervasives.$at; +let f = $at; exports.Pervasives = Pervasives$1; exports.f = f; diff --git a/jscomp/test/test_pervasive.res b/jscomp/test/test_pervasive.res index 7463c6d426..f280901a48 100644 --- a/jscomp/test/test_pervasive.res +++ b/jscomp/test/test_pervasive.res @@ -1,5 +1,5 @@ module Pervasives = { - include List + include Belt.List include Pervasives } diff --git a/jscomp/test/test_pervasives2.js b/jscomp/test/test_pervasives2.js deleted file mode 100644 index e4f3b31e88..0000000000 --- a/jscomp/test/test_pervasives2.js +++ /dev/null @@ -1,146 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let List = require("../../lib/js/list.js"); -let Stack = require("../../lib/js/stack.js"); -let Pervasives = require("../../lib/js/pervasives.js"); - -let List$1 = { - length: List.length, - compare_lengths: List.compare_lengths, - compare_length_with: List.compare_length_with, - cons: List.cons, - hd: List.hd, - tl: List.tl, - nth: List.nth, - nth_opt: List.nth_opt, - rev: List.rev, - init: List.init, - append: List.append, - rev_append: List.rev_append, - concat: List.concat, - flatten: List.flatten, - iter: List.iter, - iteri: List.iteri, - map: List.map, - mapi: List.mapi, - rev_map: List.rev_map, - fold_left: List.fold_left, - fold_right: List.fold_right, - iter2: List.iter2, - map2: List.map2, - rev_map2: List.rev_map2, - fold_left2: List.fold_left2, - fold_right2: List.fold_right2, - for_all: List.for_all, - exists: List.exists, - for_all2: List.for_all2, - exists2: List.exists2, - mem: List.mem, - memq: List.memq, - find: List.find, - find_opt: List.find_opt, - filter: List.filter, - find_all: List.find_all, - partition: List.partition, - assoc: List.assoc, - assoc_opt: List.assoc_opt, - assq: List.assq, - assq_opt: List.assq_opt, - mem_assoc: List.mem_assoc, - mem_assq: List.mem_assq, - remove_assoc: List.remove_assoc, - remove_assq: List.remove_assq, - split: List.split, - combine: List.combine, - sort: List.sort, - stable_sort: List.stable_sort, - fast_sort: List.fast_sort, - sort_uniq: List.sort_uniq, - merge: List.merge, - invalid_arg: Pervasives.invalid_arg, - failwith: Pervasives.failwith, - Exit: Pervasives.Exit, - abs: Pervasives.abs, - max_int: Pervasives.max_int, - min_int: Pervasives.min_int, - lnot: Pervasives.lnot, - infinity: Pervasives.infinity, - neg_infinity: Pervasives.neg_infinity, - max_float: Pervasives.max_float, - min_float: Pervasives.min_float, - epsilon_float: Pervasives.epsilon_float, - classify_float: Pervasives.classify_float, - char_of_int: Pervasives.char_of_int, - string_of_bool: Pervasives.string_of_bool, - bool_of_string: Pervasives.bool_of_string, - bool_of_string_opt: Pervasives.bool_of_string_opt, - int_of_string_opt: Pervasives.int_of_string_opt, - string_of_float: Pervasives.string_of_float, - float_of_string_opt: Pervasives.float_of_string_opt, - $at: Pervasives.$at, - print_string: Pervasives.print_string, - print_int: Pervasives.print_int, - print_float: Pervasives.print_float, - print_newline: Pervasives.print_newline, - prerr_newline: Pervasives.prerr_newline, - exit: Pervasives.exit, - at_exit: Pervasives.at_exit, - valid_float_lexem: Pervasives.valid_float_lexem -}; - -let U = { - Empty: Stack.Empty, - create: Stack.create, - push: Stack.push, - pop: Stack.pop, - top: Stack.top, - clear: Stack.clear, - copy: Stack.copy, - is_empty: Stack.is_empty, - length: Stack.length, - iter: Stack.iter, - fold: Stack.fold, - invalid_arg: Pervasives.invalid_arg, - failwith: Pervasives.failwith, - Exit: Pervasives.Exit, - abs: Pervasives.abs, - max_int: Pervasives.max_int, - min_int: Pervasives.min_int, - lnot: Pervasives.lnot, - infinity: Pervasives.infinity, - neg_infinity: Pervasives.neg_infinity, - max_float: Pervasives.max_float, - min_float: Pervasives.min_float, - epsilon_float: Pervasives.epsilon_float, - classify_float: Pervasives.classify_float, - char_of_int: Pervasives.char_of_int, - string_of_bool: Pervasives.string_of_bool, - bool_of_string: Pervasives.bool_of_string, - bool_of_string_opt: Pervasives.bool_of_string_opt, - int_of_string_opt: Pervasives.int_of_string_opt, - string_of_float: Pervasives.string_of_float, - float_of_string_opt: Pervasives.float_of_string_opt, - $at: Pervasives.$at, - print_string: Pervasives.print_string, - print_int: Pervasives.print_int, - print_float: Pervasives.print_float, - print_newline: Pervasives.print_newline, - prerr_newline: Pervasives.prerr_newline, - exit: Pervasives.exit, - at_exit: Pervasives.at_exit, - valid_float_lexem: Pervasives.valid_float_lexem -}; - -let f = Pervasives.$at; - -let ff = List.length; - -let fff = Pervasives.$at; - -exports.List = List$1; -exports.U = U; -exports.f = f; -exports.ff = ff; -exports.fff = fff; -/* No side effect */ diff --git a/jscomp/test/test_pervasives2.res b/jscomp/test/test_pervasives2.res deleted file mode 100644 index 4163ca8dba..0000000000 --- a/jscomp/test/test_pervasives2.res +++ /dev/null @@ -1,14 +0,0 @@ -module List = { - include List - include Pervasives -} - -module U = { - include Stack - include Pervasives -} - -let f = List.\"@" -let ff = List.length - -let fff = U.\"@" diff --git a/jscomp/test/test_pervasives3.js b/jscomp/test/test_pervasives3.js index 2ac75a92c1..27b9eb4881 100644 --- a/jscomp/test/test_pervasives3.js +++ b/jscomp/test/test_pervasives3.js @@ -1,94 +1,158 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let Pervasives = require("../../lib/js/pervasives.js"); +let $at = Pervasives.Pervasives.$at; + +let Pervasives_failwith = Pervasives.Pervasives.failwith; + +let Pervasives_invalid_arg = Pervasives.Pervasives.invalid_arg; + +let Pervasives_Exit = Pervasives.Pervasives.Exit; + +let Pervasives_abs = Pervasives.Pervasives.abs; + +let Pervasives_lnot = Pervasives.Pervasives.lnot; + +let Pervasives_max_int = Pervasives.Pervasives.max_int; + +let Pervasives_min_int = Pervasives.Pervasives.min_int; + +let Pervasives_infinity = Pervasives.Pervasives.infinity; + +let Pervasives_neg_infinity = Pervasives.Pervasives.neg_infinity; + +let Pervasives_max_float = Pervasives.Pervasives.max_float; + +let Pervasives_min_float = Pervasives.Pervasives.min_float; + +let Pervasives_epsilon_float = Pervasives.Pervasives.epsilon_float; + +let Pervasives_classify_float = Pervasives.Pervasives.classify_float; + +let Pervasives_char_of_int = Pervasives.Pervasives.char_of_int; + +let Pervasives_string_of_bool = Pervasives.Pervasives.string_of_bool; + +let Pervasives_bool_of_string = Pervasives.Pervasives.bool_of_string; + +let Pervasives_bool_of_string_opt = Pervasives.Pervasives.bool_of_string_opt; + +let Pervasives_int_of_string_opt = Pervasives.Pervasives.int_of_string_opt; + let Pervasives$1 = { - invalid_arg: Pervasives.invalid_arg, - failwith: Pervasives.failwith, - Exit: Pervasives.Exit, - abs: Pervasives.abs, - max_int: Pervasives.max_int, - min_int: Pervasives.min_int, - lnot: Pervasives.lnot, - infinity: Pervasives.infinity, - neg_infinity: Pervasives.neg_infinity, - max_float: Pervasives.max_float, - min_float: Pervasives.min_float, - epsilon_float: Pervasives.epsilon_float, - classify_float: Pervasives.classify_float, - char_of_int: Pervasives.char_of_int, - string_of_bool: Pervasives.string_of_bool, - bool_of_string: Pervasives.bool_of_string, - bool_of_string_opt: Pervasives.bool_of_string_opt, - int_of_string_opt: Pervasives.int_of_string_opt, - string_of_float: Pervasives.string_of_float, - float_of_string_opt: Pervasives.float_of_string_opt, - $at: Pervasives.$at, - print_string: Pervasives.print_string, - print_int: Pervasives.print_int, - print_float: Pervasives.print_float, - print_newline: Pervasives.print_newline, - prerr_newline: Pervasives.prerr_newline, - exit: Pervasives.exit, - at_exit: Pervasives.at_exit, - valid_float_lexem: Pervasives.valid_float_lexem, - length: List.length, - compare_lengths: List.compare_lengths, - compare_length_with: List.compare_length_with, - cons: List.cons, - hd: List.hd, - tl: List.tl, - nth: List.nth, - nth_opt: List.nth_opt, - rev: List.rev, - init: List.init, - append: List.append, - rev_append: List.rev_append, - concat: List.concat, - flatten: List.flatten, - iter: List.iter, - iteri: List.iteri, - map: List.map, - mapi: List.mapi, - rev_map: List.rev_map, - fold_left: List.fold_left, - fold_right: List.fold_right, - iter2: List.iter2, - map2: List.map2, - rev_map2: List.rev_map2, - fold_left2: List.fold_left2, - fold_right2: List.fold_right2, - for_all: List.for_all, - exists: List.exists, - for_all2: List.for_all2, - exists2: List.exists2, - mem: List.mem, - memq: List.memq, - find: List.find, - find_opt: List.find_opt, - filter: List.filter, - find_all: List.find_all, - partition: List.partition, - assoc: List.assoc, - assoc_opt: List.assoc_opt, - assq: List.assq, - assq_opt: List.assq_opt, - mem_assoc: List.mem_assoc, - mem_assq: List.mem_assq, - remove_assoc: List.remove_assoc, - remove_assq: List.remove_assq, - split: List.split, - combine: List.combine, - sort: List.sort, - stable_sort: List.stable_sort, - fast_sort: List.fast_sort, - sort_uniq: List.sort_uniq, - merge: List.merge + failwith: Pervasives_failwith, + invalid_arg: Pervasives_invalid_arg, + Exit: Pervasives_Exit, + abs: Pervasives_abs, + lnot: Pervasives_lnot, + max_int: Pervasives_max_int, + min_int: Pervasives_min_int, + infinity: Pervasives_infinity, + neg_infinity: Pervasives_neg_infinity, + max_float: Pervasives_max_float, + min_float: Pervasives_min_float, + epsilon_float: Pervasives_epsilon_float, + classify_float: Pervasives_classify_float, + char_of_int: Pervasives_char_of_int, + string_of_bool: Pervasives_string_of_bool, + bool_of_string: Pervasives_bool_of_string, + bool_of_string_opt: Pervasives_bool_of_string_opt, + int_of_string_opt: Pervasives_int_of_string_opt, + $at: $at, + length: Belt_List.length, + size: Belt_List.size, + head: Belt_List.head, + headExn: Belt_List.headExn, + tail: Belt_List.tail, + tailExn: Belt_List.tailExn, + add: Belt_List.add, + get: Belt_List.get, + getExn: Belt_List.getExn, + make: Belt_List.make, + makeByU: Belt_List.makeByU, + makeBy: Belt_List.makeBy, + shuffle: Belt_List.shuffle, + drop: Belt_List.drop, + take: Belt_List.take, + splitAt: Belt_List.splitAt, + concat: Belt_List.concat, + concatMany: Belt_List.concatMany, + reverseConcat: Belt_List.reverseConcat, + flatten: Belt_List.flatten, + mapU: Belt_List.mapU, + map: Belt_List.map, + zip: Belt_List.zip, + zipByU: Belt_List.zipByU, + zipBy: Belt_List.zipBy, + mapWithIndexU: Belt_List.mapWithIndexU, + mapWithIndex: Belt_List.mapWithIndex, + fromArray: Belt_List.fromArray, + toArray: Belt_List.toArray, + reverse: Belt_List.reverse, + mapReverseU: Belt_List.mapReverseU, + mapReverse: Belt_List.mapReverse, + forEachU: Belt_List.forEachU, + forEach: Belt_List.forEach, + forEachWithIndexU: Belt_List.forEachWithIndexU, + forEachWithIndex: Belt_List.forEachWithIndex, + reduceU: Belt_List.reduceU, + reduce: Belt_List.reduce, + reduceWithIndexU: Belt_List.reduceWithIndexU, + reduceWithIndex: Belt_List.reduceWithIndex, + reduceReverseU: Belt_List.reduceReverseU, + reduceReverse: Belt_List.reduceReverse, + mapReverse2U: Belt_List.mapReverse2U, + mapReverse2: Belt_List.mapReverse2, + forEach2U: Belt_List.forEach2U, + forEach2: Belt_List.forEach2, + reduce2U: Belt_List.reduce2U, + reduce2: Belt_List.reduce2, + reduceReverse2U: Belt_List.reduceReverse2U, + reduceReverse2: Belt_List.reduceReverse2, + everyU: Belt_List.everyU, + every: Belt_List.every, + someU: Belt_List.someU, + some: Belt_List.some, + every2U: Belt_List.every2U, + every2: Belt_List.every2, + some2U: Belt_List.some2U, + some2: Belt_List.some2, + cmpByLength: Belt_List.cmpByLength, + cmpU: Belt_List.cmpU, + cmp: Belt_List.cmp, + eqU: Belt_List.eqU, + eq: Belt_List.eq, + hasU: Belt_List.hasU, + has: Belt_List.has, + getByU: Belt_List.getByU, + getBy: Belt_List.getBy, + keepU: Belt_List.keepU, + keep: Belt_List.keep, + filter: Belt_List.filter, + keepWithIndexU: Belt_List.keepWithIndexU, + keepWithIndex: Belt_List.keepWithIndex, + filterWithIndex: Belt_List.filterWithIndex, + keepMapU: Belt_List.keepMapU, + keepMap: Belt_List.keepMap, + partitionU: Belt_List.partitionU, + partition: Belt_List.partition, + unzip: Belt_List.unzip, + getAssocU: Belt_List.getAssocU, + getAssoc: Belt_List.getAssoc, + hasAssocU: Belt_List.hasAssocU, + hasAssoc: Belt_List.hasAssoc, + removeAssocU: Belt_List.removeAssocU, + removeAssoc: Belt_List.removeAssoc, + setAssocU: Belt_List.setAssocU, + setAssoc: Belt_List.setAssoc, + sortU: Belt_List.sortU, + sort: Belt_List.sort }; -let v = Pervasives.$at; +let v = $at; exports.Pervasives = Pervasives$1; exports.v = v; diff --git a/jscomp/test/test_pervasives3.res b/jscomp/test/test_pervasives3.res index d9118e4a6c..a56aae6ad5 100644 --- a/jscomp/test/test_pervasives3.res +++ b/jscomp/test/test_pervasives3.res @@ -1,5 +1,5 @@ module Pervasives = { include Pervasives - include List + include Belt.List } let v = Pervasives.\"@" diff --git a/jscomp/test/test_primitive.js b/jscomp/test/test_primitive.js index 7ac5a138b3..6d4f8c8657 100644 --- a/jscomp/test/test_primitive.js +++ b/jscomp/test/test_primitive.js @@ -1,9 +1,8 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_array = require("../../lib/js/caml_array.js"); -let Caml_string = require("../../lib/js/caml_string.js"); -let CamlinternalLazy = require("../../lib/js/camlinternalLazy.js"); +let Lazy = require("../../lib/js/lazy.js"); +let Primitive_array = require("../../lib/js/primitive_array.js"); function a4(prim) { return [ @@ -42,11 +41,11 @@ let v = [ let xxx = "a"; -let a = Caml_string.get(xxx, 0); +let a = xxx.codePointAt(0); function u(b) { if (b) { - console.log(String(1)); + console.log(1); return 32; } else { return 7; @@ -57,7 +56,7 @@ function f2(h, b, param) { return h(b ? 32 : 7); } -Caml_array.set(v, 1, 3.0); +Primitive_array.set(v, 1, 3.0); let unboxed_x = { u: 0, @@ -72,7 +71,7 @@ function f(x) { return x.length; } -let is_lazy_force = CamlinternalLazy.force; +let is_lazy_force = Lazy.force; function fib(n) { if (n === 0 || n === 1) { diff --git a/jscomp/test/test_primitive.res b/jscomp/test/test_primitive.res index 711372a915..0e39ee35a7 100644 --- a/jscomp/test/test_primitive.res +++ b/jscomp/test/test_primitive.res @@ -37,7 +37,7 @@ let xxx = "a" let a = String.get(xxx, 0) let u = b => { let a = if b { - print_int(1) + Js.log(1) 32 } else { 3 + 4 @@ -47,7 +47,7 @@ let u = b => { let f = (h, b, ()) => h( if b { - print_int(1) + Js.log(1) 32 } else { 3 + 4 diff --git a/jscomp/test/test_runtime_encoding.js b/jscomp/test/test_runtime_encoding.js index 77edc3a296..e2efc9814f 100644 --- a/jscomp/test/test_runtime_encoding.js +++ b/jscomp/test/test_runtime_encoding.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_array = require("../../lib/js/caml_array.js"); +let Primitive_array = require("../../lib/js/primitive_array.js"); function g(x) { return [ @@ -25,11 +25,11 @@ function fff(vv, uu) { } function a(x) { - return Caml_array.get(x, 0); + return Primitive_array.get(x, 0); } function aa(x) { - return Caml_array.get(x, 0); + return Primitive_array.get(x, 0); } function aaa(x) { @@ -42,7 +42,7 @@ function aaaa(x) { function f(x) { for (let i = 0; i <= 10; ++i) { - Caml_array.set(x, i, i); + Primitive_array.set(x, i, i); } } diff --git a/jscomp/test/test_seq.js b/jscomp/test/test_seq.js index f3358b1402..711fc1a601 100644 --- a/jscomp/test/test_seq.js +++ b/jscomp/test/test_seq.js @@ -1,23 +1,22 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_obj = require("../../lib/js/caml_obj.js"); let Pervasives = require("../../lib/js/pervasives.js"); -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); -let Bad = /* @__PURE__ */Caml_exceptions.create("Test_seq.Bad"); +let Bad = /* @__PURE__ */Primitive_exceptions.create("Test_seq.Bad"); -let Help = /* @__PURE__ */Caml_exceptions.create("Test_seq.Help"); +let Help = /* @__PURE__ */Primitive_exceptions.create("Test_seq.Help"); -let Stop = /* @__PURE__ */Caml_exceptions.create("Test_seq.Stop"); +let Stop = /* @__PURE__ */Primitive_exceptions.create("Test_seq.Stop"); function assoc3(x, _l) { while (true) { let l = _l; if (l) { let match = l.hd; - if (Caml_obj.equal(match[0], x)) { + if (Primitive_object.equal(match[0], x)) { return match[1]; } _l = l.tl; @@ -56,7 +55,7 @@ function add_help(speclist) { assoc3("-help", speclist); add1 = /* [] */0; } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + let exn = Primitive_exceptions.internalToException(raw_exn); if (exn.RE_EXN_ID === "Not_found") { add1 = { hd: [ @@ -78,7 +77,7 @@ function add_help(speclist) { assoc3("--help", speclist); add2 = /* [] */0; } catch (raw_exn$1) { - let exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn$1); + let exn$1 = Primitive_exceptions.internalToException(raw_exn$1); if (exn$1.RE_EXN_ID === "Not_found") { add2 = { hd: [ diff --git a/jscomp/test/test_set.js b/jscomp/test/test_set.js index aea136d5da..d4a639a61f 100644 --- a/jscomp/test/test_set.js +++ b/jscomp/test/test_set.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); +let Belt_List = require("../../lib/js/belt_List.js"); function Make(Ord) { let height = x => { @@ -672,7 +672,7 @@ function Make(Ord) { Error: new Error() }; }; - return sub(List.length(l), l)[0]; + return sub(Belt_List.length(l), l)[0]; }; let of_list = l => { if (!l) { @@ -697,7 +697,7 @@ function Make(Ord) { let x3 = match$2.hd; if (match$3) { if (match$3.tl) { - return of_sorted_list(List.sort_uniq(Ord.compare, l)); + return of_sorted_list(Belt_List.sort(l, Ord.compare)); } else { return add(match$3.hd, add(x3, add(x2, add(x1, singleton(x0))))); } diff --git a/jscomp/test/test_set.res b/jscomp/test/test_set.res index 5d95e32f64..1abeb01034 100644 --- a/jscomp/test/test_set.res +++ b/jscomp/test/test_set.res @@ -501,7 +501,7 @@ module Make = (Ord: OrderedType) => { } } - fst(sub(List.length(l), l)) + fst(sub(Belt.List.length(l), l)) } let of_list = l => @@ -512,7 +512,7 @@ module Make = (Ord: OrderedType) => { | list{x0, x1, x2} => add(x2, add(x1, singleton(x0))) | list{x0, x1, x2, x3} => add(x3, add(x2, add(x1, singleton(x0)))) | list{x0, x1, x2, x3, x4} => add(x4, add(x3, add(x2, add(x1, singleton(x0))))) - | _ => of_sorted_list(List.sort_uniq(Ord.compare, l)) + | _ => of_sorted_list(l->Belt.List.sort(Ord.compare)) } } module N = { diff --git a/jscomp/test/test_side_effect_functor.js b/jscomp/test/test_side_effect_functor.js index 360f364740..1d0ada6b4a 100644 --- a/jscomp/test/test_side_effect_functor.js +++ b/jscomp/test/test_side_effect_functor.js @@ -6,7 +6,7 @@ let v = 0; v = v + 1 | 0; -console.log(String(v)); +console.log(v.toString()); function unuse_v() { return 35; diff --git a/jscomp/test/test_side_effect_functor.res b/jscomp/test/test_side_effect_functor.res index a8a57dfc83..f078b61346 100644 --- a/jscomp/test/test_side_effect_functor.res +++ b/jscomp/test/test_side_effect_functor.res @@ -4,7 +4,7 @@ include ( let v = ref(0) { incr(v) - print_endline(string_of_int(v.contents)) + v.contents->Js.Int.toString->Js.log } let u = 3 let use_v = () => v.contents diff --git a/jscomp/test/test_simple_include.js b/jscomp/test/test_simple_include.js index 01e2f84d75..2d55cc0b51 100644 --- a/jscomp/test/test_simple_include.js +++ b/jscomp/test/test_simple_include.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let $$Array = require("../../lib/js/array.js"); +let Belt_Array = require("../../lib/js/belt_Array.js"); let v = { contents: 32 @@ -23,92 +23,224 @@ let NN = { v: v$1 }; -let make_float = $$Array.make_float; +let get = Belt_Array.get; -let init = $$Array.init; +let getExn = Belt_Array.getExn; -let make_matrix = $$Array.make_matrix; +let set = Belt_Array.set; -let create_matrix = $$Array.create_matrix; +let setExn = Belt_Array.setExn; -let append = $$Array.append; +let shuffleInPlace = Belt_Array.shuffleInPlace; -let concat = $$Array.concat; +let shuffle = Belt_Array.shuffle; -let sub = $$Array.sub; +let reverseInPlace = Belt_Array.reverseInPlace; -let copy = $$Array.copy; +let reverse = Belt_Array.reverse; -let fill = $$Array.fill; +let make = Belt_Array.make; -let blit = $$Array.blit; +let range = Belt_Array.range; -let to_list = $$Array.to_list; +let rangeBy = Belt_Array.rangeBy; -let of_list = $$Array.of_list; +let makeByU = Belt_Array.makeByU; -let iter = $$Array.iter; +let makeBy = Belt_Array.makeBy; -let iteri = $$Array.iteri; +let makeByAndShuffleU = Belt_Array.makeByAndShuffleU; -let map = $$Array.map; +let makeByAndShuffle = Belt_Array.makeByAndShuffle; -let mapi = $$Array.mapi; +let zip = Belt_Array.zip; -let fold_left = $$Array.fold_left; +let zipByU = Belt_Array.zipByU; -let fold_right = $$Array.fold_right; +let zipBy = Belt_Array.zipBy; -let iter2 = $$Array.iter2; +let unzip = Belt_Array.unzip; -let map2 = $$Array.map2; +let concat = Belt_Array.concat; -let for_all = $$Array.for_all; +let concatMany = Belt_Array.concatMany; -let exists = $$Array.exists; +let slice = Belt_Array.slice; -let mem = $$Array.mem; +let sliceToEnd = Belt_Array.sliceToEnd; -let memq = $$Array.memq; +let fill = Belt_Array.fill; -let sort = $$Array.sort; +let blit = Belt_Array.blit; -let stable_sort = $$Array.stable_sort; +let blitUnsafe = Belt_Array.blitUnsafe; -let fast_sort = $$Array.fast_sort; +let forEachU = Belt_Array.forEachU; -let Floatarray = $$Array.Floatarray; +let forEach = Belt_Array.forEach; + +let mapU = Belt_Array.mapU; + +let map = Belt_Array.map; + +let flatMapU = Belt_Array.flatMapU; + +let flatMap = Belt_Array.flatMap; + +let getByU = Belt_Array.getByU; + +let getBy = Belt_Array.getBy; + +let getIndexByU = Belt_Array.getIndexByU; + +let getIndexBy = Belt_Array.getIndexBy; + +let keepU = Belt_Array.keepU; + +let keep = Belt_Array.keep; + +let keepWithIndexU = Belt_Array.keepWithIndexU; + +let keepWithIndex = Belt_Array.keepWithIndex; + +let keepMapU = Belt_Array.keepMapU; + +let keepMap = Belt_Array.keepMap; + +let forEachWithIndexU = Belt_Array.forEachWithIndexU; + +let forEachWithIndex = Belt_Array.forEachWithIndex; + +let mapWithIndexU = Belt_Array.mapWithIndexU; + +let mapWithIndex = Belt_Array.mapWithIndex; + +let partitionU = Belt_Array.partitionU; + +let partition = Belt_Array.partition; + +let reduceU = Belt_Array.reduceU; + +let reduce = Belt_Array.reduce; + +let reduceReverseU = Belt_Array.reduceReverseU; + +let reduceReverse = Belt_Array.reduceReverse; + +let reduceReverse2U = Belt_Array.reduceReverse2U; + +let reduceReverse2 = Belt_Array.reduceReverse2; + +let reduceWithIndexU = Belt_Array.reduceWithIndexU; + +let reduceWithIndex = Belt_Array.reduceWithIndex; + +let joinWithU = Belt_Array.joinWithU; + +let joinWith = Belt_Array.joinWith; + +let someU = Belt_Array.someU; + +let some = Belt_Array.some; + +let everyU = Belt_Array.everyU; + +let every = Belt_Array.every; + +let every2U = Belt_Array.every2U; + +let every2 = Belt_Array.every2; + +let some2U = Belt_Array.some2U; + +let some2 = Belt_Array.some2; + +let cmpU = Belt_Array.cmpU; + +let cmp = Belt_Array.cmp; + +let eqU = Belt_Array.eqU; + +let eq = Belt_Array.eq; + +let initU = Belt_Array.initU; + +let init = Belt_Array.init; let a = 3; -exports.make_float = make_float; -exports.init = init; -exports.make_matrix = make_matrix; -exports.create_matrix = create_matrix; -exports.append = append; +exports.get = get; +exports.getExn = getExn; +exports.set = set; +exports.setExn = setExn; +exports.shuffleInPlace = shuffleInPlace; +exports.shuffle = shuffle; +exports.reverseInPlace = reverseInPlace; +exports.reverse = reverse; +exports.make = make; +exports.range = range; +exports.rangeBy = rangeBy; +exports.makeByU = makeByU; +exports.makeBy = makeBy; +exports.makeByAndShuffleU = makeByAndShuffleU; +exports.makeByAndShuffle = makeByAndShuffle; +exports.zip = zip; +exports.zipByU = zipByU; +exports.zipBy = zipBy; +exports.unzip = unzip; exports.concat = concat; -exports.sub = sub; -exports.copy = copy; +exports.concatMany = concatMany; +exports.slice = slice; +exports.sliceToEnd = sliceToEnd; exports.fill = fill; exports.blit = blit; -exports.to_list = to_list; -exports.of_list = of_list; -exports.iter = iter; -exports.iteri = iteri; +exports.blitUnsafe = blitUnsafe; +exports.forEachU = forEachU; +exports.forEach = forEach; +exports.mapU = mapU; exports.map = map; -exports.mapi = mapi; -exports.fold_left = fold_left; -exports.fold_right = fold_right; -exports.iter2 = iter2; -exports.map2 = map2; -exports.for_all = for_all; -exports.exists = exists; -exports.mem = mem; -exports.memq = memq; -exports.sort = sort; -exports.stable_sort = stable_sort; -exports.fast_sort = fast_sort; -exports.Floatarray = Floatarray; +exports.flatMapU = flatMapU; +exports.flatMap = flatMap; +exports.getByU = getByU; +exports.getBy = getBy; +exports.getIndexByU = getIndexByU; +exports.getIndexBy = getIndexBy; +exports.keepU = keepU; +exports.keep = keep; +exports.keepWithIndexU = keepWithIndexU; +exports.keepWithIndex = keepWithIndex; +exports.keepMapU = keepMapU; +exports.keepMap = keepMap; +exports.forEachWithIndexU = forEachWithIndexU; +exports.forEachWithIndex = forEachWithIndex; +exports.mapWithIndexU = mapWithIndexU; +exports.mapWithIndex = mapWithIndex; +exports.partitionU = partitionU; +exports.partition = partition; +exports.reduceU = reduceU; +exports.reduce = reduce; +exports.reduceReverseU = reduceReverseU; +exports.reduceReverse = reduceReverse; +exports.reduceReverse2U = reduceReverse2U; +exports.reduceReverse2 = reduceReverse2; +exports.reduceWithIndexU = reduceWithIndexU; +exports.reduceWithIndex = reduceWithIndex; +exports.joinWithU = joinWithU; +exports.joinWith = joinWith; +exports.someU = someU; +exports.some = some; +exports.everyU = everyU; +exports.every = every; +exports.every2U = every2U; +exports.every2 = every2; +exports.some2U = some2U; +exports.some2 = some2; +exports.cmpU = cmpU; +exports.cmp = cmp; +exports.eqU = eqU; +exports.eq = eq; +exports.initU = initU; +exports.init = init; exports.N = N; exports.NN = NN; exports.a = a; diff --git a/jscomp/test/test_simple_include.res b/jscomp/test/test_simple_include.res index d6325f0063..6586d3401d 100644 --- a/jscomp/test/test_simple_include.res +++ b/jscomp/test/test_simple_include.res @@ -1,4 +1,4 @@ -include Array +include Belt.Array include { assert(1 + 2 == 3) diff --git a/jscomp/test/test_simple_pattern_match.js b/jscomp/test/test_simple_pattern_match.js index 9b64d32f86..154ec50b37 100644 --- a/jscomp/test/test_simple_pattern_match.js +++ b/jscomp/test/test_simple_pattern_match.js @@ -1,28 +1,30 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Sys = require("../../lib/js/sys.js"); +let Nodeos = require("node:os"); -let match; +let match = Nodeos.platform(); -switch (Sys.os_type) { - case "Cygwin" : - case "Unix" : - match = [ +let match$1; + +switch (match) { + case "darwin" : + case "linux" : + match$1 = [ 1, 2 ]; break; default: - match = [ + match$1 = [ 3, 4 ]; } -let a = match[0]; +let a = match$1[0]; -let b = match[1]; +let b = match$1[1]; exports.a = a; exports.b = b; diff --git a/jscomp/test/test_simple_pattern_match.res b/jscomp/test/test_simple_pattern_match.res index ef35367a7d..7c2e83baed 100644 --- a/jscomp/test/test_simple_pattern_match.res +++ b/jscomp/test/test_simple_pattern_match.res @@ -1,5 +1,7 @@ -let (a, b) = switch Sys.os_type { -| "Unix" -| "Cygwin" => (1, 2) +@module("node:os") +external platform: unit => string = "platform" + +let (a, b) = switch platform() { +| "linux" | "darwin" => (1, 2) | _ => (3, 4) } diff --git a/jscomp/test/test_stack.js b/jscomp/test/test_stack.js deleted file mode 100644 index 4c31d7845d..0000000000 --- a/jscomp/test/test_stack.js +++ /dev/null @@ -1,10 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - - -function v(x) { - return x.c === /* [] */0; -} - -exports.v = v; -/* No side effect */ diff --git a/jscomp/test/test_stack.res b/jscomp/test/test_stack.res deleted file mode 100644 index 7e2db0e097..0000000000 --- a/jscomp/test/test_stack.res +++ /dev/null @@ -1 +0,0 @@ -let v = x => Stack.is_empty(x) diff --git a/jscomp/test/test_static_catch_ident.js b/jscomp/test/test_static_catch_ident.js index 71f35bcd64..ae2fa5d87e 100644 --- a/jscomp/test/test_static_catch_ident.js +++ b/jscomp/test/test_static_catch_ident.js @@ -1,9 +1,9 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); -let Scan_failure = /* @__PURE__ */Caml_exceptions.create("Test_static_catch_ident.Scan_failure"); +let Scan_failure = /* @__PURE__ */Primitive_exceptions.create("Test_static_catch_ident.Scan_failure"); function scanf_bad_input(ib, x) { let s; diff --git a/jscomp/test/test_static_catch_ident.res b/jscomp/test/test_static_catch_ident.res index be492811a6..b893cb1ee4 100644 --- a/jscomp/test/test_static_catch_ident.res +++ b/jscomp/test/test_static_catch_ident.res @@ -4,8 +4,8 @@ let scanf_bad_input = (ib, x) => switch x { | Scan_failure(s) | Failure(s) => for i in 0 to 100 { - print_endline(s) /* necessary */ - print_endline("don't inlinie") + Js.log(s) /* necessary */ + Js.log("don't inlinie") } | x => raise(x) } diff --git a/jscomp/test/test_string.js b/jscomp/test/test_string.js index 22ba5db87b..a2db7217af 100644 --- a/jscomp/test/test_string.js +++ b/jscomp/test/test_string.js @@ -1,8 +1,6 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_bytes = require("../../lib/js/caml_bytes.js"); -let Caml_string = require("../../lib/js/caml_string.js"); function f(x) { switch (x) { @@ -37,12 +35,8 @@ function c(x, y) { let v = "xx".length; -function h(s, b) { - if (Caml_string.get(s, 0) === /* 'a' */97 && Caml_bytes.get(b, 0) === /* 'b' */98) { - return Caml_string.get(s, 1) === Caml_bytes.get(b, 2); - } else { - return false; - } +function h(s) { + return s.codePointAt(0) === /* 'a' */97; } exports.f = f; diff --git a/jscomp/test/test_string.res b/jscomp/test/test_string.res index bf06d03e99..c458f95f00 100644 --- a/jscomp/test/test_string.res +++ b/jscomp/test/test_string.res @@ -13,5 +13,4 @@ let c = (x, y) => x ++ "hello" ++ ("hi" ++ ("u" ++ ("hi" ++ y))) let v = String.length("xx") -let h = (s: string, b: bytes) => - String.get(s, 0) == 'a' && (Bytes.get(b, 0) == 'b' && String.get(s, 1) == Bytes.get(b, 2)) +let h = (s: string) => String.get(s, 0) == 'a' diff --git a/jscomp/test/test_string_const.js b/jscomp/test/test_string_const.js index 67c811f372..8af8e40e87 100644 --- a/jscomp/test/test_string_const.js +++ b/jscomp/test/test_string_const.js @@ -1,17 +1,16 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_string = require("../../lib/js/caml_string.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); -let f = Caml_string.get("ghsogh", 3); +let f = "ghsogh".codePointAt(3); let hh; try { - hh = Caml_string.get("ghsogh", -3); + hh = "ghsogh".codePointAt(-3); } catch (raw_e) { - let e = Caml_js_exceptions.internalToOCamlException(raw_e); + let e = Primitive_exceptions.internalToException(raw_e); if (e.RE_EXN_ID === "Invalid_argument") { console.log(e._1); hh = /* 'a' */97; @@ -22,4 +21,4 @@ try { exports.f = f; exports.hh = hh; -/* hh Not a pure module */ +/* f Not a pure module */ diff --git a/jscomp/test/test_string_map.js b/jscomp/test/test_string_map.js index fa07819203..4c5940c39e 100644 --- a/jscomp/test/test_string_map.js +++ b/jscomp/test/test_string_map.js @@ -1,155 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml = require("../../lib/js/caml.js"); - -function height(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} - -function create(l, x, d, r) { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} - -function bal(l, x, d, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; -} - -function add(x, data, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml.string_compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function find(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let c = Caml.string_compare(x, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} +let Belt_MapString = require("../../lib/js/belt_MapString.js"); function timing(label, f) { console.time(label); @@ -159,16 +11,16 @@ function timing(label, f) { function assertion_test() { let m = { - contents: "Empty" + contents: undefined }; timing("building", () => { for (let i = 0; i <= 1000000; ++i) { - m.contents = add(String(i), String(i), m.contents); + m.contents = Belt_MapString.set(m.contents, i.toString(), i.toString()); } }); timing("querying", () => { for (let i = 0; i <= 1000000; ++i) { - find(String(i), m.contents); + Belt_MapString.get(m.contents, i.toString()); } }); } diff --git a/jscomp/test/test_string_map.res b/jscomp/test/test_string_map.res index bb2fa0566c..7bc1a0cb29 100644 --- a/jscomp/test/test_string_map.res +++ b/jscomp/test/test_string_map.res @@ -1,9 +1,6 @@ include ( { - module StringMap = Map.Make({ - type t = string - let compare = (x: string, y) => compare(x, y) - }) + module StringMap = Belt.Map.String @val("console.time") external time: string => unit = "" @val("console.timeEnd") external timeEnd: string => unit = "" @@ -18,12 +15,12 @@ include ( let count = 1000000 \"@@"(timing("building", ...), _ => for i in 0 to count { - m := StringMap.add(string_of_int(i), string_of_int(i), m.contents) + m := m.contents->StringMap.set(Js.Int.toString(i), Js.Int.toString(i)) } ) \"@@"(timing("querying", ...), _ => for i in 0 to count { - ignore(StringMap.find(string_of_int(i), m.contents)) + m.contents->StringMap.get(Js.Int.toString(i))->ignore } ) } diff --git a/jscomp/test/test_string_switch.js b/jscomp/test/test_string_switch.js index 0a8a542cb5..3f93840d85 100644 --- a/jscomp/test/test_string_switch.js +++ b/jscomp/test/test_string_switch.js @@ -1,20 +1,22 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Sys = require("../../lib/js/sys.js"); +let Nodeos = require("node:os"); -let os_version; +let match = Nodeos.platform(); -switch (Sys.os_type) { - case "Cygwin" : - os_version = 2; +let version; + +switch (match) { + case "darwin" : + version = 2; break; - case "Unix" : - os_version = 1; + case "linux" : + version = 1; break; default: - os_version = 3; + version = 3; } -exports.os_version = os_version; -/* os_version Not a pure module */ +exports.version = version; +/* match Not a pure module */ diff --git a/jscomp/test/test_string_switch.res b/jscomp/test/test_string_switch.res index 0f5147f32e..596d12e507 100644 --- a/jscomp/test/test_string_switch.res +++ b/jscomp/test/test_string_switch.res @@ -1,5 +1,8 @@ -let os_version = switch Sys.os_type { -| "Unix" => 1 -| "Cygwin" => 2 +@module("node:os") +external platform: unit => string = "platform" + +let version = switch platform() { +| "linux" => 1 +| "darwin" => 2 | _ => 3 } diff --git a/jscomp/test/test_trywith.js b/jscomp/test/test_trywith.js index bd5cd7321f..5852f1689b 100644 --- a/jscomp/test/test_trywith.js +++ b/jscomp/test/test_trywith.js @@ -1,22 +1,21 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); -let Out_of_memory = /* @__PURE__ */Caml_exceptions.create("Test_trywith.Out_of_memory"); +let Out_of_memory = /* @__PURE__ */Primitive_exceptions.create("Test_trywith.Out_of_memory"); -let Sys_error = /* @__PURE__ */Caml_exceptions.create("Test_trywith.Sys_error"); +let Sys_error = /* @__PURE__ */Primitive_exceptions.create("Test_trywith.Sys_error"); -let Stack_overflow = /* @__PURE__ */Caml_exceptions.create("Test_trywith.Stack_overflow"); +let Stack_overflow = /* @__PURE__ */Primitive_exceptions.create("Test_trywith.Stack_overflow"); -let Sys_blocked_io = /* @__PURE__ */Caml_exceptions.create("Test_trywith.Sys_blocked_io"); +let Sys_blocked_io = /* @__PURE__ */Primitive_exceptions.create("Test_trywith.Sys_blocked_io"); function ff(g, x) { try { g(x); } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + let exn = Primitive_exceptions.internalToException(raw_exn); if (exn.RE_EXN_ID !== "Not_found") { throw exn; } @@ -25,7 +24,7 @@ function ff(g, x) { try { g(x); } catch (raw_exn$1) { - let exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn$1); + let exn$1 = Primitive_exceptions.internalToException(raw_exn$1); if (exn$1.RE_EXN_ID !== Out_of_memory) { throw exn$1; } @@ -34,7 +33,7 @@ function ff(g, x) { try { g(x); } catch (raw_exn$2) { - let exn$2 = Caml_js_exceptions.internalToOCamlException(raw_exn$2); + let exn$2 = Primitive_exceptions.internalToException(raw_exn$2); if (exn$2.RE_EXN_ID !== Sys_error) { throw exn$2; } @@ -43,7 +42,7 @@ function ff(g, x) { try { g(x); } catch (raw_exn$3) { - let exn$3 = Caml_js_exceptions.internalToOCamlException(raw_exn$3); + let exn$3 = Primitive_exceptions.internalToException(raw_exn$3); if (exn$3.RE_EXN_ID !== "Invalid_argument") { throw exn$3; } @@ -52,7 +51,7 @@ function ff(g, x) { try { g(x); } catch (raw_exn$4) { - let exn$4 = Caml_js_exceptions.internalToOCamlException(raw_exn$4); + let exn$4 = Primitive_exceptions.internalToException(raw_exn$4); if (exn$4.RE_EXN_ID !== "End_of_file") { throw exn$4; } @@ -61,7 +60,7 @@ function ff(g, x) { try { g(x); } catch (raw_exn$5) { - let exn$5 = Caml_js_exceptions.internalToOCamlException(raw_exn$5); + let exn$5 = Primitive_exceptions.internalToException(raw_exn$5); if (exn$5.RE_EXN_ID !== "Match_failure") { throw exn$5; } @@ -70,7 +69,7 @@ function ff(g, x) { try { g(x); } catch (raw_exn$6) { - let exn$6 = Caml_js_exceptions.internalToOCamlException(raw_exn$6); + let exn$6 = Primitive_exceptions.internalToException(raw_exn$6); if (exn$6.RE_EXN_ID !== Stack_overflow) { throw exn$6; } @@ -79,7 +78,7 @@ function ff(g, x) { try { g(x); } catch (raw_exn$7) { - let exn$7 = Caml_js_exceptions.internalToOCamlException(raw_exn$7); + let exn$7 = Primitive_exceptions.internalToException(raw_exn$7); if (exn$7.RE_EXN_ID !== Sys_blocked_io) { throw exn$7; } @@ -88,7 +87,7 @@ function ff(g, x) { try { g(x); } catch (raw_exn$8) { - let exn$8 = Caml_js_exceptions.internalToOCamlException(raw_exn$8); + let exn$8 = Primitive_exceptions.internalToException(raw_exn$8); if (exn$8.RE_EXN_ID !== "Assert_failure") { throw exn$8; } @@ -97,7 +96,7 @@ function ff(g, x) { try { return g(x); } catch (raw_exn$9) { - let exn$9 = Caml_js_exceptions.internalToOCamlException(raw_exn$9); + let exn$9 = Primitive_exceptions.internalToException(raw_exn$9); if (exn$9.RE_EXN_ID === "Undefined_recursive_module") { return; } diff --git a/jscomp/test/test_unknown.js b/jscomp/test/test_unknown.js index f09b3e193f..5e00b25396 100644 --- a/jscomp/test/test_unknown.js +++ b/jscomp/test/test_unknown.js @@ -1,14 +1,14 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); function some(x) { - return Caml_option.some(x); + return Primitive_option.some(x); } function some2(x) { - return Caml_option.some(x); + return Primitive_option.some(x); } let h = [ diff --git a/jscomp/test/test_while_closure.js b/jscomp/test/test_while_closure.js index c225a30bbb..ab93ac201e 100644 --- a/jscomp/test/test_while_closure.js +++ b/jscomp/test/test_while_closure.js @@ -1,20 +1,20 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let $$Array = require("../../lib/js/array.js"); -let Caml_array = require("../../lib/js/caml_array.js"); +let Belt_Array = require("../../lib/js/belt_Array.js"); +let Primitive_array = require("../../lib/js/primitive_array.js"); let v = { contents: 0 }; -let arr = Caml_array.make(10, () => {}); +let arr = Belt_Array.make(10, () => {}); function f() { let n = 0; while (n < 10) { let j = n; - Caml_array.set(arr, j, () => { + Primitive_array.set(arr, j, () => { v.contents = v.contents + j | 0; }); n = n + 1 | 0; @@ -23,9 +23,9 @@ function f() { f(); -$$Array.iter(x => x(), arr); +Belt_Array.forEach(arr, x => x()); -console.log(String(v.contents)); +console.log(v.contents.toString()); if (v.contents !== 45) { throw { @@ -45,4 +45,4 @@ exports.v = v; exports.count = count; exports.arr = arr; exports.f = f; -/* Not a pure module */ +/* arr Not a pure module */ diff --git a/jscomp/test/test_while_closure.res b/jscomp/test/test_while_closure.res index 204220c713..58fa9ad580 100644 --- a/jscomp/test/test_while_closure.res +++ b/jscomp/test/test_while_closure.res @@ -38,7 +38,7 @@ This means inline is tricky in javascript, here we try to inline [_loop]? let v = ref(0) let count = 10 -let arr = Array.make(count, _ => ()) +let arr = Belt.Array.make(count, _ => ()) let f = () => { let n = ref(0) while n.contents < count { @@ -50,7 +50,7 @@ let f = () => { let () = { f() - Array.iter(x => x(), arr) - print_endline(string_of_int(v.contents)) + arr->Belt.Array.forEach(x => x()) + v.contents->Js.Int.toString->Js.log assert(v.contents == 45) } diff --git a/jscomp/test/test_while_side_effect.js b/jscomp/test/test_while_side_effect.js index abea782887..c9f6b1d952 100644 --- a/jscomp/test/test_while_side_effect.js +++ b/jscomp/test/test_while_side_effect.js @@ -6,7 +6,7 @@ let v = { contents: 0 }; -while (console.log(String(v.contents)), v.contents = v.contents + 1 | 0, v.contents < 10) { +while (console.log(v.contents.toString()), v.contents = v.contents + 1 | 0, v.contents < 10) { }; @@ -24,12 +24,12 @@ let x = { while ((() => { let y = 3; - console.log(String(x.contents)); + console.log(x.contents.toString()); y = y + 1 | 0; x.contents = x.contents + 1 | 0; return (fib(x.contents) + fib(x.contents) | 0) < 20; })()) { - console.log(String(3)); + console.log((3).toString()); }; exports.v = v; diff --git a/jscomp/test/test_while_side_effect.res b/jscomp/test/test_while_side_effect.res index a1a17016e9..dbc49c3c66 100644 --- a/jscomp/test/test_while_side_effect.res +++ b/jscomp/test/test_while_side_effect.res @@ -1,7 +1,7 @@ let v = ref(0) while { - print_endline(string_of_int(v.contents)) + v.contents->Js.Int.toString->Js.log incr(v) v.contents < 10 } { @@ -17,10 +17,10 @@ let x = ref(3) while { let y = ref(3) - print_endline(string_of_int(x.contents)) + x.contents->Js.Int.toString->Js.log incr(y) incr(x) fib(x.contents) + fib(x.contents) < 20 } { - print_endline(string_of_int(3)) + 3->Js.Int.toString->Js.log } diff --git a/jscomp/test/test_zero_nullable.js b/jscomp/test/test_zero_nullable.js index cdb2f1b2a5..4d085e25fc 100644 --- a/jscomp/test/test_zero_nullable.js +++ b/jscomp/test/test_zero_nullable.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); let suites = { contents: /* [] */0 @@ -16,7 +16,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -88,7 +88,7 @@ function f9(x) { if (x === null) { return; } else { - return Caml_option.some(x); + return Primitive_option.some(x); } } @@ -173,7 +173,7 @@ function f9$1(x) { if (x === undefined) { return; } else { - return Caml_option.some(x); + return Primitive_option.some(x); } } @@ -256,7 +256,7 @@ function f9$2(x) { if (x == null) { return; } else { - return Caml_option.some(x); + return Primitive_option.some(x); } } @@ -280,19 +280,19 @@ let Test_null_def = { f11: f11$2 }; -eq("File \"test_zero_nullable.res\", line 244, characters 5-12", f1$2(0), 1); +eq("File \"test_zero_nullable.res\", line 247, characters 5-12", f1$2(0), 1); -eq("File \"test_zero_nullable.res\", line 245, characters 5-12", f1$2(null), 3); +eq("File \"test_zero_nullable.res\", line 248, characters 5-12", f1$2(null), 3); -eq("File \"test_zero_nullable.res\", line 246, characters 5-12", f1$2(undefined), 3); +eq("File \"test_zero_nullable.res\", line 249, characters 5-12", f1$2(undefined), 3); -eq("File \"test_zero_nullable.res\", line 248, characters 5-12", f1(0), 1); +eq("File \"test_zero_nullable.res\", line 251, characters 5-12", f1(0), 1); -eq("File \"test_zero_nullable.res\", line 249, characters 5-12", f1(null), 3); +eq("File \"test_zero_nullable.res\", line 252, characters 5-12", f1(null), 3); -eq("File \"test_zero_nullable.res\", line 251, characters 5-12", f1$1(0), 1); +eq("File \"test_zero_nullable.res\", line 254, characters 5-12", f1$1(0), 1); -eq("File \"test_zero_nullable.res\", line 252, characters 5-12", f1$1(undefined), 3); +eq("File \"test_zero_nullable.res\", line 255, characters 5-12", f1$1(undefined), 3); Mt.from_pair_suites("Test_zero_nullable", suites.contents); diff --git a/jscomp/test/test_zero_nullable.res b/jscomp/test/test_zero_nullable.res index d181becf2f..8bf0ceeb48 100644 --- a/jscomp/test/test_zero_nullable.res +++ b/jscomp/test/test_zero_nullable.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } module Test_null = { diff --git a/jscomp/test/ticker.js b/jscomp/test/ticker.js index 35dd8d70b9..d641bd46aa 100644 --- a/jscomp/test/ticker.js +++ b/jscomp/test/ticker.js @@ -1,14 +1,13 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml = require("../../lib/js/caml.js"); -let List = require("../../lib/js/list.js"); -let $$String = require("../../lib/js/string.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); +let Belt_List = require("../../lib/js/belt_List.js"); +let Belt_Float = require("../../lib/js/belt_Float.js"); let Pervasives = require("../../lib/js/pervasives.js"); -let Caml_format = require("../../lib/js/caml_format.js"); -let Caml_option = require("../../lib/js/caml_option.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); +let Belt_Option = require("../../lib/js/belt_Option.js"); +let Primitive_int = require("../../lib/js/primitive_int.js"); +let Belt_MapString = require("../../lib/js/belt_MapString.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); function split(delim, s) { let len = s.length; @@ -21,20 +20,14 @@ function split(delim, s) { if (x === 0) { return l; } - let i$p; - try { - i$p = $$String.rindex_from(s, x - 1 | 0, delim); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - return { - hd: $$String.sub(s, 0, x), - tl: l - }; - } - throw exn; + let i$p = s.lastIndexOf(delim, x - 1 | 0); + if (i$p === -1) { + return { + hd: s.substr(0, x), + tl: l + }; } - let l_0 = $$String.sub(s, i$p + 1 | 0, (x - i$p | 0) - 1 | 0); + let l_0 = s.substr(i$p + 1 | 0, (x - i$p | 0) - 1 | 0); let l$1 = { hd: l_0, tl: l @@ -54,7 +47,7 @@ function split(delim, s) { function string_of_float_option(x) { if (x !== undefined) { - return Pervasives.string_of_float(x); + return x.toString(); } else { return "nan"; } @@ -78,1004 +71,21 @@ function string_of_rank(x) { } function find_ticker_by_name(all_tickers, ticker) { - return List.find(param => param.ticker_name === ticker, all_tickers); + return Belt_Option.getExn(Belt_List.getBy(all_tickers, param => param.ticker_name === ticker)); } function print_all_composite(all_tickers) { - List.iter(x => { + Belt_List.forEach(all_tickers, x => { let tmp = x.type_; if (typeof tmp !== "object") { return; } console.log(x.ticker_name); - }, all_tickers); -} - -function height(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} - -function create(l, x, d, r) { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} - -function singleton(x, d) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: d, - r: "Empty", - h: 1 - }; -} - -function bal(l, x, d, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; -} - -function is_empty(param) { - if (typeof param !== "object") { - return true; - } else { - return false; - } -} - -function add(x, data, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml_obj.compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function find(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let c = Caml_obj.compare(x, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function find_first(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_first_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_last(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_last_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_opt(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let c = Caml_obj.compare(x, param.v); - if (c === 0) { - return Caml_option.some(param.d); - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function mem(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = Caml_obj.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function min_binding(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; -} - -function min_binding_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; -} - -function max_binding(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; -} - -function max_binding_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; + }); } -function remove_min_binding(param) { - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.remove_min_elt", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_binding(l), param.v, param.d, param.r); - } -} - -function merge(t1, t2) { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return bal(t1, match[0], match[1], remove_min_binding(t2)); -} - -function remove(x, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml_obj.compare(x, v); - if (c === 0) { - return merge(l, r); - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function update(x, f, param) { - if (typeof param !== "object") { - let data = f(undefined); - if (data !== undefined) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: Caml_option.valFromOption(data), - r: "Empty", - h: 1 - }; - } else { - return "Empty"; - } - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml_obj.compare(x, v); - if (c === 0) { - let data$1 = f(Caml_option.some(d)); - if (data$1 === undefined) { - return merge(l, r); - } - let data$2 = Caml_option.valFromOption(data$1); - if (d === data$2) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data$2, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = update(x, f, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = update(x, f, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } -} - -function iter(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v, param.d); - _param = param.r; - continue; - }; -} - -function map(f, param) { - if (typeof param !== "object") { - return "Empty"; - } - let l$p = map(f, param.l); - let d$p = f(param.d); - let r$p = map(f, param.r); - return { - TAG: "Node", - l: l$p, - v: param.v, - d: d$p, - r: r$p, - h: param.h - }; -} - -function mapi(f, param) { - if (typeof param !== "object") { - return "Empty"; - } - let v = param.v; - let l$p = mapi(f, param.l); - let d$p = f(v, param.d); - let r$p = mapi(f, param.r); - return { - TAG: "Node", - l: l$p, - v: v, - d: d$p, - r: r$p, - h: param.h - }; -} - -function fold(f, _m, _accu) { - while (true) { - let accu = _accu; - let m = _m; - if (typeof m !== "object") { - return accu; - } - _accu = f(m.v, m.d, fold(f, m.l, accu)); - _m = m.r; - continue; - }; -} - -function for_all(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v, param.d)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; -} - -function exists(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v, param.d)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; -} - -function add_min_binding(k, x, param) { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(add_min_binding(k, x, param.l), param.v, param.d, param.r); - } -} - -function add_max_binding(k, x, param) { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(param.l, param.v, param.d, add_max_binding(k, x, param.r)); - } -} - -function join(l, v, d, r) { - if (typeof l !== "object") { - return add_min_binding(v, d, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_binding(v, d, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, l.d, join(l.r, v, d, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, d, r.l), r.v, r.d, r.r); - } else { - return create(l, v, d, r); - } -} - -function concat(t1, t2) { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return join(t1, match[0], match[1], remove_min_binding(t2)); -} - -function concat_or_join(t1, v, d, t2) { - if (d !== undefined) { - return join(t1, v, Caml_option.valFromOption(d), t2); - } else { - return concat(t1, t2); - } -} - -function split$1(x, param) { - if (typeof param !== "object") { - return [ - "Empty", - undefined, - "Empty" - ]; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Caml_obj.compare(x, v); - if (c === 0) { - return [ - l, - Caml_option.some(d), - r - ]; - } - if (c < 0) { - let match = split$1(x, l); - return [ - match[0], - match[1], - join(match[2], v, d, r) - ]; - } - let match$1 = split$1(x, r); - return [ - join(l, v, d, match$1[0]), - match$1[1], - match$1[2] - ]; -} - -function merge$1(f, s1, s2) { - if (typeof s1 !== "object") { - if (typeof s2 !== "object") { - return "Empty"; - } - - } else { - let v1 = s1.v; - if (s1.h >= height(s2)) { - let match = split$1(v1, s2); - return concat_or_join(merge$1(f, s1.l, match[0]), v1, f(v1, Caml_option.some(s1.d), match[1]), merge$1(f, s1.r, match[2])); - } - - } - if (typeof s2 !== "object") { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "map.res", - 552, - 11 - ], - Error: new Error() - }; - } - let v2 = s2.v; - let match$1 = split$1(v2, s1); - return concat_or_join(merge$1(f, match$1[0], s2.l), v2, f(v2, match$1[1], Caml_option.some(s2.d)), merge$1(f, match$1[2], s2.r)); -} - -function union(f, s1, s2) { - if (typeof s1 !== "object") { - return s2; - } - let d1 = s1.d; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let d2 = s2.d; - let v2 = s2.v; - if (s1.h >= s2.h) { - let match = split$1(v1, s2); - let d2$1 = match[1]; - let l = union(f, s1.l, match[0]); - let r = union(f, s1.r, match[2]); - if (d2$1 !== undefined) { - return concat_or_join(l, v1, f(v1, d1, Caml_option.valFromOption(d2$1)), r); - } else { - return join(l, v1, d1, r); - } - } - let match$1 = split$1(v2, s1); - let d1$1 = match$1[1]; - let l$1 = union(f, match$1[0], s2.l); - let r$1 = union(f, match$1[2], s2.r); - if (d1$1 !== undefined) { - return concat_or_join(l$1, v2, f(v2, Caml_option.valFromOption(d1$1), d2), r$1); - } else { - return join(l$1, v2, d2, r$1); - } -} - -function filter(p, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pvd = p(v, d); - let r$p = filter(p, r); - if (pvd) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, d, r$p); - } - } else { - return concat(l$p, r$p); - } -} - -function partition(p, param) { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let d = param.d; - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pvd = p(v, d); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pvd) { - return [ - join(lt, v, d, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, d, rf) - ]; - } -} - -function cons_enum(_m, _e) { - while (true) { - let e = _e; - let m = _m; - if (typeof m !== "object") { - return e; - } - _e = { - TAG: "More", - _0: m.v, - _1: m.d, - _2: m.r, - _3: e - }; - _m = m.l; - continue; - }; -} - -function compare(cmp, m1, m2) { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = Caml_obj.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - let c$1 = cmp(e1._1, e2._1); - if (c$1 !== 0) { - return c$1; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; -} - -function equal(cmp, m1, m2) { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return true; - } else { - return false; - } - } - if (typeof e2 !== "object") { - return false; - } - if (!Caml_obj.equal(e1._0, e2._0)) { - return false; - } - if (!cmp(e1._1, e2._1)) { - return false; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; -} - -function cardinal(param) { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } -} - -function bindings_aux(_accu, _param) { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: [ - param.v, - param.d - ], - tl: bindings_aux(accu, param.r) - }; - continue; - }; -} - -function bindings(s) { - return bindings_aux(/* [] */0, s); -} - -let Ticker_map = { - empty: "Empty", - is_empty: is_empty, - mem: mem, - add: add, - update: update, - singleton: singleton, - remove: remove, - merge: merge$1, - union: union, - compare: compare, - equal: equal, - iter: iter, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - bindings: bindings, - min_binding: min_binding, - min_binding_opt: min_binding_opt, - max_binding: max_binding, - max_binding_opt: max_binding_opt, - choose: min_binding, - choose_opt: min_binding_opt, - split: split$1, - find: find, - find_opt: find_opt, - find_first: find_first, - find_first_opt: find_first_opt, - find_last: find_last, - find_last_opt: find_last_opt, - map: map, - mapi: mapi -}; - function compute_update_sequences(all_tickers) { - List.fold_left((counter, ticker) => { + Belt_List.reduceReverse(all_tickers, 0, (counter, ticker) => { let loop = (counter, ticker) => { let rank = ticker.rank; if (typeof rank === "object") { @@ -1105,14 +115,14 @@ function compute_update_sequences(all_tickers) { return counter$4; }; return loop(counter, ticker); - }, 0, all_tickers); - let map = List.fold_left((map, ticker) => { + }); + let map = Belt_List.reduceReverse(Belt_List.reverse(all_tickers), undefined, (map, ticker) => { let tmp = ticker.type_; if (typeof tmp !== "object") { - return add(ticker.ticker_name, { + return Belt_MapString.set(map, ticker.ticker_name, { hd: ticker, tl: /* [] */0 - }, map); + }); } let loop = (_up, _map, _ticker) => { while (true) { @@ -1122,8 +132,8 @@ function compute_update_sequences(all_tickers) { let type_ = ticker.type_; let ticker_name = ticker.ticker_name; if (typeof type_ !== "object") { - let l = find(ticker_name, map); - return add(ticker_name, Pervasives.$at(up, l), map); + let l = Belt_MapString.getExn(map, ticker_name); + return Belt_MapString.set(map, ticker_name, Pervasives.$at(up, l)); } let match = type_._0; let map$1 = loop({ @@ -1140,9 +150,9 @@ function compute_update_sequences(all_tickers) { }; }; return loop(/* [] */0, map, ticker); - }, "Empty", List.rev(all_tickers)); - return fold((k, l, map) => { - let l$1 = List.sort_uniq((lhs, rhs) => { + }); + return Belt_MapString.reduce(map, map, (map, k, l) => { + let l$1 = Belt_List.sort(l, (lhs, rhs) => { let x = lhs.rank; if (typeof x !== "object") { if (x === "Uninitialized") { @@ -1160,7 +170,7 @@ function compute_update_sequences(all_tickers) { } else { let y = rhs.rank; if (typeof y === "object") { - return Caml.int_compare(x._0, y._0); + return Primitive_int.compare(x._0, y._0); } if (y === "Uninitialized") { throw { @@ -1175,14 +185,14 @@ function compute_update_sequences(all_tickers) { Error: new Error() }; } - }, l); - return add(k, l$1, map); - }, map, map); + }); + return Belt_MapString.set(map, k, l$1); + }); } function process_quote(ticker_map, new_ticker, new_value) { - let update_sequence = find(new_ticker, ticker_map); - List.iter(ticker => { + let update_sequence = Belt_MapString.getExn(ticker_map, new_ticker); + Belt_List.forEach(update_sequence, ticker => { let match = ticker.type_; if (typeof match !== "object") { if (ticker.ticker_name === new_ticker) { @@ -1202,7 +212,7 @@ function process_quote(ticker_map, new_ticker, new_value) { match$1.op === "PLUS" ? match$2 + match$3 : match$2 - match$3 ) : undefined; ticker.value = value; - }, update_sequence); + }); } function process_input_line(ticker_map, all_tickers, line) { @@ -1223,7 +233,7 @@ function process_input_line(ticker_map, all_tickers, line) { } }; }; - let tokens = split(/* '|' */124, line); + let tokens = split("|", line); if (tokens) { switch (tokens.hd) { case "Q" : @@ -1238,12 +248,12 @@ function process_input_line(ticker_map, all_tickers, line) { Error: new Error() }; } - let ticker_map$1 = ticker_map !== undefined ? Caml_option.valFromOption(ticker_map) : compute_update_sequences(all_tickers); - let value = Caml_format.float_of_string(match$1.hd); + let ticker_map$1 = ticker_map !== undefined ? Primitive_option.valFromOption(ticker_map) : compute_update_sequences(all_tickers); + let value = Belt_Option.getExn(Belt_Float.fromString(match$1.hd)); process_quote(ticker_map$1, match.hd, value); return [ all_tickers, - Caml_option.some(ticker_map$1) + Primitive_option.some(ticker_map$1) ]; } throw { @@ -1397,6 +407,8 @@ function loop(_lines, _param) { }; } +let Ticker_map; + let lines = { hd: "R|MSFT|S", tl: { diff --git a/jscomp/test/ticker.res b/jscomp/test/ticker.res index e81690e5e8..8692cade82 100644 --- a/jscomp/test/ticker.res +++ b/jscomp/test/ticker.res @@ -1,3 +1,5 @@ +open Belt + /** General purpose utility functions */ module Util = { @@ -6,20 +8,20 @@ module Util = { switch x { | 0 => l | i => - switch String.rindex_from(s, i - 1, delim) { + switch Js.String2.lastIndexOfFrom(s, delim, i - 1) { + | -1 => list{Js.String2.substrAtMost(s, ~from=0, ~length=i), ...l} | i' => - let l = list{String.sub(s, i' + 1, i - i' - 1), ...l} + let l = list{Js.String2.substrAtMost(s, ~from=i' + 1, ~length=i - i' - 1), ...l} let l = if i' == 0 { list{"", ...l} } else { l } loop(l, i') - | exception Not_found => list{String.sub(s, 0, i), ...l} } } - let len = String.length(s) + let len = Js.String2.length(s) switch len { | 0 => list{} | _ => loop(list{}, len) @@ -28,7 +30,7 @@ module Util = { let string_of_float_option = x => switch x { - | Some(x) => string_of_float(x) + | Some(x) => Js.Float.toString(x) | None => "nan" } } @@ -69,23 +71,21 @@ let string_of_rank = x => } let find_ticker_by_name = (all_tickers, ticker) => - List.find(({ticker_name, _}) => ticker_name == ticker, all_tickers) + all_tickers->List.getBy(({ticker_name, _}) => ticker_name == ticker)->Option.getExn -let print_all_composite = all_tickers => List.iter(x => +let print_all_composite = all_tickers => + all_tickers->List.forEach(x => switch x { | {type_: Market, _} => () | {type_: Binary_op(_), ticker_name, value} => switch value { - | Some(v) => print_endline(ticker_name) - | None => print_endline(ticker_name) + | Some(v) => Js.log(ticker_name) + | None => Js.log(ticker_name) } } - , all_tickers) + ) -module Ticker_map = Map.Make({ - type t = string - let compare = Pervasives.compare -}) +module Ticker_map = Map.String /** For each market tickers, this function will compute the associated list of tickers value to be updated @@ -102,72 +102,77 @@ module Ticker_map = Map.Make({ let compute_update_sequences = all_tickers => { /* Ranking */ - \"@@"(ignore, List.fold_left((counter, ticker) => { - let rec loop = (counter, {rank, _} as ticker) => - switch rank { - | Ranked(_) => counter - | Visited => counter - | Uninitialized => - ticker.rank = Visited - switch ticker.type_ { - | Market => - let counter = counter + 1 - ticker.rank = Ranked(counter) - counter - | Binary_op({lhs, rhs, _}) => - let counter = loop(counter, lhs) - let counter = loop(counter, rhs) - let counter = counter + 1 - ticker.rank = Ranked(counter) - counter - } + all_tickers + ->List.reduceReverse(0, (counter, ticker) => { + let rec loop = (counter, {rank, _} as ticker) => + switch rank { + | Ranked(_) => counter + | Visited => counter + | Uninitialized => + ticker.rank = Visited + switch ticker.type_ { + | Market => + let counter = counter + 1 + ticker.rank = Ranked(counter) + counter + | Binary_op({lhs, rhs, _}) => + let counter = loop(counter, lhs) + let counter = loop(counter, rhs) + let counter = counter + 1 + ticker.rank = Ranked(counter) + counter } + } - loop(counter, ticker) - }, 0, all_tickers)) + loop(counter, ticker) + }) + ->ignore /* collect all dependencies of market tickers */ - let map = List.fold_left((map, {ticker_name, type_, _} as ticker) => - switch type_ { - | Market => Ticker_map.add(ticker_name, list{ticker}, map) - | _ => - let rec loop = (up, map, {ticker_name, type_} as ticker) => - switch type_ { - | Market => - let l = Ticker_map.find(ticker_name, map) - Ticker_map.add(ticker_name, \"@"(up, l), map) - | Binary_op({lhs, rhs, _}) => - let map = loop(list{ticker, ...up}, map, lhs) - loop(list{ticker, ...up}, map, rhs) - } + let map = + all_tickers + ->List.reverse + ->List.reduceReverse(Ticker_map.empty, (map, {ticker_name, type_, _} as ticker) => + switch type_ { + | Market => map->Ticker_map.set(ticker_name, list{ticker}) + | _ => + let rec loop = (up, map, {ticker_name, type_} as ticker) => + switch type_ { + | Market => + let l = map->Ticker_map.getExn(ticker_name) + map->Ticker_map.set(ticker_name, \"@"(up, l)) + | Binary_op({lhs, rhs, _}) => + let map = loop(list{ticker, ...up}, map, lhs) + loop(list{ticker, ...up}, map, rhs) + } - loop(list{}, map, ticker) - } - , Ticker_map.empty, List.rev(all_tickers)) + loop(list{}, map, ticker) + } + ) /* `List.rev is needed to process the node in the order they were processed TODO: this code should be more robust */ /* order dependencies based on rank */ - Ticker_map.fold((k, l, map) => { - let l = List.sort_uniq((lhs, rhs) => + map->Ticker_map.reduce(map, (map, k, l) => { + let l = l->List.sort((lhs, rhs) => switch (lhs, rhs) { | ({rank: Ranked(x)}, {rank: Ranked(y)}) => Pervasives.compare(x, y) | (_, _) => failwith("All nodes should be ranked") } - , l) - Ticker_map.add(k, l, map) - }, map, map) + ) + map->Ticker_map.set(k, l) + }) } /** Process a new quote for a market ticker */ let process_quote = (ticker_map, new_ticker, new_value) => { - let update_sequence = Ticker_map.find(new_ticker, ticker_map) + let update_sequence = ticker_map->Ticker_map.getExn(new_ticker) - List.iter(ticker => + update_sequence->List.forEach(ticker => switch ticker { | {type_: Market, ticker_name, _} if ticker_name == new_ticker => ticker.value = Some(new_value) @@ -187,7 +192,7 @@ let process_quote = (ticker_map, new_ticker, new_value) => { } ticker.value = value } - , update_sequence) + ) } let process_input_line = (ticker_map, all_tickers, line) => { @@ -202,7 +207,7 @@ let process_input_line = (ticker_map, all_tickers, line) => { } } - let tokens = Util.split(~delim='|', line) + let tokens = Util.split(~delim="|", line) let all_tickers = switch tokens { | list{"R", ticker_name, "S"} => ( @@ -222,7 +227,7 @@ let process_input_line = (ticker_map, all_tickers, line) => { | Some(ticker_map) => ticker_map | None => compute_update_sequences(all_tickers) } - let value = float_of_string(value) + let value = value->Float.fromString->Option.getExn process_quote(ticker_map, ticker_name, value) (all_tickers, Some(ticker_map)) | _ => failwith("Invalid input line") diff --git a/jscomp/test/to_string_test.js b/jscomp/test/to_string_test.js index 3d3f92b325..7108306618 100644 --- a/jscomp/test/to_string_test.js +++ b/jscomp/test/to_string_test.js @@ -4,28 +4,30 @@ let Mt = require("./mt.js"); let Pervasives = require("../../lib/js/pervasives.js"); -let ff = Pervasives.string_of_float; +function ff(v) { + return v.toString(); +} function f(v) { - return String(v); + return v.toString(); } Mt.from_pair_suites("To_string_test", { hd: [ - "File \"to_string_test.res\", line 6, characters 8-15", + "File \"to_string_test.res\", line 7, characters 5-12", () => ({ TAG: "Eq", - _0: Pervasives.string_of_float(Pervasives.infinity), - _1: "inf" + _0: Pervasives.infinity.toString(), + _1: "Infinity" }) ], tl: { hd: [ - "File \"to_string_test.res\", line 6, characters 49-56", + "File \"to_string_test.res\", line 8, characters 5-12", () => ({ TAG: "Eq", - _0: Pervasives.string_of_float(Pervasives.neg_infinity), - _1: "-inf" + _0: Pervasives.neg_infinity.toString(), + _1: "-Infinity" }) ], tl: /* [] */0 diff --git a/jscomp/test/to_string_test.res b/jscomp/test/to_string_test.res index 45b79dcd0d..1cf41bb309 100644 --- a/jscomp/test/to_string_test.res +++ b/jscomp/test/to_string_test.res @@ -1,7 +1,10 @@ -let ff = v => string_of_float(v) -let f = v => string_of_int(v) +let ff = v => Js.Float.toString(v) +let f = v => Js.Int.toString(v) Mt.from_pair_suites( __MODULE__, - list{(__LOC__, _ => Eq(ff(infinity), "inf")), (__LOC__, _ => Eq(ff(neg_infinity), "-inf"))}, + list{ + (__LOC__, _ => Eq(ff(infinity), "Infinity")), + (__LOC__, _ => Eq(ff(neg_infinity), "-Infinity")), + }, ) diff --git a/jscomp/test/topsort_test.js b/jscomp/test/topsort_test.js index 9288827d8b..569d103a25 100644 --- a/jscomp/test/topsort_test.js +++ b/jscomp/test/topsort_test.js @@ -1,14 +1,11 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml = require("../../lib/js/caml.js"); -let List = require("../../lib/js/list.js"); -let $$String = require("../../lib/js/string.js"); -let Caml_obj = require("../../lib/js/caml_obj.js"); +let Belt_List = require("../../lib/js/belt_List.js"); let Pervasives = require("../../lib/js/pervasives.js"); -let Caml_option = require("../../lib/js/caml_option.js"); -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); +let Belt_SetString = require("../../lib/js/belt_SetString.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); let graph = { hd: [ @@ -61,7 +58,7 @@ let graph = { }; function nexts(x, g) { - return List.fold_left((acc, param) => { + return Belt_List.reduce(g, /* [] */0, (acc, param) => { if (param[0] === x) { return { hd: param[1], @@ -70,7 +67,7 @@ function nexts(x, g) { } else { return acc; } - }, /* [] */0, g); + }); } function dfs1(_nodes, graph, _visited) { @@ -78,11 +75,11 @@ function dfs1(_nodes, graph, _visited) { let visited = _visited; let nodes = _nodes; if (!nodes) { - return List.rev(visited); + return Belt_List.reverse(visited); } let xs = nodes.tl; let x = nodes.hd; - if (List.mem(x, visited)) { + if (Belt_List.has(visited, x, (prim0, prim1) => prim0 === prim1)) { _nodes = xs; continue; } @@ -96,7 +93,7 @@ function dfs1(_nodes, graph, _visited) { }; } -if (!Caml_obj.equal(dfs1({ +if (!Primitive_object.equal(dfs1({ hd: "a", tl: /* [] */0 }, graph, /* [] */0), { @@ -125,16 +122,16 @@ if (!Caml_obj.equal(dfs1({ RE_EXN_ID: "Assert_failure", _1: [ "topsort_test.res", - 35, + 38, 2 ], Error: new Error() }; } -console.log(""); +console.log(); -if (!Caml_obj.equal(dfs1({ +if (!Primitive_object.equal(dfs1({ hd: "b", tl: /* [] */0 }, { @@ -163,7 +160,7 @@ if (!Caml_obj.equal(dfs1({ RE_EXN_ID: "Assert_failure", _1: [ "topsort_test.res", - 38, + 41, 2 ], Error: new Error() @@ -180,7 +177,7 @@ function dfs2(nodes, graph, visited) { } let xs = nodes.tl; let x = nodes.hd; - if (List.mem(x, visited)) { + if (Belt_List.has(visited, x, (prim0, prim1) => prim0 === prim1)) { _nodes = xs; continue; } @@ -192,10 +189,10 @@ function dfs2(nodes, graph, visited) { continue; }; }; - return List.rev(aux(nodes, graph, visited)); + return Belt_List.reverse(aux(nodes, graph, visited)); } -if (!Caml_obj.equal(dfs2({ +if (!Primitive_object.equal(dfs2({ hd: "a", tl: /* [] */0 }, graph, /* [] */0), { @@ -224,14 +221,14 @@ if (!Caml_obj.equal(dfs2({ RE_EXN_ID: "Assert_failure", _1: [ "topsort_test.res", - 57, + 60, 2 ], Error: new Error() }; } -if (!Caml_obj.equal(dfs2({ +if (!Primitive_object.equal(dfs2({ hd: "b", tl: /* [] */0 }, { @@ -260,7 +257,7 @@ if (!Caml_obj.equal(dfs2({ RE_EXN_ID: "Assert_failure", _1: [ "topsort_test.res", - 58, + 61, 2 ], Error: new Error() @@ -272,20 +269,20 @@ function dfs3(nodes, graph) { contents: /* [] */0 }; let aux = (node, graph) => { - if (!List.mem(node, visited.contents)) { + if (!Belt_List.has(visited.contents, node, (prim0, prim1) => prim0 === prim1)) { visited.contents = { hd: node, tl: visited.contents }; - return List.iter(x => aux(x, graph), nexts(node, graph)); + return Belt_List.forEach(nexts(node, graph), x => aux(x, graph)); } }; - List.iter(node => aux(node, graph), nodes); - return List.rev(visited.contents); + Belt_List.forEach(nodes, node => aux(node, graph)); + return Belt_List.reverse(visited.contents); } -if (!Caml_obj.equal(dfs3({ +if (!Primitive_object.equal(dfs3({ hd: "a", tl: /* [] */0 }, graph), { @@ -314,14 +311,14 @@ if (!Caml_obj.equal(dfs3({ RE_EXN_ID: "Assert_failure", _1: [ "topsort_test.res", - 74, + 77, 2 ], Error: new Error() }; } -if (!Caml_obj.equal(dfs3({ +if (!Primitive_object.equal(dfs3({ hd: "b", tl: /* [] */0 }, { @@ -350,7 +347,7 @@ if (!Caml_obj.equal(dfs3({ RE_EXN_ID: "Assert_failure", _1: [ "topsort_test.res", - 75, + 78, 2 ], Error: new Error() @@ -400,21 +397,21 @@ function unsafe_topsort(graph) { contents: /* [] */0 }; let sort_node = node => { - if (List.mem(node, visited.contents)) { + if (Belt_List.has(visited.contents, node, (prim0, prim1) => prim0 === prim1)) { return; } let nodes = nexts(node, graph); - List.iter(sort_node, nodes); + Belt_List.forEach(nodes, sort_node); visited.contents = { hd: node, tl: visited.contents }; }; - List.iter(param => sort_node(param[0]), graph); + Belt_List.forEach(graph, param => sort_node(param[0])); return visited.contents; } -if (!Caml_obj.equal(unsafe_topsort(grwork), { +if (!Primitive_object.equal(unsafe_topsort(grwork), { hd: "wake", tl: { hd: "shower", @@ -437,1023 +434,27 @@ if (!Caml_obj.equal(unsafe_topsort(grwork), { RE_EXN_ID: "Assert_failure", _1: [ "topsort_test.res", - 112, + 115, 9 ], Error: new Error() }; } -function height(param) { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } -} - -function create(l, v, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; -} - -function bal(l, v, r) { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - let lr = l.r; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, create(lr, v, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, lr.l), lr.v, create(lr.r, v, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - let rr = r.r; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, v, rl), rv, rr); - } - if (typeof rl === "object") { - return create(create(l, v, rl.l), rl.v, create(rl.r, rv, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; -} - -function add(x, param) { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = Caml.string_compare(x, v); - if (c === 0) { - return param; - } - if (c < 0) { - let ll = add(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = add(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } -} - -function singleton(x) { - return { - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }; -} - -function add_min_element(x, param) { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(add_min_element(x, param.l), param.v, param.r); - } -} - -function add_max_element(x, param) { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(param.l, param.v, add_max_element(x, param.r)); - } -} - -function join(l, v, r) { - if (typeof l !== "object") { - return add_min_element(v, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_element(v, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, join(l.r, v, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, r.l), r.v, r.r); - } else { - return create(l, v, r); - } -} - -function min_elt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.v; - } - _param = l; - continue; - }; -} - -function min_elt_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return Caml_option.some(param.v); - } - _param = l; - continue; - }; -} - -function max_elt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let r = param.r; - if (typeof r !== "object") { - return param.v; - } - _param = r; - continue; - }; -} - -function max_elt_opt(_param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return Caml_option.some(param.v); - } - _param = r; - continue; - }; -} - -function remove_min_elt(param) { - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.remove_min_elt", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_elt(l), param.v, param.r); - } -} - -function concat(t1, t2) { - if (typeof t1 !== "object") { - return t2; - } else if (typeof t2 !== "object") { - return t1; - } else { - return join(t1, min_elt(t2), remove_min_elt(t2)); - } -} - -function split(x, param) { - if (typeof param !== "object") { - return [ - "Empty", - false, - "Empty" - ]; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = Caml.string_compare(x, v); - if (c === 0) { - return [ - l, - true, - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, match$1[0]), - match$1[1], - match$1[2] - ]; -} - -function is_empty(param) { - if (typeof param !== "object") { - return true; - } else { - return false; - } -} - -function mem(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = Caml.string_compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function remove(x, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = Caml.string_compare(x, v); - if (c === 0) { - if (typeof l !== "object") { - return r; - } else if (typeof r !== "object") { - return l; - } else { - return bal(l, min_elt(r), remove_min_elt(r)); - } - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } -} - -function union(s1, s2) { - if (typeof s1 !== "object") { - return s2; - } - let h1 = s1.h; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let h2 = s2.h; - let v2 = s2.v; - if (h1 >= h2) { - if (h2 === 1) { - return add(v2, s1); - } - let match = split(v1, s2); - return join(union(s1.l, match[0]), v1, union(s1.r, match[2])); - } - if (h1 === 1) { - return add(v1, s2); - } - let match$1 = split(v2, s1); - return join(union(match$1[0], s2.l), v2, union(match$1[2], s2.r)); -} - -function inter(s1, s2) { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return "Empty"; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return join(inter(l1, l2), v1, inter(r1, match[2])); - } else { - return concat(inter(l1, l2), inter(r1, match[2])); - } -} - -function diff(s1, s2) { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return s1; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return concat(diff(l1, l2), diff(r1, match[2])); - } else { - return join(diff(l1, l2), v1, diff(r1, match[2])); - } -} - -function cons_enum(_s, _e) { - while (true) { - let e = _e; - let s = _s; - if (typeof s !== "object") { - return e; - } - _e = { - TAG: "More", - _0: s.v, - _1: s.r, - _2: e - }; - _s = s.l; - continue; - }; -} - -function compare(s1, s2) { - let _e1 = cons_enum(s1, "End"); - let _e2 = cons_enum(s2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = Caml.string_compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - _e2 = cons_enum(e2._1, e2._2); - _e1 = cons_enum(e1._1, e1._2); - continue; - }; -} - -function equal(s1, s2) { - return compare(s1, s2) === 0; -} - -function subset(_s1, _s2) { - while (true) { - let s2 = _s2; - let s1 = _s1; - if (typeof s1 !== "object") { - return true; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - if (typeof s2 !== "object") { - return false; - } - let r2 = s2.r; - let l2 = s2.l; - let c = Caml.string_compare(v1, s2.v); - if (c === 0) { - if (!subset(l1, l2)) { - return false; - } - _s2 = r2; - _s1 = r1; - continue; - } - if (c < 0) { - if (!subset({ - TAG: "Node", - l: l1, - v: v1, - r: "Empty", - h: 0 - }, l2)) { - return false; - } - _s1 = r1; - continue; - } - if (!subset({ - TAG: "Node", - l: "Empty", - v: v1, - r: r1, - h: 0 - }, r2)) { - return false; - } - _s1 = l1; - continue; - }; -} - -function iter(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v); - _param = param.r; - continue; - }; -} - -function fold(f, _s, _accu) { - while (true) { - let accu = _accu; - let s = _s; - if (typeof s !== "object") { - return accu; - } - _accu = f(s.v, fold(f, s.l, accu)); - _s = s.r; - continue; - }; -} - -function for_all(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; -} - -function exists(p, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; -} - -function filter(p, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pv = p(v); - let r$p = filter(p, r); - if (pv) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, r$p); - } - } else { - return concat(l$p, r$p); - } -} - -function partition(p, param) { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pv = p(v); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pv) { - return [ - join(lt, v, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, rf) - ]; - } -} - -function cardinal(param) { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } -} - -function elements_aux(_accu, _param) { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: param.v, - tl: elements_aux(accu, param.r) - }; - continue; - }; -} - -function elements(s) { - return elements_aux(/* [] */0, s); -} - -function find(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - let c = Caml.string_compare(x, v); - if (c === 0) { - return v; - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function find_first(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return v0; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_first_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return Caml_option.some(v0); - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; -} - -function find_last(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return v0; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_last_opt(f, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return Caml_option.some(v0); - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; -} - -function find_opt(x, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - let c = Caml.string_compare(x, v); - if (c === 0) { - return Caml_option.some(v); - } - _param = c < 0 ? param.l : param.r; - continue; - }; -} - -function map(f, param) { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = map(f, l); - let v$p = f(v); - let r$p = map(f, r); - if (l === l$p && v === v$p && r === r$p) { - return param; - } else if ((l$p === "Empty" || Caml.string_compare(max_elt(l$p), v$p) < 0) && (r$p === "Empty" || Caml.string_compare(v$p, min_elt(r$p)) < 0)) { - return join(l$p, v$p, r$p); - } else { - return union(l$p, add(v$p, r$p)); - } -} - -function of_list(l) { - if (!l) { - return "Empty"; - } - let match = l.tl; - let x0 = l.hd; - if (!match) { - return singleton(x0); - } - let match$1 = match.tl; - let x1 = match.hd; - if (!match$1) { - return add(x1, singleton(x0)); - } - let match$2 = match$1.tl; - let x2 = match$1.hd; - if (!match$2) { - return add(x2, add(x1, singleton(x0))); - } - let match$3 = match$2.tl; - let x3 = match$2.hd; - if (match$3) { - if (match$3.tl) { - let l$1 = List.sort_uniq($$String.compare, l); - let sub = (n, l) => { - switch (n) { - case 0 : - return [ - "Empty", - l - ]; - case 1 : - if (l) { - return [ - { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - l.tl - ]; - } - break; - case 2 : - if (l) { - let match = l.tl; - if (match) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match.hd, - r: "Empty", - h: 2 - }, - match.tl - ]; - } - - } - break; - case 3 : - if (l) { - let match$1 = l.tl; - if (match$1) { - let match$2 = match$1.tl; - if (match$2) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match$1.hd, - r: { - TAG: "Node", - l: "Empty", - v: match$2.hd, - r: "Empty", - h: 1 - }, - h: 2 - }, - match$2.tl - ]; - } - - } - - } - break; - } - let nl = n / 2 | 0; - let match$3 = sub(nl, l); - let l$1 = match$3[1]; - if (l$1) { - let match$4 = sub((n - nl | 0) - 1 | 0, l$1.tl); - return [ - create(match$3[0], l$1.hd, match$4[0]), - match$4[1] - ]; - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "set.res", - 691, - 20 - ], - Error: new Error() - }; - }; - return sub(List.length(l$1), l$1)[0]; - } else { - return add(match$3.hd, add(x3, add(x2, add(x1, singleton(x0))))); - } - } else { - return add(x3, add(x2, add(x1, singleton(x0)))); - } -} - -let String_set = { - empty: "Empty", - is_empty: is_empty, - mem: mem, - add: add, - singleton: singleton, - remove: remove, - union: union, - inter: inter, - diff: diff, - compare: compare, - equal: equal, - subset: subset, - iter: iter, - map: map, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - elements: elements, - min_elt: min_elt, - min_elt_opt: min_elt_opt, - max_elt: max_elt, - max_elt_opt: max_elt_opt, - choose: min_elt, - choose_opt: min_elt_opt, - split: split, - find: find, - find_opt: find_opt, - find_first: find_first, - find_first_opt: find_first_opt, - find_last: find_last, - find_last_opt: find_last_opt, - of_list: of_list -}; - -let Cycle = /* @__PURE__ */Caml_exceptions.create("Topsort_test.Cycle"); +let Cycle = /* @__PURE__ */Primitive_exceptions.create("Topsort_test.Cycle"); function pathsort(graph) { let visited = { contents: /* [] */0 }; let empty_path = [ - "Empty", + undefined, /* [] */0 ]; let $plus$great = (node, param) => { let stack = param[1]; let set = param[0]; - if (mem(node, set)) { + if (Belt_SetString.has(set, node)) { throw { RE_EXN_ID: Cycle, _1: { @@ -1464,16 +465,16 @@ function pathsort(graph) { }; } return [ - add(node, set), + Belt_SetString.add(set, node), { hd: node, tl: stack } ]; }; - let sort_nodes = (path, nodes) => List.iter(node => sort_node(path, node), nodes); + let sort_nodes = (path, nodes) => Belt_List.forEach(nodes, node => sort_node(path, node)); let sort_node = (path, node) => { - if (!List.mem(node, visited.contents)) { + if (!Belt_List.has(visited.contents, node, (prim0, prim1) => prim0 === prim1)) { sort_nodes($plus$great(node, path), nexts(node, graph)); visited.contents = { hd: node, @@ -1483,11 +484,11 @@ function pathsort(graph) { } }; - List.iter(param => sort_node(empty_path, param[0]), graph); + Belt_List.forEach(graph, param => sort_node(empty_path, param[0])); return visited.contents; } -if (!Caml_obj.equal(pathsort(grwork), { +if (!Primitive_object.equal(pathsort(grwork), { hd: "wake", tl: { hd: "shower", @@ -1510,7 +511,7 @@ if (!Caml_obj.equal(pathsort(grwork), { RE_EXN_ID: "Assert_failure", _1: [ "topsort_test.res", - 144, + 147, 9 ], Error: new Error() @@ -1529,13 +530,13 @@ try { RE_EXN_ID: "Assert_failure", _1: [ "topsort_test.res", - 148, + 151, 2 ], Error: new Error() }; } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + let exn = Primitive_exceptions.internalToException(raw_exn); let exit = 0; if (exn.RE_EXN_ID === Cycle) { let match = exn._1; @@ -1566,7 +567,7 @@ try { RE_EXN_ID: "Assert_failure", _1: [ "topsort_test.res", - 151, + 154, 7 ], Error: new Error() @@ -1575,6 +576,8 @@ try { } +let String_set; + exports.graph = graph; exports.nexts = nexts; exports.dfs1 = dfs1; diff --git a/jscomp/test/topsort_test.res b/jscomp/test/topsort_test.res index 126fedca06..6877d510d7 100644 --- a/jscomp/test/topsort_test.res +++ b/jscomp/test/topsort_test.res @@ -1,3 +1,5 @@ +open Belt + type graph = list<(string, string)> let graph: graph = list{ @@ -11,22 +13,23 @@ let graph: graph = list{ ("e", "g"), } -let nexts = (x: string, g: graph): list => List.fold_left((acc, (a, b)) => +let nexts = (x: string, g: graph): list => + g->List.reduce(list{}, (acc, (a, b)) => if a == x { list{b, ...acc} } else { acc } - , list{}, g) + ) let rec dfs1 = (nodes, graph, visited) => switch nodes { - | list{} => List.rev(visited) + | list{} => List.reverse(visited) | list{x, ...xs} => - if List.mem(x, visited) { + if visited->List.has(x, \"==") { dfs1(xs, graph, visited) } else { - print_endline(x) + Js.log(x) dfs1(\"@"(nexts(x, graph), xs), graph, list{x, ...visited}) } } @@ -34,7 +37,7 @@ let rec dfs1 = (nodes, graph, visited) => let () = { assert(dfs1(list{"a"}, graph, list{}) == list{"a", "d", "e", "g", "f", "c", "b"}) - print_newline() + Js.log() assert(dfs1(list{"b"}, list{("f", "d"), ...graph}, list{}) == list{"b", "e", "g", "f", "d"}) } @@ -43,13 +46,13 @@ let rec dfs2 = (nodes, graph, visited) => { switch nodes { | list{} => visited | list{x, ...xs} => - if List.mem(x, visited) { + if visited->List.has(x, \"==") { aux(xs, graph, visited) } else { aux(xs, graph, aux(nexts(x, graph), graph, list{x, ...visited})) } } - \"@@"(List.rev, aux(nodes, graph, visited)) + aux(nodes, graph, visited)->List.reverse } let () = { @@ -61,12 +64,12 @@ let () = { let dfs3 = (nodes, graph) => { let visited = ref(list{}) let rec aux = (node, graph) => - if \"@@"(not, List.mem(node, visited.contents)) { + if !List.has(visited.contents, node, \"==") { visited := list{node, ...visited.contents} - List.iter(x => aux(x, graph), nexts(node, graph)) + nexts(node, graph)->List.forEach(x => aux(x, graph)) } - List.iter(node => aux(node, graph), nodes) - List.rev(visited.contents) + nodes->List.forEach(node => aux(node, graph)) + visited.contents->List.reverse } let () = { @@ -90,9 +93,9 @@ let grwork = list{ let unsafe_topsort = graph => { let visited = ref(list{}) - let rec sort_nodes = nodes => List.iter(node => sort_node(node), nodes) + let rec sort_nodes = nodes => nodes->List.forEach(node => sort_node(node)) and sort_node = node => - if \"@@"(not, List.mem(node, visited.contents)) { + if !List.has(visited.contents, node, \"==") { /* This check does not prevent cycle , but it is still necessary? yes! since a node can have multiple parents @@ -105,30 +108,30 @@ let unsafe_topsort = graph => { */ visited := list{node, ...visited.contents} } - List.iter(((x, _)) => sort_node(x), graph) + graph->List.forEach(((x, _)) => sort_node(x)) visited.contents } let () = assert(unsafe_topsort(grwork) == list{"wake", "shower", "dress", "eat", "washup", "go"}) -module String_set = Set.Make(String) +module String_set = Belt.Set.String exception Cycle(list) let pathsort = graph => { let visited = ref(list{}) let empty_path = (String_set.empty, list{}) let \"+>" = (node, (set, stack)) => - if String_set.mem(node, set) { + if String_set.has(set, node) { raise(Cycle(list{node, ...stack})) } else { - (String_set.add(node, set), list{node, ...stack}) + (String_set.add(set, node), list{node, ...stack}) } /* let check node (set,stack) = if String_set.mem node set then raise (Cycle (node::stack)) in */ - let rec sort_nodes = (path, nodes) => List.iter(node => sort_node(path, node), nodes) + let rec sort_nodes = (path, nodes) => nodes->List.forEach(node => sort_node(path, node)) and sort_node = (path, node) => - if \"@@"(not, List.mem(node, visited.contents)) { + if !List.has(visited.contents, node, \"==") { /* check node path ; */ sort_nodes(\"+>"(node, path), nexts(node, graph)) /* different from dfs, recorded after its @@ -137,14 +140,14 @@ let pathsort = graph => { */ visited := list{node, ...visited.contents} } - List.iter(((x, _)) => sort_node(empty_path, x), graph) + graph->List.forEach(((x, _)) => sort_node(empty_path, x)) visited.contents } let () = assert(pathsort(grwork) == list{"wake", "shower", "dress", "eat", "washup", "go"}) let () = try { - \"@@"(ignore, pathsort(list{("go", "eat"), ...grwork})) + pathsort(list{("go", "eat"), ...grwork})->ignore assert(false) } catch { | Cycle(list{"go", "washup", "eat", "go"}) => () diff --git a/jscomp/test/unboxed_use_case.js b/jscomp/test/unboxed_use_case.js index a4b2d91ae6..87e4d4f635 100644 --- a/jscomp/test/unboxed_use_case.js +++ b/jscomp/test/unboxed_use_case.js @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_obj = require("../../lib/js/caml_obj.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); function map_pair(r, param) { return [ @@ -31,7 +31,7 @@ console.log("x"); let v0 = {}; -Caml_obj.update_dummy(v0, { +Primitive_object.updateDummy(v0, { NAME: "A", VAL: v0 }); diff --git a/jscomp/test/uncurried_cast.js b/jscomp/test/uncurried_cast.js index 92c87bf44b..c861ee130b 100644 --- a/jscomp/test/uncurried_cast.js +++ b/jscomp/test/uncurried_cast.js @@ -2,7 +2,7 @@ 'use strict'; let Belt_List = require("../../lib/js/belt_List.js"); -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); function raise(e) { throw e; @@ -19,7 +19,7 @@ let Uncurried = { List: List }; -let E = /* @__PURE__ */Caml_exceptions.create("Uncurried_cast.E"); +let E = /* @__PURE__ */Primitive_exceptions.create("Uncurried_cast.E"); function testRaise() { throw { diff --git a/jscomp/test/uncurry_external_test.js b/jscomp/test/uncurry_external_test.js index cb3e10f486..aec9171cd6 100644 --- a/jscomp/test/uncurry_external_test.js +++ b/jscomp/test/uncurry_external_test.js @@ -15,7 +15,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -33,7 +33,7 @@ function sum(a,b){ let h = sum(1.0, 2.0); -eq("File \"uncurry_external_test.res\", line 19, characters 12-19", h, 3); +eq("File \"uncurry_external_test.res\", line 22, characters 12-19", h, 3); Mt.from_pair_suites("Uncurry_external_test", suites.contents); diff --git a/jscomp/test/uncurry_external_test.res b/jscomp/test/uncurry_external_test.res index 86f9055aa9..bc83d00f64 100644 --- a/jscomp/test/uncurry_external_test.res +++ b/jscomp/test/uncurry_external_test.res @@ -3,7 +3,10 @@ let test_id = ref(0) let eq = (loc, x, y) => { incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } %%raw(` diff --git a/jscomp/test/unit_undefined_test.js b/jscomp/test/unit_undefined_test.js index 6c5ea46ed6..a0d8fa8e78 100644 --- a/jscomp/test/unit_undefined_test.js +++ b/jscomp/test/unit_undefined_test.js @@ -2,7 +2,7 @@ 'use strict'; let Mt = require("./mt.js"); -let Caml_option = require("../../lib/js/caml_option.js"); +let Primitive_option = require("../../lib/js/primitive_option.js"); let suites = { contents: /* [] */0 @@ -43,24 +43,24 @@ function fx() { } function u0(x) { - return Caml_option.some(x); + return Primitive_option.some(x); } -let u1 = Caml_option.some(undefined); +let u1 = Primitive_option.some(undefined); function u2(x) { - return Caml_option.some(x); + return Primitive_option.some(x); } -let u3 = Caml_option.some(undefined); +let u3 = Primitive_option.some(undefined); -eq("File \"unit_undefined_test.res\", line 41, characters 3-10", Caml_option.some(), Caml_option.some(undefined)); +eq("File \"unit_undefined_test.res\", line 41, characters 3-10", Primitive_option.some(), Primitive_option.some(undefined)); -eq("File \"unit_undefined_test.res\", line 42, characters 3-10", u1, Caml_option.some(undefined)); +eq("File \"unit_undefined_test.res\", line 42, characters 3-10", u1, Primitive_option.some(undefined)); -eq("File \"unit_undefined_test.res\", line 43, characters 3-10", Caml_option.some(), Caml_option.some(undefined)); +eq("File \"unit_undefined_test.res\", line 43, characters 3-10", Primitive_option.some(), Primitive_option.some(undefined)); -eq("File \"unit_undefined_test.res\", line 44, characters 3-10", u3, Caml_option.some(undefined)); +eq("File \"unit_undefined_test.res\", line 44, characters 3-10", u3, Primitive_option.some(undefined)); eq("File \"unit_undefined_test.res\", line 45, characters 3-10", undefined, undefined); diff --git a/jscomp/test/update_record_test.js b/jscomp/test/update_record_test.js index 4d034eaf83..75715296c5 100644 --- a/jscomp/test/update_record_test.js +++ b/jscomp/test/update_record_test.js @@ -19,7 +19,7 @@ function eq(loc, x, y) { test_id.contents = test_id.contents + 1 | 0; suites.contents = { hd: [ - loc + (" id " + String(test_id.contents)), + loc + (" id " + test_id.contents.toString()), () => ({ TAG: "Eq", _0: x, @@ -42,7 +42,7 @@ function f(x) { }; } -eq("File \"update_record_test.res\", line 28, characters 5-12", 1, f({ +eq("File \"update_record_test.res\", line 31, characters 5-12", 1, f({ a0: 0, a1: 0, a2: 0, @@ -65,9 +65,9 @@ function fff(x) { let val1 = fff(val0); -eq("File \"update_record_test.res\", line 41, characters 5-12", 3, 3); +eq("File \"update_record_test.res\", line 44, characters 5-12", 3, 3); -eq("File \"update_record_test.res\", line 42, characters 5-12", val1["invalid_js_id'"], 5); +eq("File \"update_record_test.res\", line 45, characters 5-12", val1["invalid_js_id'"], 5); Mt.from_pair_suites("Update_record_test", suites.contents); diff --git a/jscomp/test/update_record_test.res b/jscomp/test/update_record_test.res index c5457746e7..c1b98992d2 100644 --- a/jscomp/test/update_record_test.res +++ b/jscomp/test/update_record_test.res @@ -4,7 +4,10 @@ let eq = (loc, x, y) => { Js.log((x, y)) incr(test_id) suites := - list{(loc ++ (" id " ++ string_of_int(test_id.contents)), _ => Mt.Eq(x, y)), ...suites.contents} + list{ + (loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)), + ...suites.contents, + } } type t = { diff --git a/jscomp/test/variant.js b/jscomp/test/variant.js index 0ee7797d01..df45870a93 100644 --- a/jscomp/test/variant.js +++ b/jscomp/test/variant.js @@ -1,9 +1,8 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Caml_obj = require("../../lib/js/caml_obj.js"); -let Caml_exceptions = require("../../lib/js/caml_exceptions.js"); -let Caml_js_exceptions = require("../../lib/js/caml_js_exceptions.js"); +let Primitive_object = require("../../lib/js/primitive_object.js"); +let Primitive_exceptions = require("../../lib/js/primitive_exceptions.js"); function foo(x) { if (typeof x !== "object") { @@ -53,9 +52,9 @@ function switchNum(x) { } } -let same = Caml_obj.equal; +let same = Primitive_object.equal; -let compare = Caml_obj.compare; +let compare = Primitive_object.compare; let Path = { same: same, @@ -81,7 +80,7 @@ function rollback_path(subst, p) { try { return "try"; } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + let exn = Primitive_exceptions.internalToException(raw_exn); if (exn.RE_EXN_ID === "Not_found") { switch (p.TAG) { case "Pdot" : @@ -96,21 +95,21 @@ function rollback_path(subst, p) { } } -let EA1 = /* @__PURE__ */Caml_exceptions.create("Variant.EA1"); +let EA1 = /* @__PURE__ */Primitive_exceptions.create("Variant.EA1"); -let EA2 = /* @__PURE__ */Caml_exceptions.create("Variant.EA2"); +let EA2 = /* @__PURE__ */Primitive_exceptions.create("Variant.EA2"); -let EB = /* @__PURE__ */Caml_exceptions.create("Variant.EB"); +let EB = /* @__PURE__ */Primitive_exceptions.create("Variant.EB"); -let EC = /* @__PURE__ */Caml_exceptions.create("Variant.EC"); +let EC = /* @__PURE__ */Primitive_exceptions.create("Variant.EC"); -let ED = /* @__PURE__ */Caml_exceptions.create("Variant.ED"); +let ED = /* @__PURE__ */Primitive_exceptions.create("Variant.ED"); function fooExn(f) { try { return f(); } catch (raw_n) { - let n = Caml_js_exceptions.internalToOCamlException(raw_n); + let n = Primitive_exceptions.internalToException(raw_n); if (n.RE_EXN_ID === EA1) { return 1; } diff --git a/jscomp/test/webpack_config.js b/jscomp/test/webpack_config.js index dacb56068a..08fe58defc 100644 --- a/jscomp/test/webpack_config.js +++ b/jscomp/test/webpack_config.js @@ -1,11 +1,11 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let List = require("../../lib/js/list.js"); -let List$1 = require("List"); -let List$2 = require("reactV"); -let List$3 = require("reactX"); +let List = require("List"); +let List$1 = require("reactV"); +let List$2 = require("reactX"); let Local = require("./local"); +let Belt_List = require("../../lib/js/belt_List.js"); let WebpackConfigJs = require("../../../webpack.config.js"); let WebpackMiddlewareConfigJs = require("../../../webpack.middleware.config.js"); @@ -40,23 +40,23 @@ let B = {}; function f() { return [ prim => { - List$3.ff(); + List$2.ff(); }, prim => { - List$3.ff2(); + List$2.ff2(); }, prim => { - List$2.ff(); + List$1.ff(); }, prim => { - List$2.ff2(); + List$1.ff2(); } ]; } -List$1.xx(); +List.xx(); -List.length({ +Belt_List.length({ hd: 1, tl: { hd: 2, @@ -64,7 +64,7 @@ List.length({ } }); -List.length(/* [] */0); +Belt_List.length(/* [] */0); function ff(prim) { return Local.ff(); diff --git a/jscomp/test/webpack_config.res b/jscomp/test/webpack_config.res index 96f6ede97a..a013d1456e 100644 --- a/jscomp/test/webpack_config.res +++ b/jscomp/test/webpack_config.res @@ -1,3 +1,5 @@ +open Belt + module type Config = { let configx: Js.Json.t } diff --git a/lib/es6/arg.js b/lib/es6/arg.js deleted file mode 100644 index a02eb4814e..0000000000 --- a/lib/es6/arg.js +++ /dev/null @@ -1,691 +0,0 @@ - - -import * as Sys from "./sys.js"; -import * as Caml from "./caml.js"; -import * as List from "./list.js"; -import * as $$Array from "./array.js"; -import * as Buffer from "./buffer.js"; -import * as $$String from "./string.js"; -import * as Caml_obj from "./caml_obj.js"; -import * as Caml_array from "./caml_array.js"; -import * as Pervasives from "./pervasives.js"; -import * as Caml_format from "./caml_format.js"; -import * as Caml_string from "./caml_string.js"; -import * as Caml_exceptions from "./caml_exceptions.js"; -import * as Caml_js_exceptions from "./caml_js_exceptions.js"; - -let Bad = /* @__PURE__ */Caml_exceptions.create("Arg.Bad"); - -let Help = /* @__PURE__ */Caml_exceptions.create("Arg.Help"); - -let Stop = /* @__PURE__ */Caml_exceptions.create("Arg.Stop"); - -function assoc3(x, _l) { - while (true) { - let l = _l; - if (l) { - let match = l.hd; - if (Caml_obj.equal(match[0], x)) { - return match[1]; - } - _l = l.tl; - continue; - } - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - }; -} - -function split(s) { - let i = $$String.index(s, /* '=' */61); - let len = s.length; - return [ - $$String.sub(s, 0, i), - $$String.sub(s, i + 1 | 0, len - (i + 1 | 0) | 0) - ]; -} - -function make_symlist(prefix, sep, suffix, l) { - if (l) { - return List.fold_left((x, y) => x + (sep + y), prefix + l.hd, l.tl) + suffix; - } else { - return ""; - } -} - -function help_action() { - throw { - RE_EXN_ID: Stop, - _1: { - TAG: "Unknown", - _0: "-help" - }, - Error: new Error() - }; -} - -function add_help(speclist) { - let add1; - try { - assoc3("-help", speclist); - add1 = /* [] */0; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - add1 = { - hd: [ - "-help", - { - TAG: "Unit", - _0: help_action - }, - " Display this list of options" - ], - tl: /* [] */0 - }; - } else { - throw exn; - } - } - let add2; - try { - assoc3("--help", speclist); - add2 = /* [] */0; - } catch (raw_exn$1) { - let exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn$1); - if (exn$1.RE_EXN_ID === "Not_found") { - add2 = { - hd: [ - "--help", - { - TAG: "Unit", - _0: help_action - }, - " Display this list of options" - ], - tl: /* [] */0 - }; - } else { - throw exn$1; - } - } - return Pervasives.$at(speclist, Pervasives.$at(add1, add2)); -} - -function usage_b(buf, speclist, errmsg) { - Buffer.add_string(buf, errmsg + "\n"); - List.iter(x => { - let doc = x[2]; - if (doc.length === 0) { - return; - } - let spec = x[1]; - let key = x[0]; - if (spec.TAG !== "Symbol") { - return Buffer.add_string(buf, " " + key + " " + doc + "\n"); - } - let sym = make_symlist("{", "|", "}", spec._0); - Buffer.add_string(buf, " " + key + " " + sym + doc + "\n"); - }, add_help(speclist)); -} - -function usage_string(speclist, errmsg) { - let b = Buffer.create(200); - usage_b(b, speclist, errmsg); - return Buffer.contents(b); -} - -function usage(speclist, errmsg) { - console.log(usage_string(speclist, errmsg)); -} - -let current = { - contents: 0 -}; - -function bool_of_string_opt(x) { - try { - return Pervasives.bool_of_string(x); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Invalid_argument") { - return; - } - throw exn; - } -} - -function int_of_string_opt(x) { - try { - return Caml_format.int_of_string(x); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Failure") { - return; - } - throw exn; - } -} - -function float_of_string_opt(x) { - try { - return Caml_format.float_of_string(x); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Failure") { - return; - } - throw exn; - } -} - -function parse_and_expand_argv_dynamic_aux(allow_expand, current, argv, speclist, anonfun, errmsg) { - let initpos = current.contents; - let convert_error = error => { - let b = Buffer.create(200); - let progname = initpos < argv.contents.length ? Caml_array.get(argv.contents, initpos) : "(?)"; - switch (error.TAG) { - case "Unknown" : - let s = error._0; - switch (s) { - case "--help" : - case "-help" : - break; - default: - Buffer.add_string(b, progname + ": unknown option '" + s + "'.\n"); - } - break; - case "Wrong" : - Buffer.add_string(b, progname + ": wrong argument '" + error._1 + "'; option '" + error._0 + "' expects " + error._2 + ".\n"); - break; - case "Missing" : - Buffer.add_string(b, progname + ": option '" + error._0 + "' needs an argument.\n"); - break; - case "Message" : - Buffer.add_string(b, progname + ": " + error._0 + ".\n"); - break; - } - usage_b(b, speclist.contents, errmsg); - if (Caml_obj.equal(error, { - TAG: "Unknown", - _0: "-help" - }) || Caml_obj.equal(error, { - TAG: "Unknown", - _0: "--help" - })) { - return { - RE_EXN_ID: Help, - _1: Buffer.contents(b) - }; - } else { - return { - RE_EXN_ID: Bad, - _1: Buffer.contents(b) - }; - } - }; - current.contents = current.contents + 1 | 0; - while (current.contents < argv.contents.length) { - try { - let s = Caml_array.get(argv.contents, current.contents); - if (s.length >= 1 && Caml_string.get(s, 0) === /* '-' */45) { - let match; - try { - match = [ - assoc3(s, speclist.contents), - undefined - ]; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - try { - let match$1 = split(s); - match = [ - assoc3(match$1[0], speclist.contents), - match$1[1] - ]; - } catch (raw_exn$1) { - let exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn$1); - if (exn$1.RE_EXN_ID === "Not_found") { - throw { - RE_EXN_ID: Stop, - _1: { - TAG: "Unknown", - _0: s - }, - Error: new Error() - }; - } - throw exn$1; - } - } else { - throw exn; - } - } - let follow = match[1]; - let no_arg = () => { - if (follow === undefined) { - return; - } - throw { - RE_EXN_ID: Stop, - _1: { - TAG: "Wrong", - _0: s, - _1: follow, - _2: "no argument" - }, - Error: new Error() - }; - }; - let get_arg = () => { - if (follow !== undefined) { - return follow; - } - if ((current.contents + 1 | 0) < argv.contents.length) { - return Caml_array.get(argv.contents, current.contents + 1 | 0); - } - throw { - RE_EXN_ID: Stop, - _1: { - TAG: "Missing", - _0: s - }, - Error: new Error() - }; - }; - let consume_arg = () => { - if (follow !== undefined) { - return; - } else { - current.contents = current.contents + 1 | 0; - return; - } - }; - let treat_action = f => { - switch (f.TAG) { - case "Unit" : - return f._0(); - case "Bool" : - let arg = get_arg(); - let s$1 = bool_of_string_opt(arg); - if (s$1 !== undefined) { - f._0(s$1); - } else { - throw { - RE_EXN_ID: Stop, - _1: { - TAG: "Wrong", - _0: s, - _1: arg, - _2: "a boolean" - }, - Error: new Error() - }; - } - return consume_arg(); - case "Set" : - no_arg(); - f._0.contents = true; - return; - case "Clear" : - no_arg(); - f._0.contents = false; - return; - case "String" : - let arg$1 = get_arg(); - f._0(arg$1); - return consume_arg(); - case "Set_string" : - f._0.contents = get_arg(); - return consume_arg(); - case "Int" : - let arg$2 = get_arg(); - let x = int_of_string_opt(arg$2); - if (x !== undefined) { - f._0(x); - } else { - throw { - RE_EXN_ID: Stop, - _1: { - TAG: "Wrong", - _0: s, - _1: arg$2, - _2: "an integer" - }, - Error: new Error() - }; - } - return consume_arg(); - case "Set_int" : - let arg$3 = get_arg(); - let x$1 = int_of_string_opt(arg$3); - if (x$1 !== undefined) { - f._0.contents = x$1; - } else { - throw { - RE_EXN_ID: Stop, - _1: { - TAG: "Wrong", - _0: s, - _1: arg$3, - _2: "an integer" - }, - Error: new Error() - }; - } - return consume_arg(); - case "Float" : - let arg$4 = get_arg(); - let x$2 = float_of_string_opt(arg$4); - if (x$2 !== undefined) { - f._0(x$2); - } else { - throw { - RE_EXN_ID: Stop, - _1: { - TAG: "Wrong", - _0: s, - _1: arg$4, - _2: "a float" - }, - Error: new Error() - }; - } - return consume_arg(); - case "Set_float" : - let arg$5 = get_arg(); - let x$3 = float_of_string_opt(arg$5); - if (x$3 !== undefined) { - f._0.contents = x$3; - } else { - throw { - RE_EXN_ID: Stop, - _1: { - TAG: "Wrong", - _0: s, - _1: arg$5, - _2: "a float" - }, - Error: new Error() - }; - } - return consume_arg(); - case "Tuple" : - return List.iter(treat_action, f._0); - case "Symbol" : - let symb = f._0; - let arg$6 = get_arg(); - if (List.mem(arg$6, symb)) { - f._1(arg$6); - return consume_arg(); - } - throw { - RE_EXN_ID: Stop, - _1: { - TAG: "Wrong", - _0: s, - _1: arg$6, - _2: "one of: " + make_symlist("", " ", "", symb) - }, - Error: new Error() - }; - case "Rest" : - let f$1 = f._0; - while (current.contents < (argv.contents.length - 1 | 0)) { - f$1(Caml_array.get(argv.contents, current.contents + 1 | 0)); - consume_arg(); - }; - return; - case "Expand" : - if (!allow_expand) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Arg.Expand is is only allowed with Arg.parse_and_expand_argv_dynamic", - Error: new Error() - }; - } - let arg$7 = get_arg(); - let newarg = f._0(arg$7); - consume_arg(); - let before = $$Array.sub(argv.contents, 0, current.contents + 1 | 0); - let after = $$Array.sub(argv.contents, current.contents + 1 | 0, (argv.contents.length - current.contents | 0) - 1 | 0); - argv.contents = Caml_array.concat({ - hd: before, - tl: { - hd: newarg, - tl: { - hd: after, - tl: /* [] */0 - } - } - }); - return; - } - }; - treat_action(match[0]); - } else { - anonfun(s); - } - } catch (raw_m) { - let m = Caml_js_exceptions.internalToOCamlException(raw_m); - if (m.RE_EXN_ID === Bad) { - throw convert_error({ - TAG: "Message", - _0: m._1 - }); - } - if (m.RE_EXN_ID === Stop) { - throw convert_error(m._1); - } - throw m; - } - current.contents = current.contents + 1 | 0; - }; -} - -function parse_and_expand_argv_dynamic(current, argv, speclist, anonfun, errmsg) { - parse_and_expand_argv_dynamic_aux(true, current, argv, speclist, anonfun, errmsg); -} - -function parse_argv_dynamic(currentOpt, argv, speclist, anonfun, errmsg) { - let current$1 = currentOpt !== undefined ? currentOpt : current; - parse_and_expand_argv_dynamic_aux(false, current$1, { - contents: argv - }, speclist, anonfun, errmsg); -} - -function parse_argv(currentOpt, argv, speclist, anonfun, errmsg) { - let current$1 = currentOpt !== undefined ? currentOpt : current; - parse_argv_dynamic(current$1, argv, { - contents: speclist - }, anonfun, errmsg); -} - -function parse(l, f, msg) { - try { - return parse_argv(undefined, Sys.argv, l, f, msg); - } catch (raw_msg) { - let msg$1 = Caml_js_exceptions.internalToOCamlException(raw_msg); - if (msg$1.RE_EXN_ID === Bad) { - console.log(msg$1._1); - return Pervasives.exit(2); - } - if (msg$1.RE_EXN_ID === Help) { - console.log(msg$1._1); - return Pervasives.exit(0); - } - throw msg$1; - } -} - -function parse_dynamic(l, f, msg) { - try { - return parse_argv_dynamic(undefined, Sys.argv, l, f, msg); - } catch (raw_msg) { - let msg$1 = Caml_js_exceptions.internalToOCamlException(raw_msg); - if (msg$1.RE_EXN_ID === Bad) { - console.log(msg$1._1); - return Pervasives.exit(2); - } - if (msg$1.RE_EXN_ID === Help) { - console.log(msg$1._1); - return Pervasives.exit(0); - } - throw msg$1; - } -} - -function parse_expand(l, f, msg) { - try { - let argv = { - contents: Sys.argv - }; - let spec = { - contents: l - }; - let current$1 = { - contents: current.contents - }; - return parse_and_expand_argv_dynamic(current$1, argv, spec, f, msg); - } catch (raw_msg) { - let msg$1 = Caml_js_exceptions.internalToOCamlException(raw_msg); - if (msg$1.RE_EXN_ID === Bad) { - console.log(msg$1._1); - return Pervasives.exit(2); - } - if (msg$1.RE_EXN_ID === Help) { - console.log(msg$1._1); - return Pervasives.exit(0); - } - throw msg$1; - } -} - -function second_word(s) { - let len = s.length; - let loop = _n => { - while (true) { - let n = _n; - if (n >= len) { - return len; - } - if (Caml_string.get(s, n) !== /* ' ' */32) { - return n; - } - _n = n + 1 | 0; - continue; - }; - }; - let n; - try { - n = $$String.index(s, /* '\t' */9); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - let exit = 0; - let n$1; - try { - n$1 = $$String.index(s, /* ' ' */32); - exit = 2; - } catch (raw_exn$1) { - let exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn$1); - if (exn$1.RE_EXN_ID === "Not_found") { - return len; - } - throw exn$1; - } - if (exit === 2) { - return loop(n$1 + 1 | 0); - } - - } else { - throw exn; - } - } - return loop(n + 1 | 0); -} - -function max_arg_len(cur, param) { - let kwd = param[0]; - if (param[1].TAG === "Symbol") { - return Caml.int_max(cur, kwd.length); - } else { - return Caml.int_max(cur, kwd.length + second_word(param[2]) | 0); - } -} - -function replace_leading_tab(s) { - let seen = { - contents: false - }; - return $$String.map(c => { - if (c !== 9 || seen.contents) { - return c; - } else { - seen.contents = true; - return /* ' ' */32; - } - }, s); -} - -function align(limitOpt, speclist) { - let limit = limitOpt !== undefined ? limitOpt : Pervasives.max_int; - let completed = add_help(speclist); - let len = List.fold_left(max_arg_len, 0, completed); - let len$1 = len < limit ? len : limit; - return List.map(x => { - let spec = x[1]; - let kwd = x[0]; - if (x[2] === "") { - return x; - } - if (spec.TAG === "Symbol") { - let msg = x[2]; - let cutcol = second_word(msg); - let spaces = " ".repeat(Caml.int_max(0, len$1 - cutcol | 0) + 3 | 0); - return [ - kwd, - spec, - "\n" + (spaces + replace_leading_tab(msg)) - ]; - } - let msg$1 = x[2]; - let cutcol$1 = second_word(msg$1); - let kwd_len = kwd.length; - let diff = (len$1 - kwd_len | 0) - cutcol$1 | 0; - if (diff <= 0) { - return [ - kwd, - spec, - replace_leading_tab(msg$1) - ]; - } - let spaces$1 = " ".repeat(diff); - let prefix = $$String.sub(replace_leading_tab(msg$1), 0, cutcol$1); - let suffix = $$String.sub(msg$1, cutcol$1, msg$1.length - cutcol$1 | 0); - return [ - kwd, - spec, - prefix + (spaces$1 + suffix) - ]; - }, completed); -} - -export { - parse, - parse_dynamic, - parse_argv, - parse_argv_dynamic, - parse_and_expand_argv_dynamic, - parse_expand, - Help, - Bad, - usage, - usage_string, - align, - current, -} -/* No side effect */ diff --git a/lib/es6/array.js b/lib/es6/array.js index ff3b8d976d..4e0d2fecfc 100644 --- a/lib/es6/array.js +++ b/lib/es6/array.js @@ -1,55 +1,42 @@ -import * as Caml_obj from "./caml_obj.js"; -import * as Caml_array from "./caml_array.js"; -import * as Caml_exceptions from "./caml_exceptions.js"; -import * as Caml_js_exceptions from "./caml_js_exceptions.js"; +import * as List from "./list.js"; +import * as Primitive_array from "./primitive_array.js"; +import * as Primitive_exceptions from "./primitive_exceptions.js"; -let make_float = Caml_array.make_float; +let init = ((length, f) => Array.from({ length }, f)); -let Floatarray = {}; +function make(len, x) { + return init(len, param => x); +} -function init(l, f) { - if (l === 0) { - return []; - } - if (l < 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Array.init", - Error: new Error() - }; - } - let res = Caml_array.make(l, f(0)); - for (let i = 1; i < l; ++i) { - res[i] = f(i); - } - return res; +function unsafe_sub(array, offset, length) { + return array.slice(offset, offset + length | 0); } -function make_matrix(sx, sy, init) { - let res = Caml_array.make(sx, []); - for (let x = 0; x < sx; ++x) { - res[x] = Caml_array.make(sy, init); - } - return res; +function concat(list) { + return List.fold_left((arr1, arr2) => arr1.concat(arr2), [], list); } -function copy(a) { - let l = a.length; - if (l === 0) { - return []; - } else { - return Caml_array.sub(a, 0, l); +function create_float(len) { + return init(len, param => 0.0); +} + +function make_matrix(sx, sy, init$1) { + let x = []; + let res = init(sx, param => x); + for (let x$1 = 0; x$1 < sx; ++x$1) { + res[x$1] = init(sy, param => init$1); } + return res; } function append(a1, a2) { let l1 = a1.length; if (l1 === 0) { - return copy(a2); + return a2.slice(); } else if (a2.length === 0) { - return Caml_array.sub(a1, 0, l1); + return unsafe_sub(a1, 0, l1); } else { return a1.concat(a2); } @@ -63,7 +50,7 @@ function sub(a, ofs, len) { Error: new Error() }; } - return Caml_array.sub(a, ofs, len); + return unsafe_sub(a, ofs, len); } function fill(a, ofs, len, v) { @@ -87,7 +74,9 @@ function blit(a1, ofs1, a2, ofs2, len) { Error: new Error() }; } - Caml_array.blit(a1, ofs1, a2, ofs2, len); + for (let i = 0; i < len; ++i) { + a2[ofs2 + i | 0] = a1[ofs1 + i | 0]; + } } function iter(f, a) { @@ -114,7 +103,8 @@ function map(f, a) { if (l === 0) { return []; } - let r = Caml_array.make(l, f(a[0])); + let x = f(a[0]); + let r = init(l, param => x); for (let i = 1; i < l; ++i) { r[i] = f(a[i]); } @@ -134,7 +124,8 @@ function map2(f, a, b) { if (la === 0) { return []; } - let r = Caml_array.make(la, f(a[0], b[0])); + let x = f(a[0], b[0]); + let r = init(la, param => x); for (let i = 1; i < la; ++i) { r[i] = f(a[i], b[i]); } @@ -152,7 +143,8 @@ function mapi(f, a) { if (l === 0) { return []; } - let r = Caml_array.make(l, f(0, a[0])); + let x = f(0, a[0]); + let r = init(l, param => x); for (let i = 1; i < l; ++i) { r[i] = f(i, a[i]); } @@ -194,7 +186,9 @@ function of_list(param) { if (!param) { return []; } - let a = Caml_array.make(list_length(0, param), param.hd); + let hd = param.hd; + let len = list_length(0, param); + let a = init(len, param => hd); let _i = 1; let _param = param.tl; while (true) { @@ -266,7 +260,7 @@ function mem(x, a) { if (i === n) { return false; } - if (Caml_obj.equal(a[i], x)) { + if (a[i] === x) { return true; } _i = i + 1 | 0; @@ -290,22 +284,22 @@ function memq(x, a) { }; } -let Bottom = /* @__PURE__ */Caml_exceptions.create("Array.Bottom"); +let Bottom = /* @__PURE__ */Primitive_exceptions.create("Array.Bottom"); function sort(cmp, a) { let maxson = (l, i) => { let i31 = ((i + i | 0) + i | 0) + 1 | 0; let x = i31; if ((i31 + 2 | 0) < l) { - if (cmp(Caml_array.get(a, i31), Caml_array.get(a, i31 + 1 | 0)) < 0) { + if (cmp(Primitive_array.get(a, i31), Primitive_array.get(a, i31 + 1 | 0)) < 0) { x = i31 + 1 | 0; } - if (cmp(Caml_array.get(a, x), Caml_array.get(a, i31 + 2 | 0)) < 0) { + if (cmp(Primitive_array.get(a, x), Primitive_array.get(a, i31 + 2 | 0)) < 0) { x = i31 + 2 | 0; } return x; } - if ((i31 + 1 | 0) < l && cmp(Caml_array.get(a, i31), Caml_array.get(a, i31 + 1 | 0)) < 0) { + if ((i31 + 1 | 0) < l && cmp(Primitive_array.get(a, i31), Primitive_array.get(a, i31 + 1 | 0)) < 0) { return i31 + 1 | 0; } if (i31 < l) { @@ -323,17 +317,17 @@ function sort(cmp, a) { while (true) { let i$1 = _i; let j = maxson(l, i$1); - if (cmp(Caml_array.get(a, j), e) <= 0) { - return Caml_array.set(a, i$1, e); + if (cmp(Primitive_array.get(a, j), e) <= 0) { + return Primitive_array.set(a, i$1, e); } - Caml_array.set(a, i$1, Caml_array.get(a, j)); + Primitive_array.set(a, i$1, Primitive_array.get(a, j)); _i = j; continue; }; } catch (raw_i) { - let i$2 = Caml_js_exceptions.internalToOCamlException(raw_i); + let i$2 = Primitive_exceptions.internalToException(raw_i); if (i$2.RE_EXN_ID === Bottom) { - return Caml_array.set(a, i$2._1, e); + return Primitive_array.set(a, i$2._1, e); } throw i$2; } @@ -344,12 +338,12 @@ function sort(cmp, a) { while (true) { let i$1 = _i; let j = maxson(l, i$1); - Caml_array.set(a, i$1, Caml_array.get(a, j)); + Primitive_array.set(a, i$1, Primitive_array.get(a, j)); _i = j; continue; }; } catch (raw_i) { - let i$2 = Caml_js_exceptions.internalToOCamlException(raw_i); + let i$2 = Primitive_exceptions.internalToException(raw_i); if (i$2.RE_EXN_ID === Bottom) { return i$2._1; } @@ -365,18 +359,18 @@ function sort(cmp, a) { RE_EXN_ID: "Assert_failure", _1: [ "array.res", - 321, + 294, 4 ], Error: new Error() }; } - if (cmp(Caml_array.get(a, father), e) >= 0) { - return Caml_array.set(a, i, e); + if (cmp(Primitive_array.get(a, father), e) >= 0) { + return Primitive_array.set(a, i, e); } - Caml_array.set(a, i, Caml_array.get(a, father)); + Primitive_array.set(a, i, Primitive_array.get(a, father)); if (father <= 0) { - return Caml_array.set(a, 0, e); + return Primitive_array.set(a, 0, e); } _i = father; continue; @@ -384,19 +378,19 @@ function sort(cmp, a) { }; let l = a.length; for (let i = ((l + 1 | 0) / 3 | 0) - 1 | 0; i >= 0; --i) { - trickle(l, i, Caml_array.get(a, i)); + trickle(l, i, Primitive_array.get(a, i)); } for (let i$1 = l - 1 | 0; i$1 >= 2; --i$1) { - let e = Caml_array.get(a, i$1); - Caml_array.set(a, i$1, Caml_array.get(a, 0)); + let e = Primitive_array.get(a, i$1); + Primitive_array.set(a, i$1, Primitive_array.get(a, 0)); trickleup(bubble(i$1, 0), e); } if (l <= 1) { return; } - let e$1 = Caml_array.get(a, 1); - Caml_array.set(a, 1, Caml_array.get(a, 0)); - Caml_array.set(a, 0, e$1); + let e$1 = Primitive_array.get(a, 1); + Primitive_array.set(a, 1, Primitive_array.get(a, 0)); + Primitive_array.set(a, 0, e$1); } function stable_sort(cmp, a) { @@ -404,9 +398,9 @@ function stable_sort(cmp, a) { let src1r = src1ofs + src1len | 0; let src2r = src2ofs + src2len | 0; let _i1 = src1ofs; - let _s1 = Caml_array.get(a, src1ofs); + let _s1 = Primitive_array.get(a, src1ofs); let _i2 = src2ofs; - let _s2 = Caml_array.get(src2, src2ofs); + let _s2 = Primitive_array.get(src2, src2ofs); let _d = dstofs; while (true) { let d = _d; @@ -415,36 +409,36 @@ function stable_sort(cmp, a) { let s1 = _s1; let i1 = _i1; if (cmp(s1, s2) <= 0) { - Caml_array.set(dst, d, s1); + Primitive_array.set(dst, d, s1); let i1$1 = i1 + 1 | 0; if (i1$1 >= src1r) { return blit(src2, i2, dst, d + 1 | 0, src2r - i2 | 0); } _d = d + 1 | 0; - _s1 = Caml_array.get(a, i1$1); + _s1 = Primitive_array.get(a, i1$1); _i1 = i1$1; continue; } - Caml_array.set(dst, d, s2); + Primitive_array.set(dst, d, s2); let i2$1 = i2 + 1 | 0; if (i2$1 >= src2r) { return blit(a, i1, dst, d + 1 | 0, src1r - i1 | 0); } _d = d + 1 | 0; - _s2 = Caml_array.get(src2, i2$1); + _s2 = Primitive_array.get(src2, i2$1); _i2 = i2$1; continue; }; }; let isortto = (srcofs, dst, dstofs, len) => { for (let i = 0; i < len; ++i) { - let e = Caml_array.get(a, srcofs + i | 0); + let e = Primitive_array.get(a, srcofs + i | 0); let j = (dstofs + i | 0) - 1 | 0; - while (j >= dstofs && cmp(Caml_array.get(dst, j), e) > 0) { - Caml_array.set(dst, j + 1 | 0, Caml_array.get(dst, j)); + while (j >= dstofs && cmp(Primitive_array.get(dst, j), e) > 0) { + Primitive_array.set(dst, j + 1 | 0, Primitive_array.get(dst, j)); j = j - 1 | 0; }; - Caml_array.set(dst, j + 1 | 0, e); + Primitive_array.set(dst, j + 1 | 0, e); } }; let sortto = (srcofs, dst, dstofs, len) => { @@ -463,27 +457,23 @@ function stable_sort(cmp, a) { } let l1 = l / 2 | 0; let l2 = l - l1 | 0; - let t = Caml_array.make(l2, Caml_array.get(a, 0)); + let x = Primitive_array.get(a, 0); + let t = init(l2, param => x); sortto(l1, t, 0, l2); sortto(0, a, l2, l1); merge(l2, l1, t, 0, l2, a, 0); } -let create_matrix = make_matrix; - -let concat = Caml_array.concat; - let fast_sort = stable_sort; export { - make_float, + make, + create_float, init, make_matrix, - create_matrix, append, concat, sub, - copy, fill, blit, to_list, @@ -503,6 +493,5 @@ export { sort, stable_sort, fast_sort, - Floatarray, } /* No side effect */ diff --git a/lib/es6/arrayLabels.js b/lib/es6/arrayLabels.js deleted file mode 100644 index 8832f68edb..0000000000 --- a/lib/es6/arrayLabels.js +++ /dev/null @@ -1,508 +0,0 @@ - - -import * as Caml_obj from "./caml_obj.js"; -import * as Caml_array from "./caml_array.js"; -import * as Caml_exceptions from "./caml_exceptions.js"; -import * as Caml_js_exceptions from "./caml_js_exceptions.js"; - -let make_float = Caml_array.make_float; - -let Floatarray = {}; - -function init(l, f) { - if (l === 0) { - return []; - } - if (l < 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Array.init", - Error: new Error() - }; - } - let res = Caml_array.make(l, f(0)); - for (let i = 1; i < l; ++i) { - res[i] = f(i); - } - return res; -} - -function make_matrix(sx, sy, init) { - let res = Caml_array.make(sx, []); - for (let x = 0; x < sx; ++x) { - res[x] = Caml_array.make(sy, init); - } - return res; -} - -function copy(a) { - let l = a.length; - if (l === 0) { - return []; - } else { - return Caml_array.sub(a, 0, l); - } -} - -function append(a1, a2) { - let l1 = a1.length; - if (l1 === 0) { - return copy(a2); - } else if (a2.length === 0) { - return Caml_array.sub(a1, 0, l1); - } else { - return a1.concat(a2); - } -} - -function sub(a, ofs, len) { - if (ofs < 0 || len < 0 || ofs > (a.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Array.sub", - Error: new Error() - }; - } - return Caml_array.sub(a, ofs, len); -} - -function fill(a, ofs, len, v) { - if (ofs < 0 || len < 0 || ofs > (a.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Array.fill", - Error: new Error() - }; - } - for (let i = ofs, i_finish = ofs + len | 0; i < i_finish; ++i) { - a[i] = v; - } -} - -function blit(a1, ofs1, a2, ofs2, len) { - if (len < 0 || ofs1 < 0 || ofs1 > (a1.length - len | 0) || ofs2 < 0 || ofs2 > (a2.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Array.blit", - Error: new Error() - }; - } - Caml_array.blit(a1, ofs1, a2, ofs2, len); -} - -function iter(f, a) { - for (let i = 0, i_finish = a.length; i < i_finish; ++i) { - f(a[i]); - } -} - -function iter2(f, a, b) { - if (a.length !== b.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Array.iter2: arrays must have the same length", - Error: new Error() - }; - } - for (let i = 0, i_finish = a.length; i < i_finish; ++i) { - f(a[i], b[i]); - } -} - -function map(f, a) { - let l = a.length; - if (l === 0) { - return []; - } - let r = Caml_array.make(l, f(a[0])); - for (let i = 1; i < l; ++i) { - r[i] = f(a[i]); - } - return r; -} - -function map2(f, a, b) { - let la = a.length; - let lb = b.length; - if (la !== lb) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Array.map2: arrays must have the same length", - Error: new Error() - }; - } - if (la === 0) { - return []; - } - let r = Caml_array.make(la, f(a[0], b[0])); - for (let i = 1; i < la; ++i) { - r[i] = f(a[i], b[i]); - } - return r; -} - -function iteri(f, a) { - for (let i = 0, i_finish = a.length; i < i_finish; ++i) { - f(i, a[i]); - } -} - -function mapi(f, a) { - let l = a.length; - if (l === 0) { - return []; - } - let r = Caml_array.make(l, f(0, a[0])); - for (let i = 1; i < l; ++i) { - r[i] = f(i, a[i]); - } - return r; -} - -function to_list(a) { - let _i = a.length - 1 | 0; - let _res = /* [] */0; - while (true) { - let res = _res; - let i = _i; - if (i < 0) { - return res; - } - _res = { - hd: a[i], - tl: res - }; - _i = i - 1 | 0; - continue; - }; -} - -function list_length(_accu, _param) { - while (true) { - let param = _param; - let accu = _accu; - if (!param) { - return accu; - } - _param = param.tl; - _accu = accu + 1 | 0; - continue; - }; -} - -function of_list(param) { - if (!param) { - return []; - } - let a = Caml_array.make(list_length(0, param), param.hd); - let _i = 1; - let _param = param.tl; - while (true) { - let param$1 = _param; - let i = _i; - if (!param$1) { - return a; - } - a[i] = param$1.hd; - _param = param$1.tl; - _i = i + 1 | 0; - continue; - }; -} - -function fold_left(f, x, a) { - let r = x; - for (let i = 0, i_finish = a.length; i < i_finish; ++i) { - r = f(r, a[i]); - } - return r; -} - -function fold_right(f, a, x) { - let r = x; - for (let i = a.length - 1 | 0; i >= 0; --i) { - r = f(a[i], r); - } - return r; -} - -function exists(p, a) { - let n = a.length; - let _i = 0; - while (true) { - let i = _i; - if (i === n) { - return false; - } - if (p(a[i])) { - return true; - } - _i = i + 1 | 0; - continue; - }; -} - -function for_all(p, a) { - let n = a.length; - let _i = 0; - while (true) { - let i = _i; - if (i === n) { - return true; - } - if (!p(a[i])) { - return false; - } - _i = i + 1 | 0; - continue; - }; -} - -function mem(x, a) { - let n = a.length; - let _i = 0; - while (true) { - let i = _i; - if (i === n) { - return false; - } - if (Caml_obj.equal(a[i], x)) { - return true; - } - _i = i + 1 | 0; - continue; - }; -} - -function memq(x, a) { - let n = a.length; - let _i = 0; - while (true) { - let i = _i; - if (i === n) { - return false; - } - if (x === a[i]) { - return true; - } - _i = i + 1 | 0; - continue; - }; -} - -let Bottom = /* @__PURE__ */Caml_exceptions.create("ArrayLabels.Bottom"); - -function sort(cmp, a) { - let maxson = (l, i) => { - let i31 = ((i + i | 0) + i | 0) + 1 | 0; - let x = i31; - if ((i31 + 2 | 0) < l) { - if (cmp(Caml_array.get(a, i31), Caml_array.get(a, i31 + 1 | 0)) < 0) { - x = i31 + 1 | 0; - } - if (cmp(Caml_array.get(a, x), Caml_array.get(a, i31 + 2 | 0)) < 0) { - x = i31 + 2 | 0; - } - return x; - } - if ((i31 + 1 | 0) < l && cmp(Caml_array.get(a, i31), Caml_array.get(a, i31 + 1 | 0)) < 0) { - return i31 + 1 | 0; - } - if (i31 < l) { - return i31; - } - throw { - RE_EXN_ID: Bottom, - _1: i, - Error: new Error() - }; - }; - let trickle = (l, i, e) => { - try { - let _i = i; - while (true) { - let i$1 = _i; - let j = maxson(l, i$1); - if (cmp(Caml_array.get(a, j), e) <= 0) { - return Caml_array.set(a, i$1, e); - } - Caml_array.set(a, i$1, Caml_array.get(a, j)); - _i = j; - continue; - }; - } catch (raw_i) { - let i$2 = Caml_js_exceptions.internalToOCamlException(raw_i); - if (i$2.RE_EXN_ID === Bottom) { - return Caml_array.set(a, i$2._1, e); - } - throw i$2; - } - }; - let bubble = (l, i) => { - try { - let _i = i; - while (true) { - let i$1 = _i; - let j = maxson(l, i$1); - Caml_array.set(a, i$1, Caml_array.get(a, j)); - _i = j; - continue; - }; - } catch (raw_i) { - let i$2 = Caml_js_exceptions.internalToOCamlException(raw_i); - if (i$2.RE_EXN_ID === Bottom) { - return i$2._1; - } - throw i$2; - } - }; - let trickleup = (_i, e) => { - while (true) { - let i = _i; - let father = (i - 1 | 0) / 3 | 0; - if (i === father) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "arrayLabels.res", - 321, - 4 - ], - Error: new Error() - }; - } - if (cmp(Caml_array.get(a, father), e) >= 0) { - return Caml_array.set(a, i, e); - } - Caml_array.set(a, i, Caml_array.get(a, father)); - if (father <= 0) { - return Caml_array.set(a, 0, e); - } - _i = father; - continue; - }; - }; - let l = a.length; - for (let i = ((l + 1 | 0) / 3 | 0) - 1 | 0; i >= 0; --i) { - trickle(l, i, Caml_array.get(a, i)); - } - for (let i$1 = l - 1 | 0; i$1 >= 2; --i$1) { - let e = Caml_array.get(a, i$1); - Caml_array.set(a, i$1, Caml_array.get(a, 0)); - trickleup(bubble(i$1, 0), e); - } - if (l <= 1) { - return; - } - let e$1 = Caml_array.get(a, 1); - Caml_array.set(a, 1, Caml_array.get(a, 0)); - Caml_array.set(a, 0, e$1); -} - -function stable_sort(cmp, a) { - let merge = (src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs) => { - let src1r = src1ofs + src1len | 0; - let src2r = src2ofs + src2len | 0; - let _i1 = src1ofs; - let _s1 = Caml_array.get(a, src1ofs); - let _i2 = src2ofs; - let _s2 = Caml_array.get(src2, src2ofs); - let _d = dstofs; - while (true) { - let d = _d; - let s2 = _s2; - let i2 = _i2; - let s1 = _s1; - let i1 = _i1; - if (cmp(s1, s2) <= 0) { - Caml_array.set(dst, d, s1); - let i1$1 = i1 + 1 | 0; - if (i1$1 >= src1r) { - return blit(src2, i2, dst, d + 1 | 0, src2r - i2 | 0); - } - _d = d + 1 | 0; - _s1 = Caml_array.get(a, i1$1); - _i1 = i1$1; - continue; - } - Caml_array.set(dst, d, s2); - let i2$1 = i2 + 1 | 0; - if (i2$1 >= src2r) { - return blit(a, i1, dst, d + 1 | 0, src1r - i1 | 0); - } - _d = d + 1 | 0; - _s2 = Caml_array.get(src2, i2$1); - _i2 = i2$1; - continue; - }; - }; - let isortto = (srcofs, dst, dstofs, len) => { - for (let i = 0; i < len; ++i) { - let e = Caml_array.get(a, srcofs + i | 0); - let j = (dstofs + i | 0) - 1 | 0; - while (j >= dstofs && cmp(Caml_array.get(dst, j), e) > 0) { - Caml_array.set(dst, j + 1 | 0, Caml_array.get(dst, j)); - j = j - 1 | 0; - }; - Caml_array.set(dst, j + 1 | 0, e); - } - }; - let sortto = (srcofs, dst, dstofs, len) => { - if (len <= 5) { - return isortto(srcofs, dst, dstofs, len); - } - let l1 = len / 2 | 0; - let l2 = len - l1 | 0; - sortto(srcofs + l1 | 0, dst, dstofs + l1 | 0, l2); - sortto(srcofs, a, srcofs + l2 | 0, l1); - merge(srcofs + l2 | 0, l1, dst, dstofs + l1 | 0, l2, dst, dstofs); - }; - let l = a.length; - if (l <= 5) { - return isortto(0, a, 0, l); - } - let l1 = l / 2 | 0; - let l2 = l - l1 | 0; - let t = Caml_array.make(l2, Caml_array.get(a, 0)); - sortto(l1, t, 0, l2); - sortto(0, a, l2, l1); - merge(l2, l1, t, 0, l2, a, 0); -} - -let create_matrix = make_matrix; - -let concat = Caml_array.concat; - -let fast_sort = stable_sort; - -export { - init, - make_matrix, - create_matrix, - append, - concat, - sub, - copy, - fill, - blit, - to_list, - of_list, - iter, - map, - iteri, - mapi, - fold_left, - fold_right, - iter2, - map2, - exists, - for_all, - mem, - memq, - make_float, - sort, - stable_sort, - fast_sort, - Floatarray, -} -/* No side effect */ diff --git a/lib/es6/belt_Array.js b/lib/es6/belt_Array.js index 52df9f4a28..b5923010b4 100644 --- a/lib/es6/belt_Array.js +++ b/lib/es6/belt_Array.js @@ -1,11 +1,11 @@ -import * as Caml from "./caml.js"; -import * as Caml_option from "./caml_option.js"; +import * as Primitive_int from "./primitive_int.js"; +import * as Primitive_option from "./primitive_option.js"; function get(arr, i) { if (i >= 0 && i < arr.length) { - return Caml_option.some(arr[i]); + return Primitive_option.some(arr[i]); } } @@ -144,7 +144,7 @@ function rangeBy(start, finish, step) { function zip(xs, ys) { let lenx = xs.length; let leny = ys.length; - let len = lenx < leny ? lenx : leny; + let len = Primitive_int.min(lenx, leny); let s = new Array(len); for (let i = 0; i < len; ++i) { s[i] = [ @@ -158,7 +158,7 @@ function zip(xs, ys) { function zipBy(xs, ys, f) { let lenx = xs.length; let leny = ys.length; - let len = lenx < leny ? lenx : leny; + let len = Primitive_int.min(lenx, leny); let s = new Array(len); for (let i = 0; i < len; ++i) { s[i] = f(xs[i], ys[i]); @@ -202,9 +202,9 @@ function slice(a, offset, len) { return []; } let lena = a.length; - let ofs = offset < 0 ? Caml.int_max(lena + offset | 0, 0) : offset; + let ofs = offset < 0 ? Primitive_int.max(lena + offset | 0, 0) : offset; let hasLen = lena - ofs | 0; - let copyLength = hasLen < len ? hasLen : len; + let copyLength = Primitive_int.min(hasLen, len); if (copyLength <= 0) { return []; } @@ -217,7 +217,7 @@ function slice(a, offset, len) { function sliceToEnd(a, offset) { let lena = a.length; - let ofs = offset < 0 ? Caml.int_max(lena + offset | 0, 0) : offset; + let ofs = offset < 0 ? Primitive_int.max(lena + offset | 0, 0) : offset; let len = lena > ofs ? lena - ofs | 0 : 0; let result = new Array(len); for (let i = 0; i < len; ++i) { @@ -231,9 +231,9 @@ function fill(a, offset, len, v) { return; } let lena = a.length; - let ofs = offset < 0 ? Caml.int_max(lena + offset | 0, 0) : offset; + let ofs = offset < 0 ? Primitive_int.max(lena + offset | 0, 0) : offset; let hasLen = lena - ofs | 0; - let fillLength = hasLen < len ? hasLen : len; + let fillLength = Primitive_int.min(hasLen, len); if (fillLength <= 0) { return; } @@ -257,9 +257,9 @@ function blitUnsafe(a1, srcofs1, a2, srcofs2, blitLength) { function blit(a1, ofs1, a2, ofs2, len) { let lena1 = a1.length; let lena2 = a2.length; - let srcofs1 = ofs1 < 0 ? Caml.int_max(lena1 + ofs1 | 0, 0) : ofs1; - let srcofs2 = ofs2 < 0 ? Caml.int_max(lena2 + ofs2 | 0, 0) : ofs2; - let blitLength = Caml.int_min(len, Caml.int_min(lena1 - srcofs1 | 0, lena2 - srcofs2 | 0)); + let srcofs1 = ofs1 < 0 ? Primitive_int.max(lena1 + ofs1 | 0, 0) : ofs1; + let srcofs2 = ofs2 < 0 ? Primitive_int.max(lena2 + ofs2 | 0, 0) : ofs2; + let blitLength = Primitive_int.min(len, Primitive_int.min(lena1 - srcofs1 | 0, lena2 - srcofs2 | 0)); if (srcofs2 <= srcofs1) { for (let j = 0; j < blitLength; ++j) { a2[j + srcofs2 | 0] = a1[j + srcofs1 | 0]; @@ -297,7 +297,7 @@ function getBy(a, p) { while (r === undefined && i < l) { let v = a[i]; if (p(v)) { - r = Caml_option.some(v); + r = Primitive_option.some(v); } i = i + 1 | 0; }; @@ -358,7 +358,7 @@ function keepMap(a, f) { let v = a[i]; let v$1 = f(v); if (v$1 !== undefined) { - r[j] = Caml_option.valFromOption(v$1); + r[j] = Primitive_option.valFromOption(v$1); j = j + 1 | 0; } @@ -400,7 +400,7 @@ function reduceReverse(a, x, f) { function reduceReverse2(a, b, x, f) { let r = x; - let len = Caml.int_min(a.length, b.length); + let len = Primitive_int.min(a.length, b.length); for (let i = len - 1 | 0; i >= 0; --i) { r = f(r, a[i], b[i]); } @@ -462,12 +462,12 @@ function everyAux2(arr1, arr2, _i, b, len) { } function every2(a, b, p) { - return everyAux2(a, b, 0, p, Caml.int_min(a.length, b.length)); + return everyAux2(a, b, 0, p, Primitive_int.min(a.length, b.length)); } function some2(a, b, p) { let _i = 0; - let len = Caml.int_min(a.length, b.length); + let len = Primitive_int.min(a.length, b.length); while (true) { let i = _i; if (i === len) { diff --git a/lib/es6/belt_HashMap.js b/lib/es6/belt_HashMap.js index a8b574065f..a8149b88fd 100644 --- a/lib/es6/belt_HashMap.js +++ b/lib/es6/belt_HashMap.js @@ -1,6 +1,6 @@ -import * as Caml_option from "./caml_option.js"; +import * as Primitive_option from "./primitive_option.js"; import * as Belt_internalBuckets from "./belt_internalBuckets.js"; import * as Belt_internalBucketsType from "./belt_internalBucketsType.js"; @@ -138,19 +138,19 @@ function get(h, key) { } let eq = h.eq; if (eq(key, cell1.key)) { - return Caml_option.some(cell1.value); + return Primitive_option.some(cell1.value); } let cell2 = cell1.next; if (cell2 === undefined) { return; } if (eq(key, cell2.key)) { - return Caml_option.some(cell2.value); + return Primitive_option.some(cell2.value); } let cell3 = cell2.next; if (cell3 !== undefined) { if (eq(key, cell3.key)) { - return Caml_option.some(cell3.value); + return Primitive_option.some(cell3.value); } else { let _buckets = cell3.next; while (true) { @@ -159,7 +159,7 @@ function get(h, key) { return; } if (eq(key, buckets.key)) { - return Caml_option.some(buckets.value); + return Primitive_option.some(buckets.value); } _buckets = buckets.next; continue; diff --git a/lib/es6/belt_HashMapInt.js b/lib/es6/belt_HashMapInt.js index 095ac46a7e..6e218fb20c 100644 --- a/lib/es6/belt_HashMapInt.js +++ b/lib/es6/belt_HashMapInt.js @@ -1,7 +1,7 @@ -import * as Caml_option from "./caml_option.js"; -import * as Caml_hash_primitive from "./caml_hash_primitive.js"; +import * as Primitive_hash from "./primitive_hash.js"; +import * as Primitive_option from "./primitive_option.js"; import * as Belt_internalBuckets from "./belt_internalBuckets.js"; import * as Belt_internalBucketsType from "./belt_internalBucketsType.js"; @@ -11,7 +11,7 @@ function copyBucketReHash(h_buckets, ndata_tail, _old_bucket) { if (old_bucket === undefined) { return; } - let nidx = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_int(0, old_bucket.key)) & (h_buckets.length - 1 | 0); + let nidx = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_int(0, old_bucket.key)) & (h_buckets.length - 1 | 0); let tail = ndata_tail[nidx]; if (tail !== undefined) { tail.next = old_bucket; @@ -43,7 +43,7 @@ function replaceInBucket(key, info, _cell) { function set(h, key, value) { let h_buckets = h.buckets; let buckets_len = h_buckets.length; - let i = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_int(0, key)) & (buckets_len - 1 | 0); + let i = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_int(0, key)) & (buckets_len - 1 | 0); let l = h_buckets[i]; if (l !== undefined) { if (replaceInBucket(key, value, l)) { @@ -90,7 +90,7 @@ function set(h, key, value) { function remove(h, key) { let h_buckets = h.buckets; - let i = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_int(0, key)) & (h_buckets.length - 1 | 0); + let i = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_int(0, key)) & (h_buckets.length - 1 | 0); let bucket = h_buckets[i]; if (bucket !== undefined) { if (bucket.key === key) { @@ -123,25 +123,25 @@ function remove(h, key) { function get(h, key) { let h_buckets = h.buckets; - let nid = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_int(0, key)) & (h_buckets.length - 1 | 0); + let nid = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_int(0, key)) & (h_buckets.length - 1 | 0); let cell1 = h_buckets[nid]; if (cell1 === undefined) { return; } if (key === cell1.key) { - return Caml_option.some(cell1.value); + return Primitive_option.some(cell1.value); } let cell2 = cell1.next; if (cell2 === undefined) { return; } if (key === cell2.key) { - return Caml_option.some(cell2.value); + return Primitive_option.some(cell2.value); } let cell3 = cell2.next; if (cell3 !== undefined) { if (key === cell3.key) { - return Caml_option.some(cell3.value); + return Primitive_option.some(cell3.value); } else { let _buckets = cell3.next; while (true) { @@ -150,7 +150,7 @@ function get(h, key) { return; } if (key === buckets.key) { - return Caml_option.some(buckets.value); + return Primitive_option.some(buckets.value); } _buckets = buckets.next; continue; @@ -162,7 +162,7 @@ function get(h, key) { function has(h, key) { let h_buckets = h.buckets; - let nid = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_int(0, key)) & (h_buckets.length - 1 | 0); + let nid = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_int(0, key)) & (h_buckets.length - 1 | 0); let bucket = h_buckets[nid]; if (bucket !== undefined) { let _cell = bucket; diff --git a/lib/es6/belt_HashMapString.js b/lib/es6/belt_HashMapString.js index ed7da631a5..02ab31a16a 100644 --- a/lib/es6/belt_HashMapString.js +++ b/lib/es6/belt_HashMapString.js @@ -1,7 +1,7 @@ -import * as Caml_option from "./caml_option.js"; -import * as Caml_hash_primitive from "./caml_hash_primitive.js"; +import * as Primitive_hash from "./primitive_hash.js"; +import * as Primitive_option from "./primitive_option.js"; import * as Belt_internalBuckets from "./belt_internalBuckets.js"; import * as Belt_internalBucketsType from "./belt_internalBucketsType.js"; @@ -11,7 +11,7 @@ function copyBucketReHash(h_buckets, ndata_tail, _old_bucket) { if (old_bucket === undefined) { return; } - let nidx = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_string(0, old_bucket.key)) & (h_buckets.length - 1 | 0); + let nidx = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_string(0, old_bucket.key)) & (h_buckets.length - 1 | 0); let tail = ndata_tail[nidx]; if (tail !== undefined) { tail.next = old_bucket; @@ -43,7 +43,7 @@ function replaceInBucket(key, info, _cell) { function set(h, key, value) { let h_buckets = h.buckets; let buckets_len = h_buckets.length; - let i = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_string(0, key)) & (buckets_len - 1 | 0); + let i = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_string(0, key)) & (buckets_len - 1 | 0); let l = h_buckets[i]; if (l !== undefined) { if (replaceInBucket(key, value, l)) { @@ -90,7 +90,7 @@ function set(h, key, value) { function remove(h, key) { let h_buckets = h.buckets; - let i = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_string(0, key)) & (h_buckets.length - 1 | 0); + let i = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_string(0, key)) & (h_buckets.length - 1 | 0); let bucket = h_buckets[i]; if (bucket !== undefined) { if (bucket.key === key) { @@ -123,25 +123,25 @@ function remove(h, key) { function get(h, key) { let h_buckets = h.buckets; - let nid = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_string(0, key)) & (h_buckets.length - 1 | 0); + let nid = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_string(0, key)) & (h_buckets.length - 1 | 0); let cell1 = h_buckets[nid]; if (cell1 === undefined) { return; } if (key === cell1.key) { - return Caml_option.some(cell1.value); + return Primitive_option.some(cell1.value); } let cell2 = cell1.next; if (cell2 === undefined) { return; } if (key === cell2.key) { - return Caml_option.some(cell2.value); + return Primitive_option.some(cell2.value); } let cell3 = cell2.next; if (cell3 !== undefined) { if (key === cell3.key) { - return Caml_option.some(cell3.value); + return Primitive_option.some(cell3.value); } else { let _buckets = cell3.next; while (true) { @@ -150,7 +150,7 @@ function get(h, key) { return; } if (key === buckets.key) { - return Caml_option.some(buckets.value); + return Primitive_option.some(buckets.value); } _buckets = buckets.next; continue; @@ -162,7 +162,7 @@ function get(h, key) { function has(h, key) { let h_buckets = h.buckets; - let nid = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_string(0, key)) & (h_buckets.length - 1 | 0); + let nid = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_string(0, key)) & (h_buckets.length - 1 | 0); let bucket = h_buckets[nid]; if (bucket !== undefined) { let _cell = bucket; diff --git a/lib/es6/belt_HashSetInt.js b/lib/es6/belt_HashSetInt.js index 5352654a43..14ed070ec5 100644 --- a/lib/es6/belt_HashSetInt.js +++ b/lib/es6/belt_HashSetInt.js @@ -1,6 +1,6 @@ -import * as Caml_hash_primitive from "./caml_hash_primitive.js"; +import * as Primitive_hash from "./primitive_hash.js"; import * as Belt_internalSetBuckets from "./belt_internalSetBuckets.js"; import * as Belt_internalBucketsType from "./belt_internalBucketsType.js"; @@ -10,7 +10,7 @@ function copyBucket(h_buckets, ndata_tail, _old_bucket) { if (old_bucket === undefined) { return; } - let nidx = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_int(0, old_bucket.key)) & (h_buckets.length - 1 | 0); + let nidx = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_int(0, old_bucket.key)) & (h_buckets.length - 1 | 0); let tail = ndata_tail[nidx]; if (tail !== undefined) { tail.next = old_bucket; @@ -25,7 +25,7 @@ function copyBucket(h_buckets, ndata_tail, _old_bucket) { function remove(h, key) { let h_buckets = h.buckets; - let i = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_int(0, key)) & (h_buckets.length - 1 | 0); + let i = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_int(0, key)) & (h_buckets.length - 1 | 0); let l = h_buckets[i]; if (l === undefined) { return; @@ -82,7 +82,7 @@ function addBucket(h, key, _cell) { function add(h, key) { let h_buckets = h.buckets; let buckets_len = h_buckets.length; - let i = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_int(0, key)) & (buckets_len - 1 | 0); + let i = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_int(0, key)) & (buckets_len - 1 | 0); let l = h_buckets[i]; if (l !== undefined) { addBucket(h, key, l); @@ -120,7 +120,7 @@ function add(h, key) { function has(h, key) { let h_buckets = h.buckets; - let nid = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_int(0, key)) & (h_buckets.length - 1 | 0); + let nid = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_int(0, key)) & (h_buckets.length - 1 | 0); let bucket = h_buckets[nid]; if (bucket !== undefined) { let _cell = bucket; diff --git a/lib/es6/belt_HashSetString.js b/lib/es6/belt_HashSetString.js index 43dc7f2a97..b53f127068 100644 --- a/lib/es6/belt_HashSetString.js +++ b/lib/es6/belt_HashSetString.js @@ -1,6 +1,6 @@ -import * as Caml_hash_primitive from "./caml_hash_primitive.js"; +import * as Primitive_hash from "./primitive_hash.js"; import * as Belt_internalSetBuckets from "./belt_internalSetBuckets.js"; import * as Belt_internalBucketsType from "./belt_internalBucketsType.js"; @@ -10,7 +10,7 @@ function copyBucket(h_buckets, ndata_tail, _old_bucket) { if (old_bucket === undefined) { return; } - let nidx = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_string(0, old_bucket.key)) & (h_buckets.length - 1 | 0); + let nidx = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_string(0, old_bucket.key)) & (h_buckets.length - 1 | 0); let tail = ndata_tail[nidx]; if (tail !== undefined) { tail.next = old_bucket; @@ -25,7 +25,7 @@ function copyBucket(h_buckets, ndata_tail, _old_bucket) { function remove(h, key) { let h_buckets = h.buckets; - let i = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_string(0, key)) & (h_buckets.length - 1 | 0); + let i = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_string(0, key)) & (h_buckets.length - 1 | 0); let l = h_buckets[i]; if (l === undefined) { return; @@ -82,7 +82,7 @@ function addBucket(h, key, _cell) { function add(h, key) { let h_buckets = h.buckets; let buckets_len = h_buckets.length; - let i = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_string(0, key)) & (buckets_len - 1 | 0); + let i = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_string(0, key)) & (buckets_len - 1 | 0); let l = h_buckets[i]; if (l !== undefined) { addBucket(h, key, l); @@ -120,7 +120,7 @@ function add(h, key) { function has(h, key) { let h_buckets = h.buckets; - let nid = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_string(0, key)) & (h_buckets.length - 1 | 0); + let nid = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_string(0, key)) & (h_buckets.length - 1 | 0); let bucket = h_buckets[nid]; if (bucket !== undefined) { let _cell = bucket; diff --git a/lib/es6/belt_List.js b/lib/es6/belt_List.js index 219db44fc9..d34068b414 100644 --- a/lib/es6/belt_List.js +++ b/lib/es6/belt_List.js @@ -1,12 +1,12 @@ import * as Belt_Array from "./belt_Array.js"; -import * as Caml_option from "./caml_option.js"; import * as Belt_SortArray from "./belt_SortArray.js"; +import * as Primitive_option from "./primitive_option.js"; function head(x) { if (x) { - return Caml_option.some(x.hd); + return Primitive_option.some(x.hd); } } @@ -58,7 +58,7 @@ function get(x, n) { return; } if (n$1 === 0) { - return Caml_option.some(x$1.hd); + return Primitive_option.some(x$1.hd); } _n = n$1 - 1 | 0; _x = x$1.tl; @@ -227,7 +227,7 @@ function copyAuxWitFilterMap(f, _cellX, _prec) { let h = f(cellX.hd); if (h !== undefined) { let next = { - hd: Caml_option.valFromOption(h), + hd: Primitive_option.valFromOption(h), tl: /* [] */0 }; prec.tl = next; @@ -1047,7 +1047,7 @@ function getAssoc(_xs, x, eq) { } let match = xs.hd; if (eq(match[0], x)) { - return Caml_option.some(match[1]); + return Primitive_option.some(match[1]); } _xs = xs.tl; continue; @@ -1142,7 +1142,7 @@ function getBy(_xs, p) { } let x = xs.hd; if (p(x)) { - return Caml_option.some(x); + return Primitive_option.some(x); } _xs = xs.tl; continue; @@ -1205,7 +1205,7 @@ function keepMap(_xs, p) { let h = p(xs.hd); if (h !== undefined) { let cell = { - hd: Caml_option.valFromOption(h), + hd: Primitive_option.valFromOption(h), tl: /* [] */0 }; copyAuxWitFilterMap(p, t, cell); diff --git a/lib/es6/belt_MapDict.js b/lib/es6/belt_MapDict.js index 9326d3fd62..074d28a0d9 100644 --- a/lib/es6/belt_MapDict.js +++ b/lib/es6/belt_MapDict.js @@ -1,6 +1,6 @@ -import * as Caml_option from "./caml_option.js"; +import * as Primitive_option from "./primitive_option.js"; import * as Belt_internalAVLtree from "./belt_internalAVLtree.js"; function set(t, newK, newD, cmp) { @@ -27,9 +27,9 @@ function update(t, newK, f, cmp) { let k = t.k; let c = cmp(newK, k); if (c === 0) { - let newD = f(Caml_option.some(t.v)); + let newD = f(Primitive_option.some(t.v)); if (newD !== undefined) { - return Belt_internalAVLtree.updateValue(t, Caml_option.valFromOption(newD)); + return Belt_internalAVLtree.updateValue(t, Primitive_option.valFromOption(newD)); } let l = t.l; let r = t.r; @@ -68,7 +68,7 @@ function update(t, newK, f, cmp) { } let newD$1 = f(undefined); if (newD$1 !== undefined) { - return Belt_internalAVLtree.singleton(newK, Caml_option.valFromOption(newD$1)); + return Belt_internalAVLtree.singleton(newK, Primitive_option.valFromOption(newD$1)); } else { return t; } @@ -141,7 +141,7 @@ function splitAuxPivot(n, x, pres, cmp) { let r = n.r; let c = cmp(x, v); if (c === 0) { - pres.contents = Caml_option.some(d); + pres.contents = Primitive_option.some(d); return [ l, r @@ -196,13 +196,13 @@ function split(n, x, cmp) { function merge(s1, s2, f, cmp) { if (s1 === undefined) { if (s2 !== undefined) { - return Belt_internalAVLtree.keepMap(s2, (k, v) => f(k, undefined, Caml_option.some(v))); + return Belt_internalAVLtree.keepMap(s2, (k, v) => f(k, undefined, Primitive_option.some(v))); } else { return; } } if (s2 === undefined) { - return Belt_internalAVLtree.keepMap(s1, (k, v) => f(k, Caml_option.some(v), undefined)); + return Belt_internalAVLtree.keepMap(s1, (k, v) => f(k, Primitive_option.some(v), undefined)); } if (s1.h >= s2.h) { let v1 = s1.k; @@ -215,7 +215,7 @@ function merge(s1, s2, f, cmp) { let match = splitAuxPivot(s2, v1, d2, cmp); let d2$1 = d2.contents; let newLeft = merge(l1, match[0], f, cmp); - let newD = f(v1, Caml_option.some(d1), d2$1); + let newD = f(v1, Primitive_option.some(d1), d2$1); let newRight = merge(r1, match[1], f, cmp); return Belt_internalAVLtree.concatOrJoin(newLeft, v1, newD, newRight); } @@ -229,7 +229,7 @@ function merge(s1, s2, f, cmp) { let match$1 = splitAuxPivot(s1, v2, d1$1, cmp); let d1$2 = d1$1.contents; let newLeft$1 = merge(match$1[0], l2, f, cmp); - let newD$1 = f(v2, d1$2, Caml_option.some(d2$2)); + let newD$1 = f(v2, d1$2, Primitive_option.some(d2$2)); let newRight$1 = merge(match$1[1], r2, f, cmp); return Belt_internalAVLtree.concatOrJoin(newLeft$1, v2, newD$1, newRight$1); } diff --git a/lib/es6/belt_MapInt.js b/lib/es6/belt_MapInt.js index b480fb9dbe..556c44f202 100644 --- a/lib/es6/belt_MapInt.js +++ b/lib/es6/belt_MapInt.js @@ -1,6 +1,6 @@ -import * as Caml_option from "./caml_option.js"; +import * as Primitive_option from "./primitive_option.js"; import * as Belt_internalMapInt from "./belt_internalMapInt.js"; import * as Belt_internalAVLtree from "./belt_internalAVLtree.js"; @@ -24,9 +24,9 @@ function update(t, x, f) { if (t !== undefined) { let k = t.k; if (x === k) { - let data = f(Caml_option.some(t.v)); + let data = f(Primitive_option.some(t.v)); if (data !== undefined) { - return Belt_internalAVLtree.updateValue(t, Caml_option.valFromOption(data)); + return Belt_internalAVLtree.updateValue(t, Primitive_option.valFromOption(data)); } let l = t.l; let r = t.r; @@ -65,7 +65,7 @@ function update(t, x, f) { } let data$1 = f(undefined); if (data$1 !== undefined) { - return Belt_internalAVLtree.singleton(x, Caml_option.valFromOption(data$1)); + return Belt_internalAVLtree.singleton(x, Primitive_option.valFromOption(data$1)); } else { return t; } diff --git a/lib/es6/belt_MapString.js b/lib/es6/belt_MapString.js index d52880d55a..dac08cbed6 100644 --- a/lib/es6/belt_MapString.js +++ b/lib/es6/belt_MapString.js @@ -1,6 +1,6 @@ -import * as Caml_option from "./caml_option.js"; +import * as Primitive_option from "./primitive_option.js"; import * as Belt_internalAVLtree from "./belt_internalAVLtree.js"; import * as Belt_internalMapString from "./belt_internalMapString.js"; @@ -24,9 +24,9 @@ function update(t, x, f) { if (t !== undefined) { let k = t.k; if (x === k) { - let data = f(Caml_option.some(t.v)); + let data = f(Primitive_option.some(t.v)); if (data !== undefined) { - return Belt_internalAVLtree.updateValue(t, Caml_option.valFromOption(data)); + return Belt_internalAVLtree.updateValue(t, Primitive_option.valFromOption(data)); } let l = t.l; let r = t.r; @@ -65,7 +65,7 @@ function update(t, x, f) { } let data$1 = f(undefined); if (data$1 !== undefined) { - return Belt_internalAVLtree.singleton(x, Caml_option.valFromOption(data$1)); + return Belt_internalAVLtree.singleton(x, Primitive_option.valFromOption(data$1)); } else { return t; } diff --git a/lib/es6/belt_MutableMap.js b/lib/es6/belt_MutableMap.js index bfefbe093b..2aa197c10c 100644 --- a/lib/es6/belt_MutableMap.js +++ b/lib/es6/belt_MutableMap.js @@ -1,6 +1,6 @@ -import * as Caml_option from "./caml_option.js"; +import * as Primitive_option from "./primitive_option.js"; import * as Belt_internalAVLtree from "./belt_internalAVLtree.js"; function removeMutateAux(nt, x, cmp) { @@ -90,9 +90,9 @@ function updateDone(t, x, f, cmp) { let k = t.k; let c = cmp(x, k); if (c === 0) { - let data = f(Caml_option.some(t.v)); + let data = f(Primitive_option.some(t.v)); if (data !== undefined) { - t.v = Caml_option.valFromOption(data); + t.v = Primitive_option.valFromOption(data); return t; } let l = t.l; @@ -119,7 +119,7 @@ function updateDone(t, x, f, cmp) { } let data$1 = f(undefined); if (data$1 !== undefined) { - return Belt_internalAVLtree.singleton(x, Caml_option.valFromOption(data$1)); + return Belt_internalAVLtree.singleton(x, Primitive_option.valFromOption(data$1)); } else { return t; } diff --git a/lib/es6/belt_MutableMapInt.js b/lib/es6/belt_MutableMapInt.js index 14d8722c75..3b0599b5d7 100644 --- a/lib/es6/belt_MutableMapInt.js +++ b/lib/es6/belt_MutableMapInt.js @@ -1,6 +1,6 @@ -import * as Caml_option from "./caml_option.js"; +import * as Primitive_option from "./primitive_option.js"; import * as Belt_internalMapInt from "./belt_internalMapInt.js"; import * as Belt_internalAVLtree from "./belt_internalAVLtree.js"; @@ -168,9 +168,9 @@ function updateDone(t, x, f) { if (t !== undefined) { let k = t.k; if (k === x) { - let data = f(Caml_option.some(t.v)); + let data = f(Primitive_option.some(t.v)); if (data !== undefined) { - t.v = Caml_option.valFromOption(data); + t.v = Primitive_option.valFromOption(data); return t; } let l = t.l; @@ -198,7 +198,7 @@ function updateDone(t, x, f) { } let data$1 = f(undefined); if (data$1 !== undefined) { - return Belt_internalAVLtree.singleton(x, Caml_option.valFromOption(data$1)); + return Belt_internalAVLtree.singleton(x, Primitive_option.valFromOption(data$1)); } else { return t; } diff --git a/lib/es6/belt_MutableMapString.js b/lib/es6/belt_MutableMapString.js index dfc72c9a0f..a1bf18d0f0 100644 --- a/lib/es6/belt_MutableMapString.js +++ b/lib/es6/belt_MutableMapString.js @@ -1,6 +1,6 @@ -import * as Caml_option from "./caml_option.js"; +import * as Primitive_option from "./primitive_option.js"; import * as Belt_internalAVLtree from "./belt_internalAVLtree.js"; import * as Belt_internalMapString from "./belt_internalMapString.js"; @@ -168,9 +168,9 @@ function updateDone(t, x, f) { if (t !== undefined) { let k = t.k; if (k === x) { - let data = f(Caml_option.some(t.v)); + let data = f(Primitive_option.some(t.v)); if (data !== undefined) { - t.v = Caml_option.valFromOption(data); + t.v = Primitive_option.valFromOption(data); return t; } let l = t.l; @@ -198,7 +198,7 @@ function updateDone(t, x, f) { } let data$1 = f(undefined); if (data$1 !== undefined) { - return Belt_internalAVLtree.singleton(x, Caml_option.valFromOption(data$1)); + return Belt_internalAVLtree.singleton(x, Primitive_option.valFromOption(data$1)); } else { return t; } diff --git a/lib/es6/belt_MutableQueue.js b/lib/es6/belt_MutableQueue.js index 04f7171036..a6366ac163 100644 --- a/lib/es6/belt_MutableQueue.js +++ b/lib/es6/belt_MutableQueue.js @@ -1,6 +1,6 @@ -import * as Caml_option from "./caml_option.js"; +import * as Primitive_option from "./primitive_option.js"; function make() { return { @@ -36,7 +36,7 @@ function add(q, x) { function peek(q) { let v = q.first; if (v !== undefined) { - return Caml_option.some(v.content); + return Primitive_option.some(v.content); } } @@ -68,11 +68,11 @@ function pop(q) { let next = x.next; if (next === undefined) { clear(q); - return Caml_option.some(x.content); + return Primitive_option.some(x.content); } else { q.length = q.length - 1 | 0; q.first = next; - return Caml_option.some(x.content); + return Primitive_option.some(x.content); } } diff --git a/lib/es6/belt_MutableSet.js b/lib/es6/belt_MutableSet.js index 5da8e78766..808e3be97b 100644 --- a/lib/es6/belt_MutableSet.js +++ b/lib/es6/belt_MutableSet.js @@ -1,5 +1,6 @@ +import * as Primitive_int from "./primitive_int.js"; import * as Belt_SortArray from "./belt_SortArray.js"; import * as Belt_internalAVLset from "./belt_internalAVLset.js"; @@ -369,7 +370,7 @@ function intersect(a, b) { data: undefined }; } - let tmp2 = new Array(sizea < sizeb ? sizea : sizeb); + let tmp2 = new Array(Primitive_int.min(sizea, sizeb)); let k = Belt_SortArray.intersect(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0, cmp); return { cmp: cmp, diff --git a/lib/es6/belt_MutableSetInt.js b/lib/es6/belt_MutableSetInt.js index f3655bc4cf..e58bad3b46 100644 --- a/lib/es6/belt_MutableSetInt.js +++ b/lib/es6/belt_MutableSetInt.js @@ -1,5 +1,6 @@ +import * as Primitive_int from "./primitive_int.js"; import * as Belt_SortArrayInt from "./belt_SortArrayInt.js"; import * as Belt_internalAVLset from "./belt_internalAVLset.js"; import * as Belt_internalSetInt from "./belt_internalSetInt.js"; @@ -350,7 +351,7 @@ function intersect(dataa, datab) { data: undefined }; } - let tmp2 = new Array(sizea < sizeb ? sizea : sizeb); + let tmp2 = new Array(Primitive_int.min(sizea, sizeb)); let k = Belt_SortArrayInt.intersect(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0); return { data: Belt_internalAVLset.fromSortedArrayAux(tmp2, 0, k) diff --git a/lib/es6/belt_MutableSetString.js b/lib/es6/belt_MutableSetString.js index 9922a73a2a..b68dc6ea04 100644 --- a/lib/es6/belt_MutableSetString.js +++ b/lib/es6/belt_MutableSetString.js @@ -1,5 +1,6 @@ +import * as Primitive_int from "./primitive_int.js"; import * as Belt_internalAVLset from "./belt_internalAVLset.js"; import * as Belt_SortArrayString from "./belt_SortArrayString.js"; import * as Belt_internalSetString from "./belt_internalSetString.js"; @@ -350,7 +351,7 @@ function intersect(dataa, datab) { data: undefined }; } - let tmp2 = new Array(sizea < sizeb ? sizea : sizeb); + let tmp2 = new Array(Primitive_int.min(sizea, sizeb)); let k = Belt_SortArrayString.intersect(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0); return { data: Belt_internalAVLset.fromSortedArrayAux(tmp2, 0, k) diff --git a/lib/es6/belt_MutableStack.js b/lib/es6/belt_MutableStack.js index 122e06a0e5..eee6156e44 100644 --- a/lib/es6/belt_MutableStack.js +++ b/lib/es6/belt_MutableStack.js @@ -1,6 +1,6 @@ -import * as Caml_option from "./caml_option.js"; +import * as Primitive_option from "./primitive_option.js"; function make() { return { @@ -36,7 +36,7 @@ function topUndefined(s) { function top(s) { let x = s.root; if (x !== undefined) { - return Caml_option.some(x.head); + return Primitive_option.some(x.head); } } @@ -58,7 +58,7 @@ function pop(s) { let x = s.root; if (x !== undefined) { s.root = x.tail; - return Caml_option.some(x.head); + return Primitive_option.some(x.head); } } diff --git a/lib/es6/belt_Option.js b/lib/es6/belt_Option.js index 318e5e749e..fddaddd7a1 100644 --- a/lib/es6/belt_Option.js +++ b/lib/es6/belt_Option.js @@ -1,9 +1,9 @@ -import * as Caml_option from "./caml_option.js"; +import * as Primitive_option from "./primitive_option.js"; function keep(opt, p) { - if (opt !== undefined && p(Caml_option.valFromOption(opt))) { + if (opt !== undefined && p(Primitive_option.valFromOption(opt))) { return opt; } @@ -11,14 +11,14 @@ function keep(opt, p) { function forEach(opt, f) { if (opt !== undefined) { - return f(Caml_option.valFromOption(opt)); + return f(Primitive_option.valFromOption(opt)); } } function getExn(x) { if (x !== undefined) { - return Caml_option.valFromOption(x); + return Primitive_option.valFromOption(x); } throw { RE_EXN_ID: "Not_found", @@ -28,7 +28,7 @@ function getExn(x) { function mapWithDefault(opt, $$default, f) { if (opt !== undefined) { - return f(Caml_option.valFromOption(opt)); + return f(Primitive_option.valFromOption(opt)); } else { return $$default; } @@ -36,21 +36,21 @@ function mapWithDefault(opt, $$default, f) { function map(opt, f) { if (opt !== undefined) { - return Caml_option.some(f(Caml_option.valFromOption(opt))); + return Primitive_option.some(f(Primitive_option.valFromOption(opt))); } } function flatMap(opt, f) { if (opt !== undefined) { - return f(Caml_option.valFromOption(opt)); + return f(Primitive_option.valFromOption(opt)); } } function getWithDefault(opt, $$default) { if (opt !== undefined) { - return Caml_option.valFromOption(opt); + return Primitive_option.valFromOption(opt); } else { return $$default; } @@ -75,7 +75,7 @@ function isNone(x) { function eq(a, b, f) { if (a !== undefined) { if (b !== undefined) { - return f(Caml_option.valFromOption(a), Caml_option.valFromOption(b)); + return f(Primitive_option.valFromOption(a), Primitive_option.valFromOption(b)); } else { return false; } @@ -87,7 +87,7 @@ function eq(a, b, f) { function cmp(a, b, f) { if (a !== undefined) { if (b !== undefined) { - return f(Caml_option.valFromOption(a), Caml_option.valFromOption(b)); + return f(Primitive_option.valFromOption(a), Primitive_option.valFromOption(b)); } else { return 1; } diff --git a/lib/es6/belt_internalAVLset.js b/lib/es6/belt_internalAVLset.js index 1306dda6c3..4357ac887d 100644 --- a/lib/es6/belt_internalAVLset.js +++ b/lib/es6/belt_internalAVLset.js @@ -1,7 +1,8 @@ -import * as Caml_option from "./caml_option.js"; +import * as Primitive_int from "./primitive_int.js"; import * as Belt_SortArray from "./belt_SortArray.js"; +import * as Primitive_option from "./primitive_option.js"; function copy(n) { if (n !== undefined) { @@ -95,7 +96,7 @@ function min0Aux(_n) { function minimum(n) { if (n !== undefined) { - return Caml_option.some(min0Aux(n)); + return Primitive_option.some(min0Aux(n)); } } @@ -121,7 +122,7 @@ function max0Aux(_n) { function maximum(n) { if (n !== undefined) { - return Caml_option.some(max0Aux(n)); + return Primitive_option.some(max0Aux(n)); } } @@ -664,7 +665,7 @@ function get(_n, x, cmp) { let v = n.v; let c = cmp(x, v); if (c === 0) { - return Caml_option.some(v); + return Primitive_option.some(v); } _n = c < 0 ? n.l : n.r; continue; @@ -714,15 +715,11 @@ function rotateWithLeftChild(k2) { let hlk2 = n !== undefined ? n.h : 0; let n$1 = k2.r; let hrk2 = n$1 !== undefined ? n$1.h : 0; - k2.h = ( - hlk2 > hrk2 ? hlk2 : hrk2 - ) + 1 | 0; + k2.h = Primitive_int.max(hlk2, hrk2) + 1 | 0; let n$2 = k1.l; let hlk1 = n$2 !== undefined ? n$2.h : 0; let hk2 = k2.h; - k1.h = ( - hlk1 > hk2 ? hlk1 : hk2 - ) + 1 | 0; + k1.h = Primitive_int.max(hlk1, hk2) + 1 | 0; return k1; } @@ -734,15 +731,11 @@ function rotateWithRightChild(k1) { let hlk1 = n !== undefined ? n.h : 0; let n$1 = k1.r; let hrk1 = n$1 !== undefined ? n$1.h : 0; - k1.h = ( - hlk1 > hrk1 ? hlk1 : hrk1 - ) + 1 | 0; + k1.h = Primitive_int.max(hlk1, hrk1) + 1 | 0; let n$2 = k2.r; let hrk2 = n$2 !== undefined ? n$2.h : 0; let hk1 = k1.h; - k2.h = ( - hrk2 > hk1 ? hrk2 : hk1 - ) + 1 | 0; + k2.h = Primitive_int.max(hrk2, hk1) + 1 | 0; return k2; } @@ -765,9 +758,7 @@ function heightUpdateMutate(t) { let hlt = n !== undefined ? n.h : 0; let n$1 = t.r; let hrt = n$1 !== undefined ? n$1.h : 0; - t.h = ( - hlt > hrt ? hlt : hrt - ) + 1 | 0; + t.h = Primitive_int.max(hlt, hrt) + 1 | 0; return t; } @@ -794,9 +785,7 @@ function balMutate(nt) { return heightUpdateMutate(doubleWithRightChild(nt)); } } - nt.h = ( - hl > hr ? hl : hr - ) + 1 | 0; + nt.h = Primitive_int.max(hl, hr) + 1 | 0; return nt; } diff --git a/lib/es6/belt_internalAVLtree.js b/lib/es6/belt_internalAVLtree.js index 37ee7a6a2f..3642cb9647 100644 --- a/lib/es6/belt_internalAVLtree.js +++ b/lib/es6/belt_internalAVLtree.js @@ -1,7 +1,8 @@ -import * as Caml_option from "./caml_option.js"; +import * as Primitive_int from "./primitive_int.js"; import * as Belt_SortArray from "./belt_SortArray.js"; +import * as Primitive_option from "./primitive_option.js"; function treeHeight(n) { if (n !== undefined) { @@ -117,7 +118,7 @@ function minKey0Aux(_n) { function minKey(n) { if (n !== undefined) { - return Caml_option.some(minKey0Aux(n)); + return Primitive_option.some(minKey0Aux(n)); } } @@ -143,7 +144,7 @@ function maxKey0Aux(_n) { function maxKey(n) { if (n !== undefined) { - return Caml_option.some(maxKey0Aux(n)); + return Primitive_option.some(maxKey0Aux(n)); } } @@ -426,7 +427,7 @@ function concat(t1, t2) { function concatOrJoin(t1, v, d, t2) { if (d !== undefined) { - return join(t1, v, Caml_option.valFromOption(d), t2); + return join(t1, v, Primitive_option.valFromOption(d), t2); } else { return concat(t1, t2); } @@ -458,7 +459,7 @@ function keepMap(n, p) { let pvd = p(v, d); let newRight = keepMap(n.r, p); if (pvd !== undefined) { - return join(newLeft, v, Caml_option.valFromOption(pvd), newRight); + return join(newLeft, v, Primitive_option.valFromOption(pvd), newRight); } else { return concat(newLeft, newRight); } @@ -813,7 +814,7 @@ function get(_n, x, cmp) { let v = n.k; let c = cmp(x, v); if (c === 0) { - return Caml_option.some(n.v); + return Primitive_option.some(n.v); } _n = c < 0 ? n.l : n.r; continue; @@ -893,14 +894,10 @@ function rotateWithLeftChild(k2) { k1.r = k2; let hlk2 = treeHeight(k2.l); let hrk2 = treeHeight(k2.r); - k2.h = ( - hlk2 > hrk2 ? hlk2 : hrk2 - ) + 1 | 0; + k2.h = Primitive_int.max(hlk2, hrk2) + 1 | 0; let hlk1 = treeHeight(k1.l); let hk2 = k2.h; - k1.h = ( - hlk1 > hk2 ? hlk1 : hk2 - ) + 1 | 0; + k1.h = Primitive_int.max(hlk1, hk2) + 1 | 0; return k1; } @@ -910,14 +907,10 @@ function rotateWithRightChild(k1) { k2.l = k1; let hlk1 = treeHeight(k1.l); let hrk1 = treeHeight(k1.r); - k1.h = ( - hlk1 > hrk1 ? hlk1 : hrk1 - ) + 1 | 0; + k1.h = Primitive_int.max(hlk1, hrk1) + 1 | 0; let hrk2 = treeHeight(k2.r); let hk1 = k1.h; - k2.h = ( - hrk2 > hk1 ? hrk2 : hk1 - ) + 1 | 0; + k2.h = Primitive_int.max(hrk2, hk1) + 1 | 0; return k2; } @@ -938,9 +931,7 @@ function doubleWithRightChild(k2) { function heightUpdateMutate(t) { let hlt = treeHeight(t.l); let hrt = treeHeight(t.r); - t.h = ( - hlt > hrt ? hlt : hrt - ) + 1 | 0; + t.h = Primitive_int.max(hlt, hrt) + 1 | 0; return t; } @@ -967,9 +958,7 @@ function balMutate(nt) { return heightUpdateMutate(doubleWithRightChild(nt)); } } - nt.h = ( - hl > hr ? hl : hr - ) + 1 | 0; + nt.h = Primitive_int.max(hl, hr) + 1 | 0; return nt; } diff --git a/lib/es6/belt_internalBuckets.js b/lib/es6/belt_internalBuckets.js index 6d6027ff47..57962d0866 100644 --- a/lib/es6/belt_internalBuckets.js +++ b/lib/es6/belt_internalBuckets.js @@ -1,7 +1,8 @@ import * as Belt_Array from "./belt_Array.js"; -import * as Caml_option from "./caml_option.js"; +import * as Primitive_int from "./primitive_int.js"; +import * as Primitive_option from "./primitive_option.js"; function copyAuxCont(_c, _prec) { while (true) { @@ -110,11 +111,7 @@ function reduce(h, init, f) { function getMaxBucketLength(h) { return Belt_Array.reduce(h.buckets, 0, (m, b) => { let len = bucketLength(0, b); - if (m > len) { - return m; - } else { - return len; - } + return Primitive_int.max(m, len); }); } @@ -149,7 +146,7 @@ function filterMapInplaceBucket(f, h, i, _prec, _cell) { } else { h.buckets[i] = cell; } - cell.value = Caml_option.valFromOption(data); + cell.value = Primitive_option.valFromOption(data); if (n === undefined) { cell.next = n; return; diff --git a/lib/es6/belt_internalMapInt.js b/lib/es6/belt_internalMapInt.js index 4c3042dabb..5c5560017f 100644 --- a/lib/es6/belt_internalMapInt.js +++ b/lib/es6/belt_internalMapInt.js @@ -1,8 +1,8 @@ -import * as Caml from "./caml.js"; -import * as Caml_option from "./caml_option.js"; +import * as Primitive_int from "./primitive_int.js"; import * as Belt_SortArray from "./belt_SortArray.js"; +import * as Primitive_option from "./primitive_option.js"; import * as Belt_internalAVLtree from "./belt_internalAVLtree.js"; function add(t, x, data) { @@ -29,7 +29,7 @@ function get(_n, x) { } let v = n.k; if (x === v) { - return Caml_option.some(n.v); + return Primitive_option.some(n.v); } _n = x < v ? n.l : n.r; continue; @@ -137,7 +137,7 @@ function splitAux(x, n) { if (x === v) { return [ l, - Caml_option.some(d), + Primitive_option.some(d), r ]; } @@ -193,7 +193,7 @@ function merge(s1, s2, f) { let l1 = s1.l; let r1 = s1.r; let match = split(v1, s2); - return Belt_internalAVLtree.concatOrJoin(merge(l1, match[0], f), v1, f(v1, Caml_option.some(d1), match[1]), merge(r1, match[2], f)); + return Belt_internalAVLtree.concatOrJoin(merge(l1, match[0], f), v1, f(v1, Primitive_option.some(d1), match[1]), merge(r1, match[2], f)); } } else if (s2 === undefined) { @@ -204,7 +204,7 @@ function merge(s1, s2, f) { let l2 = s2.l; let r2 = s2.r; let match$1 = split(v2, s1); - return Belt_internalAVLtree.concatOrJoin(merge(match$1[0], l2, f), v2, f(v2, match$1[1], Caml_option.some(d2)), merge(match$1[2], r2, f)); + return Belt_internalAVLtree.concatOrJoin(merge(match$1[0], l2, f), v2, f(v2, match$1[1], Primitive_option.some(d2)), merge(match$1[2], r2, f)); } function compareAux(_e1, _e2, vcmp) { @@ -219,7 +219,7 @@ function compareAux(_e1, _e2, vcmp) { } let h2 = e2.hd; let h1 = e1.hd; - let c = Caml.int_compare(h1.k, h2.k); + let c = Primitive_int.compare(h1.k, h2.k); if (c !== 0) { return c; } diff --git a/lib/es6/belt_internalMapString.js b/lib/es6/belt_internalMapString.js index 3b98f118ff..f0d8e9c490 100644 --- a/lib/es6/belt_internalMapString.js +++ b/lib/es6/belt_internalMapString.js @@ -1,8 +1,8 @@ -import * as Caml from "./caml.js"; -import * as Caml_option from "./caml_option.js"; import * as Belt_SortArray from "./belt_SortArray.js"; +import * as Primitive_option from "./primitive_option.js"; +import * as Primitive_string from "./primitive_string.js"; import * as Belt_internalAVLtree from "./belt_internalAVLtree.js"; function add(t, x, data) { @@ -29,7 +29,7 @@ function get(_n, x) { } let v = n.k; if (x === v) { - return Caml_option.some(n.v); + return Primitive_option.some(n.v); } _n = x < v ? n.l : n.r; continue; @@ -137,7 +137,7 @@ function splitAux(x, n) { if (x === v) { return [ l, - Caml_option.some(d), + Primitive_option.some(d), r ]; } @@ -193,7 +193,7 @@ function merge(s1, s2, f) { let l1 = s1.l; let r1 = s1.r; let match = split(v1, s2); - return Belt_internalAVLtree.concatOrJoin(merge(l1, match[0], f), v1, f(v1, Caml_option.some(d1), match[1]), merge(r1, match[2], f)); + return Belt_internalAVLtree.concatOrJoin(merge(l1, match[0], f), v1, f(v1, Primitive_option.some(d1), match[1]), merge(r1, match[2], f)); } } else if (s2 === undefined) { @@ -204,7 +204,7 @@ function merge(s1, s2, f) { let l2 = s2.l; let r2 = s2.r; let match$1 = split(v2, s1); - return Belt_internalAVLtree.concatOrJoin(merge(match$1[0], l2, f), v2, f(v2, match$1[1], Caml_option.some(d2)), merge(match$1[2], r2, f)); + return Belt_internalAVLtree.concatOrJoin(merge(match$1[0], l2, f), v2, f(v2, match$1[1], Primitive_option.some(d2)), merge(match$1[2], r2, f)); } function compareAux(_e1, _e2, vcmp) { @@ -219,7 +219,7 @@ function compareAux(_e1, _e2, vcmp) { } let h2 = e2.hd; let h1 = e1.hd; - let c = Caml.string_compare(h1.k, h2.k); + let c = Primitive_string.compare(h1.k, h2.k); if (c !== 0) { return c; } diff --git a/lib/es6/belt_internalSetBuckets.js b/lib/es6/belt_internalSetBuckets.js index f98cc4c595..1e642f47d5 100644 --- a/lib/es6/belt_internalSetBuckets.js +++ b/lib/es6/belt_internalSetBuckets.js @@ -1,6 +1,19 @@ import * as Belt_Array from "./belt_Array.js"; +import * as Primitive_int from "./primitive_int.js"; + +function copyBucket(c) { + if (c === undefined) { + return c; + } + let head = { + key: c.key, + next: undefined + }; + copyAuxCont(c.next, head); + return head; +} function copyAuxCont(_c, _prec) { while (true) { @@ -20,18 +33,6 @@ function copyAuxCont(_c, _prec) { }; } -function copyBucket(c) { - if (c === undefined) { - return c; - } - let head = { - key: c.key, - next: undefined - }; - copyAuxCont(c.next, head); - return head; -} - function copyBuckets(buckets) { let len = buckets.length; let newBuckets = new Array(len); @@ -136,11 +137,7 @@ function reduce(h, init, f) { function getMaxBucketLength(h) { return Belt_Array.reduce(h.buckets, 0, (m, b) => { let len = bucketLength(0, b); - if (m > len) { - return m; - } else { - return len; - } + return Primitive_int.max(m, len); }); } diff --git a/lib/es6/buffer.js b/lib/es6/buffer.js deleted file mode 100644 index 09ba8d632d..0000000000 --- a/lib/es6/buffer.js +++ /dev/null @@ -1,476 +0,0 @@ - - -import * as Bytes from "./bytes.js"; -import * as $$String from "./string.js"; -import * as Caml_bytes from "./caml_bytes.js"; -import * as Caml_string from "./caml_string.js"; - -function create(n) { - let n$1 = n < 1 ? 1 : n; - let s = Caml_bytes.create(n$1); - return { - buffer: s, - position: 0, - length: n$1, - initial_buffer: s - }; -} - -function contents(b) { - return Bytes.sub_string(b.buffer, 0, b.position); -} - -function to_bytes(b) { - return Bytes.sub(b.buffer, 0, b.position); -} - -function sub(b, ofs, len) { - if (ofs < 0 || len < 0 || ofs > (b.position - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Buffer.sub", - Error: new Error() - }; - } - return Bytes.sub_string(b.buffer, ofs, len); -} - -function blit(src, srcoff, dst, dstoff, len) { - if (len < 0 || srcoff < 0 || srcoff > (src.position - len | 0) || dstoff < 0 || dstoff > (dst.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Buffer.blit", - Error: new Error() - }; - } - Bytes.blit(src.buffer, srcoff, dst, dstoff, len); -} - -function nth(b, ofs) { - if (ofs < 0 || ofs >= b.position) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Buffer.nth", - Error: new Error() - }; - } - return b.buffer[ofs]; -} - -function length(b) { - return b.position; -} - -function clear(b) { - b.position = 0; -} - -function reset(b) { - b.position = 0; - b.buffer = b.initial_buffer; - b.length = b.buffer.length; -} - -function resize(b, more) { - let len = b.length; - let new_len = len; - while ((b.position + more | 0) > new_len) { - new_len = (new_len << 1); - }; - let new_buffer = Caml_bytes.create(new_len); - Bytes.blit(b.buffer, 0, new_buffer, 0, b.position); - b.buffer = new_buffer; - b.length = new_len; -} - -function add_char(b, c) { - let pos = b.position; - if (pos >= b.length) { - resize(b, 1); - } - b.buffer[pos] = c; - b.position = pos + 1 | 0; -} - -function add_utf_8_uchar(b, u) { - let u$1 = u; - if (u$1 < 0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "buffer.res", - 98, - 18 - ], - Error: new Error() - }; - } - if (u$1 <= 127) { - return add_char(b, u$1); - } - if (u$1 <= 2047) { - let pos = b.position; - if ((pos + 2 | 0) > b.length) { - resize(b, 2); - } - b.buffer[pos] = 192 | (u$1 >>> 6); - b.buffer[pos + 1 | 0] = 128 | u$1 & 63; - b.position = pos + 2 | 0; - return; - } - if (u$1 <= 65535) { - let pos$1 = b.position; - if ((pos$1 + 3 | 0) > b.length) { - resize(b, 3); - } - b.buffer[pos$1] = 224 | (u$1 >>> 12); - b.buffer[pos$1 + 1 | 0] = 128 | (u$1 >>> 6) & 63; - b.buffer[pos$1 + 2 | 0] = 128 | u$1 & 63; - b.position = pos$1 + 3 | 0; - return; - } - if (u$1 <= 1114111) { - let pos$2 = b.position; - if ((pos$2 + 4 | 0) > b.length) { - resize(b, 4); - } - b.buffer[pos$2] = 240 | (u$1 >>> 18); - b.buffer[pos$2 + 1 | 0] = 128 | (u$1 >>> 12) & 63; - b.buffer[pos$2 + 2 | 0] = 128 | (u$1 >>> 6) & 63; - b.buffer[pos$2 + 3 | 0] = 128 | u$1 & 63; - b.position = pos$2 + 4 | 0; - return; - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "buffer.res", - 127, - 9 - ], - Error: new Error() - }; -} - -function add_utf_16be_uchar(b, u) { - let u$1 = u; - if (u$1 < 0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "buffer.res", - 132, - 18 - ], - Error: new Error() - }; - } - if (u$1 <= 65535) { - let pos = b.position; - if ((pos + 2 | 0) > b.length) { - resize(b, 2); - } - b.buffer[pos] = (u$1 >>> 8); - b.buffer[pos + 1 | 0] = u$1 & 255; - b.position = pos + 2 | 0; - return; - } - if (u$1 <= 1114111) { - let u$p = u$1 - 65536 | 0; - let hi = 55296 | (u$p >>> 10); - let lo = 56320 | u$p & 1023; - let pos$1 = b.position; - if ((pos$1 + 4 | 0) > b.length) { - resize(b, 4); - } - b.buffer[pos$1] = (hi >>> 8); - b.buffer[pos$1 + 1 | 0] = hi & 255; - b.buffer[pos$1 + 2 | 0] = (lo >>> 8); - b.buffer[pos$1 + 3 | 0] = lo & 255; - b.position = pos$1 + 4 | 0; - return; - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "buffer.res", - 154, - 9 - ], - Error: new Error() - }; -} - -function add_utf_16le_uchar(b, u) { - let u$1 = u; - if (u$1 < 0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "buffer.res", - 159, - 18 - ], - Error: new Error() - }; - } - if (u$1 <= 65535) { - let pos = b.position; - if ((pos + 2 | 0) > b.length) { - resize(b, 2); - } - b.buffer[pos] = u$1 & 255; - b.buffer[pos + 1 | 0] = (u$1 >>> 8); - b.position = pos + 2 | 0; - return; - } - if (u$1 <= 1114111) { - let u$p = u$1 - 65536 | 0; - let hi = 55296 | (u$p >>> 10); - let lo = 56320 | u$p & 1023; - let pos$1 = b.position; - if ((pos$1 + 4 | 0) > b.length) { - resize(b, 4); - } - b.buffer[pos$1] = hi & 255; - b.buffer[pos$1 + 1 | 0] = (hi >>> 8); - b.buffer[pos$1 + 2 | 0] = lo & 255; - b.buffer[pos$1 + 3 | 0] = (lo >>> 8); - b.position = pos$1 + 4 | 0; - return; - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "buffer.res", - 181, - 9 - ], - Error: new Error() - }; -} - -function add_substring(b, s, offset, len) { - if (offset < 0 || len < 0 || offset > (s.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Buffer.add_substring/add_subbytes", - Error: new Error() - }; - } - let new_position = b.position + len | 0; - if (new_position > b.length) { - resize(b, len); - } - Bytes.blit_string(s, offset, b.buffer, b.position, len); - b.position = new_position; -} - -function add_subbytes(b, s, offset, len) { - add_substring(b, Bytes.unsafe_to_string(s), offset, len); -} - -function add_string(b, s) { - let len = s.length; - let new_position = b.position + len | 0; - if (new_position > b.length) { - resize(b, len); - } - Bytes.blit_string(s, 0, b.buffer, b.position, len); - b.position = new_position; -} - -function add_bytes(b, s) { - add_string(b, Bytes.unsafe_to_string(s)); -} - -function add_buffer(b, bs) { - add_subbytes(b, bs.buffer, 0, bs.position); -} - -function closing(param) { - if (param === 40) { - return /* ')' */41; - } - if (param === 123) { - return /* '}' */125; - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "buffer.res", - 216, - 9 - ], - Error: new Error() - }; -} - -function advance_to_closing(opening, closing, k, s, start) { - let _k = k; - let _i = start; - let lim = s.length; - while (true) { - let i = _i; - let k$1 = _k; - if (i >= lim) { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - if (Caml_string.get(s, i) === opening) { - _i = i + 1 | 0; - _k = k$1 + 1 | 0; - continue; - } - if (Caml_string.get(s, i) === closing) { - if (k$1 === 0) { - return i; - } - _i = i + 1 | 0; - _k = k$1 - 1 | 0; - continue; - } - _i = i + 1 | 0; - continue; - }; -} - -function advance_to_non_alpha(s, start) { - let _i = start; - let lim = s.length; - while (true) { - let i = _i; - if (i >= lim) { - return lim; - } - let match = Caml_string.get(s, i); - if (match >= 91) { - if (match >= 97) { - if (match >= 123) { - return i; - } - - } else if (match !== 95) { - return i; - } - - } else if (match >= 58) { - if (match < 65) { - return i; - } - - } else if (match < 48) { - return i; - } - _i = i + 1 | 0; - continue; - }; -} - -function find_ident(s, start, lim) { - if (start >= lim) { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let c = Caml_string.get(s, start); - if (c !== 40 && c !== 123) { - let stop = advance_to_non_alpha(s, start + 1 | 0); - return [ - $$String.sub(s, start, stop - start | 0), - stop - ]; - } - let new_start = start + 1 | 0; - let stop$1 = advance_to_closing(c, closing(c), 0, s, new_start); - return [ - $$String.sub(s, new_start, (stop$1 - start | 0) - 1 | 0), - stop$1 + 1 | 0 - ]; -} - -function add_substitute(b, f, s) { - let lim = s.length; - let _previous = /* ' ' */32; - let _i = 0; - while (true) { - let i = _i; - let previous = _previous; - if (i >= lim) { - if (previous === /* '\\' */92) { - return add_char(b, previous); - } else { - return; - } - } - let current = Caml_string.get(s, i); - if (current !== 36) { - if (previous === /* '\\' */92) { - add_char(b, /* '\\' */92); - add_char(b, current); - _i = i + 1 | 0; - _previous = /* ' ' */32; - continue; - } - if (current !== 92) { - add_char(b, current); - _i = i + 1 | 0; - _previous = current; - continue; - } - _i = i + 1 | 0; - _previous = current; - continue; - } - if (previous === /* '\\' */92) { - add_char(b, current); - _i = i + 1 | 0; - _previous = /* ' ' */32; - continue; - } - let j = i + 1 | 0; - let match = find_ident(s, j, lim); - add_string(b, f(match[0])); - _i = match[1]; - _previous = /* ' ' */32; - continue; - }; -} - -function truncate(b, len) { - if (len < 0 || len > b.position) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Buffer.truncate", - Error: new Error() - }; - } - b.position = len; -} - -export { - create, - contents, - to_bytes, - sub, - blit, - nth, - length, - clear, - reset, - add_char, - add_utf_8_uchar, - add_utf_16le_uchar, - add_utf_16be_uchar, - add_string, - add_bytes, - add_substring, - add_subbytes, - add_substitute, - add_buffer, - truncate, -} -/* No side effect */ diff --git a/lib/es6/bytes.js b/lib/es6/bytes.js deleted file mode 100644 index 518ae3c793..0000000000 --- a/lib/es6/bytes.js +++ /dev/null @@ -1,699 +0,0 @@ - - -import * as Caml from "./caml.js"; -import * as Char from "./char.js"; -import * as Caml_bytes from "./caml_bytes.js"; -import * as Caml_js_exceptions from "./caml_js_exceptions.js"; - -function unsafe_fill(s, i, l, c) { - if (l <= 0) { - return; - } - for (let k = i, k_finish = l + i | 0; k < k_finish; ++k) { - s[k] = c; - } -} - -function unsafe_blit(s1, i1, s2, i2, len) { - if (len <= 0) { - return; - } - if (s1 === s2) { - if (i1 < i2) { - let range_a = (s1.length - i2 | 0) - 1 | 0; - let range_b = len - 1 | 0; - let range = range_a > range_b ? range_b : range_a; - for (let j = range; j >= 0; --j) { - s1[i2 + j | 0] = s1[i1 + j | 0]; - } - return; - } - if (i1 <= i2) { - return; - } - let range_a$1 = (s1.length - i1 | 0) - 1 | 0; - let range_b$1 = len - 1 | 0; - let range$1 = range_a$1 > range_b$1 ? range_b$1 : range_a$1; - for (let k = 0; k <= range$1; ++k) { - s1[i2 + k | 0] = s1[i1 + k | 0]; - } - return; - } - let off1 = s1.length - i1 | 0; - if (len <= off1) { - for (let i = 0; i < len; ++i) { - s2[i2 + i | 0] = s1[i1 + i | 0]; - } - return; - } - for (let i$1 = 0; i$1 < off1; ++i$1) { - s2[i2 + i$1 | 0] = s1[i1 + i$1 | 0]; - } - for (let i$2 = off1; i$2 < len; ++i$2) { - s2[i2 + i$2 | 0] = /* '\000' */0; - } -} - -function make(n, c) { - let s = Caml_bytes.create(n); - unsafe_fill(s, 0, n, c); - return s; -} - -function init(n, f) { - let s = Caml_bytes.create(n); - for (let i = 0; i < n; ++i) { - s[i] = f(i); - } - return s; -} - -let empty = []; - -function copy(s) { - let len = s.length; - let r = Caml_bytes.create(len); - unsafe_blit(s, 0, r, 0, len); - return r; -} - -function to_string(a) { - let i = 0; - let len = a.length; - let s = ""; - let s_len = len; - if (i === 0 && len <= 4096 && len === a.length) { - return String.fromCharCode.apply(null, a); - } - let offset = 0; - while (s_len > 0) { - let next = s_len < 1024 ? s_len : 1024; - let tmp_bytes = new Array(next); - for (let k = 0; k < next; ++k) { - tmp_bytes[k] = a[k + offset | 0]; - } - s = s + String.fromCharCode.apply(null, tmp_bytes); - s_len = s_len - next | 0; - offset = offset + next | 0; - }; - return s; -} - -function of_string(s) { - let len = s.length; - let res = new Array(len); - for (let i = 0; i < len; ++i) { - res[i] = s.codePointAt(i); - } - return res; -} - -function sub(s, ofs, len) { - if (ofs < 0 || len < 0 || ofs > (s.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.sub / Bytes.sub", - Error: new Error() - }; - } - let r = Caml_bytes.create(len); - unsafe_blit(s, ofs, r, 0, len); - return r; -} - -function sub_string(b, ofs, len) { - return to_string(sub(b, ofs, len)); -} - -function $plus$plus(a, b) { - let c = a + b | 0; - let match = a < 0; - let match$1 = b < 0; - let match$2 = c < 0; - if (match) { - if (!match$1) { - return c; - } - if (match$2) { - return c; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Bytes.extend", - Error: new Error() - }; - } - if (match$1) { - return c; - } - if (match$2) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Bytes.extend", - Error: new Error() - }; - } - return c; -} - -function extend(s, left, right) { - let len = $plus$plus($plus$plus(s.length, left), right); - let r = Caml_bytes.create(len); - let match = left < 0 ? [ - -left | 0, - 0 - ] : [ - 0, - left - ]; - let dstoff = match[1]; - let srcoff = match[0]; - let cpylen = Caml.int_min(s.length - srcoff | 0, len - dstoff | 0); - if (cpylen > 0) { - unsafe_blit(s, srcoff, r, dstoff, cpylen); - } - return r; -} - -function fill(s, ofs, len, c) { - if (ofs < 0 || len < 0 || ofs > (s.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.fill / Bytes.fill", - Error: new Error() - }; - } - unsafe_fill(s, ofs, len, c); -} - -function blit(s1, ofs1, s2, ofs2, len) { - if (len < 0 || ofs1 < 0 || ofs1 > (s1.length - len | 0) || ofs2 < 0 || ofs2 > (s2.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Bytes.blit", - Error: new Error() - }; - } - unsafe_blit(s1, ofs1, s2, ofs2, len); -} - -function blit_string(s1, ofs1, s2, ofs2, len) { - if (len < 0 || ofs1 < 0 || ofs1 > (s1.length - len | 0) || ofs2 < 0 || ofs2 > (s2.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.blit / Bytes.blit_string", - Error: new Error() - }; - } - if (len <= 0) { - return; - } - let off1 = s1.length - ofs1 | 0; - if (len <= off1) { - for (let i = 0; i < len; ++i) { - s2[ofs2 + i | 0] = s1.codePointAt(ofs1 + i | 0); - } - return; - } - for (let i$1 = 0; i$1 < off1; ++i$1) { - s2[ofs2 + i$1 | 0] = s1.codePointAt(ofs1 + i$1 | 0); - } - for (let i$2 = off1; i$2 < len; ++i$2) { - s2[ofs2 + i$2 | 0] = /* '\000' */0; - } -} - -function iter(f, a) { - for (let i = 0, i_finish = a.length; i < i_finish; ++i) { - f(a[i]); - } -} - -function iteri(f, a) { - for (let i = 0, i_finish = a.length; i < i_finish; ++i) { - f(i, a[i]); - } -} - -function ensure_ge(x, y) { - if (x >= y) { - return x; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Bytes.concat", - Error: new Error() - }; -} - -function sum_lengths(_acc, seplen, _param) { - while (true) { - let param = _param; - let acc = _acc; - if (!param) { - return acc; - } - let tl = param.tl; - let hd = param.hd; - if (!tl) { - return hd.length + acc | 0; - } - _param = tl; - _acc = ensure_ge((hd.length + seplen | 0) + acc | 0, acc); - continue; - }; -} - -function concat(sep, param) { - if (!param) { - return empty; - } - let seplen = sep.length; - let dst = Caml_bytes.create(sum_lengths(0, seplen, param)); - let _pos = 0; - let _param = param; - while (true) { - let param$1 = _param; - let pos = _pos; - if (!param$1) { - return dst; - } - let tl = param$1.tl; - let hd = param$1.hd; - if (tl) { - unsafe_blit(hd, 0, dst, pos, hd.length); - unsafe_blit(sep, 0, dst, pos + hd.length | 0, seplen); - _param = tl; - _pos = (pos + hd.length | 0) + seplen | 0; - continue; - } - unsafe_blit(hd, 0, dst, pos, hd.length); - return dst; - }; -} - -function cat(s1, s2) { - let l1 = s1.length; - let l2 = s2.length; - let r = Caml_bytes.create(l1 + l2 | 0); - unsafe_blit(s1, 0, r, 0, l1); - unsafe_blit(s2, 0, r, l1, l2); - return r; -} - -function is_space(param) { - if (param > 13 || param < 9) { - return param === 32; - } else { - return param !== 11; - } -} - -function trim(s) { - let len = s.length; - let i = 0; - while (i < len && is_space(s[i])) { - i = i + 1 | 0; - }; - let j = len - 1 | 0; - while (j >= i && is_space(s[j])) { - j = j - 1 | 0; - }; - if (j >= i) { - return sub(s, i, (j - i | 0) + 1 | 0); - } else { - return empty; - } -} - -function escaped(s) { - let n = 0; - for (let i = 0, i_finish = s.length; i < i_finish; ++i) { - let match = s[i]; - n = n + ( - match >= 32 ? ( - match > 92 || match < 34 ? ( - match >= 127 ? 4 : 1 - ) : ( - match > 91 || match < 35 ? 2 : 1 - ) - ) : ( - match >= 11 ? ( - match !== 13 ? 4 : 2 - ) : ( - match >= 8 ? 2 : 4 - ) - ) - ) | 0; - } - if (n === s.length) { - return copy(s); - } - let s$p = Caml_bytes.create(n); - n = 0; - for (let i$1 = 0, i_finish$1 = s.length; i$1 < i_finish$1; ++i$1) { - let c = s[i$1]; - let exit = 0; - if (c >= 35) { - if (c !== 92) { - if (c >= 127) { - exit = 1; - } else { - s$p[n] = c; - } - } else { - exit = 2; - } - } else if (c >= 32) { - if (c >= 34) { - exit = 2; - } else { - s$p[n] = c; - } - } else if (c >= 14) { - exit = 1; - } else { - switch (c) { - case 8 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 'b' */98; - break; - case 9 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 't' */116; - break; - case 10 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 'n' */110; - break; - case 0 : - case 1 : - case 2 : - case 3 : - case 4 : - case 5 : - case 6 : - case 7 : - case 11 : - case 12 : - exit = 1; - break; - case 13 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 'r' */114; - break; - } - } - switch (exit) { - case 1 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = 48 + (c / 100 | 0) | 0; - n = n + 1 | 0; - s$p[n] = 48 + (c / 10 | 0) % 10 | 0; - n = n + 1 | 0; - s$p[n] = 48 + c % 10 | 0; - break; - case 2 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = c; - break; - } - n = n + 1 | 0; - } - return s$p; -} - -function map(f, s) { - let l = s.length; - if (l === 0) { - return s; - } - let r = Caml_bytes.create(l); - for (let i = 0; i < l; ++i) { - r[i] = f(s[i]); - } - return r; -} - -function mapi(f, s) { - let l = s.length; - if (l === 0) { - return s; - } - let r = Caml_bytes.create(l); - for (let i = 0; i < l; ++i) { - r[i] = f(i, s[i]); - } - return r; -} - -function uppercase_ascii(s) { - return map(Char.uppercase_ascii, s); -} - -function lowercase_ascii(s) { - return map(Char.lowercase_ascii, s); -} - -function apply1(f, s) { - if (s.length === 0) { - return s; - } - let r = copy(s); - r[0] = f(s[0]); - return r; -} - -function capitalize_ascii(s) { - return apply1(Char.uppercase_ascii, s); -} - -function uncapitalize_ascii(s) { - return apply1(Char.lowercase_ascii, s); -} - -function index_rec(s, lim, _i, c) { - while (true) { - let i = _i; - if (i >= lim) { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - if (s[i] === c) { - return i; - } - _i = i + 1 | 0; - continue; - }; -} - -function index(s, c) { - return index_rec(s, s.length, 0, c); -} - -function index_rec_opt(s, lim, _i, c) { - while (true) { - let i = _i; - if (i >= lim) { - return; - } - if (s[i] === c) { - return i; - } - _i = i + 1 | 0; - continue; - }; -} - -function index_opt(s, c) { - return index_rec_opt(s, s.length, 0, c); -} - -function index_from(s, i, c) { - let l = s.length; - if (i < 0 || i > l) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from / Bytes.index_from", - Error: new Error() - }; - } - return index_rec(s, l, i, c); -} - -function index_from_opt(s, i, c) { - let l = s.length; - if (i < 0 || i > l) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from_opt / Bytes.index_from_opt", - Error: new Error() - }; - } - return index_rec_opt(s, l, i, c); -} - -function rindex_rec(s, _i, c) { - while (true) { - let i = _i; - if (i < 0) { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - if (s[i] === c) { - return i; - } - _i = i - 1 | 0; - continue; - }; -} - -function rindex(s, c) { - return rindex_rec(s, s.length - 1 | 0, c); -} - -function rindex_from(s, i, c) { - if (i < -1 || i >= s.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from / Bytes.rindex_from", - Error: new Error() - }; - } - return rindex_rec(s, i, c); -} - -function rindex_rec_opt(s, _i, c) { - while (true) { - let i = _i; - if (i < 0) { - return; - } - if (s[i] === c) { - return i; - } - _i = i - 1 | 0; - continue; - }; -} - -function rindex_opt(s, c) { - return rindex_rec_opt(s, s.length - 1 | 0, c); -} - -function rindex_from_opt(s, i, c) { - if (i < -1 || i >= s.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from_opt / Bytes.rindex_from_opt", - Error: new Error() - }; - } - return rindex_rec_opt(s, i, c); -} - -function contains_from(s, i, c) { - let l = s.length; - if (i < 0 || i > l) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.contains_from / Bytes.contains_from", - Error: new Error() - }; - } - try { - index_rec(s, l, i, c); - return true; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - return false; - } - throw exn; - } -} - -function contains(s, c) { - return contains_from(s, 0, c); -} - -function rcontains_from(s, i, c) { - if (i < 0 || i >= s.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.rcontains_from / Bytes.rcontains_from", - Error: new Error() - }; - } - try { - rindex_rec(s, i, c); - return true; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - return false; - } - throw exn; - } -} - -let compare = Caml_bytes.bytes_compare; - -let equal = Caml_bytes.bytes_equal; - -let unsafe_to_string = to_string; - -let unsafe_of_string = of_string; - -export { - make, - init, - empty, - copy, - of_string, - to_string, - sub, - sub_string, - extend, - fill, - blit, - blit_string, - concat, - cat, - iter, - iteri, - map, - mapi, - trim, - escaped, - index, - index_opt, - rindex, - rindex_opt, - index_from, - index_from_opt, - rindex_from, - rindex_from_opt, - contains, - contains_from, - rcontains_from, - uppercase_ascii, - lowercase_ascii, - capitalize_ascii, - uncapitalize_ascii, - compare, - equal, - unsafe_to_string, - unsafe_of_string, -} -/* No side effect */ diff --git a/lib/es6/bytesLabels.js b/lib/es6/bytesLabels.js deleted file mode 100644 index 518ae3c793..0000000000 --- a/lib/es6/bytesLabels.js +++ /dev/null @@ -1,699 +0,0 @@ - - -import * as Caml from "./caml.js"; -import * as Char from "./char.js"; -import * as Caml_bytes from "./caml_bytes.js"; -import * as Caml_js_exceptions from "./caml_js_exceptions.js"; - -function unsafe_fill(s, i, l, c) { - if (l <= 0) { - return; - } - for (let k = i, k_finish = l + i | 0; k < k_finish; ++k) { - s[k] = c; - } -} - -function unsafe_blit(s1, i1, s2, i2, len) { - if (len <= 0) { - return; - } - if (s1 === s2) { - if (i1 < i2) { - let range_a = (s1.length - i2 | 0) - 1 | 0; - let range_b = len - 1 | 0; - let range = range_a > range_b ? range_b : range_a; - for (let j = range; j >= 0; --j) { - s1[i2 + j | 0] = s1[i1 + j | 0]; - } - return; - } - if (i1 <= i2) { - return; - } - let range_a$1 = (s1.length - i1 | 0) - 1 | 0; - let range_b$1 = len - 1 | 0; - let range$1 = range_a$1 > range_b$1 ? range_b$1 : range_a$1; - for (let k = 0; k <= range$1; ++k) { - s1[i2 + k | 0] = s1[i1 + k | 0]; - } - return; - } - let off1 = s1.length - i1 | 0; - if (len <= off1) { - for (let i = 0; i < len; ++i) { - s2[i2 + i | 0] = s1[i1 + i | 0]; - } - return; - } - for (let i$1 = 0; i$1 < off1; ++i$1) { - s2[i2 + i$1 | 0] = s1[i1 + i$1 | 0]; - } - for (let i$2 = off1; i$2 < len; ++i$2) { - s2[i2 + i$2 | 0] = /* '\000' */0; - } -} - -function make(n, c) { - let s = Caml_bytes.create(n); - unsafe_fill(s, 0, n, c); - return s; -} - -function init(n, f) { - let s = Caml_bytes.create(n); - for (let i = 0; i < n; ++i) { - s[i] = f(i); - } - return s; -} - -let empty = []; - -function copy(s) { - let len = s.length; - let r = Caml_bytes.create(len); - unsafe_blit(s, 0, r, 0, len); - return r; -} - -function to_string(a) { - let i = 0; - let len = a.length; - let s = ""; - let s_len = len; - if (i === 0 && len <= 4096 && len === a.length) { - return String.fromCharCode.apply(null, a); - } - let offset = 0; - while (s_len > 0) { - let next = s_len < 1024 ? s_len : 1024; - let tmp_bytes = new Array(next); - for (let k = 0; k < next; ++k) { - tmp_bytes[k] = a[k + offset | 0]; - } - s = s + String.fromCharCode.apply(null, tmp_bytes); - s_len = s_len - next | 0; - offset = offset + next | 0; - }; - return s; -} - -function of_string(s) { - let len = s.length; - let res = new Array(len); - for (let i = 0; i < len; ++i) { - res[i] = s.codePointAt(i); - } - return res; -} - -function sub(s, ofs, len) { - if (ofs < 0 || len < 0 || ofs > (s.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.sub / Bytes.sub", - Error: new Error() - }; - } - let r = Caml_bytes.create(len); - unsafe_blit(s, ofs, r, 0, len); - return r; -} - -function sub_string(b, ofs, len) { - return to_string(sub(b, ofs, len)); -} - -function $plus$plus(a, b) { - let c = a + b | 0; - let match = a < 0; - let match$1 = b < 0; - let match$2 = c < 0; - if (match) { - if (!match$1) { - return c; - } - if (match$2) { - return c; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Bytes.extend", - Error: new Error() - }; - } - if (match$1) { - return c; - } - if (match$2) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Bytes.extend", - Error: new Error() - }; - } - return c; -} - -function extend(s, left, right) { - let len = $plus$plus($plus$plus(s.length, left), right); - let r = Caml_bytes.create(len); - let match = left < 0 ? [ - -left | 0, - 0 - ] : [ - 0, - left - ]; - let dstoff = match[1]; - let srcoff = match[0]; - let cpylen = Caml.int_min(s.length - srcoff | 0, len - dstoff | 0); - if (cpylen > 0) { - unsafe_blit(s, srcoff, r, dstoff, cpylen); - } - return r; -} - -function fill(s, ofs, len, c) { - if (ofs < 0 || len < 0 || ofs > (s.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.fill / Bytes.fill", - Error: new Error() - }; - } - unsafe_fill(s, ofs, len, c); -} - -function blit(s1, ofs1, s2, ofs2, len) { - if (len < 0 || ofs1 < 0 || ofs1 > (s1.length - len | 0) || ofs2 < 0 || ofs2 > (s2.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Bytes.blit", - Error: new Error() - }; - } - unsafe_blit(s1, ofs1, s2, ofs2, len); -} - -function blit_string(s1, ofs1, s2, ofs2, len) { - if (len < 0 || ofs1 < 0 || ofs1 > (s1.length - len | 0) || ofs2 < 0 || ofs2 > (s2.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.blit / Bytes.blit_string", - Error: new Error() - }; - } - if (len <= 0) { - return; - } - let off1 = s1.length - ofs1 | 0; - if (len <= off1) { - for (let i = 0; i < len; ++i) { - s2[ofs2 + i | 0] = s1.codePointAt(ofs1 + i | 0); - } - return; - } - for (let i$1 = 0; i$1 < off1; ++i$1) { - s2[ofs2 + i$1 | 0] = s1.codePointAt(ofs1 + i$1 | 0); - } - for (let i$2 = off1; i$2 < len; ++i$2) { - s2[ofs2 + i$2 | 0] = /* '\000' */0; - } -} - -function iter(f, a) { - for (let i = 0, i_finish = a.length; i < i_finish; ++i) { - f(a[i]); - } -} - -function iteri(f, a) { - for (let i = 0, i_finish = a.length; i < i_finish; ++i) { - f(i, a[i]); - } -} - -function ensure_ge(x, y) { - if (x >= y) { - return x; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Bytes.concat", - Error: new Error() - }; -} - -function sum_lengths(_acc, seplen, _param) { - while (true) { - let param = _param; - let acc = _acc; - if (!param) { - return acc; - } - let tl = param.tl; - let hd = param.hd; - if (!tl) { - return hd.length + acc | 0; - } - _param = tl; - _acc = ensure_ge((hd.length + seplen | 0) + acc | 0, acc); - continue; - }; -} - -function concat(sep, param) { - if (!param) { - return empty; - } - let seplen = sep.length; - let dst = Caml_bytes.create(sum_lengths(0, seplen, param)); - let _pos = 0; - let _param = param; - while (true) { - let param$1 = _param; - let pos = _pos; - if (!param$1) { - return dst; - } - let tl = param$1.tl; - let hd = param$1.hd; - if (tl) { - unsafe_blit(hd, 0, dst, pos, hd.length); - unsafe_blit(sep, 0, dst, pos + hd.length | 0, seplen); - _param = tl; - _pos = (pos + hd.length | 0) + seplen | 0; - continue; - } - unsafe_blit(hd, 0, dst, pos, hd.length); - return dst; - }; -} - -function cat(s1, s2) { - let l1 = s1.length; - let l2 = s2.length; - let r = Caml_bytes.create(l1 + l2 | 0); - unsafe_blit(s1, 0, r, 0, l1); - unsafe_blit(s2, 0, r, l1, l2); - return r; -} - -function is_space(param) { - if (param > 13 || param < 9) { - return param === 32; - } else { - return param !== 11; - } -} - -function trim(s) { - let len = s.length; - let i = 0; - while (i < len && is_space(s[i])) { - i = i + 1 | 0; - }; - let j = len - 1 | 0; - while (j >= i && is_space(s[j])) { - j = j - 1 | 0; - }; - if (j >= i) { - return sub(s, i, (j - i | 0) + 1 | 0); - } else { - return empty; - } -} - -function escaped(s) { - let n = 0; - for (let i = 0, i_finish = s.length; i < i_finish; ++i) { - let match = s[i]; - n = n + ( - match >= 32 ? ( - match > 92 || match < 34 ? ( - match >= 127 ? 4 : 1 - ) : ( - match > 91 || match < 35 ? 2 : 1 - ) - ) : ( - match >= 11 ? ( - match !== 13 ? 4 : 2 - ) : ( - match >= 8 ? 2 : 4 - ) - ) - ) | 0; - } - if (n === s.length) { - return copy(s); - } - let s$p = Caml_bytes.create(n); - n = 0; - for (let i$1 = 0, i_finish$1 = s.length; i$1 < i_finish$1; ++i$1) { - let c = s[i$1]; - let exit = 0; - if (c >= 35) { - if (c !== 92) { - if (c >= 127) { - exit = 1; - } else { - s$p[n] = c; - } - } else { - exit = 2; - } - } else if (c >= 32) { - if (c >= 34) { - exit = 2; - } else { - s$p[n] = c; - } - } else if (c >= 14) { - exit = 1; - } else { - switch (c) { - case 8 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 'b' */98; - break; - case 9 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 't' */116; - break; - case 10 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 'n' */110; - break; - case 0 : - case 1 : - case 2 : - case 3 : - case 4 : - case 5 : - case 6 : - case 7 : - case 11 : - case 12 : - exit = 1; - break; - case 13 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 'r' */114; - break; - } - } - switch (exit) { - case 1 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = 48 + (c / 100 | 0) | 0; - n = n + 1 | 0; - s$p[n] = 48 + (c / 10 | 0) % 10 | 0; - n = n + 1 | 0; - s$p[n] = 48 + c % 10 | 0; - break; - case 2 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = c; - break; - } - n = n + 1 | 0; - } - return s$p; -} - -function map(f, s) { - let l = s.length; - if (l === 0) { - return s; - } - let r = Caml_bytes.create(l); - for (let i = 0; i < l; ++i) { - r[i] = f(s[i]); - } - return r; -} - -function mapi(f, s) { - let l = s.length; - if (l === 0) { - return s; - } - let r = Caml_bytes.create(l); - for (let i = 0; i < l; ++i) { - r[i] = f(i, s[i]); - } - return r; -} - -function uppercase_ascii(s) { - return map(Char.uppercase_ascii, s); -} - -function lowercase_ascii(s) { - return map(Char.lowercase_ascii, s); -} - -function apply1(f, s) { - if (s.length === 0) { - return s; - } - let r = copy(s); - r[0] = f(s[0]); - return r; -} - -function capitalize_ascii(s) { - return apply1(Char.uppercase_ascii, s); -} - -function uncapitalize_ascii(s) { - return apply1(Char.lowercase_ascii, s); -} - -function index_rec(s, lim, _i, c) { - while (true) { - let i = _i; - if (i >= lim) { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - if (s[i] === c) { - return i; - } - _i = i + 1 | 0; - continue; - }; -} - -function index(s, c) { - return index_rec(s, s.length, 0, c); -} - -function index_rec_opt(s, lim, _i, c) { - while (true) { - let i = _i; - if (i >= lim) { - return; - } - if (s[i] === c) { - return i; - } - _i = i + 1 | 0; - continue; - }; -} - -function index_opt(s, c) { - return index_rec_opt(s, s.length, 0, c); -} - -function index_from(s, i, c) { - let l = s.length; - if (i < 0 || i > l) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from / Bytes.index_from", - Error: new Error() - }; - } - return index_rec(s, l, i, c); -} - -function index_from_opt(s, i, c) { - let l = s.length; - if (i < 0 || i > l) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from_opt / Bytes.index_from_opt", - Error: new Error() - }; - } - return index_rec_opt(s, l, i, c); -} - -function rindex_rec(s, _i, c) { - while (true) { - let i = _i; - if (i < 0) { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - if (s[i] === c) { - return i; - } - _i = i - 1 | 0; - continue; - }; -} - -function rindex(s, c) { - return rindex_rec(s, s.length - 1 | 0, c); -} - -function rindex_from(s, i, c) { - if (i < -1 || i >= s.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from / Bytes.rindex_from", - Error: new Error() - }; - } - return rindex_rec(s, i, c); -} - -function rindex_rec_opt(s, _i, c) { - while (true) { - let i = _i; - if (i < 0) { - return; - } - if (s[i] === c) { - return i; - } - _i = i - 1 | 0; - continue; - }; -} - -function rindex_opt(s, c) { - return rindex_rec_opt(s, s.length - 1 | 0, c); -} - -function rindex_from_opt(s, i, c) { - if (i < -1 || i >= s.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from_opt / Bytes.rindex_from_opt", - Error: new Error() - }; - } - return rindex_rec_opt(s, i, c); -} - -function contains_from(s, i, c) { - let l = s.length; - if (i < 0 || i > l) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.contains_from / Bytes.contains_from", - Error: new Error() - }; - } - try { - index_rec(s, l, i, c); - return true; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - return false; - } - throw exn; - } -} - -function contains(s, c) { - return contains_from(s, 0, c); -} - -function rcontains_from(s, i, c) { - if (i < 0 || i >= s.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.rcontains_from / Bytes.rcontains_from", - Error: new Error() - }; - } - try { - rindex_rec(s, i, c); - return true; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - return false; - } - throw exn; - } -} - -let compare = Caml_bytes.bytes_compare; - -let equal = Caml_bytes.bytes_equal; - -let unsafe_to_string = to_string; - -let unsafe_of_string = of_string; - -export { - make, - init, - empty, - copy, - of_string, - to_string, - sub, - sub_string, - extend, - fill, - blit, - blit_string, - concat, - cat, - iter, - iteri, - map, - mapi, - trim, - escaped, - index, - index_opt, - rindex, - rindex_opt, - index_from, - index_from_opt, - rindex_from, - rindex_from_opt, - contains, - contains_from, - rcontains_from, - uppercase_ascii, - lowercase_ascii, - capitalize_ascii, - uncapitalize_ascii, - compare, - equal, - unsafe_to_string, - unsafe_of_string, -} -/* No side effect */ diff --git a/lib/es6/callback.js b/lib/es6/callback.js deleted file mode 100644 index 9b2784be9b..0000000000 --- a/lib/es6/callback.js +++ /dev/null @@ -1,16 +0,0 @@ - - - -function register(param, param$1) { - -} - -function register_exception(param, param$1) { - -} - -export { - register, - register_exception, -} -/* No side effect */ diff --git a/lib/es6/caml.js b/lib/es6/caml.js deleted file mode 100644 index a85e2555f3..0000000000 --- a/lib/es6/caml.js +++ /dev/null @@ -1,207 +0,0 @@ - - - -function int_compare(x, y) { - if (x < y) { - return -1; - } else if (x === y) { - return 0; - } else { - return 1; - } -} - -function bool_compare(x, y) { - if (x) { - if (y) { - return 0; - } else { - return 1; - } - } else if (y) { - return -1; - } else { - return 0; - } -} - -function float_compare(x, y) { - if (x === y) { - return 0; - } else if (x < y) { - return -1; - } else if (x > y || x === x) { - return 1; - } else if (y === y) { - return -1; - } else { - return 0; - } -} - -function bigint_compare(x, y) { - if (x < y) { - return -1; - } else if (x === y) { - return 0; - } else { - return 1; - } -} - -function string_compare(s1, s2) { - if (s1 === s2) { - return 0; - } else if (s1 < s2) { - return -1; - } else { - return 1; - } -} - -function bool_min(x, y) { - if (x) { - return y; - } else { - return x; - } -} - -function int_min(x, y) { - if (x < y) { - return x; - } else { - return y; - } -} - -function float_min(x, y) { - if (x < y) { - return x; - } else { - return y; - } -} - -function string_min(x, y) { - if (x < y) { - return x; - } else { - return y; - } -} - -function bool_max(x, y) { - if (x) { - return x; - } else { - return y; - } -} - -function int_max(x, y) { - if (x > y) { - return x; - } else { - return y; - } -} - -function float_max(x, y) { - if (x > y) { - return x; - } else { - return y; - } -} - -function string_max(x, y) { - if (x > y) { - return x; - } else { - return y; - } -} - -function i64_eq(x, y) { - if (x[1] === y[1]) { - return x[0] === y[0]; - } else { - return false; - } -} - -function i64_ge(param, param$1) { - let other_hi = param$1[0]; - let hi = param[0]; - if (hi > other_hi) { - return true; - } else if (hi < other_hi) { - return false; - } else { - return param[1] >= param$1[1]; - } -} - -function i64_neq(x, y) { - return !i64_eq(x, y); -} - -function i64_lt(x, y) { - return !i64_ge(x, y); -} - -function i64_gt(x, y) { - if (x[0] > y[0]) { - return true; - } else if (x[0] < y[0]) { - return false; - } else { - return x[1] > y[1]; - } -} - -function i64_le(x, y) { - return !i64_gt(x, y); -} - -function i64_min(x, y) { - if (i64_ge(x, y)) { - return y; - } else { - return x; - } -} - -function i64_max(x, y) { - if (i64_gt(x, y)) { - return x; - } else { - return y; - } -} - -export { - int_compare, - bool_compare, - float_compare, - bigint_compare, - string_compare, - bool_min, - int_min, - float_min, - string_min, - bool_max, - int_max, - float_max, - string_max, - i64_eq, - i64_neq, - i64_lt, - i64_gt, - i64_le, - i64_ge, - i64_min, - i64_max, -} -/* No side effect */ diff --git a/lib/es6/caml_array.js b/lib/es6/caml_array.js deleted file mode 100644 index c9d8e3c8b0..0000000000 --- a/lib/es6/caml_array.js +++ /dev/null @@ -1,122 +0,0 @@ - - - -function sub(x, offset, len) { - let result = new Array(len); - let j = 0; - let i = offset; - while (j < len) { - result[j] = x[i]; - j = j + 1 | 0; - i = i + 1 | 0; - }; - return result; -} - -function len(_acc, _l) { - while (true) { - let l = _l; - let acc = _acc; - if (!l) { - return acc; - } - _l = l.tl; - _acc = l.hd.length + acc | 0; - continue; - }; -} - -function fill(arr, _i, _l) { - while (true) { - let l = _l; - let i = _i; - if (!l) { - return; - } - let x = l.hd; - let l$1 = x.length; - let k = i; - let j = 0; - while (j < l$1) { - arr[k] = x[j]; - k = k + 1 | 0; - j = j + 1 | 0; - }; - _l = l.tl; - _i = k; - continue; - }; -} - -function concat(l) { - let v = len(0, l); - let result = new Array(v); - fill(result, 0, l); - return result; -} - -function set(xs, index, newval) { - if (index < 0 || index >= xs.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "index out of bounds", - Error: new Error() - }; - } - xs[index] = newval; -} - -function get(xs, index) { - if (index < 0 || index >= xs.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "index out of bounds", - Error: new Error() - }; - } - return xs[index]; -} - -function make(len, init) { - let b = new Array(len); - for (let i = 0; i < len; ++i) { - b[i] = init; - } - return b; -} - -function make_float(len) { - let b = new Array(len); - for (let i = 0; i < len; ++i) { - b[i] = 0; - } - return b; -} - -function blit(a1, i1, a2, i2, len) { - if (i2 <= i1) { - for (let j = 0; j < len; ++j) { - a2[j + i2 | 0] = a1[j + i1 | 0]; - } - return; - } - for (let j$1 = len - 1 | 0; j$1 >= 0; --j$1) { - a2[j$1 + i2 | 0] = a1[j$1 + i1 | 0]; - } -} - -function dup(prim) { - return prim.slice(0); -} - -export { - dup, - sub, - concat, - make, - make_float, - blit, - get, - set, -} -/* No side effect */ diff --git a/lib/es6/caml_bytes.js b/lib/es6/caml_bytes.js deleted file mode 100644 index 86d784b8cf..0000000000 --- a/lib/es6/caml_bytes.js +++ /dev/null @@ -1,122 +0,0 @@ - - - -function set(s, i, ch) { - if (i < 0 || i >= s.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "index out of bounds", - Error: new Error() - }; - } - s[i] = ch; -} - -function get(s, i) { - if (i < 0 || i >= s.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "index out of bounds", - Error: new Error() - }; - } - return s[i]; -} - -function create(len) { - if (len < 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.create", - Error: new Error() - }; - } - let result = new Array(len); - for (let i = 0; i < len; ++i) { - result[i] = /* '\000' */0; - } - return result; -} - -function bytes_compare_aux(s1, s2, _off, len, def) { - while (true) { - let off = _off; - if (off >= len) { - return def; - } - let a = s1[off]; - let b = s2[off]; - if (a > b) { - return 1; - } - if (a < b) { - return -1; - } - _off = off + 1 | 0; - continue; - }; -} - -function bytes_compare(s1, s2) { - let len1 = s1.length; - let len2 = s2.length; - if (len1 === len2) { - return bytes_compare_aux(s1, s2, 0, len1, 0); - } else if (len1 < len2) { - return bytes_compare_aux(s1, s2, 0, len1, -1); - } else { - return bytes_compare_aux(s1, s2, 0, len2, 1); - } -} - -function bytes_equal(s1, s2) { - let len1 = s1.length; - let len2 = s2.length; - if (len1 === len2) { - let _off = 0; - while (true) { - let off = _off; - if (off === len1) { - return true; - } - let a = s1[off]; - let b = s2[off]; - if (a !== b) { - return false; - } - _off = off + 1 | 0; - continue; - }; - } else { - return false; - } -} - -function bytes_greaterthan(s1, s2) { - return bytes_compare(s1, s2) > 0; -} - -function bytes_greaterequal(s1, s2) { - return bytes_compare(s1, s2) >= 0; -} - -function bytes_lessthan(s1, s2) { - return bytes_compare(s1, s2) < 0; -} - -function bytes_lessequal(s1, s2) { - return bytes_compare(s1, s2) <= 0; -} - -export { - create, - get, - set, - bytes_compare, - bytes_greaterthan, - bytes_greaterequal, - bytes_lessthan, - bytes_lessequal, - bytes_equal, -} -/* No side effect */ diff --git a/lib/es6/caml_float.js b/lib/es6/caml_float.js deleted file mode 100644 index 4cd67eddf0..0000000000 --- a/lib/es6/caml_float.js +++ /dev/null @@ -1,129 +0,0 @@ - - - -let int_float_of_bits = (function(x){ - return new Float32Array(new Int32Array([x]).buffer)[0] - }); - -let int_bits_of_float = (function(x){ - return new Int32Array(new Float32Array([x]).buffer)[0] -}); - -function modf_float(x) { - if (!isFinite(x)) { - if (isNaN(x)) { - return [ - NaN, - NaN - ]; - } else { - return [ - 1 / x, - x - ]; - } - } - let neg = 1 / x < 0; - let x$1 = Math.abs(x); - let i = Math.floor(x$1); - let f = x$1 - i; - if (neg) { - return [ - - f, - - i - ]; - } else { - return [ - f, - i - ]; - } -} - -function ldexp_float(x, exp) { - let x$p = x; - let exp$p = exp; - if (exp$p > 1023) { - exp$p = exp$p - 1023; - x$p = x$p * Math.pow(2, 1023); - if (exp$p > 1023) { - exp$p = exp$p - 1023; - x$p = x$p * Math.pow(2, 1023); - } - - } else if (exp$p < -1023) { - exp$p = exp$p + 1023; - x$p = x$p * Math.pow(2, -1023); - } - return x$p * Math.pow(2, exp$p); -} - -function frexp_float(x) { - if (x === 0 || !isFinite(x)) { - return [ - x, - 0 - ]; - } - let neg = x < 0; - let x$p = Math.abs(x); - let exp = Math.floor(Math.LOG2E * Math.log(x$p)) + 1; - x$p = x$p * Math.pow(2, - exp); - if (x$p < 0.5) { - x$p = x$p * 2; - exp = exp - 1; - } - if (neg) { - x$p = - x$p; - } - return [ - x$p, - exp | 0 - ]; -} - -function copysign_float(x, y) { - let x$1 = Math.abs(x); - let y$1 = y === 0 ? 1 / y : y; - if (y$1 < 0) { - return - x$1; - } else { - return x$1; - } -} - -function expm1_float(x) { - let y = Math.exp(x); - let z = y - 1; - if (Math.abs(x) > 1) { - return z; - } else if (z === 0) { - return x; - } else { - return x * z / Math.log(y); - } -} - -function hypot_float(x, y) { - let x0 = Math.abs(x); - let y0 = Math.abs(y); - let a = x0 > y0 ? x0 : y0; - let b = ( - x0 < y0 ? x0 : y0 - ) / ( - a !== 0 ? a : 1 - ); - return a * Math.sqrt(1 + b * b); -} - -export { - int_float_of_bits, - int_bits_of_float, - modf_float, - ldexp_float, - frexp_float, - copysign_float, - expm1_float, - hypot_float, -} -/* No side effect */ diff --git a/lib/es6/caml_format.js b/lib/es6/caml_format.js deleted file mode 100644 index 4a806955d6..0000000000 --- a/lib/es6/caml_format.js +++ /dev/null @@ -1,787 +0,0 @@ - - -import * as Caml from "./caml.js"; -import * as Caml_int64 from "./caml_int64.js"; - -function parse_digit(c) { - if (c >= 65) { - if (c >= 97) { - if (c >= 123) { - return -1; - } else { - return c - 87 | 0; - } - } else if (c >= 91) { - return -1; - } else { - return c - 55 | 0; - } - } else if (c > 57 || c < 48) { - return -1; - } else { - return c - 48 | 0; - } -} - -function int_of_string_base(x) { - switch (x) { - case "Oct" : - return 8; - case "Hex" : - return 16; - case "Dec" : - return 10; - case "Bin" : - return 2; - } -} - -function parse_sign_and_base(s) { - let sign = 1; - let base = "Dec"; - let i = 0; - let match = s.codePointAt(i); - switch (match) { - case 43 : - i = i + 1 | 0; - break; - case 45 : - sign = -1; - i = i + 1 | 0; - break; - } - if (s.codePointAt(i) === /* '0' */48) { - let match$1 = s.codePointAt(i + 1 | 0); - if (match$1 >= 89) { - if (match$1 >= 111) { - if (match$1 < 121) { - switch (match$1) { - case 111 : - base = "Oct"; - i = i + 2 | 0; - break; - case 117 : - i = i + 2 | 0; - break; - case 112 : - case 113 : - case 114 : - case 115 : - case 116 : - case 118 : - case 119 : - break; - case 120 : - base = "Hex"; - i = i + 2 | 0; - break; - } - } - - } else if (match$1 === 98) { - base = "Bin"; - i = i + 2 | 0; - } - - } else if (match$1 !== 66) { - if (match$1 >= 79) { - switch (match$1) { - case 79 : - base = "Oct"; - i = i + 2 | 0; - break; - case 85 : - i = i + 2 | 0; - break; - case 80 : - case 81 : - case 82 : - case 83 : - case 84 : - case 86 : - case 87 : - break; - case 88 : - base = "Hex"; - i = i + 2 | 0; - break; - } - } - - } else { - base = "Bin"; - i = i + 2 | 0; - } - } - return [ - i, - sign, - base - ]; -} - -function int_of_string(s) { - let match = parse_sign_and_base(s); - let i = match[0]; - let base = int_of_string_base(match[2]); - let threshold = 4294967295; - let len = s.length; - let c = i < len ? s.codePointAt(i) : /* '\000' */0; - let d = parse_digit(c); - if (d < 0 || d >= base) { - throw { - RE_EXN_ID: "Failure", - _1: "int_of_string", - Error: new Error() - }; - } - let aux = (_acc, _k) => { - while (true) { - let k = _k; - let acc = _acc; - if (k === len) { - return acc; - } - let a = s.codePointAt(k); - if (a === /* '_' */95) { - _k = k + 1 | 0; - continue; - } - let v = parse_digit(a); - if (v < 0 || v >= base) { - throw { - RE_EXN_ID: "Failure", - _1: "int_of_string", - Error: new Error() - }; - } - let acc$1 = base * acc + v; - if (acc$1 > threshold) { - throw { - RE_EXN_ID: "Failure", - _1: "int_of_string", - Error: new Error() - }; - } - _k = k + 1 | 0; - _acc = acc$1; - continue; - }; - }; - let res = match[1] * aux(d, i + 1 | 0); - let or_res = res | 0; - if (base === 10 && res !== or_res) { - throw { - RE_EXN_ID: "Failure", - _1: "int_of_string", - Error: new Error() - }; - } - return or_res; -} - -function int64_of_string(s) { - let match = parse_sign_and_base(s); - let hbase = match[2]; - let i = match[0]; - let base = Caml_int64.of_int32(int_of_string_base(hbase)); - let sign = Caml_int64.of_int32(match[1]); - let threshold; - switch (hbase) { - case "Oct" : - threshold = [ - 536870911, - 4294967295 - ]; - break; - case "Hex" : - threshold = [ - 268435455, - 4294967295 - ]; - break; - case "Dec" : - threshold = [ - 429496729, - 2576980377 - ]; - break; - case "Bin" : - threshold = Caml_int64.max_int; - break; - } - let len = s.length; - let c = i < len ? s.codePointAt(i) : /* '\000' */0; - let d = Caml_int64.of_int32(parse_digit(c)); - if (Caml.i64_lt(d, Caml_int64.zero) || Caml.i64_ge(d, base)) { - throw { - RE_EXN_ID: "Failure", - _1: "int64_of_string", - Error: new Error() - }; - } - let aux = (_acc, _k) => { - while (true) { - let k = _k; - let acc = _acc; - if (k === len) { - return acc; - } - let a = s.codePointAt(k); - if (a === /* '_' */95) { - _k = k + 1 | 0; - continue; - } - let v = Caml_int64.of_int32(parse_digit(a)); - if (Caml.i64_lt(v, Caml_int64.zero) || Caml.i64_ge(v, base) || Caml.i64_gt(acc, threshold)) { - throw { - RE_EXN_ID: "Failure", - _1: "int64_of_string", - Error: new Error() - }; - } - let acc$1 = Caml_int64.add(Caml_int64.mul(base, acc), v); - _k = k + 1 | 0; - _acc = acc$1; - continue; - }; - }; - let res = Caml_int64.mul(sign, aux(d, i + 1 | 0)); - let or_res = Caml_int64.or_(res, Caml_int64.zero); - if (Caml.i64_eq(base, [ - 0, - 10 - ]) && Caml.i64_neq(res, or_res)) { - throw { - RE_EXN_ID: "Failure", - _1: "int64_of_string", - Error: new Error() - }; - } - return or_res; -} - -function int_of_base(x) { - switch (x) { - case "Oct" : - return 8; - case "Hex" : - return 16; - case "Dec" : - return 10; - } -} - -function lowercase(c) { - if (c >= /* 'A' */65 && c <= /* 'Z' */90 || c >= /* '\192' */192 && c <= /* '\214' */214 || c >= /* '\216' */216 && c <= /* '\222' */222) { - return c + 32 | 0; - } else { - return c; - } -} - -function parse_format(fmt) { - let len = fmt.length; - if (len > 31) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "format_int: format too long", - Error: new Error() - }; - } - let f = { - justify: "+", - signstyle: "-", - filter: " ", - alternate: false, - base: "Dec", - signedconv: false, - width: 0, - uppercase: false, - sign: 1, - prec: -1, - conv: "f" - }; - let _i = 0; - while (true) { - let i = _i; - if (i >= len) { - return f; - } - let c = fmt.codePointAt(i); - let exit = 0; - if (c >= 69) { - if (c >= 88) { - if (c >= 121) { - exit = 1; - } else { - switch (c) { - case 88 : - f.base = "Hex"; - f.uppercase = true; - _i = i + 1 | 0; - continue; - case 101 : - case 102 : - case 103 : - exit = 5; - break; - case 100 : - case 105 : - exit = 4; - break; - case 111 : - f.base = "Oct"; - _i = i + 1 | 0; - continue; - case 117 : - f.base = "Dec"; - _i = i + 1 | 0; - continue; - case 89 : - case 90 : - case 91 : - case 92 : - case 93 : - case 94 : - case 95 : - case 96 : - case 97 : - case 98 : - case 99 : - case 104 : - case 106 : - case 107 : - case 108 : - case 109 : - case 110 : - case 112 : - case 113 : - case 114 : - case 115 : - case 116 : - case 118 : - case 119 : - exit = 1; - break; - case 120 : - f.base = "Hex"; - _i = i + 1 | 0; - continue; - } - } - } else if (c >= 72) { - exit = 1; - } else { - f.signedconv = true; - f.uppercase = true; - f.conv = String.fromCharCode(lowercase(c)); - _i = i + 1 | 0; - continue; - } - } else { - switch (c) { - case 35 : - f.alternate = true; - _i = i + 1 | 0; - continue; - case 32 : - case 43 : - exit = 2; - break; - case 45 : - f.justify = "-"; - _i = i + 1 | 0; - continue; - case 46 : - f.prec = 0; - let j = i + 1 | 0; - while ((() => { - let w = fmt.codePointAt(j) - 48 | 0; - return w >= 0 && w <= 9; - })()) { - f.prec = (Math.imul(f.prec, 10) + fmt.codePointAt(j) | 0) - 48 | 0; - j = j + 1 | 0; - }; - _i = j; - continue; - case 48 : - f.filter = "0"; - _i = i + 1 | 0; - continue; - case 49 : - case 50 : - case 51 : - case 52 : - case 53 : - case 54 : - case 55 : - case 56 : - case 57 : - exit = 3; - break; - default: - exit = 1; - } - } - switch (exit) { - case 1 : - _i = i + 1 | 0; - continue; - case 2 : - f.signstyle = String.fromCharCode(c); - _i = i + 1 | 0; - continue; - case 3 : - f.width = 0; - let j$1 = i; - while ((() => { - let w = fmt.codePointAt(j$1) - 48 | 0; - return w >= 0 && w <= 9; - })()) { - f.width = (Math.imul(f.width, 10) + fmt.codePointAt(j$1) | 0) - 48 | 0; - j$1 = j$1 + 1 | 0; - }; - _i = j$1; - continue; - case 4 : - f.signedconv = true; - f.base = "Dec"; - _i = i + 1 | 0; - continue; - case 5 : - f.signedconv = true; - f.conv = String.fromCharCode(c); - _i = i + 1 | 0; - continue; - } - }; -} - -function finish_formatting(config, rawbuffer) { - let justify = config.justify; - let signstyle = config.signstyle; - let filter = config.filter; - let alternate = config.alternate; - let base = config.base; - let signedconv = config.signedconv; - let width = config.width; - let uppercase = config.uppercase; - let sign = config.sign; - let len = rawbuffer.length; - if (signedconv && (sign < 0 || signstyle !== "-")) { - len = len + 1 | 0; - } - if (alternate) { - if (base === "Oct") { - len = len + 1 | 0; - } else if (base === "Hex") { - len = len + 2 | 0; - } - - } - let buffer = ""; - if (justify === "+" && filter === " ") { - for (let _for = len; _for < width; ++_for) { - buffer = buffer + filter; - } - } - if (signedconv) { - if (sign < 0) { - buffer = buffer + "-"; - } else if (signstyle !== "-") { - buffer = buffer + signstyle; - } - - } - if (alternate && base === "Oct") { - buffer = buffer + "0"; - } - if (alternate && base === "Hex") { - buffer = buffer + "0x"; - } - if (justify === "+" && filter === "0") { - for (let _for$1 = len; _for$1 < width; ++_for$1) { - buffer = buffer + filter; - } - } - buffer = uppercase ? buffer + rawbuffer.toUpperCase() : buffer + rawbuffer; - if (justify === "-") { - for (let _for$2 = len; _for$2 < width; ++_for$2) { - buffer = buffer + " "; - } - } - return buffer; -} - -function format_int(fmt, i) { - if (fmt === "%d") { - return String(i); - } - let f = parse_format(fmt); - let i$1 = i < 0 ? ( - f.signedconv ? (f.sign = -1, (-i >>> 0)) : (i >>> 0) - ) : i; - let s = i$1.toString(int_of_base(f.base)); - if (f.prec >= 0) { - f.filter = " "; - let n = f.prec - s.length | 0; - if (n > 0) { - s = "0".repeat(n) + s; - } - - } - return finish_formatting(f, s); -} - -function dec_of_pos_int64(x) { - if (!Caml.i64_lt(x, Caml_int64.zero)) { - return Caml_int64.to_string(x); - } - let wbase = [ - 0, - 10 - ]; - let y = Caml_int64.discard_sign(x); - let match = Caml_int64.div_mod(y, wbase); - let match$1 = Caml_int64.div_mod(Caml_int64.add([ - 0, - 8 - ], match[1]), wbase); - let quotient = Caml_int64.add(Caml_int64.add([ - 214748364, - 3435973836 - ], match[0]), match$1[0]); - return Caml_int64.to_string(quotient) + "0123456789"[Caml_int64.to_int32(match$1[1])]; -} - -function oct_of_int64(x) { - let s = ""; - let wbase = [ - 0, - 8 - ]; - let cvtbl = "01234567"; - if (Caml.i64_lt(x, Caml_int64.zero)) { - let y = Caml_int64.discard_sign(x); - let match = Caml_int64.div_mod(y, wbase); - let quotient = Caml_int64.add([ - 268435456, - 0 - ], match[0]); - let modulus = match[1]; - s = cvtbl[Caml_int64.to_int32(modulus)] + s; - while (Caml.i64_neq(quotient, Caml_int64.zero)) { - let match$1 = Caml_int64.div_mod(quotient, wbase); - quotient = match$1[0]; - modulus = match$1[1]; - s = cvtbl[Caml_int64.to_int32(modulus)] + s; - }; - } else { - let match$2 = Caml_int64.div_mod(x, wbase); - let quotient$1 = match$2[0]; - let modulus$1 = match$2[1]; - s = cvtbl[Caml_int64.to_int32(modulus$1)] + s; - while (Caml.i64_neq(quotient$1, Caml_int64.zero)) { - let match$3 = Caml_int64.div_mod(quotient$1, wbase); - quotient$1 = match$3[0]; - modulus$1 = match$3[1]; - s = cvtbl[Caml_int64.to_int32(modulus$1)] + s; - }; - } - return s; -} - -function int64_format(fmt, x) { - if (fmt === "%d") { - return Caml_int64.to_string(x); - } - let f = parse_format(fmt); - let x$1 = f.signedconv && Caml.i64_lt(x, Caml_int64.zero) ? (f.sign = -1, Caml_int64.neg(x)) : x; - let match = f.base; - let s; - switch (match) { - case "Oct" : - s = oct_of_int64(x$1); - break; - case "Hex" : - s = Caml_int64.to_hex(x$1); - break; - case "Dec" : - s = dec_of_pos_int64(x$1); - break; - } - let fill_s; - if (f.prec >= 0) { - f.filter = " "; - let n = f.prec - s.length | 0; - fill_s = n > 0 ? "0".repeat(n) + s : s; - } else { - fill_s = s; - } - return finish_formatting(f, fill_s); -} - -function format_float(fmt, x) { - let f = parse_format(fmt); - let prec = f.prec < 0 ? 6 : f.prec; - let x$1 = x < 0 ? (f.sign = -1, - x) : x; - let s = ""; - if (isNaN(x$1)) { - s = "nan"; - f.filter = " "; - } else if (isFinite(x$1)) { - let match = f.conv; - switch (match) { - case "e" : - s = x$1.toExponential(prec); - let i = s.length; - if (s.codePointAt(i - 3 | 0) === /* 'e' */101) { - s = s.slice(0, i - 1 | 0) + ("0" + s.slice(i - 1 | 0)); - } - break; - case "f" : - s = x$1.toFixed(prec); - break; - case "g" : - let prec$1 = prec !== 0 ? prec : 1; - s = x$1.toExponential(prec$1 - 1 | 0); - let j = s.indexOf("e"); - let exp = Number(s.slice(j + 1 | 0)) | 0; - if (exp < -4 || x$1 >= 1e21 || x$1.toFixed().length > prec$1) { - let i$1 = j - 1 | 0; - while (s.codePointAt(i$1) === /* '0' */48) { - i$1 = i$1 - 1 | 0; - }; - if (s.codePointAt(i$1) === /* '.' */46) { - i$1 = i$1 - 1 | 0; - } - s = s.slice(0, i$1 + 1 | 0) + s.slice(j); - let i$2 = s.length; - if (s.codePointAt(i$2 - 3 | 0) === /* 'e' */101) { - s = s.slice(0, i$2 - 1 | 0) + ("0" + s.slice(i$2 - 1 | 0)); - } - - } else { - let p = prec$1; - if (exp < 0) { - p = p - (exp + 1 | 0) | 0; - s = x$1.toFixed(p); - } else { - while ((() => { - s = x$1.toFixed(p); - return s.length > (prec$1 + 1 | 0); - })()) { - p = p - 1 | 0; - }; - } - if (p !== 0) { - let k = s.length - 1 | 0; - while (s.codePointAt(k) === /* '0' */48) { - k = k - 1 | 0; - }; - if (s.codePointAt(k) === /* '.' */46) { - k = k - 1 | 0; - } - s = s.slice(0, k + 1 | 0); - } - - } - break; - } - } else { - s = "inf"; - f.filter = " "; - } - return finish_formatting(f, s); -} - -let hexstring_of_float = (function(x,prec,style){ - if (!isFinite(x)) { - if (isNaN(x)) return "nan"; - return x > 0 ? "infinity":"-infinity"; - } - var sign = (x==0 && 1/x == -Infinity)?1:(x>=0)?0:1; - if(sign) x = -x; - var exp = 0; - if (x == 0) { } - else if (x < 1) { - while (x < 1 && exp > -1022) { x *= 2; exp-- } - } else { - while (x >= 2) { x /= 2; exp++ } - } - var exp_sign = exp < 0 ? '' : '+'; - var sign_str = ''; - if (sign) sign_str = '-' - else { - switch(style){ - case 43 /* '+' */: sign_str = '+'; break; - case 32 /* ' ' */: sign_str = ' '; break; - default: break; - } - } - if (prec >= 0 && prec < 13) { - /* If a precision is given, and is small, round mantissa accordingly */ - var cst = Math.pow(2,prec * 4); - x = Math.round(x * cst) / cst; - } - var x_str = x.toString(16); - if(prec >= 0){ - var idx = x_str.indexOf('.'); - if(idx<0) { - x_str += '.' + '0'.repeat(prec); - } - else { - var size = idx+1+prec; - if(x_str.length < size) - x_str += '0'.repeat(size - x_str.length); - else - x_str = x_str.substr(0,size); - } - } - return (sign_str + '0x' + x_str + 'p' + exp_sign + exp.toString(10)); -}); - -let float_of_string = (function(s,exn){ - - var res = +s; - if ((s.length > 0) && (res === res)) - return res; - s = s.replace(/_/g, ""); - res = +s; - if (((s.length > 0) && (res === res)) || /^[+-]?nan$/i.test(s)) { - return res; - }; - var m = /^ *([+-]?)0x([0-9a-f]+)\.?([0-9a-f]*)p([+-]?[0-9]+)/i.exec(s); - // 1 2 3 4 - if(m){ - var m3 = m[3].replace(/0+$/,''); - var mantissa = parseInt(m[1] + m[2] + m3, 16); - var exponent = (m[4]|0) - 4*m3.length; - res = mantissa * Math.pow(2, exponent); - return res; - } - if (/^\+?inf(inity)?$/i.test(s)) - return Infinity; - if (/^-inf(inity)?$/i.test(s)) - return -Infinity; - throw exn; -}); - -function float_of_string$1(s) { - return float_of_string(s, { - RE_EXN_ID: "Failure", - _1: "float_of_string" - }); -} - -export { - format_float, - hexstring_of_float, - format_int, - float_of_string$1 as float_of_string, - int64_format, - int_of_string, - int64_of_string, -} -/* No side effect */ diff --git a/lib/es6/caml_hash.js b/lib/es6/caml_hash.js deleted file mode 100644 index c238fbd048..0000000000 --- a/lib/es6/caml_hash.js +++ /dev/null @@ -1,99 +0,0 @@ - - -import * as Caml_hash_primitive from "./caml_hash_primitive.js"; - -function push_back(q, v) { - let cell = { - content: v, - next: undefined - }; - let last = q.last; - if (last !== undefined) { - q.length = q.length + 1 | 0; - last.next = cell; - q.last = cell; - } else { - q.length = 1; - q.first = cell; - q.last = cell; - } -} - -function unsafe_pop(q) { - let cell = q.first; - let next = cell.next; - if (next === undefined) { - q.length = 0; - q.first = undefined; - q.last = undefined; - } else { - q.length = q.length - 1 | 0; - q.first = next; - } - return cell.content; -} - -function hash(count, _limit, seed, obj) { - let s = seed; - if (typeof obj === "number") { - let u = obj | 0; - s = Caml_hash_primitive.hash_mix_int(s, (u + u | 0) + 1 | 0); - return Caml_hash_primitive.hash_final_mix(s); - } - if (typeof obj === "string") { - s = Caml_hash_primitive.hash_mix_string(s, obj); - return Caml_hash_primitive.hash_final_mix(s); - } - let queue = { - length: 0, - first: undefined, - last: undefined - }; - let num = count; - push_back(queue, obj); - num = num - 1 | 0; - while (queue.length !== 0 && num > 0) { - let obj$1 = unsafe_pop(queue); - if (typeof obj$1 === "number") { - let u$1 = obj$1 | 0; - s = Caml_hash_primitive.hash_mix_int(s, (u$1 + u$1 | 0) + 1 | 0); - num = num - 1 | 0; - } else if (typeof obj$1 === "string") { - s = Caml_hash_primitive.hash_mix_string(s, obj$1); - num = num - 1 | 0; - } else if (typeof obj$1 !== "boolean" && typeof obj$1 !== "undefined" && typeof obj$1 !== "symbol" && typeof obj$1 !== "function") { - let size = obj$1.length | 0; - if (size !== 0) { - let obj_tag = obj$1.TAG; - let tag = (size << 10) | obj_tag; - if (obj_tag === 248) { - s = Caml_hash_primitive.hash_mix_int(s, obj$1[1]); - } else { - s = Caml_hash_primitive.hash_mix_int(s, tag); - let v = size - 1 | 0; - let block = v < num ? v : num; - for (let i = 0; i <= block; ++i) { - push_back(queue, obj$1[i]); - } - } - } else { - let size$1 = (function(obj,cb){ - var size = 0 - for(var k in obj){ - cb(obj[k]) - ++ size - } - return size - })(obj$1, v => push_back(queue, v)); - s = Caml_hash_primitive.hash_mix_int(s, (size$1 << 10) | 0); - } - } - - }; - return Caml_hash_primitive.hash_final_mix(s); -} - -export { - hash, -} -/* No side effect */ diff --git a/lib/es6/caml_hash_primitive.js b/lib/es6/caml_hash_primitive.js deleted file mode 100644 index bd5d59943e..0000000000 --- a/lib/es6/caml_hash_primitive.js +++ /dev/null @@ -1,51 +0,0 @@ - - - -function rotl32(x, n) { - return (x << n) | (x >>> (32 - n | 0)) | 0; -} - -function hash_mix_int(h, d) { - let d$1 = d; - d$1 = Math.imul(d$1, -862048943); - d$1 = rotl32(d$1, 15); - d$1 = Math.imul(d$1, 461845907); - let h$1 = h ^ d$1; - h$1 = rotl32(h$1, 13); - return (h$1 + (h$1 << 2) | 0) - 430675100 | 0; -} - -function hash_final_mix(h) { - let h$1 = h ^ (h >>> 16); - h$1 = Math.imul(h$1, -2048144789); - h$1 = h$1 ^ (h$1 >>> 13); - h$1 = Math.imul(h$1, -1028477387); - return h$1 ^ (h$1 >>> 16); -} - -function hash_mix_string(h, s) { - let len = s.length; - let block = (len / 4 | 0) - 1 | 0; - let hash = h; - for (let i = 0; i <= block; ++i) { - let j = (i << 2); - let w = s.charCodeAt(j) | (s.charCodeAt(j + 1 | 0) << 8) | (s.charCodeAt(j + 2 | 0) << 16) | (s.charCodeAt(j + 3 | 0) << 24); - hash = hash_mix_int(hash, w); - } - let modulo = len & 3; - if (modulo !== 0) { - let w$1 = modulo === 3 ? (s.charCodeAt(len - 1 | 0) << 16) | (s.charCodeAt(len - 2 | 0) << 8) | s.charCodeAt(len - 3 | 0) : ( - modulo === 2 ? (s.charCodeAt(len - 1 | 0) << 8) | s.charCodeAt(len - 2 | 0) : s.charCodeAt(len - 1 | 0) - ); - hash = hash_mix_int(hash, w$1); - } - hash = hash ^ len; - return hash; -} - -export { - hash_mix_int, - hash_mix_string, - hash_final_mix, -} -/* No side effect */ diff --git a/lib/es6/caml_int64.js b/lib/es6/caml_int64.js deleted file mode 100644 index 2ad58e6cf4..0000000000 --- a/lib/es6/caml_int64.js +++ /dev/null @@ -1,604 +0,0 @@ - - -import * as Caml from "./caml.js"; - -function mk(lo, hi) { - return [ - hi, - (lo >>> 0) - ]; -} - -let min_int = [ - -2147483648, - 0 -]; - -let max_int = [ - 2147483647, - 4294967295 -]; - -let one = [ - 0, - 1 -]; - -let zero = [ - 0, - 0 -]; - -let neg_one = [ - -1, - 4294967295 -]; - -function neg_signed(x) { - return (x & -2147483648) !== 0; -} - -function non_neg_signed(x) { - return (x & -2147483648) === 0; -} - -function succ(param) { - let x_lo = param[1]; - let x_hi = param[0]; - let lo = x_lo + 1 | 0; - return [ - x_hi + ( - lo === 0 ? 1 : 0 - ) | 0, - (lo >>> 0) - ]; -} - -function neg(param) { - let other_lo = (param[1] ^ -1) + 1 | 0; - return [ - (param[0] ^ -1) + ( - other_lo === 0 ? 1 : 0 - ) | 0, - (other_lo >>> 0) - ]; -} - -function add_aux(param, y_lo, y_hi) { - let x_lo = param[1]; - let lo = x_lo + y_lo | 0; - let overflow = neg_signed(x_lo) && (neg_signed(y_lo) || non_neg_signed(lo)) || neg_signed(y_lo) && non_neg_signed(lo) ? 1 : 0; - return [ - param[0] + y_hi + overflow | 0, - (lo >>> 0) - ]; -} - -function add(self, param) { - return add_aux(self, param[1], param[0]); -} - -function equal(x, y) { - if (x[1] === y[1]) { - return x[0] === y[0]; - } else { - return false; - } -} - -function equal_null(x, y) { - if (y !== null) { - return Caml.i64_eq(x, y); - } else { - return false; - } -} - -function equal_undefined(x, y) { - if (y !== undefined) { - return Caml.i64_eq(x, y); - } else { - return false; - } -} - -function equal_nullable(x, y) { - if (y == null) { - return false; - } else { - return Caml.i64_eq(x, y); - } -} - -function sub_aux(x, lo, hi) { - let y_lo = ((lo ^ -1) + 1 >>> 0); - let y_hi = (hi ^ -1) + ( - y_lo === 0 ? 1 : 0 - ) | 0; - return add_aux(x, y_lo, y_hi); -} - -function sub(self, param) { - return sub_aux(self, param[1], param[0]); -} - -function lsl_(x, numBits) { - if (numBits === 0) { - return x; - } - let lo = x[1]; - if (numBits >= 32) { - return [ - (lo << (numBits - 32 | 0)), - 0 - ]; - } else { - return [ - (lo >>> (32 - numBits | 0)) | (x[0] << numBits), - ((lo << numBits) >>> 0) - ]; - } -} - -function lsr_(x, numBits) { - if (numBits === 0) { - return x; - } - let hi = x[0]; - let offset = numBits - 32 | 0; - if (offset === 0) { - return [ - 0, - (hi >>> 0) - ]; - } else if (offset > 0) { - return [ - 0, - (hi >>> offset) - ]; - } else { - return [ - (hi >>> numBits), - (((hi << (-offset | 0)) | (x[1] >>> numBits)) >>> 0) - ]; - } -} - -function asr_(x, numBits) { - if (numBits === 0) { - return x; - } - let hi = x[0]; - if (numBits < 32) { - return [ - (hi >> numBits), - (((hi << (32 - numBits | 0)) | (x[1] >>> numBits)) >>> 0) - ]; - } else { - return [ - hi >= 0 ? 0 : -1, - ((hi >> (numBits - 32 | 0)) >>> 0) - ]; - } -} - -function is_zero(x) { - if (x[0] !== 0) { - return false; - } else { - return x[1] === 0; - } -} - -function mul(_this, _other) { - while (true) { - let other = _other; - let $$this = _this; - let lo; - let this_hi = $$this[0]; - let exit = 0; - let exit$1 = 0; - let exit$2 = 0; - if (this_hi !== 0) { - exit$2 = 4; - } else { - if ($$this[1] === 0) { - return zero; - } - exit$2 = 4; - } - if (exit$2 === 4) { - if (other[0] !== 0) { - exit$1 = 3; - } else { - if (other[1] === 0) { - return zero; - } - exit$1 = 3; - } - } - if (exit$1 === 3) { - if (this_hi !== -2147483648 || $$this[1] !== 0) { - exit = 2; - } else { - lo = other[1]; - } - } - if (exit === 2) { - let other_hi = other[0]; - let lo$1 = $$this[1]; - let exit$3 = 0; - if (other_hi !== -2147483648 || other[1] !== 0) { - exit$3 = 3; - } else { - lo = lo$1; - } - if (exit$3 === 3) { - let other_lo = other[1]; - if (this_hi < 0) { - if (other_hi >= 0) { - return neg(mul(neg($$this), other)); - } - _other = neg(other); - _this = neg($$this); - continue; - } - if (other_hi < 0) { - return neg(mul($$this, neg(other))); - } - let a48 = (this_hi >>> 16); - let a32 = this_hi & 65535; - let a16 = (lo$1 >>> 16); - let a00 = lo$1 & 65535; - let b48 = (other_hi >>> 16); - let b32 = other_hi & 65535; - let b16 = (other_lo >>> 16); - let b00 = other_lo & 65535; - let c48 = 0; - let c32 = 0; - let c16 = 0; - let c00 = a00 * b00; - c16 = (c00 >>> 16) + a16 * b00; - c32 = (c16 >>> 16); - c16 = (c16 & 65535) + a00 * b16; - c32 = c32 + (c16 >>> 16) + a32 * b00; - c48 = (c32 >>> 16); - c32 = (c32 & 65535) + a16 * b16; - c48 = c48 + (c32 >>> 16); - c32 = (c32 & 65535) + a00 * b32; - c48 = c48 + (c32 >>> 16); - c32 = c32 & 65535; - c48 = c48 + (a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48) & 65535; - return [ - c32 | (c48 << 16), - ((c00 & 65535 | ((c16 & 65535) << 16)) >>> 0) - ]; - } - - } - if ((lo & 1) === 0) { - return zero; - } else { - return min_int; - } - }; -} - -function xor(param, param$1) { - return [ - param[0] ^ param$1[0], - ((param[1] ^ param$1[1]) >>> 0) - ]; -} - -function or_(param, param$1) { - return [ - param[0] | param$1[0], - ((param[1] | param$1[1]) >>> 0) - ]; -} - -function and_(param, param$1) { - return [ - param[0] & param$1[0], - ((param[1] & param$1[1]) >>> 0) - ]; -} - -function to_float(param) { - return param[0] * 0x100000000 + param[1]; -} - -function of_float(x) { - if (isNaN(x) || !isFinite(x)) { - return zero; - } - if (x <= -9.22337203685477581e+18) { - return min_int; - } - if (x + 1 >= 9.22337203685477581e+18) { - return max_int; - } - if (x < 0) { - return neg(of_float(- x)); - } - let hi = x / 4294967296 | 0; - let lo = x % 4294967296 | 0; - return [ - hi, - (lo >>> 0) - ]; -} - -function isSafeInteger(param) { - let hi = param[0]; - let top11Bits = (hi >> 21); - if (top11Bits === 0) { - return true; - } else if (top11Bits === -1) { - return !(param[1] === 0 && hi === -2097152); - } else { - return false; - } -} - -function to_string(self) { - if (isSafeInteger(self)) { - return String(to_float(self)); - } - if (self[0] < 0) { - if (Caml.i64_eq(self, min_int)) { - return "-9223372036854775808"; - } else { - return "-" + to_string(neg(self)); - } - } - let approx_div1 = of_float(Math.floor(to_float(self) / 10)); - let lo = approx_div1[1]; - let hi = approx_div1[0]; - let match = sub_aux(sub_aux(self, (lo << 3), (lo >>> 29) | (hi << 3)), (lo << 1), (lo >>> 31) | (hi << 1)); - let rem_lo = match[1]; - let rem_hi = match[0]; - if (rem_lo === 0 && rem_hi === 0) { - return to_string(approx_div1) + "0"; - } - if (rem_hi < 0) { - let rem_lo$1 = ((rem_lo ^ -1) + 1 >>> 0); - let delta = Math.ceil(rem_lo$1 / 10); - let remainder = 10 * delta - rem_lo$1; - return to_string(sub_aux(approx_div1, delta | 0, 0)) + String(remainder | 0); - } - let delta$1 = Math.floor(rem_lo / 10); - let remainder$1 = rem_lo - 10 * delta$1; - return to_string(add_aux(approx_div1, delta$1 | 0, 0)) + String(remainder$1 | 0); -} - -function div(_self, _other) { - while (true) { - let other = _other; - let self = _self; - let self_hi = self[0]; - let exit = 0; - let exit$1 = 0; - if (other[0] !== 0 || other[1] !== 0) { - exit$1 = 2; - } else { - throw { - RE_EXN_ID: "Division_by_zero", - Error: new Error() - }; - } - if (exit$1 === 2) { - if (self_hi !== -2147483648) { - if (self_hi !== 0) { - exit = 1; - } else { - if (self[1] === 0) { - return zero; - } - exit = 1; - } - } else if (self[1] !== 0) { - exit = 1; - } else { - if (Caml.i64_eq(other, one) || Caml.i64_eq(other, neg_one)) { - return self; - } - if (Caml.i64_eq(other, min_int)) { - return one; - } - let half_this = asr_(self, 1); - let approx = lsl_(div(half_this, other), 1); - let exit$2 = 0; - if (approx[0] !== 0) { - exit$2 = 3; - } else { - if (approx[1] === 0) { - if (other[0] < 0) { - return one; - } else { - return neg(one); - } - } - exit$2 = 3; - } - if (exit$2 === 3) { - let rem = sub(self, mul(other, approx)); - return add(approx, div(rem, other)); - } - - } - } - if (exit === 1) { - let other_hi = other[0]; - let exit$3 = 0; - if (other_hi !== -2147483648) { - exit$3 = 2; - } else { - if (other[1] === 0) { - return zero; - } - exit$3 = 2; - } - if (exit$3 === 2) { - if (self_hi < 0) { - if (other_hi >= 0) { - return neg(div(neg(self), other)); - } - _other = neg(other); - _self = neg(self); - continue; - } - if (other_hi < 0) { - return neg(div(self, neg(other))); - } - let res = zero; - let rem$1 = self; - while (Caml.i64_ge(rem$1, other)) { - let b = Math.floor(to_float(rem$1) / to_float(other)); - let approx$1 = 1 > b ? 1 : b; - let log2 = Math.ceil(Math.log(approx$1) / Math.LN2); - let delta = log2 <= 48 ? 1 : Math.pow(2, log2 - 48); - let approxRes = of_float(approx$1); - let approxRem = mul(approxRes, other); - while (approxRem[0] < 0 || Caml.i64_gt(approxRem, rem$1)) { - approx$1 = approx$1 - delta; - approxRes = of_float(approx$1); - approxRem = mul(approxRes, other); - }; - if (is_zero(approxRes)) { - approxRes = one; - } - res = add(res, approxRes); - rem$1 = sub(rem$1, approxRem); - }; - return res; - } - - } - - }; -} - -function mod_(self, other) { - return sub(self, mul(div(self, other), other)); -} - -function div_mod(self, other) { - let quotient = div(self, other); - return [ - quotient, - sub(self, mul(quotient, other)) - ]; -} - -function compare(self, other) { - let y = other[0]; - let x = self[0]; - let v = x < y ? -1 : ( - x === y ? 0 : 1 - ); - if (v !== 0) { - return v; - } - let y$1 = other[1]; - let x$1 = self[1]; - if (x$1 < y$1) { - return -1; - } else if (x$1 === y$1) { - return 0; - } else { - return 1; - } -} - -function of_int32(lo) { - return [ - lo < 0 ? -1 : 0, - (lo >>> 0) - ]; -} - -function to_int32(x) { - return x[1] | 0; -} - -function to_hex(x) { - let x_lo = x[1]; - let x_hi = x[0]; - let aux = v => (v >>> 0).toString(16); - if (x_hi === 0 && x_lo === 0) { - return "0"; - } - if (x_lo === 0) { - return aux(x_hi) + "00000000"; - } - if (x_hi === 0) { - return aux(x_lo); - } - let lo = aux(x_lo); - let pad = 8 - lo.length | 0; - if (pad <= 0) { - return aux(x_hi) + lo; - } else { - return aux(x_hi) + ("0".repeat(pad) + lo); - } -} - -function discard_sign(x) { - return [ - 2147483647 & x[0], - x[1] - ]; -} - -function float_of_bits(x) { - return (function(lo,hi){ return (new Float64Array(new Int32Array([lo,hi]).buffer))[0]})(x[1], x[0]); -} - -function bits_of_float(x) { - let match = (function(x){return new Int32Array(new Float64Array([x]).buffer)})(x); - return [ - match[1], - (match[0] >>> 0) - ]; -} - -export { - mk, - succ, - min_int, - max_int, - one, - zero, - neg_one, - of_int32, - to_int32, - add, - neg, - sub, - lsl_, - lsr_, - asr_, - is_zero, - mul, - xor, - or_, - and_, - equal, - equal_null, - equal_undefined, - equal_nullable, - to_float, - of_float, - div, - mod_, - compare, - float_of_bits, - bits_of_float, - div_mod, - to_hex, - discard_sign, - to_string, -} -/* No side effect */ diff --git a/lib/es6/caml_js_exceptions.js b/lib/es6/caml_js_exceptions.js deleted file mode 100644 index 8c89bc2438..0000000000 --- a/lib/es6/caml_js_exceptions.js +++ /dev/null @@ -1,31 +0,0 @@ - - -import * as Caml_option from "./caml_option.js"; -import * as Caml_exceptions from "./caml_exceptions.js"; - -let $$Error = "JsError"; - -function internalToOCamlException(e) { - if (Caml_exceptions.is_extension(e)) { - return e; - } else { - return { - RE_EXN_ID: "JsError", - _1: e - }; - } -} - -function as_js_exn(exn) { - if (exn.RE_EXN_ID === $$Error) { - return Caml_option.some(exn._1); - } - -} - -export { - $$Error, - internalToOCamlException, - as_js_exn, -} -/* No side effect */ diff --git a/lib/es6/caml_lexer.js b/lib/es6/caml_lexer.js deleted file mode 100644 index a1ad028fd3..0000000000 --- a/lib/es6/caml_lexer.js +++ /dev/null @@ -1,258 +0,0 @@ - - - -/***********************************************************************/ -/* */ -/* Objective Caml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 Institut National de Recherche en Informatique et */ -/* en Automatique. All rights reserved. This file is distributed */ -/* under the terms of the GNU Library General Public License, with */ -/* the special exception on linking described in file ../LICENSE. */ -/* */ -/***********************************************************************/ - -/* $Id: lexing.c 6045 2004-01-01 16:42:43Z doligez $ */ - -/* The table-driven automaton for lexers generated by camllex. */ - -function caml_lex_array(s) { - var l = s.length / 2; - var a = new Array(l); - // when s.charCodeAt(2 * i + 1 ) > 128 (0x80) - // a[i] < 0 - // for(var i = 0 ; i <= 0xffff; ++i) { if (i << 16 >> 16 !==i){console.log(i<<16>>16, 'vs',i)}} - // - for (var i = 0; i < l; i++) - a[i] = (s.charCodeAt(2 * i) | (s.charCodeAt(2 * i + 1) << 8)) << 16 >> 16; - return a; -} -; - -let caml_lex_engine_aux = (function (tbl, start_state, lexbuf, exn){ - - if (!Array.isArray(tbl.lex_default)) { - tbl.lex_base = caml_lex_array(tbl.lex_base); - tbl.lex_backtrk = caml_lex_array(tbl.lex_backtrk); - tbl.lex_check = caml_lex_array(tbl.lex_check); - tbl.lex_trans = caml_lex_array(tbl.lex_trans); - tbl.lex_default = caml_lex_array(tbl.lex_default); - } - var c; - var state = start_state; - //var buffer = bytes_of_string(lexbuf.lex_buffer); - var buffer = lexbuf.lex_buffer; - if (state >= 0) { - /* First entry */ - lexbuf.lex_last_pos = lexbuf.lex_start_pos = lexbuf.lex_curr_pos; - lexbuf.lex_last_action = -1; - } - else { - /* Reentry after refill */ - state = -state - 1; - } - for (;;) { - /* Lookup base address or action number for current state */ - var base = tbl.lex_base[state]; - if (base < 0) - return -base - 1; - /* See if it's a backtrack point */ - var backtrk = tbl.lex_backtrk[state]; - if (backtrk >= 0) { - lexbuf.lex_last_pos = lexbuf.lex_curr_pos; - lexbuf.lex_last_action = backtrk; - } - /* See if we need a refill */ - if (lexbuf.lex_curr_pos >= lexbuf.lex_buffer_len) { - if (lexbuf.lex_eof_reached === 0) - return -state - 1; - else - c = 256; - } - else { - /* Read next input char */ - c = buffer[lexbuf.lex_curr_pos]; - lexbuf.lex_curr_pos++; - } - /* Determine next state */ - if (tbl.lex_check[base + c] === state) { - state = tbl.lex_trans[base + c]; - } - else { - state = tbl.lex_default[state]; - } - /* If no transition on this char, return to last backtrack point */ - if (state < 0) { - lexbuf.lex_curr_pos = lexbuf.lex_last_pos; - if (lexbuf.lex_last_action == -1) - throw exn - else - return lexbuf.lex_last_action; - } - else { - /* Erase the EOF condition only if the EOF pseudo-character was - consumed by the automaton (i.e. there was no backtrack above) - */ - if (c == 256) - lexbuf.lex_eof_reached = 0; - } - } -}); - -let empty_token_lit = "lexing: empty token"; - -function lex_engine(tbls, i, buf) { - return caml_lex_engine_aux(tbls, i, buf, { - RE_EXN_ID: "Failure", - _1: empty_token_lit - }); -} - -/***********************************************/ -/* New lexer engine, with memory of positions */ -/***********************************************/ - -/** - * s -> Lexing.lex_tables.lex_code - * mem -> Lexing.lexbuf.lex_mem (* int array *) - */ - -function caml_lex_run_mem(s, i, mem, curr_pos) { - for (;;) { - var dst = s.charCodeAt(i); - i++; - if (dst == 0xff) - return; - var src = s.charCodeAt(i); - i++; - if (src == 0xff) - mem[dst] = curr_pos; - else - mem[dst] = mem[src]; - } -} - - -/** - * s -> Lexing.lex_tables.lex_code - * mem -> Lexing.lexbuf.lex_mem (* int array *) - */ - -function caml_lex_run_tag(s, i, mem) { - for (;;) { - var dst = s.charCodeAt(i); - i++; - if (dst == 0xff) - return; - var src = s.charCodeAt(i); - i++; - if (src == 0xff) - mem[dst] = -1; - else - mem[dst] = mem[src]; - } -} -; - -let caml_new_lex_engine_aux = (function (tbl, start_state, lexbuf, exn) { - - if (!Array.isArray(tbl.lex_default)) { - tbl.lex_base = caml_lex_array(tbl.lex_base); - tbl.lex_backtrk = caml_lex_array(tbl.lex_backtrk); - tbl.lex_check = caml_lex_array(tbl.lex_check); - tbl.lex_trans = caml_lex_array(tbl.lex_trans); - tbl.lex_default = caml_lex_array(tbl.lex_default); - } - if(!Array.isArray(tbl.lex_default_code)){ - tbl.lex_base_code = caml_lex_array(tbl.lex_base_code); - tbl.lex_backtrk_code = caml_lex_array(tbl.lex_backtrk_code); - tbl.lex_check_code = caml_lex_array(tbl.lex_check_code); - tbl.lex_trans_code = caml_lex_array(tbl.lex_trans_code); - tbl.lex_default_code = caml_lex_array(tbl.lex_default_code); - } - var c, state = start_state; - //var buffer = caml_bytes_of_string(lexbuf.lex_buffer); - var buffer = lexbuf.lex_buffer; - if (state >= 0) { - /* First entry */ - lexbuf.lex_last_pos = lexbuf.lex_start_pos = lexbuf.lex_curr_pos; - lexbuf.lex_last_action = -1; - } - else { - /* Reentry after refill */ - state = -state - 1; - } - for (;;) { - /* Lookup base address or action number for current state */ - var base = tbl.lex_base[state]; - if (base < 0) { - var pc_off = tbl.lex_base_code[state]; - caml_lex_run_tag(tbl.lex_code, pc_off, lexbuf.lex_mem); - return -base - 1; - } - /* See if it's a backtrack point */ - var backtrk = tbl.lex_backtrk[state]; - if (backtrk >= 0) { - var pc_off = tbl.lex_backtrk_code[state]; - caml_lex_run_tag(tbl.lex_code, pc_off, lexbuf.lex_mem); - lexbuf.lex_last_pos = lexbuf.lex_curr_pos; - lexbuf.lex_last_action = backtrk; - } - /* See if we need a refill */ - if (lexbuf.lex_curr_pos >= lexbuf.lex_buffer_len) { - if (lexbuf.lex_eof_reached == 0) - return -state - 1; - else - c = 256; - } - else { - /* Read next input char */ - c = buffer[lexbuf.lex_curr_pos]; - lexbuf.lex_curr_pos++; - } - /* Determine next state */ - var pstate = state; - if (tbl.lex_check[base + c] == state) - state = tbl.lex_trans[base + c]; - else - state = tbl.lex_default[state]; - /* If no transition on this char, return to last backtrack point */ - if (state < 0) { - lexbuf.lex_curr_pos = lexbuf.lex_last_pos; - if (lexbuf.lex_last_action == -1) - throw exn; - else - return lexbuf.lex_last_action; - } - else { - /* If some transition, get and perform memory moves */ - var base_code = tbl.lex_base_code[pstate], pc_off; - if (tbl.lex_check_code[base_code + c] == pstate) - pc_off = tbl.lex_trans_code[base_code + c]; - else - pc_off = tbl.lex_default_code[pstate]; - if (pc_off > 0) - caml_lex_run_mem(tbl.lex_code, pc_off, lexbuf.lex_mem, lexbuf.lex_curr_pos); - /* Erase the EOF condition only if the EOF pseudo-character was - consumed by the automaton (i.e. there was no backtrack above) - */ - if (c == 256) - lexbuf.lex_eof_reached = 0; - } - } - }); - -function new_lex_engine(tbl, i, buf) { - return caml_new_lex_engine_aux(tbl, i, buf, { - RE_EXN_ID: "Failure", - _1: empty_token_lit - }); -} - -export { - lex_engine, - new_lex_engine, -} -/* Not a pure module */ diff --git a/lib/es6/caml_md5.js b/lib/es6/caml_md5.js deleted file mode 100644 index 8ae9fe01f9..0000000000 --- a/lib/es6/caml_md5.js +++ /dev/null @@ -1,168 +0,0 @@ - - - -function cmn(q, a, b, x, s, t) { - let a$1 = ((a + q | 0) + x | 0) + t | 0; - return ((a$1 << s) | (a$1 >>> (32 - s | 0)) | 0) + b | 0; -} - -function f(a, b, c, d, x, s, t) { - return cmn(b & c | (b ^ -1) & d, a, b, x, s, t); -} - -function g(a, b, c, d, x, s, t) { - return cmn(b & d | c & (d ^ -1), a, b, x, s, t); -} - -function h(a, b, c, d, x, s, t) { - return cmn(b ^ c ^ d, a, b, x, s, t); -} - -function i(a, b, c, d, x, s, t) { - return cmn(c ^ (b | d ^ -1), a, b, x, s, t); -} - -function cycle(x, k) { - let a = x[0]; - let b = x[1]; - let c = x[2]; - let d = x[3]; - a = f(a, b, c, d, k[0], 7, -680876936); - d = f(d, a, b, c, k[1], 12, -389564586); - c = f(c, d, a, b, k[2], 17, 606105819); - b = f(b, c, d, a, k[3], 22, -1044525330); - a = f(a, b, c, d, k[4], 7, -176418897); - d = f(d, a, b, c, k[5], 12, 1200080426); - c = f(c, d, a, b, k[6], 17, -1473231341); - b = f(b, c, d, a, k[7], 22, -45705983); - a = f(a, b, c, d, k[8], 7, 1770035416); - d = f(d, a, b, c, k[9], 12, -1958414417); - c = f(c, d, a, b, k[10], 17, -42063); - b = f(b, c, d, a, k[11], 22, -1990404162); - a = f(a, b, c, d, k[12], 7, 1804603682); - d = f(d, a, b, c, k[13], 12, -40341101); - c = f(c, d, a, b, k[14], 17, -1502002290); - b = f(b, c, d, a, k[15], 22, 1236535329); - a = g(a, b, c, d, k[1], 5, -165796510); - d = g(d, a, b, c, k[6], 9, -1069501632); - c = g(c, d, a, b, k[11], 14, 643717713); - b = g(b, c, d, a, k[0], 20, -373897302); - a = g(a, b, c, d, k[5], 5, -701558691); - d = g(d, a, b, c, k[10], 9, 38016083); - c = g(c, d, a, b, k[15], 14, -660478335); - b = g(b, c, d, a, k[4], 20, -405537848); - a = g(a, b, c, d, k[9], 5, 568446438); - d = g(d, a, b, c, k[14], 9, -1019803690); - c = g(c, d, a, b, k[3], 14, -187363961); - b = g(b, c, d, a, k[8], 20, 1163531501); - a = g(a, b, c, d, k[13], 5, -1444681467); - d = g(d, a, b, c, k[2], 9, -51403784); - c = g(c, d, a, b, k[7], 14, 1735328473); - b = g(b, c, d, a, k[12], 20, -1926607734); - a = h(a, b, c, d, k[5], 4, -378558); - d = h(d, a, b, c, k[8], 11, -2022574463); - c = h(c, d, a, b, k[11], 16, 1839030562); - b = h(b, c, d, a, k[14], 23, -35309556); - a = h(a, b, c, d, k[1], 4, -1530992060); - d = h(d, a, b, c, k[4], 11, 1272893353); - c = h(c, d, a, b, k[7], 16, -155497632); - b = h(b, c, d, a, k[10], 23, -1094730640); - a = h(a, b, c, d, k[13], 4, 681279174); - d = h(d, a, b, c, k[0], 11, -358537222); - c = h(c, d, a, b, k[3], 16, -722521979); - b = h(b, c, d, a, k[6], 23, 76029189); - a = h(a, b, c, d, k[9], 4, -640364487); - d = h(d, a, b, c, k[12], 11, -421815835); - c = h(c, d, a, b, k[15], 16, 530742520); - b = h(b, c, d, a, k[2], 23, -995338651); - a = i(a, b, c, d, k[0], 6, -198630844); - d = i(d, a, b, c, k[7], 10, 1126891415); - c = i(c, d, a, b, k[14], 15, -1416354905); - b = i(b, c, d, a, k[5], 21, -57434055); - a = i(a, b, c, d, k[12], 6, 1700485571); - d = i(d, a, b, c, k[3], 10, -1894986606); - c = i(c, d, a, b, k[10], 15, -1051523); - b = i(b, c, d, a, k[1], 21, -2054922799); - a = i(a, b, c, d, k[8], 6, 1873313359); - d = i(d, a, b, c, k[15], 10, -30611744); - c = i(c, d, a, b, k[6], 15, -1560198380); - b = i(b, c, d, a, k[13], 21, 1309151649); - a = i(a, b, c, d, k[4], 6, -145523070); - d = i(d, a, b, c, k[11], 10, -1120210379); - c = i(c, d, a, b, k[2], 15, 718787259); - b = i(b, c, d, a, k[9], 21, -343485551); - x[0] = a + x[0] | 0; - x[1] = b + x[1] | 0; - x[2] = c + x[2] | 0; - x[3] = d + x[3] | 0; -} - -let state = [ - 1732584193, - -271733879, - -1732584194, - 271733878 -]; - -let md5blk = [ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 -]; - -function md5_string(s, start, len) { - let s$1 = s.slice(start, len); - let n = s$1.length; - state[0] = 1732584193; - state[1] = -271733879; - state[2] = -1732584194; - state[3] = 271733878; - for (let i = 0; i <= 15; ++i) { - md5blk[i] = 0; - } - let i_end = n / 64 | 0; - for (let i$1 = 1; i$1 <= i_end; ++i$1) { - for (let j = 0; j <= 15; ++j) { - let k = ((i$1 << 6) - 64 | 0) + (j << 2) | 0; - md5blk[j] = ((s$1.charCodeAt(k) + (s$1.charCodeAt(k + 1 | 0) << 8) | 0) + (s$1.charCodeAt(k + 2 | 0) << 16) | 0) + (s$1.charCodeAt(k + 3 | 0) << 24) | 0; - } - cycle(state, md5blk); - } - let s_tail = s$1.slice((i_end << 6)); - for (let kk = 0; kk <= 15; ++kk) { - md5blk[kk] = 0; - } - let i_end$1 = s_tail.length - 1 | 0; - for (let i$2 = 0; i$2 <= i_end$1; ++i$2) { - md5blk[i$2 / 4 | 0] = md5blk[i$2 / 4 | 0] | (s_tail.charCodeAt(i$2) << (i$2 % 4 << 3)); - } - let i$3 = i_end$1 + 1 | 0; - md5blk[i$3 / 4 | 0] = md5blk[i$3 / 4 | 0] | (128 << (i$3 % 4 << 3)); - if (i$3 > 55) { - cycle(state, md5blk); - for (let i$4 = 0; i$4 <= 15; ++i$4) { - md5blk[i$4] = 0; - } - } - md5blk[14] = (n << 3); - cycle(state, md5blk); - return String.fromCharCode(state[0] & 255, (state[0] >> 8) & 255, (state[0] >> 16) & 255, (state[0] >> 24) & 255, state[1] & 255, (state[1] >> 8) & 255, (state[1] >> 16) & 255, (state[1] >> 24) & 255, state[2] & 255, (state[2] >> 8) & 255, (state[2] >> 16) & 255, (state[2] >> 24) & 255, state[3] & 255, (state[3] >> 8) & 255, (state[3] >> 16) & 255, (state[3] >> 24) & 255); -} - -export { - md5_string, -} -/* No side effect */ diff --git a/lib/es6/caml_parser.js b/lib/es6/caml_parser.js deleted file mode 100644 index cbd8dc7b8d..0000000000 --- a/lib/es6/caml_parser.js +++ /dev/null @@ -1,303 +0,0 @@ - - - -/***********************************************************************/ -/* */ -/* Objective Caml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 Institut National de Recherche en Informatique et */ -/* en Automatique. All rights reserved. This file is distributed */ -/* under the terms of the GNU Library General Public License, with */ -/* the special exception on linking described in file ../LICENSE. */ -/* */ -/***********************************************************************/ - -/* $Id: parsing.c 8983 2008-08-06 09:38:25Z xleroy $ */ - -/* The PDA automaton for parsers generated by camlyacc */ - -/* The pushdown automata */ - -/** - * caml_lex_array("abcd") - * [25185, 25699] - * @param s - * @returns {any[]} - * TODO: duplicated with module {!Caml_lex} - */ -function caml_lex_array(s) { - var l = s.length / 2; - var a = new Array(l); - for (var i = 0; i < l; i++) - a[i] = (s.charCodeAt(2 * i) | (s.charCodeAt(2 * i + 1) << 8)) << 16 >> 16; - return a; -} -/** - * Note that TS enum is not friendly to Closure compiler - * @enum{number} - */ -var Automata = { - START: 0, - LOOP: 6, - TOKEN_READ: 1, - TEST_SHIFT: 7, - ERROR_DETECTED: 5, - SHIFT: 8, - SHIFT_RECOVER: 9, - STACK_GROWN_1: 2, - REDUCE: 10, - STACK_GROWN_2: 3, - SEMANTIC_ACTION_COMPUTED: 4 -}; -/** - * @enum{number} - */ -var Result = { - READ_TOKEN: 0, - RAISE_PARSE_ERROR: 1, - GROW_STACKS_1: 2, - GROW_STACKS_2: 3, - COMPUTE_SEMANTIC_ACTION: 4, - CALL_ERROR_FUNCTION: 5 -}; -var PARSER_TRACE = false; -; - -let parse_engine = (function (tables /* parser_table */, env /* parser_env */, cmd /* parser_input*/, arg /* Obj.t*/) { - var ERRCODE = 256; - //var START = 0; - //var TOKEN_READ = 1; - //var STACKS_GROWN_1 = 2; - //var STACKS_GROWN_2 = 3; - //var SEMANTIC_ACTION_COMPUTED = 4; - //var ERROR_DETECTED = 5; - //var loop = 6; - //var testshift = 7; - //var shift = 8; - //var shift_recover = 9; - //var reduce = 10; - // Parsing.parser_env - var env_s_stack = 's_stack'; // array - var env_v_stack = 'v_stack'; // array - var env_symb_start_stack = 'symb_start_stack'; // array - var env_symb_end_stack = 'symb_end_stack'; // array - var env_stacksize = 'stacksize'; - var env_stackbase = 'stackbase'; - var env_curr_char = 'curr_char'; - var env_lval = 'lval'; // Obj.t - var env_symb_start = 'symb_start'; // position - var env_symb_end = 'symb_end'; // position - var env_asp = 'asp'; - var env_rule_len = 'rule_len'; - var env_rule_number = 'rule_number'; - var env_sp = 'sp'; - var env_state = 'state'; - var env_errflag = 'errflag'; - // Parsing.parse_tables - // var _tbl_actions = 1; - var tbl_transl_const = 'transl_const'; // array - var tbl_transl_block = 'transl_block'; // array - var tbl_lhs = 'lhs'; - var tbl_len = 'len'; - var tbl_defred = 'defred'; - var tbl_dgoto = 'dgoto'; - var tbl_sindex = 'sindex'; - var tbl_rindex = 'rindex'; - var tbl_gindex = 'gindex'; - var tbl_tablesize = 'tablesize'; - var tbl_table = 'table'; - var tbl_check = 'check'; - // var _tbl_error_function = 14; - // var _tbl_names_const = 15; - // var _tbl_names_block = 16; - if (!tables.preprocessed) { - tables.defred = caml_lex_array(tables[tbl_defred]); - tables.sindex = caml_lex_array(tables[tbl_sindex]); - tables.check = caml_lex_array(tables[tbl_check]); - tables.rindex = caml_lex_array(tables[tbl_rindex]); - tables.table = caml_lex_array(tables[tbl_table]); - tables.len = caml_lex_array(tables[tbl_len]); - tables.lhs = caml_lex_array(tables[tbl_lhs]); - tables.gindex = caml_lex_array(tables[tbl_gindex]); - tables.dgoto = caml_lex_array(tables[tbl_dgoto]); - tables.preprocessed = true; - } - var res; - var n, n1, n2, state1; - // RESTORE - var sp = env[env_sp]; - var state = env[env_state]; - var errflag = env[env_errflag]; - exit: for (;;) { - //console.error("State", Automata[cmd]); - switch (cmd) { - case Automata.START: - state = 0; - errflag = 0; - // Fall through - case Automata.LOOP: - n = tables.defred[state]; - if (n != 0) { - cmd = Automata.REDUCE; - break; - } - if (env[env_curr_char] >= 0) { - cmd = Automata.TEST_SHIFT; - break; - } - res = Result.READ_TOKEN; - break exit; - /* The ML code calls the lexer and updates */ - /* symb_start and symb_end */ - case Automata.TOKEN_READ: - if (typeof arg !== 'number') { - env[env_curr_char] = tables[tbl_transl_block][arg.TAG | 0 /* + 1 */]; - env[env_lval] = arg._0; // token carries payload - } - else { - env[env_curr_char] = tables[tbl_transl_const][arg /* + 1 */]; - env[env_lval] = 0; // const token - } - if (PARSER_TRACE) { - console.error("State %d, read token", state, arg); - } - // Fall through - case Automata.TEST_SHIFT: - n1 = tables.sindex[state]; - n2 = n1 + env[env_curr_char]; - if (n1 != 0 && n2 >= 0 && n2 <= tables[tbl_tablesize] && - tables.check[n2] == env[env_curr_char]) { - cmd = Automata.SHIFT; - break; - } - n1 = tables.rindex[state]; - n2 = n1 + env[env_curr_char]; - if (n1 != 0 && n2 >= 0 && n2 <= tables[tbl_tablesize] && - tables.check[n2] == env[env_curr_char]) { - n = tables.table[n2]; - cmd = Automata.REDUCE; - break; - } - if (errflag <= 0) { - res = Result.CALL_ERROR_FUNCTION; - break exit; - } - // Fall through - /* The ML code calls the error function */ - case Automata.ERROR_DETECTED: - if (errflag < 3) { - errflag = 3; - for (;;) { - state1 = env[env_s_stack][sp /* + 1*/]; - n1 = tables.sindex[state1]; - n2 = n1 + ERRCODE; - if (n1 != 0 && n2 >= 0 && n2 <= tables[tbl_tablesize] && - tables.check[n2] == ERRCODE) { - cmd = Automata.SHIFT_RECOVER; - break; - } - else { - if (sp <= env[env_stackbase]) - return Result.RAISE_PARSE_ERROR; - /* The ML code raises Parse_error */ - sp--; - } - } - } - else { - if (env[env_curr_char] == 0) - return Result.RAISE_PARSE_ERROR; - /* The ML code raises Parse_error */ - env[env_curr_char] = -1; - cmd = Automata.LOOP; - break; - } - // Fall through - case Automata.SHIFT: - env[env_curr_char] = -1; - if (errflag > 0) - errflag--; - // Fall through - case Automata.SHIFT_RECOVER: - if (PARSER_TRACE) { - console.error("State %d: shift to state %d", state, tables.table[n2]); - } - state = tables.table[n2]; - sp++; - if (sp >= env[env_stacksize]) { - res = Result.GROW_STACKS_1; - break exit; - } - // Fall through - /* The ML code resizes the stacks */ - case Automata.STACK_GROWN_1: - env[env_s_stack][sp /* + 1 */] = state; - env[env_v_stack][sp /* + 1 */] = env[env_lval]; - env[env_symb_start_stack][sp /* + 1 */] = env[env_symb_start]; - env[env_symb_end_stack][sp /* + 1 */] = env[env_symb_end]; - cmd = Automata.LOOP; - break; - case Automata.REDUCE: - if (PARSER_TRACE) { - console.error("State %d : reduce by rule %d", state, n); - } - var m = tables.len[n]; - env[env_asp] = sp; - env[env_rule_number] = n; - env[env_rule_len] = m; - sp = sp - m + 1; - m = tables.lhs[n]; - state1 = env[env_s_stack][sp - 1]; // - n1 = tables.gindex[m]; - n2 = n1 + state1; - if (n1 != 0 && n2 >= 0 && n2 <= tables[tbl_tablesize] && - tables.check[n2] == state1) - state = tables.table[n2]; - else - state = tables.dgoto[m]; - if (sp >= env[env_stacksize]) { - res = Result.GROW_STACKS_2; - break exit; - } - // Fall through - /* The ML code resizes the stacks */ - case Automata.STACK_GROWN_2: - res = Result.COMPUTE_SEMANTIC_ACTION; - break exit; - /* The ML code calls the semantic action */ - case Automata.SEMANTIC_ACTION_COMPUTED: - env[env_s_stack][sp /* + 1 */] = state; - env[env_v_stack][sp /* + 1*/] = arg; - var asp = env[env_asp]; - env[env_symb_end_stack][sp /* + 1*/] = env[env_symb_end_stack][asp /* + 1*/]; - if (sp > asp) { - /* This is an epsilon production. Take symb_start equal to symb_end. */ - env[env_symb_start_stack][sp /* + 1*/] = env[env_symb_end_stack][asp /*+ 1*/]; - } - cmd = Automata.LOOP; - break; - /* Should not happen */ - default: - return Result.RAISE_PARSE_ERROR; - } - } - // SAVE - env[env_sp] = sp; - env[env_state] = state; - env[env_errflag] = errflag; - return res; -}); - -let set_parser_trace = (function (v) { - var old = PARSER_TRACE; - PARSER_TRACE = v; - return old; -}); - -export { - parse_engine, - set_parser_trace, -} -/* Not a pure module */ diff --git a/lib/es6/caml_string.js b/lib/es6/caml_string.js deleted file mode 100644 index 741ccb6ddf..0000000000 --- a/lib/es6/caml_string.js +++ /dev/null @@ -1,23 +0,0 @@ - - - -function get(s, i) { - if (i >= s.length || i < 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "index out of bounds", - Error: new Error() - }; - } - return s.codePointAt(i); -} - -function make(n, ch) { - return String.fromCharCode(ch).repeat(n); -} - -export { - get, - make, -} -/* No side effect */ diff --git a/lib/es6/caml_sys.js b/lib/es6/caml_sys.js deleted file mode 100644 index 864a14fabf..0000000000 --- a/lib/es6/caml_sys.js +++ /dev/null @@ -1,99 +0,0 @@ - - - -function sys_getenv(s) { - if (typeof process === "undefined" || process.env === undefined) { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let x = process.env[s]; - if (x !== undefined) { - return x; - } - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; -} - -let os_type = (function(_){ - if(typeof process !== 'undefined' && process.platform === 'win32'){ - return "Win32" - } - else { - return "Unix" - } -}); - -function sys_time() { - if (typeof process === "undefined" || process.uptime === undefined) { - return -1; - } else { - return process.uptime(); - } -} - -let sys_getcwd = (function(param){ - if (typeof process === "undefined" || process.cwd === undefined){ - return "/" - } - return process.cwd() - }); - -function sys_get_argv() { - if (typeof process === "undefined") { - return [ - "", - [""] - ]; - } - let argv = process.argv; - if (argv == null) { - return [ - "", - [""] - ]; - } else { - return [ - argv[0], - argv - ]; - } -} - -function sys_exit(exit_code) { - if (typeof process !== "undefined") { - return process.exit(exit_code); - } - -} - -function sys_is_directory(_s) { - throw { - RE_EXN_ID: "Failure", - _1: "sys_is_directory not implemented", - Error: new Error() - }; -} - -function sys_file_exists(_s) { - throw { - RE_EXN_ID: "Failure", - _1: "sys_file_exists not implemented", - Error: new Error() - }; -} - -export { - sys_getenv, - sys_time, - os_type, - sys_getcwd, - sys_get_argv, - sys_exit, - sys_is_directory, - sys_file_exists, -} -/* No side effect */ diff --git a/lib/es6/char.js b/lib/es6/char.js index 79cec11931..6686f5d84f 100644 --- a/lib/es6/char.js +++ b/lib/es6/char.js @@ -1,16 +1,8 @@ -import * as Bytes from "./bytes.js"; -function chr(n) { - if (n < 0 || n > 255) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Char.chr", - Error: new Error() - }; - } - return n; +function chr(prim) { + return prim; } function escaped(param) { @@ -53,37 +45,16 @@ function escaped(param) { } switch (exit) { case 1 : - let s = [ - 0, - 0, - 0, - 0 - ]; + let s = Array(4); s[0] = /* '\\' */92; s[1] = 48 + (param / 100 | 0) | 0; s[2] = 48 + (param / 10 | 0) % 10 | 0; s[3] = 48 + param % 10 | 0; - return Bytes.to_string(s); + return String.fromCodePoint(...s); case 2 : - let s$1 = [0]; + let s$1 = Array(1); s$1[0] = param; - return Bytes.to_string(s$1); - } -} - -function lowercase(c) { - if (c >= /* 'A' */65 && c <= /* 'Z' */90 || c >= /* '\192' */192 && c <= /* '\214' */214 || c >= /* '\216' */216 && c <= /* '\222' */222) { - return c + 32 | 0; - } else { - return c; - } -} - -function uppercase(c) { - if (c >= /* 'a' */97 && c <= /* 'z' */122 || c >= /* '\224' */224 && c <= /* '\246' */246 || c >= /* '\248' */248 && c <= /* '\254' */254) { - return c - 32 | 0; - } else { - return c; + return String.fromCodePoint(...s$1); } } @@ -114,8 +85,6 @@ function equal(c1, c2) { export { chr, escaped, - lowercase, - uppercase, lowercase_ascii, uppercase_ascii, compare, diff --git a/lib/es6/complex.js b/lib/es6/complex.js deleted file mode 100644 index 9285c41e45..0000000000 --- a/lib/es6/complex.js +++ /dev/null @@ -1,176 +0,0 @@ - - - -let one = { - re: 1.0, - im: 0.0 -}; - -function add(x, y) { - return { - re: x.re + y.re, - im: x.im + y.im - }; -} - -function sub(x, y) { - return { - re: x.re - y.re, - im: x.im - y.im - }; -} - -function neg(x) { - return { - re: - x.re, - im: - x.im - }; -} - -function conj(x) { - return { - re: x.re, - im: - x.im - }; -} - -function mul(x, y) { - return { - re: x.re * y.re - x.im * y.im, - im: x.re * y.im + x.im * y.re - }; -} - -function div(x, y) { - if (Math.abs(y.re) >= Math.abs(y.im)) { - let r = y.im / y.re; - let d = y.re + r * y.im; - return { - re: (x.re + r * x.im) / d, - im: (x.im - r * x.re) / d - }; - } - let r$1 = y.re / y.im; - let d$1 = y.im + r$1 * y.re; - return { - re: (r$1 * x.re + x.im) / d$1, - im: (r$1 * x.im - x.re) / d$1 - }; -} - -function inv(x) { - return div(one, x); -} - -function norm2(x) { - return x.re * x.re + x.im * x.im; -} - -function norm(x) { - let r = Math.abs(x.re); - let i = Math.abs(x.im); - if (r === 0.0) { - return i; - } - if (i === 0.0) { - return r; - } - if (r >= i) { - let q = i / r; - return r * Math.sqrt(1.0 + q * q); - } - let q$1 = r / i; - return i * Math.sqrt(1.0 + q$1 * q$1); -} - -function arg(x) { - return Math.atan2(x.im, x.re); -} - -function polar(n, a) { - return { - re: Math.cos(a) * n, - im: Math.sin(a) * n - }; -} - -function sqrt(x) { - if (x.re === 0.0 && x.im === 0.0) { - return { - re: 0.0, - im: 0.0 - }; - } - let r = Math.abs(x.re); - let i = Math.abs(x.im); - let w; - if (r >= i) { - let q = i / r; - w = Math.sqrt(r) * Math.sqrt(0.5 * (1.0 + Math.sqrt(1.0 + q * q))); - } else { - let q$1 = r / i; - w = Math.sqrt(i) * Math.sqrt(0.5 * (q$1 + Math.sqrt(1.0 + q$1 * q$1))); - } - if (x.re >= 0.0) { - return { - re: w, - im: 0.5 * x.im / w - }; - } else { - return { - re: 0.5 * i / w, - im: x.im >= 0.0 ? w : - w - }; - } -} - -function exp(x) { - let e = Math.exp(x.re); - return { - re: e * Math.cos(x.im), - im: e * Math.sin(x.im) - }; -} - -function log(x) { - return { - re: Math.log(norm(x)), - im: Math.atan2(x.im, x.re) - }; -} - -function pow(x, y) { - return exp(mul(y, log(x))); -} - -let zero = { - re: 0.0, - im: 0.0 -}; - -let i = { - re: 0.0, - im: 1.0 -}; - -export { - zero, - one, - i, - neg, - conj, - add, - sub, - mul, - inv, - div, - sqrt, - norm2, - norm, - arg, - polar, - exp, - log, - pow, -} -/* No side effect */ diff --git a/lib/es6/curry.js b/lib/es6/curry.js deleted file mode 100644 index 793b2d7f9a..0000000000 --- a/lib/es6/curry.js +++ /dev/null @@ -1,464 +0,0 @@ - - -import * as Caml_array from "./caml_array.js"; - -function app(_f, _args) { - while (true) { - let args = _args; - let f = _f; - let init_arity = f.length; - let arity = init_arity === 0 ? 1 : init_arity; - let len = args.length; - let d = arity - len | 0; - if (d === 0) { - return f.apply(null, args); - } - if (d >= 0) { - return x => app(f, args.concat([x])); - } - _args = Caml_array.sub(args, arity, -d | 0); - _f = f.apply(null, Caml_array.sub(args, 0, arity)); - continue; - }; -} - -function _1(o, a0) { - let arity = o.length; - if (arity === 1) { - return o(a0); - } else { - switch (arity) { - case 1 : - return o(a0); - case 2 : - return param => o(a0, param); - case 3 : - return (param, param$1) => o(a0, param, param$1); - case 4 : - return (param, param$1, param$2) => o(a0, param, param$1, param$2); - case 5 : - return (param, param$1, param$2, param$3) => o(a0, param, param$1, param$2, param$3); - case 6 : - return (param, param$1, param$2, param$3, param$4) => o(a0, param, param$1, param$2, param$3, param$4); - case 7 : - return (param, param$1, param$2, param$3, param$4, param$5) => o(a0, param, param$1, param$2, param$3, param$4, param$5); - default: - return app(o, [a0]); - } - } -} - -function __1(o) { - let arity = o.length; - if (arity === 1) { - return o; - } else { - return a0 => _1(o, a0); - } -} - -function _2(o, a0, a1) { - let arity = o.length; - if (arity === 2) { - return o(a0, a1); - } else { - switch (arity) { - case 1 : - return app(o(a0), [a1]); - case 2 : - return o(a0, a1); - case 3 : - return param => o(a0, a1, param); - case 4 : - return (param, param$1) => o(a0, a1, param, param$1); - case 5 : - return (param, param$1, param$2) => o(a0, a1, param, param$1, param$2); - case 6 : - return (param, param$1, param$2, param$3) => o(a0, a1, param, param$1, param$2, param$3); - case 7 : - return (param, param$1, param$2, param$3, param$4) => o(a0, a1, param, param$1, param$2, param$3, param$4); - default: - return app(o, [ - a0, - a1 - ]); - } - } -} - -function __2(o) { - let arity = o.length; - if (arity === 2) { - return o; - } else { - return (a0, a1) => _2(o, a0, a1); - } -} - -function _3(o, a0, a1, a2) { - let arity = o.length; - if (arity === 3) { - return o(a0, a1, a2); - } else { - switch (arity) { - case 1 : - return app(o(a0), [ - a1, - a2 - ]); - case 2 : - return app(o(a0, a1), [a2]); - case 3 : - return o(a0, a1, a2); - case 4 : - return param => o(a0, a1, a2, param); - case 5 : - return (param, param$1) => o(a0, a1, a2, param, param$1); - case 6 : - return (param, param$1, param$2) => o(a0, a1, a2, param, param$1, param$2); - case 7 : - return (param, param$1, param$2, param$3) => o(a0, a1, a2, param, param$1, param$2, param$3); - default: - return app(o, [ - a0, - a1, - a2 - ]); - } - } -} - -function __3(o) { - let arity = o.length; - if (arity === 3) { - return o; - } else { - return (a0, a1, a2) => _3(o, a0, a1, a2); - } -} - -function _4(o, a0, a1, a2, a3) { - let arity = o.length; - if (arity === 4) { - return o(a0, a1, a2, a3); - } else { - switch (arity) { - case 1 : - return app(o(a0), [ - a1, - a2, - a3 - ]); - case 2 : - return app(o(a0, a1), [ - a2, - a3 - ]); - case 3 : - return app(o(a0, a1, a2), [a3]); - case 4 : - return o(a0, a1, a2, a3); - case 5 : - return param => o(a0, a1, a2, a3, param); - case 6 : - return (param, param$1) => o(a0, a1, a2, a3, param, param$1); - case 7 : - return (param, param$1, param$2) => o(a0, a1, a2, a3, param, param$1, param$2); - default: - return app(o, [ - a0, - a1, - a2, - a3 - ]); - } - } -} - -function __4(o) { - let arity = o.length; - if (arity === 4) { - return o; - } else { - return (a0, a1, a2, a3) => _4(o, a0, a1, a2, a3); - } -} - -function _5(o, a0, a1, a2, a3, a4) { - let arity = o.length; - if (arity === 5) { - return o(a0, a1, a2, a3, a4); - } else { - switch (arity) { - case 1 : - return app(o(a0), [ - a1, - a2, - a3, - a4 - ]); - case 2 : - return app(o(a0, a1), [ - a2, - a3, - a4 - ]); - case 3 : - return app(o(a0, a1, a2), [ - a3, - a4 - ]); - case 4 : - return app(o(a0, a1, a2, a3), [a4]); - case 5 : - return o(a0, a1, a2, a3, a4); - case 6 : - return param => o(a0, a1, a2, a3, a4, param); - case 7 : - return (param, param$1) => o(a0, a1, a2, a3, a4, param, param$1); - default: - return app(o, [ - a0, - a1, - a2, - a3, - a4 - ]); - } - } -} - -function __5(o) { - let arity = o.length; - if (arity === 5) { - return o; - } else { - return (a0, a1, a2, a3, a4) => _5(o, a0, a1, a2, a3, a4); - } -} - -function _6(o, a0, a1, a2, a3, a4, a5) { - let arity = o.length; - if (arity === 6) { - return o(a0, a1, a2, a3, a4, a5); - } else { - switch (arity) { - case 1 : - return app(o(a0), [ - a1, - a2, - a3, - a4, - a5 - ]); - case 2 : - return app(o(a0, a1), [ - a2, - a3, - a4, - a5 - ]); - case 3 : - return app(o(a0, a1, a2), [ - a3, - a4, - a5 - ]); - case 4 : - return app(o(a0, a1, a2, a3), [ - a4, - a5 - ]); - case 5 : - return app(o(a0, a1, a2, a3, a4), [a5]); - case 6 : - return o(a0, a1, a2, a3, a4, a5); - case 7 : - return param => o(a0, a1, a2, a3, a4, a5, param); - default: - return app(o, [ - a0, - a1, - a2, - a3, - a4, - a5 - ]); - } - } -} - -function __6(o) { - let arity = o.length; - if (arity === 6) { - return o; - } else { - return (a0, a1, a2, a3, a4, a5) => _6(o, a0, a1, a2, a3, a4, a5); - } -} - -function _7(o, a0, a1, a2, a3, a4, a5, a6) { - let arity = o.length; - if (arity === 7) { - return o(a0, a1, a2, a3, a4, a5, a6); - } else { - switch (arity) { - case 1 : - return app(o(a0), [ - a1, - a2, - a3, - a4, - a5, - a6 - ]); - case 2 : - return app(o(a0, a1), [ - a2, - a3, - a4, - a5, - a6 - ]); - case 3 : - return app(o(a0, a1, a2), [ - a3, - a4, - a5, - a6 - ]); - case 4 : - return app(o(a0, a1, a2, a3), [ - a4, - a5, - a6 - ]); - case 5 : - return app(o(a0, a1, a2, a3, a4), [ - a5, - a6 - ]); - case 6 : - return app(o(a0, a1, a2, a3, a4, a5), [a6]); - case 7 : - return o(a0, a1, a2, a3, a4, a5, a6); - default: - return app(o, [ - a0, - a1, - a2, - a3, - a4, - a5, - a6 - ]); - } - } -} - -function __7(o) { - let arity = o.length; - if (arity === 7) { - return o; - } else { - return (a0, a1, a2, a3, a4, a5, a6) => _7(o, a0, a1, a2, a3, a4, a5, a6); - } -} - -function _8(o, a0, a1, a2, a3, a4, a5, a6, a7) { - let arity = o.length; - if (arity === 8) { - return o(a0, a1, a2, a3, a4, a5, a6, a7); - } else { - switch (arity) { - case 1 : - return app(o(a0), [ - a1, - a2, - a3, - a4, - a5, - a6, - a7 - ]); - case 2 : - return app(o(a0, a1), [ - a2, - a3, - a4, - a5, - a6, - a7 - ]); - case 3 : - return app(o(a0, a1, a2), [ - a3, - a4, - a5, - a6, - a7 - ]); - case 4 : - return app(o(a0, a1, a2, a3), [ - a4, - a5, - a6, - a7 - ]); - case 5 : - return app(o(a0, a1, a2, a3, a4), [ - a5, - a6, - a7 - ]); - case 6 : - return app(o(a0, a1, a2, a3, a4, a5), [ - a6, - a7 - ]); - case 7 : - return app(o(a0, a1, a2, a3, a4, a5, a6), [a7]); - default: - return app(o, [ - a0, - a1, - a2, - a3, - a4, - a5, - a6, - a7 - ]); - } - } -} - -function __8(o) { - let arity = o.length; - if (arity === 8) { - return o; - } else { - return (a0, a1, a2, a3, a4, a5, a6, a7) => _8(o, a0, a1, a2, a3, a4, a5, a6, a7); - } -} - -export { - app, - _1, - __1, - _2, - __2, - _3, - __3, - _4, - __4, - _5, - __5, - _6, - __6, - _7, - __7, - _8, - __8, -} -/* No side effect */ diff --git a/lib/es6/digest.js b/lib/es6/digest.js deleted file mode 100644 index 3226f12277..0000000000 --- a/lib/es6/digest.js +++ /dev/null @@ -1,116 +0,0 @@ - - -import * as Char from "./char.js"; -import * as Bytes from "./bytes.js"; -import * as $$String from "./string.js"; -import * as Caml_md5 from "./caml_md5.js"; -import * as Caml_bytes from "./caml_bytes.js"; -import * as Caml_string from "./caml_string.js"; - -function string(str) { - return Caml_md5.md5_string(str, 0, str.length); -} - -function bytes(b) { - return string(Bytes.unsafe_to_string(b)); -} - -function substring(str, ofs, len) { - if (ofs < 0 || len < 0 || ofs > (str.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Digest.substring", - Error: new Error() - }; - } - return Caml_md5.md5_string(str, ofs, len); -} - -function subbytes(b, ofs, len) { - return substring(Bytes.unsafe_to_string(b), ofs, len); -} - -function char_hex(n) { - return n + ( - n < 10 ? /* '0' */48 : 87 - ) | 0; -} - -function to_hex(d) { - if (d.length !== 16) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Digest.to_hex", - Error: new Error() - }; - } - let result = Caml_bytes.create(32); - for (let i = 0; i <= 15; ++i) { - let x = Caml_string.get(d, i); - result[(i << 1)] = char_hex((x >>> 4)); - result[(i << 1) + 1 | 0] = char_hex(x & 15); - } - return Bytes.unsafe_to_string(result); -} - -function from_hex(s) { - if (s.length !== 32) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Digest.from_hex", - Error: new Error() - }; - } - let digit = c => { - if (c >= 65) { - if (c >= 97) { - if (c >= 103) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Digest.from_hex", - Error: new Error() - }; - } - return (c - /* 'a' */97 | 0) + 10 | 0; - } - if (c >= 71) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Digest.from_hex", - Error: new Error() - }; - } - return (c - /* 'A' */65 | 0) + 10 | 0; - } - if (c > 57 || c < 48) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Digest.from_hex", - Error: new Error() - }; - } - return c - /* '0' */48 | 0; - }; - let byte = i => (digit(Caml_string.get(s, i)) << 4) + digit(Caml_string.get(s, i + 1 | 0)) | 0; - let result = Caml_bytes.create(16); - for (let i = 0; i <= 15; ++i) { - Caml_bytes.set(result, i, Char.chr(byte((i << 1)))); - } - return Bytes.unsafe_to_string(result); -} - -let compare = $$String.compare; - -let equal = $$String.equal; - -export { - compare, - equal, - string, - bytes, - substring, - subbytes, - to_hex, - from_hex, -} -/* No side effect */ diff --git a/lib/es6/dom_storage.js b/lib/es6/dom_storage.js index a759fbe23c..458c1b841c 100644 --- a/lib/es6/dom_storage.js +++ b/lib/es6/dom_storage.js @@ -1,9 +1,9 @@ -import * as Caml_option from "./caml_option.js"; +import * as Primitive_option from "./primitive_option.js"; function getItem(s, obj) { - return Caml_option.null_to_opt(obj.getItem(s)); + return Primitive_option.fromNull(obj.getItem(s)); } function setItem(k, v, obj) { @@ -15,7 +15,7 @@ function removeItem(s, obj) { } function key(i, obj) { - return Caml_option.null_to_opt(obj.key(i)); + return Primitive_option.fromNull(obj.key(i)); } export { diff --git a/lib/es6/filename.js b/lib/es6/filename.js deleted file mode 100644 index c186255abe..0000000000 --- a/lib/es6/filename.js +++ /dev/null @@ -1,493 +0,0 @@ - - -import * as Sys from "./sys.js"; -import * as Bytes from "./bytes.js"; -import * as Buffer from "./buffer.js"; -import * as $$String from "./string.js"; -import * as Caml_sys from "./caml_sys.js"; -import * as Caml_string from "./caml_string.js"; -import * as Caml_js_exceptions from "./caml_js_exceptions.js"; - -function generic_basename(is_dir_sep, current_dir_name, name) { - if (name === "") { - return current_dir_name; - } else { - let _n = name.length - 1 | 0; - while (true) { - let n = _n; - if (n < 0) { - return $$String.sub(name, 0, 1); - } - if (!is_dir_sep(name, n)) { - let _n$1 = n; - let p = n + 1 | 0; - while (true) { - let n$1 = _n$1; - if (n$1 < 0) { - return $$String.sub(name, 0, p); - } - if (is_dir_sep(name, n$1)) { - return $$String.sub(name, n$1 + 1 | 0, (p - n$1 | 0) - 1 | 0); - } - _n$1 = n$1 - 1 | 0; - continue; - }; - } - _n = n - 1 | 0; - continue; - }; - } -} - -function generic_dirname(is_dir_sep, current_dir_name, name) { - if (name === "") { - return current_dir_name; - } else { - let _n = name.length - 1 | 0; - while (true) { - let n = _n; - if (n < 0) { - return $$String.sub(name, 0, 1); - } - if (!is_dir_sep(name, n)) { - let _n$1 = n; - while (true) { - let n$1 = _n$1; - if (n$1 < 0) { - return current_dir_name; - } - if (is_dir_sep(name, n$1)) { - let _n$2 = n$1; - while (true) { - let n$2 = _n$2; - if (n$2 < 0) { - return $$String.sub(name, 0, 1); - } - if (!is_dir_sep(name, n$2)) { - return $$String.sub(name, 0, n$2 + 1 | 0); - } - _n$2 = n$2 - 1 | 0; - continue; - }; - } - _n$1 = n$1 - 1 | 0; - continue; - }; - } - _n = n - 1 | 0; - continue; - }; - } -} - -let current_dir_name = "."; - -function is_dir_sep(s, i) { - return Caml_string.get(s, i) === /* '/' */47; -} - -function is_relative(n) { - if (n.length < 1) { - return true; - } else { - return Caml_string.get(n, 0) !== /* '/' */47; - } -} - -function is_implicit(n) { - if (is_relative(n) && (n.length < 2 || $$String.sub(n, 0, 2) !== "./")) { - if (n.length < 3) { - return true; - } else { - return $$String.sub(n, 0, 3) !== "../"; - } - } else { - return false; - } -} - -function check_suffix(name, suff) { - if (name.length >= suff.length) { - return $$String.sub(name, name.length - suff.length | 0, suff.length) === suff; - } else { - return false; - } -} - -let temp_dir_name; - -try { - temp_dir_name = Caml_sys.sys_getenv("TMPDIR"); -} catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - temp_dir_name = "/tmp"; - } else { - throw exn; - } -} - -function quote(x) { - let quotequote = "'\\''"; - let l = x.length; - let b = Buffer.create(l + 20 | 0); - Buffer.add_char(b, /* '\'' */39); - for (let i = 0; i < l; ++i) { - if (Caml_string.get(x, i) === /* '\'' */39) { - Buffer.add_string(b, quotequote); - } else { - Buffer.add_char(b, Caml_string.get(x, i)); - } - } - Buffer.add_char(b, /* '\'' */39); - return Buffer.contents(b); -} - -function basename(x) { - return generic_basename(is_dir_sep, current_dir_name, x); -} - -function dirname(x) { - return generic_dirname(is_dir_sep, current_dir_name, x); -} - -let current_dir_name$1 = "."; - -function is_dir_sep$1(s, i) { - let c = Caml_string.get(s, i); - if (c === /* '/' */47 || c === /* '\\' */92) { - return true; - } else { - return c === /* ':' */58; - } -} - -function is_relative$1(n) { - if ((n.length < 1 || Caml_string.get(n, 0) !== /* '/' */47) && (n.length < 1 || Caml_string.get(n, 0) !== /* '\\' */92)) { - if (n.length < 2) { - return true; - } else { - return Caml_string.get(n, 1) !== /* ':' */58; - } - } else { - return false; - } -} - -function is_implicit$1(n) { - if (is_relative$1(n) && (n.length < 2 || $$String.sub(n, 0, 2) !== "./") && (n.length < 2 || $$String.sub(n, 0, 2) !== ".\\") && (n.length < 3 || $$String.sub(n, 0, 3) !== "../")) { - if (n.length < 3) { - return true; - } else { - return $$String.sub(n, 0, 3) !== "..\\"; - } - } else { - return false; - } -} - -function check_suffix$1(name, suff) { - if (name.length < suff.length) { - return false; - } - let s = $$String.sub(name, name.length - suff.length | 0, suff.length); - return Bytes.unsafe_to_string(Bytes.lowercase_ascii(Bytes.unsafe_of_string(s))) === Bytes.unsafe_to_string(Bytes.lowercase_ascii(Bytes.unsafe_of_string(suff))); -} - -let temp_dir_name$1; - -try { - temp_dir_name$1 = Caml_sys.sys_getenv("TEMP"); -} catch (raw_exn$1) { - let exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn$1); - if (exn$1.RE_EXN_ID === "Not_found") { - temp_dir_name$1 = "."; - } else { - throw exn$1; - } -} - -function quote$1(s) { - let l = s.length; - let b = Buffer.create(l + 20 | 0); - Buffer.add_char(b, /* '"' */34); - let loop = _i => { - while (true) { - let i = _i; - if (i === l) { - return Buffer.add_char(b, /* '"' */34); - } - let c = Caml_string.get(s, i); - if (c === 34) { - return loop_bs(0, i); - } - if (c === 92) { - return loop_bs(0, i); - } - Buffer.add_char(b, c); - _i = i + 1 | 0; - continue; - }; - }; - let loop_bs = (_n, _i) => { - while (true) { - let i = _i; - let n = _n; - if (i === l) { - Buffer.add_char(b, /* '"' */34); - return add_bs(n); - } - let match = Caml_string.get(s, i); - if (match !== 34) { - if (match !== 92) { - add_bs(n); - return loop(i); - } - _i = i + 1 | 0; - _n = n + 1 | 0; - continue; - } - add_bs((n << 1) + 1 | 0); - Buffer.add_char(b, /* '"' */34); - return loop(i + 1 | 0); - }; - }; - let add_bs = n => { - for (let _j = 1; _j <= n; ++_j) { - Buffer.add_char(b, /* '\\' */92); - } - }; - loop(0); - return Buffer.contents(b); -} - -function has_drive(s) { - let is_letter = param => { - if (param >= 91) { - return !(param > 122 || param < 97); - } else { - return param >= 65; - } - }; - if (s.length >= 2 && is_letter(Caml_string.get(s, 0))) { - return Caml_string.get(s, 1) === /* ':' */58; - } else { - return false; - } -} - -function drive_and_path(s) { - if (has_drive(s)) { - return [ - $$String.sub(s, 0, 2), - $$String.sub(s, 2, s.length - 2 | 0) - ]; - } else { - return [ - "", - s - ]; - } -} - -function dirname$1(s) { - let match = drive_and_path(s); - let dir = generic_dirname(is_dir_sep$1, current_dir_name$1, match[1]); - return match[0] + dir; -} - -function basename$1(s) { - let match = drive_and_path(s); - return generic_basename(is_dir_sep$1, current_dir_name$1, match[1]); -} - -let current_dir_name$2 = "."; - -function basename$2(x) { - return generic_basename(is_dir_sep$1, current_dir_name$2, x); -} - -function dirname$2(x) { - return generic_dirname(is_dir_sep$1, current_dir_name$2, x); -} - -let match; - -switch (Sys.os_type) { - case "Cygwin" : - match = [ - current_dir_name$2, - "..", - "/", - is_dir_sep$1, - is_relative$1, - is_implicit$1, - check_suffix$1, - temp_dir_name, - quote, - basename$2, - dirname$2 - ]; - break; - case "Win32" : - match = [ - current_dir_name$1, - "..", - "\\", - is_dir_sep$1, - is_relative$1, - is_implicit$1, - check_suffix$1, - temp_dir_name$1, - quote$1, - basename$1, - dirname$1 - ]; - break; - default: - match = [ - current_dir_name, - "..", - "/", - is_dir_sep, - is_relative, - is_implicit, - check_suffix, - temp_dir_name, - quote, - basename, - dirname - ]; -} - -let temp_dir_name$2 = match[7]; - -let is_dir_sep$2 = match[3]; - -let dir_sep = match[2]; - -function concat(dirname, filename) { - let l = dirname.length; - if (l === 0 || is_dir_sep$2(dirname, l - 1 | 0)) { - return dirname + filename; - } else { - return dirname + (dir_sep + filename); - } -} - -function chop_suffix(name, suff) { - let n = name.length - suff.length | 0; - if (n < 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Filename.chop_suffix", - Error: new Error() - }; - } - return $$String.sub(name, 0, n); -} - -function extension_len(name) { - let _i = name.length - 1 | 0; - while (true) { - let i = _i; - if (i < 0 || is_dir_sep$2(name, i)) { - return 0; - } - if (Caml_string.get(name, i) === /* '.' */46) { - let _i$1 = i - 1 | 0; - while (true) { - let i$1 = _i$1; - if (i$1 < 0 || is_dir_sep$2(name, i$1)) { - return 0; - } - if (Caml_string.get(name, i$1) !== /* '.' */46) { - return name.length - i | 0; - } - _i$1 = i$1 - 1 | 0; - continue; - }; - } - _i = i - 1 | 0; - continue; - }; -} - -function extension(name) { - let l = extension_len(name); - if (l === 0) { - return ""; - } else { - return $$String.sub(name, name.length - l | 0, l); - } -} - -function chop_extension(name) { - let l = extension_len(name); - if (l === 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Filename.chop_extension", - Error: new Error() - }; - } - return $$String.sub(name, 0, name.length - l | 0); -} - -function remove_extension(name) { - let l = extension_len(name); - if (l === 0) { - return name; - } else { - return $$String.sub(name, 0, name.length - l | 0); - } -} - -let current_temp_dir_name = { - contents: temp_dir_name$2 -}; - -function set_temp_dir_name(s) { - current_temp_dir_name.contents = s; -} - -function get_temp_dir_name() { - return current_temp_dir_name.contents; -} - -let current_dir_name$3 = match[0]; - -let parent_dir_name = match[1]; - -let is_relative$2 = match[4]; - -let is_implicit$2 = match[5]; - -let check_suffix$2 = match[6]; - -let basename$3 = match[9]; - -let dirname$3 = match[10]; - -let quote$2 = match[8]; - -export { - current_dir_name$3 as current_dir_name, - parent_dir_name, - dir_sep, - concat, - is_relative$2 as is_relative, - is_implicit$2 as is_implicit, - check_suffix$2 as check_suffix, - chop_suffix, - extension, - remove_extension, - chop_extension, - basename$3 as basename, - dirname$3 as dirname, - get_temp_dir_name, - set_temp_dir_name, - temp_dir_name$2 as temp_dir_name, - quote$2 as quote, -} -/* temp_dir_name Not a pure module */ diff --git a/lib/es6/genlex.js b/lib/es6/genlex.js deleted file mode 100644 index 72c88899ec..0000000000 --- a/lib/es6/genlex.js +++ /dev/null @@ -1,640 +0,0 @@ - - -import * as Char from "./char.js"; -import * as List from "./list.js"; -import * as Bytes from "./bytes.js"; -import * as Stream from "./stream.js"; -import * as Hashtbl from "./hashtbl.js"; -import * as Caml_bytes from "./caml_bytes.js"; -import * as Caml_format from "./caml_format.js"; -import * as Caml_string from "./caml_string.js"; -import * as Caml_js_exceptions from "./caml_js_exceptions.js"; - -let initial_buffer = Caml_bytes.create(32); - -let buffer = { - contents: initial_buffer -}; - -let bufpos = { - contents: 0 -}; - -function reset_buffer() { - buffer.contents = initial_buffer; - bufpos.contents = 0; -} - -function store(c) { - if (bufpos.contents >= buffer.contents.length) { - let newbuffer = Caml_bytes.create((bufpos.contents << 1)); - Bytes.blit(buffer.contents, 0, newbuffer, 0, bufpos.contents); - buffer.contents = newbuffer; - } - Caml_bytes.set(buffer.contents, bufpos.contents, c); - bufpos.contents = bufpos.contents + 1 | 0; -} - -function get_string() { - let s = Bytes.sub_string(buffer.contents, 0, bufpos.contents); - buffer.contents = initial_buffer; - return s; -} - -function make_lexer(keywords) { - let kwd_table = Hashtbl.create(undefined, 17); - List.iter(s => Hashtbl.add(kwd_table, s, { - TAG: "Kwd", - _0: s - }), keywords); - let ident_or_keyword = id => { - try { - return Hashtbl.find(kwd_table, id); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - return { - TAG: "Ident", - _0: id - }; - } - throw exn; - } - }; - let keyword_or_error = c => { - let s = Caml_string.make(1, c); - try { - return Hashtbl.find(kwd_table, s); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - throw { - RE_EXN_ID: Stream.$$Error, - _1: "Illegal character " + s, - Error: new Error() - }; - } - throw exn; - } - }; - let next_token = strm__ => { - while (true) { - let c = Stream.peek(strm__); - if (c === undefined) { - return; - } - let exit = 0; - if (c < 124) { - if (c > 122 || c < 65) { - if (c >= 123) { - exit = 1; - } else { - switch (c) { - case 9 : - case 10 : - case 12 : - case 13 : - case 26 : - case 32 : - Stream.junk(strm__); - continue; - case 34 : - Stream.junk(strm__); - reset_buffer(); - return { - TAG: "String", - _0: string(strm__) - }; - case 39 : - Stream.junk(strm__); - let c$1; - try { - c$1 = char(strm__); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === Stream.Failure) { - throw { - RE_EXN_ID: Stream.$$Error, - _1: "", - Error: new Error() - }; - } - throw exn; - } - let match = Stream.peek(strm__); - if (match !== undefined) { - if (match !== 39) { - throw { - RE_EXN_ID: Stream.$$Error, - _1: "", - Error: new Error() - }; - } - Stream.junk(strm__); - return { - TAG: "Char", - _0: c$1 - }; - } - throw { - RE_EXN_ID: Stream.$$Error, - _1: "", - Error: new Error() - }; - case 40 : - Stream.junk(strm__); - let match$1 = Stream.peek(strm__); - if (match$1 === 42) { - Stream.junk(strm__); - comment(strm__); - return next_token(strm__); - } else { - return keyword_or_error(/* '(' */40); - } - case 45 : - Stream.junk(strm__); - let c$2 = Stream.peek(strm__); - if (c$2 !== undefined && !(c$2 > 57 || c$2 < 48)) { - Stream.junk(strm__); - reset_buffer(); - store(/* '-' */45); - store(c$2); - return number(strm__); - } else { - reset_buffer(); - store(/* '-' */45); - return ident2(strm__); - } - case 48 : - case 49 : - case 50 : - case 51 : - case 52 : - case 53 : - case 54 : - case 55 : - case 56 : - case 57 : - exit = 4; - break; - case 0 : - case 1 : - case 2 : - case 3 : - case 4 : - case 5 : - case 6 : - case 7 : - case 8 : - case 11 : - case 14 : - case 15 : - case 16 : - case 17 : - case 18 : - case 19 : - case 20 : - case 21 : - case 22 : - case 23 : - case 24 : - case 25 : - case 27 : - case 28 : - case 29 : - case 30 : - case 31 : - case 41 : - case 44 : - case 46 : - case 59 : - exit = 1; - break; - case 33 : - case 35 : - case 36 : - case 37 : - case 38 : - case 42 : - case 43 : - case 47 : - case 58 : - case 60 : - case 61 : - case 62 : - case 63 : - case 64 : - exit = 3; - break; - } - } - } else { - switch (c) { - case 92 : - case 94 : - exit = 3; - break; - case 91 : - case 93 : - case 96 : - exit = 1; - break; - default: - exit = 2; - } - } - } else { - exit = c >= 127 ? ( - c > 255 || c < 192 ? 1 : 2 - ) : ( - c !== 125 ? 3 : 1 - ); - } - switch (exit) { - case 1 : - Stream.junk(strm__); - return keyword_or_error(c); - case 2 : - Stream.junk(strm__); - reset_buffer(); - store(c); - while (true) { - let c$3 = Stream.peek(strm__); - if (c$3 === undefined) { - return ident_or_keyword(get_string()); - } - if (c$3 >= 91) { - if (c$3 > 122 || c$3 < 95) { - if (c$3 > 255 || c$3 < 192) { - return ident_or_keyword(get_string()); - } - - } else if (c$3 === 96) { - return ident_or_keyword(get_string()); - } - - } else if (c$3 >= 48) { - if (!(c$3 > 64 || c$3 < 58)) { - return ident_or_keyword(get_string()); - } - - } else if (c$3 !== 39) { - return ident_or_keyword(get_string()); - } - Stream.junk(strm__); - store(c$3); - continue; - }; - case 3 : - Stream.junk(strm__); - reset_buffer(); - store(c); - return ident2(strm__); - case 4 : - Stream.junk(strm__); - reset_buffer(); - store(c); - return number(strm__); - } - }; - }; - let ident2 = strm__ => { - while (true) { - let c = Stream.peek(strm__); - if (c === undefined) { - return ident_or_keyword(get_string()); - } - if (c >= 94) { - if (c > 125 || c < 95) { - if (c >= 127) { - return ident_or_keyword(get_string()); - } - - } else if (c !== 124) { - return ident_or_keyword(get_string()); - } - - } else if (c >= 65) { - if (c !== 92) { - return ident_or_keyword(get_string()); - } - - } else { - if (c < 33) { - return ident_or_keyword(get_string()); - } - switch (c) { - case 34 : - case 39 : - case 40 : - case 41 : - case 44 : - case 46 : - case 48 : - case 49 : - case 50 : - case 51 : - case 52 : - case 53 : - case 54 : - case 55 : - case 56 : - case 57 : - case 59 : - return ident_or_keyword(get_string()); - case 33 : - case 35 : - case 36 : - case 37 : - case 38 : - case 42 : - case 43 : - case 45 : - case 47 : - case 58 : - case 60 : - case 61 : - case 62 : - case 63 : - case 64 : - break; - } - } - Stream.junk(strm__); - store(c); - continue; - }; - }; - let number = strm__ => { - while (true) { - let c = Stream.peek(strm__); - if (c !== undefined) { - if (c >= 58) { - if (!(c !== 69 && c !== 101)) { - Stream.junk(strm__); - store(/* 'E' */69); - return exponent_part(strm__); - } - - } else if (c !== 46) { - if (c >= 48) { - Stream.junk(strm__); - store(c); - continue; - } - - } else { - Stream.junk(strm__); - store(/* '.' */46); - while (true) { - let c$1 = Stream.peek(strm__); - if (c$1 !== undefined) { - if (c$1 > 101 || c$1 < 69) { - if (!(c$1 > 57 || c$1 < 48)) { - Stream.junk(strm__); - store(c$1); - continue; - } - - } else if (c$1 > 100 || c$1 < 70) { - Stream.junk(strm__); - store(/* 'E' */69); - return exponent_part(strm__); - } - - } - return { - TAG: "Float", - _0: Caml_format.float_of_string(get_string()) - }; - }; - } - } - return { - TAG: "Int", - _0: Caml_format.int_of_string(get_string()) - }; - }; - }; - let exponent_part = strm__ => { - let c = Stream.peek(strm__); - if (c !== undefined && !(c !== 43 && c !== 45)) { - Stream.junk(strm__); - store(c); - return end_exponent_part(strm__); - } else { - return end_exponent_part(strm__); - } - }; - let end_exponent_part = strm__ => { - while (true) { - let c = Stream.peek(strm__); - if (c === undefined) { - return { - TAG: "Float", - _0: Caml_format.float_of_string(get_string()) - }; - } - if (c > 57 || c < 48) { - return { - TAG: "Float", - _0: Caml_format.float_of_string(get_string()) - }; - } - Stream.junk(strm__); - store(c); - continue; - }; - }; - let string = strm__ => { - while (true) { - let c = Stream.peek(strm__); - if (c !== undefined) { - if (c !== 34) { - if (c !== 92) { - Stream.junk(strm__); - store(c); - continue; - } - Stream.junk(strm__); - let c$1; - try { - c$1 = escape(strm__); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === Stream.Failure) { - throw { - RE_EXN_ID: Stream.$$Error, - _1: "", - Error: new Error() - }; - } - throw exn; - } - store(c$1); - continue; - } - Stream.junk(strm__); - return get_string(); - } - throw { - RE_EXN_ID: Stream.Failure, - Error: new Error() - }; - }; - }; - let char = strm__ => { - let c = Stream.peek(strm__); - if (c !== undefined) { - if (c !== 92) { - Stream.junk(strm__); - return c; - } - Stream.junk(strm__); - try { - return escape(strm__); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === Stream.Failure) { - throw { - RE_EXN_ID: Stream.$$Error, - _1: "", - Error: new Error() - }; - } - throw exn; - } - } else { - throw { - RE_EXN_ID: Stream.Failure, - Error: new Error() - }; - } - }; - let escape = strm__ => { - let c1 = Stream.peek(strm__); - if (c1 !== undefined) { - if (c1 >= 58) { - switch (c1) { - case 110 : - Stream.junk(strm__); - return /* '\n' */10; - case 114 : - Stream.junk(strm__); - return /* '\r' */13; - case 116 : - Stream.junk(strm__); - return /* '\t' */9; - default: - Stream.junk(strm__); - return c1; - } - } else { - if (c1 >= 48) { - Stream.junk(strm__); - let c2 = Stream.peek(strm__); - if (c2 !== undefined) { - if (c2 > 57 || c2 < 48) { - throw { - RE_EXN_ID: Stream.$$Error, - _1: "", - Error: new Error() - }; - } - Stream.junk(strm__); - let c3 = Stream.peek(strm__); - if (c3 !== undefined) { - if (c3 > 57 || c3 < 48) { - throw { - RE_EXN_ID: Stream.$$Error, - _1: "", - Error: new Error() - }; - } - Stream.junk(strm__); - return Char.chr((Math.imul(c1 - 48 | 0, 100) + Math.imul(c2 - 48 | 0, 10) | 0) + (c3 - 48 | 0) | 0); - } - throw { - RE_EXN_ID: Stream.$$Error, - _1: "", - Error: new Error() - }; - } - throw { - RE_EXN_ID: Stream.$$Error, - _1: "", - Error: new Error() - }; - } - Stream.junk(strm__); - return c1; - } - } else { - throw { - RE_EXN_ID: Stream.Failure, - Error: new Error() - }; - } - }; - let comment = strm__ => { - while (true) { - let match = Stream.peek(strm__); - if (match !== undefined) { - switch (match) { - case 40 : - Stream.junk(strm__); - let match$1 = Stream.peek(strm__); - if (match$1 !== undefined) { - if (match$1 !== 42) { - Stream.junk(strm__); - return comment(strm__); - } else { - Stream.junk(strm__); - comment(strm__); - return comment(strm__); - } - } - throw { - RE_EXN_ID: Stream.Failure, - Error: new Error() - }; - case 42 : - Stream.junk(strm__); - while (true) { - let match$2 = Stream.peek(strm__); - if (match$2 !== undefined) { - if (match$2 !== 41) { - if (match$2 !== 42) { - Stream.junk(strm__); - return comment(strm__); - } - Stream.junk(strm__); - continue; - } - Stream.junk(strm__); - return; - } - throw { - RE_EXN_ID: Stream.Failure, - Error: new Error() - }; - }; - default: - Stream.junk(strm__); - continue; - } - } else { - throw { - RE_EXN_ID: Stream.Failure, - Error: new Error() - }; - } - }; - }; - return input => Stream.from(_count => next_token(input)); -} - -export { - make_lexer, -} -/* No side effect */ diff --git a/lib/es6/hashtbl.js b/lib/es6/hashtbl.js index f7b49ab4a7..30d99f112a 100644 --- a/lib/es6/hashtbl.js +++ b/lib/es6/hashtbl.js @@ -1,1106 +1,12 @@ -import * as Caml from "./caml.js"; -import * as $$Array from "./array.js"; -import * as Random from "./random.js"; -import * as Caml_obj from "./caml_obj.js"; -import * as Caml_hash from "./caml_hash.js"; -import * as Caml_array from "./caml_array.js"; -import * as Pervasives from "./pervasives.js"; -import * as Caml_option from "./caml_option.js"; -import * as CamlinternalLazy from "./camlinternalLazy.js"; +import * as Primitive_hash from "./primitive_hash.js"; function hash(x) { - return Caml_hash.hash(10, 100, 0, x); + return Primitive_hash.hash(10, 100, 0, x); } -function hash_param(n1, n2, x) { - return Caml_hash.hash(n1, n2, 0, x); -} - -function seeded_hash(seed, x) { - return Caml_hash.hash(10, 100, seed, x); -} - -function flip_ongoing_traversal(h) { - h.initial_size = -h.initial_size | 0; -} - -let randomized = { - contents: false -}; - -function randomize() { - randomized.contents = true; -} - -function is_randomized() { - return randomized.contents; -} - -let prng = CamlinternalLazy.from_fun(() => Random.State.make_self_init()); - -function power_2_above(_x, n) { - while (true) { - let x = _x; - if (x >= n) { - return x; - } - if ((x << 1) < x) { - return x; - } - _x = (x << 1); - continue; - }; -} - -function create(randomOpt, initial_size) { - let random = randomOpt !== undefined ? randomOpt : randomized.contents; - let s = power_2_above(16, initial_size); - let seed = random ? Random.State.bits(CamlinternalLazy.force(prng)) : 0; - return { - size: 0, - data: Caml_array.make(s, "Empty"), - seed: seed, - initial_size: s - }; -} - -function clear(h) { - h.size = 0; - let len = h.data.length; - for (let i = 0; i < len; ++i) { - Caml_array.set(h.data, i, "Empty"); - } -} - -function reset(h) { - let len = h.data.length; - if (len === Pervasives.abs(h.initial_size)) { - return clear(h); - } else { - h.size = 0; - h.data = Caml_array.make(Pervasives.abs(h.initial_size), "Empty"); - return; - } -} - -function copy_bucketlist(param) { - if (typeof param !== "object") { - return "Empty"; - } - let key = param.key; - let data = param.data; - let next = param.next; - let loop = (_prec, _param) => { - while (true) { - let param = _param; - let prec = _prec; - if (typeof param !== "object") { - return; - } - let key = param.key; - let data = param.data; - let next = param.next; - let r = { - TAG: "Cons", - key: key, - data: data, - next: next - }; - if (typeof prec !== "object") { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "hashtbl.res", - 110, - 19 - ], - Error: new Error() - }; - } - prec.next = r; - _param = next; - _prec = r; - continue; - }; - }; - let r = { - TAG: "Cons", - key: key, - data: data, - next: next - }; - loop(r, next); - return r; -} - -function copy(h) { - return { - size: h.size, - data: $$Array.map(copy_bucketlist, h.data), - seed: h.seed, - initial_size: h.initial_size - }; -} - -function length(h) { - return h.size; -} - -function resize(indexfun, h) { - let odata = h.data; - let osize = odata.length; - let nsize = (osize << 1); - if (nsize < osize) { - return; - } - let ndata = Caml_array.make(nsize, "Empty"); - let ndata_tail = Caml_array.make(nsize, "Empty"); - let inplace = h.initial_size >= 0; - h.data = ndata; - let insert_bucket = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let key = param.key; - let data = param.data; - let next = param.next; - let cell = inplace ? param : ({ - TAG: "Cons", - key: key, - data: data, - next: "Empty" - }); - let nidx = indexfun(h, key); - let tail = Caml_array.get(ndata_tail, nidx); - if (typeof tail !== "object") { - Caml_array.set(ndata, nidx, cell); - } else { - tail.next = cell; - } - Caml_array.set(ndata_tail, nidx, cell); - _param = next; - continue; - }; - }; - for (let i = 0; i < osize; ++i) { - insert_bucket(Caml_array.get(odata, i)); - } - if (!inplace) { - return; - } - for (let i$1 = 0; i$1 < nsize; ++i$1) { - let tail = Caml_array.get(ndata_tail, i$1); - if (typeof tail === "object") { - tail.next = "Empty"; - } - - } -} - -function key_index(h, key) { - return Caml_hash.hash(10, 100, h.seed, key) & (h.data.length - 1 | 0); -} - -function add(h, key, data) { - let i = key_index(h, key); - let bucket = { - TAG: "Cons", - key: key, - data: data, - next: Caml_array.get(h.data, i) - }; - Caml_array.set(h.data, i, bucket); - h.size = h.size + 1 | 0; - if (h.size > (h.data.length << 1)) { - return resize(key_index, h); - } - -} - -function remove(h, key) { - let i = key_index(h, key); - let _prec = "Empty"; - let _param = Caml_array.get(h.data, i); - while (true) { - let param = _param; - let prec = _prec; - if (typeof param !== "object") { - return; - } - let k = param.key; - let next = param.next; - if (Caml_obj.equal(k, key)) { - h.size = h.size - 1 | 0; - if (typeof prec !== "object") { - return Caml_array.set(h.data, i, next); - } else { - prec.next = next; - return; - } - } - _param = next; - _prec = param; - continue; - }; -} - -function find(h, key) { - let match = Caml_array.get(h.data, key_index(h, key)); - if (typeof match !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let k1 = match.key; - let d1 = match.data; - let next1 = match.next; - if (Caml_obj.equal(key, k1)) { - return d1; - } - if (typeof next1 !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let k2 = next1.key; - let d2 = next1.data; - let next2 = next1.next; - if (Caml_obj.equal(key, k2)) { - return d2; - } - if (typeof next2 !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let k3 = next2.key; - let d3 = next2.data; - let next3 = next2.next; - if (Caml_obj.equal(key, k3)) { - return d3; - } else { - let _param = next3; - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let k = param.key; - let data = param.data; - let next = param.next; - if (Caml_obj.equal(key, k)) { - return data; - } - _param = next; - continue; - }; - } -} - -function find_opt(h, key) { - let match = Caml_array.get(h.data, key_index(h, key)); - if (typeof match !== "object") { - return; - } - let k1 = match.key; - let d1 = match.data; - let next1 = match.next; - if (Caml_obj.equal(key, k1)) { - return Caml_option.some(d1); - } - if (typeof next1 !== "object") { - return; - } - let k2 = next1.key; - let d2 = next1.data; - let next2 = next1.next; - if (Caml_obj.equal(key, k2)) { - return Caml_option.some(d2); - } - if (typeof next2 !== "object") { - return; - } - let k3 = next2.key; - let d3 = next2.data; - let next3 = next2.next; - if (Caml_obj.equal(key, k3)) { - return Caml_option.some(d3); - } else { - let _param = next3; - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let k = param.key; - let data = param.data; - let next = param.next; - if (Caml_obj.equal(key, k)) { - return Caml_option.some(data); - } - _param = next; - continue; - }; - } -} - -function find_all(h, key) { - let find_in_bucket = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return /* [] */0; - } - let k = param.key; - let data = param.data; - let next = param.next; - if (Caml_obj.equal(k, key)) { - return { - hd: data, - tl: find_in_bucket(next) - }; - } - _param = next; - continue; - }; - }; - return find_in_bucket(Caml_array.get(h.data, key_index(h, key))); -} - -function replace_bucket(key, data, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - let k = param.key; - let next = param.next; - if (Caml_obj.equal(k, key)) { - param.key = key; - param.data = data; - return false; - } - _param = next; - continue; - }; -} - -function replace(h, key, data) { - let i = key_index(h, key); - let l = Caml_array.get(h.data, i); - if (replace_bucket(key, data, l)) { - Caml_array.set(h.data, i, { - TAG: "Cons", - key: key, - data: data, - next: l - }); - h.size = h.size + 1 | 0; - if (h.size > (h.data.length << 1)) { - return resize(key_index, h); - } else { - return; - } - } - -} - -function mem(h, key) { - let _param = Caml_array.get(h.data, key_index(h, key)); - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let k = param.key; - let next = param.next; - if (Caml_obj.equal(k, key)) { - return true; - } - _param = next; - continue; - }; -} - -function iter(f, h) { - let do_bucket = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let key = param.key; - let data = param.data; - let next = param.next; - f(key, data); - _param = next; - continue; - }; - }; - let old_trav = h.initial_size < 0; - if (!old_trav) { - flip_ongoing_traversal(h); - } - try { - let d = h.data; - for (let i = 0, i_finish = d.length; i < i_finish; ++i) { - do_bucket(Caml_array.get(d, i)); - } - if (!old_trav) { - return flip_ongoing_traversal(h); - } else { - return; - } - } catch (exn) { - if (old_trav) { - throw exn; - } - flip_ongoing_traversal(h); - throw exn; - } -} - -function filter_map_inplace_bucket(f, h, i, _prec, _param) { - while (true) { - let param = _param; - let prec = _prec; - if (typeof param !== "object") { - if (typeof prec !== "object") { - return Caml_array.set(h.data, i, "Empty"); - } else { - prec.next = "Empty"; - return; - } - } - let key = param.key; - let data = param.data; - let next = param.next; - let data$1 = f(key, data); - if (data$1 !== undefined) { - if (typeof prec !== "object") { - Caml_array.set(h.data, i, param); - } else { - prec.next = param; - } - param.data = Caml_option.valFromOption(data$1); - _param = next; - _prec = param; - continue; - } - h.size = h.size - 1 | 0; - _param = next; - continue; - }; -} - -function filter_map_inplace(f, h) { - let d = h.data; - let old_trav = h.initial_size < 0; - if (!old_trav) { - flip_ongoing_traversal(h); - } - try { - for (let i = 0, i_finish = d.length; i < i_finish; ++i) { - filter_map_inplace_bucket(f, h, i, "Empty", Caml_array.get(h.data, i)); - } - return; - } catch (exn) { - if (old_trav) { - throw exn; - } - flip_ongoing_traversal(h); - throw exn; - } -} - -function fold(f, h, init) { - let do_bucket = (_b, _accu) => { - while (true) { - let accu = _accu; - let b = _b; - if (typeof b !== "object") { - return accu; - } - let key = b.key; - let data = b.data; - let next = b.next; - _accu = f(key, data, accu); - _b = next; - continue; - }; - }; - let old_trav = h.initial_size < 0; - if (!old_trav) { - flip_ongoing_traversal(h); - } - try { - let d = h.data; - let accu = init; - for (let i = 0, i_finish = d.length; i < i_finish; ++i) { - accu = do_bucket(Caml_array.get(d, i), accu); - } - if (!old_trav) { - flip_ongoing_traversal(h); - } - return accu; - } catch (exn) { - if (old_trav) { - throw exn; - } - flip_ongoing_traversal(h); - throw exn; - } -} - -function bucket_length(_accu, _param) { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - let next = param.next; - _param = next; - _accu = accu + 1 | 0; - continue; - }; -} - -function stats(h) { - let mbl = $$Array.fold_left((m, b) => Caml.int_max(m, bucket_length(0, b)), 0, h.data); - let histo = Caml_array.make(mbl + 1 | 0, 0); - $$Array.iter(b => { - let l = bucket_length(0, b); - Caml_array.set(histo, l, Caml_array.get(histo, l) + 1 | 0); - }, h.data); - return { - num_bindings: h.size, - num_buckets: h.data.length, - max_bucket_length: mbl, - bucket_histogram: histo - }; -} - -function MakeSeeded(H) { - let key_index = (h, key) => H.hash(h.seed, key) & (h.data.length - 1 | 0); - let add = (h, key, data) => { - let i = key_index(h, key); - let bucket = { - TAG: "Cons", - key: key, - data: data, - next: Caml_array.get(h.data, i) - }; - Caml_array.set(h.data, i, bucket); - h.size = h.size + 1 | 0; - if (h.size > (h.data.length << 1)) { - return resize(key_index, h); - } - - }; - let remove = (h, key) => { - let i = key_index(h, key); - let _prec = "Empty"; - let _param = Caml_array.get(h.data, i); - while (true) { - let param = _param; - let prec = _prec; - if (typeof param !== "object") { - return; - } - let k = param.key; - let next = param.next; - if (H.equal(k, key)) { - h.size = h.size - 1 | 0; - if (typeof prec !== "object") { - return Caml_array.set(h.data, i, next); - } else { - prec.next = next; - return; - } - } - _param = next; - _prec = param; - continue; - }; - }; - let find = (h, key) => { - let match = Caml_array.get(h.data, key_index(h, key)); - if (typeof match !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let k1 = match.key; - let d1 = match.data; - let next1 = match.next; - if (H.equal(key, k1)) { - return d1; - } - if (typeof next1 !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let k2 = next1.key; - let d2 = next1.data; - let next2 = next1.next; - if (H.equal(key, k2)) { - return d2; - } - if (typeof next2 !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let k3 = next2.key; - let d3 = next2.data; - let next3 = next2.next; - if (H.equal(key, k3)) { - return d3; - } else { - let _param = next3; - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let k = param.key; - let data = param.data; - let next = param.next; - if (H.equal(key, k)) { - return data; - } - _param = next; - continue; - }; - } - }; - let find_opt = (h, key) => { - let match = Caml_array.get(h.data, key_index(h, key)); - if (typeof match !== "object") { - return; - } - let k1 = match.key; - let d1 = match.data; - let next1 = match.next; - if (H.equal(key, k1)) { - return Caml_option.some(d1); - } - if (typeof next1 !== "object") { - return; - } - let k2 = next1.key; - let d2 = next1.data; - let next2 = next1.next; - if (H.equal(key, k2)) { - return Caml_option.some(d2); - } - if (typeof next2 !== "object") { - return; - } - let k3 = next2.key; - let d3 = next2.data; - let next3 = next2.next; - if (H.equal(key, k3)) { - return Caml_option.some(d3); - } else { - let _param = next3; - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let k = param.key; - let data = param.data; - let next = param.next; - if (H.equal(key, k)) { - return Caml_option.some(data); - } - _param = next; - continue; - }; - } - }; - let find_all = (h, key) => { - let find_in_bucket = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return /* [] */0; - } - let k = param.key; - let d = param.data; - let next = param.next; - if (H.equal(k, key)) { - return { - hd: d, - tl: find_in_bucket(next) - }; - } - _param = next; - continue; - }; - }; - return find_in_bucket(Caml_array.get(h.data, key_index(h, key))); - }; - let replace_bucket = (key, data, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - let k = param.key; - let next = param.next; - if (H.equal(k, key)) { - param.key = key; - param.data = data; - return false; - } - _param = next; - continue; - }; - }; - let replace = (h, key, data) => { - let i = key_index(h, key); - let l = Caml_array.get(h.data, i); - if (replace_bucket(key, data, l)) { - Caml_array.set(h.data, i, { - TAG: "Cons", - key: key, - data: data, - next: l - }); - h.size = h.size + 1 | 0; - if (h.size > (h.data.length << 1)) { - return resize(key_index, h); - } else { - return; - } - } - - }; - let mem = (h, key) => { - let _param = Caml_array.get(h.data, key_index(h, key)); - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let k = param.key; - let next = param.next; - if (H.equal(k, key)) { - return true; - } - _param = next; - continue; - }; - }; - return { - create: create, - clear: clear, - reset: reset, - copy: copy, - add: add, - remove: remove, - find: find, - find_opt: find_opt, - find_all: find_all, - replace: replace, - mem: mem, - iter: iter, - filter_map_inplace: filter_map_inplace, - fold: fold, - length: length, - stats: stats - }; -} - -function Make(H) { - let equal = H.equal; - let key_index = (h, key) => H.hash(key) & (h.data.length - 1 | 0); - let add = (h, key, data) => { - let i = key_index(h, key); - let bucket = { - TAG: "Cons", - key: key, - data: data, - next: Caml_array.get(h.data, i) - }; - Caml_array.set(h.data, i, bucket); - h.size = h.size + 1 | 0; - if (h.size > (h.data.length << 1)) { - return resize(key_index, h); - } - - }; - let remove = (h, key) => { - let i = key_index(h, key); - let _prec = "Empty"; - let _param = Caml_array.get(h.data, i); - while (true) { - let param = _param; - let prec = _prec; - if (typeof param !== "object") { - return; - } - let k = param.key; - let next = param.next; - if (equal(k, key)) { - h.size = h.size - 1 | 0; - if (typeof prec !== "object") { - return Caml_array.set(h.data, i, next); - } else { - prec.next = next; - return; - } - } - _param = next; - _prec = param; - continue; - }; - }; - let find = (h, key) => { - let match = Caml_array.get(h.data, key_index(h, key)); - if (typeof match !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let k1 = match.key; - let d1 = match.data; - let next1 = match.next; - if (equal(key, k1)) { - return d1; - } - if (typeof next1 !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let k2 = next1.key; - let d2 = next1.data; - let next2 = next1.next; - if (equal(key, k2)) { - return d2; - } - if (typeof next2 !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let k3 = next2.key; - let d3 = next2.data; - let next3 = next2.next; - if (equal(key, k3)) { - return d3; - } else { - let _param = next3; - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let k = param.key; - let data = param.data; - let next = param.next; - if (equal(key, k)) { - return data; - } - _param = next; - continue; - }; - } - }; - let find_opt = (h, key) => { - let match = Caml_array.get(h.data, key_index(h, key)); - if (typeof match !== "object") { - return; - } - let k1 = match.key; - let d1 = match.data; - let next1 = match.next; - if (equal(key, k1)) { - return Caml_option.some(d1); - } - if (typeof next1 !== "object") { - return; - } - let k2 = next1.key; - let d2 = next1.data; - let next2 = next1.next; - if (equal(key, k2)) { - return Caml_option.some(d2); - } - if (typeof next2 !== "object") { - return; - } - let k3 = next2.key; - let d3 = next2.data; - let next3 = next2.next; - if (equal(key, k3)) { - return Caml_option.some(d3); - } else { - let _param = next3; - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let k = param.key; - let data = param.data; - let next = param.next; - if (equal(key, k)) { - return Caml_option.some(data); - } - _param = next; - continue; - }; - } - }; - let find_all = (h, key) => { - let find_in_bucket = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return /* [] */0; - } - let k = param.key; - let d = param.data; - let next = param.next; - if (equal(k, key)) { - return { - hd: d, - tl: find_in_bucket(next) - }; - } - _param = next; - continue; - }; - }; - return find_in_bucket(Caml_array.get(h.data, key_index(h, key))); - }; - let replace_bucket = (key, data, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - let k = param.key; - let next = param.next; - if (equal(k, key)) { - param.key = key; - param.data = data; - return false; - } - _param = next; - continue; - }; - }; - let replace = (h, key, data) => { - let i = key_index(h, key); - let l = Caml_array.get(h.data, i); - if (replace_bucket(key, data, l)) { - Caml_array.set(h.data, i, { - TAG: "Cons", - key: key, - data: data, - next: l - }); - h.size = h.size + 1 | 0; - if (h.size > (h.data.length << 1)) { - return resize(key_index, h); - } else { - return; - } - } - - }; - let mem = (h, key) => { - let _param = Caml_array.get(h.data, key_index(h, key)); - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let k = param.key; - let next = param.next; - if (equal(k, key)) { - return true; - } - _param = next; - continue; - }; - }; - let create$1 = sz => create(false, sz); - return { - create: create$1, - clear: clear, - reset: reset, - copy: copy, - add: add, - remove: remove, - find: find, - find_opt: find_opt, - find_all: find_all, - replace: replace, - mem: mem, - iter: iter, - filter_map_inplace: filter_map_inplace, - fold: fold, - length: length, - stats: stats - }; -} - -let seeded_hash_param = Caml_hash.hash; - export { - create, - clear, - reset, - copy, - add, - find, - find_opt, - find_all, - mem, - remove, - replace, - iter, - filter_map_inplace, - fold, - length, - randomize, - is_randomized, - stats, - Make, - MakeSeeded, hash, - seeded_hash, - hash_param, - seeded_hash_param, } /* No side effect */ diff --git a/lib/es6/hashtblLabels.js b/lib/es6/hashtblLabels.js deleted file mode 100644 index 830e53d19f..0000000000 --- a/lib/es6/hashtblLabels.js +++ /dev/null @@ -1,157 +0,0 @@ - - -import * as Hashtbl from "./hashtbl.js"; - -function add(tbl, key, data) { - Hashtbl.add(tbl, key, data); -} - -function replace(tbl, key, data) { - Hashtbl.replace(tbl, key, data); -} - -function iter(f, tbl) { - Hashtbl.iter((key, data) => f(key, data), tbl); -} - -function filter_map_inplace(f, tbl) { - Hashtbl.filter_map_inplace((key, data) => f(key, data), tbl); -} - -function fold(f, tbl, init) { - return Hashtbl.fold((key, data, acc) => f(key, data, acc), tbl, init); -} - -function MakeSeeded(H) { - let include = Hashtbl.MakeSeeded(H); - let add = include.add; - let replace = include.replace; - let iter = include.iter; - let filter_map_inplace = include.filter_map_inplace; - let fold = include.fold; - let add$1 = (tbl, key, data) => add(tbl, key, data); - let replace$1 = (tbl, key, data) => replace(tbl, key, data); - let iter$1 = (f, tbl) => iter((key, data) => f(key, data), tbl); - let filter_map_inplace$1 = (f, tbl) => filter_map_inplace((key, data) => f(key, data), tbl); - let fold$1 = (f, tbl, init) => fold((key, data, acc) => f(key, data, acc), tbl, init); - return { - create: include.create, - clear: include.clear, - reset: include.reset, - copy: include.copy, - add: add$1, - remove: include.remove, - find: include.find, - find_opt: include.find_opt, - find_all: include.find_all, - replace: replace$1, - mem: include.mem, - iter: iter$1, - filter_map_inplace: filter_map_inplace$1, - fold: fold$1, - length: include.length, - stats: include.stats - }; -} - -function Make(H) { - let hash = (_seed, x) => H.hash(x); - let H_equal = H.equal; - let H$1 = { - equal: H_equal, - hash: hash - }; - let include = Hashtbl.MakeSeeded(H$1); - let create = include.create; - let add = include.add; - let replace = include.replace; - let iter = include.iter; - let filter_map_inplace = include.filter_map_inplace; - let fold = include.fold; - let add$1 = (tbl, key, data) => add(tbl, key, data); - let replace$1 = (tbl, key, data) => replace(tbl, key, data); - let iter$1 = (f, tbl) => iter((key, data) => f(key, data), tbl); - let filter_map_inplace$1 = (f, tbl) => filter_map_inplace((key, data) => f(key, data), tbl); - let fold$1 = (f, tbl, init) => fold((key, data, acc) => f(key, data, acc), tbl, init); - let create$1 = sz => create(false, sz); - return { - create: create$1, - clear: include.clear, - reset: include.reset, - copy: include.copy, - add: add$1, - remove: include.remove, - find: include.find, - find_opt: include.find_opt, - find_all: include.find_all, - replace: replace$1, - mem: include.mem, - iter: iter$1, - filter_map_inplace: filter_map_inplace$1, - fold: fold$1, - length: include.length, - stats: include.stats - }; -} - -let create = Hashtbl.create; - -let clear = Hashtbl.clear; - -let reset = Hashtbl.reset; - -let copy = Hashtbl.copy; - -let find = Hashtbl.find; - -let find_opt = Hashtbl.find_opt; - -let find_all = Hashtbl.find_all; - -let mem = Hashtbl.mem; - -let remove = Hashtbl.remove; - -let length = Hashtbl.length; - -let randomize = Hashtbl.randomize; - -let is_randomized = Hashtbl.is_randomized; - -let stats = Hashtbl.stats; - -let hash = Hashtbl.hash; - -let seeded_hash = Hashtbl.seeded_hash; - -let hash_param = Hashtbl.hash_param; - -let seeded_hash_param = Hashtbl.seeded_hash_param; - -export { - create, - clear, - reset, - copy, - find, - find_opt, - find_all, - mem, - remove, - length, - randomize, - is_randomized, - stats, - hash, - seeded_hash, - hash_param, - seeded_hash_param, - add, - replace, - iter, - filter_map_inplace, - fold, - MakeSeeded, - Make, -} -/* No side effect */ diff --git a/lib/es6/int32.js b/lib/es6/int32.js deleted file mode 100644 index dff650c3e9..0000000000 --- a/lib/es6/int32.js +++ /dev/null @@ -1,74 +0,0 @@ - - -import * as Caml from "./caml.js"; -import * as Caml_format from "./caml_format.js"; -import * as Caml_js_exceptions from "./caml_js_exceptions.js"; - -function succ(n) { - return n + 1 | 0; -} - -function pred(n) { - return n - 1 | 0; -} - -function abs(n) { - if (n >= 0) { - return n; - } else { - return -n | 0; - } -} - -function lognot(n) { - return n ^ -1; -} - -function to_string(n) { - return Caml_format.format_int("%d", n); -} - -function of_string_opt(s) { - try { - return Caml_format.int_of_string(s); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Failure") { - return; - } - throw exn; - } -} - -let compare = Caml.int_compare; - -function equal(x, y) { - return x === y; -} - -let zero = 0; - -let one = 1; - -let minus_one = -1; - -let max_int = 2147483647; - -let min_int = -2147483648; - -export { - zero, - one, - minus_one, - succ, - pred, - abs, - max_int, - min_int, - lognot, - of_string_opt, - to_string, - compare, - equal, -} -/* No side effect */ diff --git a/lib/es6/int64.js b/lib/es6/int64.js deleted file mode 100644 index 37fd9241c7..0000000000 --- a/lib/es6/int64.js +++ /dev/null @@ -1,69 +0,0 @@ - - -import * as Caml from "./caml.js"; -import * as Caml_int64 from "./caml_int64.js"; -import * as Caml_format from "./caml_format.js"; -import * as Caml_js_exceptions from "./caml_js_exceptions.js"; - -function pred(n) { - return Caml_int64.sub(n, Caml_int64.one); -} - -function abs(n) { - if (Caml.i64_ge(n, Caml_int64.zero)) { - return n; - } else { - return Caml_int64.neg(n); - } -} - -function lognot(n) { - return Caml_int64.xor(n, Caml_int64.neg_one); -} - -function of_string_opt(s) { - try { - return Caml_format.int64_of_string(s); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Failure") { - return; - } - throw exn; - } -} - -let compare = Caml_int64.compare; - -let equal = Caml_int64.equal; - -let zero = Caml_int64.zero; - -let one = Caml_int64.one; - -let minus_one = Caml_int64.neg_one; - -let succ = Caml_int64.succ; - -let max_int = Caml_int64.max_int; - -let min_int = Caml_int64.min_int; - -let to_string = Caml_int64.to_string; - -export { - zero, - one, - minus_one, - succ, - pred, - abs, - max_int, - min_int, - lognot, - of_string_opt, - to_string, - compare, - equal, -} -/* No side effect */ diff --git a/lib/es6/js_array.js b/lib/es6/js_array.js index 792c8b9f75..a994aae64f 100644 --- a/lib/es6/js_array.js +++ b/lib/es6/js_array.js @@ -1,6 +1,6 @@ -import * as Caml_option from "./caml_option.js"; +import * as Primitive_option from "./primitive_option.js"; function copyWithin(to_, obj) { return obj.copyWithin(to_); @@ -115,11 +115,11 @@ function filteri(arg1, obj) { } function find(arg1, obj) { - return Caml_option.undefined_to_opt(obj.find(arg1)); + return Primitive_option.fromUndefined(obj.find(arg1)); } function findi(arg1, obj) { - return Caml_option.undefined_to_opt(obj.find(arg1)); + return Primitive_option.fromUndefined(obj.find(arg1)); } function findIndex(arg1, obj) { diff --git a/lib/es6/js_dict.js b/lib/es6/js_dict.js index 3aae438cf0..9982e6e400 100644 --- a/lib/es6/js_dict.js +++ b/lib/es6/js_dict.js @@ -1,10 +1,10 @@ -import * as Caml_option from "./caml_option.js"; +import * as Primitive_option from "./primitive_option.js"; function get(dict, k) { if ((k in dict)) { - return Caml_option.some(dict[k]); + return Primitive_option.some(dict[k]); } } diff --git a/lib/es6/js_exn.js b/lib/es6/js_exn.js index 74add0dd3a..b377a7d4ec 100644 --- a/lib/es6/js_exn.js +++ b/lib/es6/js_exn.js @@ -1,5 +1,16 @@ +import * as Primitive_option from "./primitive_option.js"; + +let $$Error = "JsError"; + +function asJsExn(exn) { + let t = exn; + if (t.RE_EXN_ID === $$Error) { + return Primitive_option.some(t._1); + } + +} function raiseError(str) { throw new Error(str); @@ -29,10 +40,9 @@ function raiseUriError(str) { throw new URIError(str); } -let $$Error$1 = "JsError"; - export { - $$Error$1 as $$Error, + $$Error, + asJsExn, raiseError, raiseEvalError, raiseRangeError, diff --git a/lib/es6/caml_array_extern.js b/lib/es6/js_extern.js similarity index 100% rename from lib/es6/caml_array_extern.js rename to lib/es6/js_extern.js diff --git a/lib/es6/js_null.js b/lib/es6/js_null.js index 9ac6a94514..7265c16353 100644 --- a/lib/es6/js_null.js +++ b/lib/es6/js_null.js @@ -1,6 +1,6 @@ -import * as Caml_option from "./caml_option.js"; +import * as Primitive_option from "./primitive_option.js"; function test(x) { return x === null; @@ -30,7 +30,7 @@ function iter(x, f) { function fromOption(x) { if (x !== undefined) { - return Caml_option.valFromOption(x); + return Primitive_option.valFromOption(x); } else { return null; } diff --git a/lib/es6/js_null_undefined.js b/lib/es6/js_null_undefined.js index 58e5799d43..a690d60b65 100644 --- a/lib/es6/js_null_undefined.js +++ b/lib/es6/js_null_undefined.js @@ -1,6 +1,6 @@ -import * as Caml_option from "./caml_option.js"; +import * as Primitive_option from "./primitive_option.js"; function bind(x, f) { if (x == null) { @@ -19,7 +19,7 @@ function iter(x, f) { function fromOption(x) { if (x !== undefined) { - return Caml_option.valFromOption(x); + return Primitive_option.valFromOption(x); } } diff --git a/lib/es6/js_option.js b/lib/es6/js_option.js index 0667fcd74d..168a15c637 100644 --- a/lib/es6/js_option.js +++ b/lib/es6/js_option.js @@ -1,9 +1,9 @@ -import * as Caml_option from "./caml_option.js"; +import * as Primitive_option from "./primitive_option.js"; function some(x) { - return Caml_option.some(x); + return Primitive_option.some(x); } function isSome(x) { @@ -12,7 +12,7 @@ function isSome(x) { function isSomeValue(eq, v, x) { if (x !== undefined) { - return eq(v, Caml_option.valFromOption(x)); + return eq(v, Primitive_option.valFromOption(x)); } else { return false; } @@ -24,7 +24,7 @@ function isNone(x) { function getExn(x) { if (x !== undefined) { - return Caml_option.valFromOption(x); + return Primitive_option.valFromOption(x); } throw new Error("getExn"); } @@ -32,7 +32,7 @@ function getExn(x) { function equal(eq, a, b) { if (a !== undefined) { if (b !== undefined) { - return eq(Caml_option.valFromOption(a), Caml_option.valFromOption(b)); + return eq(Primitive_option.valFromOption(a), Primitive_option.valFromOption(b)); } else { return false; } @@ -43,21 +43,21 @@ function equal(eq, a, b) { function andThen(f, x) { if (x !== undefined) { - return f(Caml_option.valFromOption(x)); + return f(Primitive_option.valFromOption(x)); } } function map(f, x) { if (x !== undefined) { - return Caml_option.some(f(Caml_option.valFromOption(x))); + return Primitive_option.some(f(Primitive_option.valFromOption(x))); } } function getWithDefault(a, x) { if (x !== undefined) { - return Caml_option.valFromOption(x); + return Primitive_option.valFromOption(x); } else { return a; } @@ -67,9 +67,9 @@ function filter(f, x) { if (x === undefined) { return; } - let x$1 = Caml_option.valFromOption(x); + let x$1 = Primitive_option.valFromOption(x); if (f(x$1)) { - return Caml_option.some(x$1); + return Primitive_option.some(x$1); } } diff --git a/lib/es6/js_string.js b/lib/es6/js_string.js index 05ba50bd0c..e0af5fc66c 100644 --- a/lib/es6/js_string.js +++ b/lib/es6/js_string.js @@ -1,6 +1,6 @@ -import * as Caml_option from "./caml_option.js"; +import * as Primitive_option from "./primitive_option.js"; function charAt(arg1, obj) { return obj.charAt(arg1); @@ -59,7 +59,7 @@ function localeCompare(arg1, obj) { } function match_(arg1, obj) { - return Caml_option.null_to_opt(obj.match(arg1)); + return Primitive_option.fromNull(obj.match(arg1)); } function normalizeByForm(arg1, obj) { diff --git a/lib/es6/js_undefined.js b/lib/es6/js_undefined.js index 8d5125bc03..a48caa1d9d 100644 --- a/lib/es6/js_undefined.js +++ b/lib/es6/js_undefined.js @@ -1,6 +1,6 @@ -import * as Caml_option from "./caml_option.js"; +import * as Primitive_option from "./primitive_option.js"; function test(x) { return x === undefined; @@ -33,7 +33,7 @@ function iter(x, f) { function fromOption(x) { if (x !== undefined) { - return Caml_option.valFromOption(x); + return Primitive_option.valFromOption(x); } } diff --git a/lib/es6/lazy.js b/lib/es6/lazy.js index e858dde9b2..2826f65e78 100644 --- a/lib/es6/lazy.js +++ b/lib/es6/lazy.js @@ -1,33 +1,25 @@ -import * as CamlinternalLazy from "./camlinternalLazy.js"; +import * as Primitive_lazy from "./primitive_lazy.js"; -function from_fun(f) { - return CamlinternalLazy.from_fun(() => f()); -} - -let from_val = CamlinternalLazy.from_val; - -let Undefined = CamlinternalLazy.Undefined; +let Undefined = Primitive_lazy.Undefined; -let force_val = CamlinternalLazy.force_val; +let force = Primitive_lazy.force; -let is_val = CamlinternalLazy.is_val; +let force_val = Primitive_lazy.force_val; -let lazy_from_fun = from_fun; +let from_fun = Primitive_lazy.from_fun; -let lazy_from_val = from_val; +let from_val = Primitive_lazy.from_val; -let lazy_is_val = CamlinternalLazy.is_val; +let is_val = Primitive_lazy.is_val; export { Undefined, + force, force_val, from_fun, from_val, is_val, - lazy_from_fun, - lazy_from_val, - lazy_is_val, } /* No side effect */ diff --git a/lib/es6/lexing.js b/lib/es6/lexing.js deleted file mode 100644 index 33175bdb02..0000000000 --- a/lib/es6/lexing.js +++ /dev/null @@ -1,216 +0,0 @@ - - -import * as Bytes from "./bytes.js"; -import * as Caml_array from "./caml_array.js"; -import * as Caml_bytes from "./caml_bytes.js"; -import * as Caml_lexer from "./caml_lexer.js"; - -function engine(tbl, state, buf) { - let result = Caml_lexer.lex_engine(tbl, state, buf); - if (result >= 0) { - buf.lex_start_p = buf.lex_curr_p; - let init = buf.lex_curr_p; - buf.lex_curr_p = { - pos_fname: init.pos_fname, - pos_lnum: init.pos_lnum, - pos_bol: init.pos_bol, - pos_cnum: buf.lex_abs_pos + buf.lex_curr_pos | 0 - }; - } - return result; -} - -function new_engine(tbl, state, buf) { - let result = Caml_lexer.new_lex_engine(tbl, state, buf); - if (result >= 0) { - buf.lex_start_p = buf.lex_curr_p; - let init = buf.lex_curr_p; - buf.lex_curr_p = { - pos_fname: init.pos_fname, - pos_lnum: init.pos_lnum, - pos_bol: init.pos_bol, - pos_cnum: buf.lex_abs_pos + buf.lex_curr_pos | 0 - }; - } - return result; -} - -let zero_pos = { - pos_fname: "", - pos_lnum: 1, - pos_bol: 0, - pos_cnum: 0 -}; - -function from_function(f) { - return { - refill_buff: x => { - let aux_buffer = Caml_bytes.create(512); - let read = f(aux_buffer, aux_buffer.length); - let n = read > 0 ? read : (x.lex_eof_reached = true, 0); - if ((x.lex_buffer_len + n | 0) > x.lex_buffer.length) { - if (((x.lex_buffer_len - x.lex_start_pos | 0) + n | 0) <= x.lex_buffer.length) { - Bytes.blit(x.lex_buffer, x.lex_start_pos, x.lex_buffer, 0, x.lex_buffer_len - x.lex_start_pos | 0); - } else { - let newlen = (x.lex_buffer.length << 1); - if (((x.lex_buffer_len - x.lex_start_pos | 0) + n | 0) > newlen) { - throw { - RE_EXN_ID: "Failure", - _1: "Lexing.lex_refill: cannot grow buffer", - Error: new Error() - }; - } - let newbuf = Caml_bytes.create(newlen); - Bytes.blit(x.lex_buffer, x.lex_start_pos, newbuf, 0, x.lex_buffer_len - x.lex_start_pos | 0); - x.lex_buffer = newbuf; - } - let s = x.lex_start_pos; - x.lex_abs_pos = x.lex_abs_pos + s | 0; - x.lex_curr_pos = x.lex_curr_pos - s | 0; - x.lex_start_pos = 0; - x.lex_last_pos = x.lex_last_pos - s | 0; - x.lex_buffer_len = x.lex_buffer_len - s | 0; - let t = x.lex_mem; - for (let i = 0, i_finish = t.length; i < i_finish; ++i) { - let v = Caml_array.get(t, i); - if (v >= 0) { - Caml_array.set(t, i, v - s | 0); - } - - } - } - Bytes.blit(aux_buffer, 0, x.lex_buffer, x.lex_buffer_len, n); - x.lex_buffer_len = x.lex_buffer_len + n | 0; - }, - lex_buffer: Caml_bytes.create(1024), - lex_buffer_len: 0, - lex_abs_pos: 0, - lex_start_pos: 0, - lex_curr_pos: 0, - lex_last_pos: 0, - lex_last_action: 0, - lex_eof_reached: false, - lex_mem: [], - lex_start_p: zero_pos, - lex_curr_p: zero_pos - }; -} - -function from_string(s) { - return { - refill_buff: lexbuf => { - lexbuf.lex_eof_reached = true; - }, - lex_buffer: Bytes.of_string(s), - lex_buffer_len: s.length, - lex_abs_pos: 0, - lex_start_pos: 0, - lex_curr_pos: 0, - lex_last_pos: 0, - lex_last_action: 0, - lex_eof_reached: true, - lex_mem: [], - lex_start_p: zero_pos, - lex_curr_p: zero_pos - }; -} - -function lexeme(lexbuf) { - let len = lexbuf.lex_curr_pos - lexbuf.lex_start_pos | 0; - return Bytes.sub_string(lexbuf.lex_buffer, lexbuf.lex_start_pos, len); -} - -function sub_lexeme(lexbuf, i1, i2) { - let len = i2 - i1 | 0; - return Bytes.sub_string(lexbuf.lex_buffer, i1, len); -} - -function sub_lexeme_opt(lexbuf, i1, i2) { - if (i1 < 0) { - return; - } - let len = i2 - i1 | 0; - return Bytes.sub_string(lexbuf.lex_buffer, i1, len); -} - -function sub_lexeme_char(lexbuf, i) { - return Caml_bytes.get(lexbuf.lex_buffer, i); -} - -function sub_lexeme_char_opt(lexbuf, i) { - if (i >= 0) { - return Caml_bytes.get(lexbuf.lex_buffer, i); - } - -} - -function lexeme_char(lexbuf, i) { - return Caml_bytes.get(lexbuf.lex_buffer, lexbuf.lex_start_pos + i | 0); -} - -function lexeme_start(lexbuf) { - return lexbuf.lex_start_p.pos_cnum; -} - -function lexeme_end(lexbuf) { - return lexbuf.lex_curr_p.pos_cnum; -} - -function lexeme_start_p(lexbuf) { - return lexbuf.lex_start_p; -} - -function lexeme_end_p(lexbuf) { - return lexbuf.lex_curr_p; -} - -function new_line(lexbuf) { - let lcp = lexbuf.lex_curr_p; - lexbuf.lex_curr_p = { - pos_fname: lcp.pos_fname, - pos_lnum: lcp.pos_lnum + 1 | 0, - pos_bol: lcp.pos_cnum, - pos_cnum: lcp.pos_cnum - }; -} - -function flush_input(lb) { - lb.lex_curr_pos = 0; - lb.lex_abs_pos = 0; - let init = lb.lex_curr_p; - lb.lex_curr_p = { - pos_fname: init.pos_fname, - pos_lnum: init.pos_lnum, - pos_bol: init.pos_bol, - pos_cnum: 0 - }; - lb.lex_buffer_len = 0; -} - -let dummy_pos = { - pos_fname: "", - pos_lnum: 0, - pos_bol: 0, - pos_cnum: -1 -}; - -export { - dummy_pos, - from_string, - from_function, - lexeme, - lexeme_char, - lexeme_start, - lexeme_end, - lexeme_start_p, - lexeme_end_p, - new_line, - flush_input, - sub_lexeme, - sub_lexeme_opt, - sub_lexeme_char, - sub_lexeme_char_opt, - engine, - new_engine, -} -/* No side effect */ diff --git a/lib/es6/list.js b/lib/es6/list.js index 0143699d17..e49b834516 100644 --- a/lib/es6/list.js +++ b/lib/es6/list.js @@ -1,8 +1,7 @@ -import * as Caml_obj from "./caml_obj.js"; import * as Pervasives from "./pervasives.js"; -import * as Caml_option from "./caml_option.js"; +import * as Primitive_option from "./primitive_option.js"; function length(l) { let _len = 0; @@ -94,7 +93,7 @@ function nth_opt(l, n) { return; } if (n$1 === 0) { - return Caml_option.some(l$1.hd); + return Primitive_option.some(l$1.hd); } _n = n$1 - 1 | 0; _l = l$1.tl; @@ -497,7 +496,7 @@ function mem(x, _param) { if (!param) { return false; } - if (Caml_obj.equal(param.hd, x)) { + if (param.hd === x) { return true; } _param = param.tl; @@ -524,7 +523,7 @@ function assoc(x, _param) { let param = _param; if (param) { let match = param.hd; - if (Caml_obj.equal(match[0], x)) { + if (match[0] === x) { return match[1]; } _param = param.tl; @@ -544,8 +543,8 @@ function assoc_opt(x, _param) { return; } let match = param.hd; - if (Caml_obj.equal(match[0], x)) { - return Caml_option.some(match[1]); + if (match[0] === x) { + return Primitive_option.some(match[1]); } _param = param.tl; continue; @@ -578,7 +577,7 @@ function assq_opt(x, _param) { } let match = param.hd; if (match[0] === x) { - return Caml_option.some(match[1]); + return Primitive_option.some(match[1]); } _param = param.tl; continue; @@ -591,7 +590,7 @@ function mem_assoc(x, _param) { if (!param) { return false; } - if (Caml_obj.equal(param.hd[0], x)) { + if (param.hd[0] === x) { return true; } _param = param.tl; @@ -619,7 +618,7 @@ function remove_assoc(x, param) { } let l = param.tl; let pair = param.hd; - if (Caml_obj.equal(pair[0], x)) { + if (pair[0] === x) { return l; } else { return { @@ -671,7 +670,7 @@ function find_opt(p, _param) { } let x = param.hd; if (p(x)) { - return Caml_option.some(x); + return Primitive_option.some(x); } _param = param.tl; continue; @@ -821,7 +820,7 @@ function chop(_k, _l) { RE_EXN_ID: "Assert_failure", _1: [ "list.res", - 420, + 411, 11 ], Error: new Error() diff --git a/lib/es6/listLabels.js b/lib/es6/listLabels.js deleted file mode 100644 index e85c6163f4..0000000000 --- a/lib/es6/listLabels.js +++ /dev/null @@ -1,1710 +0,0 @@ - - -import * as Caml_obj from "./caml_obj.js"; -import * as Pervasives from "./pervasives.js"; -import * as Caml_option from "./caml_option.js"; - -function length(l) { - let _len = 0; - let _param = l; - while (true) { - let param = _param; - let len = _len; - if (!param) { - return len; - } - _param = param.tl; - _len = len + 1 | 0; - continue; - }; -} - -function cons(a, l) { - return { - hd: a, - tl: l - }; -} - -function hd(param) { - if (param) { - return param.hd; - } - throw { - RE_EXN_ID: "Failure", - _1: "hd", - Error: new Error() - }; -} - -function tl(param) { - if (param) { - return param.tl; - } - throw { - RE_EXN_ID: "Failure", - _1: "tl", - Error: new Error() - }; -} - -function nth(l, n) { - if (n < 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.nth", - Error: new Error() - }; - } - let _l = l; - let _n = n; - while (true) { - let n$1 = _n; - let l$1 = _l; - if (l$1) { - if (n$1 === 0) { - return l$1.hd; - } - _n = n$1 - 1 | 0; - _l = l$1.tl; - continue; - } - throw { - RE_EXN_ID: "Failure", - _1: "nth", - Error: new Error() - }; - }; -} - -function nth_opt(l, n) { - if (n < 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.nth", - Error: new Error() - }; - } - let _l = l; - let _n = n; - while (true) { - let n$1 = _n; - let l$1 = _l; - if (!l$1) { - return; - } - if (n$1 === 0) { - return Caml_option.some(l$1.hd); - } - _n = n$1 - 1 | 0; - _l = l$1.tl; - continue; - }; -} - -function rev_append(_l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (!l1) { - return l2; - } - _l2 = { - hd: l1.hd, - tl: l2 - }; - _l1 = l1.tl; - continue; - }; -} - -function rev(l) { - return rev_append(l, /* [] */0); -} - -function init_tailrec_aux(_acc, _i, n, f) { - while (true) { - let i = _i; - let acc = _acc; - if (i >= n) { - return acc; - } - _i = i + 1 | 0; - _acc = { - hd: f(i), - tl: acc - }; - continue; - }; -} - -function init_aux(i, n, f) { - if (i >= n) { - return /* [] */0; - } - let r = f(i); - return { - hd: r, - tl: init_aux(i + 1 | 0, n, f) - }; -} - -function init(len, f) { - if (len < 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.init", - Error: new Error() - }; - } - if (len > 10000) { - return rev_append(init_tailrec_aux(/* [] */0, 0, len, f), /* [] */0); - } else { - return init_aux(0, len, f); - } -} - -function flatten(param) { - if (param) { - return Pervasives.$at(param.hd, flatten(param.tl)); - } else { - return /* [] */0; - } -} - -function map(f, param) { - if (!param) { - return /* [] */0; - } - let r = f(param.hd); - return { - hd: r, - tl: map(f, param.tl) - }; -} - -function mapi(i, f, param) { - if (!param) { - return /* [] */0; - } - let r = f(i, param.hd); - return { - hd: r, - tl: mapi(i + 1 | 0, f, param.tl) - }; -} - -function mapi$1(f, l) { - return mapi(0, f, l); -} - -function rev_map(f, l) { - let _accu = /* [] */0; - let _param = l; - while (true) { - let param = _param; - let accu = _accu; - if (!param) { - return accu; - } - _param = param.tl; - _accu = { - hd: f(param.hd), - tl: accu - }; - continue; - }; -} - -function iter(f, _param) { - while (true) { - let param = _param; - if (!param) { - return; - } - f(param.hd); - _param = param.tl; - continue; - }; -} - -function iteri(f, l) { - let _i = 0; - let _param = l; - while (true) { - let param = _param; - let i = _i; - if (!param) { - return; - } - f(i, param.hd); - _param = param.tl; - _i = i + 1 | 0; - continue; - }; -} - -function fold_left(f, _accu, _l) { - while (true) { - let l = _l; - let accu = _accu; - if (!l) { - return accu; - } - _l = l.tl; - _accu = f(accu, l.hd); - continue; - }; -} - -function fold_right(f, l, accu) { - if (l) { - return f(l.hd, fold_right(f, l.tl, accu)); - } else { - return accu; - } -} - -function map2(f, l1, l2) { - if (l1) { - if (l2) { - let r = f(l1.hd, l2.hd); - return { - hd: r, - tl: map2(f, l1.tl, l2.tl) - }; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.map2", - Error: new Error() - }; - } - if (!l2) { - return /* [] */0; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.map2", - Error: new Error() - }; -} - -function rev_map2(f, l1, l2) { - let _accu = /* [] */0; - let _l1 = l1; - let _l2 = l2; - while (true) { - let l2$1 = _l2; - let l1$1 = _l1; - let accu = _accu; - if (l1$1) { - if (l2$1) { - _l2 = l2$1.tl; - _l1 = l1$1.tl; - _accu = { - hd: f(l1$1.hd, l2$1.hd), - tl: accu - }; - continue; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.rev_map2", - Error: new Error() - }; - } - if (l2$1) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.rev_map2", - Error: new Error() - }; - } - return accu; - }; -} - -function iter2(f, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (l1) { - if (l2) { - f(l1.hd, l2.hd); - _l2 = l2.tl; - _l1 = l1.tl; - continue; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.iter2", - Error: new Error() - }; - } - if (!l2) { - return; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.iter2", - Error: new Error() - }; - }; -} - -function fold_left2(f, _accu, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - let accu = _accu; - if (l1) { - if (l2) { - _l2 = l2.tl; - _l1 = l1.tl; - _accu = f(accu, l1.hd, l2.hd); - continue; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_left2", - Error: new Error() - }; - } - if (l2) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_left2", - Error: new Error() - }; - } - return accu; - }; -} - -function fold_right2(f, l1, l2, accu) { - if (l1) { - if (l2) { - return f(l1.hd, l2.hd, fold_right2(f, l1.tl, l2.tl, accu)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_right2", - Error: new Error() - }; - } - if (l2) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_right2", - Error: new Error() - }; - } - return accu; -} - -function for_all(p, _param) { - while (true) { - let param = _param; - if (!param) { - return true; - } - if (!p(param.hd)) { - return false; - } - _param = param.tl; - continue; - }; -} - -function exists(p, _param) { - while (true) { - let param = _param; - if (!param) { - return false; - } - if (p(param.hd)) { - return true; - } - _param = param.tl; - continue; - }; -} - -function for_all2(p, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (l1) { - if (l2) { - if (!p(l1.hd, l2.hd)) { - return false; - } - _l2 = l2.tl; - _l1 = l1.tl; - continue; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.for_all2", - Error: new Error() - }; - } - if (!l2) { - return true; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.for_all2", - Error: new Error() - }; - }; -} - -function exists2(p, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (l1) { - if (l2) { - if (p(l1.hd, l2.hd)) { - return true; - } - _l2 = l2.tl; - _l1 = l1.tl; - continue; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.exists2", - Error: new Error() - }; - } - if (!l2) { - return false; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.exists2", - Error: new Error() - }; - }; -} - -function mem(x, _set) { - while (true) { - let set = _set; - if (!set) { - return false; - } - if (Caml_obj.equal(set.hd, x)) { - return true; - } - _set = set.tl; - continue; - }; -} - -function memq(x, _set) { - while (true) { - let set = _set; - if (!set) { - return false; - } - if (set.hd === x) { - return true; - } - _set = set.tl; - continue; - }; -} - -function assoc(x, _param) { - while (true) { - let param = _param; - if (param) { - let match = param.hd; - if (Caml_obj.equal(match[0], x)) { - return match[1]; - } - _param = param.tl; - continue; - } - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - }; -} - -function assoc_opt(x, _param) { - while (true) { - let param = _param; - if (!param) { - return; - } - let match = param.hd; - if (Caml_obj.equal(match[0], x)) { - return Caml_option.some(match[1]); - } - _param = param.tl; - continue; - }; -} - -function assq(x, _param) { - while (true) { - let param = _param; - if (param) { - let match = param.hd; - if (match[0] === x) { - return match[1]; - } - _param = param.tl; - continue; - } - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - }; -} - -function assq_opt(x, _param) { - while (true) { - let param = _param; - if (!param) { - return; - } - let match = param.hd; - if (match[0] === x) { - return Caml_option.some(match[1]); - } - _param = param.tl; - continue; - }; -} - -function mem_assoc(x, _map) { - while (true) { - let map = _map; - if (!map) { - return false; - } - if (Caml_obj.equal(map.hd[0], x)) { - return true; - } - _map = map.tl; - continue; - }; -} - -function mem_assq(x, _map) { - while (true) { - let map = _map; - if (!map) { - return false; - } - if (map.hd[0] === x) { - return true; - } - _map = map.tl; - continue; - }; -} - -function remove_assoc(x, param) { - if (!param) { - return /* [] */0; - } - let l = param.tl; - let pair = param.hd; - if (Caml_obj.equal(pair[0], x)) { - return l; - } else { - return { - hd: pair, - tl: remove_assoc(x, l) - }; - } -} - -function remove_assq(x, param) { - if (!param) { - return /* [] */0; - } - let l = param.tl; - let pair = param.hd; - if (pair[0] === x) { - return l; - } else { - return { - hd: pair, - tl: remove_assq(x, l) - }; - } -} - -function find(p, _param) { - while (true) { - let param = _param; - if (param) { - let x = param.hd; - if (p(x)) { - return x; - } - _param = param.tl; - continue; - } - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - }; -} - -function find_opt(p, _param) { - while (true) { - let param = _param; - if (!param) { - return; - } - let x = param.hd; - if (p(x)) { - return Caml_option.some(x); - } - _param = param.tl; - continue; - }; -} - -function find_all(p, l) { - let _accu = /* [] */0; - let _param = l; - while (true) { - let param = _param; - let accu = _accu; - if (!param) { - return rev_append(accu, /* [] */0); - } - let l$1 = param.tl; - let x = param.hd; - if (p(x)) { - _param = l$1; - _accu = { - hd: x, - tl: accu - }; - continue; - } - _param = l$1; - continue; - }; -} - -function partition(p, l) { - let _yes = /* [] */0; - let _no = /* [] */0; - let _param = l; - while (true) { - let param = _param; - let no = _no; - let yes = _yes; - if (!param) { - return [ - rev_append(yes, /* [] */0), - rev_append(no, /* [] */0) - ]; - } - let l$1 = param.tl; - let x = param.hd; - if (p(x)) { - _param = l$1; - _yes = { - hd: x, - tl: yes - }; - continue; - } - _param = l$1; - _no = { - hd: x, - tl: no - }; - continue; - }; -} - -function split(param) { - if (!param) { - return [ - /* [] */0, - /* [] */0 - ]; - } - let match = param.hd; - let match$1 = split(param.tl); - return [ - { - hd: match[0], - tl: match$1[0] - }, - { - hd: match[1], - tl: match$1[1] - } - ]; -} - -function combine(l1, l2) { - if (l1) { - if (l2) { - return { - hd: [ - l1.hd, - l2.hd - ], - tl: combine(l1.tl, l2.tl) - }; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.combine", - Error: new Error() - }; - } - if (!l2) { - return /* [] */0; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.combine", - Error: new Error() - }; -} - -function merge(cmp, l1, l2) { - if (!l1) { - return l2; - } - if (!l2) { - return l1; - } - let h2 = l2.hd; - let h1 = l1.hd; - if (cmp(h1, h2) <= 0) { - return { - hd: h1, - tl: merge(cmp, l1.tl, l2) - }; - } else { - return { - hd: h2, - tl: merge(cmp, l1, l2.tl) - }; - } -} - -function chop(_k, _l) { - while (true) { - let l = _l; - let k = _k; - if (k === 0) { - return l; - } - if (l) { - _l = l.tl; - _k = k - 1 | 0; - continue; - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "listLabels.res", - 420, - 11 - ], - Error: new Error() - }; - }; -} - -function stable_sort(cmp, l) { - let sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l) { - let match = l.tl; - if (match) { - let match$1 = match.tl; - if (match$1) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - if (cmp(x1, x2) <= 0) { - if (cmp(x2, x3) <= 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x1, x3) <= 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } else if (cmp(x1, x3) <= 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x2, x3) <= 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l) { - let match$2 = l.tl; - if (match$2) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - if (cmp(x1$1, x2$1) <= 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = rev_sort(n1, l); - let s2 = rev_sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (!l1) { - return rev_append(l2$1, accu); - } - if (!l2$1) { - return rev_append(l1, accu); - } - let h2 = l2$1.hd; - let h1 = l1.hd; - if (cmp(h1, h2) > 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = l1.tl; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = l2$1.tl; - continue; - }; - }; - let rev_sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l) { - let match = l.tl; - if (match) { - let match$1 = match.tl; - if (match$1) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - if (cmp(x1, x2) > 0) { - if (cmp(x2, x3) > 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x1, x3) > 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } else if (cmp(x1, x3) > 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x2, x3) > 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l) { - let match$2 = l.tl; - if (match$2) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - if (cmp(x1$1, x2$1) > 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = sort(n1, l); - let s2 = sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (!l1) { - return rev_append(l2$1, accu); - } - if (!l2$1) { - return rev_append(l1, accu); - } - let h2 = l2$1.hd; - let h1 = l1.hd; - if (cmp(h1, h2) <= 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = l1.tl; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = l2$1.tl; - continue; - }; - }; - let len = length(l); - if (len < 2) { - return l; - } else { - return sort(len, l); - } -} - -function sort_uniq(cmp, l) { - let sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l) { - let match = l.tl; - if (match) { - let match$1 = match.tl; - if (match$1) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - let c = cmp(x1, x2); - if (c === 0) { - let c$1 = cmp(x2, x3); - if (c$1 === 0) { - return { - hd: x2, - tl: /* [] */0 - }; - } else if (c$1 < 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - } - if (c < 0) { - let c$2 = cmp(x2, x3); - if (c$2 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - if (c$2 < 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$3 = cmp(x1, x3); - if (c$3 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } else if (c$3 < 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } - let c$4 = cmp(x1, x3); - if (c$4 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } - if (c$4 < 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$5 = cmp(x2, x3); - if (c$5 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } else if (c$5 < 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l) { - let match$2 = l.tl; - if (match$2) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - let c$6 = cmp(x1$1, x2$1); - if (c$6 === 0) { - return { - hd: x1$1, - tl: /* [] */0 - }; - } else if (c$6 < 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = rev_sort(n1, l); - let s2 = rev_sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (!l1) { - return rev_append(l2$1, accu); - } - if (!l2$1) { - return rev_append(l1, accu); - } - let t2 = l2$1.tl; - let h2 = l2$1.hd; - let t1 = l1.tl; - let h1 = l1.hd; - let c$7 = cmp(h1, h2); - if (c$7 === 0) { - _accu = { - hd: h1, - tl: accu - }; - _l2 = t2; - _l1 = t1; - continue; - } - if (c$7 > 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = t1; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = t2; - continue; - }; - }; - let rev_sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l) { - let match = l.tl; - if (match) { - let match$1 = match.tl; - if (match$1) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - let c = cmp(x1, x2); - if (c === 0) { - let c$1 = cmp(x2, x3); - if (c$1 === 0) { - return { - hd: x2, - tl: /* [] */0 - }; - } else if (c$1 > 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - } - if (c > 0) { - let c$2 = cmp(x2, x3); - if (c$2 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - if (c$2 > 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$3 = cmp(x1, x3); - if (c$3 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } else if (c$3 > 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } - let c$4 = cmp(x1, x3); - if (c$4 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } - if (c$4 > 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$5 = cmp(x2, x3); - if (c$5 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } else if (c$5 > 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l) { - let match$2 = l.tl; - if (match$2) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - let c$6 = cmp(x1$1, x2$1); - if (c$6 === 0) { - return { - hd: x1$1, - tl: /* [] */0 - }; - } else if (c$6 > 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = sort(n1, l); - let s2 = sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (!l1) { - return rev_append(l2$1, accu); - } - if (!l2$1) { - return rev_append(l1, accu); - } - let t2 = l2$1.tl; - let h2 = l2$1.hd; - let t1 = l1.tl; - let h1 = l1.hd; - let c$7 = cmp(h1, h2); - if (c$7 === 0) { - _accu = { - hd: h1, - tl: accu - }; - _l2 = t2; - _l1 = t1; - continue; - } - if (c$7 < 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = t1; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = t2; - continue; - }; - }; - let len = length(l); - if (len < 2) { - return l; - } else { - return sort(len, l); - } -} - -function compare_lengths(_l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (!l1) { - if (l2) { - return -1; - } else { - return 0; - } - } - if (!l2) { - return 1; - } - _l2 = l2.tl; - _l1 = l1.tl; - continue; - }; -} - -function compare_length_with(_l, _n) { - while (true) { - let n = _n; - let l = _l; - if (!l) { - if (n === 0) { - return 0; - } else if (n > 0) { - return -1; - } else { - return 1; - } - } - if (n <= 0) { - return 1; - } - _n = n - 1 | 0; - _l = l.tl; - continue; - }; -} - -let append = Pervasives.$at; - -let concat = flatten; - -let filter = find_all; - -let sort = stable_sort; - -let fast_sort = stable_sort; - -export { - length, - hd, - compare_lengths, - compare_length_with, - cons, - tl, - nth, - nth_opt, - rev, - init, - append, - rev_append, - concat, - flatten, - iter, - iteri, - map, - mapi$1 as mapi, - rev_map, - fold_left, - fold_right, - iter2, - map2, - rev_map2, - fold_left2, - fold_right2, - for_all, - exists, - for_all2, - exists2, - mem, - memq, - find, - find_opt, - filter, - find_all, - partition, - assoc, - assoc_opt, - assq, - assq_opt, - mem_assoc, - mem_assq, - remove_assoc, - remove_assq, - split, - combine, - sort, - stable_sort, - fast_sort, - sort_uniq, - merge, -} -/* No side effect */ diff --git a/lib/es6/map.js b/lib/es6/map.js index 6829c40962..ae1b9f17e6 100644 --- a/lib/es6/map.js +++ b/lib/es6/map.js @@ -1,946 +1 @@ - - -import * as Caml_option from "./caml_option.js"; - -function Make(funarg) { - let height = param => { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } - }; - let create = (l, x, d, r) => { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - }; - let singleton = (x, d) => ({ - TAG: "Node", - l: "Empty", - v: x, - d: d, - r: "Empty", - h: 1 - }); - let bal = (l, x, d, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - }; - let is_empty = param => { - if (typeof param !== "object") { - return true; - } else { - return false; - } - }; - let add = (x, data, param) => { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let find = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let c = funarg.compare(x, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let find_first = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; - }; - let find_first_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; - }; - let find_last = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; - }; - let find_last_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; - }; - let find_opt = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let c = funarg.compare(x, param.v); - if (c === 0) { - return Caml_option.some(param.d); - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let mem = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = funarg.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let min_binding = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; - }; - let min_binding_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; - }; - let max_binding = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; - }; - let max_binding_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; - }; - let remove_min_binding = param => { - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.remove_min_elt", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_binding(l), param.v, param.d, param.r); - } - }; - let merge = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return bal(t1, match[0], match[1], remove_min_binding(t2)); - }; - let remove = (x, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - return merge(l, r); - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let update = (x, f, param) => { - if (typeof param !== "object") { - let data = f(undefined); - if (data !== undefined) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: Caml_option.valFromOption(data), - r: "Empty", - h: 1 - }; - } else { - return "Empty"; - } - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - let data$1 = f(Caml_option.some(d)); - if (data$1 === undefined) { - return merge(l, r); - } - let data$2 = Caml_option.valFromOption(data$1); - if (d === data$2) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data$2, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = update(x, f, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = update(x, f, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let iter = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v, param.d); - _param = param.r; - continue; - }; - }; - let map = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let l$p = map(f, param.l); - let d$p = f(param.d); - let r$p = map(f, param.r); - return { - TAG: "Node", - l: l$p, - v: param.v, - d: d$p, - r: r$p, - h: param.h - }; - }; - let mapi = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let v = param.v; - let l$p = mapi(f, param.l); - let d$p = f(v, param.d); - let r$p = mapi(f, param.r); - return { - TAG: "Node", - l: l$p, - v: v, - d: d$p, - r: r$p, - h: param.h - }; - }; - let fold = (f, _m, _accu) => { - while (true) { - let accu = _accu; - let m = _m; - if (typeof m !== "object") { - return accu; - } - _accu = f(m.v, m.d, fold(f, m.l, accu)); - _m = m.r; - continue; - }; - }; - let for_all = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v, param.d)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; - }; - let exists = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v, param.d)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; - }; - let add_min_binding = (k, x, param) => { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(add_min_binding(k, x, param.l), param.v, param.d, param.r); - } - }; - let add_max_binding = (k, x, param) => { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(param.l, param.v, param.d, add_max_binding(k, x, param.r)); - } - }; - let join = (l, v, d, r) => { - if (typeof l !== "object") { - return add_min_binding(v, d, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_binding(v, d, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, l.d, join(l.r, v, d, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, d, r.l), r.v, r.d, r.r); - } else { - return create(l, v, d, r); - } - }; - let concat = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return join(t1, match[0], match[1], remove_min_binding(t2)); - }; - let concat_or_join = (t1, v, d, t2) => { - if (d !== undefined) { - return join(t1, v, Caml_option.valFromOption(d), t2); - } else { - return concat(t1, t2); - } - }; - let split = (x, param) => { - if (typeof param !== "object") { - return [ - "Empty", - undefined, - "Empty" - ]; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - return [ - l, - Caml_option.some(d), - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, d, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, d, match$1[0]), - match$1[1], - match$1[2] - ]; - }; - let merge$1 = (f, s1, s2) => { - if (typeof s1 !== "object") { - if (typeof s2 !== "object") { - return "Empty"; - } - - } else { - let v1 = s1.v; - if (s1.h >= height(s2)) { - let match = split(v1, s2); - return concat_or_join(merge$1(f, s1.l, match[0]), v1, f(v1, Caml_option.some(s1.d), match[1]), merge$1(f, s1.r, match[2])); - } - - } - if (typeof s2 !== "object") { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "map.res", - 552, - 11 - ], - Error: new Error() - }; - } - let v2 = s2.v; - let match$1 = split(v2, s1); - return concat_or_join(merge$1(f, match$1[0], s2.l), v2, f(v2, match$1[1], Caml_option.some(s2.d)), merge$1(f, match$1[2], s2.r)); - }; - let union = (f, s1, s2) => { - if (typeof s1 !== "object") { - return s2; - } - let d1 = s1.d; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let d2 = s2.d; - let v2 = s2.v; - if (s1.h >= s2.h) { - let match = split(v1, s2); - let d2$1 = match[1]; - let l = union(f, s1.l, match[0]); - let r = union(f, s1.r, match[2]); - if (d2$1 !== undefined) { - return concat_or_join(l, v1, f(v1, d1, Caml_option.valFromOption(d2$1)), r); - } else { - return join(l, v1, d1, r); - } - } - let match$1 = split(v2, s1); - let d1$1 = match$1[1]; - let l$1 = union(f, match$1[0], s2.l); - let r$1 = union(f, match$1[2], s2.r); - if (d1$1 !== undefined) { - return concat_or_join(l$1, v2, f(v2, Caml_option.valFromOption(d1$1), d2), r$1); - } else { - return join(l$1, v2, d2, r$1); - } - }; - let filter = (p, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pvd = p(v, d); - let r$p = filter(p, r); - if (pvd) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, d, r$p); - } - } else { - return concat(l$p, r$p); - } - }; - let partition = (p, param) => { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let d = param.d; - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pvd = p(v, d); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pvd) { - return [ - join(lt, v, d, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, d, rf) - ]; - } - }; - let cons_enum = (_m, _e) => { - while (true) { - let e = _e; - let m = _m; - if (typeof m !== "object") { - return e; - } - _e = { - TAG: "More", - _0: m.v, - _1: m.d, - _2: m.r, - _3: e - }; - _m = m.l; - continue; - }; - }; - let compare = (cmp, m1, m2) => { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = funarg.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - let c$1 = cmp(e1._1, e2._1); - if (c$1 !== 0) { - return c$1; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; - }; - let equal = (cmp, m1, m2) => { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return true; - } else { - return false; - } - } - if (typeof e2 !== "object") { - return false; - } - if (funarg.compare(e1._0, e2._0) !== 0) { - return false; - } - if (!cmp(e1._1, e2._1)) { - return false; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; - }; - let cardinal = param => { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } - }; - let bindings_aux = (_accu, _param) => { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: [ - param.v, - param.d - ], - tl: bindings_aux(accu, param.r) - }; - continue; - }; - }; - let bindings = s => bindings_aux(/* [] */0, s); - return { - empty: "Empty", - is_empty: is_empty, - mem: mem, - add: add, - update: update, - singleton: singleton, - remove: remove, - merge: merge$1, - union: union, - compare: compare, - equal: equal, - iter: iter, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - bindings: bindings, - min_binding: min_binding, - min_binding_opt: min_binding_opt, - max_binding: max_binding, - max_binding_opt: max_binding_opt, - choose: min_binding, - choose_opt: min_binding_opt, - split: split, - find: find, - find_opt: find_opt, - find_first: find_first, - find_first_opt: find_first_opt, - find_last: find_last, - find_last_opt: find_last_opt, - map: map, - mapi: mapi - }; -} - -export { - Make, -} -/* No side effect */ +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/lib/es6/mapLabels.js b/lib/es6/mapLabels.js deleted file mode 100644 index 713328179b..0000000000 --- a/lib/es6/mapLabels.js +++ /dev/null @@ -1,961 +0,0 @@ - - -import * as Caml_option from "./caml_option.js"; - -function Make(Ord) { - let height = param => { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } - }; - let create = (l, x, d, r) => { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - }; - let singleton = (x, d) => ({ - TAG: "Node", - l: "Empty", - v: x, - d: d, - r: "Empty", - h: 1 - }); - let bal = (l, x, d, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - }; - let is_empty = param => { - if (typeof param !== "object") { - return true; - } else { - return false; - } - }; - let add = (x, data, param) => { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let find = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let c = Ord.compare(x, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let find_first_aux = (_v0, _d0, f, _param) => { - while (true) { - let param = _param; - let d0 = _d0; - let v0 = _v0; - if (typeof param !== "object") { - return [ - v0, - d0 - ]; - } - let v = param.v; - if (f(v)) { - _param = param.l; - _d0 = param.d; - _v0 = v; - continue; - } - _param = param.r; - continue; - }; - }; - let find_first = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - return find_first_aux(v, param.d, f, param.l); - } - _param = param.r; - continue; - }; - }; - let find_first_opt_aux = (_v0, _d0, f, _param) => { - while (true) { - let param = _param; - let d0 = _d0; - let v0 = _v0; - if (typeof param !== "object") { - return [ - v0, - d0 - ]; - } - let v = param.v; - if (f(v)) { - _param = param.l; - _d0 = param.d; - _v0 = v; - continue; - } - _param = param.r; - continue; - }; - }; - let find_first_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - return find_first_opt_aux(v, param.d, f, param.l); - } - _param = param.r; - continue; - }; - }; - let find_last_aux = (_v0, _d0, f, _param) => { - while (true) { - let param = _param; - let d0 = _d0; - let v0 = _v0; - if (typeof param !== "object") { - return [ - v0, - d0 - ]; - } - let v = param.v; - if (f(v)) { - _param = param.r; - _d0 = param.d; - _v0 = v; - continue; - } - _param = param.l; - continue; - }; - }; - let find_last = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - return find_last_aux(v, param.d, f, param.r); - } - _param = param.l; - continue; - }; - }; - let find_last_opt_aux = (_v0, _d0, f, _param) => { - while (true) { - let param = _param; - let d0 = _d0; - let v0 = _v0; - if (typeof param !== "object") { - return [ - v0, - d0 - ]; - } - let v = param.v; - if (f(v)) { - _param = param.r; - _d0 = param.d; - _v0 = v; - continue; - } - _param = param.l; - continue; - }; - }; - let find_last_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - return find_last_opt_aux(v, param.d, f, param.r); - } - _param = param.l; - continue; - }; - }; - let find_opt = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let c = Ord.compare(x, param.v); - if (c === 0) { - return Caml_option.some(param.d); - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let mem = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = Ord.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let min_binding = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; - }; - let min_binding_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; - }; - let max_binding = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; - }; - let max_binding_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; - }; - let remove_min_binding = param => { - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.remove_min_elt", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_binding(l), param.v, param.d, param.r); - } - }; - let merge = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return bal(t1, match[0], match[1], remove_min_binding(t2)); - }; - let remove = (x, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - return merge(l, r); - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let update = (x, f, param) => { - if (typeof param !== "object") { - let data = f(undefined); - if (data !== undefined) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: Caml_option.valFromOption(data), - r: "Empty", - h: 1 - }; - } else { - return "Empty"; - } - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - let data$1 = f(Caml_option.some(d)); - if (data$1 === undefined) { - return merge(l, r); - } - let data$2 = Caml_option.valFromOption(data$1); - if (d === data$2) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data$2, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = update(x, f, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = update(x, f, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let iter = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v, param.d); - _param = param.r; - continue; - }; - }; - let map = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let l$p = map(f, param.l); - let d$p = f(param.d); - let r$p = map(f, param.r); - return { - TAG: "Node", - l: l$p, - v: param.v, - d: d$p, - r: r$p, - h: param.h - }; - }; - let mapi = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let v = param.v; - let l$p = mapi(f, param.l); - let d$p = f(v, param.d); - let r$p = mapi(f, param.r); - return { - TAG: "Node", - l: l$p, - v: v, - d: d$p, - r: r$p, - h: param.h - }; - }; - let fold = (f, _m, _accu) => { - while (true) { - let accu = _accu; - let m = _m; - if (typeof m !== "object") { - return accu; - } - _accu = f(m.v, m.d, fold(f, m.l, accu)); - _m = m.r; - continue; - }; - }; - let for_all = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v, param.d)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; - }; - let exists = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v, param.d)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; - }; - let add_min_binding = (k, x, param) => { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(add_min_binding(k, x, param.l), param.v, param.d, param.r); - } - }; - let add_max_binding = (k, x, param) => { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(param.l, param.v, param.d, add_max_binding(k, x, param.r)); - } - }; - let join = (l, v, d, r) => { - if (typeof l !== "object") { - return add_min_binding(v, d, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_binding(v, d, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, l.d, join(l.r, v, d, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, d, r.l), r.v, r.d, r.r); - } else { - return create(l, v, d, r); - } - }; - let concat = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return join(t1, match[0], match[1], remove_min_binding(t2)); - }; - let concat_or_join = (t1, v, d, t2) => { - if (d !== undefined) { - return join(t1, v, Caml_option.valFromOption(d), t2); - } else { - return concat(t1, t2); - } - }; - let split = (x, param) => { - if (typeof param !== "object") { - return [ - "Empty", - undefined, - "Empty" - ]; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - return [ - l, - Caml_option.some(d), - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, d, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, d, match$1[0]), - match$1[1], - match$1[2] - ]; - }; - let merge$1 = (f, s1, s2) => { - if (typeof s1 !== "object") { - if (typeof s2 !== "object") { - return "Empty"; - } - - } else { - let v1 = s1.v; - if (s1.h >= height(s2)) { - let match = split(v1, s2); - return concat_or_join(merge$1(f, s1.l, match[0]), v1, f(v1, Caml_option.some(s1.d), match[1]), merge$1(f, s1.r, match[2])); - } - - } - if (typeof s2 !== "object") { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "mapLabels.res", - 552, - 11 - ], - Error: new Error() - }; - } - let v2 = s2.v; - let match$1 = split(v2, s1); - return concat_or_join(merge$1(f, match$1[0], s2.l), v2, f(v2, match$1[1], Caml_option.some(s2.d)), merge$1(f, match$1[2], s2.r)); - }; - let union = (f, s1, s2) => { - if (typeof s1 !== "object") { - return s2; - } - let d1 = s1.d; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let d2 = s2.d; - let v2 = s2.v; - if (s1.h >= s2.h) { - let match = split(v1, s2); - let d2$1 = match[1]; - let l = union(f, s1.l, match[0]); - let r = union(f, s1.r, match[2]); - if (d2$1 !== undefined) { - return concat_or_join(l, v1, f(v1, d1, Caml_option.valFromOption(d2$1)), r); - } else { - return join(l, v1, d1, r); - } - } - let match$1 = split(v2, s1); - let d1$1 = match$1[1]; - let l$1 = union(f, match$1[0], s2.l); - let r$1 = union(f, match$1[2], s2.r); - if (d1$1 !== undefined) { - return concat_or_join(l$1, v2, f(v2, Caml_option.valFromOption(d1$1), d2), r$1); - } else { - return join(l$1, v2, d2, r$1); - } - }; - let filter = (p, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pvd = p(v, d); - let r$p = filter(p, r); - if (pvd) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, d, r$p); - } - } else { - return concat(l$p, r$p); - } - }; - let partition = (p, param) => { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let d = param.d; - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pvd = p(v, d); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pvd) { - return [ - join(lt, v, d, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, d, rf) - ]; - } - }; - let cons_enum = (_m, _e) => { - while (true) { - let e = _e; - let m = _m; - if (typeof m !== "object") { - return e; - } - _e = { - TAG: "More", - _0: m.v, - _1: m.d, - _2: m.r, - _3: e - }; - _m = m.l; - continue; - }; - }; - let compare = (cmp, m1, m2) => { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = Ord.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - let c$1 = cmp(e1._1, e2._1); - if (c$1 !== 0) { - return c$1; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; - }; - let equal = (cmp, m1, m2) => { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return true; - } else { - return false; - } - } - if (typeof e2 !== "object") { - return false; - } - if (Ord.compare(e1._0, e2._0) !== 0) { - return false; - } - if (!cmp(e1._1, e2._1)) { - return false; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; - }; - let cardinal = param => { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } - }; - let bindings_aux = (_accu, _param) => { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: [ - param.v, - param.d - ], - tl: bindings_aux(accu, param.r) - }; - continue; - }; - }; - let bindings = s => bindings_aux(/* [] */0, s); - return { - height: height, - create: create, - singleton: singleton, - bal: bal, - empty: "Empty", - is_empty: is_empty, - add: add, - find: find, - find_first_aux: find_first_aux, - find_first: find_first, - find_first_opt_aux: find_first_opt_aux, - find_first_opt: find_first_opt, - find_last_aux: find_last_aux, - find_last: find_last, - find_last_opt_aux: find_last_opt_aux, - find_last_opt: find_last_opt, - find_opt: find_opt, - mem: mem, - min_binding: min_binding, - min_binding_opt: min_binding_opt, - max_binding: max_binding, - max_binding_opt: max_binding_opt, - remove_min_binding: remove_min_binding, - remove: remove, - update: update, - iter: iter, - map: map, - mapi: mapi, - fold: fold, - for_all: for_all, - exists: exists, - add_min_binding: add_min_binding, - add_max_binding: add_max_binding, - join: join, - concat: concat, - concat_or_join: concat_or_join, - split: split, - merge: merge$1, - union: union, - filter: filter, - partition: partition, - cons_enum: cons_enum, - compare: compare, - equal: equal, - cardinal: cardinal, - bindings_aux: bindings_aux, - bindings: bindings, - choose: min_binding, - choose_opt: min_binding_opt - }; -} - -export { - Make, -} -/* No side effect */ diff --git a/lib/es6/moreLabels.js b/lib/es6/moreLabels.js deleted file mode 100644 index e42e900b6e..0000000000 --- a/lib/es6/moreLabels.js +++ /dev/null @@ -1,1944 +0,0 @@ - - -import * as List from "./list.js"; -import * as Caml_option from "./caml_option.js"; -import * as HashtblLabels from "./hashtblLabels.js"; - -let Hashtbl = { - create: HashtblLabels.create, - clear: HashtblLabels.clear, - reset: HashtblLabels.reset, - copy: HashtblLabels.copy, - add: HashtblLabels.add, - find: HashtblLabels.find, - find_opt: HashtblLabels.find_opt, - find_all: HashtblLabels.find_all, - mem: HashtblLabels.mem, - remove: HashtblLabels.remove, - replace: HashtblLabels.replace, - iter: HashtblLabels.iter, - filter_map_inplace: HashtblLabels.filter_map_inplace, - fold: HashtblLabels.fold, - length: HashtblLabels.length, - randomize: HashtblLabels.randomize, - is_randomized: HashtblLabels.is_randomized, - stats: HashtblLabels.stats, - Make: HashtblLabels.Make, - MakeSeeded: HashtblLabels.MakeSeeded, - hash: HashtblLabels.hash, - seeded_hash: HashtblLabels.seeded_hash, - hash_param: HashtblLabels.hash_param, - seeded_hash_param: HashtblLabels.seeded_hash_param -}; - -let $$Map = { - Make: funarg => { - let height = param => { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } - }; - let create = (l, x, d, r) => { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - }; - let singleton = (x, d) => ({ - TAG: "Node", - l: "Empty", - v: x, - d: d, - r: "Empty", - h: 1 - }); - let bal = (l, x, d, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - }; - let is_empty = param => { - if (typeof param !== "object") { - return true; - } else { - return false; - } - }; - let add = (x, data, param) => { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let find = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let c = funarg.compare(x, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let find_first_aux = (_v0, _d0, f, _param) => { - while (true) { - let param = _param; - let d0 = _d0; - let v0 = _v0; - if (typeof param !== "object") { - return [ - v0, - d0 - ]; - } - let v = param.v; - if (f(v)) { - _param = param.l; - _d0 = param.d; - _v0 = v; - continue; - } - _param = param.r; - continue; - }; - }; - let find_first = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - return find_first_aux(v, param.d, f, param.l); - } - _param = param.r; - continue; - }; - }; - let find_first_opt_aux = (_v0, _d0, f, _param) => { - while (true) { - let param = _param; - let d0 = _d0; - let v0 = _v0; - if (typeof param !== "object") { - return [ - v0, - d0 - ]; - } - let v = param.v; - if (f(v)) { - _param = param.l; - _d0 = param.d; - _v0 = v; - continue; - } - _param = param.r; - continue; - }; - }; - let find_first_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - return find_first_opt_aux(v, param.d, f, param.l); - } - _param = param.r; - continue; - }; - }; - let find_last_aux = (_v0, _d0, f, _param) => { - while (true) { - let param = _param; - let d0 = _d0; - let v0 = _v0; - if (typeof param !== "object") { - return [ - v0, - d0 - ]; - } - let v = param.v; - if (f(v)) { - _param = param.r; - _d0 = param.d; - _v0 = v; - continue; - } - _param = param.l; - continue; - }; - }; - let find_last = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - return find_last_aux(v, param.d, f, param.r); - } - _param = param.l; - continue; - }; - }; - let find_last_opt_aux = (_v0, _d0, f, _param) => { - while (true) { - let param = _param; - let d0 = _d0; - let v0 = _v0; - if (typeof param !== "object") { - return [ - v0, - d0 - ]; - } - let v = param.v; - if (f(v)) { - _param = param.r; - _d0 = param.d; - _v0 = v; - continue; - } - _param = param.l; - continue; - }; - }; - let find_last_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - return find_last_opt_aux(v, param.d, f, param.r); - } - _param = param.l; - continue; - }; - }; - let find_opt = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let c = funarg.compare(x, param.v); - if (c === 0) { - return Caml_option.some(param.d); - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let mem = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = funarg.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let min_binding = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; - }; - let min_binding_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; - }; - let max_binding = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; - }; - let max_binding_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; - }; - let remove_min_binding = param => { - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.remove_min_elt", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_binding(l), param.v, param.d, param.r); - } - }; - let merge = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return bal(t1, match[0], match[1], remove_min_binding(t2)); - }; - let remove = (x, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - return merge(l, r); - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let update = (x, f, param) => { - if (typeof param !== "object") { - let data = f(undefined); - if (data !== undefined) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: Caml_option.valFromOption(data), - r: "Empty", - h: 1 - }; - } else { - return "Empty"; - } - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - let data$1 = f(Caml_option.some(d)); - if (data$1 === undefined) { - return merge(l, r); - } - let data$2 = Caml_option.valFromOption(data$1); - if (d === data$2) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data$2, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = update(x, f, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = update(x, f, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let iter = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v, param.d); - _param = param.r; - continue; - }; - }; - let map = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let l$p = map(f, param.l); - let d$p = f(param.d); - let r$p = map(f, param.r); - return { - TAG: "Node", - l: l$p, - v: param.v, - d: d$p, - r: r$p, - h: param.h - }; - }; - let mapi = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let v = param.v; - let l$p = mapi(f, param.l); - let d$p = f(v, param.d); - let r$p = mapi(f, param.r); - return { - TAG: "Node", - l: l$p, - v: v, - d: d$p, - r: r$p, - h: param.h - }; - }; - let fold = (f, _m, _accu) => { - while (true) { - let accu = _accu; - let m = _m; - if (typeof m !== "object") { - return accu; - } - _accu = f(m.v, m.d, fold(f, m.l, accu)); - _m = m.r; - continue; - }; - }; - let for_all = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v, param.d)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; - }; - let exists = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v, param.d)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; - }; - let add_min_binding = (k, x, param) => { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(add_min_binding(k, x, param.l), param.v, param.d, param.r); - } - }; - let add_max_binding = (k, x, param) => { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(param.l, param.v, param.d, add_max_binding(k, x, param.r)); - } - }; - let join = (l, v, d, r) => { - if (typeof l !== "object") { - return add_min_binding(v, d, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_binding(v, d, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, l.d, join(l.r, v, d, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, d, r.l), r.v, r.d, r.r); - } else { - return create(l, v, d, r); - } - }; - let concat = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return join(t1, match[0], match[1], remove_min_binding(t2)); - }; - let concat_or_join = (t1, v, d, t2) => { - if (d !== undefined) { - return join(t1, v, Caml_option.valFromOption(d), t2); - } else { - return concat(t1, t2); - } - }; - let split = (x, param) => { - if (typeof param !== "object") { - return [ - "Empty", - undefined, - "Empty" - ]; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - return [ - l, - Caml_option.some(d), - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, d, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, d, match$1[0]), - match$1[1], - match$1[2] - ]; - }; - let merge$1 = (f, s1, s2) => { - if (typeof s1 !== "object") { - if (typeof s2 !== "object") { - return "Empty"; - } - - } else { - let v1 = s1.v; - if (s1.h >= height(s2)) { - let match = split(v1, s2); - return concat_or_join(merge$1(f, s1.l, match[0]), v1, f(v1, Caml_option.some(s1.d), match[1]), merge$1(f, s1.r, match[2])); - } - - } - if (typeof s2 !== "object") { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "mapLabels.res", - 552, - 11 - ], - Error: new Error() - }; - } - let v2 = s2.v; - let match$1 = split(v2, s1); - return concat_or_join(merge$1(f, match$1[0], s2.l), v2, f(v2, match$1[1], Caml_option.some(s2.d)), merge$1(f, match$1[2], s2.r)); - }; - let union = (f, s1, s2) => { - if (typeof s1 !== "object") { - return s2; - } - let d1 = s1.d; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let d2 = s2.d; - let v2 = s2.v; - if (s1.h >= s2.h) { - let match = split(v1, s2); - let d2$1 = match[1]; - let l = union(f, s1.l, match[0]); - let r = union(f, s1.r, match[2]); - if (d2$1 !== undefined) { - return concat_or_join(l, v1, f(v1, d1, Caml_option.valFromOption(d2$1)), r); - } else { - return join(l, v1, d1, r); - } - } - let match$1 = split(v2, s1); - let d1$1 = match$1[1]; - let l$1 = union(f, match$1[0], s2.l); - let r$1 = union(f, match$1[2], s2.r); - if (d1$1 !== undefined) { - return concat_or_join(l$1, v2, f(v2, Caml_option.valFromOption(d1$1), d2), r$1); - } else { - return join(l$1, v2, d2, r$1); - } - }; - let filter = (p, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pvd = p(v, d); - let r$p = filter(p, r); - if (pvd) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, d, r$p); - } - } else { - return concat(l$p, r$p); - } - }; - let partition = (p, param) => { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let d = param.d; - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pvd = p(v, d); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pvd) { - return [ - join(lt, v, d, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, d, rf) - ]; - } - }; - let cons_enum = (_m, _e) => { - while (true) { - let e = _e; - let m = _m; - if (typeof m !== "object") { - return e; - } - _e = { - TAG: "More", - _0: m.v, - _1: m.d, - _2: m.r, - _3: e - }; - _m = m.l; - continue; - }; - }; - let compare = (cmp, m1, m2) => { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = funarg.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - let c$1 = cmp(e1._1, e2._1); - if (c$1 !== 0) { - return c$1; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; - }; - let equal = (cmp, m1, m2) => { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return true; - } else { - return false; - } - } - if (typeof e2 !== "object") { - return false; - } - if (funarg.compare(e1._0, e2._0) !== 0) { - return false; - } - if (!cmp(e1._1, e2._1)) { - return false; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; - }; - let cardinal = param => { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } - }; - let bindings_aux = (_accu, _param) => { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: [ - param.v, - param.d - ], - tl: bindings_aux(accu, param.r) - }; - continue; - }; - }; - let bindings = s => bindings_aux(/* [] */0, s); - return { - empty: "Empty", - is_empty: is_empty, - mem: mem, - add: add, - update: update, - singleton: singleton, - remove: remove, - merge: merge$1, - union: union, - compare: compare, - equal: equal, - iter: iter, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - bindings: bindings, - min_binding: min_binding, - min_binding_opt: min_binding_opt, - max_binding: max_binding, - max_binding_opt: max_binding_opt, - choose: min_binding, - choose_opt: min_binding_opt, - split: split, - find: find, - find_opt: find_opt, - find_first: find_first, - find_first_opt: find_first_opt, - find_last: find_last, - find_last_opt: find_last_opt, - map: map, - mapi: mapi - }; - } -}; - -let $$Set = { - Make: funarg => { - let height = param => { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } - }; - let create = (l, v, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - }; - let bal = (l, v, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - let lr = l.r; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, create(lr, v, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, lr.l), lr.v, create(lr.r, v, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - let rr = r.r; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, v, rl), rv, rr); - } - if (typeof rl === "object") { - return create(create(l, v, rl.l), rl.v, create(rl.r, rv, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - }; - let add = (x, param) => { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - return param; - } - if (c < 0) { - let ll = add(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = add(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } - }; - let singleton = x => ({ - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }); - let add_min_element = (x, param) => { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(add_min_element(x, param.l), param.v, param.r); - } - }; - let add_max_element = (x, param) => { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(param.l, param.v, add_max_element(x, param.r)); - } - }; - let join = (l, v, r) => { - if (typeof l !== "object") { - return add_min_element(v, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_element(v, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, join(l.r, v, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, r.l), r.v, r.r); - } else { - return create(l, v, r); - } - }; - let min_elt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.v; - } - _param = l; - continue; - }; - }; - let min_elt_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return Caml_option.some(param.v); - } - _param = l; - continue; - }; - }; - let max_elt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let r = param.r; - if (typeof r !== "object") { - return param.v; - } - _param = r; - continue; - }; - }; - let max_elt_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return Caml_option.some(param.v); - } - _param = r; - continue; - }; - }; - let remove_min_elt = param => { - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.remove_min_elt", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_elt(l), param.v, param.r); - } - }; - let merge = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } else if (typeof t2 !== "object") { - return t1; - } else { - return bal(t1, min_elt(t2), remove_min_elt(t2)); - } - }; - let concat = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } else if (typeof t2 !== "object") { - return t1; - } else { - return join(t1, min_elt(t2), remove_min_elt(t2)); - } - }; - let split = (x, param) => { - if (typeof param !== "object") { - return [ - "Empty", - false, - "Empty" - ]; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - return [ - l, - true, - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, match$1[0]), - match$1[1], - match$1[2] - ]; - }; - let is_empty = param => { - if (typeof param !== "object") { - return true; - } else { - return false; - } - }; - let mem = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = funarg.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let remove = (x, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - return merge(l, r); - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } - }; - let union = (s1, s2) => { - if (typeof s1 !== "object") { - return s2; - } - let h1 = s1.h; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let h2 = s2.h; - let v2 = s2.v; - if (h1 >= h2) { - if (h2 === 1) { - return add(v2, s1); - } - let match = split(v1, s2); - return join(union(s1.l, match[0]), v1, union(s1.r, match[2])); - } - if (h1 === 1) { - return add(v1, s2); - } - let match$1 = split(v2, s1); - return join(union(match$1[0], s2.l), v2, union(match$1[2], s2.r)); - }; - let inter = (s1, s2) => { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return "Empty"; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return join(inter(l1, l2), v1, inter(r1, match[2])); - } else { - return concat(inter(l1, l2), inter(r1, match[2])); - } - }; - let diff = (s1, s2) => { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return s1; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return concat(diff(l1, l2), diff(r1, match[2])); - } else { - return join(diff(l1, l2), v1, diff(r1, match[2])); - } - }; - let cons_enum = (_s, _e) => { - while (true) { - let e = _e; - let s = _s; - if (typeof s !== "object") { - return e; - } - _e = { - TAG: "More", - _0: s.v, - _1: s.r, - _2: e - }; - _s = s.l; - continue; - }; - }; - let compare_aux = (_e1, _e2) => { - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = funarg.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - _e2 = cons_enum(e2._1, e2._2); - _e1 = cons_enum(e1._1, e1._2); - continue; - }; - }; - let compare = (s1, s2) => compare_aux(cons_enum(s1, "End"), cons_enum(s2, "End")); - let equal = (s1, s2) => compare(s1, s2) === 0; - let subset = (_s1, _s2) => { - while (true) { - let s2 = _s2; - let s1 = _s1; - if (typeof s1 !== "object") { - return true; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - if (typeof s2 !== "object") { - return false; - } - let r2 = s2.r; - let l2 = s2.l; - let c = funarg.compare(v1, s2.v); - if (c === 0) { - if (!subset(l1, l2)) { - return false; - } - _s2 = r2; - _s1 = r1; - continue; - } - if (c < 0) { - if (!subset({ - TAG: "Node", - l: l1, - v: v1, - r: "Empty", - h: 0 - }, l2)) { - return false; - } - _s1 = r1; - continue; - } - if (!subset({ - TAG: "Node", - l: "Empty", - v: v1, - r: r1, - h: 0 - }, r2)) { - return false; - } - _s1 = l1; - continue; - }; - }; - let iter = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v); - _param = param.r; - continue; - }; - }; - let fold = (f, _s, _accu) => { - while (true) { - let accu = _accu; - let s = _s; - if (typeof s !== "object") { - return accu; - } - _accu = f(s.v, fold(f, s.l, accu)); - _s = s.r; - continue; - }; - }; - let for_all = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; - }; - let exists = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; - }; - let filter = (p, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pv = p(v); - let r$p = filter(p, r); - if (pv) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, r$p); - } - } else { - return concat(l$p, r$p); - } - }; - let partition = (p, param) => { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pv = p(v); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pv) { - return [ - join(lt, v, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, rf) - ]; - } - }; - let cardinal = param => { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } - }; - let elements_aux = (_accu, _param) => { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: param.v, - tl: elements_aux(accu, param.r) - }; - continue; - }; - }; - let elements = s => elements_aux(/* [] */0, s); - let find = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - let c = funarg.compare(x, v); - if (c === 0) { - return v; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let find_first_aux = (_v0, f, _param) => { - while (true) { - let param = _param; - let v0 = _v0; - if (typeof param !== "object") { - return v0; - } - let v = param.v; - if (f(v)) { - _param = param.l; - _v0 = v; - continue; - } - _param = param.r; - continue; - }; - }; - let find_first = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - return find_first_aux(v, f, param.l); - } - _param = param.r; - continue; - }; - }; - let find_first_opt_aux = (_v0, f, _param) => { - while (true) { - let param = _param; - let v0 = _v0; - if (typeof param !== "object") { - return Caml_option.some(v0); - } - let v = param.v; - if (f(v)) { - _param = param.l; - _v0 = v; - continue; - } - _param = param.r; - continue; - }; - }; - let find_first_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - return find_first_opt_aux(v, f, param.l); - } - _param = param.r; - continue; - }; - }; - let find_last_aux = (_v0, f, _param) => { - while (true) { - let param = _param; - let v0 = _v0; - if (typeof param !== "object") { - return v0; - } - let v = param.v; - if (f(v)) { - _param = param.r; - _v0 = v; - continue; - } - _param = param.l; - continue; - }; - }; - let find_last = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - return find_last_aux(v, f, param.r); - } - _param = param.l; - continue; - }; - }; - let find_last_opt_aux = (_v0, f, _param) => { - while (true) { - let param = _param; - let v0 = _v0; - if (typeof param !== "object") { - return Caml_option.some(v0); - } - let v = param.v; - if (f(v)) { - _param = param.r; - _v0 = v; - continue; - } - _param = param.l; - continue; - }; - }; - let find_last_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - return find_last_opt_aux(v, f, param.r); - } - _param = param.l; - continue; - }; - }; - let find_opt = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - let c = funarg.compare(x, v); - if (c === 0) { - return Caml_option.some(v); - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let try_join = (l, v, r) => { - if ((l === "Empty" || funarg.compare(max_elt(l), v) < 0) && (r === "Empty" || funarg.compare(v, min_elt(r)) < 0)) { - return join(l, v, r); - } else { - return union(l, add(v, r)); - } - }; - let map = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = map(f, l); - let v$p = f(v); - let r$p = map(f, r); - if (l === l$p && v === v$p && r === r$p) { - return param; - } else { - return try_join(l$p, v$p, r$p); - } - }; - let of_sorted_list = l => { - let sub = (n, l) => { - switch (n) { - case 0 : - return [ - "Empty", - l - ]; - case 1 : - if (l) { - return [ - { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - l.tl - ]; - } - break; - case 2 : - if (l) { - let match = l.tl; - if (match) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match.hd, - r: "Empty", - h: 2 - }, - match.tl - ]; - } - - } - break; - case 3 : - if (l) { - let match$1 = l.tl; - if (match$1) { - let match$2 = match$1.tl; - if (match$2) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match$1.hd, - r: { - TAG: "Node", - l: "Empty", - v: match$2.hd, - r: "Empty", - h: 1 - }, - h: 2 - }, - match$2.tl - ]; - } - - } - - } - break; - } - let nl = n / 2 | 0; - let match$3 = sub(nl, l); - let l$1 = match$3[1]; - if (l$1) { - let match$4 = sub((n - nl | 0) - 1 | 0, l$1.tl); - return [ - create(match$3[0], l$1.hd, match$4[0]), - match$4[1] - ]; - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "setLabels.res", - 691, - 20 - ], - Error: new Error() - }; - }; - return sub(List.length(l), l)[0]; - }; - let of_list = l => { - if (!l) { - return "Empty"; - } - let match = l.tl; - let x0 = l.hd; - if (!match) { - return singleton(x0); - } - let match$1 = match.tl; - let x1 = match.hd; - if (!match$1) { - return add(x1, singleton(x0)); - } - let match$2 = match$1.tl; - let x2 = match$1.hd; - if (!match$2) { - return add(x2, add(x1, singleton(x0))); - } - let match$3 = match$2.tl; - let x3 = match$2.hd; - if (match$3) { - if (match$3.tl) { - return of_sorted_list(List.sort_uniq(funarg.compare, l)); - } else { - return add(match$3.hd, add(x3, add(x2, add(x1, singleton(x0))))); - } - } else { - return add(x3, add(x2, add(x1, singleton(x0)))); - } - }; - return { - empty: "Empty", - is_empty: is_empty, - mem: mem, - add: add, - singleton: singleton, - remove: remove, - union: union, - inter: inter, - diff: diff, - compare: compare, - equal: equal, - subset: subset, - iter: iter, - map: map, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - elements: elements, - min_elt: min_elt, - min_elt_opt: min_elt_opt, - max_elt: max_elt, - max_elt_opt: max_elt_opt, - choose: min_elt, - choose_opt: min_elt_opt, - split: split, - find: find, - find_opt: find_opt, - find_first: find_first, - find_first_opt: find_first_opt, - find_last: find_last, - find_last_opt: find_last_opt, - of_list: of_list - }; - } -}; - -export { - Hashtbl, - $$Map, - $$Set, -} -/* No side effect */ diff --git a/lib/es6/obj.js b/lib/es6/obj.js index 3377aadc04..c436633a10 100644 --- a/lib/es6/obj.js +++ b/lib/es6/obj.js @@ -1,11 +1,51 @@ -function is_block(a) { - return typeof a !== "number"; +function magic(prim) { + return prim; +} + +function repr(prim) { + return prim; +} + +function obj(prim) { + return prim; +} + +function tag(prim) { + return prim.TAG; +} + +function size(prim) { + return prim.length | 0; +} + +function field(prim0, prim1) { + return prim0[prim1]; +} + +function set_field(prim0, prim1, prim2) { + prim0[prim1] = prim2; +} + +function dup(prim) { + return {...prim}; +} + +function update_dummy(prim0, prim1) { + Object.assign(prim0, prim1); } export { - is_block, + magic, + repr, + obj, + tag, + size, + field, + set_field, + dup, + update_dummy, } /* No side effect */ diff --git a/lib/es6/parsing.js b/lib/es6/parsing.js deleted file mode 100644 index e882967d42..0000000000 --- a/lib/es6/parsing.js +++ /dev/null @@ -1,231 +0,0 @@ - - -import * as $$Array from "./array.js"; -import * as Lexing from "./lexing.js"; -import * as Caml_obj from "./caml_obj.js"; -import * as Caml_array from "./caml_array.js"; -import * as Caml_parser from "./caml_parser.js"; -import * as Caml_exceptions from "./caml_exceptions.js"; -import * as Caml_js_exceptions from "./caml_js_exceptions.js"; - -let YYexit = /* @__PURE__ */Caml_exceptions.create("Parsing.YYexit"); - -let Parse_error = /* @__PURE__ */Caml_exceptions.create("Parsing.Parse_error"); - -let env = { - s_stack: Caml_array.make(100, 0), - v_stack: Caml_array.make(100, undefined), - symb_start_stack: Caml_array.make(100, Lexing.dummy_pos), - symb_end_stack: Caml_array.make(100, Lexing.dummy_pos), - stacksize: 100, - stackbase: 0, - curr_char: 0, - lval: undefined, - symb_start: Lexing.dummy_pos, - symb_end: Lexing.dummy_pos, - asp: 0, - rule_len: 0, - rule_number: 0, - sp: 0, - state: 0, - errflag: 0 -}; - -function grow_stacks() { - let oldsize = env.stacksize; - let newsize = (oldsize << 1); - let new_s = Caml_array.make(newsize, 0); - let new_v = Caml_array.make(newsize, undefined); - let new_start = Caml_array.make(newsize, Lexing.dummy_pos); - let new_end = Caml_array.make(newsize, Lexing.dummy_pos); - $$Array.blit(env.s_stack, 0, new_s, 0, oldsize); - env.s_stack = new_s; - $$Array.blit(env.v_stack, 0, new_v, 0, oldsize); - env.v_stack = new_v; - $$Array.blit(env.symb_start_stack, 0, new_start, 0, oldsize); - env.symb_start_stack = new_start; - $$Array.blit(env.symb_end_stack, 0, new_end, 0, oldsize); - env.symb_end_stack = new_end; - env.stacksize = newsize; -} - -function clear_parser() { - $$Array.fill(env.v_stack, 0, env.stacksize, undefined); - env.lval = undefined; -} - -let current_lookahead_fun = { - contents: param => false -}; - -function yyparse(tables, start, lexer, lexbuf) { - let init_asp = env.asp; - let init_sp = env.sp; - let init_stackbase = env.stackbase; - let init_state = env.state; - let init_curr_char = env.curr_char; - let init_lval = env.lval; - let init_errflag = env.errflag; - env.stackbase = env.sp + 1 | 0; - env.curr_char = start; - env.symb_end = lexbuf.lex_curr_p; - try { - let _cmd = "Start"; - let _arg; - while (true) { - let arg = _arg; - let cmd = _cmd; - let match = Caml_parser.parse_engine(tables, env, cmd, arg); - switch (match) { - case "Read_token" : - let t = lexer(lexbuf); - env.symb_start = lexbuf.lex_start_p; - env.symb_end = lexbuf.lex_curr_p; - _arg = t; - _cmd = "Token_read"; - continue; - case "Raise_parse_error" : - throw { - RE_EXN_ID: Parse_error, - Error: new Error() - }; - case "Grow_stacks_1" : - grow_stacks(); - _arg = undefined; - _cmd = "Stacks_grown_1"; - continue; - case "Grow_stacks_2" : - grow_stacks(); - _arg = undefined; - _cmd = "Stacks_grown_2"; - continue; - case "Compute_semantic_action" : - let match$1; - try { - match$1 = [ - "Semantic_action_computed", - Caml_array.get(tables.actions, env.rule_number)(env) - ]; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === Parse_error) { - match$1 = [ - "Error_detected", - undefined - ]; - } else { - throw exn; - } - } - _arg = match$1[1]; - _cmd = match$1[0]; - continue; - case "Call_error_function" : - tables.error_function("syntax error"); - _arg = undefined; - _cmd = "Error_detected"; - continue; - } - }; - } catch (raw_exn$1) { - let exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn$1); - let curr_char = env.curr_char; - env.asp = init_asp; - env.sp = init_sp; - env.stackbase = init_stackbase; - env.state = init_state; - env.curr_char = init_curr_char; - env.lval = init_lval; - env.errflag = init_errflag; - if (exn$1.RE_EXN_ID === YYexit) { - return exn$1._1; - } - current_lookahead_fun.contents = tok => { - if (typeof tok !== "number") { - return Caml_array.get(tables.transl_block, tok.TAG) === curr_char; - } else { - return Caml_array.get(tables.transl_const, tok) === curr_char; - } - }; - throw exn$1; - } -} - -function peek_val(env, n) { - return Caml_array.get(env.v_stack, env.asp - n | 0); -} - -function symbol_start_pos() { - let _i = env.rule_len; - while (true) { - let i = _i; - if (i <= 0) { - return Caml_array.get(env.symb_end_stack, env.asp); - } - let st = Caml_array.get(env.symb_start_stack, (env.asp - i | 0) + 1 | 0); - let en = Caml_array.get(env.symb_end_stack, (env.asp - i | 0) + 1 | 0); - if (Caml_obj.notequal(st, en)) { - return st; - } - _i = i - 1 | 0; - continue; - }; -} - -function symbol_end_pos() { - return Caml_array.get(env.symb_end_stack, env.asp); -} - -function rhs_start_pos(n) { - return Caml_array.get(env.symb_start_stack, env.asp - (env.rule_len - n | 0) | 0); -} - -function rhs_end_pos(n) { - return Caml_array.get(env.symb_end_stack, env.asp - (env.rule_len - n | 0) | 0); -} - -function symbol_start() { - return symbol_start_pos().pos_cnum; -} - -function symbol_end() { - return symbol_end_pos().pos_cnum; -} - -function rhs_start(n) { - return rhs_start_pos(n).pos_cnum; -} - -function rhs_end(n) { - return rhs_end_pos(n).pos_cnum; -} - -function is_current_lookahead(tok) { - return current_lookahead_fun.contents(tok); -} - -function parse_error(param) { - -} - -let set_trace = Caml_parser.set_parser_trace; - -export { - symbol_start, - symbol_end, - rhs_start, - rhs_end, - symbol_start_pos, - symbol_end_pos, - rhs_start_pos, - rhs_end_pos, - clear_parser, - Parse_error, - set_trace, - YYexit, - yyparse, - peek_val, - is_current_lookahead, - parse_error, -} -/* No side effect */ diff --git a/lib/es6/pervasives.js b/lib/es6/pervasives.js index ef8e3d41a5..62aebb9e77 100644 --- a/lib/es6/pervasives.js +++ b/lib/es6/pervasives.js @@ -1,10 +1,6 @@ -import * as Caml_sys from "./caml_sys.js"; -import * as Caml_format from "./caml_format.js"; -import * as Caml_string from "./caml_string.js"; -import * as Caml_exceptions from "./caml_exceptions.js"; -import * as Caml_js_exceptions from "./caml_js_exceptions.js"; +import * as Primitive_exceptions from "./primitive_exceptions.js"; function failwith(s) { throw { @@ -22,7 +18,7 @@ function invalid_arg(s) { }; } -let Exit = /* @__PURE__ */Caml_exceptions.create("Pervasives.Exit"); +let Exit = /* @__PURE__ */Primitive_exceptions.create("Pervasives.Pervasives.Exit"); function abs(x) { if (x >= 0) { @@ -100,54 +96,11 @@ function bool_of_string_opt(param) { } function int_of_string_opt(s) { - try { - return Caml_format.int_of_string(s); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Failure") { - return; - } - throw exn; - } -} - -function valid_float_lexem(s) { - let l = s.length; - let _i = 0; - while (true) { - let i = _i; - if (i >= l) { - return s + "."; - } - let match = Caml_string.get(s, i); - if (match >= 48) { - if (match >= 58) { - return s; - } - _i = i + 1 | 0; - continue; - } - if (match !== 45) { - return s; - } - _i = i + 1 | 0; - continue; - }; -} - -function string_of_float(f) { - return valid_float_lexem(Caml_format.format_float("%.12g", f)); -} - -function float_of_string_opt(s) { - try { - return Caml_format.float_of_string(s); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Failure") { - return; - } - throw exn; + let n = Number.parseInt(s); + if (n === NaN) { + return; + } else { + return n; } } @@ -162,43 +115,28 @@ function $at(l1, l2) { } } -function print_newline() { - console.log(""); -} - -function prerr_newline() { - console.error(""); -} - -function print_int(i) { - console.log(String(i)); -} - -function print_float(i) { - console.log(valid_float_lexem(Caml_format.format_float("%.12g", i))); -} - -function print_string(prim) { - console.log(prim); -} - -let exit_function = { - contents: prim => {} +let Pervasives = { + failwith: failwith, + invalid_arg: invalid_arg, + Exit: Exit, + abs: abs, + lnot: lnot, + max_int: 2147483647, + min_int: min_int, + infinity: Infinity, + neg_infinity: -Infinity, + max_float: 1.79769313486231571e+308, + min_float: 2.22507385850720138e-308, + epsilon_float: 2.22044604925031308e-16, + classify_float: classify_float, + char_of_int: char_of_int, + string_of_bool: string_of_bool, + bool_of_string: bool_of_string, + bool_of_string_opt: bool_of_string_opt, + int_of_string_opt: int_of_string_opt, + $at: $at }; -function at_exit(f) { - let g = exit_function.contents; - exit_function.contents = () => { - f(); - g(); - }; -} - -function exit(retcode) { - exit_function.contents(); - return Caml_sys.sys_exit(retcode); -} - let max_int = 2147483647; let infinity = Infinity; @@ -212,13 +150,14 @@ let min_float = 2.22507385850720138e-308; let epsilon_float = 2.22044604925031308e-16; export { - invalid_arg, + Pervasives, failwith, + invalid_arg, Exit, abs, + lnot, max_int, min_int, - lnot, infinity, neg_infinity, max_float, @@ -230,16 +169,6 @@ export { bool_of_string, bool_of_string_opt, int_of_string_opt, - string_of_float, - float_of_string_opt, $at, - print_string, - print_int, - print_float, - print_newline, - prerr_newline, - exit, - at_exit, - valid_float_lexem, } /* No side effect */ diff --git a/lib/es6/primitive_array.js b/lib/es6/primitive_array.js new file mode 100644 index 0000000000..61e5492a8b --- /dev/null +++ b/lib/es6/primitive_array.js @@ -0,0 +1,35 @@ + + + +function length(prim) { + return prim.length; +} + +function get(xs, index) { + if (index < 0 || index >= xs.length) { + throw { + RE_EXN_ID: "Invalid_argument", + _1: "index out of bounds", + Error: new Error() + }; + } + return xs[index]; +} + +function set(xs, index, newval) { + if (index < 0 || index >= xs.length) { + throw { + RE_EXN_ID: "Invalid_argument", + _1: "index out of bounds", + Error: new Error() + }; + } + xs[index] = newval; +} + +export { + length, + get, + set, +} +/* No side effect */ diff --git a/lib/es6/caml_bigint_extern.js b/lib/es6/primitive_array_extern.js similarity index 100% rename from lib/es6/caml_bigint_extern.js rename to lib/es6/primitive_array_extern.js diff --git a/lib/es6/caml_bigint.js b/lib/es6/primitive_bigint.js similarity index 51% rename from lib/es6/caml_bigint.js rename to lib/es6/primitive_bigint.js index 098bf20b67..baa6793c36 100644 --- a/lib/es6/caml_bigint.js +++ b/lib/es6/primitive_bigint.js @@ -1,6 +1,32 @@ +function compare(x, y) { + if (x < y) { + return -1; + } else if (x === y) { + return 0; + } else { + return 1; + } +} + +function min(x, y) { + if (x < y) { + return x; + } else { + return y; + } +} + +function max(x, y) { + if (x > y) { + return x; + } else { + return y; + } +} + function div(x, y) { if (y === 0n) { throw { @@ -22,6 +48,9 @@ function mod_(x, y) { } export { + compare, + min, + max, div, mod_, } diff --git a/lib/es6/primitive_bool.js b/lib/es6/primitive_bool.js new file mode 100644 index 0000000000..1a849982f0 --- /dev/null +++ b/lib/es6/primitive_bool.js @@ -0,0 +1,39 @@ + + + +function compare(x, y) { + if (x) { + if (y) { + return 0; + } else { + return 1; + } + } else if (y) { + return -1; + } else { + return 0; + } +} + +function min(x, y) { + if (x) { + return y; + } else { + return x; + } +} + +function max(x, y) { + if (x) { + return x; + } else { + return y; + } +} + +export { + compare, + min, + max, +} +/* No side effect */ diff --git a/lib/es6/caml_float_extern.js b/lib/es6/primitive_char_extern.js similarity index 100% rename from lib/es6/caml_float_extern.js rename to lib/es6/primitive_char_extern.js diff --git a/lib/es6/primitive_curry.js b/lib/es6/primitive_curry.js new file mode 100644 index 0000000000..dc32d8492c --- /dev/null +++ b/lib/es6/primitive_curry.js @@ -0,0 +1,438 @@ + + + +function app(_f, _args) { + while (true) { + let args = _args; + let f = _f; + let init_arity = f.length; + let arity = init_arity === 0 ? 1 : init_arity; + let len = args.length; + let d = arity - len | 0; + if (d === 0) { + return f.apply(null, args); + } + if (d >= 0) { + return x => app(f, args.concat([x])); + } + _args = args.slice(arity, len); + _f = f.apply(null, args.slice(0, arity)); + continue; + }; +} + +function __1(o) { + let arity = o.length; + if (arity === 1) { + return o; + } else { + return a0 => { + let arity = o.length; + if (arity === 1) { + return o(a0); + } else { + switch (arity) { + case 1 : + return o(a0); + case 2 : + return param => o(a0, param); + case 3 : + return (param, param$1) => o(a0, param, param$1); + case 4 : + return (param, param$1, param$2) => o(a0, param, param$1, param$2); + case 5 : + return (param, param$1, param$2, param$3) => o(a0, param, param$1, param$2, param$3); + case 6 : + return (param, param$1, param$2, param$3, param$4) => o(a0, param, param$1, param$2, param$3, param$4); + case 7 : + return (param, param$1, param$2, param$3, param$4, param$5) => o(a0, param, param$1, param$2, param$3, param$4, param$5); + default: + return app(o, [a0]); + } + } + }; + } +} + +function __2(o) { + let arity = o.length; + if (arity === 2) { + return o; + } else { + return (a0, a1) => { + let arity = o.length; + if (arity === 2) { + return o(a0, a1); + } else { + switch (arity) { + case 1 : + return app(o(a0), [a1]); + case 2 : + return o(a0, a1); + case 3 : + return param => o(a0, a1, param); + case 4 : + return (param, param$1) => o(a0, a1, param, param$1); + case 5 : + return (param, param$1, param$2) => o(a0, a1, param, param$1, param$2); + case 6 : + return (param, param$1, param$2, param$3) => o(a0, a1, param, param$1, param$2, param$3); + case 7 : + return (param, param$1, param$2, param$3, param$4) => o(a0, a1, param, param$1, param$2, param$3, param$4); + default: + return app(o, [ + a0, + a1 + ]); + } + } + }; + } +} + +function __3(o) { + let arity = o.length; + if (arity === 3) { + return o; + } else { + return (a0, a1, a2) => { + let arity = o.length; + if (arity === 3) { + return o(a0, a1, a2); + } else { + switch (arity) { + case 1 : + return app(o(a0), [ + a1, + a2 + ]); + case 2 : + return app(o(a0, a1), [a2]); + case 3 : + return o(a0, a1, a2); + case 4 : + return param => o(a0, a1, a2, param); + case 5 : + return (param, param$1) => o(a0, a1, a2, param, param$1); + case 6 : + return (param, param$1, param$2) => o(a0, a1, a2, param, param$1, param$2); + case 7 : + return (param, param$1, param$2, param$3) => o(a0, a1, a2, param, param$1, param$2, param$3); + default: + return app(o, [ + a0, + a1, + a2 + ]); + } + } + }; + } +} + +function __4(o) { + let arity = o.length; + if (arity === 4) { + return o; + } else { + return (a0, a1, a2, a3) => { + let arity = o.length; + if (arity === 4) { + return o(a0, a1, a2, a3); + } else { + switch (arity) { + case 1 : + return app(o(a0), [ + a1, + a2, + a3 + ]); + case 2 : + return app(o(a0, a1), [ + a2, + a3 + ]); + case 3 : + return app(o(a0, a1, a2), [a3]); + case 4 : + return o(a0, a1, a2, a3); + case 5 : + return param => o(a0, a1, a2, a3, param); + case 6 : + return (param, param$1) => o(a0, a1, a2, a3, param, param$1); + case 7 : + return (param, param$1, param$2) => o(a0, a1, a2, a3, param, param$1, param$2); + default: + return app(o, [ + a0, + a1, + a2, + a3 + ]); + } + } + }; + } +} + +function __5(o) { + let arity = o.length; + if (arity === 5) { + return o; + } else { + return (a0, a1, a2, a3, a4) => { + let arity = o.length; + if (arity === 5) { + return o(a0, a1, a2, a3, a4); + } else { + switch (arity) { + case 1 : + return app(o(a0), [ + a1, + a2, + a3, + a4 + ]); + case 2 : + return app(o(a0, a1), [ + a2, + a3, + a4 + ]); + case 3 : + return app(o(a0, a1, a2), [ + a3, + a4 + ]); + case 4 : + return app(o(a0, a1, a2, a3), [a4]); + case 5 : + return o(a0, a1, a2, a3, a4); + case 6 : + return param => o(a0, a1, a2, a3, a4, param); + case 7 : + return (param, param$1) => o(a0, a1, a2, a3, a4, param, param$1); + default: + return app(o, [ + a0, + a1, + a2, + a3, + a4 + ]); + } + } + }; + } +} + +function __6(o) { + let arity = o.length; + if (arity === 6) { + return o; + } else { + return (a0, a1, a2, a3, a4, a5) => { + let arity = o.length; + if (arity === 6) { + return o(a0, a1, a2, a3, a4, a5); + } else { + switch (arity) { + case 1 : + return app(o(a0), [ + a1, + a2, + a3, + a4, + a5 + ]); + case 2 : + return app(o(a0, a1), [ + a2, + a3, + a4, + a5 + ]); + case 3 : + return app(o(a0, a1, a2), [ + a3, + a4, + a5 + ]); + case 4 : + return app(o(a0, a1, a2, a3), [ + a4, + a5 + ]); + case 5 : + return app(o(a0, a1, a2, a3, a4), [a5]); + case 6 : + return o(a0, a1, a2, a3, a4, a5); + case 7 : + return param => o(a0, a1, a2, a3, a4, a5, param); + default: + return app(o, [ + a0, + a1, + a2, + a3, + a4, + a5 + ]); + } + } + }; + } +} + +function __7(o) { + let arity = o.length; + if (arity === 7) { + return o; + } else { + return (a0, a1, a2, a3, a4, a5, a6) => { + let arity = o.length; + if (arity === 7) { + return o(a0, a1, a2, a3, a4, a5, a6); + } else { + switch (arity) { + case 1 : + return app(o(a0), [ + a1, + a2, + a3, + a4, + a5, + a6 + ]); + case 2 : + return app(o(a0, a1), [ + a2, + a3, + a4, + a5, + a6 + ]); + case 3 : + return app(o(a0, a1, a2), [ + a3, + a4, + a5, + a6 + ]); + case 4 : + return app(o(a0, a1, a2, a3), [ + a4, + a5, + a6 + ]); + case 5 : + return app(o(a0, a1, a2, a3, a4), [ + a5, + a6 + ]); + case 6 : + return app(o(a0, a1, a2, a3, a4, a5), [a6]); + case 7 : + return o(a0, a1, a2, a3, a4, a5, a6); + default: + return app(o, [ + a0, + a1, + a2, + a3, + a4, + a5, + a6 + ]); + } + } + }; + } +} + +function __8(o) { + let arity = o.length; + if (arity === 8) { + return o; + } else { + return (a0, a1, a2, a3, a4, a5, a6, a7) => { + let arity = o.length; + if (arity === 8) { + return o(a0, a1, a2, a3, a4, a5, a6, a7); + } else { + switch (arity) { + case 1 : + return app(o(a0), [ + a1, + a2, + a3, + a4, + a5, + a6, + a7 + ]); + case 2 : + return app(o(a0, a1), [ + a2, + a3, + a4, + a5, + a6, + a7 + ]); + case 3 : + return app(o(a0, a1, a2), [ + a3, + a4, + a5, + a6, + a7 + ]); + case 4 : + return app(o(a0, a1, a2, a3), [ + a4, + a5, + a6, + a7 + ]); + case 5 : + return app(o(a0, a1, a2, a3, a4), [ + a5, + a6, + a7 + ]); + case 6 : + return app(o(a0, a1, a2, a3, a4, a5), [ + a6, + a7 + ]); + case 7 : + return app(o(a0, a1, a2, a3, a4, a5, a6), [a7]); + default: + return app(o, [ + a0, + a1, + a2, + a3, + a4, + a5, + a6, + a7 + ]); + } + } + }; + } +} + +export { + __1, + __2, + __3, + __4, + __5, + __6, + __7, + __8, +} +/* No side effect */ diff --git a/lib/es6/caml_int64_extern.js b/lib/es6/primitive_dict.js similarity index 100% rename from lib/es6/caml_int64_extern.js rename to lib/es6/primitive_dict.js diff --git a/lib/es6/caml_exceptions.js b/lib/es6/primitive_exceptions.js similarity index 59% rename from lib/es6/caml_exceptions.js rename to lib/es6/primitive_exceptions.js index 9db019af3c..f4fefef083 100644 --- a/lib/es6/caml_exceptions.js +++ b/lib/es6/primitive_exceptions.js @@ -1,6 +1,25 @@ +function isExtension(e) { + if (e == null) { + return false; + } else { + return typeof e.RE_EXN_ID === "string"; + } +} + +function internalToException(e) { + if (isExtension(e)) { + return e; + } else { + return { + RE_EXN_ID: "JsError", + _1: e + }; + } +} + let idMap = {}; function create(str) { @@ -14,21 +33,11 @@ function create(str) { return str; } -function is_extension(e) { - if (e == null) { - return false; - } else { - return typeof e.RE_EXN_ID === "string"; - } -} - -function exn_slot_name(x) { - return x.RE_EXN_ID; -} +let $$Error = "JsError"; export { + $$Error, create, - is_extension, - exn_slot_name, + internalToException, } /* No side effect */ diff --git a/lib/es6/primitive_float.js b/lib/es6/primitive_float.js new file mode 100644 index 0000000000..b87b31cbf9 --- /dev/null +++ b/lib/es6/primitive_float.js @@ -0,0 +1,39 @@ + + + +function compare(x, y) { + if (x === y) { + return 0; + } else if (x < y) { + return -1; + } else if (x > y || x === x) { + return 1; + } else if (y === y) { + return -1; + } else { + return 0; + } +} + +function min(x, y) { + if (x < y) { + return x; + } else { + return y; + } +} + +function max(x, y) { + if (x > y) { + return x; + } else { + return y; + } +} + +export { + compare, + min, + max, +} +/* No side effect */ diff --git a/lib/es6/caml_nativeint_extern.js b/lib/es6/primitive_float_extern.js similarity index 100% rename from lib/es6/caml_nativeint_extern.js rename to lib/es6/primitive_float_extern.js diff --git a/lib/es6/primitive_hash.js b/lib/es6/primitive_hash.js new file mode 100644 index 0000000000..e6069cd9ac --- /dev/null +++ b/lib/es6/primitive_hash.js @@ -0,0 +1,154 @@ + + + +function push_back(q, v) { + let cell = { + content: v, + next: undefined + }; + let last = q.last; + if (last !== undefined) { + q.length = q.length + 1 | 0; + last.next = cell; + q.last = cell; + } else { + q.length = 1; + q.first = cell; + q.last = cell; + } +} + +function unsafe_pop(q) { + let cell = q.first; + if (cell !== undefined) { + let next = cell.next; + if (next === undefined) { + q.length = 0; + q.first = undefined; + q.last = undefined; + } else { + q.length = q.length - 1 | 0; + q.first = next; + } + return cell.content; + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "primitive_hash.res", + 70, + 12 + ], + Error: new Error() + }; +} + +function rotl32(x, n) { + return (x << n) | (x >>> (32 - n | 0)) | 0; +} + +function hash_mix_int(h, d) { + let d$1 = d; + d$1 = Math.imul(d$1, -862048943); + d$1 = rotl32(d$1, 15); + d$1 = Math.imul(d$1, 461845907); + let h$1 = h ^ d$1; + h$1 = rotl32(h$1, 13); + return (h$1 + (h$1 << 2) | 0) - 430675100 | 0; +} + +function hash_final_mix(h) { + let h$1 = h ^ (h >>> 16); + h$1 = Math.imul(h$1, -2048144789); + h$1 = h$1 ^ (h$1 >>> 13); + h$1 = Math.imul(h$1, -1028477387); + return h$1 ^ (h$1 >>> 16); +} + +function hash_mix_string(h, s) { + let len = s.length; + let block = (len / 4 | 0) - 1 | 0; + let hash = h; + for (let i = 0; i <= block; ++i) { + let j = (i << 2); + let w = s.charCodeAt(j) | (s.charCodeAt(j + 1 | 0) << 8) | (s.charCodeAt(j + 2 | 0) << 16) | (s.charCodeAt(j + 3 | 0) << 24); + hash = hash_mix_int(hash, w); + } + let modulo = len & 3; + if (modulo !== 0) { + let w$1 = modulo === 3 ? (s.charCodeAt(len - 1 | 0) << 16) | (s.charCodeAt(len - 2 | 0) << 8) | s.charCodeAt(len - 3 | 0) : ( + modulo === 2 ? (s.charCodeAt(len - 1 | 0) << 8) | s.charCodeAt(len - 2 | 0) : s.charCodeAt(len - 1 | 0) + ); + hash = hash_mix_int(hash, w$1); + } + hash = hash ^ len; + return hash; +} + +function hash(count, _limit, seed, obj) { + let s = seed; + if (typeof obj === "number") { + let u = obj | 0; + s = hash_mix_int(s, (u + u | 0) + 1 | 0); + return hash_final_mix(s); + } + if (typeof obj === "string") { + s = hash_mix_string(s, obj); + return hash_final_mix(s); + } + let queue = { + length: 0, + first: undefined, + last: undefined + }; + let num = count; + push_back(queue, obj); + num = num - 1 | 0; + while (queue.length !== 0 && num > 0) { + let obj$1 = unsafe_pop(queue); + if (typeof obj$1 === "number") { + let u$1 = obj$1 | 0; + s = hash_mix_int(s, (u$1 + u$1 | 0) + 1 | 0); + num = num - 1 | 0; + } else if (typeof obj$1 === "string") { + s = hash_mix_string(s, obj$1); + num = num - 1 | 0; + } else if (typeof obj$1 !== "boolean" && typeof obj$1 !== "undefined" && typeof obj$1 !== "symbol" && typeof obj$1 !== "function") { + let size = obj$1.length | 0; + if (size !== 0) { + let obj_tag = obj$1.TAG; + let tag = (size << 10) | obj_tag; + if (obj_tag === 248) { + s = hash_mix_int(s, obj$1[1]); + } else { + s = hash_mix_int(s, tag); + let v = size - 1 | 0; + let block = v < num ? v : num; + for (let i = 0; i <= block; ++i) { + push_back(queue, obj$1[i]); + } + } + } else { + let size$1 = (function(obj,cb){ + var size = 0 + for(var k in obj){ + cb(obj[k]) + ++ size + } + return size + })(obj$1, v => push_back(queue, v)); + s = hash_mix_int(s, (size$1 << 10) | 0); + } + } + + }; + return hash_final_mix(s); +} + +export { + hash_mix_int, + hash_mix_string, + hash_final_mix, + hash, +} +/* No side effect */ diff --git a/lib/es6/caml_int32.js b/lib/es6/primitive_int.js similarity index 51% rename from lib/es6/caml_int32.js rename to lib/es6/primitive_int.js index adc5a19e40..7f638f0723 100644 --- a/lib/es6/caml_int32.js +++ b/lib/es6/primitive_int.js @@ -1,6 +1,32 @@ +function compare(x, y) { + if (x < y) { + return -1; + } else if (x === y) { + return 0; + } else { + return 1; + } +} + +function min(x, y) { + if (x < y) { + return x; + } else { + return y; + } +} + +function max(x, y) { + if (x > y) { + return x; + } else { + return y; + } +} + function div(x, y) { if (y === 0) { throw { @@ -22,6 +48,9 @@ function mod_(x, y) { } export { + compare, + min, + max, div, mod_, } diff --git a/lib/es6/caml_string_extern.js b/lib/es6/primitive_int_extern.js similarity index 100% rename from lib/es6/caml_string_extern.js rename to lib/es6/primitive_int_extern.js diff --git a/lib/es6/caml_undefined_extern.js b/lib/es6/primitive_js_extern.js similarity index 100% rename from lib/es6/caml_undefined_extern.js rename to lib/es6/primitive_js_extern.js diff --git a/lib/es6/camlinternalLazy.js b/lib/es6/primitive_lazy.js similarity index 86% rename from lib/es6/camlinternalLazy.js rename to lib/es6/primitive_lazy.js index c6dbdc0c20..0505d2aa35 100644 --- a/lib/es6/camlinternalLazy.js +++ b/lib/es6/primitive_lazy.js @@ -1,12 +1,12 @@ -import * as Caml_exceptions from "./caml_exceptions.js"; +import * as Primitive_exceptions from "./primitive_exceptions.js"; function is_val(l) { return l.LAZY_DONE; } -let Undefined = /* @__PURE__ */Caml_exceptions.create("CamlinternalLazy.Undefined"); +let Undefined = /* @__PURE__ */Primitive_exceptions.create("Primitive_lazy.Undefined"); function forward_with_closure(blk, closure) { let result = closure(); @@ -67,8 +67,8 @@ export { Undefined, force, force_val, - is_val, from_fun, from_val, + is_val, } /* No side effect */ diff --git a/lib/es6/caml_module.js b/lib/es6/primitive_module.js similarity index 76% rename from lib/es6/caml_module.js rename to lib/es6/primitive_module.js index 09f354ec2e..b2832a9f10 100644 --- a/lib/es6/caml_module.js +++ b/lib/es6/primitive_module.js @@ -1,8 +1,7 @@ -import * as Caml_obj from "./caml_obj.js"; -function init_mod(loc, shape) { +function init(loc, shape) { let undef_module = param => { throw { RE_EXN_ID: "Undefined_recursive_module", @@ -27,18 +26,18 @@ function init_mod(loc, shape) { return; } } else { - if (shape.TAG === "Module") { - let comps = shape._0; - let v = {}; - struct_[idx] = v; - let len = comps.length; - for (let i = 0; i < len; ++i) { - let match = comps[i]; - loop(match[0], v, match[1]); - } + if (shape.TAG !== "Module") { + struct_[idx] = shape._0; return; } - struct_[idx] = shape._0; + let comps = shape._0; + let v = {}; + struct_[idx] = v; + let len = comps.length; + for (let i = 0; i < len; ++i) { + let match = comps[i]; + loop(match[0], v, match[1]); + } return; } }; @@ -48,7 +47,7 @@ function init_mod(loc, shape) { return res[dummy_name]; } -function update_mod(shape, o, n) { +function update(shape, o, n) { let aux = (shape, o, n, parent, i) => { if (typeof shape !== "object") { switch (shape) { @@ -57,7 +56,8 @@ function update_mod(shape, o, n) { return; case "Lazy" : case "Class" : - return Caml_obj.update_dummy(o, n); + Object.assign(o, n); + return; } } else { if (shape.TAG !== "Module") { @@ -76,8 +76,8 @@ function update_mod(shape, o, n) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "caml_module.res", - 109, + "primitive_module.res", + 68, 9 ], Error: new Error() @@ -95,8 +95,8 @@ function update_mod(shape, o, n) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "caml_module.res", - 109, + "primitive_module.res", + 68, 9 ], Error: new Error() @@ -104,7 +104,7 @@ function update_mod(shape, o, n) { } export { - init_mod, - update_mod, + init, + update, } /* No side effect */ diff --git a/lib/es6/caml_obj.js b/lib/es6/primitive_object.js similarity index 89% rename from lib/es6/caml_obj.js rename to lib/es6/primitive_object.js index 244a87161d..a0014407ff 100644 --- a/lib/es6/caml_obj.js +++ b/lib/es6/primitive_object.js @@ -1,25 +1,16 @@ -import * as Caml from "./caml.js"; +import * as Primitive_int from "./primitive_int.js"; +import * as Primitive_bool from "./primitive_bool.js"; +import * as Primitive_float from "./primitive_float.js"; +import * as Primitive_string from "./primitive_string.js"; let for_in = (function(o,foo){ for (var x in o) { foo(x) }}); -let update_dummy = (function(x,y){ - var k - if(Array.isArray(y)){ - for(k = 0; k < y.length ; ++k){ - x[k] = y[k] - } - if(y.TAG !== undefined){ - x.TAG = y.TAG - } - } else { - for (var k in y){ - x[k] = y[k] - } - } -}); +function updateDummy(prim0, prim1) { + Object.assign(prim0, prim1); +} function compare(a, b) { if (a === b) { @@ -30,12 +21,12 @@ function compare(a, b) { switch (a_type) { case "bigint" : if (b_type === "bigint") { - return Caml.float_compare(a, b); + return Primitive_float.compare(a, b); } break; case "boolean" : if (b_type === "boolean") { - return Caml.bool_compare(a, b); + return Primitive_bool.compare(a, b); } break; case "function" : @@ -49,12 +40,12 @@ function compare(a, b) { break; case "number" : if (b_type === "number") { - return Caml.float_compare(a, b); + return Primitive_float.compare(a, b); } break; case "string" : if (b_type === "string") { - return Caml.string_compare(a, b); + return Primitive_string.compare(a, b); } else { return 1; } @@ -117,7 +108,7 @@ function compare(a, b) { let tag_a = a.TAG; let tag_b = b.TAG; if (tag_a === 248) { - return Caml.int_compare(a[1], b[1]); + return Primitive_int.compare(a[1], b[1]); } if (tag_a === 251) { throw { @@ -224,7 +215,7 @@ function aux_obj_compare(a, b) { let match$1 = min_key_rhs.contents; if (match !== undefined) { if (match$1 !== undefined) { - return Caml.string_compare(match, match$1); + return Primitive_string.compare(match, match$1); } else { return -1; } @@ -316,30 +307,6 @@ function equal(a, b) { } } -function equal_null(x, y) { - if (y !== null) { - return equal(x, y); - } else { - return x === y; - } -} - -function equal_undefined(x, y) { - if (y !== undefined) { - return equal(x, y); - } else { - return x === y; - } -} - -function equal_nullable(x, y) { - if (y == null) { - return x === y; - } else { - return equal(x, y); - } -} - function notequal(a, b) { if ((typeof a === "number" || typeof a === "bigint") && (typeof b === "number" || typeof b === "bigint")) { return a !== b; @@ -397,12 +364,9 @@ function max(x, y) { } export { - update_dummy, + updateDummy, compare, equal, - equal_null, - equal_undefined, - equal_nullable, notequal, greaterequal, greaterthan, diff --git a/lib/es6/camlinternalMod.js b/lib/es6/primitive_object_extern.js similarity index 100% rename from lib/es6/camlinternalMod.js rename to lib/es6/primitive_object_extern.js diff --git a/lib/es6/caml_option.js b/lib/es6/primitive_option.js similarity index 83% rename from lib/es6/caml_option.js rename to lib/es6/primitive_option.js index 704efe581c..2bdb0ccca9 100644 --- a/lib/es6/caml_option.js +++ b/lib/es6/primitive_option.js @@ -19,7 +19,7 @@ function some(x) { } } -function nullable_to_opt(x) { +function fromNullable(x) { if (x == null) { return; } else { @@ -27,7 +27,7 @@ function nullable_to_opt(x) { } } -function undefined_to_opt(x) { +function fromUndefined(x) { if (x === undefined) { return; } else { @@ -35,7 +35,7 @@ function undefined_to_opt(x) { } } -function null_to_opt(x) { +function fromNull(x) { if (x === null) { return; } else { @@ -57,7 +57,7 @@ function valFromOption(x) { } } -function option_get(x) { +function toUndefined(x) { if (x === undefined) { return; } else { @@ -65,7 +65,7 @@ function option_get(x) { } } -function option_unwrap(x) { +function unwrapPolyVar(x) { if (x !== undefined) { return x.VAL; } else { @@ -74,13 +74,13 @@ function option_unwrap(x) { } export { - nullable_to_opt, - undefined_to_opt, - null_to_opt, + fromNullable, + fromUndefined, + fromNull, valFromOption, some, isNested, - option_get, - option_unwrap, + toUndefined, + unwrapPolyVar, } /* No side effect */ diff --git a/lib/es6/runtime_dict.js b/lib/es6/primitive_promise.js similarity index 100% rename from lib/es6/runtime_dict.js rename to lib/es6/primitive_promise.js diff --git a/lib/es6/primitive_string.js b/lib/es6/primitive_string.js new file mode 100644 index 0000000000..1aa94d4627 --- /dev/null +++ b/lib/es6/primitive_string.js @@ -0,0 +1,52 @@ + + + +function compare(s1, s2) { + if (s1 === s2) { + return 0; + } else if (s1 < s2) { + return -1; + } else { + return 1; + } +} + +function min(x, y) { + if (x < y) { + return x; + } else { + return y; + } +} + +function max(x, y) { + if (x > y) { + return x; + } else { + return y; + } +} + +function getChar(s, i) { + if (i >= s.length || i < 0) { + throw { + RE_EXN_ID: "Invalid_argument", + _1: "index out of bounds", + Error: new Error() + }; + } + return s.codePointAt(i); +} + +function make(n, ch) { + return String.fromCodePoint(ch).repeat(n); +} + +export { + compare, + min, + max, + getChar, + make, +} +/* No side effect */ diff --git a/lib/es6/runtime_promise.js b/lib/es6/primitive_string_extern.js similarity index 100% rename from lib/es6/runtime_promise.js rename to lib/es6/primitive_string_extern.js diff --git a/lib/es6/runtime_deriving.js b/lib/es6/primitive_util.js similarity index 93% rename from lib/es6/runtime_deriving.js rename to lib/es6/primitive_util.js index a5299e3648..6aef21e923 100644 --- a/lib/es6/runtime_deriving.js +++ b/lib/es6/primitive_util.js @@ -11,7 +11,10 @@ function raiseWhenNotFound(x) { return x; } +let Js; + export { + Js, raiseWhenNotFound, } /* No side effect */ diff --git a/lib/es6/queue.js b/lib/es6/queue.js deleted file mode 100644 index 060df8ec7e..0000000000 --- a/lib/es6/queue.js +++ /dev/null @@ -1,180 +0,0 @@ - - -import * as Caml_exceptions from "./caml_exceptions.js"; - -let Empty = /* @__PURE__ */Caml_exceptions.create("Queue.Empty"); - -function create() { - return { - length: 0, - first: "Nil", - last: "Nil" - }; -} - -function clear(q) { - q.length = 0; - q.first = "Nil"; - q.last = "Nil"; -} - -function add(x, q) { - let cell = { - TAG: "Cons", - content: x, - next: "Nil" - }; - let last = q.last; - if (typeof last !== "object") { - q.length = 1; - q.first = cell; - q.last = cell; - return; - } - q.length = q.length + 1 | 0; - last.next = cell; - q.last = cell; -} - -function peek(q) { - let match = q.first; - if (typeof match === "object") { - return match.content; - } - throw { - RE_EXN_ID: Empty, - Error: new Error() - }; -} - -function take(q) { - let match = q.first; - if (typeof match !== "object") { - throw { - RE_EXN_ID: Empty, - Error: new Error() - }; - } - let content = match.content; - let next = match.next; - if (typeof next !== "object") { - clear(q); - return content; - } - q.length = q.length - 1 | 0; - q.first = next; - return content; -} - -function copy(q) { - let q_res = { - length: q.length, - first: "Nil", - last: "Nil" - }; - let _prev = "Nil"; - let _cell = q.first; - while (true) { - let cell = _cell; - let prev = _prev; - if (typeof cell !== "object") { - q_res.last = prev; - return q_res; - } - let next = cell.next; - let res = { - TAG: "Cons", - content: cell.content, - next: "Nil" - }; - if (typeof prev !== "object") { - q_res.first = res; - } else { - prev.next = res; - } - _cell = next; - _prev = res; - continue; - }; -} - -function is_empty(q) { - return q.length === 0; -} - -function length(q) { - return q.length; -} - -function iter(f, q) { - let _cell = q.first; - while (true) { - let cell = _cell; - if (typeof cell !== "object") { - return; - } - let next = cell.next; - f(cell.content); - _cell = next; - continue; - }; -} - -function fold(f, accu, q) { - let _accu = accu; - let _cell = q.first; - while (true) { - let cell = _cell; - let accu$1 = _accu; - if (typeof cell !== "object") { - return accu$1; - } - let next = cell.next; - let accu$2 = f(accu$1, cell.content); - _cell = next; - _accu = accu$2; - continue; - }; -} - -function transfer(q1, q2) { - if (q1.length <= 0) { - return; - } - let last = q2.last; - if (typeof last !== "object") { - q2.length = q1.length; - q2.first = q1.first; - q2.last = q1.last; - return clear(q1); - } - q2.length = q2.length + q1.length | 0; - last.next = q1.first; - q2.last = q1.last; - clear(q1); -} - -let push = add; - -let pop = take; - -let top = peek; - -export { - Empty, - create, - add, - push, - take, - pop, - peek, - top, - clear, - copy, - is_empty, - length, - iter, - fold, - transfer, -} -/* No side effect */ diff --git a/lib/es6/random.js b/lib/es6/random.js deleted file mode 100644 index e73c109347..0000000000 --- a/lib/es6/random.js +++ /dev/null @@ -1,276 +0,0 @@ - - -import * as Caml from "./caml.js"; -import * as $$Array from "./array.js"; -import * as Int32 from "./int32.js"; -import * as Int64 from "./int64.js"; -import * as Digest from "./digest.js"; -import * as Caml_array from "./caml_array.js"; -import * as Caml_int64 from "./caml_int64.js"; -import * as Caml_string from "./caml_string.js"; - -function random_seed() { - return [(Math.floor(Math.random()*0x7fffffff))]; -} - -function assign(st1, st2) { - $$Array.blit(st2.st, 0, st1.st, 0, 55); - st1.idx = st2.idx; -} - -function full_init(s, seed) { - let combine = (accu, x) => Digest.string(accu + String(x)); - let extract = d => ((Caml_string.get(d, 0) + (Caml_string.get(d, 1) << 8) | 0) + (Caml_string.get(d, 2) << 16) | 0) + (Caml_string.get(d, 3) << 24) | 0; - let seed$1 = seed.length === 0 ? [0] : seed; - let l = seed$1.length; - for (let i = 0; i <= 54; ++i) { - Caml_array.set(s.st, i, i); - } - let accu = "x"; - for (let i$1 = 0, i_finish = 54 + ( - 55 > l ? 55 : l - ) | 0; i$1 <= i_finish; ++i$1) { - let j = i$1 % 55; - let k = i$1 % l; - accu = combine(accu, Caml_array.get(seed$1, k)); - Caml_array.set(s.st, j, (Caml_array.get(s.st, j) ^ extract(accu)) & 1073741823); - } - s.idx = 0; -} - -function make(seed) { - let result = { - st: Caml_array.make(55, 0), - idx: 0 - }; - full_init(result, seed); - return result; -} - -function make_self_init() { - return make(random_seed()); -} - -function copy(s) { - let result = { - st: Caml_array.make(55, 0), - idx: 0 - }; - assign(result, s); - return result; -} - -function bits(s) { - s.idx = (s.idx + 1 | 0) % 55; - let curval = Caml_array.get(s.st, s.idx); - let newval = Caml_array.get(s.st, (s.idx + 24 | 0) % 55) + (curval ^ (curval >>> 25) & 31) | 0; - let newval30 = newval & 1073741823; - Caml_array.set(s.st, s.idx, newval30); - return newval30; -} - -function int(s, bound) { - if (bound > 1073741823 || bound <= 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Random.int", - Error: new Error() - }; - } - while (true) { - let r = bits(s); - let v = r % bound; - if ((r - v | 0) <= ((1073741823 - bound | 0) + 1 | 0)) { - return v; - } - continue; - }; -} - -function int32(s, bound) { - if (bound <= 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Random.int32", - Error: new Error() - }; - } - while (true) { - let b1 = bits(s); - let b2 = ((bits(s) & 1) << 30); - let r = b1 | b2; - let v = r % bound; - if ((r - v | 0) <= ((Int32.max_int - bound | 0) + 1 | 0)) { - return v; - } - continue; - }; -} - -function int64(s, bound) { - if (Caml.i64_le(bound, Caml_int64.zero)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Random.int64", - Error: new Error() - }; - } - while (true) { - let b1 = Caml_int64.of_int32(bits(s)); - let b2 = Caml_int64.lsl_(Caml_int64.of_int32(bits(s)), 30); - let b3 = Caml_int64.lsl_(Caml_int64.of_int32(bits(s) & 7), 60); - let r = Caml_int64.or_(b1, Caml_int64.or_(b2, b3)); - let v = Caml_int64.mod_(r, bound); - if (!Caml.i64_gt(Caml_int64.sub(r, v), Caml_int64.add(Caml_int64.sub(Int64.max_int, bound), Caml_int64.one))) { - return v; - } - continue; - }; -} - -function rawfloat(s) { - let r1 = bits(s); - let r2 = bits(s); - return (r1 / 1073741824.0 + r2) / 1073741824.0; -} - -function float(s, bound) { - return rawfloat(s) * bound; -} - -function bool(s) { - return (bits(s) & 1) === 0; -} - -let $$default = { - st: [ - 987910699, - 495797812, - 364182224, - 414272206, - 318284740, - 990407751, - 383018966, - 270373319, - 840823159, - 24560019, - 536292337, - 512266505, - 189156120, - 730249596, - 143776328, - 51606627, - 140166561, - 366354223, - 1003410265, - 700563762, - 981890670, - 913149062, - 526082594, - 1021425055, - 784300257, - 667753350, - 630144451, - 949649812, - 48546892, - 415514493, - 258888527, - 511570777, - 89983870, - 283659902, - 308386020, - 242688715, - 482270760, - 865188196, - 1027664170, - 207196989, - 193777847, - 619708188, - 671350186, - 149669678, - 257044018, - 87658204, - 558145612, - 183450813, - 28133145, - 901332182, - 710253903, - 510646120, - 652377910, - 409934019, - 801085050 - ], - idx: 0 -}; - -function bits$1() { - return bits($$default); -} - -function int$1(bound) { - return int($$default, bound); -} - -function int32$1(bound) { - return int32($$default, bound); -} - -function int64$1(bound) { - return int64($$default, bound); -} - -function float$1(scale) { - return rawfloat($$default) * scale; -} - -function bool$1() { - return bool($$default); -} - -function full_init$1(seed) { - full_init($$default, seed); -} - -function init(seed) { - full_init($$default, [seed]); -} - -function self_init() { - full_init$1(random_seed()); -} - -function get_state() { - return copy($$default); -} - -function set_state(s) { - assign($$default, s); -} - -let State = { - make: make, - make_self_init: make_self_init, - copy: copy, - bits: bits, - int: int, - int32: int32, - int64: int64, - float: float, - bool: bool -}; - -export { - init, - full_init$1 as full_init, - self_init, - bits$1 as bits, - int$1 as int, - int32$1 as int32, - int64$1 as int64, - float$1 as float, - bool$1 as bool, - State, - get_state, - set_state, -} -/* No side effect */ diff --git a/lib/es6/set.js b/lib/es6/set.js index dbebe6a6a9..ae1b9f17e6 100644 --- a/lib/es6/set.js +++ b/lib/es6/set.js @@ -1,959 +1 @@ - - -import * as List from "./list.js"; -import * as Caml_option from "./caml_option.js"; - -function Make(funarg) { - let height = param => { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } - }; - let create = (l, v, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - }; - let bal = (l, v, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - let lr = l.r; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, create(lr, v, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, lr.l), lr.v, create(lr.r, v, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - let rr = r.r; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, v, rl), rv, rr); - } - if (typeof rl === "object") { - return create(create(l, v, rl.l), rl.v, create(rl.r, rv, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - }; - let add = (x, param) => { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - return param; - } - if (c < 0) { - let ll = add(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = add(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } - }; - let singleton = x => ({ - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }); - let add_min_element = (x, param) => { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(add_min_element(x, param.l), param.v, param.r); - } - }; - let add_max_element = (x, param) => { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(param.l, param.v, add_max_element(x, param.r)); - } - }; - let join = (l, v, r) => { - if (typeof l !== "object") { - return add_min_element(v, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_element(v, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, join(l.r, v, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, r.l), r.v, r.r); - } else { - return create(l, v, r); - } - }; - let min_elt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.v; - } - _param = l; - continue; - }; - }; - let min_elt_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return Caml_option.some(param.v); - } - _param = l; - continue; - }; - }; - let max_elt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let r = param.r; - if (typeof r !== "object") { - return param.v; - } - _param = r; - continue; - }; - }; - let max_elt_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return Caml_option.some(param.v); - } - _param = r; - continue; - }; - }; - let remove_min_elt = param => { - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.remove_min_elt", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_elt(l), param.v, param.r); - } - }; - let concat = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } else if (typeof t2 !== "object") { - return t1; - } else { - return join(t1, min_elt(t2), remove_min_elt(t2)); - } - }; - let split = (x, param) => { - if (typeof param !== "object") { - return [ - "Empty", - false, - "Empty" - ]; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - return [ - l, - true, - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, match$1[0]), - match$1[1], - match$1[2] - ]; - }; - let is_empty = param => { - if (typeof param !== "object") { - return true; - } else { - return false; - } - }; - let mem = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = funarg.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let remove = (x, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - if (typeof l !== "object") { - return r; - } else if (typeof r !== "object") { - return l; - } else { - return bal(l, min_elt(r), remove_min_elt(r)); - } - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } - }; - let union = (s1, s2) => { - if (typeof s1 !== "object") { - return s2; - } - let h1 = s1.h; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let h2 = s2.h; - let v2 = s2.v; - if (h1 >= h2) { - if (h2 === 1) { - return add(v2, s1); - } - let match = split(v1, s2); - return join(union(s1.l, match[0]), v1, union(s1.r, match[2])); - } - if (h1 === 1) { - return add(v1, s2); - } - let match$1 = split(v2, s1); - return join(union(match$1[0], s2.l), v2, union(match$1[2], s2.r)); - }; - let inter = (s1, s2) => { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return "Empty"; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return join(inter(l1, l2), v1, inter(r1, match[2])); - } else { - return concat(inter(l1, l2), inter(r1, match[2])); - } - }; - let diff = (s1, s2) => { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return s1; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return concat(diff(l1, l2), diff(r1, match[2])); - } else { - return join(diff(l1, l2), v1, diff(r1, match[2])); - } - }; - let cons_enum = (_s, _e) => { - while (true) { - let e = _e; - let s = _s; - if (typeof s !== "object") { - return e; - } - _e = { - TAG: "More", - _0: s.v, - _1: s.r, - _2: e - }; - _s = s.l; - continue; - }; - }; - let compare = (s1, s2) => { - let _e1 = cons_enum(s1, "End"); - let _e2 = cons_enum(s2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = funarg.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - _e2 = cons_enum(e2._1, e2._2); - _e1 = cons_enum(e1._1, e1._2); - continue; - }; - }; - let equal = (s1, s2) => compare(s1, s2) === 0; - let subset = (_s1, _s2) => { - while (true) { - let s2 = _s2; - let s1 = _s1; - if (typeof s1 !== "object") { - return true; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - if (typeof s2 !== "object") { - return false; - } - let r2 = s2.r; - let l2 = s2.l; - let c = funarg.compare(v1, s2.v); - if (c === 0) { - if (!subset(l1, l2)) { - return false; - } - _s2 = r2; - _s1 = r1; - continue; - } - if (c < 0) { - if (!subset({ - TAG: "Node", - l: l1, - v: v1, - r: "Empty", - h: 0 - }, l2)) { - return false; - } - _s1 = r1; - continue; - } - if (!subset({ - TAG: "Node", - l: "Empty", - v: v1, - r: r1, - h: 0 - }, r2)) { - return false; - } - _s1 = l1; - continue; - }; - }; - let iter = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v); - _param = param.r; - continue; - }; - }; - let fold = (f, _s, _accu) => { - while (true) { - let accu = _accu; - let s = _s; - if (typeof s !== "object") { - return accu; - } - _accu = f(s.v, fold(f, s.l, accu)); - _s = s.r; - continue; - }; - }; - let for_all = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; - }; - let exists = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; - }; - let filter = (p, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pv = p(v); - let r$p = filter(p, r); - if (pv) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, r$p); - } - } else { - return concat(l$p, r$p); - } - }; - let partition = (p, param) => { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pv = p(v); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pv) { - return [ - join(lt, v, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, rf) - ]; - } - }; - let cardinal = param => { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } - }; - let elements_aux = (_accu, _param) => { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: param.v, - tl: elements_aux(accu, param.r) - }; - continue; - }; - }; - let elements = s => elements_aux(/* [] */0, s); - let find = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - let c = funarg.compare(x, v); - if (c === 0) { - return v; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let find_first = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return v0; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; - }; - let find_first_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return Caml_option.some(v0); - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; - }; - let find_last = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return v0; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; - }; - let find_last_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return Caml_option.some(v0); - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; - }; - let find_opt = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - let c = funarg.compare(x, v); - if (c === 0) { - return Caml_option.some(v); - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let map = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = map(f, l); - let v$p = f(v); - let r$p = map(f, r); - if (l === l$p && v === v$p && r === r$p) { - return param; - } else if ((l$p === "Empty" || funarg.compare(max_elt(l$p), v$p) < 0) && (r$p === "Empty" || funarg.compare(v$p, min_elt(r$p)) < 0)) { - return join(l$p, v$p, r$p); - } else { - return union(l$p, add(v$p, r$p)); - } - }; - let of_list = l => { - if (!l) { - return "Empty"; - } - let match = l.tl; - let x0 = l.hd; - if (!match) { - return singleton(x0); - } - let match$1 = match.tl; - let x1 = match.hd; - if (!match$1) { - return add(x1, singleton(x0)); - } - let match$2 = match$1.tl; - let x2 = match$1.hd; - if (!match$2) { - return add(x2, add(x1, singleton(x0))); - } - let match$3 = match$2.tl; - let x3 = match$2.hd; - if (match$3) { - if (match$3.tl) { - let l$1 = List.sort_uniq(funarg.compare, l); - let sub = (n, l) => { - switch (n) { - case 0 : - return [ - "Empty", - l - ]; - case 1 : - if (l) { - return [ - { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - l.tl - ]; - } - break; - case 2 : - if (l) { - let match = l.tl; - if (match) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match.hd, - r: "Empty", - h: 2 - }, - match.tl - ]; - } - - } - break; - case 3 : - if (l) { - let match$1 = l.tl; - if (match$1) { - let match$2 = match$1.tl; - if (match$2) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match$1.hd, - r: { - TAG: "Node", - l: "Empty", - v: match$2.hd, - r: "Empty", - h: 1 - }, - h: 2 - }, - match$2.tl - ]; - } - - } - - } - break; - } - let nl = n / 2 | 0; - let match$3 = sub(nl, l); - let l$1 = match$3[1]; - if (l$1) { - let match$4 = sub((n - nl | 0) - 1 | 0, l$1.tl); - return [ - create(match$3[0], l$1.hd, match$4[0]), - match$4[1] - ]; - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "set.res", - 691, - 20 - ], - Error: new Error() - }; - }; - return sub(List.length(l$1), l$1)[0]; - } else { - return add(match$3.hd, add(x3, add(x2, add(x1, singleton(x0))))); - } - } else { - return add(x3, add(x2, add(x1, singleton(x0)))); - } - }; - return { - empty: "Empty", - is_empty: is_empty, - mem: mem, - add: add, - singleton: singleton, - remove: remove, - union: union, - inter: inter, - diff: diff, - compare: compare, - equal: equal, - subset: subset, - iter: iter, - map: map, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - elements: elements, - min_elt: min_elt, - min_elt_opt: min_elt_opt, - max_elt: max_elt, - max_elt_opt: max_elt_opt, - choose: min_elt, - choose_opt: min_elt_opt, - split: split, - find: find, - find_opt: find_opt, - find_first: find_first, - find_first_opt: find_first_opt, - find_last: find_last, - find_last_opt: find_last_opt, - of_list: of_list - }; -} - -export { - Make, -} -/* No side effect */ +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/lib/es6/setLabels.js b/lib/es6/setLabels.js deleted file mode 100644 index f803387202..0000000000 --- a/lib/es6/setLabels.js +++ /dev/null @@ -1,990 +0,0 @@ - - -import * as List from "./list.js"; -import * as Caml_option from "./caml_option.js"; - -function Make(Ord) { - let height = param => { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } - }; - let create = (l, v, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - }; - let bal = (l, v, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - let lr = l.r; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, create(lr, v, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, lr.l), lr.v, create(lr.r, v, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - let rr = r.r; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, v, rl), rv, rr); - } - if (typeof rl === "object") { - return create(create(l, v, rl.l), rl.v, create(rl.r, rv, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - }; - let add = (x, param) => { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - return param; - } - if (c < 0) { - let ll = add(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = add(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } - }; - let singleton = x => ({ - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }); - let add_min_element = (x, param) => { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(add_min_element(x, param.l), param.v, param.r); - } - }; - let add_max_element = (x, param) => { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(param.l, param.v, add_max_element(x, param.r)); - } - }; - let join = (l, v, r) => { - if (typeof l !== "object") { - return add_min_element(v, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_element(v, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, join(l.r, v, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, r.l), r.v, r.r); - } else { - return create(l, v, r); - } - }; - let min_elt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.v; - } - _param = l; - continue; - }; - }; - let min_elt_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return Caml_option.some(param.v); - } - _param = l; - continue; - }; - }; - let max_elt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let r = param.r; - if (typeof r !== "object") { - return param.v; - } - _param = r; - continue; - }; - }; - let max_elt_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return Caml_option.some(param.v); - } - _param = r; - continue; - }; - }; - let remove_min_elt = param => { - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.remove_min_elt", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_elt(l), param.v, param.r); - } - }; - let merge = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } else if (typeof t2 !== "object") { - return t1; - } else { - return bal(t1, min_elt(t2), remove_min_elt(t2)); - } - }; - let concat = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } else if (typeof t2 !== "object") { - return t1; - } else { - return join(t1, min_elt(t2), remove_min_elt(t2)); - } - }; - let split = (x, param) => { - if (typeof param !== "object") { - return [ - "Empty", - false, - "Empty" - ]; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - return [ - l, - true, - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, match$1[0]), - match$1[1], - match$1[2] - ]; - }; - let is_empty = param => { - if (typeof param !== "object") { - return true; - } else { - return false; - } - }; - let mem = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = Ord.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let remove = (x, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - return merge(l, r); - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } - }; - let union = (s1, s2) => { - if (typeof s1 !== "object") { - return s2; - } - let h1 = s1.h; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let h2 = s2.h; - let v2 = s2.v; - if (h1 >= h2) { - if (h2 === 1) { - return add(v2, s1); - } - let match = split(v1, s2); - return join(union(s1.l, match[0]), v1, union(s1.r, match[2])); - } - if (h1 === 1) { - return add(v1, s2); - } - let match$1 = split(v2, s1); - return join(union(match$1[0], s2.l), v2, union(match$1[2], s2.r)); - }; - let inter = (s1, s2) => { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return "Empty"; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return join(inter(l1, l2), v1, inter(r1, match[2])); - } else { - return concat(inter(l1, l2), inter(r1, match[2])); - } - }; - let diff = (s1, s2) => { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return s1; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return concat(diff(l1, l2), diff(r1, match[2])); - } else { - return join(diff(l1, l2), v1, diff(r1, match[2])); - } - }; - let cons_enum = (_s, _e) => { - while (true) { - let e = _e; - let s = _s; - if (typeof s !== "object") { - return e; - } - _e = { - TAG: "More", - _0: s.v, - _1: s.r, - _2: e - }; - _s = s.l; - continue; - }; - }; - let compare_aux = (_e1, _e2) => { - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = Ord.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - _e2 = cons_enum(e2._1, e2._2); - _e1 = cons_enum(e1._1, e1._2); - continue; - }; - }; - let compare = (s1, s2) => compare_aux(cons_enum(s1, "End"), cons_enum(s2, "End")); - let equal = (s1, s2) => compare(s1, s2) === 0; - let subset = (_s1, _s2) => { - while (true) { - let s2 = _s2; - let s1 = _s1; - if (typeof s1 !== "object") { - return true; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - if (typeof s2 !== "object") { - return false; - } - let r2 = s2.r; - let l2 = s2.l; - let c = Ord.compare(v1, s2.v); - if (c === 0) { - if (!subset(l1, l2)) { - return false; - } - _s2 = r2; - _s1 = r1; - continue; - } - if (c < 0) { - if (!subset({ - TAG: "Node", - l: l1, - v: v1, - r: "Empty", - h: 0 - }, l2)) { - return false; - } - _s1 = r1; - continue; - } - if (!subset({ - TAG: "Node", - l: "Empty", - v: v1, - r: r1, - h: 0 - }, r2)) { - return false; - } - _s1 = l1; - continue; - }; - }; - let iter = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v); - _param = param.r; - continue; - }; - }; - let fold = (f, _s, _accu) => { - while (true) { - let accu = _accu; - let s = _s; - if (typeof s !== "object") { - return accu; - } - _accu = f(s.v, fold(f, s.l, accu)); - _s = s.r; - continue; - }; - }; - let for_all = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; - }; - let exists = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; - }; - let filter = (p, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pv = p(v); - let r$p = filter(p, r); - if (pv) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, r$p); - } - } else { - return concat(l$p, r$p); - } - }; - let partition = (p, param) => { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pv = p(v); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pv) { - return [ - join(lt, v, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, rf) - ]; - } - }; - let cardinal = param => { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } - }; - let elements_aux = (_accu, _param) => { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: param.v, - tl: elements_aux(accu, param.r) - }; - continue; - }; - }; - let elements = s => elements_aux(/* [] */0, s); - let find = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - let c = Ord.compare(x, v); - if (c === 0) { - return v; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let find_first_aux = (_v0, f, _param) => { - while (true) { - let param = _param; - let v0 = _v0; - if (typeof param !== "object") { - return v0; - } - let v = param.v; - if (f(v)) { - _param = param.l; - _v0 = v; - continue; - } - _param = param.r; - continue; - }; - }; - let find_first = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - return find_first_aux(v, f, param.l); - } - _param = param.r; - continue; - }; - }; - let find_first_opt_aux = (_v0, f, _param) => { - while (true) { - let param = _param; - let v0 = _v0; - if (typeof param !== "object") { - return Caml_option.some(v0); - } - let v = param.v; - if (f(v)) { - _param = param.l; - _v0 = v; - continue; - } - _param = param.r; - continue; - }; - }; - let find_first_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - return find_first_opt_aux(v, f, param.l); - } - _param = param.r; - continue; - }; - }; - let find_last_aux = (_v0, f, _param) => { - while (true) { - let param = _param; - let v0 = _v0; - if (typeof param !== "object") { - return v0; - } - let v = param.v; - if (f(v)) { - _param = param.r; - _v0 = v; - continue; - } - _param = param.l; - continue; - }; - }; - let find_last = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - return find_last_aux(v, f, param.r); - } - _param = param.l; - continue; - }; - }; - let find_last_opt_aux = (_v0, f, _param) => { - while (true) { - let param = _param; - let v0 = _v0; - if (typeof param !== "object") { - return Caml_option.some(v0); - } - let v = param.v; - if (f(v)) { - _param = param.r; - _v0 = v; - continue; - } - _param = param.l; - continue; - }; - }; - let find_last_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - return find_last_opt_aux(v, f, param.r); - } - _param = param.l; - continue; - }; - }; - let find_opt = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - let c = Ord.compare(x, v); - if (c === 0) { - return Caml_option.some(v); - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let try_join = (l, v, r) => { - if ((l === "Empty" || Ord.compare(max_elt(l), v) < 0) && (r === "Empty" || Ord.compare(v, min_elt(r)) < 0)) { - return join(l, v, r); - } else { - return union(l, add(v, r)); - } - }; - let map = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = map(f, l); - let v$p = f(v); - let r$p = map(f, r); - if (l === l$p && v === v$p && r === r$p) { - return param; - } else { - return try_join(l$p, v$p, r$p); - } - }; - let of_sorted_list = l => { - let sub = (n, l) => { - switch (n) { - case 0 : - return [ - "Empty", - l - ]; - case 1 : - if (l) { - return [ - { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - l.tl - ]; - } - break; - case 2 : - if (l) { - let match = l.tl; - if (match) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match.hd, - r: "Empty", - h: 2 - }, - match.tl - ]; - } - - } - break; - case 3 : - if (l) { - let match$1 = l.tl; - if (match$1) { - let match$2 = match$1.tl; - if (match$2) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match$1.hd, - r: { - TAG: "Node", - l: "Empty", - v: match$2.hd, - r: "Empty", - h: 1 - }, - h: 2 - }, - match$2.tl - ]; - } - - } - - } - break; - } - let nl = n / 2 | 0; - let match$3 = sub(nl, l); - let l$1 = match$3[1]; - if (l$1) { - let match$4 = sub((n - nl | 0) - 1 | 0, l$1.tl); - return [ - create(match$3[0], l$1.hd, match$4[0]), - match$4[1] - ]; - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "setLabels.res", - 691, - 20 - ], - Error: new Error() - }; - }; - return sub(List.length(l), l)[0]; - }; - let of_list = l => { - if (!l) { - return "Empty"; - } - let match = l.tl; - let x0 = l.hd; - if (!match) { - return singleton(x0); - } - let match$1 = match.tl; - let x1 = match.hd; - if (!match$1) { - return add(x1, singleton(x0)); - } - let match$2 = match$1.tl; - let x2 = match$1.hd; - if (!match$2) { - return add(x2, add(x1, singleton(x0))); - } - let match$3 = match$2.tl; - let x3 = match$2.hd; - if (match$3) { - if (match$3.tl) { - return of_sorted_list(List.sort_uniq(Ord.compare, l)); - } else { - return add(match$3.hd, add(x3, add(x2, add(x1, singleton(x0))))); - } - } else { - return add(x3, add(x2, add(x1, singleton(x0)))); - } - }; - return { - height: height, - create: create, - bal: bal, - add: add, - singleton: singleton, - add_min_element: add_min_element, - add_max_element: add_max_element, - join: join, - min_elt: min_elt, - min_elt_opt: min_elt_opt, - max_elt: max_elt, - max_elt_opt: max_elt_opt, - remove_min_elt: remove_min_elt, - merge: merge, - concat: concat, - split: split, - empty: "Empty", - is_empty: is_empty, - mem: mem, - remove: remove, - union: union, - inter: inter, - diff: diff, - cons_enum: cons_enum, - compare_aux: compare_aux, - compare: compare, - equal: equal, - subset: subset, - iter: iter, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - elements_aux: elements_aux, - elements: elements, - choose: min_elt, - choose_opt: min_elt_opt, - find: find, - find_first_aux: find_first_aux, - find_first: find_first, - find_first_opt_aux: find_first_opt_aux, - find_first_opt: find_first_opt, - find_last_aux: find_last_aux, - find_last: find_last, - find_last_opt_aux: find_last_opt_aux, - find_last_opt: find_last_opt, - find_opt: find_opt, - try_join: try_join, - map: map, - of_sorted_list: of_sorted_list, - of_list: of_list - }; -} - -export { - Make, -} -/* No side effect */ diff --git a/lib/es6/sort.js b/lib/es6/sort.js deleted file mode 100644 index cc9d550760..0000000000 --- a/lib/es6/sort.js +++ /dev/null @@ -1,167 +0,0 @@ - - - -function merge(order, l1, l2) { - if (!l1) { - return l2; - } - if (!l2) { - return l1; - } - let h2 = l2.hd; - let h1 = l1.hd; - if (order(h1, h2)) { - return { - hd: h1, - tl: merge(order, l1.tl, l2) - }; - } else { - return { - hd: h2, - tl: merge(order, l1, l2.tl) - }; - } -} - -function list(order, l) { - let initlist = param => { - if (!param) { - return /* [] */0; - } - let match = param.tl; - let e = param.hd; - if (!match) { - return { - hd: { - hd: e, - tl: /* [] */0 - }, - tl: /* [] */0 - }; - } - let e2 = match.hd; - return { - hd: order(e, e2) ? ({ - hd: e, - tl: { - hd: e2, - tl: /* [] */0 - } - }) : ({ - hd: e2, - tl: { - hd: e, - tl: /* [] */0 - } - }), - tl: initlist(match.tl) - }; - }; - let merge2 = param => { - if (!param) { - return param; - } - let match = param.tl; - if (match) { - return { - hd: merge(order, param.hd, match.hd), - tl: merge2(match.tl) - }; - } else { - return param; - } - }; - let _param = initlist(l); - while (true) { - let param = _param; - if (!param) { - return /* [] */0; - } - if (!param.tl) { - return param.hd; - } - _param = merge2(param); - continue; - }; -} - -function swap(arr, i, j) { - let tmp = arr[i]; - arr[i] = arr[j]; - arr[j] = tmp; -} - -function array(cmp, arr) { - let qsort = (_lo, _hi) => { - while (true) { - let hi = _hi; - let lo = _lo; - if ((hi - lo | 0) < 6) { - return; - } - let mid = ((lo + hi | 0) >>> 1); - if (cmp(arr[mid], arr[lo])) { - swap(arr, mid, lo); - } - if (cmp(arr[hi], arr[mid])) { - swap(arr, mid, hi); - if (cmp(arr[mid], arr[lo])) { - swap(arr, mid, lo); - } - - } - let pivot = arr[mid]; - let i = lo + 1 | 0; - let j = hi - 1 | 0; - if (!cmp(pivot, arr[hi]) || !cmp(arr[lo], pivot)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Sort.array", - Error: new Error() - }; - } - while (i < j) { - while (!cmp(pivot, arr[i])) { - i = i + 1 | 0; - }; - while (!cmp(arr[j], pivot)) { - j = j - 1 | 0; - }; - if (i < j) { - swap(arr, i, j); - } - i = i + 1 | 0; - j = j - 1 | 0; - }; - if ((j - lo | 0) <= (hi - i | 0)) { - qsort(lo, j); - _lo = i; - continue; - } - qsort(i, hi); - _hi = j; - continue; - }; - }; - qsort(0, arr.length - 1 | 0); - for (let i = 1, i_finish = arr.length; i < i_finish; ++i) { - let val_i = arr[i]; - if (!cmp(arr[i - 1 | 0], val_i)) { - arr[i] = arr[i - 1 | 0]; - let j = i - 1 | 0; - while (j >= 1 && !cmp(arr[j - 1 | 0], val_i)) { - arr[j] = arr[j - 1 | 0]; - j = j - 1 | 0; - }; - arr[j] = val_i; - } - - } -} - -export { - list, - array, - merge, -} -/* No side effect */ diff --git a/lib/es6/stack.js b/lib/es6/stack.js deleted file mode 100644 index 2ae12c6064..0000000000 --- a/lib/es6/stack.js +++ /dev/null @@ -1,88 +0,0 @@ - - -import * as List from "./list.js"; -import * as Caml_exceptions from "./caml_exceptions.js"; - -let Empty = /* @__PURE__ */Caml_exceptions.create("Stack.Empty"); - -function create() { - return { - c: /* [] */0, - len: 0 - }; -} - -function clear(s) { - s.c = /* [] */0; - s.len = 0; -} - -function copy(s) { - return { - c: s.c, - len: s.len - }; -} - -function push(x, s) { - s.c = { - hd: x, - tl: s.c - }; - s.len = s.len + 1 | 0; -} - -function pop(s) { - let match = s.c; - if (match) { - s.c = match.tl; - s.len = s.len - 1 | 0; - return match.hd; - } - throw { - RE_EXN_ID: Empty, - Error: new Error() - }; -} - -function top(s) { - let match = s.c; - if (match) { - return match.hd; - } - throw { - RE_EXN_ID: Empty, - Error: new Error() - }; -} - -function is_empty(s) { - return s.c === /* [] */0; -} - -function length(s) { - return s.len; -} - -function iter(f, s) { - List.iter(f, s.c); -} - -function fold(f, acc, s) { - return List.fold_left(f, acc, s.c); -} - -export { - Empty, - create, - push, - pop, - top, - clear, - copy, - is_empty, - length, - iter, - fold, -} -/* No side effect */ diff --git a/lib/es6/stdLabels.js b/lib/es6/stdLabels.js deleted file mode 100644 index 0c1119f91d..0000000000 --- a/lib/es6/stdLabels.js +++ /dev/null @@ -1,18 +0,0 @@ - - - -let $$Array; - -let Bytes; - -let List; - -let $$String; - -export { - $$Array, - Bytes, - List, - $$String, -} -/* No side effect */ diff --git a/lib/es6/stream.js b/lib/es6/stream.js deleted file mode 100644 index 6e0c953032..0000000000 --- a/lib/es6/stream.js +++ /dev/null @@ -1,471 +0,0 @@ - - -import * as List from "./list.js"; -import * as Caml_bytes from "./caml_bytes.js"; -import * as Caml_option from "./caml_option.js"; -import * as Caml_string from "./caml_string.js"; -import * as Caml_exceptions from "./caml_exceptions.js"; -import * as CamlinternalLazy from "./camlinternalLazy.js"; - -let Failure = /* @__PURE__ */Caml_exceptions.create("Stream.Failure"); - -let $$Error = /* @__PURE__ */Caml_exceptions.create("Stream.Error"); - -function count(param) { - if (param !== undefined) { - return param.count; - } else { - return 0; - } -} - -function data(param) { - if (param !== undefined) { - return param.data; - } else { - return "Sempty"; - } -} - -function get_data(count, _d) { - while (true) { - let d = _d; - if (typeof d !== "object") { - return d; - } - switch (d.TAG) { - case "Scons" : - return d; - case "Sapp" : - let d2 = d._1; - let match = get_data(count, d._0); - if (typeof match !== "object") { - _d = d2; - continue; - } - if (match.TAG === "Scons") { - return { - TAG: "Scons", - _0: match._0, - _1: { - TAG: "Sapp", - _0: match._1, - _1: d2 - } - }; - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "stream.res", - 53, - 13 - ], - Error: new Error() - }; - case "Slazy" : - _d = CamlinternalLazy.force(d._0); - continue; - case "Sgen" : - let g = d._0; - let match$1 = g.curr; - if (match$1 !== undefined) { - let a = Caml_option.valFromOption(match$1); - if (a !== undefined) { - g.curr = undefined; - return { - TAG: "Scons", - _0: Caml_option.valFromOption(a), - _1: d - }; - } else { - return "Sempty"; - } - } - let a$1 = g.func(count); - if (a$1 !== undefined) { - return { - TAG: "Scons", - _0: Caml_option.valFromOption(a$1), - _1: d - }; - } else { - g.curr = Caml_option.some(undefined); - return "Sempty"; - } - } - }; -} - -function peek_data(s) { - while (true) { - let f = s.data; - if (typeof f !== "object") { - return; - } - switch (f.TAG) { - case "Scons" : - return Caml_option.some(f._0); - case "Sapp" : - let d = get_data(s.count, s.data); - if (typeof d !== "object") { - return; - } - if (d.TAG === "Scons") { - s.data = d; - return Caml_option.some(d._0); - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "stream.res", - 83, - 13 - ], - Error: new Error() - }; - case "Slazy" : - s.data = CamlinternalLazy.force(f._0); - continue; - case "Sgen" : - let g = f._0; - let a = g.curr; - if (a !== undefined) { - return Caml_option.valFromOption(a); - } - let x = g.func(s.count); - g.curr = Caml_option.some(x); - return x; - } - }; -} - -function peek(param) { - if (param !== undefined) { - return peek_data(param); - } - -} - -function junk_data(s) { - while (true) { - let g = s.data; - if (typeof g === "object") { - switch (g.TAG) { - case "Scons" : - s.count = s.count + 1 | 0; - s.data = g._1; - return; - case "Sgen" : - let g$1 = g._0; - let match = g$1.curr; - if (match !== undefined) { - s.count = s.count + 1 | 0; - g$1.curr = undefined; - return; - } - break; - } - } - let match$1 = peek_data(s); - if (match$1 === undefined) { - return; - } - continue; - }; -} - -function junk(param) { - if (param !== undefined) { - return junk_data(param); - } - -} - -function nget_data(n, s) { - if (n <= 0) { - return [ - /* [] */0, - s.data, - 0 - ]; - } - let a = peek_data(s); - if (a === undefined) { - return [ - /* [] */0, - s.data, - 0 - ]; - } - let a$1 = Caml_option.valFromOption(a); - junk_data(s); - let match = nget_data(n - 1 | 0, s); - return [ - { - hd: a$1, - tl: match[0] - }, - { - TAG: "Scons", - _0: a$1, - _1: match[1] - }, - match[2] + 1 | 0 - ]; -} - -function npeek(n, param) { - if (param !== undefined) { - let match = nget_data(n, param); - param.count = param.count - match[2] | 0; - param.data = match[1]; - return match[0]; - } else { - return /* [] */0; - } -} - -function next(s) { - let a = peek(s); - if (a !== undefined) { - junk(s); - return Caml_option.valFromOption(a); - } - throw { - RE_EXN_ID: Failure, - Error: new Error() - }; -} - -function empty(s) { - let match = peek(s); - if (match === undefined) { - return; - } - throw { - RE_EXN_ID: Failure, - Error: new Error() - }; -} - -function iter(f, strm) { - let do_rec = () => { - while (true) { - let a = peek(strm); - if (a === undefined) { - return; - } - junk(strm); - f(Caml_option.valFromOption(a)); - continue; - }; - }; - do_rec(); -} - -function from(f) { - return { - count: 0, - data: { - TAG: "Sgen", - _0: { - curr: undefined, - func: f - } - } - }; -} - -function of_list(l) { - return { - count: 0, - data: List.fold_right((x, l) => ({ - TAG: "Scons", - _0: x, - _1: l - }), l, "Sempty") - }; -} - -function of_string(s) { - let count = { - contents: 0 - }; - return from(param => { - let c = count.contents; - if (c < s.length) { - count.contents = count.contents + 1 | 0; - return Caml_string.get(s, c); - } - - }); -} - -function of_bytes(s) { - let count = { - contents: 0 - }; - return from(param => { - let c = count.contents; - if (c < s.length) { - count.contents = count.contents + 1 | 0; - return Caml_bytes.get(s, c); - } - - }); -} - -function iapp(i, s) { - return { - count: 0, - data: { - TAG: "Sapp", - _0: data(i), - _1: data(s) - } - }; -} - -function icons(i, s) { - return { - count: 0, - data: { - TAG: "Scons", - _0: i, - _1: data(s) - } - }; -} - -function ising(i) { - return { - count: 0, - data: { - TAG: "Scons", - _0: i, - _1: "Sempty" - } - }; -} - -function lapp(f, s) { - let f$1 = () => ({ - TAG: "Sapp", - _0: data(f()), - _1: data(s) - }); - return { - count: 0, - data: { - TAG: "Slazy", - _0: CamlinternalLazy.from_fun(() => f$1()) - } - }; -} - -function lcons(f, s) { - let f$1 = () => ({ - TAG: "Scons", - _0: f(), - _1: data(s) - }); - return { - count: 0, - data: { - TAG: "Slazy", - _0: CamlinternalLazy.from_fun(() => f$1()) - } - }; -} - -function lsing(f) { - return { - count: 0, - data: { - TAG: "Slazy", - _0: CamlinternalLazy.from_fun(() => ({ - TAG: "Scons", - _0: f(), - _1: "Sempty" - })) - } - }; -} - -function slazy(f) { - return { - count: 0, - data: { - TAG: "Slazy", - _0: CamlinternalLazy.from_fun(() => data(f())) - } - }; -} - -function dump_data(f, param) { - if (typeof param !== "object") { - console.log("Sempty"); - return; - } - switch (param.TAG) { - case "Scons" : - console.log("Scons ("); - f(param._0); - console.log(", "); - dump_data(f, param._1); - console.log(")"); - return; - case "Sapp" : - console.log("Sapp ("); - dump_data(f, param._0); - console.log(", "); - dump_data(f, param._1); - console.log(")"); - return; - case "Slazy" : - console.log("Slazy"); - return; - case "Sgen" : - console.log("Sgen"); - return; - } -} - -function dump(f, s) { - console.log("{count = "); - let i = count(s); - console.log(String(i)); - console.log("; data = "); - dump_data(f, data(s)); - console.log("}"); - console.log(""); -} - -let sempty; - -export { - Failure, - $$Error, - from, - of_list, - of_string, - of_bytes, - iter, - next, - empty, - peek, - junk, - count, - npeek, - iapp, - icons, - ising, - lapp, - lcons, - lsing, - sempty, - slazy, - dump, -} -/* No side effect */ diff --git a/lib/es6/string.js b/lib/es6/string.js index 55e9b890cc..9f8621b6ae 100644 --- a/lib/es6/string.js +++ b/lib/es6/string.js @@ -1,23 +1,50 @@ -import * as Caml from "./caml.js"; +import * as Char from "./char.js"; import * as $$Array from "./array.js"; -import * as Bytes from "./bytes.js"; -import * as Caml_string from "./caml_string.js"; -import * as Caml_js_exceptions from "./caml_js_exceptions.js"; +import * as Primitive_exceptions from "./primitive_exceptions.js"; -function init(n, f) { - return Bytes.unsafe_to_string(Bytes.init(n, f)); -} - -function sub(s, ofs, len) { - return Bytes.unsafe_to_string(Bytes.sub(Bytes.unsafe_of_string(s), ofs, len)); +function apply1(f, bytes) { + if (bytes.length === 0) { + return bytes; + } + let r = bytes.slice(); + r[0] = f(bytes[0]); + return r; } function concat(sep, xs) { return $$Array.of_list(xs).join(sep); } +function length(prim) { + return prim.length; +} + +function get(prim0, prim1) { + return prim0.codePointAt(prim1); +} + +function unsafe_get(prim0, prim1) { + return prim0.codePointAt(prim1); +} + +function bos(str) { + return $$Array.map(str => str.codePointAt(0), Array.from(str)); +} + +function make(len, ch) { + return String.fromCodePoint(ch).repeat(len); +} + +function init(len, f) { + return $$Array.init(len, i => String.fromCodePoint(f(i))).join(""); +} + +function sub(s, ofs, len) { + return String.fromCodePoint(...$$Array.sub(bos(s), ofs, len)); +} + function iter(f, s) { for (let i = 0, i_finish = s.length; i < i_finish; ++i) { f(s.codePointAt(i)); @@ -31,27 +58,11 @@ function iteri(f, s) { } function map(f, s) { - return Bytes.unsafe_to_string(Bytes.map(f, Bytes.unsafe_of_string(s))); + return String.fromCodePoint(...$$Array.map(f, bos(s))); } function mapi(f, s) { - return Bytes.unsafe_to_string(Bytes.mapi(f, Bytes.unsafe_of_string(s))); -} - -function is_space(param) { - if (param > 13 || param < 9) { - return param === 32; - } else { - return param !== 11; - } -} - -function trim(s) { - if (s === "" || !(is_space(s.codePointAt(0)) || is_space(s.codePointAt(s.length - 1 | 0)))) { - return s; - } else { - return Bytes.unsafe_to_string(Bytes.trim(Bytes.unsafe_of_string(s))); - } + return String.fromCodePoint(...$$Array.mapi(f, bos(s))); } function escaped(s) { @@ -79,11 +90,11 @@ function escaped(s) { continue; }; }; - if (needs_escape(0)) { - return Bytes.unsafe_to_string(Bytes.escaped(Bytes.unsafe_of_string(s))); - } else { + if (!needs_escape(0)) { return s; } + let bytes = bos(s); + return $$Array.map(Char.escaped, bytes).join(""); } function index_rec(s, lim, _i, c) { @@ -223,7 +234,7 @@ function contains_from(s, i, c) { index_rec(s, l, i, c); return true; } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + let exn = Primitive_exceptions.internalToException(raw_exn); if (exn.RE_EXN_ID === "Not_found") { return false; } @@ -247,7 +258,7 @@ function rcontains_from(s, i, c) { rindex_rec(s, i, c); return true; } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + let exn = Primitive_exceptions.internalToException(raw_exn); if (exn.RE_EXN_ID === "Not_found") { return false; } @@ -256,25 +267,23 @@ function rcontains_from(s, i, c) { } function uppercase_ascii(s) { - return Bytes.unsafe_to_string(Bytes.uppercase_ascii(Bytes.unsafe_of_string(s))); + let bytes = bos(s); + return String.fromCodePoint(...$$Array.map(Char.uppercase_ascii, bytes)); } function lowercase_ascii(s) { - return Bytes.unsafe_to_string(Bytes.lowercase_ascii(Bytes.unsafe_of_string(s))); + let bytes = bos(s); + return String.fromCodePoint(...$$Array.map(Char.lowercase_ascii, bytes)); } function capitalize_ascii(s) { - return Bytes.unsafe_to_string(Bytes.capitalize_ascii(Bytes.unsafe_of_string(s))); + let bytes = bos(s); + return String.fromCodePoint(...apply1(Char.uppercase_ascii, bytes)); } function uncapitalize_ascii(s) { - return Bytes.unsafe_to_string(Bytes.uncapitalize_ascii(Bytes.unsafe_of_string(s))); -} - -let compare = Caml.string_compare; - -function equal(a, b) { - return a === b; + let bytes = bos(s); + return String.fromCodePoint(...apply1(Char.lowercase_ascii, bytes)); } function split_on_char(sep, s) { @@ -296,21 +305,17 @@ function split_on_char(sep, s) { }; } -let make = Caml_string.make; - -let blit = Bytes.blit_string; - export { + length, + get, make, init, sub, - blit, concat, iter, iteri, map, mapi, - trim, escaped, index, index_opt, @@ -327,8 +332,7 @@ export { lowercase_ascii, capitalize_ascii, uncapitalize_ascii, - compare, - equal, split_on_char, + unsafe_get, } /* No side effect */ diff --git a/lib/es6/stringLabels.js b/lib/es6/stringLabels.js deleted file mode 100644 index 789a8ff622..0000000000 --- a/lib/es6/stringLabels.js +++ /dev/null @@ -1,334 +0,0 @@ - - -import * as Caml from "./caml.js"; -import * as $$Array from "./array.js"; -import * as Bytes from "./bytes.js"; -import * as Caml_string from "./caml_string.js"; -import * as Caml_js_exceptions from "./caml_js_exceptions.js"; - -function init(n, f) { - return Bytes.unsafe_to_string(Bytes.init(n, f)); -} - -function sub(s, ofs, len) { - return Bytes.unsafe_to_string(Bytes.sub(Bytes.unsafe_of_string(s), ofs, len)); -} - -let blit = Bytes.blit_string; - -function concat(sep, xs) { - return $$Array.of_list(xs).join(sep); -} - -function iter(f, s) { - for (let i = 0, i_finish = s.length; i < i_finish; ++i) { - f(s.codePointAt(i)); - } -} - -function iteri(f, s) { - for (let i = 0, i_finish = s.length; i < i_finish; ++i) { - f(i, s.codePointAt(i)); - } -} - -function map(f, s) { - return Bytes.unsafe_to_string(Bytes.map(f, Bytes.unsafe_of_string(s))); -} - -function mapi(f, s) { - return Bytes.unsafe_to_string(Bytes.mapi(f, Bytes.unsafe_of_string(s))); -} - -function is_space(param) { - if (param > 13 || param < 9) { - return param === 32; - } else { - return param !== 11; - } -} - -function trim(s) { - if (s === "" || !(is_space(s.codePointAt(0)) || is_space(s.codePointAt(s.length - 1 | 0)))) { - return s; - } else { - return Bytes.unsafe_to_string(Bytes.trim(Bytes.unsafe_of_string(s))); - } -} - -function escaped(s) { - let needs_escape = _i => { - while (true) { - let i = _i; - if (i >= s.length) { - return false; - } - let match = s.codePointAt(i); - if (match < 32) { - return true; - } - if (match > 92 || match < 34) { - if (match >= 127) { - return true; - } - _i = i + 1 | 0; - continue; - } - if (match > 91 || match < 35) { - return true; - } - _i = i + 1 | 0; - continue; - }; - }; - if (needs_escape(0)) { - return Bytes.unsafe_to_string(Bytes.escaped(Bytes.unsafe_of_string(s))); - } else { - return s; - } -} - -function index_rec(s, lim, _i, c) { - while (true) { - let i = _i; - if (i >= lim) { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - if (s.codePointAt(i) === c) { - return i; - } - _i = i + 1 | 0; - continue; - }; -} - -function index(s, c) { - return index_rec(s, s.length, 0, c); -} - -function index_rec_opt(s, lim, _i, c) { - while (true) { - let i = _i; - if (i >= lim) { - return; - } - if (s.codePointAt(i) === c) { - return i; - } - _i = i + 1 | 0; - continue; - }; -} - -function index_opt(s, c) { - return index_rec_opt(s, s.length, 0, c); -} - -function index_from(s, i, c) { - let l = s.length; - if (i < 0 || i > l) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from / Bytes.index_from", - Error: new Error() - }; - } - return index_rec(s, l, i, c); -} - -function index_from_opt(s, i, c) { - let l = s.length; - if (i < 0 || i > l) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from_opt / Bytes.index_from_opt", - Error: new Error() - }; - } - return index_rec_opt(s, l, i, c); -} - -function rindex_rec(s, _i, c) { - while (true) { - let i = _i; - if (i < 0) { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - if (s.codePointAt(i) === c) { - return i; - } - _i = i - 1 | 0; - continue; - }; -} - -function rindex(s, c) { - return rindex_rec(s, s.length - 1 | 0, c); -} - -function rindex_from(s, i, c) { - if (i < -1 || i >= s.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from / Bytes.rindex_from", - Error: new Error() - }; - } - return rindex_rec(s, i, c); -} - -function rindex_rec_opt(s, _i, c) { - while (true) { - let i = _i; - if (i < 0) { - return; - } - if (s.codePointAt(i) === c) { - return i; - } - _i = i - 1 | 0; - continue; - }; -} - -function rindex_opt(s, c) { - return rindex_rec_opt(s, s.length - 1 | 0, c); -} - -function rindex_from_opt(s, i, c) { - if (i < -1 || i >= s.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from_opt / Bytes.rindex_from_opt", - Error: new Error() - }; - } - return rindex_rec_opt(s, i, c); -} - -function contains_from(s, i, c) { - let l = s.length; - if (i < 0 || i > l) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.contains_from / Bytes.contains_from", - Error: new Error() - }; - } - try { - index_rec(s, l, i, c); - return true; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - return false; - } - throw exn; - } -} - -function contains(s, c) { - return contains_from(s, 0, c); -} - -function rcontains_from(s, i, c) { - if (i < 0 || i >= s.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.rcontains_from / Bytes.rcontains_from", - Error: new Error() - }; - } - try { - rindex_rec(s, i, c); - return true; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - return false; - } - throw exn; - } -} - -function uppercase_ascii(s) { - return Bytes.unsafe_to_string(Bytes.uppercase_ascii(Bytes.unsafe_of_string(s))); -} - -function lowercase_ascii(s) { - return Bytes.unsafe_to_string(Bytes.lowercase_ascii(Bytes.unsafe_of_string(s))); -} - -function capitalize_ascii(s) { - return Bytes.unsafe_to_string(Bytes.capitalize_ascii(Bytes.unsafe_of_string(s))); -} - -function uncapitalize_ascii(s) { - return Bytes.unsafe_to_string(Bytes.uncapitalize_ascii(Bytes.unsafe_of_string(s))); -} - -let compare = Caml.string_compare; - -function equal(a, b) { - return a === b; -} - -function split_on_char(sep, s) { - let r = /* [] */0; - let j = s.length; - for (let i = s.length - 1 | 0; i >= 0; --i) { - if (s.codePointAt(i) === sep) { - r = { - hd: sub(s, i + 1 | 0, (j - i | 0) - 1 | 0), - tl: r - }; - j = i; - } - - } - return { - hd: sub(s, 0, j), - tl: r - }; -} - -let make = Caml_string.make; - -export { - make, - init, - sub, - blit, - concat, - iter, - iteri, - map, - mapi, - trim, - escaped, - index, - index_opt, - rindex, - rindex_opt, - index_from, - index_from_opt, - rindex_from, - rindex_from_opt, - contains, - contains_from, - rcontains_from, - uppercase_ascii, - lowercase_ascii, - capitalize_ascii, - uncapitalize_ascii, - compare, - equal, - split_on_char, -} -/* No side effect */ diff --git a/lib/es6/sys.js b/lib/es6/sys.js deleted file mode 100644 index 1ded50c6ab..0000000000 --- a/lib/es6/sys.js +++ /dev/null @@ -1,183 +0,0 @@ - - -import * as Caml_sys from "./caml_sys.js"; -import * as Caml_exceptions from "./caml_exceptions.js"; - -let match = Caml_sys.sys_get_argv(); - -let os_type = Caml_sys.os_type(); - -let backend_type = { - TAG: "Other", - _0: "BS" -}; - -let big_endian = false; - -let unix = Caml_sys.os_type() === "Unix"; - -let win32 = Caml_sys.os_type() === "Win32"; - -function getenv_opt(s) { - let x = typeof process === "undefined" ? undefined : process; - if (x !== undefined) { - return x.env[s]; - } - -} - -function command(param) { - return 127; -} - -let interactive = { - contents: false -}; - -function signal(param, param$1) { - return "Signal_default"; -} - -function set_signal(sig_num, sig_beh) { - -} - -let Break = /* @__PURE__ */Caml_exceptions.create("Sys.Break"); - -function catch_break(on) { - -} - -function enable_runtime_warnings(param) { - -} - -function runtime_warnings_enabled() { - return false; -} - -let argv = match[1]; - -let executable_name = match[0]; - -let cygwin = false; - -let word_size = 32; - -let int_size = 32; - -let max_string_length = 2147483647; - -let max_array_length = 2147483647; - -let sigabrt = -1; - -let sigalrm = -2; - -let sigfpe = -3; - -let sighup = -4; - -let sigill = -5; - -let sigint = -6; - -let sigkill = -7; - -let sigpipe = -8; - -let sigquit = -9; - -let sigsegv = -10; - -let sigterm = -11; - -let sigusr1 = -12; - -let sigusr2 = -13; - -let sigchld = -14; - -let sigcont = -15; - -let sigstop = -16; - -let sigtstp = -17; - -let sigttin = -18; - -let sigttou = -19; - -let sigvtalrm = -20; - -let sigprof = -21; - -let sigbus = -22; - -let sigpoll = -23; - -let sigsys = -24; - -let sigtrap = -25; - -let sigurg = -26; - -let sigxcpu = -27; - -let sigxfsz = -28; - -let ocaml_version = "4.06.2+BS"; - -export { - argv, - executable_name, - getenv_opt, - command, - interactive, - os_type, - backend_type, - unix, - win32, - cygwin, - word_size, - int_size, - big_endian, - max_string_length, - max_array_length, - signal, - set_signal, - sigabrt, - sigalrm, - sigfpe, - sighup, - sigill, - sigint, - sigkill, - sigpipe, - sigquit, - sigsegv, - sigterm, - sigusr1, - sigusr2, - sigchld, - sigcont, - sigstop, - sigtstp, - sigttin, - sigttou, - sigvtalrm, - sigprof, - sigbus, - sigpoll, - sigsys, - sigtrap, - sigurg, - sigxcpu, - sigxfsz, - Break, - catch_break, - ocaml_version, - enable_runtime_warnings, - runtime_warnings_enabled, -} -/* No side effect */ diff --git a/lib/es6/uchar.js b/lib/es6/uchar.js deleted file mode 100644 index 8ffb9e2054..0000000000 --- a/lib/es6/uchar.js +++ /dev/null @@ -1,133 +0,0 @@ - - -import * as Caml from "./caml.js"; -import * as Caml_format from "./caml_format.js"; - -function err_not_sv(i) { - return Caml_format.format_int("%X", i) + " is not an Unicode scalar value"; -} - -function err_not_latin1(u) { - return "U+" + (Caml_format.format_int("%04X", u) + " is not a latin1 character"); -} - -function succ(u) { - if (u === 55295) { - return 57344; - } - if (u === 1114111) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "U+10FFFF has no successor", - Error: new Error() - }; - } - return u + 1 | 0; -} - -function pred(u) { - if (u === 57344) { - return 55295; - } - if (u === 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "U+0000 has no predecessor", - Error: new Error() - }; - } - return u - 1 | 0; -} - -function is_valid(i) { - if (0 <= i && i <= 55295) { - return true; - } else if (57344 <= i) { - return i <= 1114111; - } else { - return false; - } -} - -function of_int(i) { - if (is_valid(i)) { - return i; - } - let s = err_not_sv(i); - throw { - RE_EXN_ID: "Invalid_argument", - _1: s, - Error: new Error() - }; -} - -function is_char(u) { - return u < 256; -} - -function of_char(c) { - return c; -} - -function to_char(u) { - if (u <= 255) { - return u; - } - let s = err_not_latin1(u); - throw { - RE_EXN_ID: "Invalid_argument", - _1: s, - Error: new Error() - }; -} - -function unsafe_to_char(prim) { - return prim; -} - -function equal(prim0, prim1) { - return prim0 === prim1; -} - -let compare = Caml.int_compare; - -function hash(prim) { - return prim; -} - -let min = 0; - -let max = 1114111; - -let bom = 65279; - -let rep = 65533; - -function unsafe_of_int(prim) { - return prim; -} - -function to_int(prim) { - return prim; -} - -export { - min, - max, - bom, - rep, - succ, - pred, - is_valid, - of_int, - unsafe_of_int, - to_int, - is_char, - of_char, - to_char, - unsafe_to_char, - equal, - compare, - hash, -} -/* No side effect */ diff --git a/lib/js/arg.js b/lib/js/arg.js deleted file mode 100644 index f606de0d6b..0000000000 --- a/lib/js/arg.js +++ /dev/null @@ -1,689 +0,0 @@ -'use strict'; - -let Sys = require("./sys.js"); -let Caml = require("./caml.js"); -let List = require("./list.js"); -let $$Array = require("./array.js"); -let Buffer = require("./buffer.js"); -let $$String = require("./string.js"); -let Caml_obj = require("./caml_obj.js"); -let Caml_array = require("./caml_array.js"); -let Pervasives = require("./pervasives.js"); -let Caml_format = require("./caml_format.js"); -let Caml_string = require("./caml_string.js"); -let Caml_exceptions = require("./caml_exceptions.js"); -let Caml_js_exceptions = require("./caml_js_exceptions.js"); - -let Bad = /* @__PURE__ */Caml_exceptions.create("Arg.Bad"); - -let Help = /* @__PURE__ */Caml_exceptions.create("Arg.Help"); - -let Stop = /* @__PURE__ */Caml_exceptions.create("Arg.Stop"); - -function assoc3(x, _l) { - while (true) { - let l = _l; - if (l) { - let match = l.hd; - if (Caml_obj.equal(match[0], x)) { - return match[1]; - } - _l = l.tl; - continue; - } - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - }; -} - -function split(s) { - let i = $$String.index(s, /* '=' */61); - let len = s.length; - return [ - $$String.sub(s, 0, i), - $$String.sub(s, i + 1 | 0, len - (i + 1 | 0) | 0) - ]; -} - -function make_symlist(prefix, sep, suffix, l) { - if (l) { - return List.fold_left((x, y) => x + (sep + y), prefix + l.hd, l.tl) + suffix; - } else { - return ""; - } -} - -function help_action() { - throw { - RE_EXN_ID: Stop, - _1: { - TAG: "Unknown", - _0: "-help" - }, - Error: new Error() - }; -} - -function add_help(speclist) { - let add1; - try { - assoc3("-help", speclist); - add1 = /* [] */0; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - add1 = { - hd: [ - "-help", - { - TAG: "Unit", - _0: help_action - }, - " Display this list of options" - ], - tl: /* [] */0 - }; - } else { - throw exn; - } - } - let add2; - try { - assoc3("--help", speclist); - add2 = /* [] */0; - } catch (raw_exn$1) { - let exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn$1); - if (exn$1.RE_EXN_ID === "Not_found") { - add2 = { - hd: [ - "--help", - { - TAG: "Unit", - _0: help_action - }, - " Display this list of options" - ], - tl: /* [] */0 - }; - } else { - throw exn$1; - } - } - return Pervasives.$at(speclist, Pervasives.$at(add1, add2)); -} - -function usage_b(buf, speclist, errmsg) { - Buffer.add_string(buf, errmsg + "\n"); - List.iter(x => { - let doc = x[2]; - if (doc.length === 0) { - return; - } - let spec = x[1]; - let key = x[0]; - if (spec.TAG !== "Symbol") { - return Buffer.add_string(buf, " " + key + " " + doc + "\n"); - } - let sym = make_symlist("{", "|", "}", spec._0); - Buffer.add_string(buf, " " + key + " " + sym + doc + "\n"); - }, add_help(speclist)); -} - -function usage_string(speclist, errmsg) { - let b = Buffer.create(200); - usage_b(b, speclist, errmsg); - return Buffer.contents(b); -} - -function usage(speclist, errmsg) { - console.log(usage_string(speclist, errmsg)); -} - -let current = { - contents: 0 -}; - -function bool_of_string_opt(x) { - try { - return Pervasives.bool_of_string(x); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Invalid_argument") { - return; - } - throw exn; - } -} - -function int_of_string_opt(x) { - try { - return Caml_format.int_of_string(x); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Failure") { - return; - } - throw exn; - } -} - -function float_of_string_opt(x) { - try { - return Caml_format.float_of_string(x); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Failure") { - return; - } - throw exn; - } -} - -function parse_and_expand_argv_dynamic_aux(allow_expand, current, argv, speclist, anonfun, errmsg) { - let initpos = current.contents; - let convert_error = error => { - let b = Buffer.create(200); - let progname = initpos < argv.contents.length ? Caml_array.get(argv.contents, initpos) : "(?)"; - switch (error.TAG) { - case "Unknown" : - let s = error._0; - switch (s) { - case "--help" : - case "-help" : - break; - default: - Buffer.add_string(b, progname + ": unknown option '" + s + "'.\n"); - } - break; - case "Wrong" : - Buffer.add_string(b, progname + ": wrong argument '" + error._1 + "'; option '" + error._0 + "' expects " + error._2 + ".\n"); - break; - case "Missing" : - Buffer.add_string(b, progname + ": option '" + error._0 + "' needs an argument.\n"); - break; - case "Message" : - Buffer.add_string(b, progname + ": " + error._0 + ".\n"); - break; - } - usage_b(b, speclist.contents, errmsg); - if (Caml_obj.equal(error, { - TAG: "Unknown", - _0: "-help" - }) || Caml_obj.equal(error, { - TAG: "Unknown", - _0: "--help" - })) { - return { - RE_EXN_ID: Help, - _1: Buffer.contents(b) - }; - } else { - return { - RE_EXN_ID: Bad, - _1: Buffer.contents(b) - }; - } - }; - current.contents = current.contents + 1 | 0; - while (current.contents < argv.contents.length) { - try { - let s = Caml_array.get(argv.contents, current.contents); - if (s.length >= 1 && Caml_string.get(s, 0) === /* '-' */45) { - let match; - try { - match = [ - assoc3(s, speclist.contents), - undefined - ]; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - try { - let match$1 = split(s); - match = [ - assoc3(match$1[0], speclist.contents), - match$1[1] - ]; - } catch (raw_exn$1) { - let exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn$1); - if (exn$1.RE_EXN_ID === "Not_found") { - throw { - RE_EXN_ID: Stop, - _1: { - TAG: "Unknown", - _0: s - }, - Error: new Error() - }; - } - throw exn$1; - } - } else { - throw exn; - } - } - let follow = match[1]; - let no_arg = () => { - if (follow === undefined) { - return; - } - throw { - RE_EXN_ID: Stop, - _1: { - TAG: "Wrong", - _0: s, - _1: follow, - _2: "no argument" - }, - Error: new Error() - }; - }; - let get_arg = () => { - if (follow !== undefined) { - return follow; - } - if ((current.contents + 1 | 0) < argv.contents.length) { - return Caml_array.get(argv.contents, current.contents + 1 | 0); - } - throw { - RE_EXN_ID: Stop, - _1: { - TAG: "Missing", - _0: s - }, - Error: new Error() - }; - }; - let consume_arg = () => { - if (follow !== undefined) { - return; - } else { - current.contents = current.contents + 1 | 0; - return; - } - }; - let treat_action = f => { - switch (f.TAG) { - case "Unit" : - return f._0(); - case "Bool" : - let arg = get_arg(); - let s$1 = bool_of_string_opt(arg); - if (s$1 !== undefined) { - f._0(s$1); - } else { - throw { - RE_EXN_ID: Stop, - _1: { - TAG: "Wrong", - _0: s, - _1: arg, - _2: "a boolean" - }, - Error: new Error() - }; - } - return consume_arg(); - case "Set" : - no_arg(); - f._0.contents = true; - return; - case "Clear" : - no_arg(); - f._0.contents = false; - return; - case "String" : - let arg$1 = get_arg(); - f._0(arg$1); - return consume_arg(); - case "Set_string" : - f._0.contents = get_arg(); - return consume_arg(); - case "Int" : - let arg$2 = get_arg(); - let x = int_of_string_opt(arg$2); - if (x !== undefined) { - f._0(x); - } else { - throw { - RE_EXN_ID: Stop, - _1: { - TAG: "Wrong", - _0: s, - _1: arg$2, - _2: "an integer" - }, - Error: new Error() - }; - } - return consume_arg(); - case "Set_int" : - let arg$3 = get_arg(); - let x$1 = int_of_string_opt(arg$3); - if (x$1 !== undefined) { - f._0.contents = x$1; - } else { - throw { - RE_EXN_ID: Stop, - _1: { - TAG: "Wrong", - _0: s, - _1: arg$3, - _2: "an integer" - }, - Error: new Error() - }; - } - return consume_arg(); - case "Float" : - let arg$4 = get_arg(); - let x$2 = float_of_string_opt(arg$4); - if (x$2 !== undefined) { - f._0(x$2); - } else { - throw { - RE_EXN_ID: Stop, - _1: { - TAG: "Wrong", - _0: s, - _1: arg$4, - _2: "a float" - }, - Error: new Error() - }; - } - return consume_arg(); - case "Set_float" : - let arg$5 = get_arg(); - let x$3 = float_of_string_opt(arg$5); - if (x$3 !== undefined) { - f._0.contents = x$3; - } else { - throw { - RE_EXN_ID: Stop, - _1: { - TAG: "Wrong", - _0: s, - _1: arg$5, - _2: "a float" - }, - Error: new Error() - }; - } - return consume_arg(); - case "Tuple" : - return List.iter(treat_action, f._0); - case "Symbol" : - let symb = f._0; - let arg$6 = get_arg(); - if (List.mem(arg$6, symb)) { - f._1(arg$6); - return consume_arg(); - } - throw { - RE_EXN_ID: Stop, - _1: { - TAG: "Wrong", - _0: s, - _1: arg$6, - _2: "one of: " + make_symlist("", " ", "", symb) - }, - Error: new Error() - }; - case "Rest" : - let f$1 = f._0; - while (current.contents < (argv.contents.length - 1 | 0)) { - f$1(Caml_array.get(argv.contents, current.contents + 1 | 0)); - consume_arg(); - }; - return; - case "Expand" : - if (!allow_expand) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Arg.Expand is is only allowed with Arg.parse_and_expand_argv_dynamic", - Error: new Error() - }; - } - let arg$7 = get_arg(); - let newarg = f._0(arg$7); - consume_arg(); - let before = $$Array.sub(argv.contents, 0, current.contents + 1 | 0); - let after = $$Array.sub(argv.contents, current.contents + 1 | 0, (argv.contents.length - current.contents | 0) - 1 | 0); - argv.contents = Caml_array.concat({ - hd: before, - tl: { - hd: newarg, - tl: { - hd: after, - tl: /* [] */0 - } - } - }); - return; - } - }; - treat_action(match[0]); - } else { - anonfun(s); - } - } catch (raw_m) { - let m = Caml_js_exceptions.internalToOCamlException(raw_m); - if (m.RE_EXN_ID === Bad) { - throw convert_error({ - TAG: "Message", - _0: m._1 - }); - } - if (m.RE_EXN_ID === Stop) { - throw convert_error(m._1); - } - throw m; - } - current.contents = current.contents + 1 | 0; - }; -} - -function parse_and_expand_argv_dynamic(current, argv, speclist, anonfun, errmsg) { - parse_and_expand_argv_dynamic_aux(true, current, argv, speclist, anonfun, errmsg); -} - -function parse_argv_dynamic(currentOpt, argv, speclist, anonfun, errmsg) { - let current$1 = currentOpt !== undefined ? currentOpt : current; - parse_and_expand_argv_dynamic_aux(false, current$1, { - contents: argv - }, speclist, anonfun, errmsg); -} - -function parse_argv(currentOpt, argv, speclist, anonfun, errmsg) { - let current$1 = currentOpt !== undefined ? currentOpt : current; - parse_argv_dynamic(current$1, argv, { - contents: speclist - }, anonfun, errmsg); -} - -function parse(l, f, msg) { - try { - return parse_argv(undefined, Sys.argv, l, f, msg); - } catch (raw_msg) { - let msg$1 = Caml_js_exceptions.internalToOCamlException(raw_msg); - if (msg$1.RE_EXN_ID === Bad) { - console.log(msg$1._1); - return Pervasives.exit(2); - } - if (msg$1.RE_EXN_ID === Help) { - console.log(msg$1._1); - return Pervasives.exit(0); - } - throw msg$1; - } -} - -function parse_dynamic(l, f, msg) { - try { - return parse_argv_dynamic(undefined, Sys.argv, l, f, msg); - } catch (raw_msg) { - let msg$1 = Caml_js_exceptions.internalToOCamlException(raw_msg); - if (msg$1.RE_EXN_ID === Bad) { - console.log(msg$1._1); - return Pervasives.exit(2); - } - if (msg$1.RE_EXN_ID === Help) { - console.log(msg$1._1); - return Pervasives.exit(0); - } - throw msg$1; - } -} - -function parse_expand(l, f, msg) { - try { - let argv = { - contents: Sys.argv - }; - let spec = { - contents: l - }; - let current$1 = { - contents: current.contents - }; - return parse_and_expand_argv_dynamic(current$1, argv, spec, f, msg); - } catch (raw_msg) { - let msg$1 = Caml_js_exceptions.internalToOCamlException(raw_msg); - if (msg$1.RE_EXN_ID === Bad) { - console.log(msg$1._1); - return Pervasives.exit(2); - } - if (msg$1.RE_EXN_ID === Help) { - console.log(msg$1._1); - return Pervasives.exit(0); - } - throw msg$1; - } -} - -function second_word(s) { - let len = s.length; - let loop = _n => { - while (true) { - let n = _n; - if (n >= len) { - return len; - } - if (Caml_string.get(s, n) !== /* ' ' */32) { - return n; - } - _n = n + 1 | 0; - continue; - }; - }; - let n; - try { - n = $$String.index(s, /* '\t' */9); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - let exit = 0; - let n$1; - try { - n$1 = $$String.index(s, /* ' ' */32); - exit = 2; - } catch (raw_exn$1) { - let exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn$1); - if (exn$1.RE_EXN_ID === "Not_found") { - return len; - } - throw exn$1; - } - if (exit === 2) { - return loop(n$1 + 1 | 0); - } - - } else { - throw exn; - } - } - return loop(n + 1 | 0); -} - -function max_arg_len(cur, param) { - let kwd = param[0]; - if (param[1].TAG === "Symbol") { - return Caml.int_max(cur, kwd.length); - } else { - return Caml.int_max(cur, kwd.length + second_word(param[2]) | 0); - } -} - -function replace_leading_tab(s) { - let seen = { - contents: false - }; - return $$String.map(c => { - if (c !== 9 || seen.contents) { - return c; - } else { - seen.contents = true; - return /* ' ' */32; - } - }, s); -} - -function align(limitOpt, speclist) { - let limit = limitOpt !== undefined ? limitOpt : Pervasives.max_int; - let completed = add_help(speclist); - let len = List.fold_left(max_arg_len, 0, completed); - let len$1 = len < limit ? len : limit; - return List.map(x => { - let spec = x[1]; - let kwd = x[0]; - if (x[2] === "") { - return x; - } - if (spec.TAG === "Symbol") { - let msg = x[2]; - let cutcol = second_word(msg); - let spaces = " ".repeat(Caml.int_max(0, len$1 - cutcol | 0) + 3 | 0); - return [ - kwd, - spec, - "\n" + (spaces + replace_leading_tab(msg)) - ]; - } - let msg$1 = x[2]; - let cutcol$1 = second_word(msg$1); - let kwd_len = kwd.length; - let diff = (len$1 - kwd_len | 0) - cutcol$1 | 0; - if (diff <= 0) { - return [ - kwd, - spec, - replace_leading_tab(msg$1) - ]; - } - let spaces$1 = " ".repeat(diff); - let prefix = $$String.sub(replace_leading_tab(msg$1), 0, cutcol$1); - let suffix = $$String.sub(msg$1, cutcol$1, msg$1.length - cutcol$1 | 0); - return [ - kwd, - spec, - prefix + (spaces$1 + suffix) - ]; - }, completed); -} - -exports.parse = parse; -exports.parse_dynamic = parse_dynamic; -exports.parse_argv = parse_argv; -exports.parse_argv_dynamic = parse_argv_dynamic; -exports.parse_and_expand_argv_dynamic = parse_and_expand_argv_dynamic; -exports.parse_expand = parse_expand; -exports.Help = Help; -exports.Bad = Bad; -exports.usage = usage; -exports.usage_string = usage_string; -exports.align = align; -exports.current = current; -/* No side effect */ diff --git a/lib/js/array.js b/lib/js/array.js index b262d5b67b..e78d6732e5 100644 --- a/lib/js/array.js +++ b/lib/js/array.js @@ -1,55 +1,42 @@ 'use strict'; -let Caml_obj = require("./caml_obj.js"); -let Caml_array = require("./caml_array.js"); -let Caml_exceptions = require("./caml_exceptions.js"); -let Caml_js_exceptions = require("./caml_js_exceptions.js"); +let List = require("./list.js"); +let Primitive_array = require("./primitive_array.js"); +let Primitive_exceptions = require("./primitive_exceptions.js"); -let make_float = Caml_array.make_float; +let init = ((length, f) => Array.from({ length }, f)); -let Floatarray = {}; +function make(len, x) { + return init(len, param => x); +} -function init(l, f) { - if (l === 0) { - return []; - } - if (l < 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Array.init", - Error: new Error() - }; - } - let res = Caml_array.make(l, f(0)); - for (let i = 1; i < l; ++i) { - res[i] = f(i); - } - return res; +function unsafe_sub(array, offset, length) { + return array.slice(offset, offset + length | 0); } -function make_matrix(sx, sy, init) { - let res = Caml_array.make(sx, []); - for (let x = 0; x < sx; ++x) { - res[x] = Caml_array.make(sy, init); - } - return res; +function concat(list) { + return List.fold_left((arr1, arr2) => arr1.concat(arr2), [], list); } -function copy(a) { - let l = a.length; - if (l === 0) { - return []; - } else { - return Caml_array.sub(a, 0, l); +function create_float(len) { + return init(len, param => 0.0); +} + +function make_matrix(sx, sy, init$1) { + let x = []; + let res = init(sx, param => x); + for (let x$1 = 0; x$1 < sx; ++x$1) { + res[x$1] = init(sy, param => init$1); } + return res; } function append(a1, a2) { let l1 = a1.length; if (l1 === 0) { - return copy(a2); + return a2.slice(); } else if (a2.length === 0) { - return Caml_array.sub(a1, 0, l1); + return unsafe_sub(a1, 0, l1); } else { return a1.concat(a2); } @@ -63,7 +50,7 @@ function sub(a, ofs, len) { Error: new Error() }; } - return Caml_array.sub(a, ofs, len); + return unsafe_sub(a, ofs, len); } function fill(a, ofs, len, v) { @@ -87,7 +74,9 @@ function blit(a1, ofs1, a2, ofs2, len) { Error: new Error() }; } - Caml_array.blit(a1, ofs1, a2, ofs2, len); + for (let i = 0; i < len; ++i) { + a2[ofs2 + i | 0] = a1[ofs1 + i | 0]; + } } function iter(f, a) { @@ -114,7 +103,8 @@ function map(f, a) { if (l === 0) { return []; } - let r = Caml_array.make(l, f(a[0])); + let x = f(a[0]); + let r = init(l, param => x); for (let i = 1; i < l; ++i) { r[i] = f(a[i]); } @@ -134,7 +124,8 @@ function map2(f, a, b) { if (la === 0) { return []; } - let r = Caml_array.make(la, f(a[0], b[0])); + let x = f(a[0], b[0]); + let r = init(la, param => x); for (let i = 1; i < la; ++i) { r[i] = f(a[i], b[i]); } @@ -152,7 +143,8 @@ function mapi(f, a) { if (l === 0) { return []; } - let r = Caml_array.make(l, f(0, a[0])); + let x = f(0, a[0]); + let r = init(l, param => x); for (let i = 1; i < l; ++i) { r[i] = f(i, a[i]); } @@ -194,7 +186,9 @@ function of_list(param) { if (!param) { return []; } - let a = Caml_array.make(list_length(0, param), param.hd); + let hd = param.hd; + let len = list_length(0, param); + let a = init(len, param => hd); let _i = 1; let _param = param.tl; while (true) { @@ -266,7 +260,7 @@ function mem(x, a) { if (i === n) { return false; } - if (Caml_obj.equal(a[i], x)) { + if (a[i] === x) { return true; } _i = i + 1 | 0; @@ -290,22 +284,22 @@ function memq(x, a) { }; } -let Bottom = /* @__PURE__ */Caml_exceptions.create("Array.Bottom"); +let Bottom = /* @__PURE__ */Primitive_exceptions.create("Array.Bottom"); function sort(cmp, a) { let maxson = (l, i) => { let i31 = ((i + i | 0) + i | 0) + 1 | 0; let x = i31; if ((i31 + 2 | 0) < l) { - if (cmp(Caml_array.get(a, i31), Caml_array.get(a, i31 + 1 | 0)) < 0) { + if (cmp(Primitive_array.get(a, i31), Primitive_array.get(a, i31 + 1 | 0)) < 0) { x = i31 + 1 | 0; } - if (cmp(Caml_array.get(a, x), Caml_array.get(a, i31 + 2 | 0)) < 0) { + if (cmp(Primitive_array.get(a, x), Primitive_array.get(a, i31 + 2 | 0)) < 0) { x = i31 + 2 | 0; } return x; } - if ((i31 + 1 | 0) < l && cmp(Caml_array.get(a, i31), Caml_array.get(a, i31 + 1 | 0)) < 0) { + if ((i31 + 1 | 0) < l && cmp(Primitive_array.get(a, i31), Primitive_array.get(a, i31 + 1 | 0)) < 0) { return i31 + 1 | 0; } if (i31 < l) { @@ -323,17 +317,17 @@ function sort(cmp, a) { while (true) { let i$1 = _i; let j = maxson(l, i$1); - if (cmp(Caml_array.get(a, j), e) <= 0) { - return Caml_array.set(a, i$1, e); + if (cmp(Primitive_array.get(a, j), e) <= 0) { + return Primitive_array.set(a, i$1, e); } - Caml_array.set(a, i$1, Caml_array.get(a, j)); + Primitive_array.set(a, i$1, Primitive_array.get(a, j)); _i = j; continue; }; } catch (raw_i) { - let i$2 = Caml_js_exceptions.internalToOCamlException(raw_i); + let i$2 = Primitive_exceptions.internalToException(raw_i); if (i$2.RE_EXN_ID === Bottom) { - return Caml_array.set(a, i$2._1, e); + return Primitive_array.set(a, i$2._1, e); } throw i$2; } @@ -344,12 +338,12 @@ function sort(cmp, a) { while (true) { let i$1 = _i; let j = maxson(l, i$1); - Caml_array.set(a, i$1, Caml_array.get(a, j)); + Primitive_array.set(a, i$1, Primitive_array.get(a, j)); _i = j; continue; }; } catch (raw_i) { - let i$2 = Caml_js_exceptions.internalToOCamlException(raw_i); + let i$2 = Primitive_exceptions.internalToException(raw_i); if (i$2.RE_EXN_ID === Bottom) { return i$2._1; } @@ -365,18 +359,18 @@ function sort(cmp, a) { RE_EXN_ID: "Assert_failure", _1: [ "array.res", - 321, + 294, 4 ], Error: new Error() }; } - if (cmp(Caml_array.get(a, father), e) >= 0) { - return Caml_array.set(a, i, e); + if (cmp(Primitive_array.get(a, father), e) >= 0) { + return Primitive_array.set(a, i, e); } - Caml_array.set(a, i, Caml_array.get(a, father)); + Primitive_array.set(a, i, Primitive_array.get(a, father)); if (father <= 0) { - return Caml_array.set(a, 0, e); + return Primitive_array.set(a, 0, e); } _i = father; continue; @@ -384,19 +378,19 @@ function sort(cmp, a) { }; let l = a.length; for (let i = ((l + 1 | 0) / 3 | 0) - 1 | 0; i >= 0; --i) { - trickle(l, i, Caml_array.get(a, i)); + trickle(l, i, Primitive_array.get(a, i)); } for (let i$1 = l - 1 | 0; i$1 >= 2; --i$1) { - let e = Caml_array.get(a, i$1); - Caml_array.set(a, i$1, Caml_array.get(a, 0)); + let e = Primitive_array.get(a, i$1); + Primitive_array.set(a, i$1, Primitive_array.get(a, 0)); trickleup(bubble(i$1, 0), e); } if (l <= 1) { return; } - let e$1 = Caml_array.get(a, 1); - Caml_array.set(a, 1, Caml_array.get(a, 0)); - Caml_array.set(a, 0, e$1); + let e$1 = Primitive_array.get(a, 1); + Primitive_array.set(a, 1, Primitive_array.get(a, 0)); + Primitive_array.set(a, 0, e$1); } function stable_sort(cmp, a) { @@ -404,9 +398,9 @@ function stable_sort(cmp, a) { let src1r = src1ofs + src1len | 0; let src2r = src2ofs + src2len | 0; let _i1 = src1ofs; - let _s1 = Caml_array.get(a, src1ofs); + let _s1 = Primitive_array.get(a, src1ofs); let _i2 = src2ofs; - let _s2 = Caml_array.get(src2, src2ofs); + let _s2 = Primitive_array.get(src2, src2ofs); let _d = dstofs; while (true) { let d = _d; @@ -415,36 +409,36 @@ function stable_sort(cmp, a) { let s1 = _s1; let i1 = _i1; if (cmp(s1, s2) <= 0) { - Caml_array.set(dst, d, s1); + Primitive_array.set(dst, d, s1); let i1$1 = i1 + 1 | 0; if (i1$1 >= src1r) { return blit(src2, i2, dst, d + 1 | 0, src2r - i2 | 0); } _d = d + 1 | 0; - _s1 = Caml_array.get(a, i1$1); + _s1 = Primitive_array.get(a, i1$1); _i1 = i1$1; continue; } - Caml_array.set(dst, d, s2); + Primitive_array.set(dst, d, s2); let i2$1 = i2 + 1 | 0; if (i2$1 >= src2r) { return blit(a, i1, dst, d + 1 | 0, src1r - i1 | 0); } _d = d + 1 | 0; - _s2 = Caml_array.get(src2, i2$1); + _s2 = Primitive_array.get(src2, i2$1); _i2 = i2$1; continue; }; }; let isortto = (srcofs, dst, dstofs, len) => { for (let i = 0; i < len; ++i) { - let e = Caml_array.get(a, srcofs + i | 0); + let e = Primitive_array.get(a, srcofs + i | 0); let j = (dstofs + i | 0) - 1 | 0; - while (j >= dstofs && cmp(Caml_array.get(dst, j), e) > 0) { - Caml_array.set(dst, j + 1 | 0, Caml_array.get(dst, j)); + while (j >= dstofs && cmp(Primitive_array.get(dst, j), e) > 0) { + Primitive_array.set(dst, j + 1 | 0, Primitive_array.get(dst, j)); j = j - 1 | 0; }; - Caml_array.set(dst, j + 1 | 0, e); + Primitive_array.set(dst, j + 1 | 0, e); } }; let sortto = (srcofs, dst, dstofs, len) => { @@ -463,26 +457,22 @@ function stable_sort(cmp, a) { } let l1 = l / 2 | 0; let l2 = l - l1 | 0; - let t = Caml_array.make(l2, Caml_array.get(a, 0)); + let x = Primitive_array.get(a, 0); + let t = init(l2, param => x); sortto(l1, t, 0, l2); sortto(0, a, l2, l1); merge(l2, l1, t, 0, l2, a, 0); } -let create_matrix = make_matrix; - -let concat = Caml_array.concat; - let fast_sort = stable_sort; -exports.make_float = make_float; +exports.make = make; +exports.create_float = create_float; exports.init = init; exports.make_matrix = make_matrix; -exports.create_matrix = create_matrix; exports.append = append; exports.concat = concat; exports.sub = sub; -exports.copy = copy; exports.fill = fill; exports.blit = blit; exports.to_list = to_list; @@ -502,5 +492,4 @@ exports.memq = memq; exports.sort = sort; exports.stable_sort = stable_sort; exports.fast_sort = fast_sort; -exports.Floatarray = Floatarray; /* No side effect */ diff --git a/lib/js/arrayLabels.js b/lib/js/arrayLabels.js deleted file mode 100644 index bec5ae1c21..0000000000 --- a/lib/js/arrayLabels.js +++ /dev/null @@ -1,506 +0,0 @@ -'use strict'; - -let Caml_obj = require("./caml_obj.js"); -let Caml_array = require("./caml_array.js"); -let Caml_exceptions = require("./caml_exceptions.js"); -let Caml_js_exceptions = require("./caml_js_exceptions.js"); - -let make_float = Caml_array.make_float; - -let Floatarray = {}; - -function init(l, f) { - if (l === 0) { - return []; - } - if (l < 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Array.init", - Error: new Error() - }; - } - let res = Caml_array.make(l, f(0)); - for (let i = 1; i < l; ++i) { - res[i] = f(i); - } - return res; -} - -function make_matrix(sx, sy, init) { - let res = Caml_array.make(sx, []); - for (let x = 0; x < sx; ++x) { - res[x] = Caml_array.make(sy, init); - } - return res; -} - -function copy(a) { - let l = a.length; - if (l === 0) { - return []; - } else { - return Caml_array.sub(a, 0, l); - } -} - -function append(a1, a2) { - let l1 = a1.length; - if (l1 === 0) { - return copy(a2); - } else if (a2.length === 0) { - return Caml_array.sub(a1, 0, l1); - } else { - return a1.concat(a2); - } -} - -function sub(a, ofs, len) { - if (ofs < 0 || len < 0 || ofs > (a.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Array.sub", - Error: new Error() - }; - } - return Caml_array.sub(a, ofs, len); -} - -function fill(a, ofs, len, v) { - if (ofs < 0 || len < 0 || ofs > (a.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Array.fill", - Error: new Error() - }; - } - for (let i = ofs, i_finish = ofs + len | 0; i < i_finish; ++i) { - a[i] = v; - } -} - -function blit(a1, ofs1, a2, ofs2, len) { - if (len < 0 || ofs1 < 0 || ofs1 > (a1.length - len | 0) || ofs2 < 0 || ofs2 > (a2.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Array.blit", - Error: new Error() - }; - } - Caml_array.blit(a1, ofs1, a2, ofs2, len); -} - -function iter(f, a) { - for (let i = 0, i_finish = a.length; i < i_finish; ++i) { - f(a[i]); - } -} - -function iter2(f, a, b) { - if (a.length !== b.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Array.iter2: arrays must have the same length", - Error: new Error() - }; - } - for (let i = 0, i_finish = a.length; i < i_finish; ++i) { - f(a[i], b[i]); - } -} - -function map(f, a) { - let l = a.length; - if (l === 0) { - return []; - } - let r = Caml_array.make(l, f(a[0])); - for (let i = 1; i < l; ++i) { - r[i] = f(a[i]); - } - return r; -} - -function map2(f, a, b) { - let la = a.length; - let lb = b.length; - if (la !== lb) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Array.map2: arrays must have the same length", - Error: new Error() - }; - } - if (la === 0) { - return []; - } - let r = Caml_array.make(la, f(a[0], b[0])); - for (let i = 1; i < la; ++i) { - r[i] = f(a[i], b[i]); - } - return r; -} - -function iteri(f, a) { - for (let i = 0, i_finish = a.length; i < i_finish; ++i) { - f(i, a[i]); - } -} - -function mapi(f, a) { - let l = a.length; - if (l === 0) { - return []; - } - let r = Caml_array.make(l, f(0, a[0])); - for (let i = 1; i < l; ++i) { - r[i] = f(i, a[i]); - } - return r; -} - -function to_list(a) { - let _i = a.length - 1 | 0; - let _res = /* [] */0; - while (true) { - let res = _res; - let i = _i; - if (i < 0) { - return res; - } - _res = { - hd: a[i], - tl: res - }; - _i = i - 1 | 0; - continue; - }; -} - -function list_length(_accu, _param) { - while (true) { - let param = _param; - let accu = _accu; - if (!param) { - return accu; - } - _param = param.tl; - _accu = accu + 1 | 0; - continue; - }; -} - -function of_list(param) { - if (!param) { - return []; - } - let a = Caml_array.make(list_length(0, param), param.hd); - let _i = 1; - let _param = param.tl; - while (true) { - let param$1 = _param; - let i = _i; - if (!param$1) { - return a; - } - a[i] = param$1.hd; - _param = param$1.tl; - _i = i + 1 | 0; - continue; - }; -} - -function fold_left(f, x, a) { - let r = x; - for (let i = 0, i_finish = a.length; i < i_finish; ++i) { - r = f(r, a[i]); - } - return r; -} - -function fold_right(f, a, x) { - let r = x; - for (let i = a.length - 1 | 0; i >= 0; --i) { - r = f(a[i], r); - } - return r; -} - -function exists(p, a) { - let n = a.length; - let _i = 0; - while (true) { - let i = _i; - if (i === n) { - return false; - } - if (p(a[i])) { - return true; - } - _i = i + 1 | 0; - continue; - }; -} - -function for_all(p, a) { - let n = a.length; - let _i = 0; - while (true) { - let i = _i; - if (i === n) { - return true; - } - if (!p(a[i])) { - return false; - } - _i = i + 1 | 0; - continue; - }; -} - -function mem(x, a) { - let n = a.length; - let _i = 0; - while (true) { - let i = _i; - if (i === n) { - return false; - } - if (Caml_obj.equal(a[i], x)) { - return true; - } - _i = i + 1 | 0; - continue; - }; -} - -function memq(x, a) { - let n = a.length; - let _i = 0; - while (true) { - let i = _i; - if (i === n) { - return false; - } - if (x === a[i]) { - return true; - } - _i = i + 1 | 0; - continue; - }; -} - -let Bottom = /* @__PURE__ */Caml_exceptions.create("ArrayLabels.Bottom"); - -function sort(cmp, a) { - let maxson = (l, i) => { - let i31 = ((i + i | 0) + i | 0) + 1 | 0; - let x = i31; - if ((i31 + 2 | 0) < l) { - if (cmp(Caml_array.get(a, i31), Caml_array.get(a, i31 + 1 | 0)) < 0) { - x = i31 + 1 | 0; - } - if (cmp(Caml_array.get(a, x), Caml_array.get(a, i31 + 2 | 0)) < 0) { - x = i31 + 2 | 0; - } - return x; - } - if ((i31 + 1 | 0) < l && cmp(Caml_array.get(a, i31), Caml_array.get(a, i31 + 1 | 0)) < 0) { - return i31 + 1 | 0; - } - if (i31 < l) { - return i31; - } - throw { - RE_EXN_ID: Bottom, - _1: i, - Error: new Error() - }; - }; - let trickle = (l, i, e) => { - try { - let _i = i; - while (true) { - let i$1 = _i; - let j = maxson(l, i$1); - if (cmp(Caml_array.get(a, j), e) <= 0) { - return Caml_array.set(a, i$1, e); - } - Caml_array.set(a, i$1, Caml_array.get(a, j)); - _i = j; - continue; - }; - } catch (raw_i) { - let i$2 = Caml_js_exceptions.internalToOCamlException(raw_i); - if (i$2.RE_EXN_ID === Bottom) { - return Caml_array.set(a, i$2._1, e); - } - throw i$2; - } - }; - let bubble = (l, i) => { - try { - let _i = i; - while (true) { - let i$1 = _i; - let j = maxson(l, i$1); - Caml_array.set(a, i$1, Caml_array.get(a, j)); - _i = j; - continue; - }; - } catch (raw_i) { - let i$2 = Caml_js_exceptions.internalToOCamlException(raw_i); - if (i$2.RE_EXN_ID === Bottom) { - return i$2._1; - } - throw i$2; - } - }; - let trickleup = (_i, e) => { - while (true) { - let i = _i; - let father = (i - 1 | 0) / 3 | 0; - if (i === father) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "arrayLabels.res", - 321, - 4 - ], - Error: new Error() - }; - } - if (cmp(Caml_array.get(a, father), e) >= 0) { - return Caml_array.set(a, i, e); - } - Caml_array.set(a, i, Caml_array.get(a, father)); - if (father <= 0) { - return Caml_array.set(a, 0, e); - } - _i = father; - continue; - }; - }; - let l = a.length; - for (let i = ((l + 1 | 0) / 3 | 0) - 1 | 0; i >= 0; --i) { - trickle(l, i, Caml_array.get(a, i)); - } - for (let i$1 = l - 1 | 0; i$1 >= 2; --i$1) { - let e = Caml_array.get(a, i$1); - Caml_array.set(a, i$1, Caml_array.get(a, 0)); - trickleup(bubble(i$1, 0), e); - } - if (l <= 1) { - return; - } - let e$1 = Caml_array.get(a, 1); - Caml_array.set(a, 1, Caml_array.get(a, 0)); - Caml_array.set(a, 0, e$1); -} - -function stable_sort(cmp, a) { - let merge = (src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs) => { - let src1r = src1ofs + src1len | 0; - let src2r = src2ofs + src2len | 0; - let _i1 = src1ofs; - let _s1 = Caml_array.get(a, src1ofs); - let _i2 = src2ofs; - let _s2 = Caml_array.get(src2, src2ofs); - let _d = dstofs; - while (true) { - let d = _d; - let s2 = _s2; - let i2 = _i2; - let s1 = _s1; - let i1 = _i1; - if (cmp(s1, s2) <= 0) { - Caml_array.set(dst, d, s1); - let i1$1 = i1 + 1 | 0; - if (i1$1 >= src1r) { - return blit(src2, i2, dst, d + 1 | 0, src2r - i2 | 0); - } - _d = d + 1 | 0; - _s1 = Caml_array.get(a, i1$1); - _i1 = i1$1; - continue; - } - Caml_array.set(dst, d, s2); - let i2$1 = i2 + 1 | 0; - if (i2$1 >= src2r) { - return blit(a, i1, dst, d + 1 | 0, src1r - i1 | 0); - } - _d = d + 1 | 0; - _s2 = Caml_array.get(src2, i2$1); - _i2 = i2$1; - continue; - }; - }; - let isortto = (srcofs, dst, dstofs, len) => { - for (let i = 0; i < len; ++i) { - let e = Caml_array.get(a, srcofs + i | 0); - let j = (dstofs + i | 0) - 1 | 0; - while (j >= dstofs && cmp(Caml_array.get(dst, j), e) > 0) { - Caml_array.set(dst, j + 1 | 0, Caml_array.get(dst, j)); - j = j - 1 | 0; - }; - Caml_array.set(dst, j + 1 | 0, e); - } - }; - let sortto = (srcofs, dst, dstofs, len) => { - if (len <= 5) { - return isortto(srcofs, dst, dstofs, len); - } - let l1 = len / 2 | 0; - let l2 = len - l1 | 0; - sortto(srcofs + l1 | 0, dst, dstofs + l1 | 0, l2); - sortto(srcofs, a, srcofs + l2 | 0, l1); - merge(srcofs + l2 | 0, l1, dst, dstofs + l1 | 0, l2, dst, dstofs); - }; - let l = a.length; - if (l <= 5) { - return isortto(0, a, 0, l); - } - let l1 = l / 2 | 0; - let l2 = l - l1 | 0; - let t = Caml_array.make(l2, Caml_array.get(a, 0)); - sortto(l1, t, 0, l2); - sortto(0, a, l2, l1); - merge(l2, l1, t, 0, l2, a, 0); -} - -let create_matrix = make_matrix; - -let concat = Caml_array.concat; - -let fast_sort = stable_sort; - -exports.init = init; -exports.make_matrix = make_matrix; -exports.create_matrix = create_matrix; -exports.append = append; -exports.concat = concat; -exports.sub = sub; -exports.copy = copy; -exports.fill = fill; -exports.blit = blit; -exports.to_list = to_list; -exports.of_list = of_list; -exports.iter = iter; -exports.map = map; -exports.iteri = iteri; -exports.mapi = mapi; -exports.fold_left = fold_left; -exports.fold_right = fold_right; -exports.iter2 = iter2; -exports.map2 = map2; -exports.exists = exists; -exports.for_all = for_all; -exports.mem = mem; -exports.memq = memq; -exports.make_float = make_float; -exports.sort = sort; -exports.stable_sort = stable_sort; -exports.fast_sort = fast_sort; -exports.Floatarray = Floatarray; -/* No side effect */ diff --git a/lib/js/belt_Array.js b/lib/js/belt_Array.js index 16962fb170..ed86097aac 100644 --- a/lib/js/belt_Array.js +++ b/lib/js/belt_Array.js @@ -1,11 +1,11 @@ 'use strict'; -let Caml = require("./caml.js"); -let Caml_option = require("./caml_option.js"); +let Primitive_int = require("./primitive_int.js"); +let Primitive_option = require("./primitive_option.js"); function get(arr, i) { if (i >= 0 && i < arr.length) { - return Caml_option.some(arr[i]); + return Primitive_option.some(arr[i]); } } @@ -144,7 +144,7 @@ function rangeBy(start, finish, step) { function zip(xs, ys) { let lenx = xs.length; let leny = ys.length; - let len = lenx < leny ? lenx : leny; + let len = Primitive_int.min(lenx, leny); let s = new Array(len); for (let i = 0; i < len; ++i) { s[i] = [ @@ -158,7 +158,7 @@ function zip(xs, ys) { function zipBy(xs, ys, f) { let lenx = xs.length; let leny = ys.length; - let len = lenx < leny ? lenx : leny; + let len = Primitive_int.min(lenx, leny); let s = new Array(len); for (let i = 0; i < len; ++i) { s[i] = f(xs[i], ys[i]); @@ -202,9 +202,9 @@ function slice(a, offset, len) { return []; } let lena = a.length; - let ofs = offset < 0 ? Caml.int_max(lena + offset | 0, 0) : offset; + let ofs = offset < 0 ? Primitive_int.max(lena + offset | 0, 0) : offset; let hasLen = lena - ofs | 0; - let copyLength = hasLen < len ? hasLen : len; + let copyLength = Primitive_int.min(hasLen, len); if (copyLength <= 0) { return []; } @@ -217,7 +217,7 @@ function slice(a, offset, len) { function sliceToEnd(a, offset) { let lena = a.length; - let ofs = offset < 0 ? Caml.int_max(lena + offset | 0, 0) : offset; + let ofs = offset < 0 ? Primitive_int.max(lena + offset | 0, 0) : offset; let len = lena > ofs ? lena - ofs | 0 : 0; let result = new Array(len); for (let i = 0; i < len; ++i) { @@ -231,9 +231,9 @@ function fill(a, offset, len, v) { return; } let lena = a.length; - let ofs = offset < 0 ? Caml.int_max(lena + offset | 0, 0) : offset; + let ofs = offset < 0 ? Primitive_int.max(lena + offset | 0, 0) : offset; let hasLen = lena - ofs | 0; - let fillLength = hasLen < len ? hasLen : len; + let fillLength = Primitive_int.min(hasLen, len); if (fillLength <= 0) { return; } @@ -257,9 +257,9 @@ function blitUnsafe(a1, srcofs1, a2, srcofs2, blitLength) { function blit(a1, ofs1, a2, ofs2, len) { let lena1 = a1.length; let lena2 = a2.length; - let srcofs1 = ofs1 < 0 ? Caml.int_max(lena1 + ofs1 | 0, 0) : ofs1; - let srcofs2 = ofs2 < 0 ? Caml.int_max(lena2 + ofs2 | 0, 0) : ofs2; - let blitLength = Caml.int_min(len, Caml.int_min(lena1 - srcofs1 | 0, lena2 - srcofs2 | 0)); + let srcofs1 = ofs1 < 0 ? Primitive_int.max(lena1 + ofs1 | 0, 0) : ofs1; + let srcofs2 = ofs2 < 0 ? Primitive_int.max(lena2 + ofs2 | 0, 0) : ofs2; + let blitLength = Primitive_int.min(len, Primitive_int.min(lena1 - srcofs1 | 0, lena2 - srcofs2 | 0)); if (srcofs2 <= srcofs1) { for (let j = 0; j < blitLength; ++j) { a2[j + srcofs2 | 0] = a1[j + srcofs1 | 0]; @@ -297,7 +297,7 @@ function getBy(a, p) { while (r === undefined && i < l) { let v = a[i]; if (p(v)) { - r = Caml_option.some(v); + r = Primitive_option.some(v); } i = i + 1 | 0; }; @@ -358,7 +358,7 @@ function keepMap(a, f) { let v = a[i]; let v$1 = f(v); if (v$1 !== undefined) { - r[j] = Caml_option.valFromOption(v$1); + r[j] = Primitive_option.valFromOption(v$1); j = j + 1 | 0; } @@ -400,7 +400,7 @@ function reduceReverse(a, x, f) { function reduceReverse2(a, b, x, f) { let r = x; - let len = Caml.int_min(a.length, b.length); + let len = Primitive_int.min(a.length, b.length); for (let i = len - 1 | 0; i >= 0; --i) { r = f(r, a[i], b[i]); } @@ -462,12 +462,12 @@ function everyAux2(arr1, arr2, _i, b, len) { } function every2(a, b, p) { - return everyAux2(a, b, 0, p, Caml.int_min(a.length, b.length)); + return everyAux2(a, b, 0, p, Primitive_int.min(a.length, b.length)); } function some2(a, b, p) { let _i = 0; - let len = Caml.int_min(a.length, b.length); + let len = Primitive_int.min(a.length, b.length); while (true) { let i = _i; if (i === len) { diff --git a/lib/js/belt_HashMap.js b/lib/js/belt_HashMap.js index e2687ec144..070df0ac5d 100644 --- a/lib/js/belt_HashMap.js +++ b/lib/js/belt_HashMap.js @@ -1,6 +1,6 @@ 'use strict'; -let Caml_option = require("./caml_option.js"); +let Primitive_option = require("./primitive_option.js"); let Belt_internalBuckets = require("./belt_internalBuckets.js"); let Belt_internalBucketsType = require("./belt_internalBucketsType.js"); @@ -138,19 +138,19 @@ function get(h, key) { } let eq = h.eq; if (eq(key, cell1.key)) { - return Caml_option.some(cell1.value); + return Primitive_option.some(cell1.value); } let cell2 = cell1.next; if (cell2 === undefined) { return; } if (eq(key, cell2.key)) { - return Caml_option.some(cell2.value); + return Primitive_option.some(cell2.value); } let cell3 = cell2.next; if (cell3 !== undefined) { if (eq(key, cell3.key)) { - return Caml_option.some(cell3.value); + return Primitive_option.some(cell3.value); } else { let _buckets = cell3.next; while (true) { @@ -159,7 +159,7 @@ function get(h, key) { return; } if (eq(key, buckets.key)) { - return Caml_option.some(buckets.value); + return Primitive_option.some(buckets.value); } _buckets = buckets.next; continue; diff --git a/lib/js/belt_HashMapInt.js b/lib/js/belt_HashMapInt.js index da481360c2..6b1698fec7 100644 --- a/lib/js/belt_HashMapInt.js +++ b/lib/js/belt_HashMapInt.js @@ -1,7 +1,7 @@ 'use strict'; -let Caml_option = require("./caml_option.js"); -let Caml_hash_primitive = require("./caml_hash_primitive.js"); +let Primitive_hash = require("./primitive_hash.js"); +let Primitive_option = require("./primitive_option.js"); let Belt_internalBuckets = require("./belt_internalBuckets.js"); let Belt_internalBucketsType = require("./belt_internalBucketsType.js"); @@ -11,7 +11,7 @@ function copyBucketReHash(h_buckets, ndata_tail, _old_bucket) { if (old_bucket === undefined) { return; } - let nidx = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_int(0, old_bucket.key)) & (h_buckets.length - 1 | 0); + let nidx = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_int(0, old_bucket.key)) & (h_buckets.length - 1 | 0); let tail = ndata_tail[nidx]; if (tail !== undefined) { tail.next = old_bucket; @@ -43,7 +43,7 @@ function replaceInBucket(key, info, _cell) { function set(h, key, value) { let h_buckets = h.buckets; let buckets_len = h_buckets.length; - let i = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_int(0, key)) & (buckets_len - 1 | 0); + let i = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_int(0, key)) & (buckets_len - 1 | 0); let l = h_buckets[i]; if (l !== undefined) { if (replaceInBucket(key, value, l)) { @@ -90,7 +90,7 @@ function set(h, key, value) { function remove(h, key) { let h_buckets = h.buckets; - let i = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_int(0, key)) & (h_buckets.length - 1 | 0); + let i = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_int(0, key)) & (h_buckets.length - 1 | 0); let bucket = h_buckets[i]; if (bucket !== undefined) { if (bucket.key === key) { @@ -123,25 +123,25 @@ function remove(h, key) { function get(h, key) { let h_buckets = h.buckets; - let nid = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_int(0, key)) & (h_buckets.length - 1 | 0); + let nid = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_int(0, key)) & (h_buckets.length - 1 | 0); let cell1 = h_buckets[nid]; if (cell1 === undefined) { return; } if (key === cell1.key) { - return Caml_option.some(cell1.value); + return Primitive_option.some(cell1.value); } let cell2 = cell1.next; if (cell2 === undefined) { return; } if (key === cell2.key) { - return Caml_option.some(cell2.value); + return Primitive_option.some(cell2.value); } let cell3 = cell2.next; if (cell3 !== undefined) { if (key === cell3.key) { - return Caml_option.some(cell3.value); + return Primitive_option.some(cell3.value); } else { let _buckets = cell3.next; while (true) { @@ -150,7 +150,7 @@ function get(h, key) { return; } if (key === buckets.key) { - return Caml_option.some(buckets.value); + return Primitive_option.some(buckets.value); } _buckets = buckets.next; continue; @@ -162,7 +162,7 @@ function get(h, key) { function has(h, key) { let h_buckets = h.buckets; - let nid = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_int(0, key)) & (h_buckets.length - 1 | 0); + let nid = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_int(0, key)) & (h_buckets.length - 1 | 0); let bucket = h_buckets[nid]; if (bucket !== undefined) { let _cell = bucket; diff --git a/lib/js/belt_HashMapString.js b/lib/js/belt_HashMapString.js index 412658586d..6eeb2d8a73 100644 --- a/lib/js/belt_HashMapString.js +++ b/lib/js/belt_HashMapString.js @@ -1,7 +1,7 @@ 'use strict'; -let Caml_option = require("./caml_option.js"); -let Caml_hash_primitive = require("./caml_hash_primitive.js"); +let Primitive_hash = require("./primitive_hash.js"); +let Primitive_option = require("./primitive_option.js"); let Belt_internalBuckets = require("./belt_internalBuckets.js"); let Belt_internalBucketsType = require("./belt_internalBucketsType.js"); @@ -11,7 +11,7 @@ function copyBucketReHash(h_buckets, ndata_tail, _old_bucket) { if (old_bucket === undefined) { return; } - let nidx = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_string(0, old_bucket.key)) & (h_buckets.length - 1 | 0); + let nidx = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_string(0, old_bucket.key)) & (h_buckets.length - 1 | 0); let tail = ndata_tail[nidx]; if (tail !== undefined) { tail.next = old_bucket; @@ -43,7 +43,7 @@ function replaceInBucket(key, info, _cell) { function set(h, key, value) { let h_buckets = h.buckets; let buckets_len = h_buckets.length; - let i = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_string(0, key)) & (buckets_len - 1 | 0); + let i = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_string(0, key)) & (buckets_len - 1 | 0); let l = h_buckets[i]; if (l !== undefined) { if (replaceInBucket(key, value, l)) { @@ -90,7 +90,7 @@ function set(h, key, value) { function remove(h, key) { let h_buckets = h.buckets; - let i = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_string(0, key)) & (h_buckets.length - 1 | 0); + let i = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_string(0, key)) & (h_buckets.length - 1 | 0); let bucket = h_buckets[i]; if (bucket !== undefined) { if (bucket.key === key) { @@ -123,25 +123,25 @@ function remove(h, key) { function get(h, key) { let h_buckets = h.buckets; - let nid = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_string(0, key)) & (h_buckets.length - 1 | 0); + let nid = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_string(0, key)) & (h_buckets.length - 1 | 0); let cell1 = h_buckets[nid]; if (cell1 === undefined) { return; } if (key === cell1.key) { - return Caml_option.some(cell1.value); + return Primitive_option.some(cell1.value); } let cell2 = cell1.next; if (cell2 === undefined) { return; } if (key === cell2.key) { - return Caml_option.some(cell2.value); + return Primitive_option.some(cell2.value); } let cell3 = cell2.next; if (cell3 !== undefined) { if (key === cell3.key) { - return Caml_option.some(cell3.value); + return Primitive_option.some(cell3.value); } else { let _buckets = cell3.next; while (true) { @@ -150,7 +150,7 @@ function get(h, key) { return; } if (key === buckets.key) { - return Caml_option.some(buckets.value); + return Primitive_option.some(buckets.value); } _buckets = buckets.next; continue; @@ -162,7 +162,7 @@ function get(h, key) { function has(h, key) { let h_buckets = h.buckets; - let nid = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_string(0, key)) & (h_buckets.length - 1 | 0); + let nid = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_string(0, key)) & (h_buckets.length - 1 | 0); let bucket = h_buckets[nid]; if (bucket !== undefined) { let _cell = bucket; diff --git a/lib/js/belt_HashSetInt.js b/lib/js/belt_HashSetInt.js index cd38c10533..4c768efbb2 100644 --- a/lib/js/belt_HashSetInt.js +++ b/lib/js/belt_HashSetInt.js @@ -1,6 +1,6 @@ 'use strict'; -let Caml_hash_primitive = require("./caml_hash_primitive.js"); +let Primitive_hash = require("./primitive_hash.js"); let Belt_internalSetBuckets = require("./belt_internalSetBuckets.js"); let Belt_internalBucketsType = require("./belt_internalBucketsType.js"); @@ -10,7 +10,7 @@ function copyBucket(h_buckets, ndata_tail, _old_bucket) { if (old_bucket === undefined) { return; } - let nidx = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_int(0, old_bucket.key)) & (h_buckets.length - 1 | 0); + let nidx = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_int(0, old_bucket.key)) & (h_buckets.length - 1 | 0); let tail = ndata_tail[nidx]; if (tail !== undefined) { tail.next = old_bucket; @@ -25,7 +25,7 @@ function copyBucket(h_buckets, ndata_tail, _old_bucket) { function remove(h, key) { let h_buckets = h.buckets; - let i = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_int(0, key)) & (h_buckets.length - 1 | 0); + let i = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_int(0, key)) & (h_buckets.length - 1 | 0); let l = h_buckets[i]; if (l === undefined) { return; @@ -82,7 +82,7 @@ function addBucket(h, key, _cell) { function add(h, key) { let h_buckets = h.buckets; let buckets_len = h_buckets.length; - let i = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_int(0, key)) & (buckets_len - 1 | 0); + let i = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_int(0, key)) & (buckets_len - 1 | 0); let l = h_buckets[i]; if (l !== undefined) { addBucket(h, key, l); @@ -120,7 +120,7 @@ function add(h, key) { function has(h, key) { let h_buckets = h.buckets; - let nid = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_int(0, key)) & (h_buckets.length - 1 | 0); + let nid = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_int(0, key)) & (h_buckets.length - 1 | 0); let bucket = h_buckets[nid]; if (bucket !== undefined) { let _cell = bucket; diff --git a/lib/js/belt_HashSetString.js b/lib/js/belt_HashSetString.js index acfad23eb5..24e0f21380 100644 --- a/lib/js/belt_HashSetString.js +++ b/lib/js/belt_HashSetString.js @@ -1,6 +1,6 @@ 'use strict'; -let Caml_hash_primitive = require("./caml_hash_primitive.js"); +let Primitive_hash = require("./primitive_hash.js"); let Belt_internalSetBuckets = require("./belt_internalSetBuckets.js"); let Belt_internalBucketsType = require("./belt_internalBucketsType.js"); @@ -10,7 +10,7 @@ function copyBucket(h_buckets, ndata_tail, _old_bucket) { if (old_bucket === undefined) { return; } - let nidx = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_string(0, old_bucket.key)) & (h_buckets.length - 1 | 0); + let nidx = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_string(0, old_bucket.key)) & (h_buckets.length - 1 | 0); let tail = ndata_tail[nidx]; if (tail !== undefined) { tail.next = old_bucket; @@ -25,7 +25,7 @@ function copyBucket(h_buckets, ndata_tail, _old_bucket) { function remove(h, key) { let h_buckets = h.buckets; - let i = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_string(0, key)) & (h_buckets.length - 1 | 0); + let i = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_string(0, key)) & (h_buckets.length - 1 | 0); let l = h_buckets[i]; if (l === undefined) { return; @@ -82,7 +82,7 @@ function addBucket(h, key, _cell) { function add(h, key) { let h_buckets = h.buckets; let buckets_len = h_buckets.length; - let i = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_string(0, key)) & (buckets_len - 1 | 0); + let i = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_string(0, key)) & (buckets_len - 1 | 0); let l = h_buckets[i]; if (l !== undefined) { addBucket(h, key, l); @@ -120,7 +120,7 @@ function add(h, key) { function has(h, key) { let h_buckets = h.buckets; - let nid = Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_string(0, key)) & (h_buckets.length - 1 | 0); + let nid = Primitive_hash.hash_final_mix(Primitive_hash.hash_mix_string(0, key)) & (h_buckets.length - 1 | 0); let bucket = h_buckets[nid]; if (bucket !== undefined) { let _cell = bucket; diff --git a/lib/js/belt_List.js b/lib/js/belt_List.js index 05e7f60db8..5fe5cd5bec 100644 --- a/lib/js/belt_List.js +++ b/lib/js/belt_List.js @@ -1,12 +1,12 @@ 'use strict'; let Belt_Array = require("./belt_Array.js"); -let Caml_option = require("./caml_option.js"); let Belt_SortArray = require("./belt_SortArray.js"); +let Primitive_option = require("./primitive_option.js"); function head(x) { if (x) { - return Caml_option.some(x.hd); + return Primitive_option.some(x.hd); } } @@ -58,7 +58,7 @@ function get(x, n) { return; } if (n$1 === 0) { - return Caml_option.some(x$1.hd); + return Primitive_option.some(x$1.hd); } _n = n$1 - 1 | 0; _x = x$1.tl; @@ -227,7 +227,7 @@ function copyAuxWitFilterMap(f, _cellX, _prec) { let h = f(cellX.hd); if (h !== undefined) { let next = { - hd: Caml_option.valFromOption(h), + hd: Primitive_option.valFromOption(h), tl: /* [] */0 }; prec.tl = next; @@ -1047,7 +1047,7 @@ function getAssoc(_xs, x, eq) { } let match = xs.hd; if (eq(match[0], x)) { - return Caml_option.some(match[1]); + return Primitive_option.some(match[1]); } _xs = xs.tl; continue; @@ -1142,7 +1142,7 @@ function getBy(_xs, p) { } let x = xs.hd; if (p(x)) { - return Caml_option.some(x); + return Primitive_option.some(x); } _xs = xs.tl; continue; @@ -1205,7 +1205,7 @@ function keepMap(_xs, p) { let h = p(xs.hd); if (h !== undefined) { let cell = { - hd: Caml_option.valFromOption(h), + hd: Primitive_option.valFromOption(h), tl: /* [] */0 }; copyAuxWitFilterMap(p, t, cell); diff --git a/lib/js/belt_MapDict.js b/lib/js/belt_MapDict.js index a4581f83e9..b16b5b0cb3 100644 --- a/lib/js/belt_MapDict.js +++ b/lib/js/belt_MapDict.js @@ -1,6 +1,6 @@ 'use strict'; -let Caml_option = require("./caml_option.js"); +let Primitive_option = require("./primitive_option.js"); let Belt_internalAVLtree = require("./belt_internalAVLtree.js"); function set(t, newK, newD, cmp) { @@ -27,9 +27,9 @@ function update(t, newK, f, cmp) { let k = t.k; let c = cmp(newK, k); if (c === 0) { - let newD = f(Caml_option.some(t.v)); + let newD = f(Primitive_option.some(t.v)); if (newD !== undefined) { - return Belt_internalAVLtree.updateValue(t, Caml_option.valFromOption(newD)); + return Belt_internalAVLtree.updateValue(t, Primitive_option.valFromOption(newD)); } let l = t.l; let r = t.r; @@ -68,7 +68,7 @@ function update(t, newK, f, cmp) { } let newD$1 = f(undefined); if (newD$1 !== undefined) { - return Belt_internalAVLtree.singleton(newK, Caml_option.valFromOption(newD$1)); + return Belt_internalAVLtree.singleton(newK, Primitive_option.valFromOption(newD$1)); } else { return t; } @@ -141,7 +141,7 @@ function splitAuxPivot(n, x, pres, cmp) { let r = n.r; let c = cmp(x, v); if (c === 0) { - pres.contents = Caml_option.some(d); + pres.contents = Primitive_option.some(d); return [ l, r @@ -196,13 +196,13 @@ function split(n, x, cmp) { function merge(s1, s2, f, cmp) { if (s1 === undefined) { if (s2 !== undefined) { - return Belt_internalAVLtree.keepMap(s2, (k, v) => f(k, undefined, Caml_option.some(v))); + return Belt_internalAVLtree.keepMap(s2, (k, v) => f(k, undefined, Primitive_option.some(v))); } else { return; } } if (s2 === undefined) { - return Belt_internalAVLtree.keepMap(s1, (k, v) => f(k, Caml_option.some(v), undefined)); + return Belt_internalAVLtree.keepMap(s1, (k, v) => f(k, Primitive_option.some(v), undefined)); } if (s1.h >= s2.h) { let v1 = s1.k; @@ -215,7 +215,7 @@ function merge(s1, s2, f, cmp) { let match = splitAuxPivot(s2, v1, d2, cmp); let d2$1 = d2.contents; let newLeft = merge(l1, match[0], f, cmp); - let newD = f(v1, Caml_option.some(d1), d2$1); + let newD = f(v1, Primitive_option.some(d1), d2$1); let newRight = merge(r1, match[1], f, cmp); return Belt_internalAVLtree.concatOrJoin(newLeft, v1, newD, newRight); } @@ -229,7 +229,7 @@ function merge(s1, s2, f, cmp) { let match$1 = splitAuxPivot(s1, v2, d1$1, cmp); let d1$2 = d1$1.contents; let newLeft$1 = merge(match$1[0], l2, f, cmp); - let newD$1 = f(v2, d1$2, Caml_option.some(d2$2)); + let newD$1 = f(v2, d1$2, Primitive_option.some(d2$2)); let newRight$1 = merge(match$1[1], r2, f, cmp); return Belt_internalAVLtree.concatOrJoin(newLeft$1, v2, newD$1, newRight$1); } diff --git a/lib/js/belt_MapInt.js b/lib/js/belt_MapInt.js index 06da974458..b67dcd350e 100644 --- a/lib/js/belt_MapInt.js +++ b/lib/js/belt_MapInt.js @@ -1,6 +1,6 @@ 'use strict'; -let Caml_option = require("./caml_option.js"); +let Primitive_option = require("./primitive_option.js"); let Belt_internalMapInt = require("./belt_internalMapInt.js"); let Belt_internalAVLtree = require("./belt_internalAVLtree.js"); @@ -24,9 +24,9 @@ function update(t, x, f) { if (t !== undefined) { let k = t.k; if (x === k) { - let data = f(Caml_option.some(t.v)); + let data = f(Primitive_option.some(t.v)); if (data !== undefined) { - return Belt_internalAVLtree.updateValue(t, Caml_option.valFromOption(data)); + return Belt_internalAVLtree.updateValue(t, Primitive_option.valFromOption(data)); } let l = t.l; let r = t.r; @@ -65,7 +65,7 @@ function update(t, x, f) { } let data$1 = f(undefined); if (data$1 !== undefined) { - return Belt_internalAVLtree.singleton(x, Caml_option.valFromOption(data$1)); + return Belt_internalAVLtree.singleton(x, Primitive_option.valFromOption(data$1)); } else { return t; } diff --git a/lib/js/belt_MapString.js b/lib/js/belt_MapString.js index 701e28f63f..8d4c178d90 100644 --- a/lib/js/belt_MapString.js +++ b/lib/js/belt_MapString.js @@ -1,6 +1,6 @@ 'use strict'; -let Caml_option = require("./caml_option.js"); +let Primitive_option = require("./primitive_option.js"); let Belt_internalAVLtree = require("./belt_internalAVLtree.js"); let Belt_internalMapString = require("./belt_internalMapString.js"); @@ -24,9 +24,9 @@ function update(t, x, f) { if (t !== undefined) { let k = t.k; if (x === k) { - let data = f(Caml_option.some(t.v)); + let data = f(Primitive_option.some(t.v)); if (data !== undefined) { - return Belt_internalAVLtree.updateValue(t, Caml_option.valFromOption(data)); + return Belt_internalAVLtree.updateValue(t, Primitive_option.valFromOption(data)); } let l = t.l; let r = t.r; @@ -65,7 +65,7 @@ function update(t, x, f) { } let data$1 = f(undefined); if (data$1 !== undefined) { - return Belt_internalAVLtree.singleton(x, Caml_option.valFromOption(data$1)); + return Belt_internalAVLtree.singleton(x, Primitive_option.valFromOption(data$1)); } else { return t; } diff --git a/lib/js/belt_MutableMap.js b/lib/js/belt_MutableMap.js index 1212025da3..7b6e4d4977 100644 --- a/lib/js/belt_MutableMap.js +++ b/lib/js/belt_MutableMap.js @@ -1,6 +1,6 @@ 'use strict'; -let Caml_option = require("./caml_option.js"); +let Primitive_option = require("./primitive_option.js"); let Belt_internalAVLtree = require("./belt_internalAVLtree.js"); function removeMutateAux(nt, x, cmp) { @@ -90,9 +90,9 @@ function updateDone(t, x, f, cmp) { let k = t.k; let c = cmp(x, k); if (c === 0) { - let data = f(Caml_option.some(t.v)); + let data = f(Primitive_option.some(t.v)); if (data !== undefined) { - t.v = Caml_option.valFromOption(data); + t.v = Primitive_option.valFromOption(data); return t; } let l = t.l; @@ -119,7 +119,7 @@ function updateDone(t, x, f, cmp) { } let data$1 = f(undefined); if (data$1 !== undefined) { - return Belt_internalAVLtree.singleton(x, Caml_option.valFromOption(data$1)); + return Belt_internalAVLtree.singleton(x, Primitive_option.valFromOption(data$1)); } else { return t; } diff --git a/lib/js/belt_MutableMapInt.js b/lib/js/belt_MutableMapInt.js index a45983808d..d2b1bf31cc 100644 --- a/lib/js/belt_MutableMapInt.js +++ b/lib/js/belt_MutableMapInt.js @@ -1,6 +1,6 @@ 'use strict'; -let Caml_option = require("./caml_option.js"); +let Primitive_option = require("./primitive_option.js"); let Belt_internalMapInt = require("./belt_internalMapInt.js"); let Belt_internalAVLtree = require("./belt_internalAVLtree.js"); @@ -168,9 +168,9 @@ function updateDone(t, x, f) { if (t !== undefined) { let k = t.k; if (k === x) { - let data = f(Caml_option.some(t.v)); + let data = f(Primitive_option.some(t.v)); if (data !== undefined) { - t.v = Caml_option.valFromOption(data); + t.v = Primitive_option.valFromOption(data); return t; } let l = t.l; @@ -198,7 +198,7 @@ function updateDone(t, x, f) { } let data$1 = f(undefined); if (data$1 !== undefined) { - return Belt_internalAVLtree.singleton(x, Caml_option.valFromOption(data$1)); + return Belt_internalAVLtree.singleton(x, Primitive_option.valFromOption(data$1)); } else { return t; } diff --git a/lib/js/belt_MutableMapString.js b/lib/js/belt_MutableMapString.js index 2ea626961f..88910e670a 100644 --- a/lib/js/belt_MutableMapString.js +++ b/lib/js/belt_MutableMapString.js @@ -1,6 +1,6 @@ 'use strict'; -let Caml_option = require("./caml_option.js"); +let Primitive_option = require("./primitive_option.js"); let Belt_internalAVLtree = require("./belt_internalAVLtree.js"); let Belt_internalMapString = require("./belt_internalMapString.js"); @@ -168,9 +168,9 @@ function updateDone(t, x, f) { if (t !== undefined) { let k = t.k; if (k === x) { - let data = f(Caml_option.some(t.v)); + let data = f(Primitive_option.some(t.v)); if (data !== undefined) { - t.v = Caml_option.valFromOption(data); + t.v = Primitive_option.valFromOption(data); return t; } let l = t.l; @@ -198,7 +198,7 @@ function updateDone(t, x, f) { } let data$1 = f(undefined); if (data$1 !== undefined) { - return Belt_internalAVLtree.singleton(x, Caml_option.valFromOption(data$1)); + return Belt_internalAVLtree.singleton(x, Primitive_option.valFromOption(data$1)); } else { return t; } diff --git a/lib/js/belt_MutableQueue.js b/lib/js/belt_MutableQueue.js index 45ce2b1b62..999c96ae0d 100644 --- a/lib/js/belt_MutableQueue.js +++ b/lib/js/belt_MutableQueue.js @@ -1,6 +1,6 @@ 'use strict'; -let Caml_option = require("./caml_option.js"); +let Primitive_option = require("./primitive_option.js"); function make() { return { @@ -36,7 +36,7 @@ function add(q, x) { function peek(q) { let v = q.first; if (v !== undefined) { - return Caml_option.some(v.content); + return Primitive_option.some(v.content); } } @@ -68,11 +68,11 @@ function pop(q) { let next = x.next; if (next === undefined) { clear(q); - return Caml_option.some(x.content); + return Primitive_option.some(x.content); } else { q.length = q.length - 1 | 0; q.first = next; - return Caml_option.some(x.content); + return Primitive_option.some(x.content); } } diff --git a/lib/js/belt_MutableSet.js b/lib/js/belt_MutableSet.js index d0e60b2132..25411a9277 100644 --- a/lib/js/belt_MutableSet.js +++ b/lib/js/belt_MutableSet.js @@ -1,5 +1,6 @@ 'use strict'; +let Primitive_int = require("./primitive_int.js"); let Belt_SortArray = require("./belt_SortArray.js"); let Belt_internalAVLset = require("./belt_internalAVLset.js"); @@ -369,7 +370,7 @@ function intersect(a, b) { data: undefined }; } - let tmp2 = new Array(sizea < sizeb ? sizea : sizeb); + let tmp2 = new Array(Primitive_int.min(sizea, sizeb)); let k = Belt_SortArray.intersect(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0, cmp); return { cmp: cmp, diff --git a/lib/js/belt_MutableSetInt.js b/lib/js/belt_MutableSetInt.js index 6bc925689a..3880d01547 100644 --- a/lib/js/belt_MutableSetInt.js +++ b/lib/js/belt_MutableSetInt.js @@ -1,5 +1,6 @@ 'use strict'; +let Primitive_int = require("./primitive_int.js"); let Belt_SortArrayInt = require("./belt_SortArrayInt.js"); let Belt_internalAVLset = require("./belt_internalAVLset.js"); let Belt_internalSetInt = require("./belt_internalSetInt.js"); @@ -350,7 +351,7 @@ function intersect(dataa, datab) { data: undefined }; } - let tmp2 = new Array(sizea < sizeb ? sizea : sizeb); + let tmp2 = new Array(Primitive_int.min(sizea, sizeb)); let k = Belt_SortArrayInt.intersect(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0); return { data: Belt_internalAVLset.fromSortedArrayAux(tmp2, 0, k) diff --git a/lib/js/belt_MutableSetString.js b/lib/js/belt_MutableSetString.js index 1ab76091b1..005dea47db 100644 --- a/lib/js/belt_MutableSetString.js +++ b/lib/js/belt_MutableSetString.js @@ -1,5 +1,6 @@ 'use strict'; +let Primitive_int = require("./primitive_int.js"); let Belt_internalAVLset = require("./belt_internalAVLset.js"); let Belt_SortArrayString = require("./belt_SortArrayString.js"); let Belt_internalSetString = require("./belt_internalSetString.js"); @@ -350,7 +351,7 @@ function intersect(dataa, datab) { data: undefined }; } - let tmp2 = new Array(sizea < sizeb ? sizea : sizeb); + let tmp2 = new Array(Primitive_int.min(sizea, sizeb)); let k = Belt_SortArrayString.intersect(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0); return { data: Belt_internalAVLset.fromSortedArrayAux(tmp2, 0, k) diff --git a/lib/js/belt_MutableStack.js b/lib/js/belt_MutableStack.js index d8ed800e49..415911a4b3 100644 --- a/lib/js/belt_MutableStack.js +++ b/lib/js/belt_MutableStack.js @@ -1,6 +1,6 @@ 'use strict'; -let Caml_option = require("./caml_option.js"); +let Primitive_option = require("./primitive_option.js"); function make() { return { @@ -36,7 +36,7 @@ function topUndefined(s) { function top(s) { let x = s.root; if (x !== undefined) { - return Caml_option.some(x.head); + return Primitive_option.some(x.head); } } @@ -58,7 +58,7 @@ function pop(s) { let x = s.root; if (x !== undefined) { s.root = x.tail; - return Caml_option.some(x.head); + return Primitive_option.some(x.head); } } diff --git a/lib/js/belt_Option.js b/lib/js/belt_Option.js index c4f301c2b5..ed53a51192 100644 --- a/lib/js/belt_Option.js +++ b/lib/js/belt_Option.js @@ -1,9 +1,9 @@ 'use strict'; -let Caml_option = require("./caml_option.js"); +let Primitive_option = require("./primitive_option.js"); function keep(opt, p) { - if (opt !== undefined && p(Caml_option.valFromOption(opt))) { + if (opt !== undefined && p(Primitive_option.valFromOption(opt))) { return opt; } @@ -11,14 +11,14 @@ function keep(opt, p) { function forEach(opt, f) { if (opt !== undefined) { - return f(Caml_option.valFromOption(opt)); + return f(Primitive_option.valFromOption(opt)); } } function getExn(x) { if (x !== undefined) { - return Caml_option.valFromOption(x); + return Primitive_option.valFromOption(x); } throw { RE_EXN_ID: "Not_found", @@ -28,7 +28,7 @@ function getExn(x) { function mapWithDefault(opt, $$default, f) { if (opt !== undefined) { - return f(Caml_option.valFromOption(opt)); + return f(Primitive_option.valFromOption(opt)); } else { return $$default; } @@ -36,21 +36,21 @@ function mapWithDefault(opt, $$default, f) { function map(opt, f) { if (opt !== undefined) { - return Caml_option.some(f(Caml_option.valFromOption(opt))); + return Primitive_option.some(f(Primitive_option.valFromOption(opt))); } } function flatMap(opt, f) { if (opt !== undefined) { - return f(Caml_option.valFromOption(opt)); + return f(Primitive_option.valFromOption(opt)); } } function getWithDefault(opt, $$default) { if (opt !== undefined) { - return Caml_option.valFromOption(opt); + return Primitive_option.valFromOption(opt); } else { return $$default; } @@ -75,7 +75,7 @@ function isNone(x) { function eq(a, b, f) { if (a !== undefined) { if (b !== undefined) { - return f(Caml_option.valFromOption(a), Caml_option.valFromOption(b)); + return f(Primitive_option.valFromOption(a), Primitive_option.valFromOption(b)); } else { return false; } @@ -87,7 +87,7 @@ function eq(a, b, f) { function cmp(a, b, f) { if (a !== undefined) { if (b !== undefined) { - return f(Caml_option.valFromOption(a), Caml_option.valFromOption(b)); + return f(Primitive_option.valFromOption(a), Primitive_option.valFromOption(b)); } else { return 1; } diff --git a/lib/js/belt_internalAVLset.js b/lib/js/belt_internalAVLset.js index 3580ec8f6c..c80999536d 100644 --- a/lib/js/belt_internalAVLset.js +++ b/lib/js/belt_internalAVLset.js @@ -1,7 +1,8 @@ 'use strict'; -let Caml_option = require("./caml_option.js"); +let Primitive_int = require("./primitive_int.js"); let Belt_SortArray = require("./belt_SortArray.js"); +let Primitive_option = require("./primitive_option.js"); function copy(n) { if (n !== undefined) { @@ -95,7 +96,7 @@ function min0Aux(_n) { function minimum(n) { if (n !== undefined) { - return Caml_option.some(min0Aux(n)); + return Primitive_option.some(min0Aux(n)); } } @@ -121,7 +122,7 @@ function max0Aux(_n) { function maximum(n) { if (n !== undefined) { - return Caml_option.some(max0Aux(n)); + return Primitive_option.some(max0Aux(n)); } } @@ -664,7 +665,7 @@ function get(_n, x, cmp) { let v = n.v; let c = cmp(x, v); if (c === 0) { - return Caml_option.some(v); + return Primitive_option.some(v); } _n = c < 0 ? n.l : n.r; continue; @@ -714,15 +715,11 @@ function rotateWithLeftChild(k2) { let hlk2 = n !== undefined ? n.h : 0; let n$1 = k2.r; let hrk2 = n$1 !== undefined ? n$1.h : 0; - k2.h = ( - hlk2 > hrk2 ? hlk2 : hrk2 - ) + 1 | 0; + k2.h = Primitive_int.max(hlk2, hrk2) + 1 | 0; let n$2 = k1.l; let hlk1 = n$2 !== undefined ? n$2.h : 0; let hk2 = k2.h; - k1.h = ( - hlk1 > hk2 ? hlk1 : hk2 - ) + 1 | 0; + k1.h = Primitive_int.max(hlk1, hk2) + 1 | 0; return k1; } @@ -734,15 +731,11 @@ function rotateWithRightChild(k1) { let hlk1 = n !== undefined ? n.h : 0; let n$1 = k1.r; let hrk1 = n$1 !== undefined ? n$1.h : 0; - k1.h = ( - hlk1 > hrk1 ? hlk1 : hrk1 - ) + 1 | 0; + k1.h = Primitive_int.max(hlk1, hrk1) + 1 | 0; let n$2 = k2.r; let hrk2 = n$2 !== undefined ? n$2.h : 0; let hk1 = k1.h; - k2.h = ( - hrk2 > hk1 ? hrk2 : hk1 - ) + 1 | 0; + k2.h = Primitive_int.max(hrk2, hk1) + 1 | 0; return k2; } @@ -765,9 +758,7 @@ function heightUpdateMutate(t) { let hlt = n !== undefined ? n.h : 0; let n$1 = t.r; let hrt = n$1 !== undefined ? n$1.h : 0; - t.h = ( - hlt > hrt ? hlt : hrt - ) + 1 | 0; + t.h = Primitive_int.max(hlt, hrt) + 1 | 0; return t; } @@ -794,9 +785,7 @@ function balMutate(nt) { return heightUpdateMutate(doubleWithRightChild(nt)); } } - nt.h = ( - hl > hr ? hl : hr - ) + 1 | 0; + nt.h = Primitive_int.max(hl, hr) + 1 | 0; return nt; } diff --git a/lib/js/belt_internalAVLtree.js b/lib/js/belt_internalAVLtree.js index 9fd0ebe1bf..6bf32cb647 100644 --- a/lib/js/belt_internalAVLtree.js +++ b/lib/js/belt_internalAVLtree.js @@ -1,7 +1,8 @@ 'use strict'; -let Caml_option = require("./caml_option.js"); +let Primitive_int = require("./primitive_int.js"); let Belt_SortArray = require("./belt_SortArray.js"); +let Primitive_option = require("./primitive_option.js"); function treeHeight(n) { if (n !== undefined) { @@ -117,7 +118,7 @@ function minKey0Aux(_n) { function minKey(n) { if (n !== undefined) { - return Caml_option.some(minKey0Aux(n)); + return Primitive_option.some(minKey0Aux(n)); } } @@ -143,7 +144,7 @@ function maxKey0Aux(_n) { function maxKey(n) { if (n !== undefined) { - return Caml_option.some(maxKey0Aux(n)); + return Primitive_option.some(maxKey0Aux(n)); } } @@ -426,7 +427,7 @@ function concat(t1, t2) { function concatOrJoin(t1, v, d, t2) { if (d !== undefined) { - return join(t1, v, Caml_option.valFromOption(d), t2); + return join(t1, v, Primitive_option.valFromOption(d), t2); } else { return concat(t1, t2); } @@ -458,7 +459,7 @@ function keepMap(n, p) { let pvd = p(v, d); let newRight = keepMap(n.r, p); if (pvd !== undefined) { - return join(newLeft, v, Caml_option.valFromOption(pvd), newRight); + return join(newLeft, v, Primitive_option.valFromOption(pvd), newRight); } else { return concat(newLeft, newRight); } @@ -813,7 +814,7 @@ function get(_n, x, cmp) { let v = n.k; let c = cmp(x, v); if (c === 0) { - return Caml_option.some(n.v); + return Primitive_option.some(n.v); } _n = c < 0 ? n.l : n.r; continue; @@ -893,14 +894,10 @@ function rotateWithLeftChild(k2) { k1.r = k2; let hlk2 = treeHeight(k2.l); let hrk2 = treeHeight(k2.r); - k2.h = ( - hlk2 > hrk2 ? hlk2 : hrk2 - ) + 1 | 0; + k2.h = Primitive_int.max(hlk2, hrk2) + 1 | 0; let hlk1 = treeHeight(k1.l); let hk2 = k2.h; - k1.h = ( - hlk1 > hk2 ? hlk1 : hk2 - ) + 1 | 0; + k1.h = Primitive_int.max(hlk1, hk2) + 1 | 0; return k1; } @@ -910,14 +907,10 @@ function rotateWithRightChild(k1) { k2.l = k1; let hlk1 = treeHeight(k1.l); let hrk1 = treeHeight(k1.r); - k1.h = ( - hlk1 > hrk1 ? hlk1 : hrk1 - ) + 1 | 0; + k1.h = Primitive_int.max(hlk1, hrk1) + 1 | 0; let hrk2 = treeHeight(k2.r); let hk1 = k1.h; - k2.h = ( - hrk2 > hk1 ? hrk2 : hk1 - ) + 1 | 0; + k2.h = Primitive_int.max(hrk2, hk1) + 1 | 0; return k2; } @@ -938,9 +931,7 @@ function doubleWithRightChild(k2) { function heightUpdateMutate(t) { let hlt = treeHeight(t.l); let hrt = treeHeight(t.r); - t.h = ( - hlt > hrt ? hlt : hrt - ) + 1 | 0; + t.h = Primitive_int.max(hlt, hrt) + 1 | 0; return t; } @@ -967,9 +958,7 @@ function balMutate(nt) { return heightUpdateMutate(doubleWithRightChild(nt)); } } - nt.h = ( - hl > hr ? hl : hr - ) + 1 | 0; + nt.h = Primitive_int.max(hl, hr) + 1 | 0; return nt; } diff --git a/lib/js/belt_internalBuckets.js b/lib/js/belt_internalBuckets.js index 159c1934fd..20b2dfa577 100644 --- a/lib/js/belt_internalBuckets.js +++ b/lib/js/belt_internalBuckets.js @@ -1,7 +1,8 @@ 'use strict'; let Belt_Array = require("./belt_Array.js"); -let Caml_option = require("./caml_option.js"); +let Primitive_int = require("./primitive_int.js"); +let Primitive_option = require("./primitive_option.js"); function copyAuxCont(_c, _prec) { while (true) { @@ -110,11 +111,7 @@ function reduce(h, init, f) { function getMaxBucketLength(h) { return Belt_Array.reduce(h.buckets, 0, (m, b) => { let len = bucketLength(0, b); - if (m > len) { - return m; - } else { - return len; - } + return Primitive_int.max(m, len); }); } @@ -149,7 +146,7 @@ function filterMapInplaceBucket(f, h, i, _prec, _cell) { } else { h.buckets[i] = cell; } - cell.value = Caml_option.valFromOption(data); + cell.value = Primitive_option.valFromOption(data); if (n === undefined) { cell.next = n; return; diff --git a/lib/js/belt_internalMapInt.js b/lib/js/belt_internalMapInt.js index 969acf741e..ef18962030 100644 --- a/lib/js/belt_internalMapInt.js +++ b/lib/js/belt_internalMapInt.js @@ -1,8 +1,8 @@ 'use strict'; -let Caml = require("./caml.js"); -let Caml_option = require("./caml_option.js"); +let Primitive_int = require("./primitive_int.js"); let Belt_SortArray = require("./belt_SortArray.js"); +let Primitive_option = require("./primitive_option.js"); let Belt_internalAVLtree = require("./belt_internalAVLtree.js"); function add(t, x, data) { @@ -29,7 +29,7 @@ function get(_n, x) { } let v = n.k; if (x === v) { - return Caml_option.some(n.v); + return Primitive_option.some(n.v); } _n = x < v ? n.l : n.r; continue; @@ -137,7 +137,7 @@ function splitAux(x, n) { if (x === v) { return [ l, - Caml_option.some(d), + Primitive_option.some(d), r ]; } @@ -193,7 +193,7 @@ function merge(s1, s2, f) { let l1 = s1.l; let r1 = s1.r; let match = split(v1, s2); - return Belt_internalAVLtree.concatOrJoin(merge(l1, match[0], f), v1, f(v1, Caml_option.some(d1), match[1]), merge(r1, match[2], f)); + return Belt_internalAVLtree.concatOrJoin(merge(l1, match[0], f), v1, f(v1, Primitive_option.some(d1), match[1]), merge(r1, match[2], f)); } } else if (s2 === undefined) { @@ -204,7 +204,7 @@ function merge(s1, s2, f) { let l2 = s2.l; let r2 = s2.r; let match$1 = split(v2, s1); - return Belt_internalAVLtree.concatOrJoin(merge(match$1[0], l2, f), v2, f(v2, match$1[1], Caml_option.some(d2)), merge(match$1[2], r2, f)); + return Belt_internalAVLtree.concatOrJoin(merge(match$1[0], l2, f), v2, f(v2, match$1[1], Primitive_option.some(d2)), merge(match$1[2], r2, f)); } function compareAux(_e1, _e2, vcmp) { @@ -219,7 +219,7 @@ function compareAux(_e1, _e2, vcmp) { } let h2 = e2.hd; let h1 = e1.hd; - let c = Caml.int_compare(h1.k, h2.k); + let c = Primitive_int.compare(h1.k, h2.k); if (c !== 0) { return c; } diff --git a/lib/js/belt_internalMapString.js b/lib/js/belt_internalMapString.js index a371514a69..c894e33e3c 100644 --- a/lib/js/belt_internalMapString.js +++ b/lib/js/belt_internalMapString.js @@ -1,8 +1,8 @@ 'use strict'; -let Caml = require("./caml.js"); -let Caml_option = require("./caml_option.js"); let Belt_SortArray = require("./belt_SortArray.js"); +let Primitive_option = require("./primitive_option.js"); +let Primitive_string = require("./primitive_string.js"); let Belt_internalAVLtree = require("./belt_internalAVLtree.js"); function add(t, x, data) { @@ -29,7 +29,7 @@ function get(_n, x) { } let v = n.k; if (x === v) { - return Caml_option.some(n.v); + return Primitive_option.some(n.v); } _n = x < v ? n.l : n.r; continue; @@ -137,7 +137,7 @@ function splitAux(x, n) { if (x === v) { return [ l, - Caml_option.some(d), + Primitive_option.some(d), r ]; } @@ -193,7 +193,7 @@ function merge(s1, s2, f) { let l1 = s1.l; let r1 = s1.r; let match = split(v1, s2); - return Belt_internalAVLtree.concatOrJoin(merge(l1, match[0], f), v1, f(v1, Caml_option.some(d1), match[1]), merge(r1, match[2], f)); + return Belt_internalAVLtree.concatOrJoin(merge(l1, match[0], f), v1, f(v1, Primitive_option.some(d1), match[1]), merge(r1, match[2], f)); } } else if (s2 === undefined) { @@ -204,7 +204,7 @@ function merge(s1, s2, f) { let l2 = s2.l; let r2 = s2.r; let match$1 = split(v2, s1); - return Belt_internalAVLtree.concatOrJoin(merge(match$1[0], l2, f), v2, f(v2, match$1[1], Caml_option.some(d2)), merge(match$1[2], r2, f)); + return Belt_internalAVLtree.concatOrJoin(merge(match$1[0], l2, f), v2, f(v2, match$1[1], Primitive_option.some(d2)), merge(match$1[2], r2, f)); } function compareAux(_e1, _e2, vcmp) { @@ -219,7 +219,7 @@ function compareAux(_e1, _e2, vcmp) { } let h2 = e2.hd; let h1 = e1.hd; - let c = Caml.string_compare(h1.k, h2.k); + let c = Primitive_string.compare(h1.k, h2.k); if (c !== 0) { return c; } diff --git a/lib/js/belt_internalSetBuckets.js b/lib/js/belt_internalSetBuckets.js index c899bd03dd..b34bd00fa2 100644 --- a/lib/js/belt_internalSetBuckets.js +++ b/lib/js/belt_internalSetBuckets.js @@ -1,6 +1,19 @@ 'use strict'; let Belt_Array = require("./belt_Array.js"); +let Primitive_int = require("./primitive_int.js"); + +function copyBucket(c) { + if (c === undefined) { + return c; + } + let head = { + key: c.key, + next: undefined + }; + copyAuxCont(c.next, head); + return head; +} function copyAuxCont(_c, _prec) { while (true) { @@ -20,18 +33,6 @@ function copyAuxCont(_c, _prec) { }; } -function copyBucket(c) { - if (c === undefined) { - return c; - } - let head = { - key: c.key, - next: undefined - }; - copyAuxCont(c.next, head); - return head; -} - function copyBuckets(buckets) { let len = buckets.length; let newBuckets = new Array(len); @@ -136,11 +137,7 @@ function reduce(h, init, f) { function getMaxBucketLength(h) { return Belt_Array.reduce(h.buckets, 0, (m, b) => { let len = bucketLength(0, b); - if (m > len) { - return m; - } else { - return len; - } + return Primitive_int.max(m, len); }); } diff --git a/lib/js/buffer.js b/lib/js/buffer.js deleted file mode 100644 index 6eedc8ab79..0000000000 --- a/lib/js/buffer.js +++ /dev/null @@ -1,474 +0,0 @@ -'use strict'; - -let Bytes = require("./bytes.js"); -let $$String = require("./string.js"); -let Caml_bytes = require("./caml_bytes.js"); -let Caml_string = require("./caml_string.js"); - -function create(n) { - let n$1 = n < 1 ? 1 : n; - let s = Caml_bytes.create(n$1); - return { - buffer: s, - position: 0, - length: n$1, - initial_buffer: s - }; -} - -function contents(b) { - return Bytes.sub_string(b.buffer, 0, b.position); -} - -function to_bytes(b) { - return Bytes.sub(b.buffer, 0, b.position); -} - -function sub(b, ofs, len) { - if (ofs < 0 || len < 0 || ofs > (b.position - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Buffer.sub", - Error: new Error() - }; - } - return Bytes.sub_string(b.buffer, ofs, len); -} - -function blit(src, srcoff, dst, dstoff, len) { - if (len < 0 || srcoff < 0 || srcoff > (src.position - len | 0) || dstoff < 0 || dstoff > (dst.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Buffer.blit", - Error: new Error() - }; - } - Bytes.blit(src.buffer, srcoff, dst, dstoff, len); -} - -function nth(b, ofs) { - if (ofs < 0 || ofs >= b.position) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Buffer.nth", - Error: new Error() - }; - } - return b.buffer[ofs]; -} - -function length(b) { - return b.position; -} - -function clear(b) { - b.position = 0; -} - -function reset(b) { - b.position = 0; - b.buffer = b.initial_buffer; - b.length = b.buffer.length; -} - -function resize(b, more) { - let len = b.length; - let new_len = len; - while ((b.position + more | 0) > new_len) { - new_len = (new_len << 1); - }; - let new_buffer = Caml_bytes.create(new_len); - Bytes.blit(b.buffer, 0, new_buffer, 0, b.position); - b.buffer = new_buffer; - b.length = new_len; -} - -function add_char(b, c) { - let pos = b.position; - if (pos >= b.length) { - resize(b, 1); - } - b.buffer[pos] = c; - b.position = pos + 1 | 0; -} - -function add_utf_8_uchar(b, u) { - let u$1 = u; - if (u$1 < 0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "buffer.res", - 98, - 18 - ], - Error: new Error() - }; - } - if (u$1 <= 127) { - return add_char(b, u$1); - } - if (u$1 <= 2047) { - let pos = b.position; - if ((pos + 2 | 0) > b.length) { - resize(b, 2); - } - b.buffer[pos] = 192 | (u$1 >>> 6); - b.buffer[pos + 1 | 0] = 128 | u$1 & 63; - b.position = pos + 2 | 0; - return; - } - if (u$1 <= 65535) { - let pos$1 = b.position; - if ((pos$1 + 3 | 0) > b.length) { - resize(b, 3); - } - b.buffer[pos$1] = 224 | (u$1 >>> 12); - b.buffer[pos$1 + 1 | 0] = 128 | (u$1 >>> 6) & 63; - b.buffer[pos$1 + 2 | 0] = 128 | u$1 & 63; - b.position = pos$1 + 3 | 0; - return; - } - if (u$1 <= 1114111) { - let pos$2 = b.position; - if ((pos$2 + 4 | 0) > b.length) { - resize(b, 4); - } - b.buffer[pos$2] = 240 | (u$1 >>> 18); - b.buffer[pos$2 + 1 | 0] = 128 | (u$1 >>> 12) & 63; - b.buffer[pos$2 + 2 | 0] = 128 | (u$1 >>> 6) & 63; - b.buffer[pos$2 + 3 | 0] = 128 | u$1 & 63; - b.position = pos$2 + 4 | 0; - return; - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "buffer.res", - 127, - 9 - ], - Error: new Error() - }; -} - -function add_utf_16be_uchar(b, u) { - let u$1 = u; - if (u$1 < 0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "buffer.res", - 132, - 18 - ], - Error: new Error() - }; - } - if (u$1 <= 65535) { - let pos = b.position; - if ((pos + 2 | 0) > b.length) { - resize(b, 2); - } - b.buffer[pos] = (u$1 >>> 8); - b.buffer[pos + 1 | 0] = u$1 & 255; - b.position = pos + 2 | 0; - return; - } - if (u$1 <= 1114111) { - let u$p = u$1 - 65536 | 0; - let hi = 55296 | (u$p >>> 10); - let lo = 56320 | u$p & 1023; - let pos$1 = b.position; - if ((pos$1 + 4 | 0) > b.length) { - resize(b, 4); - } - b.buffer[pos$1] = (hi >>> 8); - b.buffer[pos$1 + 1 | 0] = hi & 255; - b.buffer[pos$1 + 2 | 0] = (lo >>> 8); - b.buffer[pos$1 + 3 | 0] = lo & 255; - b.position = pos$1 + 4 | 0; - return; - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "buffer.res", - 154, - 9 - ], - Error: new Error() - }; -} - -function add_utf_16le_uchar(b, u) { - let u$1 = u; - if (u$1 < 0) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "buffer.res", - 159, - 18 - ], - Error: new Error() - }; - } - if (u$1 <= 65535) { - let pos = b.position; - if ((pos + 2 | 0) > b.length) { - resize(b, 2); - } - b.buffer[pos] = u$1 & 255; - b.buffer[pos + 1 | 0] = (u$1 >>> 8); - b.position = pos + 2 | 0; - return; - } - if (u$1 <= 1114111) { - let u$p = u$1 - 65536 | 0; - let hi = 55296 | (u$p >>> 10); - let lo = 56320 | u$p & 1023; - let pos$1 = b.position; - if ((pos$1 + 4 | 0) > b.length) { - resize(b, 4); - } - b.buffer[pos$1] = hi & 255; - b.buffer[pos$1 + 1 | 0] = (hi >>> 8); - b.buffer[pos$1 + 2 | 0] = lo & 255; - b.buffer[pos$1 + 3 | 0] = (lo >>> 8); - b.position = pos$1 + 4 | 0; - return; - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "buffer.res", - 181, - 9 - ], - Error: new Error() - }; -} - -function add_substring(b, s, offset, len) { - if (offset < 0 || len < 0 || offset > (s.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Buffer.add_substring/add_subbytes", - Error: new Error() - }; - } - let new_position = b.position + len | 0; - if (new_position > b.length) { - resize(b, len); - } - Bytes.blit_string(s, offset, b.buffer, b.position, len); - b.position = new_position; -} - -function add_subbytes(b, s, offset, len) { - add_substring(b, Bytes.unsafe_to_string(s), offset, len); -} - -function add_string(b, s) { - let len = s.length; - let new_position = b.position + len | 0; - if (new_position > b.length) { - resize(b, len); - } - Bytes.blit_string(s, 0, b.buffer, b.position, len); - b.position = new_position; -} - -function add_bytes(b, s) { - add_string(b, Bytes.unsafe_to_string(s)); -} - -function add_buffer(b, bs) { - add_subbytes(b, bs.buffer, 0, bs.position); -} - -function closing(param) { - if (param === 40) { - return /* ')' */41; - } - if (param === 123) { - return /* '}' */125; - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "buffer.res", - 216, - 9 - ], - Error: new Error() - }; -} - -function advance_to_closing(opening, closing, k, s, start) { - let _k = k; - let _i = start; - let lim = s.length; - while (true) { - let i = _i; - let k$1 = _k; - if (i >= lim) { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - if (Caml_string.get(s, i) === opening) { - _i = i + 1 | 0; - _k = k$1 + 1 | 0; - continue; - } - if (Caml_string.get(s, i) === closing) { - if (k$1 === 0) { - return i; - } - _i = i + 1 | 0; - _k = k$1 - 1 | 0; - continue; - } - _i = i + 1 | 0; - continue; - }; -} - -function advance_to_non_alpha(s, start) { - let _i = start; - let lim = s.length; - while (true) { - let i = _i; - if (i >= lim) { - return lim; - } - let match = Caml_string.get(s, i); - if (match >= 91) { - if (match >= 97) { - if (match >= 123) { - return i; - } - - } else if (match !== 95) { - return i; - } - - } else if (match >= 58) { - if (match < 65) { - return i; - } - - } else if (match < 48) { - return i; - } - _i = i + 1 | 0; - continue; - }; -} - -function find_ident(s, start, lim) { - if (start >= lim) { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let c = Caml_string.get(s, start); - if (c !== 40 && c !== 123) { - let stop = advance_to_non_alpha(s, start + 1 | 0); - return [ - $$String.sub(s, start, stop - start | 0), - stop - ]; - } - let new_start = start + 1 | 0; - let stop$1 = advance_to_closing(c, closing(c), 0, s, new_start); - return [ - $$String.sub(s, new_start, (stop$1 - start | 0) - 1 | 0), - stop$1 + 1 | 0 - ]; -} - -function add_substitute(b, f, s) { - let lim = s.length; - let _previous = /* ' ' */32; - let _i = 0; - while (true) { - let i = _i; - let previous = _previous; - if (i >= lim) { - if (previous === /* '\\' */92) { - return add_char(b, previous); - } else { - return; - } - } - let current = Caml_string.get(s, i); - if (current !== 36) { - if (previous === /* '\\' */92) { - add_char(b, /* '\\' */92); - add_char(b, current); - _i = i + 1 | 0; - _previous = /* ' ' */32; - continue; - } - if (current !== 92) { - add_char(b, current); - _i = i + 1 | 0; - _previous = current; - continue; - } - _i = i + 1 | 0; - _previous = current; - continue; - } - if (previous === /* '\\' */92) { - add_char(b, current); - _i = i + 1 | 0; - _previous = /* ' ' */32; - continue; - } - let j = i + 1 | 0; - let match = find_ident(s, j, lim); - add_string(b, f(match[0])); - _i = match[1]; - _previous = /* ' ' */32; - continue; - }; -} - -function truncate(b, len) { - if (len < 0 || len > b.position) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Buffer.truncate", - Error: new Error() - }; - } - b.position = len; -} - -exports.create = create; -exports.contents = contents; -exports.to_bytes = to_bytes; -exports.sub = sub; -exports.blit = blit; -exports.nth = nth; -exports.length = length; -exports.clear = clear; -exports.reset = reset; -exports.add_char = add_char; -exports.add_utf_8_uchar = add_utf_8_uchar; -exports.add_utf_16le_uchar = add_utf_16le_uchar; -exports.add_utf_16be_uchar = add_utf_16be_uchar; -exports.add_string = add_string; -exports.add_bytes = add_bytes; -exports.add_substring = add_substring; -exports.add_subbytes = add_subbytes; -exports.add_substitute = add_substitute; -exports.add_buffer = add_buffer; -exports.truncate = truncate; -/* No side effect */ diff --git a/lib/js/bytes.js b/lib/js/bytes.js deleted file mode 100644 index 13d10fe842..0000000000 --- a/lib/js/bytes.js +++ /dev/null @@ -1,697 +0,0 @@ -'use strict'; - -let Caml = require("./caml.js"); -let Char = require("./char.js"); -let Caml_bytes = require("./caml_bytes.js"); -let Caml_js_exceptions = require("./caml_js_exceptions.js"); - -function unsafe_fill(s, i, l, c) { - if (l <= 0) { - return; - } - for (let k = i, k_finish = l + i | 0; k < k_finish; ++k) { - s[k] = c; - } -} - -function unsafe_blit(s1, i1, s2, i2, len) { - if (len <= 0) { - return; - } - if (s1 === s2) { - if (i1 < i2) { - let range_a = (s1.length - i2 | 0) - 1 | 0; - let range_b = len - 1 | 0; - let range = range_a > range_b ? range_b : range_a; - for (let j = range; j >= 0; --j) { - s1[i2 + j | 0] = s1[i1 + j | 0]; - } - return; - } - if (i1 <= i2) { - return; - } - let range_a$1 = (s1.length - i1 | 0) - 1 | 0; - let range_b$1 = len - 1 | 0; - let range$1 = range_a$1 > range_b$1 ? range_b$1 : range_a$1; - for (let k = 0; k <= range$1; ++k) { - s1[i2 + k | 0] = s1[i1 + k | 0]; - } - return; - } - let off1 = s1.length - i1 | 0; - if (len <= off1) { - for (let i = 0; i < len; ++i) { - s2[i2 + i | 0] = s1[i1 + i | 0]; - } - return; - } - for (let i$1 = 0; i$1 < off1; ++i$1) { - s2[i2 + i$1 | 0] = s1[i1 + i$1 | 0]; - } - for (let i$2 = off1; i$2 < len; ++i$2) { - s2[i2 + i$2 | 0] = /* '\000' */0; - } -} - -function make(n, c) { - let s = Caml_bytes.create(n); - unsafe_fill(s, 0, n, c); - return s; -} - -function init(n, f) { - let s = Caml_bytes.create(n); - for (let i = 0; i < n; ++i) { - s[i] = f(i); - } - return s; -} - -let empty = []; - -function copy(s) { - let len = s.length; - let r = Caml_bytes.create(len); - unsafe_blit(s, 0, r, 0, len); - return r; -} - -function to_string(a) { - let i = 0; - let len = a.length; - let s = ""; - let s_len = len; - if (i === 0 && len <= 4096 && len === a.length) { - return String.fromCharCode.apply(null, a); - } - let offset = 0; - while (s_len > 0) { - let next = s_len < 1024 ? s_len : 1024; - let tmp_bytes = new Array(next); - for (let k = 0; k < next; ++k) { - tmp_bytes[k] = a[k + offset | 0]; - } - s = s + String.fromCharCode.apply(null, tmp_bytes); - s_len = s_len - next | 0; - offset = offset + next | 0; - }; - return s; -} - -function of_string(s) { - let len = s.length; - let res = new Array(len); - for (let i = 0; i < len; ++i) { - res[i] = s.codePointAt(i); - } - return res; -} - -function sub(s, ofs, len) { - if (ofs < 0 || len < 0 || ofs > (s.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.sub / Bytes.sub", - Error: new Error() - }; - } - let r = Caml_bytes.create(len); - unsafe_blit(s, ofs, r, 0, len); - return r; -} - -function sub_string(b, ofs, len) { - return to_string(sub(b, ofs, len)); -} - -function $plus$plus(a, b) { - let c = a + b | 0; - let match = a < 0; - let match$1 = b < 0; - let match$2 = c < 0; - if (match) { - if (!match$1) { - return c; - } - if (match$2) { - return c; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Bytes.extend", - Error: new Error() - }; - } - if (match$1) { - return c; - } - if (match$2) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Bytes.extend", - Error: new Error() - }; - } - return c; -} - -function extend(s, left, right) { - let len = $plus$plus($plus$plus(s.length, left), right); - let r = Caml_bytes.create(len); - let match = left < 0 ? [ - -left | 0, - 0 - ] : [ - 0, - left - ]; - let dstoff = match[1]; - let srcoff = match[0]; - let cpylen = Caml.int_min(s.length - srcoff | 0, len - dstoff | 0); - if (cpylen > 0) { - unsafe_blit(s, srcoff, r, dstoff, cpylen); - } - return r; -} - -function fill(s, ofs, len, c) { - if (ofs < 0 || len < 0 || ofs > (s.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.fill / Bytes.fill", - Error: new Error() - }; - } - unsafe_fill(s, ofs, len, c); -} - -function blit(s1, ofs1, s2, ofs2, len) { - if (len < 0 || ofs1 < 0 || ofs1 > (s1.length - len | 0) || ofs2 < 0 || ofs2 > (s2.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Bytes.blit", - Error: new Error() - }; - } - unsafe_blit(s1, ofs1, s2, ofs2, len); -} - -function blit_string(s1, ofs1, s2, ofs2, len) { - if (len < 0 || ofs1 < 0 || ofs1 > (s1.length - len | 0) || ofs2 < 0 || ofs2 > (s2.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.blit / Bytes.blit_string", - Error: new Error() - }; - } - if (len <= 0) { - return; - } - let off1 = s1.length - ofs1 | 0; - if (len <= off1) { - for (let i = 0; i < len; ++i) { - s2[ofs2 + i | 0] = s1.codePointAt(ofs1 + i | 0); - } - return; - } - for (let i$1 = 0; i$1 < off1; ++i$1) { - s2[ofs2 + i$1 | 0] = s1.codePointAt(ofs1 + i$1 | 0); - } - for (let i$2 = off1; i$2 < len; ++i$2) { - s2[ofs2 + i$2 | 0] = /* '\000' */0; - } -} - -function iter(f, a) { - for (let i = 0, i_finish = a.length; i < i_finish; ++i) { - f(a[i]); - } -} - -function iteri(f, a) { - for (let i = 0, i_finish = a.length; i < i_finish; ++i) { - f(i, a[i]); - } -} - -function ensure_ge(x, y) { - if (x >= y) { - return x; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Bytes.concat", - Error: new Error() - }; -} - -function sum_lengths(_acc, seplen, _param) { - while (true) { - let param = _param; - let acc = _acc; - if (!param) { - return acc; - } - let tl = param.tl; - let hd = param.hd; - if (!tl) { - return hd.length + acc | 0; - } - _param = tl; - _acc = ensure_ge((hd.length + seplen | 0) + acc | 0, acc); - continue; - }; -} - -function concat(sep, param) { - if (!param) { - return empty; - } - let seplen = sep.length; - let dst = Caml_bytes.create(sum_lengths(0, seplen, param)); - let _pos = 0; - let _param = param; - while (true) { - let param$1 = _param; - let pos = _pos; - if (!param$1) { - return dst; - } - let tl = param$1.tl; - let hd = param$1.hd; - if (tl) { - unsafe_blit(hd, 0, dst, pos, hd.length); - unsafe_blit(sep, 0, dst, pos + hd.length | 0, seplen); - _param = tl; - _pos = (pos + hd.length | 0) + seplen | 0; - continue; - } - unsafe_blit(hd, 0, dst, pos, hd.length); - return dst; - }; -} - -function cat(s1, s2) { - let l1 = s1.length; - let l2 = s2.length; - let r = Caml_bytes.create(l1 + l2 | 0); - unsafe_blit(s1, 0, r, 0, l1); - unsafe_blit(s2, 0, r, l1, l2); - return r; -} - -function is_space(param) { - if (param > 13 || param < 9) { - return param === 32; - } else { - return param !== 11; - } -} - -function trim(s) { - let len = s.length; - let i = 0; - while (i < len && is_space(s[i])) { - i = i + 1 | 0; - }; - let j = len - 1 | 0; - while (j >= i && is_space(s[j])) { - j = j - 1 | 0; - }; - if (j >= i) { - return sub(s, i, (j - i | 0) + 1 | 0); - } else { - return empty; - } -} - -function escaped(s) { - let n = 0; - for (let i = 0, i_finish = s.length; i < i_finish; ++i) { - let match = s[i]; - n = n + ( - match >= 32 ? ( - match > 92 || match < 34 ? ( - match >= 127 ? 4 : 1 - ) : ( - match > 91 || match < 35 ? 2 : 1 - ) - ) : ( - match >= 11 ? ( - match !== 13 ? 4 : 2 - ) : ( - match >= 8 ? 2 : 4 - ) - ) - ) | 0; - } - if (n === s.length) { - return copy(s); - } - let s$p = Caml_bytes.create(n); - n = 0; - for (let i$1 = 0, i_finish$1 = s.length; i$1 < i_finish$1; ++i$1) { - let c = s[i$1]; - let exit = 0; - if (c >= 35) { - if (c !== 92) { - if (c >= 127) { - exit = 1; - } else { - s$p[n] = c; - } - } else { - exit = 2; - } - } else if (c >= 32) { - if (c >= 34) { - exit = 2; - } else { - s$p[n] = c; - } - } else if (c >= 14) { - exit = 1; - } else { - switch (c) { - case 8 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 'b' */98; - break; - case 9 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 't' */116; - break; - case 10 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 'n' */110; - break; - case 0 : - case 1 : - case 2 : - case 3 : - case 4 : - case 5 : - case 6 : - case 7 : - case 11 : - case 12 : - exit = 1; - break; - case 13 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 'r' */114; - break; - } - } - switch (exit) { - case 1 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = 48 + (c / 100 | 0) | 0; - n = n + 1 | 0; - s$p[n] = 48 + (c / 10 | 0) % 10 | 0; - n = n + 1 | 0; - s$p[n] = 48 + c % 10 | 0; - break; - case 2 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = c; - break; - } - n = n + 1 | 0; - } - return s$p; -} - -function map(f, s) { - let l = s.length; - if (l === 0) { - return s; - } - let r = Caml_bytes.create(l); - for (let i = 0; i < l; ++i) { - r[i] = f(s[i]); - } - return r; -} - -function mapi(f, s) { - let l = s.length; - if (l === 0) { - return s; - } - let r = Caml_bytes.create(l); - for (let i = 0; i < l; ++i) { - r[i] = f(i, s[i]); - } - return r; -} - -function uppercase_ascii(s) { - return map(Char.uppercase_ascii, s); -} - -function lowercase_ascii(s) { - return map(Char.lowercase_ascii, s); -} - -function apply1(f, s) { - if (s.length === 0) { - return s; - } - let r = copy(s); - r[0] = f(s[0]); - return r; -} - -function capitalize_ascii(s) { - return apply1(Char.uppercase_ascii, s); -} - -function uncapitalize_ascii(s) { - return apply1(Char.lowercase_ascii, s); -} - -function index_rec(s, lim, _i, c) { - while (true) { - let i = _i; - if (i >= lim) { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - if (s[i] === c) { - return i; - } - _i = i + 1 | 0; - continue; - }; -} - -function index(s, c) { - return index_rec(s, s.length, 0, c); -} - -function index_rec_opt(s, lim, _i, c) { - while (true) { - let i = _i; - if (i >= lim) { - return; - } - if (s[i] === c) { - return i; - } - _i = i + 1 | 0; - continue; - }; -} - -function index_opt(s, c) { - return index_rec_opt(s, s.length, 0, c); -} - -function index_from(s, i, c) { - let l = s.length; - if (i < 0 || i > l) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from / Bytes.index_from", - Error: new Error() - }; - } - return index_rec(s, l, i, c); -} - -function index_from_opt(s, i, c) { - let l = s.length; - if (i < 0 || i > l) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from_opt / Bytes.index_from_opt", - Error: new Error() - }; - } - return index_rec_opt(s, l, i, c); -} - -function rindex_rec(s, _i, c) { - while (true) { - let i = _i; - if (i < 0) { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - if (s[i] === c) { - return i; - } - _i = i - 1 | 0; - continue; - }; -} - -function rindex(s, c) { - return rindex_rec(s, s.length - 1 | 0, c); -} - -function rindex_from(s, i, c) { - if (i < -1 || i >= s.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from / Bytes.rindex_from", - Error: new Error() - }; - } - return rindex_rec(s, i, c); -} - -function rindex_rec_opt(s, _i, c) { - while (true) { - let i = _i; - if (i < 0) { - return; - } - if (s[i] === c) { - return i; - } - _i = i - 1 | 0; - continue; - }; -} - -function rindex_opt(s, c) { - return rindex_rec_opt(s, s.length - 1 | 0, c); -} - -function rindex_from_opt(s, i, c) { - if (i < -1 || i >= s.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from_opt / Bytes.rindex_from_opt", - Error: new Error() - }; - } - return rindex_rec_opt(s, i, c); -} - -function contains_from(s, i, c) { - let l = s.length; - if (i < 0 || i > l) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.contains_from / Bytes.contains_from", - Error: new Error() - }; - } - try { - index_rec(s, l, i, c); - return true; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - return false; - } - throw exn; - } -} - -function contains(s, c) { - return contains_from(s, 0, c); -} - -function rcontains_from(s, i, c) { - if (i < 0 || i >= s.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.rcontains_from / Bytes.rcontains_from", - Error: new Error() - }; - } - try { - rindex_rec(s, i, c); - return true; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - return false; - } - throw exn; - } -} - -let compare = Caml_bytes.bytes_compare; - -let equal = Caml_bytes.bytes_equal; - -let unsafe_to_string = to_string; - -let unsafe_of_string = of_string; - -exports.make = make; -exports.init = init; -exports.empty = empty; -exports.copy = copy; -exports.of_string = of_string; -exports.to_string = to_string; -exports.sub = sub; -exports.sub_string = sub_string; -exports.extend = extend; -exports.fill = fill; -exports.blit = blit; -exports.blit_string = blit_string; -exports.concat = concat; -exports.cat = cat; -exports.iter = iter; -exports.iteri = iteri; -exports.map = map; -exports.mapi = mapi; -exports.trim = trim; -exports.escaped = escaped; -exports.index = index; -exports.index_opt = index_opt; -exports.rindex = rindex; -exports.rindex_opt = rindex_opt; -exports.index_from = index_from; -exports.index_from_opt = index_from_opt; -exports.rindex_from = rindex_from; -exports.rindex_from_opt = rindex_from_opt; -exports.contains = contains; -exports.contains_from = contains_from; -exports.rcontains_from = rcontains_from; -exports.uppercase_ascii = uppercase_ascii; -exports.lowercase_ascii = lowercase_ascii; -exports.capitalize_ascii = capitalize_ascii; -exports.uncapitalize_ascii = uncapitalize_ascii; -exports.compare = compare; -exports.equal = equal; -exports.unsafe_to_string = unsafe_to_string; -exports.unsafe_of_string = unsafe_of_string; -/* No side effect */ diff --git a/lib/js/bytesLabels.js b/lib/js/bytesLabels.js deleted file mode 100644 index 13d10fe842..0000000000 --- a/lib/js/bytesLabels.js +++ /dev/null @@ -1,697 +0,0 @@ -'use strict'; - -let Caml = require("./caml.js"); -let Char = require("./char.js"); -let Caml_bytes = require("./caml_bytes.js"); -let Caml_js_exceptions = require("./caml_js_exceptions.js"); - -function unsafe_fill(s, i, l, c) { - if (l <= 0) { - return; - } - for (let k = i, k_finish = l + i | 0; k < k_finish; ++k) { - s[k] = c; - } -} - -function unsafe_blit(s1, i1, s2, i2, len) { - if (len <= 0) { - return; - } - if (s1 === s2) { - if (i1 < i2) { - let range_a = (s1.length - i2 | 0) - 1 | 0; - let range_b = len - 1 | 0; - let range = range_a > range_b ? range_b : range_a; - for (let j = range; j >= 0; --j) { - s1[i2 + j | 0] = s1[i1 + j | 0]; - } - return; - } - if (i1 <= i2) { - return; - } - let range_a$1 = (s1.length - i1 | 0) - 1 | 0; - let range_b$1 = len - 1 | 0; - let range$1 = range_a$1 > range_b$1 ? range_b$1 : range_a$1; - for (let k = 0; k <= range$1; ++k) { - s1[i2 + k | 0] = s1[i1 + k | 0]; - } - return; - } - let off1 = s1.length - i1 | 0; - if (len <= off1) { - for (let i = 0; i < len; ++i) { - s2[i2 + i | 0] = s1[i1 + i | 0]; - } - return; - } - for (let i$1 = 0; i$1 < off1; ++i$1) { - s2[i2 + i$1 | 0] = s1[i1 + i$1 | 0]; - } - for (let i$2 = off1; i$2 < len; ++i$2) { - s2[i2 + i$2 | 0] = /* '\000' */0; - } -} - -function make(n, c) { - let s = Caml_bytes.create(n); - unsafe_fill(s, 0, n, c); - return s; -} - -function init(n, f) { - let s = Caml_bytes.create(n); - for (let i = 0; i < n; ++i) { - s[i] = f(i); - } - return s; -} - -let empty = []; - -function copy(s) { - let len = s.length; - let r = Caml_bytes.create(len); - unsafe_blit(s, 0, r, 0, len); - return r; -} - -function to_string(a) { - let i = 0; - let len = a.length; - let s = ""; - let s_len = len; - if (i === 0 && len <= 4096 && len === a.length) { - return String.fromCharCode.apply(null, a); - } - let offset = 0; - while (s_len > 0) { - let next = s_len < 1024 ? s_len : 1024; - let tmp_bytes = new Array(next); - for (let k = 0; k < next; ++k) { - tmp_bytes[k] = a[k + offset | 0]; - } - s = s + String.fromCharCode.apply(null, tmp_bytes); - s_len = s_len - next | 0; - offset = offset + next | 0; - }; - return s; -} - -function of_string(s) { - let len = s.length; - let res = new Array(len); - for (let i = 0; i < len; ++i) { - res[i] = s.codePointAt(i); - } - return res; -} - -function sub(s, ofs, len) { - if (ofs < 0 || len < 0 || ofs > (s.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.sub / Bytes.sub", - Error: new Error() - }; - } - let r = Caml_bytes.create(len); - unsafe_blit(s, ofs, r, 0, len); - return r; -} - -function sub_string(b, ofs, len) { - return to_string(sub(b, ofs, len)); -} - -function $plus$plus(a, b) { - let c = a + b | 0; - let match = a < 0; - let match$1 = b < 0; - let match$2 = c < 0; - if (match) { - if (!match$1) { - return c; - } - if (match$2) { - return c; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Bytes.extend", - Error: new Error() - }; - } - if (match$1) { - return c; - } - if (match$2) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Bytes.extend", - Error: new Error() - }; - } - return c; -} - -function extend(s, left, right) { - let len = $plus$plus($plus$plus(s.length, left), right); - let r = Caml_bytes.create(len); - let match = left < 0 ? [ - -left | 0, - 0 - ] : [ - 0, - left - ]; - let dstoff = match[1]; - let srcoff = match[0]; - let cpylen = Caml.int_min(s.length - srcoff | 0, len - dstoff | 0); - if (cpylen > 0) { - unsafe_blit(s, srcoff, r, dstoff, cpylen); - } - return r; -} - -function fill(s, ofs, len, c) { - if (ofs < 0 || len < 0 || ofs > (s.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.fill / Bytes.fill", - Error: new Error() - }; - } - unsafe_fill(s, ofs, len, c); -} - -function blit(s1, ofs1, s2, ofs2, len) { - if (len < 0 || ofs1 < 0 || ofs1 > (s1.length - len | 0) || ofs2 < 0 || ofs2 > (s2.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Bytes.blit", - Error: new Error() - }; - } - unsafe_blit(s1, ofs1, s2, ofs2, len); -} - -function blit_string(s1, ofs1, s2, ofs2, len) { - if (len < 0 || ofs1 < 0 || ofs1 > (s1.length - len | 0) || ofs2 < 0 || ofs2 > (s2.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.blit / Bytes.blit_string", - Error: new Error() - }; - } - if (len <= 0) { - return; - } - let off1 = s1.length - ofs1 | 0; - if (len <= off1) { - for (let i = 0; i < len; ++i) { - s2[ofs2 + i | 0] = s1.codePointAt(ofs1 + i | 0); - } - return; - } - for (let i$1 = 0; i$1 < off1; ++i$1) { - s2[ofs2 + i$1 | 0] = s1.codePointAt(ofs1 + i$1 | 0); - } - for (let i$2 = off1; i$2 < len; ++i$2) { - s2[ofs2 + i$2 | 0] = /* '\000' */0; - } -} - -function iter(f, a) { - for (let i = 0, i_finish = a.length; i < i_finish; ++i) { - f(a[i]); - } -} - -function iteri(f, a) { - for (let i = 0, i_finish = a.length; i < i_finish; ++i) { - f(i, a[i]); - } -} - -function ensure_ge(x, y) { - if (x >= y) { - return x; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Bytes.concat", - Error: new Error() - }; -} - -function sum_lengths(_acc, seplen, _param) { - while (true) { - let param = _param; - let acc = _acc; - if (!param) { - return acc; - } - let tl = param.tl; - let hd = param.hd; - if (!tl) { - return hd.length + acc | 0; - } - _param = tl; - _acc = ensure_ge((hd.length + seplen | 0) + acc | 0, acc); - continue; - }; -} - -function concat(sep, param) { - if (!param) { - return empty; - } - let seplen = sep.length; - let dst = Caml_bytes.create(sum_lengths(0, seplen, param)); - let _pos = 0; - let _param = param; - while (true) { - let param$1 = _param; - let pos = _pos; - if (!param$1) { - return dst; - } - let tl = param$1.tl; - let hd = param$1.hd; - if (tl) { - unsafe_blit(hd, 0, dst, pos, hd.length); - unsafe_blit(sep, 0, dst, pos + hd.length | 0, seplen); - _param = tl; - _pos = (pos + hd.length | 0) + seplen | 0; - continue; - } - unsafe_blit(hd, 0, dst, pos, hd.length); - return dst; - }; -} - -function cat(s1, s2) { - let l1 = s1.length; - let l2 = s2.length; - let r = Caml_bytes.create(l1 + l2 | 0); - unsafe_blit(s1, 0, r, 0, l1); - unsafe_blit(s2, 0, r, l1, l2); - return r; -} - -function is_space(param) { - if (param > 13 || param < 9) { - return param === 32; - } else { - return param !== 11; - } -} - -function trim(s) { - let len = s.length; - let i = 0; - while (i < len && is_space(s[i])) { - i = i + 1 | 0; - }; - let j = len - 1 | 0; - while (j >= i && is_space(s[j])) { - j = j - 1 | 0; - }; - if (j >= i) { - return sub(s, i, (j - i | 0) + 1 | 0); - } else { - return empty; - } -} - -function escaped(s) { - let n = 0; - for (let i = 0, i_finish = s.length; i < i_finish; ++i) { - let match = s[i]; - n = n + ( - match >= 32 ? ( - match > 92 || match < 34 ? ( - match >= 127 ? 4 : 1 - ) : ( - match > 91 || match < 35 ? 2 : 1 - ) - ) : ( - match >= 11 ? ( - match !== 13 ? 4 : 2 - ) : ( - match >= 8 ? 2 : 4 - ) - ) - ) | 0; - } - if (n === s.length) { - return copy(s); - } - let s$p = Caml_bytes.create(n); - n = 0; - for (let i$1 = 0, i_finish$1 = s.length; i$1 < i_finish$1; ++i$1) { - let c = s[i$1]; - let exit = 0; - if (c >= 35) { - if (c !== 92) { - if (c >= 127) { - exit = 1; - } else { - s$p[n] = c; - } - } else { - exit = 2; - } - } else if (c >= 32) { - if (c >= 34) { - exit = 2; - } else { - s$p[n] = c; - } - } else if (c >= 14) { - exit = 1; - } else { - switch (c) { - case 8 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 'b' */98; - break; - case 9 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 't' */116; - break; - case 10 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 'n' */110; - break; - case 0 : - case 1 : - case 2 : - case 3 : - case 4 : - case 5 : - case 6 : - case 7 : - case 11 : - case 12 : - exit = 1; - break; - case 13 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = /* 'r' */114; - break; - } - } - switch (exit) { - case 1 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = 48 + (c / 100 | 0) | 0; - n = n + 1 | 0; - s$p[n] = 48 + (c / 10 | 0) % 10 | 0; - n = n + 1 | 0; - s$p[n] = 48 + c % 10 | 0; - break; - case 2 : - s$p[n] = /* '\\' */92; - n = n + 1 | 0; - s$p[n] = c; - break; - } - n = n + 1 | 0; - } - return s$p; -} - -function map(f, s) { - let l = s.length; - if (l === 0) { - return s; - } - let r = Caml_bytes.create(l); - for (let i = 0; i < l; ++i) { - r[i] = f(s[i]); - } - return r; -} - -function mapi(f, s) { - let l = s.length; - if (l === 0) { - return s; - } - let r = Caml_bytes.create(l); - for (let i = 0; i < l; ++i) { - r[i] = f(i, s[i]); - } - return r; -} - -function uppercase_ascii(s) { - return map(Char.uppercase_ascii, s); -} - -function lowercase_ascii(s) { - return map(Char.lowercase_ascii, s); -} - -function apply1(f, s) { - if (s.length === 0) { - return s; - } - let r = copy(s); - r[0] = f(s[0]); - return r; -} - -function capitalize_ascii(s) { - return apply1(Char.uppercase_ascii, s); -} - -function uncapitalize_ascii(s) { - return apply1(Char.lowercase_ascii, s); -} - -function index_rec(s, lim, _i, c) { - while (true) { - let i = _i; - if (i >= lim) { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - if (s[i] === c) { - return i; - } - _i = i + 1 | 0; - continue; - }; -} - -function index(s, c) { - return index_rec(s, s.length, 0, c); -} - -function index_rec_opt(s, lim, _i, c) { - while (true) { - let i = _i; - if (i >= lim) { - return; - } - if (s[i] === c) { - return i; - } - _i = i + 1 | 0; - continue; - }; -} - -function index_opt(s, c) { - return index_rec_opt(s, s.length, 0, c); -} - -function index_from(s, i, c) { - let l = s.length; - if (i < 0 || i > l) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from / Bytes.index_from", - Error: new Error() - }; - } - return index_rec(s, l, i, c); -} - -function index_from_opt(s, i, c) { - let l = s.length; - if (i < 0 || i > l) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from_opt / Bytes.index_from_opt", - Error: new Error() - }; - } - return index_rec_opt(s, l, i, c); -} - -function rindex_rec(s, _i, c) { - while (true) { - let i = _i; - if (i < 0) { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - if (s[i] === c) { - return i; - } - _i = i - 1 | 0; - continue; - }; -} - -function rindex(s, c) { - return rindex_rec(s, s.length - 1 | 0, c); -} - -function rindex_from(s, i, c) { - if (i < -1 || i >= s.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from / Bytes.rindex_from", - Error: new Error() - }; - } - return rindex_rec(s, i, c); -} - -function rindex_rec_opt(s, _i, c) { - while (true) { - let i = _i; - if (i < 0) { - return; - } - if (s[i] === c) { - return i; - } - _i = i - 1 | 0; - continue; - }; -} - -function rindex_opt(s, c) { - return rindex_rec_opt(s, s.length - 1 | 0, c); -} - -function rindex_from_opt(s, i, c) { - if (i < -1 || i >= s.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from_opt / Bytes.rindex_from_opt", - Error: new Error() - }; - } - return rindex_rec_opt(s, i, c); -} - -function contains_from(s, i, c) { - let l = s.length; - if (i < 0 || i > l) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.contains_from / Bytes.contains_from", - Error: new Error() - }; - } - try { - index_rec(s, l, i, c); - return true; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - return false; - } - throw exn; - } -} - -function contains(s, c) { - return contains_from(s, 0, c); -} - -function rcontains_from(s, i, c) { - if (i < 0 || i >= s.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.rcontains_from / Bytes.rcontains_from", - Error: new Error() - }; - } - try { - rindex_rec(s, i, c); - return true; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - return false; - } - throw exn; - } -} - -let compare = Caml_bytes.bytes_compare; - -let equal = Caml_bytes.bytes_equal; - -let unsafe_to_string = to_string; - -let unsafe_of_string = of_string; - -exports.make = make; -exports.init = init; -exports.empty = empty; -exports.copy = copy; -exports.of_string = of_string; -exports.to_string = to_string; -exports.sub = sub; -exports.sub_string = sub_string; -exports.extend = extend; -exports.fill = fill; -exports.blit = blit; -exports.blit_string = blit_string; -exports.concat = concat; -exports.cat = cat; -exports.iter = iter; -exports.iteri = iteri; -exports.map = map; -exports.mapi = mapi; -exports.trim = trim; -exports.escaped = escaped; -exports.index = index; -exports.index_opt = index_opt; -exports.rindex = rindex; -exports.rindex_opt = rindex_opt; -exports.index_from = index_from; -exports.index_from_opt = index_from_opt; -exports.rindex_from = rindex_from; -exports.rindex_from_opt = rindex_from_opt; -exports.contains = contains; -exports.contains_from = contains_from; -exports.rcontains_from = rcontains_from; -exports.uppercase_ascii = uppercase_ascii; -exports.lowercase_ascii = lowercase_ascii; -exports.capitalize_ascii = capitalize_ascii; -exports.uncapitalize_ascii = uncapitalize_ascii; -exports.compare = compare; -exports.equal = equal; -exports.unsafe_to_string = unsafe_to_string; -exports.unsafe_of_string = unsafe_of_string; -/* No side effect */ diff --git a/lib/js/callback.js b/lib/js/callback.js deleted file mode 100644 index 684d9d8fde..0000000000 --- a/lib/js/callback.js +++ /dev/null @@ -1,14 +0,0 @@ -'use strict'; - - -function register(param, param$1) { - -} - -function register_exception(param, param$1) { - -} - -exports.register = register; -exports.register_exception = register_exception; -/* No side effect */ diff --git a/lib/js/caml.js b/lib/js/caml.js deleted file mode 100644 index c3729dc091..0000000000 --- a/lib/js/caml.js +++ /dev/null @@ -1,205 +0,0 @@ -'use strict'; - - -function int_compare(x, y) { - if (x < y) { - return -1; - } else if (x === y) { - return 0; - } else { - return 1; - } -} - -function bool_compare(x, y) { - if (x) { - if (y) { - return 0; - } else { - return 1; - } - } else if (y) { - return -1; - } else { - return 0; - } -} - -function float_compare(x, y) { - if (x === y) { - return 0; - } else if (x < y) { - return -1; - } else if (x > y || x === x) { - return 1; - } else if (y === y) { - return -1; - } else { - return 0; - } -} - -function bigint_compare(x, y) { - if (x < y) { - return -1; - } else if (x === y) { - return 0; - } else { - return 1; - } -} - -function string_compare(s1, s2) { - if (s1 === s2) { - return 0; - } else if (s1 < s2) { - return -1; - } else { - return 1; - } -} - -function bool_min(x, y) { - if (x) { - return y; - } else { - return x; - } -} - -function int_min(x, y) { - if (x < y) { - return x; - } else { - return y; - } -} - -function float_min(x, y) { - if (x < y) { - return x; - } else { - return y; - } -} - -function string_min(x, y) { - if (x < y) { - return x; - } else { - return y; - } -} - -function bool_max(x, y) { - if (x) { - return x; - } else { - return y; - } -} - -function int_max(x, y) { - if (x > y) { - return x; - } else { - return y; - } -} - -function float_max(x, y) { - if (x > y) { - return x; - } else { - return y; - } -} - -function string_max(x, y) { - if (x > y) { - return x; - } else { - return y; - } -} - -function i64_eq(x, y) { - if (x[1] === y[1]) { - return x[0] === y[0]; - } else { - return false; - } -} - -function i64_ge(param, param$1) { - let other_hi = param$1[0]; - let hi = param[0]; - if (hi > other_hi) { - return true; - } else if (hi < other_hi) { - return false; - } else { - return param[1] >= param$1[1]; - } -} - -function i64_neq(x, y) { - return !i64_eq(x, y); -} - -function i64_lt(x, y) { - return !i64_ge(x, y); -} - -function i64_gt(x, y) { - if (x[0] > y[0]) { - return true; - } else if (x[0] < y[0]) { - return false; - } else { - return x[1] > y[1]; - } -} - -function i64_le(x, y) { - return !i64_gt(x, y); -} - -function i64_min(x, y) { - if (i64_ge(x, y)) { - return y; - } else { - return x; - } -} - -function i64_max(x, y) { - if (i64_gt(x, y)) { - return x; - } else { - return y; - } -} - -exports.int_compare = int_compare; -exports.bool_compare = bool_compare; -exports.float_compare = float_compare; -exports.bigint_compare = bigint_compare; -exports.string_compare = string_compare; -exports.bool_min = bool_min; -exports.int_min = int_min; -exports.float_min = float_min; -exports.string_min = string_min; -exports.bool_max = bool_max; -exports.int_max = int_max; -exports.float_max = float_max; -exports.string_max = string_max; -exports.i64_eq = i64_eq; -exports.i64_neq = i64_neq; -exports.i64_lt = i64_lt; -exports.i64_gt = i64_gt; -exports.i64_le = i64_le; -exports.i64_ge = i64_ge; -exports.i64_min = i64_min; -exports.i64_max = i64_max; -/* No side effect */ diff --git a/lib/js/caml_array.js b/lib/js/caml_array.js deleted file mode 100644 index b04e555508..0000000000 --- a/lib/js/caml_array.js +++ /dev/null @@ -1,120 +0,0 @@ -'use strict'; - - -function sub(x, offset, len) { - let result = new Array(len); - let j = 0; - let i = offset; - while (j < len) { - result[j] = x[i]; - j = j + 1 | 0; - i = i + 1 | 0; - }; - return result; -} - -function len(_acc, _l) { - while (true) { - let l = _l; - let acc = _acc; - if (!l) { - return acc; - } - _l = l.tl; - _acc = l.hd.length + acc | 0; - continue; - }; -} - -function fill(arr, _i, _l) { - while (true) { - let l = _l; - let i = _i; - if (!l) { - return; - } - let x = l.hd; - let l$1 = x.length; - let k = i; - let j = 0; - while (j < l$1) { - arr[k] = x[j]; - k = k + 1 | 0; - j = j + 1 | 0; - }; - _l = l.tl; - _i = k; - continue; - }; -} - -function concat(l) { - let v = len(0, l); - let result = new Array(v); - fill(result, 0, l); - return result; -} - -function set(xs, index, newval) { - if (index < 0 || index >= xs.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "index out of bounds", - Error: new Error() - }; - } - xs[index] = newval; -} - -function get(xs, index) { - if (index < 0 || index >= xs.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "index out of bounds", - Error: new Error() - }; - } - return xs[index]; -} - -function make(len, init) { - let b = new Array(len); - for (let i = 0; i < len; ++i) { - b[i] = init; - } - return b; -} - -function make_float(len) { - let b = new Array(len); - for (let i = 0; i < len; ++i) { - b[i] = 0; - } - return b; -} - -function blit(a1, i1, a2, i2, len) { - if (i2 <= i1) { - for (let j = 0; j < len; ++j) { - a2[j + i2 | 0] = a1[j + i1 | 0]; - } - return; - } - for (let j$1 = len - 1 | 0; j$1 >= 0; --j$1) { - a2[j$1 + i2 | 0] = a1[j$1 + i1 | 0]; - } -} - -function dup(prim) { - return prim.slice(0); -} - -exports.dup = dup; -exports.sub = sub; -exports.concat = concat; -exports.make = make; -exports.make_float = make_float; -exports.blit = blit; -exports.get = get; -exports.set = set; -/* No side effect */ diff --git a/lib/js/caml_bytes.js b/lib/js/caml_bytes.js deleted file mode 100644 index cc6553105a..0000000000 --- a/lib/js/caml_bytes.js +++ /dev/null @@ -1,120 +0,0 @@ -'use strict'; - - -function set(s, i, ch) { - if (i < 0 || i >= s.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "index out of bounds", - Error: new Error() - }; - } - s[i] = ch; -} - -function get(s, i) { - if (i < 0 || i >= s.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "index out of bounds", - Error: new Error() - }; - } - return s[i]; -} - -function create(len) { - if (len < 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.create", - Error: new Error() - }; - } - let result = new Array(len); - for (let i = 0; i < len; ++i) { - result[i] = /* '\000' */0; - } - return result; -} - -function bytes_compare_aux(s1, s2, _off, len, def) { - while (true) { - let off = _off; - if (off >= len) { - return def; - } - let a = s1[off]; - let b = s2[off]; - if (a > b) { - return 1; - } - if (a < b) { - return -1; - } - _off = off + 1 | 0; - continue; - }; -} - -function bytes_compare(s1, s2) { - let len1 = s1.length; - let len2 = s2.length; - if (len1 === len2) { - return bytes_compare_aux(s1, s2, 0, len1, 0); - } else if (len1 < len2) { - return bytes_compare_aux(s1, s2, 0, len1, -1); - } else { - return bytes_compare_aux(s1, s2, 0, len2, 1); - } -} - -function bytes_equal(s1, s2) { - let len1 = s1.length; - let len2 = s2.length; - if (len1 === len2) { - let _off = 0; - while (true) { - let off = _off; - if (off === len1) { - return true; - } - let a = s1[off]; - let b = s2[off]; - if (a !== b) { - return false; - } - _off = off + 1 | 0; - continue; - }; - } else { - return false; - } -} - -function bytes_greaterthan(s1, s2) { - return bytes_compare(s1, s2) > 0; -} - -function bytes_greaterequal(s1, s2) { - return bytes_compare(s1, s2) >= 0; -} - -function bytes_lessthan(s1, s2) { - return bytes_compare(s1, s2) < 0; -} - -function bytes_lessequal(s1, s2) { - return bytes_compare(s1, s2) <= 0; -} - -exports.create = create; -exports.get = get; -exports.set = set; -exports.bytes_compare = bytes_compare; -exports.bytes_greaterthan = bytes_greaterthan; -exports.bytes_greaterequal = bytes_greaterequal; -exports.bytes_lessthan = bytes_lessthan; -exports.bytes_lessequal = bytes_lessequal; -exports.bytes_equal = bytes_equal; -/* No side effect */ diff --git a/lib/js/caml_float.js b/lib/js/caml_float.js deleted file mode 100644 index cc3664bdfd..0000000000 --- a/lib/js/caml_float.js +++ /dev/null @@ -1,127 +0,0 @@ -'use strict'; - - -let int_float_of_bits = (function(x){ - return new Float32Array(new Int32Array([x]).buffer)[0] - }); - -let int_bits_of_float = (function(x){ - return new Int32Array(new Float32Array([x]).buffer)[0] -}); - -function modf_float(x) { - if (!isFinite(x)) { - if (isNaN(x)) { - return [ - NaN, - NaN - ]; - } else { - return [ - 1 / x, - x - ]; - } - } - let neg = 1 / x < 0; - let x$1 = Math.abs(x); - let i = Math.floor(x$1); - let f = x$1 - i; - if (neg) { - return [ - - f, - - i - ]; - } else { - return [ - f, - i - ]; - } -} - -function ldexp_float(x, exp) { - let x$p = x; - let exp$p = exp; - if (exp$p > 1023) { - exp$p = exp$p - 1023; - x$p = x$p * Math.pow(2, 1023); - if (exp$p > 1023) { - exp$p = exp$p - 1023; - x$p = x$p * Math.pow(2, 1023); - } - - } else if (exp$p < -1023) { - exp$p = exp$p + 1023; - x$p = x$p * Math.pow(2, -1023); - } - return x$p * Math.pow(2, exp$p); -} - -function frexp_float(x) { - if (x === 0 || !isFinite(x)) { - return [ - x, - 0 - ]; - } - let neg = x < 0; - let x$p = Math.abs(x); - let exp = Math.floor(Math.LOG2E * Math.log(x$p)) + 1; - x$p = x$p * Math.pow(2, - exp); - if (x$p < 0.5) { - x$p = x$p * 2; - exp = exp - 1; - } - if (neg) { - x$p = - x$p; - } - return [ - x$p, - exp | 0 - ]; -} - -function copysign_float(x, y) { - let x$1 = Math.abs(x); - let y$1 = y === 0 ? 1 / y : y; - if (y$1 < 0) { - return - x$1; - } else { - return x$1; - } -} - -function expm1_float(x) { - let y = Math.exp(x); - let z = y - 1; - if (Math.abs(x) > 1) { - return z; - } else if (z === 0) { - return x; - } else { - return x * z / Math.log(y); - } -} - -function hypot_float(x, y) { - let x0 = Math.abs(x); - let y0 = Math.abs(y); - let a = x0 > y0 ? x0 : y0; - let b = ( - x0 < y0 ? x0 : y0 - ) / ( - a !== 0 ? a : 1 - ); - return a * Math.sqrt(1 + b * b); -} - -exports.int_float_of_bits = int_float_of_bits; -exports.int_bits_of_float = int_bits_of_float; -exports.modf_float = modf_float; -exports.ldexp_float = ldexp_float; -exports.frexp_float = frexp_float; -exports.copysign_float = copysign_float; -exports.expm1_float = expm1_float; -exports.hypot_float = hypot_float; -/* No side effect */ diff --git a/lib/js/caml_format.js b/lib/js/caml_format.js deleted file mode 100644 index e663e5d2fd..0000000000 --- a/lib/js/caml_format.js +++ /dev/null @@ -1,785 +0,0 @@ -'use strict'; - -let Caml = require("./caml.js"); -let Caml_int64 = require("./caml_int64.js"); - -function parse_digit(c) { - if (c >= 65) { - if (c >= 97) { - if (c >= 123) { - return -1; - } else { - return c - 87 | 0; - } - } else if (c >= 91) { - return -1; - } else { - return c - 55 | 0; - } - } else if (c > 57 || c < 48) { - return -1; - } else { - return c - 48 | 0; - } -} - -function int_of_string_base(x) { - switch (x) { - case "Oct" : - return 8; - case "Hex" : - return 16; - case "Dec" : - return 10; - case "Bin" : - return 2; - } -} - -function parse_sign_and_base(s) { - let sign = 1; - let base = "Dec"; - let i = 0; - let match = s.codePointAt(i); - switch (match) { - case 43 : - i = i + 1 | 0; - break; - case 45 : - sign = -1; - i = i + 1 | 0; - break; - } - if (s.codePointAt(i) === /* '0' */48) { - let match$1 = s.codePointAt(i + 1 | 0); - if (match$1 >= 89) { - if (match$1 >= 111) { - if (match$1 < 121) { - switch (match$1) { - case 111 : - base = "Oct"; - i = i + 2 | 0; - break; - case 117 : - i = i + 2 | 0; - break; - case 112 : - case 113 : - case 114 : - case 115 : - case 116 : - case 118 : - case 119 : - break; - case 120 : - base = "Hex"; - i = i + 2 | 0; - break; - } - } - - } else if (match$1 === 98) { - base = "Bin"; - i = i + 2 | 0; - } - - } else if (match$1 !== 66) { - if (match$1 >= 79) { - switch (match$1) { - case 79 : - base = "Oct"; - i = i + 2 | 0; - break; - case 85 : - i = i + 2 | 0; - break; - case 80 : - case 81 : - case 82 : - case 83 : - case 84 : - case 86 : - case 87 : - break; - case 88 : - base = "Hex"; - i = i + 2 | 0; - break; - } - } - - } else { - base = "Bin"; - i = i + 2 | 0; - } - } - return [ - i, - sign, - base - ]; -} - -function int_of_string(s) { - let match = parse_sign_and_base(s); - let i = match[0]; - let base = int_of_string_base(match[2]); - let threshold = 4294967295; - let len = s.length; - let c = i < len ? s.codePointAt(i) : /* '\000' */0; - let d = parse_digit(c); - if (d < 0 || d >= base) { - throw { - RE_EXN_ID: "Failure", - _1: "int_of_string", - Error: new Error() - }; - } - let aux = (_acc, _k) => { - while (true) { - let k = _k; - let acc = _acc; - if (k === len) { - return acc; - } - let a = s.codePointAt(k); - if (a === /* '_' */95) { - _k = k + 1 | 0; - continue; - } - let v = parse_digit(a); - if (v < 0 || v >= base) { - throw { - RE_EXN_ID: "Failure", - _1: "int_of_string", - Error: new Error() - }; - } - let acc$1 = base * acc + v; - if (acc$1 > threshold) { - throw { - RE_EXN_ID: "Failure", - _1: "int_of_string", - Error: new Error() - }; - } - _k = k + 1 | 0; - _acc = acc$1; - continue; - }; - }; - let res = match[1] * aux(d, i + 1 | 0); - let or_res = res | 0; - if (base === 10 && res !== or_res) { - throw { - RE_EXN_ID: "Failure", - _1: "int_of_string", - Error: new Error() - }; - } - return or_res; -} - -function int64_of_string(s) { - let match = parse_sign_and_base(s); - let hbase = match[2]; - let i = match[0]; - let base = Caml_int64.of_int32(int_of_string_base(hbase)); - let sign = Caml_int64.of_int32(match[1]); - let threshold; - switch (hbase) { - case "Oct" : - threshold = [ - 536870911, - 4294967295 - ]; - break; - case "Hex" : - threshold = [ - 268435455, - 4294967295 - ]; - break; - case "Dec" : - threshold = [ - 429496729, - 2576980377 - ]; - break; - case "Bin" : - threshold = Caml_int64.max_int; - break; - } - let len = s.length; - let c = i < len ? s.codePointAt(i) : /* '\000' */0; - let d = Caml_int64.of_int32(parse_digit(c)); - if (Caml.i64_lt(d, Caml_int64.zero) || Caml.i64_ge(d, base)) { - throw { - RE_EXN_ID: "Failure", - _1: "int64_of_string", - Error: new Error() - }; - } - let aux = (_acc, _k) => { - while (true) { - let k = _k; - let acc = _acc; - if (k === len) { - return acc; - } - let a = s.codePointAt(k); - if (a === /* '_' */95) { - _k = k + 1 | 0; - continue; - } - let v = Caml_int64.of_int32(parse_digit(a)); - if (Caml.i64_lt(v, Caml_int64.zero) || Caml.i64_ge(v, base) || Caml.i64_gt(acc, threshold)) { - throw { - RE_EXN_ID: "Failure", - _1: "int64_of_string", - Error: new Error() - }; - } - let acc$1 = Caml_int64.add(Caml_int64.mul(base, acc), v); - _k = k + 1 | 0; - _acc = acc$1; - continue; - }; - }; - let res = Caml_int64.mul(sign, aux(d, i + 1 | 0)); - let or_res = Caml_int64.or_(res, Caml_int64.zero); - if (Caml.i64_eq(base, [ - 0, - 10 - ]) && Caml.i64_neq(res, or_res)) { - throw { - RE_EXN_ID: "Failure", - _1: "int64_of_string", - Error: new Error() - }; - } - return or_res; -} - -function int_of_base(x) { - switch (x) { - case "Oct" : - return 8; - case "Hex" : - return 16; - case "Dec" : - return 10; - } -} - -function lowercase(c) { - if (c >= /* 'A' */65 && c <= /* 'Z' */90 || c >= /* '\192' */192 && c <= /* '\214' */214 || c >= /* '\216' */216 && c <= /* '\222' */222) { - return c + 32 | 0; - } else { - return c; - } -} - -function parse_format(fmt) { - let len = fmt.length; - if (len > 31) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "format_int: format too long", - Error: new Error() - }; - } - let f = { - justify: "+", - signstyle: "-", - filter: " ", - alternate: false, - base: "Dec", - signedconv: false, - width: 0, - uppercase: false, - sign: 1, - prec: -1, - conv: "f" - }; - let _i = 0; - while (true) { - let i = _i; - if (i >= len) { - return f; - } - let c = fmt.codePointAt(i); - let exit = 0; - if (c >= 69) { - if (c >= 88) { - if (c >= 121) { - exit = 1; - } else { - switch (c) { - case 88 : - f.base = "Hex"; - f.uppercase = true; - _i = i + 1 | 0; - continue; - case 101 : - case 102 : - case 103 : - exit = 5; - break; - case 100 : - case 105 : - exit = 4; - break; - case 111 : - f.base = "Oct"; - _i = i + 1 | 0; - continue; - case 117 : - f.base = "Dec"; - _i = i + 1 | 0; - continue; - case 89 : - case 90 : - case 91 : - case 92 : - case 93 : - case 94 : - case 95 : - case 96 : - case 97 : - case 98 : - case 99 : - case 104 : - case 106 : - case 107 : - case 108 : - case 109 : - case 110 : - case 112 : - case 113 : - case 114 : - case 115 : - case 116 : - case 118 : - case 119 : - exit = 1; - break; - case 120 : - f.base = "Hex"; - _i = i + 1 | 0; - continue; - } - } - } else if (c >= 72) { - exit = 1; - } else { - f.signedconv = true; - f.uppercase = true; - f.conv = String.fromCharCode(lowercase(c)); - _i = i + 1 | 0; - continue; - } - } else { - switch (c) { - case 35 : - f.alternate = true; - _i = i + 1 | 0; - continue; - case 32 : - case 43 : - exit = 2; - break; - case 45 : - f.justify = "-"; - _i = i + 1 | 0; - continue; - case 46 : - f.prec = 0; - let j = i + 1 | 0; - while ((() => { - let w = fmt.codePointAt(j) - 48 | 0; - return w >= 0 && w <= 9; - })()) { - f.prec = (Math.imul(f.prec, 10) + fmt.codePointAt(j) | 0) - 48 | 0; - j = j + 1 | 0; - }; - _i = j; - continue; - case 48 : - f.filter = "0"; - _i = i + 1 | 0; - continue; - case 49 : - case 50 : - case 51 : - case 52 : - case 53 : - case 54 : - case 55 : - case 56 : - case 57 : - exit = 3; - break; - default: - exit = 1; - } - } - switch (exit) { - case 1 : - _i = i + 1 | 0; - continue; - case 2 : - f.signstyle = String.fromCharCode(c); - _i = i + 1 | 0; - continue; - case 3 : - f.width = 0; - let j$1 = i; - while ((() => { - let w = fmt.codePointAt(j$1) - 48 | 0; - return w >= 0 && w <= 9; - })()) { - f.width = (Math.imul(f.width, 10) + fmt.codePointAt(j$1) | 0) - 48 | 0; - j$1 = j$1 + 1 | 0; - }; - _i = j$1; - continue; - case 4 : - f.signedconv = true; - f.base = "Dec"; - _i = i + 1 | 0; - continue; - case 5 : - f.signedconv = true; - f.conv = String.fromCharCode(c); - _i = i + 1 | 0; - continue; - } - }; -} - -function finish_formatting(config, rawbuffer) { - let justify = config.justify; - let signstyle = config.signstyle; - let filter = config.filter; - let alternate = config.alternate; - let base = config.base; - let signedconv = config.signedconv; - let width = config.width; - let uppercase = config.uppercase; - let sign = config.sign; - let len = rawbuffer.length; - if (signedconv && (sign < 0 || signstyle !== "-")) { - len = len + 1 | 0; - } - if (alternate) { - if (base === "Oct") { - len = len + 1 | 0; - } else if (base === "Hex") { - len = len + 2 | 0; - } - - } - let buffer = ""; - if (justify === "+" && filter === " ") { - for (let _for = len; _for < width; ++_for) { - buffer = buffer + filter; - } - } - if (signedconv) { - if (sign < 0) { - buffer = buffer + "-"; - } else if (signstyle !== "-") { - buffer = buffer + signstyle; - } - - } - if (alternate && base === "Oct") { - buffer = buffer + "0"; - } - if (alternate && base === "Hex") { - buffer = buffer + "0x"; - } - if (justify === "+" && filter === "0") { - for (let _for$1 = len; _for$1 < width; ++_for$1) { - buffer = buffer + filter; - } - } - buffer = uppercase ? buffer + rawbuffer.toUpperCase() : buffer + rawbuffer; - if (justify === "-") { - for (let _for$2 = len; _for$2 < width; ++_for$2) { - buffer = buffer + " "; - } - } - return buffer; -} - -function format_int(fmt, i) { - if (fmt === "%d") { - return String(i); - } - let f = parse_format(fmt); - let i$1 = i < 0 ? ( - f.signedconv ? (f.sign = -1, (-i >>> 0)) : (i >>> 0) - ) : i; - let s = i$1.toString(int_of_base(f.base)); - if (f.prec >= 0) { - f.filter = " "; - let n = f.prec - s.length | 0; - if (n > 0) { - s = "0".repeat(n) + s; - } - - } - return finish_formatting(f, s); -} - -function dec_of_pos_int64(x) { - if (!Caml.i64_lt(x, Caml_int64.zero)) { - return Caml_int64.to_string(x); - } - let wbase = [ - 0, - 10 - ]; - let y = Caml_int64.discard_sign(x); - let match = Caml_int64.div_mod(y, wbase); - let match$1 = Caml_int64.div_mod(Caml_int64.add([ - 0, - 8 - ], match[1]), wbase); - let quotient = Caml_int64.add(Caml_int64.add([ - 214748364, - 3435973836 - ], match[0]), match$1[0]); - return Caml_int64.to_string(quotient) + "0123456789"[Caml_int64.to_int32(match$1[1])]; -} - -function oct_of_int64(x) { - let s = ""; - let wbase = [ - 0, - 8 - ]; - let cvtbl = "01234567"; - if (Caml.i64_lt(x, Caml_int64.zero)) { - let y = Caml_int64.discard_sign(x); - let match = Caml_int64.div_mod(y, wbase); - let quotient = Caml_int64.add([ - 268435456, - 0 - ], match[0]); - let modulus = match[1]; - s = cvtbl[Caml_int64.to_int32(modulus)] + s; - while (Caml.i64_neq(quotient, Caml_int64.zero)) { - let match$1 = Caml_int64.div_mod(quotient, wbase); - quotient = match$1[0]; - modulus = match$1[1]; - s = cvtbl[Caml_int64.to_int32(modulus)] + s; - }; - } else { - let match$2 = Caml_int64.div_mod(x, wbase); - let quotient$1 = match$2[0]; - let modulus$1 = match$2[1]; - s = cvtbl[Caml_int64.to_int32(modulus$1)] + s; - while (Caml.i64_neq(quotient$1, Caml_int64.zero)) { - let match$3 = Caml_int64.div_mod(quotient$1, wbase); - quotient$1 = match$3[0]; - modulus$1 = match$3[1]; - s = cvtbl[Caml_int64.to_int32(modulus$1)] + s; - }; - } - return s; -} - -function int64_format(fmt, x) { - if (fmt === "%d") { - return Caml_int64.to_string(x); - } - let f = parse_format(fmt); - let x$1 = f.signedconv && Caml.i64_lt(x, Caml_int64.zero) ? (f.sign = -1, Caml_int64.neg(x)) : x; - let match = f.base; - let s; - switch (match) { - case "Oct" : - s = oct_of_int64(x$1); - break; - case "Hex" : - s = Caml_int64.to_hex(x$1); - break; - case "Dec" : - s = dec_of_pos_int64(x$1); - break; - } - let fill_s; - if (f.prec >= 0) { - f.filter = " "; - let n = f.prec - s.length | 0; - fill_s = n > 0 ? "0".repeat(n) + s : s; - } else { - fill_s = s; - } - return finish_formatting(f, fill_s); -} - -function format_float(fmt, x) { - let f = parse_format(fmt); - let prec = f.prec < 0 ? 6 : f.prec; - let x$1 = x < 0 ? (f.sign = -1, - x) : x; - let s = ""; - if (isNaN(x$1)) { - s = "nan"; - f.filter = " "; - } else if (isFinite(x$1)) { - let match = f.conv; - switch (match) { - case "e" : - s = x$1.toExponential(prec); - let i = s.length; - if (s.codePointAt(i - 3 | 0) === /* 'e' */101) { - s = s.slice(0, i - 1 | 0) + ("0" + s.slice(i - 1 | 0)); - } - break; - case "f" : - s = x$1.toFixed(prec); - break; - case "g" : - let prec$1 = prec !== 0 ? prec : 1; - s = x$1.toExponential(prec$1 - 1 | 0); - let j = s.indexOf("e"); - let exp = Number(s.slice(j + 1 | 0)) | 0; - if (exp < -4 || x$1 >= 1e21 || x$1.toFixed().length > prec$1) { - let i$1 = j - 1 | 0; - while (s.codePointAt(i$1) === /* '0' */48) { - i$1 = i$1 - 1 | 0; - }; - if (s.codePointAt(i$1) === /* '.' */46) { - i$1 = i$1 - 1 | 0; - } - s = s.slice(0, i$1 + 1 | 0) + s.slice(j); - let i$2 = s.length; - if (s.codePointAt(i$2 - 3 | 0) === /* 'e' */101) { - s = s.slice(0, i$2 - 1 | 0) + ("0" + s.slice(i$2 - 1 | 0)); - } - - } else { - let p = prec$1; - if (exp < 0) { - p = p - (exp + 1 | 0) | 0; - s = x$1.toFixed(p); - } else { - while ((() => { - s = x$1.toFixed(p); - return s.length > (prec$1 + 1 | 0); - })()) { - p = p - 1 | 0; - }; - } - if (p !== 0) { - let k = s.length - 1 | 0; - while (s.codePointAt(k) === /* '0' */48) { - k = k - 1 | 0; - }; - if (s.codePointAt(k) === /* '.' */46) { - k = k - 1 | 0; - } - s = s.slice(0, k + 1 | 0); - } - - } - break; - } - } else { - s = "inf"; - f.filter = " "; - } - return finish_formatting(f, s); -} - -let hexstring_of_float = (function(x,prec,style){ - if (!isFinite(x)) { - if (isNaN(x)) return "nan"; - return x > 0 ? "infinity":"-infinity"; - } - var sign = (x==0 && 1/x == -Infinity)?1:(x>=0)?0:1; - if(sign) x = -x; - var exp = 0; - if (x == 0) { } - else if (x < 1) { - while (x < 1 && exp > -1022) { x *= 2; exp-- } - } else { - while (x >= 2) { x /= 2; exp++ } - } - var exp_sign = exp < 0 ? '' : '+'; - var sign_str = ''; - if (sign) sign_str = '-' - else { - switch(style){ - case 43 /* '+' */: sign_str = '+'; break; - case 32 /* ' ' */: sign_str = ' '; break; - default: break; - } - } - if (prec >= 0 && prec < 13) { - /* If a precision is given, and is small, round mantissa accordingly */ - var cst = Math.pow(2,prec * 4); - x = Math.round(x * cst) / cst; - } - var x_str = x.toString(16); - if(prec >= 0){ - var idx = x_str.indexOf('.'); - if(idx<0) { - x_str += '.' + '0'.repeat(prec); - } - else { - var size = idx+1+prec; - if(x_str.length < size) - x_str += '0'.repeat(size - x_str.length); - else - x_str = x_str.substr(0,size); - } - } - return (sign_str + '0x' + x_str + 'p' + exp_sign + exp.toString(10)); -}); - -let float_of_string = (function(s,exn){ - - var res = +s; - if ((s.length > 0) && (res === res)) - return res; - s = s.replace(/_/g, ""); - res = +s; - if (((s.length > 0) && (res === res)) || /^[+-]?nan$/i.test(s)) { - return res; - }; - var m = /^ *([+-]?)0x([0-9a-f]+)\.?([0-9a-f]*)p([+-]?[0-9]+)/i.exec(s); - // 1 2 3 4 - if(m){ - var m3 = m[3].replace(/0+$/,''); - var mantissa = parseInt(m[1] + m[2] + m3, 16); - var exponent = (m[4]|0) - 4*m3.length; - res = mantissa * Math.pow(2, exponent); - return res; - } - if (/^\+?inf(inity)?$/i.test(s)) - return Infinity; - if (/^-inf(inity)?$/i.test(s)) - return -Infinity; - throw exn; -}); - -function float_of_string$1(s) { - return float_of_string(s, { - RE_EXN_ID: "Failure", - _1: "float_of_string" - }); -} - -exports.format_float = format_float; -exports.hexstring_of_float = hexstring_of_float; -exports.format_int = format_int; -exports.float_of_string = float_of_string$1; -exports.int64_format = int64_format; -exports.int_of_string = int_of_string; -exports.int64_of_string = int64_of_string; -/* No side effect */ diff --git a/lib/js/caml_hash.js b/lib/js/caml_hash.js deleted file mode 100644 index 76a6293626..0000000000 --- a/lib/js/caml_hash.js +++ /dev/null @@ -1,97 +0,0 @@ -'use strict'; - -let Caml_hash_primitive = require("./caml_hash_primitive.js"); - -function push_back(q, v) { - let cell = { - content: v, - next: undefined - }; - let last = q.last; - if (last !== undefined) { - q.length = q.length + 1 | 0; - last.next = cell; - q.last = cell; - } else { - q.length = 1; - q.first = cell; - q.last = cell; - } -} - -function unsafe_pop(q) { - let cell = q.first; - let next = cell.next; - if (next === undefined) { - q.length = 0; - q.first = undefined; - q.last = undefined; - } else { - q.length = q.length - 1 | 0; - q.first = next; - } - return cell.content; -} - -function hash(count, _limit, seed, obj) { - let s = seed; - if (typeof obj === "number") { - let u = obj | 0; - s = Caml_hash_primitive.hash_mix_int(s, (u + u | 0) + 1 | 0); - return Caml_hash_primitive.hash_final_mix(s); - } - if (typeof obj === "string") { - s = Caml_hash_primitive.hash_mix_string(s, obj); - return Caml_hash_primitive.hash_final_mix(s); - } - let queue = { - length: 0, - first: undefined, - last: undefined - }; - let num = count; - push_back(queue, obj); - num = num - 1 | 0; - while (queue.length !== 0 && num > 0) { - let obj$1 = unsafe_pop(queue); - if (typeof obj$1 === "number") { - let u$1 = obj$1 | 0; - s = Caml_hash_primitive.hash_mix_int(s, (u$1 + u$1 | 0) + 1 | 0); - num = num - 1 | 0; - } else if (typeof obj$1 === "string") { - s = Caml_hash_primitive.hash_mix_string(s, obj$1); - num = num - 1 | 0; - } else if (typeof obj$1 !== "boolean" && typeof obj$1 !== "undefined" && typeof obj$1 !== "symbol" && typeof obj$1 !== "function") { - let size = obj$1.length | 0; - if (size !== 0) { - let obj_tag = obj$1.TAG; - let tag = (size << 10) | obj_tag; - if (obj_tag === 248) { - s = Caml_hash_primitive.hash_mix_int(s, obj$1[1]); - } else { - s = Caml_hash_primitive.hash_mix_int(s, tag); - let v = size - 1 | 0; - let block = v < num ? v : num; - for (let i = 0; i <= block; ++i) { - push_back(queue, obj$1[i]); - } - } - } else { - let size$1 = (function(obj,cb){ - var size = 0 - for(var k in obj){ - cb(obj[k]) - ++ size - } - return size - })(obj$1, v => push_back(queue, v)); - s = Caml_hash_primitive.hash_mix_int(s, (size$1 << 10) | 0); - } - } - - }; - return Caml_hash_primitive.hash_final_mix(s); -} - -exports.hash = hash; -/* No side effect */ diff --git a/lib/js/caml_hash_primitive.js b/lib/js/caml_hash_primitive.js deleted file mode 100644 index 48c71a6725..0000000000 --- a/lib/js/caml_hash_primitive.js +++ /dev/null @@ -1,49 +0,0 @@ -'use strict'; - - -function rotl32(x, n) { - return (x << n) | (x >>> (32 - n | 0)) | 0; -} - -function hash_mix_int(h, d) { - let d$1 = d; - d$1 = Math.imul(d$1, -862048943); - d$1 = rotl32(d$1, 15); - d$1 = Math.imul(d$1, 461845907); - let h$1 = h ^ d$1; - h$1 = rotl32(h$1, 13); - return (h$1 + (h$1 << 2) | 0) - 430675100 | 0; -} - -function hash_final_mix(h) { - let h$1 = h ^ (h >>> 16); - h$1 = Math.imul(h$1, -2048144789); - h$1 = h$1 ^ (h$1 >>> 13); - h$1 = Math.imul(h$1, -1028477387); - return h$1 ^ (h$1 >>> 16); -} - -function hash_mix_string(h, s) { - let len = s.length; - let block = (len / 4 | 0) - 1 | 0; - let hash = h; - for (let i = 0; i <= block; ++i) { - let j = (i << 2); - let w = s.charCodeAt(j) | (s.charCodeAt(j + 1 | 0) << 8) | (s.charCodeAt(j + 2 | 0) << 16) | (s.charCodeAt(j + 3 | 0) << 24); - hash = hash_mix_int(hash, w); - } - let modulo = len & 3; - if (modulo !== 0) { - let w$1 = modulo === 3 ? (s.charCodeAt(len - 1 | 0) << 16) | (s.charCodeAt(len - 2 | 0) << 8) | s.charCodeAt(len - 3 | 0) : ( - modulo === 2 ? (s.charCodeAt(len - 1 | 0) << 8) | s.charCodeAt(len - 2 | 0) : s.charCodeAt(len - 1 | 0) - ); - hash = hash_mix_int(hash, w$1); - } - hash = hash ^ len; - return hash; -} - -exports.hash_mix_int = hash_mix_int; -exports.hash_mix_string = hash_mix_string; -exports.hash_final_mix = hash_final_mix; -/* No side effect */ diff --git a/lib/js/caml_int64.js b/lib/js/caml_int64.js deleted file mode 100644 index e83b0b310d..0000000000 --- a/lib/js/caml_int64.js +++ /dev/null @@ -1,602 +0,0 @@ -'use strict'; - -let Caml = require("./caml.js"); - -function mk(lo, hi) { - return [ - hi, - (lo >>> 0) - ]; -} - -let min_int = [ - -2147483648, - 0 -]; - -let max_int = [ - 2147483647, - 4294967295 -]; - -let one = [ - 0, - 1 -]; - -let zero = [ - 0, - 0 -]; - -let neg_one = [ - -1, - 4294967295 -]; - -function neg_signed(x) { - return (x & -2147483648) !== 0; -} - -function non_neg_signed(x) { - return (x & -2147483648) === 0; -} - -function succ(param) { - let x_lo = param[1]; - let x_hi = param[0]; - let lo = x_lo + 1 | 0; - return [ - x_hi + ( - lo === 0 ? 1 : 0 - ) | 0, - (lo >>> 0) - ]; -} - -function neg(param) { - let other_lo = (param[1] ^ -1) + 1 | 0; - return [ - (param[0] ^ -1) + ( - other_lo === 0 ? 1 : 0 - ) | 0, - (other_lo >>> 0) - ]; -} - -function add_aux(param, y_lo, y_hi) { - let x_lo = param[1]; - let lo = x_lo + y_lo | 0; - let overflow = neg_signed(x_lo) && (neg_signed(y_lo) || non_neg_signed(lo)) || neg_signed(y_lo) && non_neg_signed(lo) ? 1 : 0; - return [ - param[0] + y_hi + overflow | 0, - (lo >>> 0) - ]; -} - -function add(self, param) { - return add_aux(self, param[1], param[0]); -} - -function equal(x, y) { - if (x[1] === y[1]) { - return x[0] === y[0]; - } else { - return false; - } -} - -function equal_null(x, y) { - if (y !== null) { - return Caml.i64_eq(x, y); - } else { - return false; - } -} - -function equal_undefined(x, y) { - if (y !== undefined) { - return Caml.i64_eq(x, y); - } else { - return false; - } -} - -function equal_nullable(x, y) { - if (y == null) { - return false; - } else { - return Caml.i64_eq(x, y); - } -} - -function sub_aux(x, lo, hi) { - let y_lo = ((lo ^ -1) + 1 >>> 0); - let y_hi = (hi ^ -1) + ( - y_lo === 0 ? 1 : 0 - ) | 0; - return add_aux(x, y_lo, y_hi); -} - -function sub(self, param) { - return sub_aux(self, param[1], param[0]); -} - -function lsl_(x, numBits) { - if (numBits === 0) { - return x; - } - let lo = x[1]; - if (numBits >= 32) { - return [ - (lo << (numBits - 32 | 0)), - 0 - ]; - } else { - return [ - (lo >>> (32 - numBits | 0)) | (x[0] << numBits), - ((lo << numBits) >>> 0) - ]; - } -} - -function lsr_(x, numBits) { - if (numBits === 0) { - return x; - } - let hi = x[0]; - let offset = numBits - 32 | 0; - if (offset === 0) { - return [ - 0, - (hi >>> 0) - ]; - } else if (offset > 0) { - return [ - 0, - (hi >>> offset) - ]; - } else { - return [ - (hi >>> numBits), - (((hi << (-offset | 0)) | (x[1] >>> numBits)) >>> 0) - ]; - } -} - -function asr_(x, numBits) { - if (numBits === 0) { - return x; - } - let hi = x[0]; - if (numBits < 32) { - return [ - (hi >> numBits), - (((hi << (32 - numBits | 0)) | (x[1] >>> numBits)) >>> 0) - ]; - } else { - return [ - hi >= 0 ? 0 : -1, - ((hi >> (numBits - 32 | 0)) >>> 0) - ]; - } -} - -function is_zero(x) { - if (x[0] !== 0) { - return false; - } else { - return x[1] === 0; - } -} - -function mul(_this, _other) { - while (true) { - let other = _other; - let $$this = _this; - let lo; - let this_hi = $$this[0]; - let exit = 0; - let exit$1 = 0; - let exit$2 = 0; - if (this_hi !== 0) { - exit$2 = 4; - } else { - if ($$this[1] === 0) { - return zero; - } - exit$2 = 4; - } - if (exit$2 === 4) { - if (other[0] !== 0) { - exit$1 = 3; - } else { - if (other[1] === 0) { - return zero; - } - exit$1 = 3; - } - } - if (exit$1 === 3) { - if (this_hi !== -2147483648 || $$this[1] !== 0) { - exit = 2; - } else { - lo = other[1]; - } - } - if (exit === 2) { - let other_hi = other[0]; - let lo$1 = $$this[1]; - let exit$3 = 0; - if (other_hi !== -2147483648 || other[1] !== 0) { - exit$3 = 3; - } else { - lo = lo$1; - } - if (exit$3 === 3) { - let other_lo = other[1]; - if (this_hi < 0) { - if (other_hi >= 0) { - return neg(mul(neg($$this), other)); - } - _other = neg(other); - _this = neg($$this); - continue; - } - if (other_hi < 0) { - return neg(mul($$this, neg(other))); - } - let a48 = (this_hi >>> 16); - let a32 = this_hi & 65535; - let a16 = (lo$1 >>> 16); - let a00 = lo$1 & 65535; - let b48 = (other_hi >>> 16); - let b32 = other_hi & 65535; - let b16 = (other_lo >>> 16); - let b00 = other_lo & 65535; - let c48 = 0; - let c32 = 0; - let c16 = 0; - let c00 = a00 * b00; - c16 = (c00 >>> 16) + a16 * b00; - c32 = (c16 >>> 16); - c16 = (c16 & 65535) + a00 * b16; - c32 = c32 + (c16 >>> 16) + a32 * b00; - c48 = (c32 >>> 16); - c32 = (c32 & 65535) + a16 * b16; - c48 = c48 + (c32 >>> 16); - c32 = (c32 & 65535) + a00 * b32; - c48 = c48 + (c32 >>> 16); - c32 = c32 & 65535; - c48 = c48 + (a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48) & 65535; - return [ - c32 | (c48 << 16), - ((c00 & 65535 | ((c16 & 65535) << 16)) >>> 0) - ]; - } - - } - if ((lo & 1) === 0) { - return zero; - } else { - return min_int; - } - }; -} - -function xor(param, param$1) { - return [ - param[0] ^ param$1[0], - ((param[1] ^ param$1[1]) >>> 0) - ]; -} - -function or_(param, param$1) { - return [ - param[0] | param$1[0], - ((param[1] | param$1[1]) >>> 0) - ]; -} - -function and_(param, param$1) { - return [ - param[0] & param$1[0], - ((param[1] & param$1[1]) >>> 0) - ]; -} - -function to_float(param) { - return param[0] * 0x100000000 + param[1]; -} - -function of_float(x) { - if (isNaN(x) || !isFinite(x)) { - return zero; - } - if (x <= -9.22337203685477581e+18) { - return min_int; - } - if (x + 1 >= 9.22337203685477581e+18) { - return max_int; - } - if (x < 0) { - return neg(of_float(- x)); - } - let hi = x / 4294967296 | 0; - let lo = x % 4294967296 | 0; - return [ - hi, - (lo >>> 0) - ]; -} - -function isSafeInteger(param) { - let hi = param[0]; - let top11Bits = (hi >> 21); - if (top11Bits === 0) { - return true; - } else if (top11Bits === -1) { - return !(param[1] === 0 && hi === -2097152); - } else { - return false; - } -} - -function to_string(self) { - if (isSafeInteger(self)) { - return String(to_float(self)); - } - if (self[0] < 0) { - if (Caml.i64_eq(self, min_int)) { - return "-9223372036854775808"; - } else { - return "-" + to_string(neg(self)); - } - } - let approx_div1 = of_float(Math.floor(to_float(self) / 10)); - let lo = approx_div1[1]; - let hi = approx_div1[0]; - let match = sub_aux(sub_aux(self, (lo << 3), (lo >>> 29) | (hi << 3)), (lo << 1), (lo >>> 31) | (hi << 1)); - let rem_lo = match[1]; - let rem_hi = match[0]; - if (rem_lo === 0 && rem_hi === 0) { - return to_string(approx_div1) + "0"; - } - if (rem_hi < 0) { - let rem_lo$1 = ((rem_lo ^ -1) + 1 >>> 0); - let delta = Math.ceil(rem_lo$1 / 10); - let remainder = 10 * delta - rem_lo$1; - return to_string(sub_aux(approx_div1, delta | 0, 0)) + String(remainder | 0); - } - let delta$1 = Math.floor(rem_lo / 10); - let remainder$1 = rem_lo - 10 * delta$1; - return to_string(add_aux(approx_div1, delta$1 | 0, 0)) + String(remainder$1 | 0); -} - -function div(_self, _other) { - while (true) { - let other = _other; - let self = _self; - let self_hi = self[0]; - let exit = 0; - let exit$1 = 0; - if (other[0] !== 0 || other[1] !== 0) { - exit$1 = 2; - } else { - throw { - RE_EXN_ID: "Division_by_zero", - Error: new Error() - }; - } - if (exit$1 === 2) { - if (self_hi !== -2147483648) { - if (self_hi !== 0) { - exit = 1; - } else { - if (self[1] === 0) { - return zero; - } - exit = 1; - } - } else if (self[1] !== 0) { - exit = 1; - } else { - if (Caml.i64_eq(other, one) || Caml.i64_eq(other, neg_one)) { - return self; - } - if (Caml.i64_eq(other, min_int)) { - return one; - } - let half_this = asr_(self, 1); - let approx = lsl_(div(half_this, other), 1); - let exit$2 = 0; - if (approx[0] !== 0) { - exit$2 = 3; - } else { - if (approx[1] === 0) { - if (other[0] < 0) { - return one; - } else { - return neg(one); - } - } - exit$2 = 3; - } - if (exit$2 === 3) { - let rem = sub(self, mul(other, approx)); - return add(approx, div(rem, other)); - } - - } - } - if (exit === 1) { - let other_hi = other[0]; - let exit$3 = 0; - if (other_hi !== -2147483648) { - exit$3 = 2; - } else { - if (other[1] === 0) { - return zero; - } - exit$3 = 2; - } - if (exit$3 === 2) { - if (self_hi < 0) { - if (other_hi >= 0) { - return neg(div(neg(self), other)); - } - _other = neg(other); - _self = neg(self); - continue; - } - if (other_hi < 0) { - return neg(div(self, neg(other))); - } - let res = zero; - let rem$1 = self; - while (Caml.i64_ge(rem$1, other)) { - let b = Math.floor(to_float(rem$1) / to_float(other)); - let approx$1 = 1 > b ? 1 : b; - let log2 = Math.ceil(Math.log(approx$1) / Math.LN2); - let delta = log2 <= 48 ? 1 : Math.pow(2, log2 - 48); - let approxRes = of_float(approx$1); - let approxRem = mul(approxRes, other); - while (approxRem[0] < 0 || Caml.i64_gt(approxRem, rem$1)) { - approx$1 = approx$1 - delta; - approxRes = of_float(approx$1); - approxRem = mul(approxRes, other); - }; - if (is_zero(approxRes)) { - approxRes = one; - } - res = add(res, approxRes); - rem$1 = sub(rem$1, approxRem); - }; - return res; - } - - } - - }; -} - -function mod_(self, other) { - return sub(self, mul(div(self, other), other)); -} - -function div_mod(self, other) { - let quotient = div(self, other); - return [ - quotient, - sub(self, mul(quotient, other)) - ]; -} - -function compare(self, other) { - let y = other[0]; - let x = self[0]; - let v = x < y ? -1 : ( - x === y ? 0 : 1 - ); - if (v !== 0) { - return v; - } - let y$1 = other[1]; - let x$1 = self[1]; - if (x$1 < y$1) { - return -1; - } else if (x$1 === y$1) { - return 0; - } else { - return 1; - } -} - -function of_int32(lo) { - return [ - lo < 0 ? -1 : 0, - (lo >>> 0) - ]; -} - -function to_int32(x) { - return x[1] | 0; -} - -function to_hex(x) { - let x_lo = x[1]; - let x_hi = x[0]; - let aux = v => (v >>> 0).toString(16); - if (x_hi === 0 && x_lo === 0) { - return "0"; - } - if (x_lo === 0) { - return aux(x_hi) + "00000000"; - } - if (x_hi === 0) { - return aux(x_lo); - } - let lo = aux(x_lo); - let pad = 8 - lo.length | 0; - if (pad <= 0) { - return aux(x_hi) + lo; - } else { - return aux(x_hi) + ("0".repeat(pad) + lo); - } -} - -function discard_sign(x) { - return [ - 2147483647 & x[0], - x[1] - ]; -} - -function float_of_bits(x) { - return (function(lo,hi){ return (new Float64Array(new Int32Array([lo,hi]).buffer))[0]})(x[1], x[0]); -} - -function bits_of_float(x) { - let match = (function(x){return new Int32Array(new Float64Array([x]).buffer)})(x); - return [ - match[1], - (match[0] >>> 0) - ]; -} - -exports.mk = mk; -exports.succ = succ; -exports.min_int = min_int; -exports.max_int = max_int; -exports.one = one; -exports.zero = zero; -exports.neg_one = neg_one; -exports.of_int32 = of_int32; -exports.to_int32 = to_int32; -exports.add = add; -exports.neg = neg; -exports.sub = sub; -exports.lsl_ = lsl_; -exports.lsr_ = lsr_; -exports.asr_ = asr_; -exports.is_zero = is_zero; -exports.mul = mul; -exports.xor = xor; -exports.or_ = or_; -exports.and_ = and_; -exports.equal = equal; -exports.equal_null = equal_null; -exports.equal_undefined = equal_undefined; -exports.equal_nullable = equal_nullable; -exports.to_float = to_float; -exports.of_float = of_float; -exports.div = div; -exports.mod_ = mod_; -exports.compare = compare; -exports.float_of_bits = float_of_bits; -exports.bits_of_float = bits_of_float; -exports.div_mod = div_mod; -exports.to_hex = to_hex; -exports.discard_sign = discard_sign; -exports.to_string = to_string; -/* No side effect */ diff --git a/lib/js/caml_js_exceptions.js b/lib/js/caml_js_exceptions.js deleted file mode 100644 index 6d49e5228a..0000000000 --- a/lib/js/caml_js_exceptions.js +++ /dev/null @@ -1,29 +0,0 @@ -'use strict'; - -let Caml_option = require("./caml_option.js"); -let Caml_exceptions = require("./caml_exceptions.js"); - -let $$Error = "JsError"; - -function internalToOCamlException(e) { - if (Caml_exceptions.is_extension(e)) { - return e; - } else { - return { - RE_EXN_ID: "JsError", - _1: e - }; - } -} - -function as_js_exn(exn) { - if (exn.RE_EXN_ID === $$Error) { - return Caml_option.some(exn._1); - } - -} - -exports.$$Error = $$Error; -exports.internalToOCamlException = internalToOCamlException; -exports.as_js_exn = as_js_exn; -/* No side effect */ diff --git a/lib/js/caml_lexer.js b/lib/js/caml_lexer.js deleted file mode 100644 index 1a5be6d097..0000000000 --- a/lib/js/caml_lexer.js +++ /dev/null @@ -1,256 +0,0 @@ -'use strict'; - - -/***********************************************************************/ -/* */ -/* Objective Caml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 Institut National de Recherche en Informatique et */ -/* en Automatique. All rights reserved. This file is distributed */ -/* under the terms of the GNU Library General Public License, with */ -/* the special exception on linking described in file ../LICENSE. */ -/* */ -/***********************************************************************/ - -/* $Id: lexing.c 6045 2004-01-01 16:42:43Z doligez $ */ - -/* The table-driven automaton for lexers generated by camllex. */ - -function caml_lex_array(s) { - var l = s.length / 2; - var a = new Array(l); - // when s.charCodeAt(2 * i + 1 ) > 128 (0x80) - // a[i] < 0 - // for(var i = 0 ; i <= 0xffff; ++i) { if (i << 16 >> 16 !==i){console.log(i<<16>>16, 'vs',i)}} - // - for (var i = 0; i < l; i++) - a[i] = (s.charCodeAt(2 * i) | (s.charCodeAt(2 * i + 1) << 8)) << 16 >> 16; - return a; -} -; - -let caml_lex_engine_aux = (function (tbl, start_state, lexbuf, exn){ - - if (!Array.isArray(tbl.lex_default)) { - tbl.lex_base = caml_lex_array(tbl.lex_base); - tbl.lex_backtrk = caml_lex_array(tbl.lex_backtrk); - tbl.lex_check = caml_lex_array(tbl.lex_check); - tbl.lex_trans = caml_lex_array(tbl.lex_trans); - tbl.lex_default = caml_lex_array(tbl.lex_default); - } - var c; - var state = start_state; - //var buffer = bytes_of_string(lexbuf.lex_buffer); - var buffer = lexbuf.lex_buffer; - if (state >= 0) { - /* First entry */ - lexbuf.lex_last_pos = lexbuf.lex_start_pos = lexbuf.lex_curr_pos; - lexbuf.lex_last_action = -1; - } - else { - /* Reentry after refill */ - state = -state - 1; - } - for (;;) { - /* Lookup base address or action number for current state */ - var base = tbl.lex_base[state]; - if (base < 0) - return -base - 1; - /* See if it's a backtrack point */ - var backtrk = tbl.lex_backtrk[state]; - if (backtrk >= 0) { - lexbuf.lex_last_pos = lexbuf.lex_curr_pos; - lexbuf.lex_last_action = backtrk; - } - /* See if we need a refill */ - if (lexbuf.lex_curr_pos >= lexbuf.lex_buffer_len) { - if (lexbuf.lex_eof_reached === 0) - return -state - 1; - else - c = 256; - } - else { - /* Read next input char */ - c = buffer[lexbuf.lex_curr_pos]; - lexbuf.lex_curr_pos++; - } - /* Determine next state */ - if (tbl.lex_check[base + c] === state) { - state = tbl.lex_trans[base + c]; - } - else { - state = tbl.lex_default[state]; - } - /* If no transition on this char, return to last backtrack point */ - if (state < 0) { - lexbuf.lex_curr_pos = lexbuf.lex_last_pos; - if (lexbuf.lex_last_action == -1) - throw exn - else - return lexbuf.lex_last_action; - } - else { - /* Erase the EOF condition only if the EOF pseudo-character was - consumed by the automaton (i.e. there was no backtrack above) - */ - if (c == 256) - lexbuf.lex_eof_reached = 0; - } - } -}); - -let empty_token_lit = "lexing: empty token"; - -function lex_engine(tbls, i, buf) { - return caml_lex_engine_aux(tbls, i, buf, { - RE_EXN_ID: "Failure", - _1: empty_token_lit - }); -} - -/***********************************************/ -/* New lexer engine, with memory of positions */ -/***********************************************/ - -/** - * s -> Lexing.lex_tables.lex_code - * mem -> Lexing.lexbuf.lex_mem (* int array *) - */ - -function caml_lex_run_mem(s, i, mem, curr_pos) { - for (;;) { - var dst = s.charCodeAt(i); - i++; - if (dst == 0xff) - return; - var src = s.charCodeAt(i); - i++; - if (src == 0xff) - mem[dst] = curr_pos; - else - mem[dst] = mem[src]; - } -} - - -/** - * s -> Lexing.lex_tables.lex_code - * mem -> Lexing.lexbuf.lex_mem (* int array *) - */ - -function caml_lex_run_tag(s, i, mem) { - for (;;) { - var dst = s.charCodeAt(i); - i++; - if (dst == 0xff) - return; - var src = s.charCodeAt(i); - i++; - if (src == 0xff) - mem[dst] = -1; - else - mem[dst] = mem[src]; - } -} -; - -let caml_new_lex_engine_aux = (function (tbl, start_state, lexbuf, exn) { - - if (!Array.isArray(tbl.lex_default)) { - tbl.lex_base = caml_lex_array(tbl.lex_base); - tbl.lex_backtrk = caml_lex_array(tbl.lex_backtrk); - tbl.lex_check = caml_lex_array(tbl.lex_check); - tbl.lex_trans = caml_lex_array(tbl.lex_trans); - tbl.lex_default = caml_lex_array(tbl.lex_default); - } - if(!Array.isArray(tbl.lex_default_code)){ - tbl.lex_base_code = caml_lex_array(tbl.lex_base_code); - tbl.lex_backtrk_code = caml_lex_array(tbl.lex_backtrk_code); - tbl.lex_check_code = caml_lex_array(tbl.lex_check_code); - tbl.lex_trans_code = caml_lex_array(tbl.lex_trans_code); - tbl.lex_default_code = caml_lex_array(tbl.lex_default_code); - } - var c, state = start_state; - //var buffer = caml_bytes_of_string(lexbuf.lex_buffer); - var buffer = lexbuf.lex_buffer; - if (state >= 0) { - /* First entry */ - lexbuf.lex_last_pos = lexbuf.lex_start_pos = lexbuf.lex_curr_pos; - lexbuf.lex_last_action = -1; - } - else { - /* Reentry after refill */ - state = -state - 1; - } - for (;;) { - /* Lookup base address or action number for current state */ - var base = tbl.lex_base[state]; - if (base < 0) { - var pc_off = tbl.lex_base_code[state]; - caml_lex_run_tag(tbl.lex_code, pc_off, lexbuf.lex_mem); - return -base - 1; - } - /* See if it's a backtrack point */ - var backtrk = tbl.lex_backtrk[state]; - if (backtrk >= 0) { - var pc_off = tbl.lex_backtrk_code[state]; - caml_lex_run_tag(tbl.lex_code, pc_off, lexbuf.lex_mem); - lexbuf.lex_last_pos = lexbuf.lex_curr_pos; - lexbuf.lex_last_action = backtrk; - } - /* See if we need a refill */ - if (lexbuf.lex_curr_pos >= lexbuf.lex_buffer_len) { - if (lexbuf.lex_eof_reached == 0) - return -state - 1; - else - c = 256; - } - else { - /* Read next input char */ - c = buffer[lexbuf.lex_curr_pos]; - lexbuf.lex_curr_pos++; - } - /* Determine next state */ - var pstate = state; - if (tbl.lex_check[base + c] == state) - state = tbl.lex_trans[base + c]; - else - state = tbl.lex_default[state]; - /* If no transition on this char, return to last backtrack point */ - if (state < 0) { - lexbuf.lex_curr_pos = lexbuf.lex_last_pos; - if (lexbuf.lex_last_action == -1) - throw exn; - else - return lexbuf.lex_last_action; - } - else { - /* If some transition, get and perform memory moves */ - var base_code = tbl.lex_base_code[pstate], pc_off; - if (tbl.lex_check_code[base_code + c] == pstate) - pc_off = tbl.lex_trans_code[base_code + c]; - else - pc_off = tbl.lex_default_code[pstate]; - if (pc_off > 0) - caml_lex_run_mem(tbl.lex_code, pc_off, lexbuf.lex_mem, lexbuf.lex_curr_pos); - /* Erase the EOF condition only if the EOF pseudo-character was - consumed by the automaton (i.e. there was no backtrack above) - */ - if (c == 256) - lexbuf.lex_eof_reached = 0; - } - } - }); - -function new_lex_engine(tbl, i, buf) { - return caml_new_lex_engine_aux(tbl, i, buf, { - RE_EXN_ID: "Failure", - _1: empty_token_lit - }); -} - -exports.lex_engine = lex_engine; -exports.new_lex_engine = new_lex_engine; -/* Not a pure module */ diff --git a/lib/js/caml_md5.js b/lib/js/caml_md5.js deleted file mode 100644 index 686a1ec3b6..0000000000 --- a/lib/js/caml_md5.js +++ /dev/null @@ -1,166 +0,0 @@ -'use strict'; - - -function cmn(q, a, b, x, s, t) { - let a$1 = ((a + q | 0) + x | 0) + t | 0; - return ((a$1 << s) | (a$1 >>> (32 - s | 0)) | 0) + b | 0; -} - -function f(a, b, c, d, x, s, t) { - return cmn(b & c | (b ^ -1) & d, a, b, x, s, t); -} - -function g(a, b, c, d, x, s, t) { - return cmn(b & d | c & (d ^ -1), a, b, x, s, t); -} - -function h(a, b, c, d, x, s, t) { - return cmn(b ^ c ^ d, a, b, x, s, t); -} - -function i(a, b, c, d, x, s, t) { - return cmn(c ^ (b | d ^ -1), a, b, x, s, t); -} - -function cycle(x, k) { - let a = x[0]; - let b = x[1]; - let c = x[2]; - let d = x[3]; - a = f(a, b, c, d, k[0], 7, -680876936); - d = f(d, a, b, c, k[1], 12, -389564586); - c = f(c, d, a, b, k[2], 17, 606105819); - b = f(b, c, d, a, k[3], 22, -1044525330); - a = f(a, b, c, d, k[4], 7, -176418897); - d = f(d, a, b, c, k[5], 12, 1200080426); - c = f(c, d, a, b, k[6], 17, -1473231341); - b = f(b, c, d, a, k[7], 22, -45705983); - a = f(a, b, c, d, k[8], 7, 1770035416); - d = f(d, a, b, c, k[9], 12, -1958414417); - c = f(c, d, a, b, k[10], 17, -42063); - b = f(b, c, d, a, k[11], 22, -1990404162); - a = f(a, b, c, d, k[12], 7, 1804603682); - d = f(d, a, b, c, k[13], 12, -40341101); - c = f(c, d, a, b, k[14], 17, -1502002290); - b = f(b, c, d, a, k[15], 22, 1236535329); - a = g(a, b, c, d, k[1], 5, -165796510); - d = g(d, a, b, c, k[6], 9, -1069501632); - c = g(c, d, a, b, k[11], 14, 643717713); - b = g(b, c, d, a, k[0], 20, -373897302); - a = g(a, b, c, d, k[5], 5, -701558691); - d = g(d, a, b, c, k[10], 9, 38016083); - c = g(c, d, a, b, k[15], 14, -660478335); - b = g(b, c, d, a, k[4], 20, -405537848); - a = g(a, b, c, d, k[9], 5, 568446438); - d = g(d, a, b, c, k[14], 9, -1019803690); - c = g(c, d, a, b, k[3], 14, -187363961); - b = g(b, c, d, a, k[8], 20, 1163531501); - a = g(a, b, c, d, k[13], 5, -1444681467); - d = g(d, a, b, c, k[2], 9, -51403784); - c = g(c, d, a, b, k[7], 14, 1735328473); - b = g(b, c, d, a, k[12], 20, -1926607734); - a = h(a, b, c, d, k[5], 4, -378558); - d = h(d, a, b, c, k[8], 11, -2022574463); - c = h(c, d, a, b, k[11], 16, 1839030562); - b = h(b, c, d, a, k[14], 23, -35309556); - a = h(a, b, c, d, k[1], 4, -1530992060); - d = h(d, a, b, c, k[4], 11, 1272893353); - c = h(c, d, a, b, k[7], 16, -155497632); - b = h(b, c, d, a, k[10], 23, -1094730640); - a = h(a, b, c, d, k[13], 4, 681279174); - d = h(d, a, b, c, k[0], 11, -358537222); - c = h(c, d, a, b, k[3], 16, -722521979); - b = h(b, c, d, a, k[6], 23, 76029189); - a = h(a, b, c, d, k[9], 4, -640364487); - d = h(d, a, b, c, k[12], 11, -421815835); - c = h(c, d, a, b, k[15], 16, 530742520); - b = h(b, c, d, a, k[2], 23, -995338651); - a = i(a, b, c, d, k[0], 6, -198630844); - d = i(d, a, b, c, k[7], 10, 1126891415); - c = i(c, d, a, b, k[14], 15, -1416354905); - b = i(b, c, d, a, k[5], 21, -57434055); - a = i(a, b, c, d, k[12], 6, 1700485571); - d = i(d, a, b, c, k[3], 10, -1894986606); - c = i(c, d, a, b, k[10], 15, -1051523); - b = i(b, c, d, a, k[1], 21, -2054922799); - a = i(a, b, c, d, k[8], 6, 1873313359); - d = i(d, a, b, c, k[15], 10, -30611744); - c = i(c, d, a, b, k[6], 15, -1560198380); - b = i(b, c, d, a, k[13], 21, 1309151649); - a = i(a, b, c, d, k[4], 6, -145523070); - d = i(d, a, b, c, k[11], 10, -1120210379); - c = i(c, d, a, b, k[2], 15, 718787259); - b = i(b, c, d, a, k[9], 21, -343485551); - x[0] = a + x[0] | 0; - x[1] = b + x[1] | 0; - x[2] = c + x[2] | 0; - x[3] = d + x[3] | 0; -} - -let state = [ - 1732584193, - -271733879, - -1732584194, - 271733878 -]; - -let md5blk = [ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 -]; - -function md5_string(s, start, len) { - let s$1 = s.slice(start, len); - let n = s$1.length; - state[0] = 1732584193; - state[1] = -271733879; - state[2] = -1732584194; - state[3] = 271733878; - for (let i = 0; i <= 15; ++i) { - md5blk[i] = 0; - } - let i_end = n / 64 | 0; - for (let i$1 = 1; i$1 <= i_end; ++i$1) { - for (let j = 0; j <= 15; ++j) { - let k = ((i$1 << 6) - 64 | 0) + (j << 2) | 0; - md5blk[j] = ((s$1.charCodeAt(k) + (s$1.charCodeAt(k + 1 | 0) << 8) | 0) + (s$1.charCodeAt(k + 2 | 0) << 16) | 0) + (s$1.charCodeAt(k + 3 | 0) << 24) | 0; - } - cycle(state, md5blk); - } - let s_tail = s$1.slice((i_end << 6)); - for (let kk = 0; kk <= 15; ++kk) { - md5blk[kk] = 0; - } - let i_end$1 = s_tail.length - 1 | 0; - for (let i$2 = 0; i$2 <= i_end$1; ++i$2) { - md5blk[i$2 / 4 | 0] = md5blk[i$2 / 4 | 0] | (s_tail.charCodeAt(i$2) << (i$2 % 4 << 3)); - } - let i$3 = i_end$1 + 1 | 0; - md5blk[i$3 / 4 | 0] = md5blk[i$3 / 4 | 0] | (128 << (i$3 % 4 << 3)); - if (i$3 > 55) { - cycle(state, md5blk); - for (let i$4 = 0; i$4 <= 15; ++i$4) { - md5blk[i$4] = 0; - } - } - md5blk[14] = (n << 3); - cycle(state, md5blk); - return String.fromCharCode(state[0] & 255, (state[0] >> 8) & 255, (state[0] >> 16) & 255, (state[0] >> 24) & 255, state[1] & 255, (state[1] >> 8) & 255, (state[1] >> 16) & 255, (state[1] >> 24) & 255, state[2] & 255, (state[2] >> 8) & 255, (state[2] >> 16) & 255, (state[2] >> 24) & 255, state[3] & 255, (state[3] >> 8) & 255, (state[3] >> 16) & 255, (state[3] >> 24) & 255); -} - -exports.md5_string = md5_string; -/* No side effect */ diff --git a/lib/js/caml_parser.js b/lib/js/caml_parser.js deleted file mode 100644 index 92cf721e98..0000000000 --- a/lib/js/caml_parser.js +++ /dev/null @@ -1,301 +0,0 @@ -'use strict'; - - -/***********************************************************************/ -/* */ -/* Objective Caml */ -/* */ -/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */ -/* */ -/* Copyright 1996 Institut National de Recherche en Informatique et */ -/* en Automatique. All rights reserved. This file is distributed */ -/* under the terms of the GNU Library General Public License, with */ -/* the special exception on linking described in file ../LICENSE. */ -/* */ -/***********************************************************************/ - -/* $Id: parsing.c 8983 2008-08-06 09:38:25Z xleroy $ */ - -/* The PDA automaton for parsers generated by camlyacc */ - -/* The pushdown automata */ - -/** - * caml_lex_array("abcd") - * [25185, 25699] - * @param s - * @returns {any[]} - * TODO: duplicated with module {!Caml_lex} - */ -function caml_lex_array(s) { - var l = s.length / 2; - var a = new Array(l); - for (var i = 0; i < l; i++) - a[i] = (s.charCodeAt(2 * i) | (s.charCodeAt(2 * i + 1) << 8)) << 16 >> 16; - return a; -} -/** - * Note that TS enum is not friendly to Closure compiler - * @enum{number} - */ -var Automata = { - START: 0, - LOOP: 6, - TOKEN_READ: 1, - TEST_SHIFT: 7, - ERROR_DETECTED: 5, - SHIFT: 8, - SHIFT_RECOVER: 9, - STACK_GROWN_1: 2, - REDUCE: 10, - STACK_GROWN_2: 3, - SEMANTIC_ACTION_COMPUTED: 4 -}; -/** - * @enum{number} - */ -var Result = { - READ_TOKEN: 0, - RAISE_PARSE_ERROR: 1, - GROW_STACKS_1: 2, - GROW_STACKS_2: 3, - COMPUTE_SEMANTIC_ACTION: 4, - CALL_ERROR_FUNCTION: 5 -}; -var PARSER_TRACE = false; -; - -let parse_engine = (function (tables /* parser_table */, env /* parser_env */, cmd /* parser_input*/, arg /* Obj.t*/) { - var ERRCODE = 256; - //var START = 0; - //var TOKEN_READ = 1; - //var STACKS_GROWN_1 = 2; - //var STACKS_GROWN_2 = 3; - //var SEMANTIC_ACTION_COMPUTED = 4; - //var ERROR_DETECTED = 5; - //var loop = 6; - //var testshift = 7; - //var shift = 8; - //var shift_recover = 9; - //var reduce = 10; - // Parsing.parser_env - var env_s_stack = 's_stack'; // array - var env_v_stack = 'v_stack'; // array - var env_symb_start_stack = 'symb_start_stack'; // array - var env_symb_end_stack = 'symb_end_stack'; // array - var env_stacksize = 'stacksize'; - var env_stackbase = 'stackbase'; - var env_curr_char = 'curr_char'; - var env_lval = 'lval'; // Obj.t - var env_symb_start = 'symb_start'; // position - var env_symb_end = 'symb_end'; // position - var env_asp = 'asp'; - var env_rule_len = 'rule_len'; - var env_rule_number = 'rule_number'; - var env_sp = 'sp'; - var env_state = 'state'; - var env_errflag = 'errflag'; - // Parsing.parse_tables - // var _tbl_actions = 1; - var tbl_transl_const = 'transl_const'; // array - var tbl_transl_block = 'transl_block'; // array - var tbl_lhs = 'lhs'; - var tbl_len = 'len'; - var tbl_defred = 'defred'; - var tbl_dgoto = 'dgoto'; - var tbl_sindex = 'sindex'; - var tbl_rindex = 'rindex'; - var tbl_gindex = 'gindex'; - var tbl_tablesize = 'tablesize'; - var tbl_table = 'table'; - var tbl_check = 'check'; - // var _tbl_error_function = 14; - // var _tbl_names_const = 15; - // var _tbl_names_block = 16; - if (!tables.preprocessed) { - tables.defred = caml_lex_array(tables[tbl_defred]); - tables.sindex = caml_lex_array(tables[tbl_sindex]); - tables.check = caml_lex_array(tables[tbl_check]); - tables.rindex = caml_lex_array(tables[tbl_rindex]); - tables.table = caml_lex_array(tables[tbl_table]); - tables.len = caml_lex_array(tables[tbl_len]); - tables.lhs = caml_lex_array(tables[tbl_lhs]); - tables.gindex = caml_lex_array(tables[tbl_gindex]); - tables.dgoto = caml_lex_array(tables[tbl_dgoto]); - tables.preprocessed = true; - } - var res; - var n, n1, n2, state1; - // RESTORE - var sp = env[env_sp]; - var state = env[env_state]; - var errflag = env[env_errflag]; - exit: for (;;) { - //console.error("State", Automata[cmd]); - switch (cmd) { - case Automata.START: - state = 0; - errflag = 0; - // Fall through - case Automata.LOOP: - n = tables.defred[state]; - if (n != 0) { - cmd = Automata.REDUCE; - break; - } - if (env[env_curr_char] >= 0) { - cmd = Automata.TEST_SHIFT; - break; - } - res = Result.READ_TOKEN; - break exit; - /* The ML code calls the lexer and updates */ - /* symb_start and symb_end */ - case Automata.TOKEN_READ: - if (typeof arg !== 'number') { - env[env_curr_char] = tables[tbl_transl_block][arg.TAG | 0 /* + 1 */]; - env[env_lval] = arg._0; // token carries payload - } - else { - env[env_curr_char] = tables[tbl_transl_const][arg /* + 1 */]; - env[env_lval] = 0; // const token - } - if (PARSER_TRACE) { - console.error("State %d, read token", state, arg); - } - // Fall through - case Automata.TEST_SHIFT: - n1 = tables.sindex[state]; - n2 = n1 + env[env_curr_char]; - if (n1 != 0 && n2 >= 0 && n2 <= tables[tbl_tablesize] && - tables.check[n2] == env[env_curr_char]) { - cmd = Automata.SHIFT; - break; - } - n1 = tables.rindex[state]; - n2 = n1 + env[env_curr_char]; - if (n1 != 0 && n2 >= 0 && n2 <= tables[tbl_tablesize] && - tables.check[n2] == env[env_curr_char]) { - n = tables.table[n2]; - cmd = Automata.REDUCE; - break; - } - if (errflag <= 0) { - res = Result.CALL_ERROR_FUNCTION; - break exit; - } - // Fall through - /* The ML code calls the error function */ - case Automata.ERROR_DETECTED: - if (errflag < 3) { - errflag = 3; - for (;;) { - state1 = env[env_s_stack][sp /* + 1*/]; - n1 = tables.sindex[state1]; - n2 = n1 + ERRCODE; - if (n1 != 0 && n2 >= 0 && n2 <= tables[tbl_tablesize] && - tables.check[n2] == ERRCODE) { - cmd = Automata.SHIFT_RECOVER; - break; - } - else { - if (sp <= env[env_stackbase]) - return Result.RAISE_PARSE_ERROR; - /* The ML code raises Parse_error */ - sp--; - } - } - } - else { - if (env[env_curr_char] == 0) - return Result.RAISE_PARSE_ERROR; - /* The ML code raises Parse_error */ - env[env_curr_char] = -1; - cmd = Automata.LOOP; - break; - } - // Fall through - case Automata.SHIFT: - env[env_curr_char] = -1; - if (errflag > 0) - errflag--; - // Fall through - case Automata.SHIFT_RECOVER: - if (PARSER_TRACE) { - console.error("State %d: shift to state %d", state, tables.table[n2]); - } - state = tables.table[n2]; - sp++; - if (sp >= env[env_stacksize]) { - res = Result.GROW_STACKS_1; - break exit; - } - // Fall through - /* The ML code resizes the stacks */ - case Automata.STACK_GROWN_1: - env[env_s_stack][sp /* + 1 */] = state; - env[env_v_stack][sp /* + 1 */] = env[env_lval]; - env[env_symb_start_stack][sp /* + 1 */] = env[env_symb_start]; - env[env_symb_end_stack][sp /* + 1 */] = env[env_symb_end]; - cmd = Automata.LOOP; - break; - case Automata.REDUCE: - if (PARSER_TRACE) { - console.error("State %d : reduce by rule %d", state, n); - } - var m = tables.len[n]; - env[env_asp] = sp; - env[env_rule_number] = n; - env[env_rule_len] = m; - sp = sp - m + 1; - m = tables.lhs[n]; - state1 = env[env_s_stack][sp - 1]; // - n1 = tables.gindex[m]; - n2 = n1 + state1; - if (n1 != 0 && n2 >= 0 && n2 <= tables[tbl_tablesize] && - tables.check[n2] == state1) - state = tables.table[n2]; - else - state = tables.dgoto[m]; - if (sp >= env[env_stacksize]) { - res = Result.GROW_STACKS_2; - break exit; - } - // Fall through - /* The ML code resizes the stacks */ - case Automata.STACK_GROWN_2: - res = Result.COMPUTE_SEMANTIC_ACTION; - break exit; - /* The ML code calls the semantic action */ - case Automata.SEMANTIC_ACTION_COMPUTED: - env[env_s_stack][sp /* + 1 */] = state; - env[env_v_stack][sp /* + 1*/] = arg; - var asp = env[env_asp]; - env[env_symb_end_stack][sp /* + 1*/] = env[env_symb_end_stack][asp /* + 1*/]; - if (sp > asp) { - /* This is an epsilon production. Take symb_start equal to symb_end. */ - env[env_symb_start_stack][sp /* + 1*/] = env[env_symb_end_stack][asp /*+ 1*/]; - } - cmd = Automata.LOOP; - break; - /* Should not happen */ - default: - return Result.RAISE_PARSE_ERROR; - } - } - // SAVE - env[env_sp] = sp; - env[env_state] = state; - env[env_errflag] = errflag; - return res; -}); - -let set_parser_trace = (function (v) { - var old = PARSER_TRACE; - PARSER_TRACE = v; - return old; -}); - -exports.parse_engine = parse_engine; -exports.set_parser_trace = set_parser_trace; -/* Not a pure module */ diff --git a/lib/js/caml_string.js b/lib/js/caml_string.js deleted file mode 100644 index 4ddd60890b..0000000000 --- a/lib/js/caml_string.js +++ /dev/null @@ -1,21 +0,0 @@ -'use strict'; - - -function get(s, i) { - if (i >= s.length || i < 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "index out of bounds", - Error: new Error() - }; - } - return s.codePointAt(i); -} - -function make(n, ch) { - return String.fromCharCode(ch).repeat(n); -} - -exports.get = get; -exports.make = make; -/* No side effect */ diff --git a/lib/js/caml_sys.js b/lib/js/caml_sys.js deleted file mode 100644 index d2b6072de6..0000000000 --- a/lib/js/caml_sys.js +++ /dev/null @@ -1,97 +0,0 @@ -'use strict'; - - -function sys_getenv(s) { - if (typeof process === "undefined" || process.env === undefined) { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let x = process.env[s]; - if (x !== undefined) { - return x; - } - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; -} - -let os_type = (function(_){ - if(typeof process !== 'undefined' && process.platform === 'win32'){ - return "Win32" - } - else { - return "Unix" - } -}); - -function sys_time() { - if (typeof process === "undefined" || process.uptime === undefined) { - return -1; - } else { - return process.uptime(); - } -} - -let sys_getcwd = (function(param){ - if (typeof process === "undefined" || process.cwd === undefined){ - return "/" - } - return process.cwd() - }); - -function sys_get_argv() { - if (typeof process === "undefined") { - return [ - "", - [""] - ]; - } - let argv = process.argv; - if (argv == null) { - return [ - "", - [""] - ]; - } else { - return [ - argv[0], - argv - ]; - } -} - -function sys_exit(exit_code) { - if (typeof process !== "undefined") { - return process.exit(exit_code); - } - -} - -function sys_is_directory(_s) { - throw { - RE_EXN_ID: "Failure", - _1: "sys_is_directory not implemented", - Error: new Error() - }; -} - -function sys_file_exists(_s) { - throw { - RE_EXN_ID: "Failure", - _1: "sys_file_exists not implemented", - Error: new Error() - }; -} - -exports.sys_getenv = sys_getenv; -exports.sys_time = sys_time; -exports.os_type = os_type; -exports.sys_getcwd = sys_getcwd; -exports.sys_get_argv = sys_get_argv; -exports.sys_exit = sys_exit; -exports.sys_is_directory = sys_is_directory; -exports.sys_file_exists = sys_file_exists; -/* No side effect */ diff --git a/lib/js/char.js b/lib/js/char.js index 7a4984f70b..ae5ee0dba6 100644 --- a/lib/js/char.js +++ b/lib/js/char.js @@ -1,16 +1,8 @@ 'use strict'; -let Bytes = require("./bytes.js"); -function chr(n) { - if (n < 0 || n > 255) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Char.chr", - Error: new Error() - }; - } - return n; +function chr(prim) { + return prim; } function escaped(param) { @@ -53,37 +45,16 @@ function escaped(param) { } switch (exit) { case 1 : - let s = [ - 0, - 0, - 0, - 0 - ]; + let s = Array(4); s[0] = /* '\\' */92; s[1] = 48 + (param / 100 | 0) | 0; s[2] = 48 + (param / 10 | 0) % 10 | 0; s[3] = 48 + param % 10 | 0; - return Bytes.to_string(s); + return String.fromCodePoint(...s); case 2 : - let s$1 = [0]; + let s$1 = Array(1); s$1[0] = param; - return Bytes.to_string(s$1); - } -} - -function lowercase(c) { - if (c >= /* 'A' */65 && c <= /* 'Z' */90 || c >= /* '\192' */192 && c <= /* '\214' */214 || c >= /* '\216' */216 && c <= /* '\222' */222) { - return c + 32 | 0; - } else { - return c; - } -} - -function uppercase(c) { - if (c >= /* 'a' */97 && c <= /* 'z' */122 || c >= /* '\224' */224 && c <= /* '\246' */246 || c >= /* '\248' */248 && c <= /* '\254' */254) { - return c - 32 | 0; - } else { - return c; + return String.fromCodePoint(...s$1); } } @@ -113,8 +84,6 @@ function equal(c1, c2) { exports.chr = chr; exports.escaped = escaped; -exports.lowercase = lowercase; -exports.uppercase = uppercase; exports.lowercase_ascii = lowercase_ascii; exports.uppercase_ascii = uppercase_ascii; exports.compare = compare; diff --git a/lib/js/complex.js b/lib/js/complex.js deleted file mode 100644 index 6cedfbb02f..0000000000 --- a/lib/js/complex.js +++ /dev/null @@ -1,174 +0,0 @@ -'use strict'; - - -let one = { - re: 1.0, - im: 0.0 -}; - -function add(x, y) { - return { - re: x.re + y.re, - im: x.im + y.im - }; -} - -function sub(x, y) { - return { - re: x.re - y.re, - im: x.im - y.im - }; -} - -function neg(x) { - return { - re: - x.re, - im: - x.im - }; -} - -function conj(x) { - return { - re: x.re, - im: - x.im - }; -} - -function mul(x, y) { - return { - re: x.re * y.re - x.im * y.im, - im: x.re * y.im + x.im * y.re - }; -} - -function div(x, y) { - if (Math.abs(y.re) >= Math.abs(y.im)) { - let r = y.im / y.re; - let d = y.re + r * y.im; - return { - re: (x.re + r * x.im) / d, - im: (x.im - r * x.re) / d - }; - } - let r$1 = y.re / y.im; - let d$1 = y.im + r$1 * y.re; - return { - re: (r$1 * x.re + x.im) / d$1, - im: (r$1 * x.im - x.re) / d$1 - }; -} - -function inv(x) { - return div(one, x); -} - -function norm2(x) { - return x.re * x.re + x.im * x.im; -} - -function norm(x) { - let r = Math.abs(x.re); - let i = Math.abs(x.im); - if (r === 0.0) { - return i; - } - if (i === 0.0) { - return r; - } - if (r >= i) { - let q = i / r; - return r * Math.sqrt(1.0 + q * q); - } - let q$1 = r / i; - return i * Math.sqrt(1.0 + q$1 * q$1); -} - -function arg(x) { - return Math.atan2(x.im, x.re); -} - -function polar(n, a) { - return { - re: Math.cos(a) * n, - im: Math.sin(a) * n - }; -} - -function sqrt(x) { - if (x.re === 0.0 && x.im === 0.0) { - return { - re: 0.0, - im: 0.0 - }; - } - let r = Math.abs(x.re); - let i = Math.abs(x.im); - let w; - if (r >= i) { - let q = i / r; - w = Math.sqrt(r) * Math.sqrt(0.5 * (1.0 + Math.sqrt(1.0 + q * q))); - } else { - let q$1 = r / i; - w = Math.sqrt(i) * Math.sqrt(0.5 * (q$1 + Math.sqrt(1.0 + q$1 * q$1))); - } - if (x.re >= 0.0) { - return { - re: w, - im: 0.5 * x.im / w - }; - } else { - return { - re: 0.5 * i / w, - im: x.im >= 0.0 ? w : - w - }; - } -} - -function exp(x) { - let e = Math.exp(x.re); - return { - re: e * Math.cos(x.im), - im: e * Math.sin(x.im) - }; -} - -function log(x) { - return { - re: Math.log(norm(x)), - im: Math.atan2(x.im, x.re) - }; -} - -function pow(x, y) { - return exp(mul(y, log(x))); -} - -let zero = { - re: 0.0, - im: 0.0 -}; - -let i = { - re: 0.0, - im: 1.0 -}; - -exports.zero = zero; -exports.one = one; -exports.i = i; -exports.neg = neg; -exports.conj = conj; -exports.add = add; -exports.sub = sub; -exports.mul = mul; -exports.inv = inv; -exports.div = div; -exports.sqrt = sqrt; -exports.norm2 = norm2; -exports.norm = norm; -exports.arg = arg; -exports.polar = polar; -exports.exp = exp; -exports.log = log; -exports.pow = pow; -/* No side effect */ diff --git a/lib/js/curry.js b/lib/js/curry.js deleted file mode 100644 index 5b6f7bd1eb..0000000000 --- a/lib/js/curry.js +++ /dev/null @@ -1,462 +0,0 @@ -'use strict'; - -let Caml_array = require("./caml_array.js"); - -function app(_f, _args) { - while (true) { - let args = _args; - let f = _f; - let init_arity = f.length; - let arity = init_arity === 0 ? 1 : init_arity; - let len = args.length; - let d = arity - len | 0; - if (d === 0) { - return f.apply(null, args); - } - if (d >= 0) { - return x => app(f, args.concat([x])); - } - _args = Caml_array.sub(args, arity, -d | 0); - _f = f.apply(null, Caml_array.sub(args, 0, arity)); - continue; - }; -} - -function _1(o, a0) { - let arity = o.length; - if (arity === 1) { - return o(a0); - } else { - switch (arity) { - case 1 : - return o(a0); - case 2 : - return param => o(a0, param); - case 3 : - return (param, param$1) => o(a0, param, param$1); - case 4 : - return (param, param$1, param$2) => o(a0, param, param$1, param$2); - case 5 : - return (param, param$1, param$2, param$3) => o(a0, param, param$1, param$2, param$3); - case 6 : - return (param, param$1, param$2, param$3, param$4) => o(a0, param, param$1, param$2, param$3, param$4); - case 7 : - return (param, param$1, param$2, param$3, param$4, param$5) => o(a0, param, param$1, param$2, param$3, param$4, param$5); - default: - return app(o, [a0]); - } - } -} - -function __1(o) { - let arity = o.length; - if (arity === 1) { - return o; - } else { - return a0 => _1(o, a0); - } -} - -function _2(o, a0, a1) { - let arity = o.length; - if (arity === 2) { - return o(a0, a1); - } else { - switch (arity) { - case 1 : - return app(o(a0), [a1]); - case 2 : - return o(a0, a1); - case 3 : - return param => o(a0, a1, param); - case 4 : - return (param, param$1) => o(a0, a1, param, param$1); - case 5 : - return (param, param$1, param$2) => o(a0, a1, param, param$1, param$2); - case 6 : - return (param, param$1, param$2, param$3) => o(a0, a1, param, param$1, param$2, param$3); - case 7 : - return (param, param$1, param$2, param$3, param$4) => o(a0, a1, param, param$1, param$2, param$3, param$4); - default: - return app(o, [ - a0, - a1 - ]); - } - } -} - -function __2(o) { - let arity = o.length; - if (arity === 2) { - return o; - } else { - return (a0, a1) => _2(o, a0, a1); - } -} - -function _3(o, a0, a1, a2) { - let arity = o.length; - if (arity === 3) { - return o(a0, a1, a2); - } else { - switch (arity) { - case 1 : - return app(o(a0), [ - a1, - a2 - ]); - case 2 : - return app(o(a0, a1), [a2]); - case 3 : - return o(a0, a1, a2); - case 4 : - return param => o(a0, a1, a2, param); - case 5 : - return (param, param$1) => o(a0, a1, a2, param, param$1); - case 6 : - return (param, param$1, param$2) => o(a0, a1, a2, param, param$1, param$2); - case 7 : - return (param, param$1, param$2, param$3) => o(a0, a1, a2, param, param$1, param$2, param$3); - default: - return app(o, [ - a0, - a1, - a2 - ]); - } - } -} - -function __3(o) { - let arity = o.length; - if (arity === 3) { - return o; - } else { - return (a0, a1, a2) => _3(o, a0, a1, a2); - } -} - -function _4(o, a0, a1, a2, a3) { - let arity = o.length; - if (arity === 4) { - return o(a0, a1, a2, a3); - } else { - switch (arity) { - case 1 : - return app(o(a0), [ - a1, - a2, - a3 - ]); - case 2 : - return app(o(a0, a1), [ - a2, - a3 - ]); - case 3 : - return app(o(a0, a1, a2), [a3]); - case 4 : - return o(a0, a1, a2, a3); - case 5 : - return param => o(a0, a1, a2, a3, param); - case 6 : - return (param, param$1) => o(a0, a1, a2, a3, param, param$1); - case 7 : - return (param, param$1, param$2) => o(a0, a1, a2, a3, param, param$1, param$2); - default: - return app(o, [ - a0, - a1, - a2, - a3 - ]); - } - } -} - -function __4(o) { - let arity = o.length; - if (arity === 4) { - return o; - } else { - return (a0, a1, a2, a3) => _4(o, a0, a1, a2, a3); - } -} - -function _5(o, a0, a1, a2, a3, a4) { - let arity = o.length; - if (arity === 5) { - return o(a0, a1, a2, a3, a4); - } else { - switch (arity) { - case 1 : - return app(o(a0), [ - a1, - a2, - a3, - a4 - ]); - case 2 : - return app(o(a0, a1), [ - a2, - a3, - a4 - ]); - case 3 : - return app(o(a0, a1, a2), [ - a3, - a4 - ]); - case 4 : - return app(o(a0, a1, a2, a3), [a4]); - case 5 : - return o(a0, a1, a2, a3, a4); - case 6 : - return param => o(a0, a1, a2, a3, a4, param); - case 7 : - return (param, param$1) => o(a0, a1, a2, a3, a4, param, param$1); - default: - return app(o, [ - a0, - a1, - a2, - a3, - a4 - ]); - } - } -} - -function __5(o) { - let arity = o.length; - if (arity === 5) { - return o; - } else { - return (a0, a1, a2, a3, a4) => _5(o, a0, a1, a2, a3, a4); - } -} - -function _6(o, a0, a1, a2, a3, a4, a5) { - let arity = o.length; - if (arity === 6) { - return o(a0, a1, a2, a3, a4, a5); - } else { - switch (arity) { - case 1 : - return app(o(a0), [ - a1, - a2, - a3, - a4, - a5 - ]); - case 2 : - return app(o(a0, a1), [ - a2, - a3, - a4, - a5 - ]); - case 3 : - return app(o(a0, a1, a2), [ - a3, - a4, - a5 - ]); - case 4 : - return app(o(a0, a1, a2, a3), [ - a4, - a5 - ]); - case 5 : - return app(o(a0, a1, a2, a3, a4), [a5]); - case 6 : - return o(a0, a1, a2, a3, a4, a5); - case 7 : - return param => o(a0, a1, a2, a3, a4, a5, param); - default: - return app(o, [ - a0, - a1, - a2, - a3, - a4, - a5 - ]); - } - } -} - -function __6(o) { - let arity = o.length; - if (arity === 6) { - return o; - } else { - return (a0, a1, a2, a3, a4, a5) => _6(o, a0, a1, a2, a3, a4, a5); - } -} - -function _7(o, a0, a1, a2, a3, a4, a5, a6) { - let arity = o.length; - if (arity === 7) { - return o(a0, a1, a2, a3, a4, a5, a6); - } else { - switch (arity) { - case 1 : - return app(o(a0), [ - a1, - a2, - a3, - a4, - a5, - a6 - ]); - case 2 : - return app(o(a0, a1), [ - a2, - a3, - a4, - a5, - a6 - ]); - case 3 : - return app(o(a0, a1, a2), [ - a3, - a4, - a5, - a6 - ]); - case 4 : - return app(o(a0, a1, a2, a3), [ - a4, - a5, - a6 - ]); - case 5 : - return app(o(a0, a1, a2, a3, a4), [ - a5, - a6 - ]); - case 6 : - return app(o(a0, a1, a2, a3, a4, a5), [a6]); - case 7 : - return o(a0, a1, a2, a3, a4, a5, a6); - default: - return app(o, [ - a0, - a1, - a2, - a3, - a4, - a5, - a6 - ]); - } - } -} - -function __7(o) { - let arity = o.length; - if (arity === 7) { - return o; - } else { - return (a0, a1, a2, a3, a4, a5, a6) => _7(o, a0, a1, a2, a3, a4, a5, a6); - } -} - -function _8(o, a0, a1, a2, a3, a4, a5, a6, a7) { - let arity = o.length; - if (arity === 8) { - return o(a0, a1, a2, a3, a4, a5, a6, a7); - } else { - switch (arity) { - case 1 : - return app(o(a0), [ - a1, - a2, - a3, - a4, - a5, - a6, - a7 - ]); - case 2 : - return app(o(a0, a1), [ - a2, - a3, - a4, - a5, - a6, - a7 - ]); - case 3 : - return app(o(a0, a1, a2), [ - a3, - a4, - a5, - a6, - a7 - ]); - case 4 : - return app(o(a0, a1, a2, a3), [ - a4, - a5, - a6, - a7 - ]); - case 5 : - return app(o(a0, a1, a2, a3, a4), [ - a5, - a6, - a7 - ]); - case 6 : - return app(o(a0, a1, a2, a3, a4, a5), [ - a6, - a7 - ]); - case 7 : - return app(o(a0, a1, a2, a3, a4, a5, a6), [a7]); - default: - return app(o, [ - a0, - a1, - a2, - a3, - a4, - a5, - a6, - a7 - ]); - } - } -} - -function __8(o) { - let arity = o.length; - if (arity === 8) { - return o; - } else { - return (a0, a1, a2, a3, a4, a5, a6, a7) => _8(o, a0, a1, a2, a3, a4, a5, a6, a7); - } -} - -exports.app = app; -exports._1 = _1; -exports.__1 = __1; -exports._2 = _2; -exports.__2 = __2; -exports._3 = _3; -exports.__3 = __3; -exports._4 = _4; -exports.__4 = __4; -exports._5 = _5; -exports.__5 = __5; -exports._6 = _6; -exports.__6 = __6; -exports._7 = _7; -exports.__7 = __7; -exports._8 = _8; -exports.__8 = __8; -/* No side effect */ diff --git a/lib/js/digest.js b/lib/js/digest.js deleted file mode 100644 index 5bd173cfda..0000000000 --- a/lib/js/digest.js +++ /dev/null @@ -1,114 +0,0 @@ -'use strict'; - -let Char = require("./char.js"); -let Bytes = require("./bytes.js"); -let $$String = require("./string.js"); -let Caml_md5 = require("./caml_md5.js"); -let Caml_bytes = require("./caml_bytes.js"); -let Caml_string = require("./caml_string.js"); - -function string(str) { - return Caml_md5.md5_string(str, 0, str.length); -} - -function bytes(b) { - return string(Bytes.unsafe_to_string(b)); -} - -function substring(str, ofs, len) { - if (ofs < 0 || len < 0 || ofs > (str.length - len | 0)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Digest.substring", - Error: new Error() - }; - } - return Caml_md5.md5_string(str, ofs, len); -} - -function subbytes(b, ofs, len) { - return substring(Bytes.unsafe_to_string(b), ofs, len); -} - -function char_hex(n) { - return n + ( - n < 10 ? /* '0' */48 : 87 - ) | 0; -} - -function to_hex(d) { - if (d.length !== 16) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Digest.to_hex", - Error: new Error() - }; - } - let result = Caml_bytes.create(32); - for (let i = 0; i <= 15; ++i) { - let x = Caml_string.get(d, i); - result[(i << 1)] = char_hex((x >>> 4)); - result[(i << 1) + 1 | 0] = char_hex(x & 15); - } - return Bytes.unsafe_to_string(result); -} - -function from_hex(s) { - if (s.length !== 32) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Digest.from_hex", - Error: new Error() - }; - } - let digit = c => { - if (c >= 65) { - if (c >= 97) { - if (c >= 103) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Digest.from_hex", - Error: new Error() - }; - } - return (c - /* 'a' */97 | 0) + 10 | 0; - } - if (c >= 71) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Digest.from_hex", - Error: new Error() - }; - } - return (c - /* 'A' */65 | 0) + 10 | 0; - } - if (c > 57 || c < 48) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Digest.from_hex", - Error: new Error() - }; - } - return c - /* '0' */48 | 0; - }; - let byte = i => (digit(Caml_string.get(s, i)) << 4) + digit(Caml_string.get(s, i + 1 | 0)) | 0; - let result = Caml_bytes.create(16); - for (let i = 0; i <= 15; ++i) { - Caml_bytes.set(result, i, Char.chr(byte((i << 1)))); - } - return Bytes.unsafe_to_string(result); -} - -let compare = $$String.compare; - -let equal = $$String.equal; - -exports.compare = compare; -exports.equal = equal; -exports.string = string; -exports.bytes = bytes; -exports.substring = substring; -exports.subbytes = subbytes; -exports.to_hex = to_hex; -exports.from_hex = from_hex; -/* No side effect */ diff --git a/lib/js/dom_storage.js b/lib/js/dom_storage.js index 8d625d6a2c..1bcbd56b2d 100644 --- a/lib/js/dom_storage.js +++ b/lib/js/dom_storage.js @@ -1,9 +1,9 @@ 'use strict'; -let Caml_option = require("./caml_option.js"); +let Primitive_option = require("./primitive_option.js"); function getItem(s, obj) { - return Caml_option.null_to_opt(obj.getItem(s)); + return Primitive_option.fromNull(obj.getItem(s)); } function setItem(k, v, obj) { @@ -15,7 +15,7 @@ function removeItem(s, obj) { } function key(i, obj) { - return Caml_option.null_to_opt(obj.key(i)); + return Primitive_option.fromNull(obj.key(i)); } exports.getItem = getItem; diff --git a/lib/js/filename.js b/lib/js/filename.js deleted file mode 100644 index 468cfb2c0f..0000000000 --- a/lib/js/filename.js +++ /dev/null @@ -1,491 +0,0 @@ -'use strict'; - -let Sys = require("./sys.js"); -let Bytes = require("./bytes.js"); -let Buffer = require("./buffer.js"); -let $$String = require("./string.js"); -let Caml_sys = require("./caml_sys.js"); -let Caml_string = require("./caml_string.js"); -let Caml_js_exceptions = require("./caml_js_exceptions.js"); - -function generic_basename(is_dir_sep, current_dir_name, name) { - if (name === "") { - return current_dir_name; - } else { - let _n = name.length - 1 | 0; - while (true) { - let n = _n; - if (n < 0) { - return $$String.sub(name, 0, 1); - } - if (!is_dir_sep(name, n)) { - let _n$1 = n; - let p = n + 1 | 0; - while (true) { - let n$1 = _n$1; - if (n$1 < 0) { - return $$String.sub(name, 0, p); - } - if (is_dir_sep(name, n$1)) { - return $$String.sub(name, n$1 + 1 | 0, (p - n$1 | 0) - 1 | 0); - } - _n$1 = n$1 - 1 | 0; - continue; - }; - } - _n = n - 1 | 0; - continue; - }; - } -} - -function generic_dirname(is_dir_sep, current_dir_name, name) { - if (name === "") { - return current_dir_name; - } else { - let _n = name.length - 1 | 0; - while (true) { - let n = _n; - if (n < 0) { - return $$String.sub(name, 0, 1); - } - if (!is_dir_sep(name, n)) { - let _n$1 = n; - while (true) { - let n$1 = _n$1; - if (n$1 < 0) { - return current_dir_name; - } - if (is_dir_sep(name, n$1)) { - let _n$2 = n$1; - while (true) { - let n$2 = _n$2; - if (n$2 < 0) { - return $$String.sub(name, 0, 1); - } - if (!is_dir_sep(name, n$2)) { - return $$String.sub(name, 0, n$2 + 1 | 0); - } - _n$2 = n$2 - 1 | 0; - continue; - }; - } - _n$1 = n$1 - 1 | 0; - continue; - }; - } - _n = n - 1 | 0; - continue; - }; - } -} - -let current_dir_name = "."; - -function is_dir_sep(s, i) { - return Caml_string.get(s, i) === /* '/' */47; -} - -function is_relative(n) { - if (n.length < 1) { - return true; - } else { - return Caml_string.get(n, 0) !== /* '/' */47; - } -} - -function is_implicit(n) { - if (is_relative(n) && (n.length < 2 || $$String.sub(n, 0, 2) !== "./")) { - if (n.length < 3) { - return true; - } else { - return $$String.sub(n, 0, 3) !== "../"; - } - } else { - return false; - } -} - -function check_suffix(name, suff) { - if (name.length >= suff.length) { - return $$String.sub(name, name.length - suff.length | 0, suff.length) === suff; - } else { - return false; - } -} - -let temp_dir_name; - -try { - temp_dir_name = Caml_sys.sys_getenv("TMPDIR"); -} catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - temp_dir_name = "/tmp"; - } else { - throw exn; - } -} - -function quote(x) { - let quotequote = "'\\''"; - let l = x.length; - let b = Buffer.create(l + 20 | 0); - Buffer.add_char(b, /* '\'' */39); - for (let i = 0; i < l; ++i) { - if (Caml_string.get(x, i) === /* '\'' */39) { - Buffer.add_string(b, quotequote); - } else { - Buffer.add_char(b, Caml_string.get(x, i)); - } - } - Buffer.add_char(b, /* '\'' */39); - return Buffer.contents(b); -} - -function basename(x) { - return generic_basename(is_dir_sep, current_dir_name, x); -} - -function dirname(x) { - return generic_dirname(is_dir_sep, current_dir_name, x); -} - -let current_dir_name$1 = "."; - -function is_dir_sep$1(s, i) { - let c = Caml_string.get(s, i); - if (c === /* '/' */47 || c === /* '\\' */92) { - return true; - } else { - return c === /* ':' */58; - } -} - -function is_relative$1(n) { - if ((n.length < 1 || Caml_string.get(n, 0) !== /* '/' */47) && (n.length < 1 || Caml_string.get(n, 0) !== /* '\\' */92)) { - if (n.length < 2) { - return true; - } else { - return Caml_string.get(n, 1) !== /* ':' */58; - } - } else { - return false; - } -} - -function is_implicit$1(n) { - if (is_relative$1(n) && (n.length < 2 || $$String.sub(n, 0, 2) !== "./") && (n.length < 2 || $$String.sub(n, 0, 2) !== ".\\") && (n.length < 3 || $$String.sub(n, 0, 3) !== "../")) { - if (n.length < 3) { - return true; - } else { - return $$String.sub(n, 0, 3) !== "..\\"; - } - } else { - return false; - } -} - -function check_suffix$1(name, suff) { - if (name.length < suff.length) { - return false; - } - let s = $$String.sub(name, name.length - suff.length | 0, suff.length); - return Bytes.unsafe_to_string(Bytes.lowercase_ascii(Bytes.unsafe_of_string(s))) === Bytes.unsafe_to_string(Bytes.lowercase_ascii(Bytes.unsafe_of_string(suff))); -} - -let temp_dir_name$1; - -try { - temp_dir_name$1 = Caml_sys.sys_getenv("TEMP"); -} catch (raw_exn$1) { - let exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn$1); - if (exn$1.RE_EXN_ID === "Not_found") { - temp_dir_name$1 = "."; - } else { - throw exn$1; - } -} - -function quote$1(s) { - let l = s.length; - let b = Buffer.create(l + 20 | 0); - Buffer.add_char(b, /* '"' */34); - let loop = _i => { - while (true) { - let i = _i; - if (i === l) { - return Buffer.add_char(b, /* '"' */34); - } - let c = Caml_string.get(s, i); - if (c === 34) { - return loop_bs(0, i); - } - if (c === 92) { - return loop_bs(0, i); - } - Buffer.add_char(b, c); - _i = i + 1 | 0; - continue; - }; - }; - let loop_bs = (_n, _i) => { - while (true) { - let i = _i; - let n = _n; - if (i === l) { - Buffer.add_char(b, /* '"' */34); - return add_bs(n); - } - let match = Caml_string.get(s, i); - if (match !== 34) { - if (match !== 92) { - add_bs(n); - return loop(i); - } - _i = i + 1 | 0; - _n = n + 1 | 0; - continue; - } - add_bs((n << 1) + 1 | 0); - Buffer.add_char(b, /* '"' */34); - return loop(i + 1 | 0); - }; - }; - let add_bs = n => { - for (let _j = 1; _j <= n; ++_j) { - Buffer.add_char(b, /* '\\' */92); - } - }; - loop(0); - return Buffer.contents(b); -} - -function has_drive(s) { - let is_letter = param => { - if (param >= 91) { - return !(param > 122 || param < 97); - } else { - return param >= 65; - } - }; - if (s.length >= 2 && is_letter(Caml_string.get(s, 0))) { - return Caml_string.get(s, 1) === /* ':' */58; - } else { - return false; - } -} - -function drive_and_path(s) { - if (has_drive(s)) { - return [ - $$String.sub(s, 0, 2), - $$String.sub(s, 2, s.length - 2 | 0) - ]; - } else { - return [ - "", - s - ]; - } -} - -function dirname$1(s) { - let match = drive_and_path(s); - let dir = generic_dirname(is_dir_sep$1, current_dir_name$1, match[1]); - return match[0] + dir; -} - -function basename$1(s) { - let match = drive_and_path(s); - return generic_basename(is_dir_sep$1, current_dir_name$1, match[1]); -} - -let current_dir_name$2 = "."; - -function basename$2(x) { - return generic_basename(is_dir_sep$1, current_dir_name$2, x); -} - -function dirname$2(x) { - return generic_dirname(is_dir_sep$1, current_dir_name$2, x); -} - -let match; - -switch (Sys.os_type) { - case "Cygwin" : - match = [ - current_dir_name$2, - "..", - "/", - is_dir_sep$1, - is_relative$1, - is_implicit$1, - check_suffix$1, - temp_dir_name, - quote, - basename$2, - dirname$2 - ]; - break; - case "Win32" : - match = [ - current_dir_name$1, - "..", - "\\", - is_dir_sep$1, - is_relative$1, - is_implicit$1, - check_suffix$1, - temp_dir_name$1, - quote$1, - basename$1, - dirname$1 - ]; - break; - default: - match = [ - current_dir_name, - "..", - "/", - is_dir_sep, - is_relative, - is_implicit, - check_suffix, - temp_dir_name, - quote, - basename, - dirname - ]; -} - -let temp_dir_name$2 = match[7]; - -let is_dir_sep$2 = match[3]; - -let dir_sep = match[2]; - -function concat(dirname, filename) { - let l = dirname.length; - if (l === 0 || is_dir_sep$2(dirname, l - 1 | 0)) { - return dirname + filename; - } else { - return dirname + (dir_sep + filename); - } -} - -function chop_suffix(name, suff) { - let n = name.length - suff.length | 0; - if (n < 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Filename.chop_suffix", - Error: new Error() - }; - } - return $$String.sub(name, 0, n); -} - -function extension_len(name) { - let _i = name.length - 1 | 0; - while (true) { - let i = _i; - if (i < 0 || is_dir_sep$2(name, i)) { - return 0; - } - if (Caml_string.get(name, i) === /* '.' */46) { - let _i$1 = i - 1 | 0; - while (true) { - let i$1 = _i$1; - if (i$1 < 0 || is_dir_sep$2(name, i$1)) { - return 0; - } - if (Caml_string.get(name, i$1) !== /* '.' */46) { - return name.length - i | 0; - } - _i$1 = i$1 - 1 | 0; - continue; - }; - } - _i = i - 1 | 0; - continue; - }; -} - -function extension(name) { - let l = extension_len(name); - if (l === 0) { - return ""; - } else { - return $$String.sub(name, name.length - l | 0, l); - } -} - -function chop_extension(name) { - let l = extension_len(name); - if (l === 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Filename.chop_extension", - Error: new Error() - }; - } - return $$String.sub(name, 0, name.length - l | 0); -} - -function remove_extension(name) { - let l = extension_len(name); - if (l === 0) { - return name; - } else { - return $$String.sub(name, 0, name.length - l | 0); - } -} - -let current_temp_dir_name = { - contents: temp_dir_name$2 -}; - -function set_temp_dir_name(s) { - current_temp_dir_name.contents = s; -} - -function get_temp_dir_name() { - return current_temp_dir_name.contents; -} - -let current_dir_name$3 = match[0]; - -let parent_dir_name = match[1]; - -let is_relative$2 = match[4]; - -let is_implicit$2 = match[5]; - -let check_suffix$2 = match[6]; - -let basename$3 = match[9]; - -let dirname$3 = match[10]; - -let quote$2 = match[8]; - -exports.current_dir_name = current_dir_name$3; -exports.parent_dir_name = parent_dir_name; -exports.dir_sep = dir_sep; -exports.concat = concat; -exports.is_relative = is_relative$2; -exports.is_implicit = is_implicit$2; -exports.check_suffix = check_suffix$2; -exports.chop_suffix = chop_suffix; -exports.extension = extension; -exports.remove_extension = remove_extension; -exports.chop_extension = chop_extension; -exports.basename = basename$3; -exports.dirname = dirname$3; -exports.get_temp_dir_name = get_temp_dir_name; -exports.set_temp_dir_name = set_temp_dir_name; -exports.temp_dir_name = temp_dir_name$2; -exports.quote = quote$2; -/* temp_dir_name Not a pure module */ diff --git a/lib/js/genlex.js b/lib/js/genlex.js deleted file mode 100644 index 658e6da2a3..0000000000 --- a/lib/js/genlex.js +++ /dev/null @@ -1,638 +0,0 @@ -'use strict'; - -let Char = require("./char.js"); -let List = require("./list.js"); -let Bytes = require("./bytes.js"); -let Stream = require("./stream.js"); -let Hashtbl = require("./hashtbl.js"); -let Caml_bytes = require("./caml_bytes.js"); -let Caml_format = require("./caml_format.js"); -let Caml_string = require("./caml_string.js"); -let Caml_js_exceptions = require("./caml_js_exceptions.js"); - -let initial_buffer = Caml_bytes.create(32); - -let buffer = { - contents: initial_buffer -}; - -let bufpos = { - contents: 0 -}; - -function reset_buffer() { - buffer.contents = initial_buffer; - bufpos.contents = 0; -} - -function store(c) { - if (bufpos.contents >= buffer.contents.length) { - let newbuffer = Caml_bytes.create((bufpos.contents << 1)); - Bytes.blit(buffer.contents, 0, newbuffer, 0, bufpos.contents); - buffer.contents = newbuffer; - } - Caml_bytes.set(buffer.contents, bufpos.contents, c); - bufpos.contents = bufpos.contents + 1 | 0; -} - -function get_string() { - let s = Bytes.sub_string(buffer.contents, 0, bufpos.contents); - buffer.contents = initial_buffer; - return s; -} - -function make_lexer(keywords) { - let kwd_table = Hashtbl.create(undefined, 17); - List.iter(s => Hashtbl.add(kwd_table, s, { - TAG: "Kwd", - _0: s - }), keywords); - let ident_or_keyword = id => { - try { - return Hashtbl.find(kwd_table, id); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - return { - TAG: "Ident", - _0: id - }; - } - throw exn; - } - }; - let keyword_or_error = c => { - let s = Caml_string.make(1, c); - try { - return Hashtbl.find(kwd_table, s); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - throw { - RE_EXN_ID: Stream.$$Error, - _1: "Illegal character " + s, - Error: new Error() - }; - } - throw exn; - } - }; - let next_token = strm__ => { - while (true) { - let c = Stream.peek(strm__); - if (c === undefined) { - return; - } - let exit = 0; - if (c < 124) { - if (c > 122 || c < 65) { - if (c >= 123) { - exit = 1; - } else { - switch (c) { - case 9 : - case 10 : - case 12 : - case 13 : - case 26 : - case 32 : - Stream.junk(strm__); - continue; - case 34 : - Stream.junk(strm__); - reset_buffer(); - return { - TAG: "String", - _0: string(strm__) - }; - case 39 : - Stream.junk(strm__); - let c$1; - try { - c$1 = char(strm__); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === Stream.Failure) { - throw { - RE_EXN_ID: Stream.$$Error, - _1: "", - Error: new Error() - }; - } - throw exn; - } - let match = Stream.peek(strm__); - if (match !== undefined) { - if (match !== 39) { - throw { - RE_EXN_ID: Stream.$$Error, - _1: "", - Error: new Error() - }; - } - Stream.junk(strm__); - return { - TAG: "Char", - _0: c$1 - }; - } - throw { - RE_EXN_ID: Stream.$$Error, - _1: "", - Error: new Error() - }; - case 40 : - Stream.junk(strm__); - let match$1 = Stream.peek(strm__); - if (match$1 === 42) { - Stream.junk(strm__); - comment(strm__); - return next_token(strm__); - } else { - return keyword_or_error(/* '(' */40); - } - case 45 : - Stream.junk(strm__); - let c$2 = Stream.peek(strm__); - if (c$2 !== undefined && !(c$2 > 57 || c$2 < 48)) { - Stream.junk(strm__); - reset_buffer(); - store(/* '-' */45); - store(c$2); - return number(strm__); - } else { - reset_buffer(); - store(/* '-' */45); - return ident2(strm__); - } - case 48 : - case 49 : - case 50 : - case 51 : - case 52 : - case 53 : - case 54 : - case 55 : - case 56 : - case 57 : - exit = 4; - break; - case 0 : - case 1 : - case 2 : - case 3 : - case 4 : - case 5 : - case 6 : - case 7 : - case 8 : - case 11 : - case 14 : - case 15 : - case 16 : - case 17 : - case 18 : - case 19 : - case 20 : - case 21 : - case 22 : - case 23 : - case 24 : - case 25 : - case 27 : - case 28 : - case 29 : - case 30 : - case 31 : - case 41 : - case 44 : - case 46 : - case 59 : - exit = 1; - break; - case 33 : - case 35 : - case 36 : - case 37 : - case 38 : - case 42 : - case 43 : - case 47 : - case 58 : - case 60 : - case 61 : - case 62 : - case 63 : - case 64 : - exit = 3; - break; - } - } - } else { - switch (c) { - case 92 : - case 94 : - exit = 3; - break; - case 91 : - case 93 : - case 96 : - exit = 1; - break; - default: - exit = 2; - } - } - } else { - exit = c >= 127 ? ( - c > 255 || c < 192 ? 1 : 2 - ) : ( - c !== 125 ? 3 : 1 - ); - } - switch (exit) { - case 1 : - Stream.junk(strm__); - return keyword_or_error(c); - case 2 : - Stream.junk(strm__); - reset_buffer(); - store(c); - while (true) { - let c$3 = Stream.peek(strm__); - if (c$3 === undefined) { - return ident_or_keyword(get_string()); - } - if (c$3 >= 91) { - if (c$3 > 122 || c$3 < 95) { - if (c$3 > 255 || c$3 < 192) { - return ident_or_keyword(get_string()); - } - - } else if (c$3 === 96) { - return ident_or_keyword(get_string()); - } - - } else if (c$3 >= 48) { - if (!(c$3 > 64 || c$3 < 58)) { - return ident_or_keyword(get_string()); - } - - } else if (c$3 !== 39) { - return ident_or_keyword(get_string()); - } - Stream.junk(strm__); - store(c$3); - continue; - }; - case 3 : - Stream.junk(strm__); - reset_buffer(); - store(c); - return ident2(strm__); - case 4 : - Stream.junk(strm__); - reset_buffer(); - store(c); - return number(strm__); - } - }; - }; - let ident2 = strm__ => { - while (true) { - let c = Stream.peek(strm__); - if (c === undefined) { - return ident_or_keyword(get_string()); - } - if (c >= 94) { - if (c > 125 || c < 95) { - if (c >= 127) { - return ident_or_keyword(get_string()); - } - - } else if (c !== 124) { - return ident_or_keyword(get_string()); - } - - } else if (c >= 65) { - if (c !== 92) { - return ident_or_keyword(get_string()); - } - - } else { - if (c < 33) { - return ident_or_keyword(get_string()); - } - switch (c) { - case 34 : - case 39 : - case 40 : - case 41 : - case 44 : - case 46 : - case 48 : - case 49 : - case 50 : - case 51 : - case 52 : - case 53 : - case 54 : - case 55 : - case 56 : - case 57 : - case 59 : - return ident_or_keyword(get_string()); - case 33 : - case 35 : - case 36 : - case 37 : - case 38 : - case 42 : - case 43 : - case 45 : - case 47 : - case 58 : - case 60 : - case 61 : - case 62 : - case 63 : - case 64 : - break; - } - } - Stream.junk(strm__); - store(c); - continue; - }; - }; - let number = strm__ => { - while (true) { - let c = Stream.peek(strm__); - if (c !== undefined) { - if (c >= 58) { - if (!(c !== 69 && c !== 101)) { - Stream.junk(strm__); - store(/* 'E' */69); - return exponent_part(strm__); - } - - } else if (c !== 46) { - if (c >= 48) { - Stream.junk(strm__); - store(c); - continue; - } - - } else { - Stream.junk(strm__); - store(/* '.' */46); - while (true) { - let c$1 = Stream.peek(strm__); - if (c$1 !== undefined) { - if (c$1 > 101 || c$1 < 69) { - if (!(c$1 > 57 || c$1 < 48)) { - Stream.junk(strm__); - store(c$1); - continue; - } - - } else if (c$1 > 100 || c$1 < 70) { - Stream.junk(strm__); - store(/* 'E' */69); - return exponent_part(strm__); - } - - } - return { - TAG: "Float", - _0: Caml_format.float_of_string(get_string()) - }; - }; - } - } - return { - TAG: "Int", - _0: Caml_format.int_of_string(get_string()) - }; - }; - }; - let exponent_part = strm__ => { - let c = Stream.peek(strm__); - if (c !== undefined && !(c !== 43 && c !== 45)) { - Stream.junk(strm__); - store(c); - return end_exponent_part(strm__); - } else { - return end_exponent_part(strm__); - } - }; - let end_exponent_part = strm__ => { - while (true) { - let c = Stream.peek(strm__); - if (c === undefined) { - return { - TAG: "Float", - _0: Caml_format.float_of_string(get_string()) - }; - } - if (c > 57 || c < 48) { - return { - TAG: "Float", - _0: Caml_format.float_of_string(get_string()) - }; - } - Stream.junk(strm__); - store(c); - continue; - }; - }; - let string = strm__ => { - while (true) { - let c = Stream.peek(strm__); - if (c !== undefined) { - if (c !== 34) { - if (c !== 92) { - Stream.junk(strm__); - store(c); - continue; - } - Stream.junk(strm__); - let c$1; - try { - c$1 = escape(strm__); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === Stream.Failure) { - throw { - RE_EXN_ID: Stream.$$Error, - _1: "", - Error: new Error() - }; - } - throw exn; - } - store(c$1); - continue; - } - Stream.junk(strm__); - return get_string(); - } - throw { - RE_EXN_ID: Stream.Failure, - Error: new Error() - }; - }; - }; - let char = strm__ => { - let c = Stream.peek(strm__); - if (c !== undefined) { - if (c !== 92) { - Stream.junk(strm__); - return c; - } - Stream.junk(strm__); - try { - return escape(strm__); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === Stream.Failure) { - throw { - RE_EXN_ID: Stream.$$Error, - _1: "", - Error: new Error() - }; - } - throw exn; - } - } else { - throw { - RE_EXN_ID: Stream.Failure, - Error: new Error() - }; - } - }; - let escape = strm__ => { - let c1 = Stream.peek(strm__); - if (c1 !== undefined) { - if (c1 >= 58) { - switch (c1) { - case 110 : - Stream.junk(strm__); - return /* '\n' */10; - case 114 : - Stream.junk(strm__); - return /* '\r' */13; - case 116 : - Stream.junk(strm__); - return /* '\t' */9; - default: - Stream.junk(strm__); - return c1; - } - } else { - if (c1 >= 48) { - Stream.junk(strm__); - let c2 = Stream.peek(strm__); - if (c2 !== undefined) { - if (c2 > 57 || c2 < 48) { - throw { - RE_EXN_ID: Stream.$$Error, - _1: "", - Error: new Error() - }; - } - Stream.junk(strm__); - let c3 = Stream.peek(strm__); - if (c3 !== undefined) { - if (c3 > 57 || c3 < 48) { - throw { - RE_EXN_ID: Stream.$$Error, - _1: "", - Error: new Error() - }; - } - Stream.junk(strm__); - return Char.chr((Math.imul(c1 - 48 | 0, 100) + Math.imul(c2 - 48 | 0, 10) | 0) + (c3 - 48 | 0) | 0); - } - throw { - RE_EXN_ID: Stream.$$Error, - _1: "", - Error: new Error() - }; - } - throw { - RE_EXN_ID: Stream.$$Error, - _1: "", - Error: new Error() - }; - } - Stream.junk(strm__); - return c1; - } - } else { - throw { - RE_EXN_ID: Stream.Failure, - Error: new Error() - }; - } - }; - let comment = strm__ => { - while (true) { - let match = Stream.peek(strm__); - if (match !== undefined) { - switch (match) { - case 40 : - Stream.junk(strm__); - let match$1 = Stream.peek(strm__); - if (match$1 !== undefined) { - if (match$1 !== 42) { - Stream.junk(strm__); - return comment(strm__); - } else { - Stream.junk(strm__); - comment(strm__); - return comment(strm__); - } - } - throw { - RE_EXN_ID: Stream.Failure, - Error: new Error() - }; - case 42 : - Stream.junk(strm__); - while (true) { - let match$2 = Stream.peek(strm__); - if (match$2 !== undefined) { - if (match$2 !== 41) { - if (match$2 !== 42) { - Stream.junk(strm__); - return comment(strm__); - } - Stream.junk(strm__); - continue; - } - Stream.junk(strm__); - return; - } - throw { - RE_EXN_ID: Stream.Failure, - Error: new Error() - }; - }; - default: - Stream.junk(strm__); - continue; - } - } else { - throw { - RE_EXN_ID: Stream.Failure, - Error: new Error() - }; - } - }; - }; - return input => Stream.from(_count => next_token(input)); -} - -exports.make_lexer = make_lexer; -/* No side effect */ diff --git a/lib/js/hashtbl.js b/lib/js/hashtbl.js index 2d2fe16921..5feace2213 100644 --- a/lib/js/hashtbl.js +++ b/lib/js/hashtbl.js @@ -1,1104 +1,10 @@ 'use strict'; -let Caml = require("./caml.js"); -let $$Array = require("./array.js"); -let Random = require("./random.js"); -let Caml_obj = require("./caml_obj.js"); -let Caml_hash = require("./caml_hash.js"); -let Caml_array = require("./caml_array.js"); -let Pervasives = require("./pervasives.js"); -let Caml_option = require("./caml_option.js"); -let CamlinternalLazy = require("./camlinternalLazy.js"); +let Primitive_hash = require("./primitive_hash.js"); function hash(x) { - return Caml_hash.hash(10, 100, 0, x); + return Primitive_hash.hash(10, 100, 0, x); } -function hash_param(n1, n2, x) { - return Caml_hash.hash(n1, n2, 0, x); -} - -function seeded_hash(seed, x) { - return Caml_hash.hash(10, 100, seed, x); -} - -function flip_ongoing_traversal(h) { - h.initial_size = -h.initial_size | 0; -} - -let randomized = { - contents: false -}; - -function randomize() { - randomized.contents = true; -} - -function is_randomized() { - return randomized.contents; -} - -let prng = CamlinternalLazy.from_fun(() => Random.State.make_self_init()); - -function power_2_above(_x, n) { - while (true) { - let x = _x; - if (x >= n) { - return x; - } - if ((x << 1) < x) { - return x; - } - _x = (x << 1); - continue; - }; -} - -function create(randomOpt, initial_size) { - let random = randomOpt !== undefined ? randomOpt : randomized.contents; - let s = power_2_above(16, initial_size); - let seed = random ? Random.State.bits(CamlinternalLazy.force(prng)) : 0; - return { - size: 0, - data: Caml_array.make(s, "Empty"), - seed: seed, - initial_size: s - }; -} - -function clear(h) { - h.size = 0; - let len = h.data.length; - for (let i = 0; i < len; ++i) { - Caml_array.set(h.data, i, "Empty"); - } -} - -function reset(h) { - let len = h.data.length; - if (len === Pervasives.abs(h.initial_size)) { - return clear(h); - } else { - h.size = 0; - h.data = Caml_array.make(Pervasives.abs(h.initial_size), "Empty"); - return; - } -} - -function copy_bucketlist(param) { - if (typeof param !== "object") { - return "Empty"; - } - let key = param.key; - let data = param.data; - let next = param.next; - let loop = (_prec, _param) => { - while (true) { - let param = _param; - let prec = _prec; - if (typeof param !== "object") { - return; - } - let key = param.key; - let data = param.data; - let next = param.next; - let r = { - TAG: "Cons", - key: key, - data: data, - next: next - }; - if (typeof prec !== "object") { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "hashtbl.res", - 110, - 19 - ], - Error: new Error() - }; - } - prec.next = r; - _param = next; - _prec = r; - continue; - }; - }; - let r = { - TAG: "Cons", - key: key, - data: data, - next: next - }; - loop(r, next); - return r; -} - -function copy(h) { - return { - size: h.size, - data: $$Array.map(copy_bucketlist, h.data), - seed: h.seed, - initial_size: h.initial_size - }; -} - -function length(h) { - return h.size; -} - -function resize(indexfun, h) { - let odata = h.data; - let osize = odata.length; - let nsize = (osize << 1); - if (nsize < osize) { - return; - } - let ndata = Caml_array.make(nsize, "Empty"); - let ndata_tail = Caml_array.make(nsize, "Empty"); - let inplace = h.initial_size >= 0; - h.data = ndata; - let insert_bucket = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let key = param.key; - let data = param.data; - let next = param.next; - let cell = inplace ? param : ({ - TAG: "Cons", - key: key, - data: data, - next: "Empty" - }); - let nidx = indexfun(h, key); - let tail = Caml_array.get(ndata_tail, nidx); - if (typeof tail !== "object") { - Caml_array.set(ndata, nidx, cell); - } else { - tail.next = cell; - } - Caml_array.set(ndata_tail, nidx, cell); - _param = next; - continue; - }; - }; - for (let i = 0; i < osize; ++i) { - insert_bucket(Caml_array.get(odata, i)); - } - if (!inplace) { - return; - } - for (let i$1 = 0; i$1 < nsize; ++i$1) { - let tail = Caml_array.get(ndata_tail, i$1); - if (typeof tail === "object") { - tail.next = "Empty"; - } - - } -} - -function key_index(h, key) { - return Caml_hash.hash(10, 100, h.seed, key) & (h.data.length - 1 | 0); -} - -function add(h, key, data) { - let i = key_index(h, key); - let bucket = { - TAG: "Cons", - key: key, - data: data, - next: Caml_array.get(h.data, i) - }; - Caml_array.set(h.data, i, bucket); - h.size = h.size + 1 | 0; - if (h.size > (h.data.length << 1)) { - return resize(key_index, h); - } - -} - -function remove(h, key) { - let i = key_index(h, key); - let _prec = "Empty"; - let _param = Caml_array.get(h.data, i); - while (true) { - let param = _param; - let prec = _prec; - if (typeof param !== "object") { - return; - } - let k = param.key; - let next = param.next; - if (Caml_obj.equal(k, key)) { - h.size = h.size - 1 | 0; - if (typeof prec !== "object") { - return Caml_array.set(h.data, i, next); - } else { - prec.next = next; - return; - } - } - _param = next; - _prec = param; - continue; - }; -} - -function find(h, key) { - let match = Caml_array.get(h.data, key_index(h, key)); - if (typeof match !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let k1 = match.key; - let d1 = match.data; - let next1 = match.next; - if (Caml_obj.equal(key, k1)) { - return d1; - } - if (typeof next1 !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let k2 = next1.key; - let d2 = next1.data; - let next2 = next1.next; - if (Caml_obj.equal(key, k2)) { - return d2; - } - if (typeof next2 !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let k3 = next2.key; - let d3 = next2.data; - let next3 = next2.next; - if (Caml_obj.equal(key, k3)) { - return d3; - } else { - let _param = next3; - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let k = param.key; - let data = param.data; - let next = param.next; - if (Caml_obj.equal(key, k)) { - return data; - } - _param = next; - continue; - }; - } -} - -function find_opt(h, key) { - let match = Caml_array.get(h.data, key_index(h, key)); - if (typeof match !== "object") { - return; - } - let k1 = match.key; - let d1 = match.data; - let next1 = match.next; - if (Caml_obj.equal(key, k1)) { - return Caml_option.some(d1); - } - if (typeof next1 !== "object") { - return; - } - let k2 = next1.key; - let d2 = next1.data; - let next2 = next1.next; - if (Caml_obj.equal(key, k2)) { - return Caml_option.some(d2); - } - if (typeof next2 !== "object") { - return; - } - let k3 = next2.key; - let d3 = next2.data; - let next3 = next2.next; - if (Caml_obj.equal(key, k3)) { - return Caml_option.some(d3); - } else { - let _param = next3; - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let k = param.key; - let data = param.data; - let next = param.next; - if (Caml_obj.equal(key, k)) { - return Caml_option.some(data); - } - _param = next; - continue; - }; - } -} - -function find_all(h, key) { - let find_in_bucket = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return /* [] */0; - } - let k = param.key; - let data = param.data; - let next = param.next; - if (Caml_obj.equal(k, key)) { - return { - hd: data, - tl: find_in_bucket(next) - }; - } - _param = next; - continue; - }; - }; - return find_in_bucket(Caml_array.get(h.data, key_index(h, key))); -} - -function replace_bucket(key, data, _param) { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - let k = param.key; - let next = param.next; - if (Caml_obj.equal(k, key)) { - param.key = key; - param.data = data; - return false; - } - _param = next; - continue; - }; -} - -function replace(h, key, data) { - let i = key_index(h, key); - let l = Caml_array.get(h.data, i); - if (replace_bucket(key, data, l)) { - Caml_array.set(h.data, i, { - TAG: "Cons", - key: key, - data: data, - next: l - }); - h.size = h.size + 1 | 0; - if (h.size > (h.data.length << 1)) { - return resize(key_index, h); - } else { - return; - } - } - -} - -function mem(h, key) { - let _param = Caml_array.get(h.data, key_index(h, key)); - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let k = param.key; - let next = param.next; - if (Caml_obj.equal(k, key)) { - return true; - } - _param = next; - continue; - }; -} - -function iter(f, h) { - let do_bucket = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let key = param.key; - let data = param.data; - let next = param.next; - f(key, data); - _param = next; - continue; - }; - }; - let old_trav = h.initial_size < 0; - if (!old_trav) { - flip_ongoing_traversal(h); - } - try { - let d = h.data; - for (let i = 0, i_finish = d.length; i < i_finish; ++i) { - do_bucket(Caml_array.get(d, i)); - } - if (!old_trav) { - return flip_ongoing_traversal(h); - } else { - return; - } - } catch (exn) { - if (old_trav) { - throw exn; - } - flip_ongoing_traversal(h); - throw exn; - } -} - -function filter_map_inplace_bucket(f, h, i, _prec, _param) { - while (true) { - let param = _param; - let prec = _prec; - if (typeof param !== "object") { - if (typeof prec !== "object") { - return Caml_array.set(h.data, i, "Empty"); - } else { - prec.next = "Empty"; - return; - } - } - let key = param.key; - let data = param.data; - let next = param.next; - let data$1 = f(key, data); - if (data$1 !== undefined) { - if (typeof prec !== "object") { - Caml_array.set(h.data, i, param); - } else { - prec.next = param; - } - param.data = Caml_option.valFromOption(data$1); - _param = next; - _prec = param; - continue; - } - h.size = h.size - 1 | 0; - _param = next; - continue; - }; -} - -function filter_map_inplace(f, h) { - let d = h.data; - let old_trav = h.initial_size < 0; - if (!old_trav) { - flip_ongoing_traversal(h); - } - try { - for (let i = 0, i_finish = d.length; i < i_finish; ++i) { - filter_map_inplace_bucket(f, h, i, "Empty", Caml_array.get(h.data, i)); - } - return; - } catch (exn) { - if (old_trav) { - throw exn; - } - flip_ongoing_traversal(h); - throw exn; - } -} - -function fold(f, h, init) { - let do_bucket = (_b, _accu) => { - while (true) { - let accu = _accu; - let b = _b; - if (typeof b !== "object") { - return accu; - } - let key = b.key; - let data = b.data; - let next = b.next; - _accu = f(key, data, accu); - _b = next; - continue; - }; - }; - let old_trav = h.initial_size < 0; - if (!old_trav) { - flip_ongoing_traversal(h); - } - try { - let d = h.data; - let accu = init; - for (let i = 0, i_finish = d.length; i < i_finish; ++i) { - accu = do_bucket(Caml_array.get(d, i), accu); - } - if (!old_trav) { - flip_ongoing_traversal(h); - } - return accu; - } catch (exn) { - if (old_trav) { - throw exn; - } - flip_ongoing_traversal(h); - throw exn; - } -} - -function bucket_length(_accu, _param) { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - let next = param.next; - _param = next; - _accu = accu + 1 | 0; - continue; - }; -} - -function stats(h) { - let mbl = $$Array.fold_left((m, b) => Caml.int_max(m, bucket_length(0, b)), 0, h.data); - let histo = Caml_array.make(mbl + 1 | 0, 0); - $$Array.iter(b => { - let l = bucket_length(0, b); - Caml_array.set(histo, l, Caml_array.get(histo, l) + 1 | 0); - }, h.data); - return { - num_bindings: h.size, - num_buckets: h.data.length, - max_bucket_length: mbl, - bucket_histogram: histo - }; -} - -function MakeSeeded(H) { - let key_index = (h, key) => H.hash(h.seed, key) & (h.data.length - 1 | 0); - let add = (h, key, data) => { - let i = key_index(h, key); - let bucket = { - TAG: "Cons", - key: key, - data: data, - next: Caml_array.get(h.data, i) - }; - Caml_array.set(h.data, i, bucket); - h.size = h.size + 1 | 0; - if (h.size > (h.data.length << 1)) { - return resize(key_index, h); - } - - }; - let remove = (h, key) => { - let i = key_index(h, key); - let _prec = "Empty"; - let _param = Caml_array.get(h.data, i); - while (true) { - let param = _param; - let prec = _prec; - if (typeof param !== "object") { - return; - } - let k = param.key; - let next = param.next; - if (H.equal(k, key)) { - h.size = h.size - 1 | 0; - if (typeof prec !== "object") { - return Caml_array.set(h.data, i, next); - } else { - prec.next = next; - return; - } - } - _param = next; - _prec = param; - continue; - }; - }; - let find = (h, key) => { - let match = Caml_array.get(h.data, key_index(h, key)); - if (typeof match !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let k1 = match.key; - let d1 = match.data; - let next1 = match.next; - if (H.equal(key, k1)) { - return d1; - } - if (typeof next1 !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let k2 = next1.key; - let d2 = next1.data; - let next2 = next1.next; - if (H.equal(key, k2)) { - return d2; - } - if (typeof next2 !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let k3 = next2.key; - let d3 = next2.data; - let next3 = next2.next; - if (H.equal(key, k3)) { - return d3; - } else { - let _param = next3; - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let k = param.key; - let data = param.data; - let next = param.next; - if (H.equal(key, k)) { - return data; - } - _param = next; - continue; - }; - } - }; - let find_opt = (h, key) => { - let match = Caml_array.get(h.data, key_index(h, key)); - if (typeof match !== "object") { - return; - } - let k1 = match.key; - let d1 = match.data; - let next1 = match.next; - if (H.equal(key, k1)) { - return Caml_option.some(d1); - } - if (typeof next1 !== "object") { - return; - } - let k2 = next1.key; - let d2 = next1.data; - let next2 = next1.next; - if (H.equal(key, k2)) { - return Caml_option.some(d2); - } - if (typeof next2 !== "object") { - return; - } - let k3 = next2.key; - let d3 = next2.data; - let next3 = next2.next; - if (H.equal(key, k3)) { - return Caml_option.some(d3); - } else { - let _param = next3; - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let k = param.key; - let data = param.data; - let next = param.next; - if (H.equal(key, k)) { - return Caml_option.some(data); - } - _param = next; - continue; - }; - } - }; - let find_all = (h, key) => { - let find_in_bucket = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return /* [] */0; - } - let k = param.key; - let d = param.data; - let next = param.next; - if (H.equal(k, key)) { - return { - hd: d, - tl: find_in_bucket(next) - }; - } - _param = next; - continue; - }; - }; - return find_in_bucket(Caml_array.get(h.data, key_index(h, key))); - }; - let replace_bucket = (key, data, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - let k = param.key; - let next = param.next; - if (H.equal(k, key)) { - param.key = key; - param.data = data; - return false; - } - _param = next; - continue; - }; - }; - let replace = (h, key, data) => { - let i = key_index(h, key); - let l = Caml_array.get(h.data, i); - if (replace_bucket(key, data, l)) { - Caml_array.set(h.data, i, { - TAG: "Cons", - key: key, - data: data, - next: l - }); - h.size = h.size + 1 | 0; - if (h.size > (h.data.length << 1)) { - return resize(key_index, h); - } else { - return; - } - } - - }; - let mem = (h, key) => { - let _param = Caml_array.get(h.data, key_index(h, key)); - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let k = param.key; - let next = param.next; - if (H.equal(k, key)) { - return true; - } - _param = next; - continue; - }; - }; - return { - create: create, - clear: clear, - reset: reset, - copy: copy, - add: add, - remove: remove, - find: find, - find_opt: find_opt, - find_all: find_all, - replace: replace, - mem: mem, - iter: iter, - filter_map_inplace: filter_map_inplace, - fold: fold, - length: length, - stats: stats - }; -} - -function Make(H) { - let equal = H.equal; - let key_index = (h, key) => H.hash(key) & (h.data.length - 1 | 0); - let add = (h, key, data) => { - let i = key_index(h, key); - let bucket = { - TAG: "Cons", - key: key, - data: data, - next: Caml_array.get(h.data, i) - }; - Caml_array.set(h.data, i, bucket); - h.size = h.size + 1 | 0; - if (h.size > (h.data.length << 1)) { - return resize(key_index, h); - } - - }; - let remove = (h, key) => { - let i = key_index(h, key); - let _prec = "Empty"; - let _param = Caml_array.get(h.data, i); - while (true) { - let param = _param; - let prec = _prec; - if (typeof param !== "object") { - return; - } - let k = param.key; - let next = param.next; - if (equal(k, key)) { - h.size = h.size - 1 | 0; - if (typeof prec !== "object") { - return Caml_array.set(h.data, i, next); - } else { - prec.next = next; - return; - } - } - _param = next; - _prec = param; - continue; - }; - }; - let find = (h, key) => { - let match = Caml_array.get(h.data, key_index(h, key)); - if (typeof match !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let k1 = match.key; - let d1 = match.data; - let next1 = match.next; - if (equal(key, k1)) { - return d1; - } - if (typeof next1 !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let k2 = next1.key; - let d2 = next1.data; - let next2 = next1.next; - if (equal(key, k2)) { - return d2; - } - if (typeof next2 !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let k3 = next2.key; - let d3 = next2.data; - let next3 = next2.next; - if (equal(key, k3)) { - return d3; - } else { - let _param = next3; - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let k = param.key; - let data = param.data; - let next = param.next; - if (equal(key, k)) { - return data; - } - _param = next; - continue; - }; - } - }; - let find_opt = (h, key) => { - let match = Caml_array.get(h.data, key_index(h, key)); - if (typeof match !== "object") { - return; - } - let k1 = match.key; - let d1 = match.data; - let next1 = match.next; - if (equal(key, k1)) { - return Caml_option.some(d1); - } - if (typeof next1 !== "object") { - return; - } - let k2 = next1.key; - let d2 = next1.data; - let next2 = next1.next; - if (equal(key, k2)) { - return Caml_option.some(d2); - } - if (typeof next2 !== "object") { - return; - } - let k3 = next2.key; - let d3 = next2.data; - let next3 = next2.next; - if (equal(key, k3)) { - return Caml_option.some(d3); - } else { - let _param = next3; - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let k = param.key; - let data = param.data; - let next = param.next; - if (equal(key, k)) { - return Caml_option.some(data); - } - _param = next; - continue; - }; - } - }; - let find_all = (h, key) => { - let find_in_bucket = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return /* [] */0; - } - let k = param.key; - let d = param.data; - let next = param.next; - if (equal(k, key)) { - return { - hd: d, - tl: find_in_bucket(next) - }; - } - _param = next; - continue; - }; - }; - return find_in_bucket(Caml_array.get(h.data, key_index(h, key))); - }; - let replace_bucket = (key, data, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - let k = param.key; - let next = param.next; - if (equal(k, key)) { - param.key = key; - param.data = data; - return false; - } - _param = next; - continue; - }; - }; - let replace = (h, key, data) => { - let i = key_index(h, key); - let l = Caml_array.get(h.data, i); - if (replace_bucket(key, data, l)) { - Caml_array.set(h.data, i, { - TAG: "Cons", - key: key, - data: data, - next: l - }); - h.size = h.size + 1 | 0; - if (h.size > (h.data.length << 1)) { - return resize(key_index, h); - } else { - return; - } - } - - }; - let mem = (h, key) => { - let _param = Caml_array.get(h.data, key_index(h, key)); - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let k = param.key; - let next = param.next; - if (equal(k, key)) { - return true; - } - _param = next; - continue; - }; - }; - let create$1 = sz => create(false, sz); - return { - create: create$1, - clear: clear, - reset: reset, - copy: copy, - add: add, - remove: remove, - find: find, - find_opt: find_opt, - find_all: find_all, - replace: replace, - mem: mem, - iter: iter, - filter_map_inplace: filter_map_inplace, - fold: fold, - length: length, - stats: stats - }; -} - -let seeded_hash_param = Caml_hash.hash; - -exports.create = create; -exports.clear = clear; -exports.reset = reset; -exports.copy = copy; -exports.add = add; -exports.find = find; -exports.find_opt = find_opt; -exports.find_all = find_all; -exports.mem = mem; -exports.remove = remove; -exports.replace = replace; -exports.iter = iter; -exports.filter_map_inplace = filter_map_inplace; -exports.fold = fold; -exports.length = length; -exports.randomize = randomize; -exports.is_randomized = is_randomized; -exports.stats = stats; -exports.Make = Make; -exports.MakeSeeded = MakeSeeded; exports.hash = hash; -exports.seeded_hash = seeded_hash; -exports.hash_param = hash_param; -exports.seeded_hash_param = seeded_hash_param; /* No side effect */ diff --git a/lib/js/hashtblLabels.js b/lib/js/hashtblLabels.js deleted file mode 100644 index 26214bb36b..0000000000 --- a/lib/js/hashtblLabels.js +++ /dev/null @@ -1,155 +0,0 @@ -'use strict'; - -let Hashtbl = require("./hashtbl.js"); - -function add(tbl, key, data) { - Hashtbl.add(tbl, key, data); -} - -function replace(tbl, key, data) { - Hashtbl.replace(tbl, key, data); -} - -function iter(f, tbl) { - Hashtbl.iter((key, data) => f(key, data), tbl); -} - -function filter_map_inplace(f, tbl) { - Hashtbl.filter_map_inplace((key, data) => f(key, data), tbl); -} - -function fold(f, tbl, init) { - return Hashtbl.fold((key, data, acc) => f(key, data, acc), tbl, init); -} - -function MakeSeeded(H) { - let include = Hashtbl.MakeSeeded(H); - let add = include.add; - let replace = include.replace; - let iter = include.iter; - let filter_map_inplace = include.filter_map_inplace; - let fold = include.fold; - let add$1 = (tbl, key, data) => add(tbl, key, data); - let replace$1 = (tbl, key, data) => replace(tbl, key, data); - let iter$1 = (f, tbl) => iter((key, data) => f(key, data), tbl); - let filter_map_inplace$1 = (f, tbl) => filter_map_inplace((key, data) => f(key, data), tbl); - let fold$1 = (f, tbl, init) => fold((key, data, acc) => f(key, data, acc), tbl, init); - return { - create: include.create, - clear: include.clear, - reset: include.reset, - copy: include.copy, - add: add$1, - remove: include.remove, - find: include.find, - find_opt: include.find_opt, - find_all: include.find_all, - replace: replace$1, - mem: include.mem, - iter: iter$1, - filter_map_inplace: filter_map_inplace$1, - fold: fold$1, - length: include.length, - stats: include.stats - }; -} - -function Make(H) { - let hash = (_seed, x) => H.hash(x); - let H_equal = H.equal; - let H$1 = { - equal: H_equal, - hash: hash - }; - let include = Hashtbl.MakeSeeded(H$1); - let create = include.create; - let add = include.add; - let replace = include.replace; - let iter = include.iter; - let filter_map_inplace = include.filter_map_inplace; - let fold = include.fold; - let add$1 = (tbl, key, data) => add(tbl, key, data); - let replace$1 = (tbl, key, data) => replace(tbl, key, data); - let iter$1 = (f, tbl) => iter((key, data) => f(key, data), tbl); - let filter_map_inplace$1 = (f, tbl) => filter_map_inplace((key, data) => f(key, data), tbl); - let fold$1 = (f, tbl, init) => fold((key, data, acc) => f(key, data, acc), tbl, init); - let create$1 = sz => create(false, sz); - return { - create: create$1, - clear: include.clear, - reset: include.reset, - copy: include.copy, - add: add$1, - remove: include.remove, - find: include.find, - find_opt: include.find_opt, - find_all: include.find_all, - replace: replace$1, - mem: include.mem, - iter: iter$1, - filter_map_inplace: filter_map_inplace$1, - fold: fold$1, - length: include.length, - stats: include.stats - }; -} - -let create = Hashtbl.create; - -let clear = Hashtbl.clear; - -let reset = Hashtbl.reset; - -let copy = Hashtbl.copy; - -let find = Hashtbl.find; - -let find_opt = Hashtbl.find_opt; - -let find_all = Hashtbl.find_all; - -let mem = Hashtbl.mem; - -let remove = Hashtbl.remove; - -let length = Hashtbl.length; - -let randomize = Hashtbl.randomize; - -let is_randomized = Hashtbl.is_randomized; - -let stats = Hashtbl.stats; - -let hash = Hashtbl.hash; - -let seeded_hash = Hashtbl.seeded_hash; - -let hash_param = Hashtbl.hash_param; - -let seeded_hash_param = Hashtbl.seeded_hash_param; - -exports.create = create; -exports.clear = clear; -exports.reset = reset; -exports.copy = copy; -exports.find = find; -exports.find_opt = find_opt; -exports.find_all = find_all; -exports.mem = mem; -exports.remove = remove; -exports.length = length; -exports.randomize = randomize; -exports.is_randomized = is_randomized; -exports.stats = stats; -exports.hash = hash; -exports.seeded_hash = seeded_hash; -exports.hash_param = hash_param; -exports.seeded_hash_param = seeded_hash_param; -exports.add = add; -exports.replace = replace; -exports.iter = iter; -exports.filter_map_inplace = filter_map_inplace; -exports.fold = fold; -exports.MakeSeeded = MakeSeeded; -exports.Make = Make; -/* No side effect */ diff --git a/lib/js/int32.js b/lib/js/int32.js deleted file mode 100644 index 2493b20d95..0000000000 --- a/lib/js/int32.js +++ /dev/null @@ -1,72 +0,0 @@ -'use strict'; - -let Caml = require("./caml.js"); -let Caml_format = require("./caml_format.js"); -let Caml_js_exceptions = require("./caml_js_exceptions.js"); - -function succ(n) { - return n + 1 | 0; -} - -function pred(n) { - return n - 1 | 0; -} - -function abs(n) { - if (n >= 0) { - return n; - } else { - return -n | 0; - } -} - -function lognot(n) { - return n ^ -1; -} - -function to_string(n) { - return Caml_format.format_int("%d", n); -} - -function of_string_opt(s) { - try { - return Caml_format.int_of_string(s); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Failure") { - return; - } - throw exn; - } -} - -let compare = Caml.int_compare; - -function equal(x, y) { - return x === y; -} - -let zero = 0; - -let one = 1; - -let minus_one = -1; - -let max_int = 2147483647; - -let min_int = -2147483648; - -exports.zero = zero; -exports.one = one; -exports.minus_one = minus_one; -exports.succ = succ; -exports.pred = pred; -exports.abs = abs; -exports.max_int = max_int; -exports.min_int = min_int; -exports.lognot = lognot; -exports.of_string_opt = of_string_opt; -exports.to_string = to_string; -exports.compare = compare; -exports.equal = equal; -/* No side effect */ diff --git a/lib/js/int64.js b/lib/js/int64.js deleted file mode 100644 index c6423d62e4..0000000000 --- a/lib/js/int64.js +++ /dev/null @@ -1,67 +0,0 @@ -'use strict'; - -let Caml = require("./caml.js"); -let Caml_int64 = require("./caml_int64.js"); -let Caml_format = require("./caml_format.js"); -let Caml_js_exceptions = require("./caml_js_exceptions.js"); - -function pred(n) { - return Caml_int64.sub(n, Caml_int64.one); -} - -function abs(n) { - if (Caml.i64_ge(n, Caml_int64.zero)) { - return n; - } else { - return Caml_int64.neg(n); - } -} - -function lognot(n) { - return Caml_int64.xor(n, Caml_int64.neg_one); -} - -function of_string_opt(s) { - try { - return Caml_format.int64_of_string(s); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Failure") { - return; - } - throw exn; - } -} - -let compare = Caml_int64.compare; - -let equal = Caml_int64.equal; - -let zero = Caml_int64.zero; - -let one = Caml_int64.one; - -let minus_one = Caml_int64.neg_one; - -let succ = Caml_int64.succ; - -let max_int = Caml_int64.max_int; - -let min_int = Caml_int64.min_int; - -let to_string = Caml_int64.to_string; - -exports.zero = zero; -exports.one = one; -exports.minus_one = minus_one; -exports.succ = succ; -exports.pred = pred; -exports.abs = abs; -exports.max_int = max_int; -exports.min_int = min_int; -exports.lognot = lognot; -exports.of_string_opt = of_string_opt; -exports.to_string = to_string; -exports.compare = compare; -exports.equal = equal; -/* No side effect */ diff --git a/lib/js/js_array.js b/lib/js/js_array.js index 69df233cf0..f86bf05cbf 100644 --- a/lib/js/js_array.js +++ b/lib/js/js_array.js @@ -1,6 +1,6 @@ 'use strict'; -let Caml_option = require("./caml_option.js"); +let Primitive_option = require("./primitive_option.js"); function copyWithin(to_, obj) { return obj.copyWithin(to_); @@ -115,11 +115,11 @@ function filteri(arg1, obj) { } function find(arg1, obj) { - return Caml_option.undefined_to_opt(obj.find(arg1)); + return Primitive_option.fromUndefined(obj.find(arg1)); } function findi(arg1, obj) { - return Caml_option.undefined_to_opt(obj.find(arg1)); + return Primitive_option.fromUndefined(obj.find(arg1)); } function findIndex(arg1, obj) { diff --git a/lib/js/js_dict.js b/lib/js/js_dict.js index 00f8ce1321..ab6efd976b 100644 --- a/lib/js/js_dict.js +++ b/lib/js/js_dict.js @@ -1,10 +1,10 @@ 'use strict'; -let Caml_option = require("./caml_option.js"); +let Primitive_option = require("./primitive_option.js"); function get(dict, k) { if ((k in dict)) { - return Caml_option.some(dict[k]); + return Primitive_option.some(dict[k]); } } diff --git a/lib/js/js_exn.js b/lib/js/js_exn.js index 34b90db044..07a77f6631 100644 --- a/lib/js/js_exn.js +++ b/lib/js/js_exn.js @@ -1,5 +1,16 @@ 'use strict'; +let Primitive_option = require("./primitive_option.js"); + +let $$Error = "JsError"; + +function asJsExn(exn) { + let t = exn; + if (t.RE_EXN_ID === $$Error) { + return Primitive_option.some(t._1); + } + +} function raiseError(str) { throw new Error(str); @@ -29,9 +40,8 @@ function raiseUriError(str) { throw new URIError(str); } -let $$Error$1 = "JsError"; - -exports.$$Error = $$Error$1; +exports.$$Error = $$Error; +exports.asJsExn = asJsExn; exports.raiseError = raiseError; exports.raiseEvalError = raiseEvalError; exports.raiseRangeError = raiseRangeError; diff --git a/lib/js/caml_array_extern.js b/lib/js/js_extern.js similarity index 100% rename from lib/js/caml_array_extern.js rename to lib/js/js_extern.js diff --git a/lib/js/js_null.js b/lib/js/js_null.js index 682a2a31a5..9caa4a4a84 100644 --- a/lib/js/js_null.js +++ b/lib/js/js_null.js @@ -1,6 +1,6 @@ 'use strict'; -let Caml_option = require("./caml_option.js"); +let Primitive_option = require("./primitive_option.js"); function test(x) { return x === null; @@ -30,7 +30,7 @@ function iter(x, f) { function fromOption(x) { if (x !== undefined) { - return Caml_option.valFromOption(x); + return Primitive_option.valFromOption(x); } else { return null; } diff --git a/lib/js/js_null_undefined.js b/lib/js/js_null_undefined.js index 334fe5e479..3f846c6c1b 100644 --- a/lib/js/js_null_undefined.js +++ b/lib/js/js_null_undefined.js @@ -1,6 +1,6 @@ 'use strict'; -let Caml_option = require("./caml_option.js"); +let Primitive_option = require("./primitive_option.js"); function bind(x, f) { if (x == null) { @@ -19,7 +19,7 @@ function iter(x, f) { function fromOption(x) { if (x !== undefined) { - return Caml_option.valFromOption(x); + return Primitive_option.valFromOption(x); } } diff --git a/lib/js/js_option.js b/lib/js/js_option.js index 5a513afd29..1d9f540e0b 100644 --- a/lib/js/js_option.js +++ b/lib/js/js_option.js @@ -1,9 +1,9 @@ 'use strict'; -let Caml_option = require("./caml_option.js"); +let Primitive_option = require("./primitive_option.js"); function some(x) { - return Caml_option.some(x); + return Primitive_option.some(x); } function isSome(x) { @@ -12,7 +12,7 @@ function isSome(x) { function isSomeValue(eq, v, x) { if (x !== undefined) { - return eq(v, Caml_option.valFromOption(x)); + return eq(v, Primitive_option.valFromOption(x)); } else { return false; } @@ -24,7 +24,7 @@ function isNone(x) { function getExn(x) { if (x !== undefined) { - return Caml_option.valFromOption(x); + return Primitive_option.valFromOption(x); } throw new Error("getExn"); } @@ -32,7 +32,7 @@ function getExn(x) { function equal(eq, a, b) { if (a !== undefined) { if (b !== undefined) { - return eq(Caml_option.valFromOption(a), Caml_option.valFromOption(b)); + return eq(Primitive_option.valFromOption(a), Primitive_option.valFromOption(b)); } else { return false; } @@ -43,21 +43,21 @@ function equal(eq, a, b) { function andThen(f, x) { if (x !== undefined) { - return f(Caml_option.valFromOption(x)); + return f(Primitive_option.valFromOption(x)); } } function map(f, x) { if (x !== undefined) { - return Caml_option.some(f(Caml_option.valFromOption(x))); + return Primitive_option.some(f(Primitive_option.valFromOption(x))); } } function getWithDefault(a, x) { if (x !== undefined) { - return Caml_option.valFromOption(x); + return Primitive_option.valFromOption(x); } else { return a; } @@ -67,9 +67,9 @@ function filter(f, x) { if (x === undefined) { return; } - let x$1 = Caml_option.valFromOption(x); + let x$1 = Primitive_option.valFromOption(x); if (f(x$1)) { - return Caml_option.some(x$1); + return Primitive_option.some(x$1); } } diff --git a/lib/js/js_string.js b/lib/js/js_string.js index 93d840b104..77aa03acf3 100644 --- a/lib/js/js_string.js +++ b/lib/js/js_string.js @@ -1,6 +1,6 @@ 'use strict'; -let Caml_option = require("./caml_option.js"); +let Primitive_option = require("./primitive_option.js"); function charAt(arg1, obj) { return obj.charAt(arg1); @@ -59,7 +59,7 @@ function localeCompare(arg1, obj) { } function match_(arg1, obj) { - return Caml_option.null_to_opt(obj.match(arg1)); + return Primitive_option.fromNull(obj.match(arg1)); } function normalizeByForm(arg1, obj) { diff --git a/lib/js/js_undefined.js b/lib/js/js_undefined.js index f67e1ec960..7403aaf3b6 100644 --- a/lib/js/js_undefined.js +++ b/lib/js/js_undefined.js @@ -1,6 +1,6 @@ 'use strict'; -let Caml_option = require("./caml_option.js"); +let Primitive_option = require("./primitive_option.js"); function test(x) { return x === undefined; @@ -33,7 +33,7 @@ function iter(x, f) { function fromOption(x) { if (x !== undefined) { - return Caml_option.valFromOption(x); + return Primitive_option.valFromOption(x); } } diff --git a/lib/js/lazy.js b/lib/js/lazy.js index 5425717915..01118d4605 100644 --- a/lib/js/lazy.js +++ b/lib/js/lazy.js @@ -1,31 +1,23 @@ 'use strict'; -let CamlinternalLazy = require("./camlinternalLazy.js"); +let Primitive_lazy = require("./primitive_lazy.js"); -function from_fun(f) { - return CamlinternalLazy.from_fun(() => f()); -} +let Undefined = Primitive_lazy.Undefined; -let from_val = CamlinternalLazy.from_val; +let force = Primitive_lazy.force; -let Undefined = CamlinternalLazy.Undefined; +let force_val = Primitive_lazy.force_val; -let force_val = CamlinternalLazy.force_val; +let from_fun = Primitive_lazy.from_fun; -let is_val = CamlinternalLazy.is_val; +let from_val = Primitive_lazy.from_val; -let lazy_from_fun = from_fun; - -let lazy_from_val = from_val; - -let lazy_is_val = CamlinternalLazy.is_val; +let is_val = Primitive_lazy.is_val; exports.Undefined = Undefined; +exports.force = force; exports.force_val = force_val; exports.from_fun = from_fun; exports.from_val = from_val; exports.is_val = is_val; -exports.lazy_from_fun = lazy_from_fun; -exports.lazy_from_val = lazy_from_val; -exports.lazy_is_val = lazy_is_val; /* No side effect */ diff --git a/lib/js/lexing.js b/lib/js/lexing.js deleted file mode 100644 index 01083fc59f..0000000000 --- a/lib/js/lexing.js +++ /dev/null @@ -1,214 +0,0 @@ -'use strict'; - -let Bytes = require("./bytes.js"); -let Caml_array = require("./caml_array.js"); -let Caml_bytes = require("./caml_bytes.js"); -let Caml_lexer = require("./caml_lexer.js"); - -function engine(tbl, state, buf) { - let result = Caml_lexer.lex_engine(tbl, state, buf); - if (result >= 0) { - buf.lex_start_p = buf.lex_curr_p; - let init = buf.lex_curr_p; - buf.lex_curr_p = { - pos_fname: init.pos_fname, - pos_lnum: init.pos_lnum, - pos_bol: init.pos_bol, - pos_cnum: buf.lex_abs_pos + buf.lex_curr_pos | 0 - }; - } - return result; -} - -function new_engine(tbl, state, buf) { - let result = Caml_lexer.new_lex_engine(tbl, state, buf); - if (result >= 0) { - buf.lex_start_p = buf.lex_curr_p; - let init = buf.lex_curr_p; - buf.lex_curr_p = { - pos_fname: init.pos_fname, - pos_lnum: init.pos_lnum, - pos_bol: init.pos_bol, - pos_cnum: buf.lex_abs_pos + buf.lex_curr_pos | 0 - }; - } - return result; -} - -let zero_pos = { - pos_fname: "", - pos_lnum: 1, - pos_bol: 0, - pos_cnum: 0 -}; - -function from_function(f) { - return { - refill_buff: x => { - let aux_buffer = Caml_bytes.create(512); - let read = f(aux_buffer, aux_buffer.length); - let n = read > 0 ? read : (x.lex_eof_reached = true, 0); - if ((x.lex_buffer_len + n | 0) > x.lex_buffer.length) { - if (((x.lex_buffer_len - x.lex_start_pos | 0) + n | 0) <= x.lex_buffer.length) { - Bytes.blit(x.lex_buffer, x.lex_start_pos, x.lex_buffer, 0, x.lex_buffer_len - x.lex_start_pos | 0); - } else { - let newlen = (x.lex_buffer.length << 1); - if (((x.lex_buffer_len - x.lex_start_pos | 0) + n | 0) > newlen) { - throw { - RE_EXN_ID: "Failure", - _1: "Lexing.lex_refill: cannot grow buffer", - Error: new Error() - }; - } - let newbuf = Caml_bytes.create(newlen); - Bytes.blit(x.lex_buffer, x.lex_start_pos, newbuf, 0, x.lex_buffer_len - x.lex_start_pos | 0); - x.lex_buffer = newbuf; - } - let s = x.lex_start_pos; - x.lex_abs_pos = x.lex_abs_pos + s | 0; - x.lex_curr_pos = x.lex_curr_pos - s | 0; - x.lex_start_pos = 0; - x.lex_last_pos = x.lex_last_pos - s | 0; - x.lex_buffer_len = x.lex_buffer_len - s | 0; - let t = x.lex_mem; - for (let i = 0, i_finish = t.length; i < i_finish; ++i) { - let v = Caml_array.get(t, i); - if (v >= 0) { - Caml_array.set(t, i, v - s | 0); - } - - } - } - Bytes.blit(aux_buffer, 0, x.lex_buffer, x.lex_buffer_len, n); - x.lex_buffer_len = x.lex_buffer_len + n | 0; - }, - lex_buffer: Caml_bytes.create(1024), - lex_buffer_len: 0, - lex_abs_pos: 0, - lex_start_pos: 0, - lex_curr_pos: 0, - lex_last_pos: 0, - lex_last_action: 0, - lex_eof_reached: false, - lex_mem: [], - lex_start_p: zero_pos, - lex_curr_p: zero_pos - }; -} - -function from_string(s) { - return { - refill_buff: lexbuf => { - lexbuf.lex_eof_reached = true; - }, - lex_buffer: Bytes.of_string(s), - lex_buffer_len: s.length, - lex_abs_pos: 0, - lex_start_pos: 0, - lex_curr_pos: 0, - lex_last_pos: 0, - lex_last_action: 0, - lex_eof_reached: true, - lex_mem: [], - lex_start_p: zero_pos, - lex_curr_p: zero_pos - }; -} - -function lexeme(lexbuf) { - let len = lexbuf.lex_curr_pos - lexbuf.lex_start_pos | 0; - return Bytes.sub_string(lexbuf.lex_buffer, lexbuf.lex_start_pos, len); -} - -function sub_lexeme(lexbuf, i1, i2) { - let len = i2 - i1 | 0; - return Bytes.sub_string(lexbuf.lex_buffer, i1, len); -} - -function sub_lexeme_opt(lexbuf, i1, i2) { - if (i1 < 0) { - return; - } - let len = i2 - i1 | 0; - return Bytes.sub_string(lexbuf.lex_buffer, i1, len); -} - -function sub_lexeme_char(lexbuf, i) { - return Caml_bytes.get(lexbuf.lex_buffer, i); -} - -function sub_lexeme_char_opt(lexbuf, i) { - if (i >= 0) { - return Caml_bytes.get(lexbuf.lex_buffer, i); - } - -} - -function lexeme_char(lexbuf, i) { - return Caml_bytes.get(lexbuf.lex_buffer, lexbuf.lex_start_pos + i | 0); -} - -function lexeme_start(lexbuf) { - return lexbuf.lex_start_p.pos_cnum; -} - -function lexeme_end(lexbuf) { - return lexbuf.lex_curr_p.pos_cnum; -} - -function lexeme_start_p(lexbuf) { - return lexbuf.lex_start_p; -} - -function lexeme_end_p(lexbuf) { - return lexbuf.lex_curr_p; -} - -function new_line(lexbuf) { - let lcp = lexbuf.lex_curr_p; - lexbuf.lex_curr_p = { - pos_fname: lcp.pos_fname, - pos_lnum: lcp.pos_lnum + 1 | 0, - pos_bol: lcp.pos_cnum, - pos_cnum: lcp.pos_cnum - }; -} - -function flush_input(lb) { - lb.lex_curr_pos = 0; - lb.lex_abs_pos = 0; - let init = lb.lex_curr_p; - lb.lex_curr_p = { - pos_fname: init.pos_fname, - pos_lnum: init.pos_lnum, - pos_bol: init.pos_bol, - pos_cnum: 0 - }; - lb.lex_buffer_len = 0; -} - -let dummy_pos = { - pos_fname: "", - pos_lnum: 0, - pos_bol: 0, - pos_cnum: -1 -}; - -exports.dummy_pos = dummy_pos; -exports.from_string = from_string; -exports.from_function = from_function; -exports.lexeme = lexeme; -exports.lexeme_char = lexeme_char; -exports.lexeme_start = lexeme_start; -exports.lexeme_end = lexeme_end; -exports.lexeme_start_p = lexeme_start_p; -exports.lexeme_end_p = lexeme_end_p; -exports.new_line = new_line; -exports.flush_input = flush_input; -exports.sub_lexeme = sub_lexeme; -exports.sub_lexeme_opt = sub_lexeme_opt; -exports.sub_lexeme_char = sub_lexeme_char; -exports.sub_lexeme_char_opt = sub_lexeme_char_opt; -exports.engine = engine; -exports.new_engine = new_engine; -/* No side effect */ diff --git a/lib/js/list.js b/lib/js/list.js index 967d6dbb66..c71574f9d6 100644 --- a/lib/js/list.js +++ b/lib/js/list.js @@ -1,8 +1,7 @@ 'use strict'; -let Caml_obj = require("./caml_obj.js"); let Pervasives = require("./pervasives.js"); -let Caml_option = require("./caml_option.js"); +let Primitive_option = require("./primitive_option.js"); function length(l) { let _len = 0; @@ -94,7 +93,7 @@ function nth_opt(l, n) { return; } if (n$1 === 0) { - return Caml_option.some(l$1.hd); + return Primitive_option.some(l$1.hd); } _n = n$1 - 1 | 0; _l = l$1.tl; @@ -497,7 +496,7 @@ function mem(x, _param) { if (!param) { return false; } - if (Caml_obj.equal(param.hd, x)) { + if (param.hd === x) { return true; } _param = param.tl; @@ -524,7 +523,7 @@ function assoc(x, _param) { let param = _param; if (param) { let match = param.hd; - if (Caml_obj.equal(match[0], x)) { + if (match[0] === x) { return match[1]; } _param = param.tl; @@ -544,8 +543,8 @@ function assoc_opt(x, _param) { return; } let match = param.hd; - if (Caml_obj.equal(match[0], x)) { - return Caml_option.some(match[1]); + if (match[0] === x) { + return Primitive_option.some(match[1]); } _param = param.tl; continue; @@ -578,7 +577,7 @@ function assq_opt(x, _param) { } let match = param.hd; if (match[0] === x) { - return Caml_option.some(match[1]); + return Primitive_option.some(match[1]); } _param = param.tl; continue; @@ -591,7 +590,7 @@ function mem_assoc(x, _param) { if (!param) { return false; } - if (Caml_obj.equal(param.hd[0], x)) { + if (param.hd[0] === x) { return true; } _param = param.tl; @@ -619,7 +618,7 @@ function remove_assoc(x, param) { } let l = param.tl; let pair = param.hd; - if (Caml_obj.equal(pair[0], x)) { + if (pair[0] === x) { return l; } else { return { @@ -671,7 +670,7 @@ function find_opt(p, _param) { } let x = param.hd; if (p(x)) { - return Caml_option.some(x); + return Primitive_option.some(x); } _param = param.tl; continue; @@ -821,7 +820,7 @@ function chop(_k, _l) { RE_EXN_ID: "Assert_failure", _1: [ "list.res", - 420, + 411, 11 ], Error: new Error() diff --git a/lib/js/listLabels.js b/lib/js/listLabels.js deleted file mode 100644 index efb24d4ab4..0000000000 --- a/lib/js/listLabels.js +++ /dev/null @@ -1,1708 +0,0 @@ -'use strict'; - -let Caml_obj = require("./caml_obj.js"); -let Pervasives = require("./pervasives.js"); -let Caml_option = require("./caml_option.js"); - -function length(l) { - let _len = 0; - let _param = l; - while (true) { - let param = _param; - let len = _len; - if (!param) { - return len; - } - _param = param.tl; - _len = len + 1 | 0; - continue; - }; -} - -function cons(a, l) { - return { - hd: a, - tl: l - }; -} - -function hd(param) { - if (param) { - return param.hd; - } - throw { - RE_EXN_ID: "Failure", - _1: "hd", - Error: new Error() - }; -} - -function tl(param) { - if (param) { - return param.tl; - } - throw { - RE_EXN_ID: "Failure", - _1: "tl", - Error: new Error() - }; -} - -function nth(l, n) { - if (n < 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.nth", - Error: new Error() - }; - } - let _l = l; - let _n = n; - while (true) { - let n$1 = _n; - let l$1 = _l; - if (l$1) { - if (n$1 === 0) { - return l$1.hd; - } - _n = n$1 - 1 | 0; - _l = l$1.tl; - continue; - } - throw { - RE_EXN_ID: "Failure", - _1: "nth", - Error: new Error() - }; - }; -} - -function nth_opt(l, n) { - if (n < 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.nth", - Error: new Error() - }; - } - let _l = l; - let _n = n; - while (true) { - let n$1 = _n; - let l$1 = _l; - if (!l$1) { - return; - } - if (n$1 === 0) { - return Caml_option.some(l$1.hd); - } - _n = n$1 - 1 | 0; - _l = l$1.tl; - continue; - }; -} - -function rev_append(_l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (!l1) { - return l2; - } - _l2 = { - hd: l1.hd, - tl: l2 - }; - _l1 = l1.tl; - continue; - }; -} - -function rev(l) { - return rev_append(l, /* [] */0); -} - -function init_tailrec_aux(_acc, _i, n, f) { - while (true) { - let i = _i; - let acc = _acc; - if (i >= n) { - return acc; - } - _i = i + 1 | 0; - _acc = { - hd: f(i), - tl: acc - }; - continue; - }; -} - -function init_aux(i, n, f) { - if (i >= n) { - return /* [] */0; - } - let r = f(i); - return { - hd: r, - tl: init_aux(i + 1 | 0, n, f) - }; -} - -function init(len, f) { - if (len < 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.init", - Error: new Error() - }; - } - if (len > 10000) { - return rev_append(init_tailrec_aux(/* [] */0, 0, len, f), /* [] */0); - } else { - return init_aux(0, len, f); - } -} - -function flatten(param) { - if (param) { - return Pervasives.$at(param.hd, flatten(param.tl)); - } else { - return /* [] */0; - } -} - -function map(f, param) { - if (!param) { - return /* [] */0; - } - let r = f(param.hd); - return { - hd: r, - tl: map(f, param.tl) - }; -} - -function mapi(i, f, param) { - if (!param) { - return /* [] */0; - } - let r = f(i, param.hd); - return { - hd: r, - tl: mapi(i + 1 | 0, f, param.tl) - }; -} - -function mapi$1(f, l) { - return mapi(0, f, l); -} - -function rev_map(f, l) { - let _accu = /* [] */0; - let _param = l; - while (true) { - let param = _param; - let accu = _accu; - if (!param) { - return accu; - } - _param = param.tl; - _accu = { - hd: f(param.hd), - tl: accu - }; - continue; - }; -} - -function iter(f, _param) { - while (true) { - let param = _param; - if (!param) { - return; - } - f(param.hd); - _param = param.tl; - continue; - }; -} - -function iteri(f, l) { - let _i = 0; - let _param = l; - while (true) { - let param = _param; - let i = _i; - if (!param) { - return; - } - f(i, param.hd); - _param = param.tl; - _i = i + 1 | 0; - continue; - }; -} - -function fold_left(f, _accu, _l) { - while (true) { - let l = _l; - let accu = _accu; - if (!l) { - return accu; - } - _l = l.tl; - _accu = f(accu, l.hd); - continue; - }; -} - -function fold_right(f, l, accu) { - if (l) { - return f(l.hd, fold_right(f, l.tl, accu)); - } else { - return accu; - } -} - -function map2(f, l1, l2) { - if (l1) { - if (l2) { - let r = f(l1.hd, l2.hd); - return { - hd: r, - tl: map2(f, l1.tl, l2.tl) - }; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.map2", - Error: new Error() - }; - } - if (!l2) { - return /* [] */0; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.map2", - Error: new Error() - }; -} - -function rev_map2(f, l1, l2) { - let _accu = /* [] */0; - let _l1 = l1; - let _l2 = l2; - while (true) { - let l2$1 = _l2; - let l1$1 = _l1; - let accu = _accu; - if (l1$1) { - if (l2$1) { - _l2 = l2$1.tl; - _l1 = l1$1.tl; - _accu = { - hd: f(l1$1.hd, l2$1.hd), - tl: accu - }; - continue; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.rev_map2", - Error: new Error() - }; - } - if (l2$1) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.rev_map2", - Error: new Error() - }; - } - return accu; - }; -} - -function iter2(f, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (l1) { - if (l2) { - f(l1.hd, l2.hd); - _l2 = l2.tl; - _l1 = l1.tl; - continue; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.iter2", - Error: new Error() - }; - } - if (!l2) { - return; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.iter2", - Error: new Error() - }; - }; -} - -function fold_left2(f, _accu, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - let accu = _accu; - if (l1) { - if (l2) { - _l2 = l2.tl; - _l1 = l1.tl; - _accu = f(accu, l1.hd, l2.hd); - continue; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_left2", - Error: new Error() - }; - } - if (l2) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_left2", - Error: new Error() - }; - } - return accu; - }; -} - -function fold_right2(f, l1, l2, accu) { - if (l1) { - if (l2) { - return f(l1.hd, l2.hd, fold_right2(f, l1.tl, l2.tl, accu)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_right2", - Error: new Error() - }; - } - if (l2) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_right2", - Error: new Error() - }; - } - return accu; -} - -function for_all(p, _param) { - while (true) { - let param = _param; - if (!param) { - return true; - } - if (!p(param.hd)) { - return false; - } - _param = param.tl; - continue; - }; -} - -function exists(p, _param) { - while (true) { - let param = _param; - if (!param) { - return false; - } - if (p(param.hd)) { - return true; - } - _param = param.tl; - continue; - }; -} - -function for_all2(p, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (l1) { - if (l2) { - if (!p(l1.hd, l2.hd)) { - return false; - } - _l2 = l2.tl; - _l1 = l1.tl; - continue; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.for_all2", - Error: new Error() - }; - } - if (!l2) { - return true; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.for_all2", - Error: new Error() - }; - }; -} - -function exists2(p, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (l1) { - if (l2) { - if (p(l1.hd, l2.hd)) { - return true; - } - _l2 = l2.tl; - _l1 = l1.tl; - continue; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.exists2", - Error: new Error() - }; - } - if (!l2) { - return false; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.exists2", - Error: new Error() - }; - }; -} - -function mem(x, _set) { - while (true) { - let set = _set; - if (!set) { - return false; - } - if (Caml_obj.equal(set.hd, x)) { - return true; - } - _set = set.tl; - continue; - }; -} - -function memq(x, _set) { - while (true) { - let set = _set; - if (!set) { - return false; - } - if (set.hd === x) { - return true; - } - _set = set.tl; - continue; - }; -} - -function assoc(x, _param) { - while (true) { - let param = _param; - if (param) { - let match = param.hd; - if (Caml_obj.equal(match[0], x)) { - return match[1]; - } - _param = param.tl; - continue; - } - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - }; -} - -function assoc_opt(x, _param) { - while (true) { - let param = _param; - if (!param) { - return; - } - let match = param.hd; - if (Caml_obj.equal(match[0], x)) { - return Caml_option.some(match[1]); - } - _param = param.tl; - continue; - }; -} - -function assq(x, _param) { - while (true) { - let param = _param; - if (param) { - let match = param.hd; - if (match[0] === x) { - return match[1]; - } - _param = param.tl; - continue; - } - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - }; -} - -function assq_opt(x, _param) { - while (true) { - let param = _param; - if (!param) { - return; - } - let match = param.hd; - if (match[0] === x) { - return Caml_option.some(match[1]); - } - _param = param.tl; - continue; - }; -} - -function mem_assoc(x, _map) { - while (true) { - let map = _map; - if (!map) { - return false; - } - if (Caml_obj.equal(map.hd[0], x)) { - return true; - } - _map = map.tl; - continue; - }; -} - -function mem_assq(x, _map) { - while (true) { - let map = _map; - if (!map) { - return false; - } - if (map.hd[0] === x) { - return true; - } - _map = map.tl; - continue; - }; -} - -function remove_assoc(x, param) { - if (!param) { - return /* [] */0; - } - let l = param.tl; - let pair = param.hd; - if (Caml_obj.equal(pair[0], x)) { - return l; - } else { - return { - hd: pair, - tl: remove_assoc(x, l) - }; - } -} - -function remove_assq(x, param) { - if (!param) { - return /* [] */0; - } - let l = param.tl; - let pair = param.hd; - if (pair[0] === x) { - return l; - } else { - return { - hd: pair, - tl: remove_assq(x, l) - }; - } -} - -function find(p, _param) { - while (true) { - let param = _param; - if (param) { - let x = param.hd; - if (p(x)) { - return x; - } - _param = param.tl; - continue; - } - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - }; -} - -function find_opt(p, _param) { - while (true) { - let param = _param; - if (!param) { - return; - } - let x = param.hd; - if (p(x)) { - return Caml_option.some(x); - } - _param = param.tl; - continue; - }; -} - -function find_all(p, l) { - let _accu = /* [] */0; - let _param = l; - while (true) { - let param = _param; - let accu = _accu; - if (!param) { - return rev_append(accu, /* [] */0); - } - let l$1 = param.tl; - let x = param.hd; - if (p(x)) { - _param = l$1; - _accu = { - hd: x, - tl: accu - }; - continue; - } - _param = l$1; - continue; - }; -} - -function partition(p, l) { - let _yes = /* [] */0; - let _no = /* [] */0; - let _param = l; - while (true) { - let param = _param; - let no = _no; - let yes = _yes; - if (!param) { - return [ - rev_append(yes, /* [] */0), - rev_append(no, /* [] */0) - ]; - } - let l$1 = param.tl; - let x = param.hd; - if (p(x)) { - _param = l$1; - _yes = { - hd: x, - tl: yes - }; - continue; - } - _param = l$1; - _no = { - hd: x, - tl: no - }; - continue; - }; -} - -function split(param) { - if (!param) { - return [ - /* [] */0, - /* [] */0 - ]; - } - let match = param.hd; - let match$1 = split(param.tl); - return [ - { - hd: match[0], - tl: match$1[0] - }, - { - hd: match[1], - tl: match$1[1] - } - ]; -} - -function combine(l1, l2) { - if (l1) { - if (l2) { - return { - hd: [ - l1.hd, - l2.hd - ], - tl: combine(l1.tl, l2.tl) - }; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.combine", - Error: new Error() - }; - } - if (!l2) { - return /* [] */0; - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "List.combine", - Error: new Error() - }; -} - -function merge(cmp, l1, l2) { - if (!l1) { - return l2; - } - if (!l2) { - return l1; - } - let h2 = l2.hd; - let h1 = l1.hd; - if (cmp(h1, h2) <= 0) { - return { - hd: h1, - tl: merge(cmp, l1.tl, l2) - }; - } else { - return { - hd: h2, - tl: merge(cmp, l1, l2.tl) - }; - } -} - -function chop(_k, _l) { - while (true) { - let l = _l; - let k = _k; - if (k === 0) { - return l; - } - if (l) { - _l = l.tl; - _k = k - 1 | 0; - continue; - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "listLabels.res", - 420, - 11 - ], - Error: new Error() - }; - }; -} - -function stable_sort(cmp, l) { - let sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l) { - let match = l.tl; - if (match) { - let match$1 = match.tl; - if (match$1) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - if (cmp(x1, x2) <= 0) { - if (cmp(x2, x3) <= 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x1, x3) <= 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } else if (cmp(x1, x3) <= 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x2, x3) <= 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l) { - let match$2 = l.tl; - if (match$2) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - if (cmp(x1$1, x2$1) <= 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = rev_sort(n1, l); - let s2 = rev_sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (!l1) { - return rev_append(l2$1, accu); - } - if (!l2$1) { - return rev_append(l1, accu); - } - let h2 = l2$1.hd; - let h1 = l1.hd; - if (cmp(h1, h2) > 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = l1.tl; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = l2$1.tl; - continue; - }; - }; - let rev_sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l) { - let match = l.tl; - if (match) { - let match$1 = match.tl; - if (match$1) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - if (cmp(x1, x2) > 0) { - if (cmp(x2, x3) > 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x1, x3) > 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } else if (cmp(x1, x3) > 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x2, x3) > 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l) { - let match$2 = l.tl; - if (match$2) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - if (cmp(x1$1, x2$1) > 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = sort(n1, l); - let s2 = sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (!l1) { - return rev_append(l2$1, accu); - } - if (!l2$1) { - return rev_append(l1, accu); - } - let h2 = l2$1.hd; - let h1 = l1.hd; - if (cmp(h1, h2) <= 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = l1.tl; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = l2$1.tl; - continue; - }; - }; - let len = length(l); - if (len < 2) { - return l; - } else { - return sort(len, l); - } -} - -function sort_uniq(cmp, l) { - let sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l) { - let match = l.tl; - if (match) { - let match$1 = match.tl; - if (match$1) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - let c = cmp(x1, x2); - if (c === 0) { - let c$1 = cmp(x2, x3); - if (c$1 === 0) { - return { - hd: x2, - tl: /* [] */0 - }; - } else if (c$1 < 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - } - if (c < 0) { - let c$2 = cmp(x2, x3); - if (c$2 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - if (c$2 < 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$3 = cmp(x1, x3); - if (c$3 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } else if (c$3 < 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } - let c$4 = cmp(x1, x3); - if (c$4 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } - if (c$4 < 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$5 = cmp(x2, x3); - if (c$5 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } else if (c$5 < 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l) { - let match$2 = l.tl; - if (match$2) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - let c$6 = cmp(x1$1, x2$1); - if (c$6 === 0) { - return { - hd: x1$1, - tl: /* [] */0 - }; - } else if (c$6 < 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = rev_sort(n1, l); - let s2 = rev_sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (!l1) { - return rev_append(l2$1, accu); - } - if (!l2$1) { - return rev_append(l1, accu); - } - let t2 = l2$1.tl; - let h2 = l2$1.hd; - let t1 = l1.tl; - let h1 = l1.hd; - let c$7 = cmp(h1, h2); - if (c$7 === 0) { - _accu = { - hd: h1, - tl: accu - }; - _l2 = t2; - _l1 = t1; - continue; - } - if (c$7 > 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = t1; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = t2; - continue; - }; - }; - let rev_sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l) { - let match = l.tl; - if (match) { - let match$1 = match.tl; - if (match$1) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - let c = cmp(x1, x2); - if (c === 0) { - let c$1 = cmp(x2, x3); - if (c$1 === 0) { - return { - hd: x2, - tl: /* [] */0 - }; - } else if (c$1 > 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - } - if (c > 0) { - let c$2 = cmp(x2, x3); - if (c$2 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - if (c$2 > 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$3 = cmp(x1, x3); - if (c$3 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } else if (c$3 > 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } - let c$4 = cmp(x1, x3); - if (c$4 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } - if (c$4 > 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$5 = cmp(x2, x3); - if (c$5 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } else if (c$5 > 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l) { - let match$2 = l.tl; - if (match$2) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - let c$6 = cmp(x1$1, x2$1); - if (c$6 === 0) { - return { - hd: x1$1, - tl: /* [] */0 - }; - } else if (c$6 > 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = sort(n1, l); - let s2 = sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (!l1) { - return rev_append(l2$1, accu); - } - if (!l2$1) { - return rev_append(l1, accu); - } - let t2 = l2$1.tl; - let h2 = l2$1.hd; - let t1 = l1.tl; - let h1 = l1.hd; - let c$7 = cmp(h1, h2); - if (c$7 === 0) { - _accu = { - hd: h1, - tl: accu - }; - _l2 = t2; - _l1 = t1; - continue; - } - if (c$7 < 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = t1; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = t2; - continue; - }; - }; - let len = length(l); - if (len < 2) { - return l; - } else { - return sort(len, l); - } -} - -function compare_lengths(_l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (!l1) { - if (l2) { - return -1; - } else { - return 0; - } - } - if (!l2) { - return 1; - } - _l2 = l2.tl; - _l1 = l1.tl; - continue; - }; -} - -function compare_length_with(_l, _n) { - while (true) { - let n = _n; - let l = _l; - if (!l) { - if (n === 0) { - return 0; - } else if (n > 0) { - return -1; - } else { - return 1; - } - } - if (n <= 0) { - return 1; - } - _n = n - 1 | 0; - _l = l.tl; - continue; - }; -} - -let append = Pervasives.$at; - -let concat = flatten; - -let filter = find_all; - -let sort = stable_sort; - -let fast_sort = stable_sort; - -exports.length = length; -exports.hd = hd; -exports.compare_lengths = compare_lengths; -exports.compare_length_with = compare_length_with; -exports.cons = cons; -exports.tl = tl; -exports.nth = nth; -exports.nth_opt = nth_opt; -exports.rev = rev; -exports.init = init; -exports.append = append; -exports.rev_append = rev_append; -exports.concat = concat; -exports.flatten = flatten; -exports.iter = iter; -exports.iteri = iteri; -exports.map = map; -exports.mapi = mapi$1; -exports.rev_map = rev_map; -exports.fold_left = fold_left; -exports.fold_right = fold_right; -exports.iter2 = iter2; -exports.map2 = map2; -exports.rev_map2 = rev_map2; -exports.fold_left2 = fold_left2; -exports.fold_right2 = fold_right2; -exports.for_all = for_all; -exports.exists = exists; -exports.for_all2 = for_all2; -exports.exists2 = exists2; -exports.mem = mem; -exports.memq = memq; -exports.find = find; -exports.find_opt = find_opt; -exports.filter = filter; -exports.find_all = find_all; -exports.partition = partition; -exports.assoc = assoc; -exports.assoc_opt = assoc_opt; -exports.assq = assq; -exports.assq_opt = assq_opt; -exports.mem_assoc = mem_assoc; -exports.mem_assq = mem_assq; -exports.remove_assoc = remove_assoc; -exports.remove_assq = remove_assq; -exports.split = split; -exports.combine = combine; -exports.sort = sort; -exports.stable_sort = stable_sort; -exports.fast_sort = fast_sort; -exports.sort_uniq = sort_uniq; -exports.merge = merge; -/* No side effect */ diff --git a/lib/js/map.js b/lib/js/map.js index 33fa37ef6e..ae1b9f17e6 100644 --- a/lib/js/map.js +++ b/lib/js/map.js @@ -1,944 +1 @@ -'use strict'; - -let Caml_option = require("./caml_option.js"); - -function Make(funarg) { - let height = param => { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } - }; - let create = (l, x, d, r) => { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - }; - let singleton = (x, d) => ({ - TAG: "Node", - l: "Empty", - v: x, - d: d, - r: "Empty", - h: 1 - }); - let bal = (l, x, d, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - }; - let is_empty = param => { - if (typeof param !== "object") { - return true; - } else { - return false; - } - }; - let add = (x, data, param) => { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let find = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let c = funarg.compare(x, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let find_first = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; - }; - let find_first_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; - }; - let find_last = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; - }; - let find_last_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _d0 = param.d; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let d0 = _d0; - let v0 = _v0; - if (typeof param$1 !== "object") { - return [ - v0, - d0 - ]; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _d0 = param$1.d; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; - }; - let find_opt = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let c = funarg.compare(x, param.v); - if (c === 0) { - return Caml_option.some(param.d); - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let mem = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = funarg.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let min_binding = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; - }; - let min_binding_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; - }; - let max_binding = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; - }; - let max_binding_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; - }; - let remove_min_binding = param => { - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.remove_min_elt", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_binding(l), param.v, param.d, param.r); - } - }; - let merge = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return bal(t1, match[0], match[1], remove_min_binding(t2)); - }; - let remove = (x, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - return merge(l, r); - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let update = (x, f, param) => { - if (typeof param !== "object") { - let data = f(undefined); - if (data !== undefined) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: Caml_option.valFromOption(data), - r: "Empty", - h: 1 - }; - } else { - return "Empty"; - } - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - let data$1 = f(Caml_option.some(d)); - if (data$1 === undefined) { - return merge(l, r); - } - let data$2 = Caml_option.valFromOption(data$1); - if (d === data$2) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data$2, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = update(x, f, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = update(x, f, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let iter = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v, param.d); - _param = param.r; - continue; - }; - }; - let map = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let l$p = map(f, param.l); - let d$p = f(param.d); - let r$p = map(f, param.r); - return { - TAG: "Node", - l: l$p, - v: param.v, - d: d$p, - r: r$p, - h: param.h - }; - }; - let mapi = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let v = param.v; - let l$p = mapi(f, param.l); - let d$p = f(v, param.d); - let r$p = mapi(f, param.r); - return { - TAG: "Node", - l: l$p, - v: v, - d: d$p, - r: r$p, - h: param.h - }; - }; - let fold = (f, _m, _accu) => { - while (true) { - let accu = _accu; - let m = _m; - if (typeof m !== "object") { - return accu; - } - _accu = f(m.v, m.d, fold(f, m.l, accu)); - _m = m.r; - continue; - }; - }; - let for_all = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v, param.d)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; - }; - let exists = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v, param.d)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; - }; - let add_min_binding = (k, x, param) => { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(add_min_binding(k, x, param.l), param.v, param.d, param.r); - } - }; - let add_max_binding = (k, x, param) => { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(param.l, param.v, param.d, add_max_binding(k, x, param.r)); - } - }; - let join = (l, v, d, r) => { - if (typeof l !== "object") { - return add_min_binding(v, d, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_binding(v, d, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, l.d, join(l.r, v, d, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, d, r.l), r.v, r.d, r.r); - } else { - return create(l, v, d, r); - } - }; - let concat = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return join(t1, match[0], match[1], remove_min_binding(t2)); - }; - let concat_or_join = (t1, v, d, t2) => { - if (d !== undefined) { - return join(t1, v, Caml_option.valFromOption(d), t2); - } else { - return concat(t1, t2); - } - }; - let split = (x, param) => { - if (typeof param !== "object") { - return [ - "Empty", - undefined, - "Empty" - ]; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - return [ - l, - Caml_option.some(d), - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, d, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, d, match$1[0]), - match$1[1], - match$1[2] - ]; - }; - let merge$1 = (f, s1, s2) => { - if (typeof s1 !== "object") { - if (typeof s2 !== "object") { - return "Empty"; - } - - } else { - let v1 = s1.v; - if (s1.h >= height(s2)) { - let match = split(v1, s2); - return concat_or_join(merge$1(f, s1.l, match[0]), v1, f(v1, Caml_option.some(s1.d), match[1]), merge$1(f, s1.r, match[2])); - } - - } - if (typeof s2 !== "object") { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "map.res", - 552, - 11 - ], - Error: new Error() - }; - } - let v2 = s2.v; - let match$1 = split(v2, s1); - return concat_or_join(merge$1(f, match$1[0], s2.l), v2, f(v2, match$1[1], Caml_option.some(s2.d)), merge$1(f, match$1[2], s2.r)); - }; - let union = (f, s1, s2) => { - if (typeof s1 !== "object") { - return s2; - } - let d1 = s1.d; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let d2 = s2.d; - let v2 = s2.v; - if (s1.h >= s2.h) { - let match = split(v1, s2); - let d2$1 = match[1]; - let l = union(f, s1.l, match[0]); - let r = union(f, s1.r, match[2]); - if (d2$1 !== undefined) { - return concat_or_join(l, v1, f(v1, d1, Caml_option.valFromOption(d2$1)), r); - } else { - return join(l, v1, d1, r); - } - } - let match$1 = split(v2, s1); - let d1$1 = match$1[1]; - let l$1 = union(f, match$1[0], s2.l); - let r$1 = union(f, match$1[2], s2.r); - if (d1$1 !== undefined) { - return concat_or_join(l$1, v2, f(v2, Caml_option.valFromOption(d1$1), d2), r$1); - } else { - return join(l$1, v2, d2, r$1); - } - }; - let filter = (p, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pvd = p(v, d); - let r$p = filter(p, r); - if (pvd) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, d, r$p); - } - } else { - return concat(l$p, r$p); - } - }; - let partition = (p, param) => { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let d = param.d; - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pvd = p(v, d); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pvd) { - return [ - join(lt, v, d, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, d, rf) - ]; - } - }; - let cons_enum = (_m, _e) => { - while (true) { - let e = _e; - let m = _m; - if (typeof m !== "object") { - return e; - } - _e = { - TAG: "More", - _0: m.v, - _1: m.d, - _2: m.r, - _3: e - }; - _m = m.l; - continue; - }; - }; - let compare = (cmp, m1, m2) => { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = funarg.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - let c$1 = cmp(e1._1, e2._1); - if (c$1 !== 0) { - return c$1; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; - }; - let equal = (cmp, m1, m2) => { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return true; - } else { - return false; - } - } - if (typeof e2 !== "object") { - return false; - } - if (funarg.compare(e1._0, e2._0) !== 0) { - return false; - } - if (!cmp(e1._1, e2._1)) { - return false; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; - }; - let cardinal = param => { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } - }; - let bindings_aux = (_accu, _param) => { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: [ - param.v, - param.d - ], - tl: bindings_aux(accu, param.r) - }; - continue; - }; - }; - let bindings = s => bindings_aux(/* [] */0, s); - return { - empty: "Empty", - is_empty: is_empty, - mem: mem, - add: add, - update: update, - singleton: singleton, - remove: remove, - merge: merge$1, - union: union, - compare: compare, - equal: equal, - iter: iter, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - bindings: bindings, - min_binding: min_binding, - min_binding_opt: min_binding_opt, - max_binding: max_binding, - max_binding_opt: max_binding_opt, - choose: min_binding, - choose_opt: min_binding_opt, - split: split, - find: find, - find_opt: find_opt, - find_first: find_first, - find_first_opt: find_first_opt, - find_last: find_last, - find_last_opt: find_last_opt, - map: map, - mapi: mapi - }; -} - -exports.Make = Make; -/* No side effect */ +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/lib/js/mapLabels.js b/lib/js/mapLabels.js deleted file mode 100644 index 8b5b3c56fd..0000000000 --- a/lib/js/mapLabels.js +++ /dev/null @@ -1,959 +0,0 @@ -'use strict'; - -let Caml_option = require("./caml_option.js"); - -function Make(Ord) { - let height = param => { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } - }; - let create = (l, x, d, r) => { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - }; - let singleton = (x, d) => ({ - TAG: "Node", - l: "Empty", - v: x, - d: d, - r: "Empty", - h: 1 - }); - let bal = (l, x, d, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - }; - let is_empty = param => { - if (typeof param !== "object") { - return true; - } else { - return false; - } - }; - let add = (x, data, param) => { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let find = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let c = Ord.compare(x, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let find_first_aux = (_v0, _d0, f, _param) => { - while (true) { - let param = _param; - let d0 = _d0; - let v0 = _v0; - if (typeof param !== "object") { - return [ - v0, - d0 - ]; - } - let v = param.v; - if (f(v)) { - _param = param.l; - _d0 = param.d; - _v0 = v; - continue; - } - _param = param.r; - continue; - }; - }; - let find_first = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - return find_first_aux(v, param.d, f, param.l); - } - _param = param.r; - continue; - }; - }; - let find_first_opt_aux = (_v0, _d0, f, _param) => { - while (true) { - let param = _param; - let d0 = _d0; - let v0 = _v0; - if (typeof param !== "object") { - return [ - v0, - d0 - ]; - } - let v = param.v; - if (f(v)) { - _param = param.l; - _d0 = param.d; - _v0 = v; - continue; - } - _param = param.r; - continue; - }; - }; - let find_first_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - return find_first_opt_aux(v, param.d, f, param.l); - } - _param = param.r; - continue; - }; - }; - let find_last_aux = (_v0, _d0, f, _param) => { - while (true) { - let param = _param; - let d0 = _d0; - let v0 = _v0; - if (typeof param !== "object") { - return [ - v0, - d0 - ]; - } - let v = param.v; - if (f(v)) { - _param = param.r; - _d0 = param.d; - _v0 = v; - continue; - } - _param = param.l; - continue; - }; - }; - let find_last = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - return find_last_aux(v, param.d, f, param.r); - } - _param = param.l; - continue; - }; - }; - let find_last_opt_aux = (_v0, _d0, f, _param) => { - while (true) { - let param = _param; - let d0 = _d0; - let v0 = _v0; - if (typeof param !== "object") { - return [ - v0, - d0 - ]; - } - let v = param.v; - if (f(v)) { - _param = param.r; - _d0 = param.d; - _v0 = v; - continue; - } - _param = param.l; - continue; - }; - }; - let find_last_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - return find_last_opt_aux(v, param.d, f, param.r); - } - _param = param.l; - continue; - }; - }; - let find_opt = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let c = Ord.compare(x, param.v); - if (c === 0) { - return Caml_option.some(param.d); - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let mem = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = Ord.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let min_binding = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; - }; - let min_binding_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; - }; - let max_binding = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; - }; - let max_binding_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; - }; - let remove_min_binding = param => { - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.remove_min_elt", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_binding(l), param.v, param.d, param.r); - } - }; - let merge = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return bal(t1, match[0], match[1], remove_min_binding(t2)); - }; - let remove = (x, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - return merge(l, r); - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let update = (x, f, param) => { - if (typeof param !== "object") { - let data = f(undefined); - if (data !== undefined) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: Caml_option.valFromOption(data), - r: "Empty", - h: 1 - }; - } else { - return "Empty"; - } - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - let data$1 = f(Caml_option.some(d)); - if (data$1 === undefined) { - return merge(l, r); - } - let data$2 = Caml_option.valFromOption(data$1); - if (d === data$2) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data$2, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = update(x, f, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = update(x, f, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let iter = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v, param.d); - _param = param.r; - continue; - }; - }; - let map = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let l$p = map(f, param.l); - let d$p = f(param.d); - let r$p = map(f, param.r); - return { - TAG: "Node", - l: l$p, - v: param.v, - d: d$p, - r: r$p, - h: param.h - }; - }; - let mapi = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let v = param.v; - let l$p = mapi(f, param.l); - let d$p = f(v, param.d); - let r$p = mapi(f, param.r); - return { - TAG: "Node", - l: l$p, - v: v, - d: d$p, - r: r$p, - h: param.h - }; - }; - let fold = (f, _m, _accu) => { - while (true) { - let accu = _accu; - let m = _m; - if (typeof m !== "object") { - return accu; - } - _accu = f(m.v, m.d, fold(f, m.l, accu)); - _m = m.r; - continue; - }; - }; - let for_all = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v, param.d)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; - }; - let exists = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v, param.d)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; - }; - let add_min_binding = (k, x, param) => { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(add_min_binding(k, x, param.l), param.v, param.d, param.r); - } - }; - let add_max_binding = (k, x, param) => { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(param.l, param.v, param.d, add_max_binding(k, x, param.r)); - } - }; - let join = (l, v, d, r) => { - if (typeof l !== "object") { - return add_min_binding(v, d, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_binding(v, d, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, l.d, join(l.r, v, d, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, d, r.l), r.v, r.d, r.r); - } else { - return create(l, v, d, r); - } - }; - let concat = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return join(t1, match[0], match[1], remove_min_binding(t2)); - }; - let concat_or_join = (t1, v, d, t2) => { - if (d !== undefined) { - return join(t1, v, Caml_option.valFromOption(d), t2); - } else { - return concat(t1, t2); - } - }; - let split = (x, param) => { - if (typeof param !== "object") { - return [ - "Empty", - undefined, - "Empty" - ]; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - return [ - l, - Caml_option.some(d), - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, d, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, d, match$1[0]), - match$1[1], - match$1[2] - ]; - }; - let merge$1 = (f, s1, s2) => { - if (typeof s1 !== "object") { - if (typeof s2 !== "object") { - return "Empty"; - } - - } else { - let v1 = s1.v; - if (s1.h >= height(s2)) { - let match = split(v1, s2); - return concat_or_join(merge$1(f, s1.l, match[0]), v1, f(v1, Caml_option.some(s1.d), match[1]), merge$1(f, s1.r, match[2])); - } - - } - if (typeof s2 !== "object") { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "mapLabels.res", - 552, - 11 - ], - Error: new Error() - }; - } - let v2 = s2.v; - let match$1 = split(v2, s1); - return concat_or_join(merge$1(f, match$1[0], s2.l), v2, f(v2, match$1[1], Caml_option.some(s2.d)), merge$1(f, match$1[2], s2.r)); - }; - let union = (f, s1, s2) => { - if (typeof s1 !== "object") { - return s2; - } - let d1 = s1.d; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let d2 = s2.d; - let v2 = s2.v; - if (s1.h >= s2.h) { - let match = split(v1, s2); - let d2$1 = match[1]; - let l = union(f, s1.l, match[0]); - let r = union(f, s1.r, match[2]); - if (d2$1 !== undefined) { - return concat_or_join(l, v1, f(v1, d1, Caml_option.valFromOption(d2$1)), r); - } else { - return join(l, v1, d1, r); - } - } - let match$1 = split(v2, s1); - let d1$1 = match$1[1]; - let l$1 = union(f, match$1[0], s2.l); - let r$1 = union(f, match$1[2], s2.r); - if (d1$1 !== undefined) { - return concat_or_join(l$1, v2, f(v2, Caml_option.valFromOption(d1$1), d2), r$1); - } else { - return join(l$1, v2, d2, r$1); - } - }; - let filter = (p, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pvd = p(v, d); - let r$p = filter(p, r); - if (pvd) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, d, r$p); - } - } else { - return concat(l$p, r$p); - } - }; - let partition = (p, param) => { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let d = param.d; - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pvd = p(v, d); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pvd) { - return [ - join(lt, v, d, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, d, rf) - ]; - } - }; - let cons_enum = (_m, _e) => { - while (true) { - let e = _e; - let m = _m; - if (typeof m !== "object") { - return e; - } - _e = { - TAG: "More", - _0: m.v, - _1: m.d, - _2: m.r, - _3: e - }; - _m = m.l; - continue; - }; - }; - let compare = (cmp, m1, m2) => { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = Ord.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - let c$1 = cmp(e1._1, e2._1); - if (c$1 !== 0) { - return c$1; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; - }; - let equal = (cmp, m1, m2) => { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return true; - } else { - return false; - } - } - if (typeof e2 !== "object") { - return false; - } - if (Ord.compare(e1._0, e2._0) !== 0) { - return false; - } - if (!cmp(e1._1, e2._1)) { - return false; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; - }; - let cardinal = param => { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } - }; - let bindings_aux = (_accu, _param) => { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: [ - param.v, - param.d - ], - tl: bindings_aux(accu, param.r) - }; - continue; - }; - }; - let bindings = s => bindings_aux(/* [] */0, s); - return { - height: height, - create: create, - singleton: singleton, - bal: bal, - empty: "Empty", - is_empty: is_empty, - add: add, - find: find, - find_first_aux: find_first_aux, - find_first: find_first, - find_first_opt_aux: find_first_opt_aux, - find_first_opt: find_first_opt, - find_last_aux: find_last_aux, - find_last: find_last, - find_last_opt_aux: find_last_opt_aux, - find_last_opt: find_last_opt, - find_opt: find_opt, - mem: mem, - min_binding: min_binding, - min_binding_opt: min_binding_opt, - max_binding: max_binding, - max_binding_opt: max_binding_opt, - remove_min_binding: remove_min_binding, - remove: remove, - update: update, - iter: iter, - map: map, - mapi: mapi, - fold: fold, - for_all: for_all, - exists: exists, - add_min_binding: add_min_binding, - add_max_binding: add_max_binding, - join: join, - concat: concat, - concat_or_join: concat_or_join, - split: split, - merge: merge$1, - union: union, - filter: filter, - partition: partition, - cons_enum: cons_enum, - compare: compare, - equal: equal, - cardinal: cardinal, - bindings_aux: bindings_aux, - bindings: bindings, - choose: min_binding, - choose_opt: min_binding_opt - }; -} - -exports.Make = Make; -/* No side effect */ diff --git a/lib/js/moreLabels.js b/lib/js/moreLabels.js deleted file mode 100644 index 1afa76adb7..0000000000 --- a/lib/js/moreLabels.js +++ /dev/null @@ -1,1942 +0,0 @@ -'use strict'; - -let List = require("./list.js"); -let Caml_option = require("./caml_option.js"); -let HashtblLabels = require("./hashtblLabels.js"); - -let Hashtbl = { - create: HashtblLabels.create, - clear: HashtblLabels.clear, - reset: HashtblLabels.reset, - copy: HashtblLabels.copy, - add: HashtblLabels.add, - find: HashtblLabels.find, - find_opt: HashtblLabels.find_opt, - find_all: HashtblLabels.find_all, - mem: HashtblLabels.mem, - remove: HashtblLabels.remove, - replace: HashtblLabels.replace, - iter: HashtblLabels.iter, - filter_map_inplace: HashtblLabels.filter_map_inplace, - fold: HashtblLabels.fold, - length: HashtblLabels.length, - randomize: HashtblLabels.randomize, - is_randomized: HashtblLabels.is_randomized, - stats: HashtblLabels.stats, - Make: HashtblLabels.Make, - MakeSeeded: HashtblLabels.MakeSeeded, - hash: HashtblLabels.hash, - seeded_hash: HashtblLabels.seeded_hash, - hash_param: HashtblLabels.hash_param, - seeded_hash_param: HashtblLabels.seeded_hash_param -}; - -let $$Map = { - Make: funarg => { - let height = param => { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } - }; - let create = (l, x, d, r) => { - let hl = height(l); - let hr = height(r); - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - }; - let singleton = (x, d) => ({ - TAG: "Node", - l: "Empty", - v: x, - d: d, - r: "Empty", - h: 1 - }); - let bal = (l, x, d, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let lr = l.r; - let ld = l.d; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, ld, create(lr, x, d, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, ld, lr.l), lr.v, lr.d, create(lr.r, x, d, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: x, - d: d, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - } - let rr = r.r; - let rd = r.d; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, x, d, rl), rv, rd, rr); - } - if (typeof rl === "object") { - return create(create(l, x, d, rl.l), rl.v, rl.d, create(rl.r, rv, rd, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.bal", - Error: new Error() - }; - }; - let is_empty = param => { - if (typeof param !== "object") { - return true; - } else { - return false; - } - }; - let add = (x, data, param) => { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - d: data, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - if (d === data) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = add(x, data, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = add(x, data, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let find = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let c = funarg.compare(x, param.v); - if (c === 0) { - return param.d; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let find_first_aux = (_v0, _d0, f, _param) => { - while (true) { - let param = _param; - let d0 = _d0; - let v0 = _v0; - if (typeof param !== "object") { - return [ - v0, - d0 - ]; - } - let v = param.v; - if (f(v)) { - _param = param.l; - _d0 = param.d; - _v0 = v; - continue; - } - _param = param.r; - continue; - }; - }; - let find_first = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - return find_first_aux(v, param.d, f, param.l); - } - _param = param.r; - continue; - }; - }; - let find_first_opt_aux = (_v0, _d0, f, _param) => { - while (true) { - let param = _param; - let d0 = _d0; - let v0 = _v0; - if (typeof param !== "object") { - return [ - v0, - d0 - ]; - } - let v = param.v; - if (f(v)) { - _param = param.l; - _d0 = param.d; - _v0 = v; - continue; - } - _param = param.r; - continue; - }; - }; - let find_first_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - return find_first_opt_aux(v, param.d, f, param.l); - } - _param = param.r; - continue; - }; - }; - let find_last_aux = (_v0, _d0, f, _param) => { - while (true) { - let param = _param; - let d0 = _d0; - let v0 = _v0; - if (typeof param !== "object") { - return [ - v0, - d0 - ]; - } - let v = param.v; - if (f(v)) { - _param = param.r; - _d0 = param.d; - _v0 = v; - continue; - } - _param = param.l; - continue; - }; - }; - let find_last = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - return find_last_aux(v, param.d, f, param.r); - } - _param = param.l; - continue; - }; - }; - let find_last_opt_aux = (_v0, _d0, f, _param) => { - while (true) { - let param = _param; - let d0 = _d0; - let v0 = _v0; - if (typeof param !== "object") { - return [ - v0, - d0 - ]; - } - let v = param.v; - if (f(v)) { - _param = param.r; - _d0 = param.d; - _v0 = v; - continue; - } - _param = param.l; - continue; - }; - }; - let find_last_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - return find_last_opt_aux(v, param.d, f, param.r); - } - _param = param.l; - continue; - }; - }; - let find_opt = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let c = funarg.compare(x, param.v); - if (c === 0) { - return Caml_option.some(param.d); - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let mem = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = funarg.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let min_binding = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; - }; - let min_binding_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return [ - param.v, - param.d - ]; - } - _param = l; - continue; - }; - }; - let max_binding = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; - }; - let max_binding_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return [ - param.v, - param.d - ]; - } - _param = r; - continue; - }; - }; - let remove_min_binding = param => { - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Map.remove_min_elt", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_binding(l), param.v, param.d, param.r); - } - }; - let merge = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return bal(t1, match[0], match[1], remove_min_binding(t2)); - }; - let remove = (x, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - return merge(l, r); - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let update = (x, f, param) => { - if (typeof param !== "object") { - let data = f(undefined); - if (data !== undefined) { - return { - TAG: "Node", - l: "Empty", - v: x, - d: Caml_option.valFromOption(data), - r: "Empty", - h: 1 - }; - } else { - return "Empty"; - } - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - let data$1 = f(Caml_option.some(d)); - if (data$1 === undefined) { - return merge(l, r); - } - let data$2 = Caml_option.valFromOption(data$1); - if (d === data$2) { - return param; - } else { - return { - TAG: "Node", - l: l, - v: x, - d: data$2, - r: r, - h: param.h - }; - } - } - if (c < 0) { - let ll = update(x, f, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, d, r); - } - } - let rr = update(x, f, r); - if (r === rr) { - return param; - } else { - return bal(l, v, d, rr); - } - }; - let iter = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v, param.d); - _param = param.r; - continue; - }; - }; - let map = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let l$p = map(f, param.l); - let d$p = f(param.d); - let r$p = map(f, param.r); - return { - TAG: "Node", - l: l$p, - v: param.v, - d: d$p, - r: r$p, - h: param.h - }; - }; - let mapi = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let v = param.v; - let l$p = mapi(f, param.l); - let d$p = f(v, param.d); - let r$p = mapi(f, param.r); - return { - TAG: "Node", - l: l$p, - v: v, - d: d$p, - r: r$p, - h: param.h - }; - }; - let fold = (f, _m, _accu) => { - while (true) { - let accu = _accu; - let m = _m; - if (typeof m !== "object") { - return accu; - } - _accu = f(m.v, m.d, fold(f, m.l, accu)); - _m = m.r; - continue; - }; - }; - let for_all = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v, param.d)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; - }; - let exists = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v, param.d)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; - }; - let add_min_binding = (k, x, param) => { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(add_min_binding(k, x, param.l), param.v, param.d, param.r); - } - }; - let add_max_binding = (k, x, param) => { - if (typeof param !== "object") { - return singleton(k, x); - } else { - return bal(param.l, param.v, param.d, add_max_binding(k, x, param.r)); - } - }; - let join = (l, v, d, r) => { - if (typeof l !== "object") { - return add_min_binding(v, d, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_binding(v, d, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, l.d, join(l.r, v, d, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, d, r.l), r.v, r.d, r.r); - } else { - return create(l, v, d, r); - } - }; - let concat = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } - if (typeof t2 !== "object") { - return t1; - } - let match = min_binding(t2); - return join(t1, match[0], match[1], remove_min_binding(t2)); - }; - let concat_or_join = (t1, v, d, t2) => { - if (d !== undefined) { - return join(t1, v, Caml_option.valFromOption(d), t2); - } else { - return concat(t1, t2); - } - }; - let split = (x, param) => { - if (typeof param !== "object") { - return [ - "Empty", - undefined, - "Empty" - ]; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - return [ - l, - Caml_option.some(d), - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, d, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, d, match$1[0]), - match$1[1], - match$1[2] - ]; - }; - let merge$1 = (f, s1, s2) => { - if (typeof s1 !== "object") { - if (typeof s2 !== "object") { - return "Empty"; - } - - } else { - let v1 = s1.v; - if (s1.h >= height(s2)) { - let match = split(v1, s2); - return concat_or_join(merge$1(f, s1.l, match[0]), v1, f(v1, Caml_option.some(s1.d), match[1]), merge$1(f, s1.r, match[2])); - } - - } - if (typeof s2 !== "object") { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "mapLabels.res", - 552, - 11 - ], - Error: new Error() - }; - } - let v2 = s2.v; - let match$1 = split(v2, s1); - return concat_or_join(merge$1(f, match$1[0], s2.l), v2, f(v2, match$1[1], Caml_option.some(s2.d)), merge$1(f, match$1[2], s2.r)); - }; - let union = (f, s1, s2) => { - if (typeof s1 !== "object") { - return s2; - } - let d1 = s1.d; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let d2 = s2.d; - let v2 = s2.v; - if (s1.h >= s2.h) { - let match = split(v1, s2); - let d2$1 = match[1]; - let l = union(f, s1.l, match[0]); - let r = union(f, s1.r, match[2]); - if (d2$1 !== undefined) { - return concat_or_join(l, v1, f(v1, d1, Caml_option.valFromOption(d2$1)), r); - } else { - return join(l, v1, d1, r); - } - } - let match$1 = split(v2, s1); - let d1$1 = match$1[1]; - let l$1 = union(f, match$1[0], s2.l); - let r$1 = union(f, match$1[2], s2.r); - if (d1$1 !== undefined) { - return concat_or_join(l$1, v2, f(v2, Caml_option.valFromOption(d1$1), d2), r$1); - } else { - return join(l$1, v2, d2, r$1); - } - }; - let filter = (p, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let d = param.d; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pvd = p(v, d); - let r$p = filter(p, r); - if (pvd) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, d, r$p); - } - } else { - return concat(l$p, r$p); - } - }; - let partition = (p, param) => { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let d = param.d; - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pvd = p(v, d); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pvd) { - return [ - join(lt, v, d, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, d, rf) - ]; - } - }; - let cons_enum = (_m, _e) => { - while (true) { - let e = _e; - let m = _m; - if (typeof m !== "object") { - return e; - } - _e = { - TAG: "More", - _0: m.v, - _1: m.d, - _2: m.r, - _3: e - }; - _m = m.l; - continue; - }; - }; - let compare = (cmp, m1, m2) => { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = funarg.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - let c$1 = cmp(e1._1, e2._1); - if (c$1 !== 0) { - return c$1; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; - }; - let equal = (cmp, m1, m2) => { - let _e1 = cons_enum(m1, "End"); - let _e2 = cons_enum(m2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return true; - } else { - return false; - } - } - if (typeof e2 !== "object") { - return false; - } - if (funarg.compare(e1._0, e2._0) !== 0) { - return false; - } - if (!cmp(e1._1, e2._1)) { - return false; - } - _e2 = cons_enum(e2._2, e2._3); - _e1 = cons_enum(e1._2, e1._3); - continue; - }; - }; - let cardinal = param => { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } - }; - let bindings_aux = (_accu, _param) => { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: [ - param.v, - param.d - ], - tl: bindings_aux(accu, param.r) - }; - continue; - }; - }; - let bindings = s => bindings_aux(/* [] */0, s); - return { - empty: "Empty", - is_empty: is_empty, - mem: mem, - add: add, - update: update, - singleton: singleton, - remove: remove, - merge: merge$1, - union: union, - compare: compare, - equal: equal, - iter: iter, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - bindings: bindings, - min_binding: min_binding, - min_binding_opt: min_binding_opt, - max_binding: max_binding, - max_binding_opt: max_binding_opt, - choose: min_binding, - choose_opt: min_binding_opt, - split: split, - find: find, - find_opt: find_opt, - find_first: find_first, - find_first_opt: find_first_opt, - find_last: find_last, - find_last_opt: find_last_opt, - map: map, - mapi: mapi - }; - } -}; - -let $$Set = { - Make: funarg => { - let height = param => { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } - }; - let create = (l, v, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - }; - let bal = (l, v, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - let lr = l.r; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, create(lr, v, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, lr.l), lr.v, create(lr.r, v, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - let rr = r.r; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, v, rl), rv, rr); - } - if (typeof rl === "object") { - return create(create(l, v, rl.l), rl.v, create(rl.r, rv, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - }; - let add = (x, param) => { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - return param; - } - if (c < 0) { - let ll = add(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = add(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } - }; - let singleton = x => ({ - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }); - let add_min_element = (x, param) => { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(add_min_element(x, param.l), param.v, param.r); - } - }; - let add_max_element = (x, param) => { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(param.l, param.v, add_max_element(x, param.r)); - } - }; - let join = (l, v, r) => { - if (typeof l !== "object") { - return add_min_element(v, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_element(v, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, join(l.r, v, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, r.l), r.v, r.r); - } else { - return create(l, v, r); - } - }; - let min_elt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.v; - } - _param = l; - continue; - }; - }; - let min_elt_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return Caml_option.some(param.v); - } - _param = l; - continue; - }; - }; - let max_elt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let r = param.r; - if (typeof r !== "object") { - return param.v; - } - _param = r; - continue; - }; - }; - let max_elt_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return Caml_option.some(param.v); - } - _param = r; - continue; - }; - }; - let remove_min_elt = param => { - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.remove_min_elt", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_elt(l), param.v, param.r); - } - }; - let merge = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } else if (typeof t2 !== "object") { - return t1; - } else { - return bal(t1, min_elt(t2), remove_min_elt(t2)); - } - }; - let concat = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } else if (typeof t2 !== "object") { - return t1; - } else { - return join(t1, min_elt(t2), remove_min_elt(t2)); - } - }; - let split = (x, param) => { - if (typeof param !== "object") { - return [ - "Empty", - false, - "Empty" - ]; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - return [ - l, - true, - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, match$1[0]), - match$1[1], - match$1[2] - ]; - }; - let is_empty = param => { - if (typeof param !== "object") { - return true; - } else { - return false; - } - }; - let mem = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = funarg.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let remove = (x, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - return merge(l, r); - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } - }; - let union = (s1, s2) => { - if (typeof s1 !== "object") { - return s2; - } - let h1 = s1.h; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let h2 = s2.h; - let v2 = s2.v; - if (h1 >= h2) { - if (h2 === 1) { - return add(v2, s1); - } - let match = split(v1, s2); - return join(union(s1.l, match[0]), v1, union(s1.r, match[2])); - } - if (h1 === 1) { - return add(v1, s2); - } - let match$1 = split(v2, s1); - return join(union(match$1[0], s2.l), v2, union(match$1[2], s2.r)); - }; - let inter = (s1, s2) => { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return "Empty"; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return join(inter(l1, l2), v1, inter(r1, match[2])); - } else { - return concat(inter(l1, l2), inter(r1, match[2])); - } - }; - let diff = (s1, s2) => { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return s1; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return concat(diff(l1, l2), diff(r1, match[2])); - } else { - return join(diff(l1, l2), v1, diff(r1, match[2])); - } - }; - let cons_enum = (_s, _e) => { - while (true) { - let e = _e; - let s = _s; - if (typeof s !== "object") { - return e; - } - _e = { - TAG: "More", - _0: s.v, - _1: s.r, - _2: e - }; - _s = s.l; - continue; - }; - }; - let compare_aux = (_e1, _e2) => { - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = funarg.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - _e2 = cons_enum(e2._1, e2._2); - _e1 = cons_enum(e1._1, e1._2); - continue; - }; - }; - let compare = (s1, s2) => compare_aux(cons_enum(s1, "End"), cons_enum(s2, "End")); - let equal = (s1, s2) => compare(s1, s2) === 0; - let subset = (_s1, _s2) => { - while (true) { - let s2 = _s2; - let s1 = _s1; - if (typeof s1 !== "object") { - return true; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - if (typeof s2 !== "object") { - return false; - } - let r2 = s2.r; - let l2 = s2.l; - let c = funarg.compare(v1, s2.v); - if (c === 0) { - if (!subset(l1, l2)) { - return false; - } - _s2 = r2; - _s1 = r1; - continue; - } - if (c < 0) { - if (!subset({ - TAG: "Node", - l: l1, - v: v1, - r: "Empty", - h: 0 - }, l2)) { - return false; - } - _s1 = r1; - continue; - } - if (!subset({ - TAG: "Node", - l: "Empty", - v: v1, - r: r1, - h: 0 - }, r2)) { - return false; - } - _s1 = l1; - continue; - }; - }; - let iter = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v); - _param = param.r; - continue; - }; - }; - let fold = (f, _s, _accu) => { - while (true) { - let accu = _accu; - let s = _s; - if (typeof s !== "object") { - return accu; - } - _accu = f(s.v, fold(f, s.l, accu)); - _s = s.r; - continue; - }; - }; - let for_all = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; - }; - let exists = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; - }; - let filter = (p, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pv = p(v); - let r$p = filter(p, r); - if (pv) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, r$p); - } - } else { - return concat(l$p, r$p); - } - }; - let partition = (p, param) => { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pv = p(v); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pv) { - return [ - join(lt, v, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, rf) - ]; - } - }; - let cardinal = param => { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } - }; - let elements_aux = (_accu, _param) => { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: param.v, - tl: elements_aux(accu, param.r) - }; - continue; - }; - }; - let elements = s => elements_aux(/* [] */0, s); - let find = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - let c = funarg.compare(x, v); - if (c === 0) { - return v; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let find_first_aux = (_v0, f, _param) => { - while (true) { - let param = _param; - let v0 = _v0; - if (typeof param !== "object") { - return v0; - } - let v = param.v; - if (f(v)) { - _param = param.l; - _v0 = v; - continue; - } - _param = param.r; - continue; - }; - }; - let find_first = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - return find_first_aux(v, f, param.l); - } - _param = param.r; - continue; - }; - }; - let find_first_opt_aux = (_v0, f, _param) => { - while (true) { - let param = _param; - let v0 = _v0; - if (typeof param !== "object") { - return Caml_option.some(v0); - } - let v = param.v; - if (f(v)) { - _param = param.l; - _v0 = v; - continue; - } - _param = param.r; - continue; - }; - }; - let find_first_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - return find_first_opt_aux(v, f, param.l); - } - _param = param.r; - continue; - }; - }; - let find_last_aux = (_v0, f, _param) => { - while (true) { - let param = _param; - let v0 = _v0; - if (typeof param !== "object") { - return v0; - } - let v = param.v; - if (f(v)) { - _param = param.r; - _v0 = v; - continue; - } - _param = param.l; - continue; - }; - }; - let find_last = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - return find_last_aux(v, f, param.r); - } - _param = param.l; - continue; - }; - }; - let find_last_opt_aux = (_v0, f, _param) => { - while (true) { - let param = _param; - let v0 = _v0; - if (typeof param !== "object") { - return Caml_option.some(v0); - } - let v = param.v; - if (f(v)) { - _param = param.r; - _v0 = v; - continue; - } - _param = param.l; - continue; - }; - }; - let find_last_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - return find_last_opt_aux(v, f, param.r); - } - _param = param.l; - continue; - }; - }; - let find_opt = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - let c = funarg.compare(x, v); - if (c === 0) { - return Caml_option.some(v); - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let try_join = (l, v, r) => { - if ((l === "Empty" || funarg.compare(max_elt(l), v) < 0) && (r === "Empty" || funarg.compare(v, min_elt(r)) < 0)) { - return join(l, v, r); - } else { - return union(l, add(v, r)); - } - }; - let map = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = map(f, l); - let v$p = f(v); - let r$p = map(f, r); - if (l === l$p && v === v$p && r === r$p) { - return param; - } else { - return try_join(l$p, v$p, r$p); - } - }; - let of_sorted_list = l => { - let sub = (n, l) => { - switch (n) { - case 0 : - return [ - "Empty", - l - ]; - case 1 : - if (l) { - return [ - { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - l.tl - ]; - } - break; - case 2 : - if (l) { - let match = l.tl; - if (match) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match.hd, - r: "Empty", - h: 2 - }, - match.tl - ]; - } - - } - break; - case 3 : - if (l) { - let match$1 = l.tl; - if (match$1) { - let match$2 = match$1.tl; - if (match$2) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match$1.hd, - r: { - TAG: "Node", - l: "Empty", - v: match$2.hd, - r: "Empty", - h: 1 - }, - h: 2 - }, - match$2.tl - ]; - } - - } - - } - break; - } - let nl = n / 2 | 0; - let match$3 = sub(nl, l); - let l$1 = match$3[1]; - if (l$1) { - let match$4 = sub((n - nl | 0) - 1 | 0, l$1.tl); - return [ - create(match$3[0], l$1.hd, match$4[0]), - match$4[1] - ]; - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "setLabels.res", - 691, - 20 - ], - Error: new Error() - }; - }; - return sub(List.length(l), l)[0]; - }; - let of_list = l => { - if (!l) { - return "Empty"; - } - let match = l.tl; - let x0 = l.hd; - if (!match) { - return singleton(x0); - } - let match$1 = match.tl; - let x1 = match.hd; - if (!match$1) { - return add(x1, singleton(x0)); - } - let match$2 = match$1.tl; - let x2 = match$1.hd; - if (!match$2) { - return add(x2, add(x1, singleton(x0))); - } - let match$3 = match$2.tl; - let x3 = match$2.hd; - if (match$3) { - if (match$3.tl) { - return of_sorted_list(List.sort_uniq(funarg.compare, l)); - } else { - return add(match$3.hd, add(x3, add(x2, add(x1, singleton(x0))))); - } - } else { - return add(x3, add(x2, add(x1, singleton(x0)))); - } - }; - return { - empty: "Empty", - is_empty: is_empty, - mem: mem, - add: add, - singleton: singleton, - remove: remove, - union: union, - inter: inter, - diff: diff, - compare: compare, - equal: equal, - subset: subset, - iter: iter, - map: map, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - elements: elements, - min_elt: min_elt, - min_elt_opt: min_elt_opt, - max_elt: max_elt, - max_elt_opt: max_elt_opt, - choose: min_elt, - choose_opt: min_elt_opt, - split: split, - find: find, - find_opt: find_opt, - find_first: find_first, - find_first_opt: find_first_opt, - find_last: find_last, - find_last_opt: find_last_opt, - of_list: of_list - }; - } -}; - -exports.Hashtbl = Hashtbl; -exports.$$Map = $$Map; -exports.$$Set = $$Set; -/* No side effect */ diff --git a/lib/js/obj.js b/lib/js/obj.js index e31c8dc42f..fffba72d0c 100644 --- a/lib/js/obj.js +++ b/lib/js/obj.js @@ -1,9 +1,49 @@ 'use strict'; -function is_block(a) { - return typeof a !== "number"; +function magic(prim) { + return prim; } -exports.is_block = is_block; +function repr(prim) { + return prim; +} + +function obj(prim) { + return prim; +} + +function tag(prim) { + return prim.TAG; +} + +function size(prim) { + return prim.length | 0; +} + +function field(prim0, prim1) { + return prim0[prim1]; +} + +function set_field(prim0, prim1, prim2) { + prim0[prim1] = prim2; +} + +function dup(prim) { + return {...prim}; +} + +function update_dummy(prim0, prim1) { + Object.assign(prim0, prim1); +} + +exports.magic = magic; +exports.repr = repr; +exports.obj = obj; +exports.tag = tag; +exports.size = size; +exports.field = field; +exports.set_field = set_field; +exports.dup = dup; +exports.update_dummy = update_dummy; /* No side effect */ diff --git a/lib/js/parsing.js b/lib/js/parsing.js deleted file mode 100644 index 060a22154d..0000000000 --- a/lib/js/parsing.js +++ /dev/null @@ -1,229 +0,0 @@ -'use strict'; - -let $$Array = require("./array.js"); -let Lexing = require("./lexing.js"); -let Caml_obj = require("./caml_obj.js"); -let Caml_array = require("./caml_array.js"); -let Caml_parser = require("./caml_parser.js"); -let Caml_exceptions = require("./caml_exceptions.js"); -let Caml_js_exceptions = require("./caml_js_exceptions.js"); - -let YYexit = /* @__PURE__ */Caml_exceptions.create("Parsing.YYexit"); - -let Parse_error = /* @__PURE__ */Caml_exceptions.create("Parsing.Parse_error"); - -let env = { - s_stack: Caml_array.make(100, 0), - v_stack: Caml_array.make(100, undefined), - symb_start_stack: Caml_array.make(100, Lexing.dummy_pos), - symb_end_stack: Caml_array.make(100, Lexing.dummy_pos), - stacksize: 100, - stackbase: 0, - curr_char: 0, - lval: undefined, - symb_start: Lexing.dummy_pos, - symb_end: Lexing.dummy_pos, - asp: 0, - rule_len: 0, - rule_number: 0, - sp: 0, - state: 0, - errflag: 0 -}; - -function grow_stacks() { - let oldsize = env.stacksize; - let newsize = (oldsize << 1); - let new_s = Caml_array.make(newsize, 0); - let new_v = Caml_array.make(newsize, undefined); - let new_start = Caml_array.make(newsize, Lexing.dummy_pos); - let new_end = Caml_array.make(newsize, Lexing.dummy_pos); - $$Array.blit(env.s_stack, 0, new_s, 0, oldsize); - env.s_stack = new_s; - $$Array.blit(env.v_stack, 0, new_v, 0, oldsize); - env.v_stack = new_v; - $$Array.blit(env.symb_start_stack, 0, new_start, 0, oldsize); - env.symb_start_stack = new_start; - $$Array.blit(env.symb_end_stack, 0, new_end, 0, oldsize); - env.symb_end_stack = new_end; - env.stacksize = newsize; -} - -function clear_parser() { - $$Array.fill(env.v_stack, 0, env.stacksize, undefined); - env.lval = undefined; -} - -let current_lookahead_fun = { - contents: param => false -}; - -function yyparse(tables, start, lexer, lexbuf) { - let init_asp = env.asp; - let init_sp = env.sp; - let init_stackbase = env.stackbase; - let init_state = env.state; - let init_curr_char = env.curr_char; - let init_lval = env.lval; - let init_errflag = env.errflag; - env.stackbase = env.sp + 1 | 0; - env.curr_char = start; - env.symb_end = lexbuf.lex_curr_p; - try { - let _cmd = "Start"; - let _arg; - while (true) { - let arg = _arg; - let cmd = _cmd; - let match = Caml_parser.parse_engine(tables, env, cmd, arg); - switch (match) { - case "Read_token" : - let t = lexer(lexbuf); - env.symb_start = lexbuf.lex_start_p; - env.symb_end = lexbuf.lex_curr_p; - _arg = t; - _cmd = "Token_read"; - continue; - case "Raise_parse_error" : - throw { - RE_EXN_ID: Parse_error, - Error: new Error() - }; - case "Grow_stacks_1" : - grow_stacks(); - _arg = undefined; - _cmd = "Stacks_grown_1"; - continue; - case "Grow_stacks_2" : - grow_stacks(); - _arg = undefined; - _cmd = "Stacks_grown_2"; - continue; - case "Compute_semantic_action" : - let match$1; - try { - match$1 = [ - "Semantic_action_computed", - Caml_array.get(tables.actions, env.rule_number)(env) - ]; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === Parse_error) { - match$1 = [ - "Error_detected", - undefined - ]; - } else { - throw exn; - } - } - _arg = match$1[1]; - _cmd = match$1[0]; - continue; - case "Call_error_function" : - tables.error_function("syntax error"); - _arg = undefined; - _cmd = "Error_detected"; - continue; - } - }; - } catch (raw_exn$1) { - let exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn$1); - let curr_char = env.curr_char; - env.asp = init_asp; - env.sp = init_sp; - env.stackbase = init_stackbase; - env.state = init_state; - env.curr_char = init_curr_char; - env.lval = init_lval; - env.errflag = init_errflag; - if (exn$1.RE_EXN_ID === YYexit) { - return exn$1._1; - } - current_lookahead_fun.contents = tok => { - if (typeof tok !== "number") { - return Caml_array.get(tables.transl_block, tok.TAG) === curr_char; - } else { - return Caml_array.get(tables.transl_const, tok) === curr_char; - } - }; - throw exn$1; - } -} - -function peek_val(env, n) { - return Caml_array.get(env.v_stack, env.asp - n | 0); -} - -function symbol_start_pos() { - let _i = env.rule_len; - while (true) { - let i = _i; - if (i <= 0) { - return Caml_array.get(env.symb_end_stack, env.asp); - } - let st = Caml_array.get(env.symb_start_stack, (env.asp - i | 0) + 1 | 0); - let en = Caml_array.get(env.symb_end_stack, (env.asp - i | 0) + 1 | 0); - if (Caml_obj.notequal(st, en)) { - return st; - } - _i = i - 1 | 0; - continue; - }; -} - -function symbol_end_pos() { - return Caml_array.get(env.symb_end_stack, env.asp); -} - -function rhs_start_pos(n) { - return Caml_array.get(env.symb_start_stack, env.asp - (env.rule_len - n | 0) | 0); -} - -function rhs_end_pos(n) { - return Caml_array.get(env.symb_end_stack, env.asp - (env.rule_len - n | 0) | 0); -} - -function symbol_start() { - return symbol_start_pos().pos_cnum; -} - -function symbol_end() { - return symbol_end_pos().pos_cnum; -} - -function rhs_start(n) { - return rhs_start_pos(n).pos_cnum; -} - -function rhs_end(n) { - return rhs_end_pos(n).pos_cnum; -} - -function is_current_lookahead(tok) { - return current_lookahead_fun.contents(tok); -} - -function parse_error(param) { - -} - -let set_trace = Caml_parser.set_parser_trace; - -exports.symbol_start = symbol_start; -exports.symbol_end = symbol_end; -exports.rhs_start = rhs_start; -exports.rhs_end = rhs_end; -exports.symbol_start_pos = symbol_start_pos; -exports.symbol_end_pos = symbol_end_pos; -exports.rhs_start_pos = rhs_start_pos; -exports.rhs_end_pos = rhs_end_pos; -exports.clear_parser = clear_parser; -exports.Parse_error = Parse_error; -exports.set_trace = set_trace; -exports.YYexit = YYexit; -exports.yyparse = yyparse; -exports.peek_val = peek_val; -exports.is_current_lookahead = is_current_lookahead; -exports.parse_error = parse_error; -/* No side effect */ diff --git a/lib/js/pervasives.js b/lib/js/pervasives.js index e565627692..294ad4289c 100644 --- a/lib/js/pervasives.js +++ b/lib/js/pervasives.js @@ -1,10 +1,6 @@ 'use strict'; -let Caml_sys = require("./caml_sys.js"); -let Caml_format = require("./caml_format.js"); -let Caml_string = require("./caml_string.js"); -let Caml_exceptions = require("./caml_exceptions.js"); -let Caml_js_exceptions = require("./caml_js_exceptions.js"); +let Primitive_exceptions = require("./primitive_exceptions.js"); function failwith(s) { throw { @@ -22,7 +18,7 @@ function invalid_arg(s) { }; } -let Exit = /* @__PURE__ */Caml_exceptions.create("Pervasives.Exit"); +let Exit = /* @__PURE__ */Primitive_exceptions.create("Pervasives.Pervasives.Exit"); function abs(x) { if (x >= 0) { @@ -100,54 +96,11 @@ function bool_of_string_opt(param) { } function int_of_string_opt(s) { - try { - return Caml_format.int_of_string(s); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Failure") { - return; - } - throw exn; - } -} - -function valid_float_lexem(s) { - let l = s.length; - let _i = 0; - while (true) { - let i = _i; - if (i >= l) { - return s + "."; - } - let match = Caml_string.get(s, i); - if (match >= 48) { - if (match >= 58) { - return s; - } - _i = i + 1 | 0; - continue; - } - if (match !== 45) { - return s; - } - _i = i + 1 | 0; - continue; - }; -} - -function string_of_float(f) { - return valid_float_lexem(Caml_format.format_float("%.12g", f)); -} - -function float_of_string_opt(s) { - try { - return Caml_format.float_of_string(s); - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Failure") { - return; - } - throw exn; + let n = Number.parseInt(s); + if (n === NaN) { + return; + } else { + return n; } } @@ -162,43 +115,28 @@ function $at(l1, l2) { } } -function print_newline() { - console.log(""); -} - -function prerr_newline() { - console.error(""); -} - -function print_int(i) { - console.log(String(i)); -} - -function print_float(i) { - console.log(valid_float_lexem(Caml_format.format_float("%.12g", i))); -} - -function print_string(prim) { - console.log(prim); -} - -let exit_function = { - contents: prim => {} +let Pervasives = { + failwith: failwith, + invalid_arg: invalid_arg, + Exit: Exit, + abs: abs, + lnot: lnot, + max_int: 2147483647, + min_int: min_int, + infinity: Infinity, + neg_infinity: -Infinity, + max_float: 1.79769313486231571e+308, + min_float: 2.22507385850720138e-308, + epsilon_float: 2.22044604925031308e-16, + classify_float: classify_float, + char_of_int: char_of_int, + string_of_bool: string_of_bool, + bool_of_string: bool_of_string, + bool_of_string_opt: bool_of_string_opt, + int_of_string_opt: int_of_string_opt, + $at: $at }; -function at_exit(f) { - let g = exit_function.contents; - exit_function.contents = () => { - f(); - g(); - }; -} - -function exit(retcode) { - exit_function.contents(); - return Caml_sys.sys_exit(retcode); -} - let max_int = 2147483647; let infinity = Infinity; @@ -211,13 +149,14 @@ let min_float = 2.22507385850720138e-308; let epsilon_float = 2.22044604925031308e-16; -exports.invalid_arg = invalid_arg; +exports.Pervasives = Pervasives; exports.failwith = failwith; +exports.invalid_arg = invalid_arg; exports.Exit = Exit; exports.abs = abs; +exports.lnot = lnot; exports.max_int = max_int; exports.min_int = min_int; -exports.lnot = lnot; exports.infinity = infinity; exports.neg_infinity = neg_infinity; exports.max_float = max_float; @@ -229,15 +168,5 @@ exports.string_of_bool = string_of_bool; exports.bool_of_string = bool_of_string; exports.bool_of_string_opt = bool_of_string_opt; exports.int_of_string_opt = int_of_string_opt; -exports.string_of_float = string_of_float; -exports.float_of_string_opt = float_of_string_opt; exports.$at = $at; -exports.print_string = print_string; -exports.print_int = print_int; -exports.print_float = print_float; -exports.print_newline = print_newline; -exports.prerr_newline = prerr_newline; -exports.exit = exit; -exports.at_exit = at_exit; -exports.valid_float_lexem = valid_float_lexem; /* No side effect */ diff --git a/lib/js/primitive_array.js b/lib/js/primitive_array.js new file mode 100644 index 0000000000..7bd0ed8257 --- /dev/null +++ b/lib/js/primitive_array.js @@ -0,0 +1,33 @@ +'use strict'; + + +function length(prim) { + return prim.length; +} + +function get(xs, index) { + if (index < 0 || index >= xs.length) { + throw { + RE_EXN_ID: "Invalid_argument", + _1: "index out of bounds", + Error: new Error() + }; + } + return xs[index]; +} + +function set(xs, index, newval) { + if (index < 0 || index >= xs.length) { + throw { + RE_EXN_ID: "Invalid_argument", + _1: "index out of bounds", + Error: new Error() + }; + } + xs[index] = newval; +} + +exports.length = length; +exports.get = get; +exports.set = set; +/* No side effect */ diff --git a/lib/js/caml_bigint_extern.js b/lib/js/primitive_array_extern.js similarity index 100% rename from lib/js/caml_bigint_extern.js rename to lib/js/primitive_array_extern.js diff --git a/lib/js/caml_bigint.js b/lib/js/primitive_bigint.js similarity index 50% rename from lib/js/caml_bigint.js rename to lib/js/primitive_bigint.js index b6031d5ed0..2bcba4c9d5 100644 --- a/lib/js/caml_bigint.js +++ b/lib/js/primitive_bigint.js @@ -1,6 +1,32 @@ 'use strict'; +function compare(x, y) { + if (x < y) { + return -1; + } else if (x === y) { + return 0; + } else { + return 1; + } +} + +function min(x, y) { + if (x < y) { + return x; + } else { + return y; + } +} + +function max(x, y) { + if (x > y) { + return x; + } else { + return y; + } +} + function div(x, y) { if (y === 0n) { throw { @@ -21,6 +47,9 @@ function mod_(x, y) { return x % y; } +exports.compare = compare; +exports.min = min; +exports.max = max; exports.div = div; exports.mod_ = mod_; /* No side effect */ diff --git a/lib/js/primitive_bool.js b/lib/js/primitive_bool.js new file mode 100644 index 0000000000..4316f47b0b --- /dev/null +++ b/lib/js/primitive_bool.js @@ -0,0 +1,37 @@ +'use strict'; + + +function compare(x, y) { + if (x) { + if (y) { + return 0; + } else { + return 1; + } + } else if (y) { + return -1; + } else { + return 0; + } +} + +function min(x, y) { + if (x) { + return y; + } else { + return x; + } +} + +function max(x, y) { + if (x) { + return x; + } else { + return y; + } +} + +exports.compare = compare; +exports.min = min; +exports.max = max; +/* No side effect */ diff --git a/lib/js/caml_float_extern.js b/lib/js/primitive_char_extern.js similarity index 100% rename from lib/js/caml_float_extern.js rename to lib/js/primitive_char_extern.js diff --git a/lib/js/primitive_curry.js b/lib/js/primitive_curry.js new file mode 100644 index 0000000000..755967faf1 --- /dev/null +++ b/lib/js/primitive_curry.js @@ -0,0 +1,436 @@ +'use strict'; + + +function app(_f, _args) { + while (true) { + let args = _args; + let f = _f; + let init_arity = f.length; + let arity = init_arity === 0 ? 1 : init_arity; + let len = args.length; + let d = arity - len | 0; + if (d === 0) { + return f.apply(null, args); + } + if (d >= 0) { + return x => app(f, args.concat([x])); + } + _args = args.slice(arity, len); + _f = f.apply(null, args.slice(0, arity)); + continue; + }; +} + +function __1(o) { + let arity = o.length; + if (arity === 1) { + return o; + } else { + return a0 => { + let arity = o.length; + if (arity === 1) { + return o(a0); + } else { + switch (arity) { + case 1 : + return o(a0); + case 2 : + return param => o(a0, param); + case 3 : + return (param, param$1) => o(a0, param, param$1); + case 4 : + return (param, param$1, param$2) => o(a0, param, param$1, param$2); + case 5 : + return (param, param$1, param$2, param$3) => o(a0, param, param$1, param$2, param$3); + case 6 : + return (param, param$1, param$2, param$3, param$4) => o(a0, param, param$1, param$2, param$3, param$4); + case 7 : + return (param, param$1, param$2, param$3, param$4, param$5) => o(a0, param, param$1, param$2, param$3, param$4, param$5); + default: + return app(o, [a0]); + } + } + }; + } +} + +function __2(o) { + let arity = o.length; + if (arity === 2) { + return o; + } else { + return (a0, a1) => { + let arity = o.length; + if (arity === 2) { + return o(a0, a1); + } else { + switch (arity) { + case 1 : + return app(o(a0), [a1]); + case 2 : + return o(a0, a1); + case 3 : + return param => o(a0, a1, param); + case 4 : + return (param, param$1) => o(a0, a1, param, param$1); + case 5 : + return (param, param$1, param$2) => o(a0, a1, param, param$1, param$2); + case 6 : + return (param, param$1, param$2, param$3) => o(a0, a1, param, param$1, param$2, param$3); + case 7 : + return (param, param$1, param$2, param$3, param$4) => o(a0, a1, param, param$1, param$2, param$3, param$4); + default: + return app(o, [ + a0, + a1 + ]); + } + } + }; + } +} + +function __3(o) { + let arity = o.length; + if (arity === 3) { + return o; + } else { + return (a0, a1, a2) => { + let arity = o.length; + if (arity === 3) { + return o(a0, a1, a2); + } else { + switch (arity) { + case 1 : + return app(o(a0), [ + a1, + a2 + ]); + case 2 : + return app(o(a0, a1), [a2]); + case 3 : + return o(a0, a1, a2); + case 4 : + return param => o(a0, a1, a2, param); + case 5 : + return (param, param$1) => o(a0, a1, a2, param, param$1); + case 6 : + return (param, param$1, param$2) => o(a0, a1, a2, param, param$1, param$2); + case 7 : + return (param, param$1, param$2, param$3) => o(a0, a1, a2, param, param$1, param$2, param$3); + default: + return app(o, [ + a0, + a1, + a2 + ]); + } + } + }; + } +} + +function __4(o) { + let arity = o.length; + if (arity === 4) { + return o; + } else { + return (a0, a1, a2, a3) => { + let arity = o.length; + if (arity === 4) { + return o(a0, a1, a2, a3); + } else { + switch (arity) { + case 1 : + return app(o(a0), [ + a1, + a2, + a3 + ]); + case 2 : + return app(o(a0, a1), [ + a2, + a3 + ]); + case 3 : + return app(o(a0, a1, a2), [a3]); + case 4 : + return o(a0, a1, a2, a3); + case 5 : + return param => o(a0, a1, a2, a3, param); + case 6 : + return (param, param$1) => o(a0, a1, a2, a3, param, param$1); + case 7 : + return (param, param$1, param$2) => o(a0, a1, a2, a3, param, param$1, param$2); + default: + return app(o, [ + a0, + a1, + a2, + a3 + ]); + } + } + }; + } +} + +function __5(o) { + let arity = o.length; + if (arity === 5) { + return o; + } else { + return (a0, a1, a2, a3, a4) => { + let arity = o.length; + if (arity === 5) { + return o(a0, a1, a2, a3, a4); + } else { + switch (arity) { + case 1 : + return app(o(a0), [ + a1, + a2, + a3, + a4 + ]); + case 2 : + return app(o(a0, a1), [ + a2, + a3, + a4 + ]); + case 3 : + return app(o(a0, a1, a2), [ + a3, + a4 + ]); + case 4 : + return app(o(a0, a1, a2, a3), [a4]); + case 5 : + return o(a0, a1, a2, a3, a4); + case 6 : + return param => o(a0, a1, a2, a3, a4, param); + case 7 : + return (param, param$1) => o(a0, a1, a2, a3, a4, param, param$1); + default: + return app(o, [ + a0, + a1, + a2, + a3, + a4 + ]); + } + } + }; + } +} + +function __6(o) { + let arity = o.length; + if (arity === 6) { + return o; + } else { + return (a0, a1, a2, a3, a4, a5) => { + let arity = o.length; + if (arity === 6) { + return o(a0, a1, a2, a3, a4, a5); + } else { + switch (arity) { + case 1 : + return app(o(a0), [ + a1, + a2, + a3, + a4, + a5 + ]); + case 2 : + return app(o(a0, a1), [ + a2, + a3, + a4, + a5 + ]); + case 3 : + return app(o(a0, a1, a2), [ + a3, + a4, + a5 + ]); + case 4 : + return app(o(a0, a1, a2, a3), [ + a4, + a5 + ]); + case 5 : + return app(o(a0, a1, a2, a3, a4), [a5]); + case 6 : + return o(a0, a1, a2, a3, a4, a5); + case 7 : + return param => o(a0, a1, a2, a3, a4, a5, param); + default: + return app(o, [ + a0, + a1, + a2, + a3, + a4, + a5 + ]); + } + } + }; + } +} + +function __7(o) { + let arity = o.length; + if (arity === 7) { + return o; + } else { + return (a0, a1, a2, a3, a4, a5, a6) => { + let arity = o.length; + if (arity === 7) { + return o(a0, a1, a2, a3, a4, a5, a6); + } else { + switch (arity) { + case 1 : + return app(o(a0), [ + a1, + a2, + a3, + a4, + a5, + a6 + ]); + case 2 : + return app(o(a0, a1), [ + a2, + a3, + a4, + a5, + a6 + ]); + case 3 : + return app(o(a0, a1, a2), [ + a3, + a4, + a5, + a6 + ]); + case 4 : + return app(o(a0, a1, a2, a3), [ + a4, + a5, + a6 + ]); + case 5 : + return app(o(a0, a1, a2, a3, a4), [ + a5, + a6 + ]); + case 6 : + return app(o(a0, a1, a2, a3, a4, a5), [a6]); + case 7 : + return o(a0, a1, a2, a3, a4, a5, a6); + default: + return app(o, [ + a0, + a1, + a2, + a3, + a4, + a5, + a6 + ]); + } + } + }; + } +} + +function __8(o) { + let arity = o.length; + if (arity === 8) { + return o; + } else { + return (a0, a1, a2, a3, a4, a5, a6, a7) => { + let arity = o.length; + if (arity === 8) { + return o(a0, a1, a2, a3, a4, a5, a6, a7); + } else { + switch (arity) { + case 1 : + return app(o(a0), [ + a1, + a2, + a3, + a4, + a5, + a6, + a7 + ]); + case 2 : + return app(o(a0, a1), [ + a2, + a3, + a4, + a5, + a6, + a7 + ]); + case 3 : + return app(o(a0, a1, a2), [ + a3, + a4, + a5, + a6, + a7 + ]); + case 4 : + return app(o(a0, a1, a2, a3), [ + a4, + a5, + a6, + a7 + ]); + case 5 : + return app(o(a0, a1, a2, a3, a4), [ + a5, + a6, + a7 + ]); + case 6 : + return app(o(a0, a1, a2, a3, a4, a5), [ + a6, + a7 + ]); + case 7 : + return app(o(a0, a1, a2, a3, a4, a5, a6), [a7]); + default: + return app(o, [ + a0, + a1, + a2, + a3, + a4, + a5, + a6, + a7 + ]); + } + } + }; + } +} + +exports.__1 = __1; +exports.__2 = __2; +exports.__3 = __3; +exports.__4 = __4; +exports.__5 = __5; +exports.__6 = __6; +exports.__7 = __7; +exports.__8 = __8; +/* No side effect */ diff --git a/lib/js/caml_int64_extern.js b/lib/js/primitive_dict.js similarity index 100% rename from lib/js/caml_int64_extern.js rename to lib/js/primitive_dict.js diff --git a/lib/js/caml_exceptions.js b/lib/js/primitive_exceptions.js similarity index 56% rename from lib/js/caml_exceptions.js rename to lib/js/primitive_exceptions.js index cdff924b3f..49bf58ee20 100644 --- a/lib/js/caml_exceptions.js +++ b/lib/js/primitive_exceptions.js @@ -1,6 +1,25 @@ 'use strict'; +function isExtension(e) { + if (e == null) { + return false; + } else { + return typeof e.RE_EXN_ID === "string"; + } +} + +function internalToException(e) { + if (isExtension(e)) { + return e; + } else { + return { + RE_EXN_ID: "JsError", + _1: e + }; + } +} + let idMap = {}; function create(str) { @@ -14,19 +33,9 @@ function create(str) { return str; } -function is_extension(e) { - if (e == null) { - return false; - } else { - return typeof e.RE_EXN_ID === "string"; - } -} - -function exn_slot_name(x) { - return x.RE_EXN_ID; -} +let $$Error = "JsError"; +exports.$$Error = $$Error; exports.create = create; -exports.is_extension = is_extension; -exports.exn_slot_name = exn_slot_name; +exports.internalToException = internalToException; /* No side effect */ diff --git a/lib/js/primitive_float.js b/lib/js/primitive_float.js new file mode 100644 index 0000000000..05bf928667 --- /dev/null +++ b/lib/js/primitive_float.js @@ -0,0 +1,37 @@ +'use strict'; + + +function compare(x, y) { + if (x === y) { + return 0; + } else if (x < y) { + return -1; + } else if (x > y || x === x) { + return 1; + } else if (y === y) { + return -1; + } else { + return 0; + } +} + +function min(x, y) { + if (x < y) { + return x; + } else { + return y; + } +} + +function max(x, y) { + if (x > y) { + return x; + } else { + return y; + } +} + +exports.compare = compare; +exports.min = min; +exports.max = max; +/* No side effect */ diff --git a/lib/js/caml_nativeint_extern.js b/lib/js/primitive_float_extern.js similarity index 100% rename from lib/js/caml_nativeint_extern.js rename to lib/js/primitive_float_extern.js diff --git a/lib/js/primitive_hash.js b/lib/js/primitive_hash.js new file mode 100644 index 0000000000..d3468d5c69 --- /dev/null +++ b/lib/js/primitive_hash.js @@ -0,0 +1,152 @@ +'use strict'; + + +function push_back(q, v) { + let cell = { + content: v, + next: undefined + }; + let last = q.last; + if (last !== undefined) { + q.length = q.length + 1 | 0; + last.next = cell; + q.last = cell; + } else { + q.length = 1; + q.first = cell; + q.last = cell; + } +} + +function unsafe_pop(q) { + let cell = q.first; + if (cell !== undefined) { + let next = cell.next; + if (next === undefined) { + q.length = 0; + q.first = undefined; + q.last = undefined; + } else { + q.length = q.length - 1 | 0; + q.first = next; + } + return cell.content; + } + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "primitive_hash.res", + 70, + 12 + ], + Error: new Error() + }; +} + +function rotl32(x, n) { + return (x << n) | (x >>> (32 - n | 0)) | 0; +} + +function hash_mix_int(h, d) { + let d$1 = d; + d$1 = Math.imul(d$1, -862048943); + d$1 = rotl32(d$1, 15); + d$1 = Math.imul(d$1, 461845907); + let h$1 = h ^ d$1; + h$1 = rotl32(h$1, 13); + return (h$1 + (h$1 << 2) | 0) - 430675100 | 0; +} + +function hash_final_mix(h) { + let h$1 = h ^ (h >>> 16); + h$1 = Math.imul(h$1, -2048144789); + h$1 = h$1 ^ (h$1 >>> 13); + h$1 = Math.imul(h$1, -1028477387); + return h$1 ^ (h$1 >>> 16); +} + +function hash_mix_string(h, s) { + let len = s.length; + let block = (len / 4 | 0) - 1 | 0; + let hash = h; + for (let i = 0; i <= block; ++i) { + let j = (i << 2); + let w = s.charCodeAt(j) | (s.charCodeAt(j + 1 | 0) << 8) | (s.charCodeAt(j + 2 | 0) << 16) | (s.charCodeAt(j + 3 | 0) << 24); + hash = hash_mix_int(hash, w); + } + let modulo = len & 3; + if (modulo !== 0) { + let w$1 = modulo === 3 ? (s.charCodeAt(len - 1 | 0) << 16) | (s.charCodeAt(len - 2 | 0) << 8) | s.charCodeAt(len - 3 | 0) : ( + modulo === 2 ? (s.charCodeAt(len - 1 | 0) << 8) | s.charCodeAt(len - 2 | 0) : s.charCodeAt(len - 1 | 0) + ); + hash = hash_mix_int(hash, w$1); + } + hash = hash ^ len; + return hash; +} + +function hash(count, _limit, seed, obj) { + let s = seed; + if (typeof obj === "number") { + let u = obj | 0; + s = hash_mix_int(s, (u + u | 0) + 1 | 0); + return hash_final_mix(s); + } + if (typeof obj === "string") { + s = hash_mix_string(s, obj); + return hash_final_mix(s); + } + let queue = { + length: 0, + first: undefined, + last: undefined + }; + let num = count; + push_back(queue, obj); + num = num - 1 | 0; + while (queue.length !== 0 && num > 0) { + let obj$1 = unsafe_pop(queue); + if (typeof obj$1 === "number") { + let u$1 = obj$1 | 0; + s = hash_mix_int(s, (u$1 + u$1 | 0) + 1 | 0); + num = num - 1 | 0; + } else if (typeof obj$1 === "string") { + s = hash_mix_string(s, obj$1); + num = num - 1 | 0; + } else if (typeof obj$1 !== "boolean" && typeof obj$1 !== "undefined" && typeof obj$1 !== "symbol" && typeof obj$1 !== "function") { + let size = obj$1.length | 0; + if (size !== 0) { + let obj_tag = obj$1.TAG; + let tag = (size << 10) | obj_tag; + if (obj_tag === 248) { + s = hash_mix_int(s, obj$1[1]); + } else { + s = hash_mix_int(s, tag); + let v = size - 1 | 0; + let block = v < num ? v : num; + for (let i = 0; i <= block; ++i) { + push_back(queue, obj$1[i]); + } + } + } else { + let size$1 = (function(obj,cb){ + var size = 0 + for(var k in obj){ + cb(obj[k]) + ++ size + } + return size + })(obj$1, v => push_back(queue, v)); + s = hash_mix_int(s, (size$1 << 10) | 0); + } + } + + }; + return hash_final_mix(s); +} + +exports.hash_mix_int = hash_mix_int; +exports.hash_mix_string = hash_mix_string; +exports.hash_final_mix = hash_final_mix; +exports.hash = hash; +/* No side effect */ diff --git a/lib/js/caml_int32.js b/lib/js/primitive_int.js similarity index 50% rename from lib/js/caml_int32.js rename to lib/js/primitive_int.js index 348de87617..4886a654c1 100644 --- a/lib/js/caml_int32.js +++ b/lib/js/primitive_int.js @@ -1,6 +1,32 @@ 'use strict'; +function compare(x, y) { + if (x < y) { + return -1; + } else if (x === y) { + return 0; + } else { + return 1; + } +} + +function min(x, y) { + if (x < y) { + return x; + } else { + return y; + } +} + +function max(x, y) { + if (x > y) { + return x; + } else { + return y; + } +} + function div(x, y) { if (y === 0) { throw { @@ -21,6 +47,9 @@ function mod_(x, y) { return x % y; } +exports.compare = compare; +exports.min = min; +exports.max = max; exports.div = div; exports.mod_ = mod_; /* No side effect */ diff --git a/lib/js/caml_string_extern.js b/lib/js/primitive_int_extern.js similarity index 100% rename from lib/js/caml_string_extern.js rename to lib/js/primitive_int_extern.js diff --git a/lib/js/caml_undefined_extern.js b/lib/js/primitive_js_extern.js similarity index 100% rename from lib/js/caml_undefined_extern.js rename to lib/js/primitive_js_extern.js diff --git a/lib/js/camlinternalLazy.js b/lib/js/primitive_lazy.js similarity index 88% rename from lib/js/camlinternalLazy.js rename to lib/js/primitive_lazy.js index bf09987627..eadb61f13b 100644 --- a/lib/js/camlinternalLazy.js +++ b/lib/js/primitive_lazy.js @@ -1,12 +1,12 @@ 'use strict'; -let Caml_exceptions = require("./caml_exceptions.js"); +let Primitive_exceptions = require("./primitive_exceptions.js"); function is_val(l) { return l.LAZY_DONE; } -let Undefined = /* @__PURE__ */Caml_exceptions.create("CamlinternalLazy.Undefined"); +let Undefined = /* @__PURE__ */Primitive_exceptions.create("Primitive_lazy.Undefined"); function forward_with_closure(blk, closure) { let result = closure(); @@ -66,7 +66,7 @@ function from_val(value) { exports.Undefined = Undefined; exports.force = force; exports.force_val = force_val; -exports.is_val = is_val; exports.from_fun = from_fun; exports.from_val = from_val; +exports.is_val = is_val; /* No side effect */ diff --git a/lib/js/caml_module.js b/lib/js/primitive_module.js similarity index 75% rename from lib/js/caml_module.js rename to lib/js/primitive_module.js index f7caf02d8f..0733d05d50 100644 --- a/lib/js/caml_module.js +++ b/lib/js/primitive_module.js @@ -1,8 +1,7 @@ 'use strict'; -let Caml_obj = require("./caml_obj.js"); -function init_mod(loc, shape) { +function init(loc, shape) { let undef_module = param => { throw { RE_EXN_ID: "Undefined_recursive_module", @@ -27,18 +26,18 @@ function init_mod(loc, shape) { return; } } else { - if (shape.TAG === "Module") { - let comps = shape._0; - let v = {}; - struct_[idx] = v; - let len = comps.length; - for (let i = 0; i < len; ++i) { - let match = comps[i]; - loop(match[0], v, match[1]); - } + if (shape.TAG !== "Module") { + struct_[idx] = shape._0; return; } - struct_[idx] = shape._0; + let comps = shape._0; + let v = {}; + struct_[idx] = v; + let len = comps.length; + for (let i = 0; i < len; ++i) { + let match = comps[i]; + loop(match[0], v, match[1]); + } return; } }; @@ -48,7 +47,7 @@ function init_mod(loc, shape) { return res[dummy_name]; } -function update_mod(shape, o, n) { +function update(shape, o, n) { let aux = (shape, o, n, parent, i) => { if (typeof shape !== "object") { switch (shape) { @@ -57,7 +56,8 @@ function update_mod(shape, o, n) { return; case "Lazy" : case "Class" : - return Caml_obj.update_dummy(o, n); + Object.assign(o, n); + return; } } else { if (shape.TAG !== "Module") { @@ -76,8 +76,8 @@ function update_mod(shape, o, n) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "caml_module.res", - 109, + "primitive_module.res", + 68, 9 ], Error: new Error() @@ -95,14 +95,14 @@ function update_mod(shape, o, n) { throw { RE_EXN_ID: "Assert_failure", _1: [ - "caml_module.res", - 109, + "primitive_module.res", + 68, 9 ], Error: new Error() }; } -exports.init_mod = init_mod; -exports.update_mod = update_mod; +exports.init = init; +exports.update = update; /* No side effect */ diff --git a/lib/js/caml_obj.js b/lib/js/primitive_object.js similarity index 88% rename from lib/js/caml_obj.js rename to lib/js/primitive_object.js index bbae1cd144..0d13967ce2 100644 --- a/lib/js/caml_obj.js +++ b/lib/js/primitive_object.js @@ -1,25 +1,16 @@ 'use strict'; -let Caml = require("./caml.js"); +let Primitive_int = require("./primitive_int.js"); +let Primitive_bool = require("./primitive_bool.js"); +let Primitive_float = require("./primitive_float.js"); +let Primitive_string = require("./primitive_string.js"); let for_in = (function(o,foo){ for (var x in o) { foo(x) }}); -let update_dummy = (function(x,y){ - var k - if(Array.isArray(y)){ - for(k = 0; k < y.length ; ++k){ - x[k] = y[k] - } - if(y.TAG !== undefined){ - x.TAG = y.TAG - } - } else { - for (var k in y){ - x[k] = y[k] - } - } -}); +function updateDummy(prim0, prim1) { + Object.assign(prim0, prim1); +} function compare(a, b) { if (a === b) { @@ -30,12 +21,12 @@ function compare(a, b) { switch (a_type) { case "bigint" : if (b_type === "bigint") { - return Caml.float_compare(a, b); + return Primitive_float.compare(a, b); } break; case "boolean" : if (b_type === "boolean") { - return Caml.bool_compare(a, b); + return Primitive_bool.compare(a, b); } break; case "function" : @@ -49,12 +40,12 @@ function compare(a, b) { break; case "number" : if (b_type === "number") { - return Caml.float_compare(a, b); + return Primitive_float.compare(a, b); } break; case "string" : if (b_type === "string") { - return Caml.string_compare(a, b); + return Primitive_string.compare(a, b); } else { return 1; } @@ -117,7 +108,7 @@ function compare(a, b) { let tag_a = a.TAG; let tag_b = b.TAG; if (tag_a === 248) { - return Caml.int_compare(a[1], b[1]); + return Primitive_int.compare(a[1], b[1]); } if (tag_a === 251) { throw { @@ -224,7 +215,7 @@ function aux_obj_compare(a, b) { let match$1 = min_key_rhs.contents; if (match !== undefined) { if (match$1 !== undefined) { - return Caml.string_compare(match, match$1); + return Primitive_string.compare(match, match$1); } else { return -1; } @@ -316,30 +307,6 @@ function equal(a, b) { } } -function equal_null(x, y) { - if (y !== null) { - return equal(x, y); - } else { - return x === y; - } -} - -function equal_undefined(x, y) { - if (y !== undefined) { - return equal(x, y); - } else { - return x === y; - } -} - -function equal_nullable(x, y) { - if (y == null) { - return x === y; - } else { - return equal(x, y); - } -} - function notequal(a, b) { if ((typeof a === "number" || typeof a === "bigint") && (typeof b === "number" || typeof b === "bigint")) { return a !== b; @@ -396,12 +363,9 @@ function max(x, y) { } } -exports.update_dummy = update_dummy; +exports.updateDummy = updateDummy; exports.compare = compare; exports.equal = equal; -exports.equal_null = equal_null; -exports.equal_undefined = equal_undefined; -exports.equal_nullable = equal_nullable; exports.notequal = notequal; exports.greaterequal = greaterequal; exports.greaterthan = greaterthan; diff --git a/lib/js/camlinternalMod.js b/lib/js/primitive_object_extern.js similarity index 100% rename from lib/js/camlinternalMod.js rename to lib/js/primitive_object_extern.js diff --git a/lib/js/caml_option.js b/lib/js/primitive_option.js similarity index 77% rename from lib/js/caml_option.js rename to lib/js/primitive_option.js index 38cc8ad44e..53c29aae13 100644 --- a/lib/js/caml_option.js +++ b/lib/js/primitive_option.js @@ -19,7 +19,7 @@ function some(x) { } } -function nullable_to_opt(x) { +function fromNullable(x) { if (x == null) { return; } else { @@ -27,7 +27,7 @@ function nullable_to_opt(x) { } } -function undefined_to_opt(x) { +function fromUndefined(x) { if (x === undefined) { return; } else { @@ -35,7 +35,7 @@ function undefined_to_opt(x) { } } -function null_to_opt(x) { +function fromNull(x) { if (x === null) { return; } else { @@ -57,7 +57,7 @@ function valFromOption(x) { } } -function option_get(x) { +function toUndefined(x) { if (x === undefined) { return; } else { @@ -65,7 +65,7 @@ function option_get(x) { } } -function option_unwrap(x) { +function unwrapPolyVar(x) { if (x !== undefined) { return x.VAL; } else { @@ -73,12 +73,12 @@ function option_unwrap(x) { } } -exports.nullable_to_opt = nullable_to_opt; -exports.undefined_to_opt = undefined_to_opt; -exports.null_to_opt = null_to_opt; +exports.fromNullable = fromNullable; +exports.fromUndefined = fromUndefined; +exports.fromNull = fromNull; exports.valFromOption = valFromOption; exports.some = some; exports.isNested = isNested; -exports.option_get = option_get; -exports.option_unwrap = option_unwrap; +exports.toUndefined = toUndefined; +exports.unwrapPolyVar = unwrapPolyVar; /* No side effect */ diff --git a/lib/js/runtime_dict.js b/lib/js/primitive_promise.js similarity index 100% rename from lib/js/runtime_dict.js rename to lib/js/primitive_promise.js diff --git a/lib/js/primitive_string.js b/lib/js/primitive_string.js new file mode 100644 index 0000000000..6b75601613 --- /dev/null +++ b/lib/js/primitive_string.js @@ -0,0 +1,50 @@ +'use strict'; + + +function compare(s1, s2) { + if (s1 === s2) { + return 0; + } else if (s1 < s2) { + return -1; + } else { + return 1; + } +} + +function min(x, y) { + if (x < y) { + return x; + } else { + return y; + } +} + +function max(x, y) { + if (x > y) { + return x; + } else { + return y; + } +} + +function getChar(s, i) { + if (i >= s.length || i < 0) { + throw { + RE_EXN_ID: "Invalid_argument", + _1: "index out of bounds", + Error: new Error() + }; + } + return s.codePointAt(i); +} + +function make(n, ch) { + return String.fromCodePoint(ch).repeat(n); +} + +exports.compare = compare; +exports.min = min; +exports.max = max; +exports.getChar = getChar; +exports.make = make; +/* No side effect */ diff --git a/lib/js/runtime_promise.js b/lib/js/primitive_string_extern.js similarity index 100% rename from lib/js/runtime_promise.js rename to lib/js/primitive_string_extern.js diff --git a/lib/js/runtime_deriving.js b/lib/js/primitive_util.js similarity index 89% rename from lib/js/runtime_deriving.js rename to lib/js/primitive_util.js index 0f0f4175e3..5641a5a948 100644 --- a/lib/js/runtime_deriving.js +++ b/lib/js/primitive_util.js @@ -11,5 +11,8 @@ function raiseWhenNotFound(x) { return x; } +let Js; + +exports.Js = Js; exports.raiseWhenNotFound = raiseWhenNotFound; /* No side effect */ diff --git a/lib/js/queue.js b/lib/js/queue.js deleted file mode 100644 index a6a5df8fa2..0000000000 --- a/lib/js/queue.js +++ /dev/null @@ -1,178 +0,0 @@ -'use strict'; - -let Caml_exceptions = require("./caml_exceptions.js"); - -let Empty = /* @__PURE__ */Caml_exceptions.create("Queue.Empty"); - -function create() { - return { - length: 0, - first: "Nil", - last: "Nil" - }; -} - -function clear(q) { - q.length = 0; - q.first = "Nil"; - q.last = "Nil"; -} - -function add(x, q) { - let cell = { - TAG: "Cons", - content: x, - next: "Nil" - }; - let last = q.last; - if (typeof last !== "object") { - q.length = 1; - q.first = cell; - q.last = cell; - return; - } - q.length = q.length + 1 | 0; - last.next = cell; - q.last = cell; -} - -function peek(q) { - let match = q.first; - if (typeof match === "object") { - return match.content; - } - throw { - RE_EXN_ID: Empty, - Error: new Error() - }; -} - -function take(q) { - let match = q.first; - if (typeof match !== "object") { - throw { - RE_EXN_ID: Empty, - Error: new Error() - }; - } - let content = match.content; - let next = match.next; - if (typeof next !== "object") { - clear(q); - return content; - } - q.length = q.length - 1 | 0; - q.first = next; - return content; -} - -function copy(q) { - let q_res = { - length: q.length, - first: "Nil", - last: "Nil" - }; - let _prev = "Nil"; - let _cell = q.first; - while (true) { - let cell = _cell; - let prev = _prev; - if (typeof cell !== "object") { - q_res.last = prev; - return q_res; - } - let next = cell.next; - let res = { - TAG: "Cons", - content: cell.content, - next: "Nil" - }; - if (typeof prev !== "object") { - q_res.first = res; - } else { - prev.next = res; - } - _cell = next; - _prev = res; - continue; - }; -} - -function is_empty(q) { - return q.length === 0; -} - -function length(q) { - return q.length; -} - -function iter(f, q) { - let _cell = q.first; - while (true) { - let cell = _cell; - if (typeof cell !== "object") { - return; - } - let next = cell.next; - f(cell.content); - _cell = next; - continue; - }; -} - -function fold(f, accu, q) { - let _accu = accu; - let _cell = q.first; - while (true) { - let cell = _cell; - let accu$1 = _accu; - if (typeof cell !== "object") { - return accu$1; - } - let next = cell.next; - let accu$2 = f(accu$1, cell.content); - _cell = next; - _accu = accu$2; - continue; - }; -} - -function transfer(q1, q2) { - if (q1.length <= 0) { - return; - } - let last = q2.last; - if (typeof last !== "object") { - q2.length = q1.length; - q2.first = q1.first; - q2.last = q1.last; - return clear(q1); - } - q2.length = q2.length + q1.length | 0; - last.next = q1.first; - q2.last = q1.last; - clear(q1); -} - -let push = add; - -let pop = take; - -let top = peek; - -exports.Empty = Empty; -exports.create = create; -exports.add = add; -exports.push = push; -exports.take = take; -exports.pop = pop; -exports.peek = peek; -exports.top = top; -exports.clear = clear; -exports.copy = copy; -exports.is_empty = is_empty; -exports.length = length; -exports.iter = iter; -exports.fold = fold; -exports.transfer = transfer; -/* No side effect */ diff --git a/lib/js/random.js b/lib/js/random.js deleted file mode 100644 index 5202c9f031..0000000000 --- a/lib/js/random.js +++ /dev/null @@ -1,274 +0,0 @@ -'use strict'; - -let Caml = require("./caml.js"); -let $$Array = require("./array.js"); -let Int32 = require("./int32.js"); -let Int64 = require("./int64.js"); -let Digest = require("./digest.js"); -let Caml_array = require("./caml_array.js"); -let Caml_int64 = require("./caml_int64.js"); -let Caml_string = require("./caml_string.js"); - -function random_seed() { - return [(Math.floor(Math.random()*0x7fffffff))]; -} - -function assign(st1, st2) { - $$Array.blit(st2.st, 0, st1.st, 0, 55); - st1.idx = st2.idx; -} - -function full_init(s, seed) { - let combine = (accu, x) => Digest.string(accu + String(x)); - let extract = d => ((Caml_string.get(d, 0) + (Caml_string.get(d, 1) << 8) | 0) + (Caml_string.get(d, 2) << 16) | 0) + (Caml_string.get(d, 3) << 24) | 0; - let seed$1 = seed.length === 0 ? [0] : seed; - let l = seed$1.length; - for (let i = 0; i <= 54; ++i) { - Caml_array.set(s.st, i, i); - } - let accu = "x"; - for (let i$1 = 0, i_finish = 54 + ( - 55 > l ? 55 : l - ) | 0; i$1 <= i_finish; ++i$1) { - let j = i$1 % 55; - let k = i$1 % l; - accu = combine(accu, Caml_array.get(seed$1, k)); - Caml_array.set(s.st, j, (Caml_array.get(s.st, j) ^ extract(accu)) & 1073741823); - } - s.idx = 0; -} - -function make(seed) { - let result = { - st: Caml_array.make(55, 0), - idx: 0 - }; - full_init(result, seed); - return result; -} - -function make_self_init() { - return make(random_seed()); -} - -function copy(s) { - let result = { - st: Caml_array.make(55, 0), - idx: 0 - }; - assign(result, s); - return result; -} - -function bits(s) { - s.idx = (s.idx + 1 | 0) % 55; - let curval = Caml_array.get(s.st, s.idx); - let newval = Caml_array.get(s.st, (s.idx + 24 | 0) % 55) + (curval ^ (curval >>> 25) & 31) | 0; - let newval30 = newval & 1073741823; - Caml_array.set(s.st, s.idx, newval30); - return newval30; -} - -function int(s, bound) { - if (bound > 1073741823 || bound <= 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Random.int", - Error: new Error() - }; - } - while (true) { - let r = bits(s); - let v = r % bound; - if ((r - v | 0) <= ((1073741823 - bound | 0) + 1 | 0)) { - return v; - } - continue; - }; -} - -function int32(s, bound) { - if (bound <= 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Random.int32", - Error: new Error() - }; - } - while (true) { - let b1 = bits(s); - let b2 = ((bits(s) & 1) << 30); - let r = b1 | b2; - let v = r % bound; - if ((r - v | 0) <= ((Int32.max_int - bound | 0) + 1 | 0)) { - return v; - } - continue; - }; -} - -function int64(s, bound) { - if (Caml.i64_le(bound, Caml_int64.zero)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Random.int64", - Error: new Error() - }; - } - while (true) { - let b1 = Caml_int64.of_int32(bits(s)); - let b2 = Caml_int64.lsl_(Caml_int64.of_int32(bits(s)), 30); - let b3 = Caml_int64.lsl_(Caml_int64.of_int32(bits(s) & 7), 60); - let r = Caml_int64.or_(b1, Caml_int64.or_(b2, b3)); - let v = Caml_int64.mod_(r, bound); - if (!Caml.i64_gt(Caml_int64.sub(r, v), Caml_int64.add(Caml_int64.sub(Int64.max_int, bound), Caml_int64.one))) { - return v; - } - continue; - }; -} - -function rawfloat(s) { - let r1 = bits(s); - let r2 = bits(s); - return (r1 / 1073741824.0 + r2) / 1073741824.0; -} - -function float(s, bound) { - return rawfloat(s) * bound; -} - -function bool(s) { - return (bits(s) & 1) === 0; -} - -let $$default = { - st: [ - 987910699, - 495797812, - 364182224, - 414272206, - 318284740, - 990407751, - 383018966, - 270373319, - 840823159, - 24560019, - 536292337, - 512266505, - 189156120, - 730249596, - 143776328, - 51606627, - 140166561, - 366354223, - 1003410265, - 700563762, - 981890670, - 913149062, - 526082594, - 1021425055, - 784300257, - 667753350, - 630144451, - 949649812, - 48546892, - 415514493, - 258888527, - 511570777, - 89983870, - 283659902, - 308386020, - 242688715, - 482270760, - 865188196, - 1027664170, - 207196989, - 193777847, - 619708188, - 671350186, - 149669678, - 257044018, - 87658204, - 558145612, - 183450813, - 28133145, - 901332182, - 710253903, - 510646120, - 652377910, - 409934019, - 801085050 - ], - idx: 0 -}; - -function bits$1() { - return bits($$default); -} - -function int$1(bound) { - return int($$default, bound); -} - -function int32$1(bound) { - return int32($$default, bound); -} - -function int64$1(bound) { - return int64($$default, bound); -} - -function float$1(scale) { - return rawfloat($$default) * scale; -} - -function bool$1() { - return bool($$default); -} - -function full_init$1(seed) { - full_init($$default, seed); -} - -function init(seed) { - full_init($$default, [seed]); -} - -function self_init() { - full_init$1(random_seed()); -} - -function get_state() { - return copy($$default); -} - -function set_state(s) { - assign($$default, s); -} - -let State = { - make: make, - make_self_init: make_self_init, - copy: copy, - bits: bits, - int: int, - int32: int32, - int64: int64, - float: float, - bool: bool -}; - -exports.init = init; -exports.full_init = full_init$1; -exports.self_init = self_init; -exports.bits = bits$1; -exports.int = int$1; -exports.int32 = int32$1; -exports.int64 = int64$1; -exports.float = float$1; -exports.bool = bool$1; -exports.State = State; -exports.get_state = get_state; -exports.set_state = set_state; -/* No side effect */ diff --git a/lib/js/set.js b/lib/js/set.js index 38b2616ce9..ae1b9f17e6 100644 --- a/lib/js/set.js +++ b/lib/js/set.js @@ -1,957 +1 @@ -'use strict'; - -let List = require("./list.js"); -let Caml_option = require("./caml_option.js"); - -function Make(funarg) { - let height = param => { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } - }; - let create = (l, v, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - }; - let bal = (l, v, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - let lr = l.r; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, create(lr, v, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, lr.l), lr.v, create(lr.r, v, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - let rr = r.r; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, v, rl), rv, rr); - } - if (typeof rl === "object") { - return create(create(l, v, rl.l), rl.v, create(rl.r, rv, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - }; - let add = (x, param) => { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - return param; - } - if (c < 0) { - let ll = add(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = add(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } - }; - let singleton = x => ({ - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }); - let add_min_element = (x, param) => { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(add_min_element(x, param.l), param.v, param.r); - } - }; - let add_max_element = (x, param) => { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(param.l, param.v, add_max_element(x, param.r)); - } - }; - let join = (l, v, r) => { - if (typeof l !== "object") { - return add_min_element(v, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_element(v, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, join(l.r, v, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, r.l), r.v, r.r); - } else { - return create(l, v, r); - } - }; - let min_elt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.v; - } - _param = l; - continue; - }; - }; - let min_elt_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return Caml_option.some(param.v); - } - _param = l; - continue; - }; - }; - let max_elt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let r = param.r; - if (typeof r !== "object") { - return param.v; - } - _param = r; - continue; - }; - }; - let max_elt_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return Caml_option.some(param.v); - } - _param = r; - continue; - }; - }; - let remove_min_elt = param => { - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.remove_min_elt", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_elt(l), param.v, param.r); - } - }; - let concat = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } else if (typeof t2 !== "object") { - return t1; - } else { - return join(t1, min_elt(t2), remove_min_elt(t2)); - } - }; - let split = (x, param) => { - if (typeof param !== "object") { - return [ - "Empty", - false, - "Empty" - ]; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - return [ - l, - true, - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, match$1[0]), - match$1[1], - match$1[2] - ]; - }; - let is_empty = param => { - if (typeof param !== "object") { - return true; - } else { - return false; - } - }; - let mem = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = funarg.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let remove = (x, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = funarg.compare(x, v); - if (c === 0) { - if (typeof l !== "object") { - return r; - } else if (typeof r !== "object") { - return l; - } else { - return bal(l, min_elt(r), remove_min_elt(r)); - } - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } - }; - let union = (s1, s2) => { - if (typeof s1 !== "object") { - return s2; - } - let h1 = s1.h; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let h2 = s2.h; - let v2 = s2.v; - if (h1 >= h2) { - if (h2 === 1) { - return add(v2, s1); - } - let match = split(v1, s2); - return join(union(s1.l, match[0]), v1, union(s1.r, match[2])); - } - if (h1 === 1) { - return add(v1, s2); - } - let match$1 = split(v2, s1); - return join(union(match$1[0], s2.l), v2, union(match$1[2], s2.r)); - }; - let inter = (s1, s2) => { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return "Empty"; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return join(inter(l1, l2), v1, inter(r1, match[2])); - } else { - return concat(inter(l1, l2), inter(r1, match[2])); - } - }; - let diff = (s1, s2) => { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return s1; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return concat(diff(l1, l2), diff(r1, match[2])); - } else { - return join(diff(l1, l2), v1, diff(r1, match[2])); - } - }; - let cons_enum = (_s, _e) => { - while (true) { - let e = _e; - let s = _s; - if (typeof s !== "object") { - return e; - } - _e = { - TAG: "More", - _0: s.v, - _1: s.r, - _2: e - }; - _s = s.l; - continue; - }; - }; - let compare = (s1, s2) => { - let _e1 = cons_enum(s1, "End"); - let _e2 = cons_enum(s2, "End"); - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = funarg.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - _e2 = cons_enum(e2._1, e2._2); - _e1 = cons_enum(e1._1, e1._2); - continue; - }; - }; - let equal = (s1, s2) => compare(s1, s2) === 0; - let subset = (_s1, _s2) => { - while (true) { - let s2 = _s2; - let s1 = _s1; - if (typeof s1 !== "object") { - return true; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - if (typeof s2 !== "object") { - return false; - } - let r2 = s2.r; - let l2 = s2.l; - let c = funarg.compare(v1, s2.v); - if (c === 0) { - if (!subset(l1, l2)) { - return false; - } - _s2 = r2; - _s1 = r1; - continue; - } - if (c < 0) { - if (!subset({ - TAG: "Node", - l: l1, - v: v1, - r: "Empty", - h: 0 - }, l2)) { - return false; - } - _s1 = r1; - continue; - } - if (!subset({ - TAG: "Node", - l: "Empty", - v: v1, - r: r1, - h: 0 - }, r2)) { - return false; - } - _s1 = l1; - continue; - }; - }; - let iter = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v); - _param = param.r; - continue; - }; - }; - let fold = (f, _s, _accu) => { - while (true) { - let accu = _accu; - let s = _s; - if (typeof s !== "object") { - return accu; - } - _accu = f(s.v, fold(f, s.l, accu)); - _s = s.r; - continue; - }; - }; - let for_all = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; - }; - let exists = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; - }; - let filter = (p, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pv = p(v); - let r$p = filter(p, r); - if (pv) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, r$p); - } - } else { - return concat(l$p, r$p); - } - }; - let partition = (p, param) => { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pv = p(v); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pv) { - return [ - join(lt, v, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, rf) - ]; - } - }; - let cardinal = param => { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } - }; - let elements_aux = (_accu, _param) => { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: param.v, - tl: elements_aux(accu, param.r) - }; - continue; - }; - }; - let elements = s => elements_aux(/* [] */0, s); - let find = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - let c = funarg.compare(x, v); - if (c === 0) { - return v; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let find_first = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return v0; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; - }; - let find_first_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.l; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return Caml_option.some(v0); - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.l; - _v0 = v$1; - continue; - } - _param$1 = param$1.r; - continue; - }; - } - _param = param.r; - continue; - }; - }; - let find_last = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return v0; - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; - }; - let find_last_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - let _v0 = v; - let _param$1 = param.r; - while (true) { - let param$1 = _param$1; - let v0 = _v0; - if (typeof param$1 !== "object") { - return Caml_option.some(v0); - } - let v$1 = param$1.v; - if (f(v$1)) { - _param$1 = param$1.r; - _v0 = v$1; - continue; - } - _param$1 = param$1.l; - continue; - }; - } - _param = param.l; - continue; - }; - }; - let find_opt = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - let c = funarg.compare(x, v); - if (c === 0) { - return Caml_option.some(v); - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let map = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = map(f, l); - let v$p = f(v); - let r$p = map(f, r); - if (l === l$p && v === v$p && r === r$p) { - return param; - } else if ((l$p === "Empty" || funarg.compare(max_elt(l$p), v$p) < 0) && (r$p === "Empty" || funarg.compare(v$p, min_elt(r$p)) < 0)) { - return join(l$p, v$p, r$p); - } else { - return union(l$p, add(v$p, r$p)); - } - }; - let of_list = l => { - if (!l) { - return "Empty"; - } - let match = l.tl; - let x0 = l.hd; - if (!match) { - return singleton(x0); - } - let match$1 = match.tl; - let x1 = match.hd; - if (!match$1) { - return add(x1, singleton(x0)); - } - let match$2 = match$1.tl; - let x2 = match$1.hd; - if (!match$2) { - return add(x2, add(x1, singleton(x0))); - } - let match$3 = match$2.tl; - let x3 = match$2.hd; - if (match$3) { - if (match$3.tl) { - let l$1 = List.sort_uniq(funarg.compare, l); - let sub = (n, l) => { - switch (n) { - case 0 : - return [ - "Empty", - l - ]; - case 1 : - if (l) { - return [ - { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - l.tl - ]; - } - break; - case 2 : - if (l) { - let match = l.tl; - if (match) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match.hd, - r: "Empty", - h: 2 - }, - match.tl - ]; - } - - } - break; - case 3 : - if (l) { - let match$1 = l.tl; - if (match$1) { - let match$2 = match$1.tl; - if (match$2) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match$1.hd, - r: { - TAG: "Node", - l: "Empty", - v: match$2.hd, - r: "Empty", - h: 1 - }, - h: 2 - }, - match$2.tl - ]; - } - - } - - } - break; - } - let nl = n / 2 | 0; - let match$3 = sub(nl, l); - let l$1 = match$3[1]; - if (l$1) { - let match$4 = sub((n - nl | 0) - 1 | 0, l$1.tl); - return [ - create(match$3[0], l$1.hd, match$4[0]), - match$4[1] - ]; - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "set.res", - 691, - 20 - ], - Error: new Error() - }; - }; - return sub(List.length(l$1), l$1)[0]; - } else { - return add(match$3.hd, add(x3, add(x2, add(x1, singleton(x0))))); - } - } else { - return add(x3, add(x2, add(x1, singleton(x0)))); - } - }; - return { - empty: "Empty", - is_empty: is_empty, - mem: mem, - add: add, - singleton: singleton, - remove: remove, - union: union, - inter: inter, - diff: diff, - compare: compare, - equal: equal, - subset: subset, - iter: iter, - map: map, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - elements: elements, - min_elt: min_elt, - min_elt_opt: min_elt_opt, - max_elt: max_elt, - max_elt_opt: max_elt_opt, - choose: min_elt, - choose_opt: min_elt_opt, - split: split, - find: find, - find_opt: find_opt, - find_first: find_first, - find_first_opt: find_first_opt, - find_last: find_last, - find_last_opt: find_last_opt, - of_list: of_list - }; -} - -exports.Make = Make; -/* No side effect */ +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/lib/js/setLabels.js b/lib/js/setLabels.js deleted file mode 100644 index 2b2af67dce..0000000000 --- a/lib/js/setLabels.js +++ /dev/null @@ -1,988 +0,0 @@ -'use strict'; - -let List = require("./list.js"); -let Caml_option = require("./caml_option.js"); - -function Make(Ord) { - let height = param => { - if (typeof param !== "object") { - return 0; - } else { - return param.h; - } - }; - let create = (l, v, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - }; - let bal = (l, v, r) => { - let hl; - hl = typeof l !== "object" ? 0 : l.h; - let hr; - hr = typeof r !== "object" ? 0 : r.h; - if (hl > (hr + 2 | 0)) { - if (typeof l !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - let lr = l.r; - let lv = l.v; - let ll = l.l; - if (height(ll) >= height(lr)) { - return create(ll, lv, create(lr, v, r)); - } - if (typeof lr === "object") { - return create(create(ll, lv, lr.l), lr.v, create(lr.r, v, r)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - if (hr <= (hl + 2 | 0)) { - return { - TAG: "Node", - l: l, - v: v, - r: r, - h: hl >= hr ? hl + 1 | 0 : hr + 1 | 0 - }; - } - if (typeof r !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - } - let rr = r.r; - let rv = r.v; - let rl = r.l; - if (height(rr) >= height(rl)) { - return create(create(l, v, rl), rv, rr); - } - if (typeof rl === "object") { - return create(create(l, v, rl.l), rl.v, create(rl.r, rv, rr)); - } - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.bal", - Error: new Error() - }; - }; - let add = (x, param) => { - if (typeof param !== "object") { - return { - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - return param; - } - if (c < 0) { - let ll = add(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = add(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } - }; - let singleton = x => ({ - TAG: "Node", - l: "Empty", - v: x, - r: "Empty", - h: 1 - }); - let add_min_element = (x, param) => { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(add_min_element(x, param.l), param.v, param.r); - } - }; - let add_max_element = (x, param) => { - if (typeof param !== "object") { - return singleton(x); - } else { - return bal(param.l, param.v, add_max_element(x, param.r)); - } - }; - let join = (l, v, r) => { - if (typeof l !== "object") { - return add_min_element(v, r); - } - let lh = l.h; - if (typeof r !== "object") { - return add_max_element(v, l); - } - let rh = r.h; - if (lh > (rh + 2 | 0)) { - return bal(l.l, l.v, join(l.r, v, r)); - } else if (rh > (lh + 2 | 0)) { - return bal(join(l, v, r.l), r.v, r.r); - } else { - return create(l, v, r); - } - }; - let min_elt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.v; - } - _param = l; - continue; - }; - }; - let min_elt_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let l = param.l; - if (typeof l !== "object") { - return Caml_option.some(param.v); - } - _param = l; - continue; - }; - }; - let max_elt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let r = param.r; - if (typeof r !== "object") { - return param.v; - } - _param = r; - continue; - }; - }; - let max_elt_opt = _param => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let r = param.r; - if (typeof r !== "object") { - return Caml_option.some(param.v); - } - _param = r; - continue; - }; - }; - let remove_min_elt = param => { - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Set.remove_min_elt", - Error: new Error() - }; - } - let l = param.l; - if (typeof l !== "object") { - return param.r; - } else { - return bal(remove_min_elt(l), param.v, param.r); - } - }; - let merge = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } else if (typeof t2 !== "object") { - return t1; - } else { - return bal(t1, min_elt(t2), remove_min_elt(t2)); - } - }; - let concat = (t1, t2) => { - if (typeof t1 !== "object") { - return t2; - } else if (typeof t2 !== "object") { - return t1; - } else { - return join(t1, min_elt(t2), remove_min_elt(t2)); - } - }; - let split = (x, param) => { - if (typeof param !== "object") { - return [ - "Empty", - false, - "Empty" - ]; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - return [ - l, - true, - r - ]; - } - if (c < 0) { - let match = split(x, l); - return [ - match[0], - match[1], - join(match[2], v, r) - ]; - } - let match$1 = split(x, r); - return [ - join(l, v, match$1[0]), - match$1[1], - match$1[2] - ]; - }; - let is_empty = param => { - if (typeof param !== "object") { - return true; - } else { - return false; - } - }; - let mem = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - let c = Ord.compare(x, param.v); - if (c === 0) { - return true; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let remove = (x, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let c = Ord.compare(x, v); - if (c === 0) { - return merge(l, r); - } - if (c < 0) { - let ll = remove(x, l); - if (l === ll) { - return param; - } else { - return bal(ll, v, r); - } - } - let rr = remove(x, r); - if (r === rr) { - return param; - } else { - return bal(l, v, rr); - } - }; - let union = (s1, s2) => { - if (typeof s1 !== "object") { - return s2; - } - let h1 = s1.h; - let v1 = s1.v; - if (typeof s2 !== "object") { - return s1; - } - let h2 = s2.h; - let v2 = s2.v; - if (h1 >= h2) { - if (h2 === 1) { - return add(v2, s1); - } - let match = split(v1, s2); - return join(union(s1.l, match[0]), v1, union(s1.r, match[2])); - } - if (h1 === 1) { - return add(v1, s2); - } - let match$1 = split(v2, s1); - return join(union(match$1[0], s2.l), v2, union(match$1[2], s2.r)); - }; - let inter = (s1, s2) => { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return "Empty"; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return join(inter(l1, l2), v1, inter(r1, match[2])); - } else { - return concat(inter(l1, l2), inter(r1, match[2])); - } - }; - let diff = (s1, s2) => { - if (typeof s1 !== "object") { - return "Empty"; - } - if (typeof s2 !== "object") { - return s1; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - let match = split(v1, s2); - let l2 = match[0]; - if (match[1]) { - return concat(diff(l1, l2), diff(r1, match[2])); - } else { - return join(diff(l1, l2), v1, diff(r1, match[2])); - } - }; - let cons_enum = (_s, _e) => { - while (true) { - let e = _e; - let s = _s; - if (typeof s !== "object") { - return e; - } - _e = { - TAG: "More", - _0: s.v, - _1: s.r, - _2: e - }; - _s = s.l; - continue; - }; - }; - let compare_aux = (_e1, _e2) => { - while (true) { - let e2 = _e2; - let e1 = _e1; - if (typeof e1 !== "object") { - if (typeof e2 !== "object") { - return 0; - } else { - return -1; - } - } - if (typeof e2 !== "object") { - return 1; - } - let c = Ord.compare(e1._0, e2._0); - if (c !== 0) { - return c; - } - _e2 = cons_enum(e2._1, e2._2); - _e1 = cons_enum(e1._1, e1._2); - continue; - }; - }; - let compare = (s1, s2) => compare_aux(cons_enum(s1, "End"), cons_enum(s2, "End")); - let equal = (s1, s2) => compare(s1, s2) === 0; - let subset = (_s1, _s2) => { - while (true) { - let s2 = _s2; - let s1 = _s1; - if (typeof s1 !== "object") { - return true; - } - let r1 = s1.r; - let v1 = s1.v; - let l1 = s1.l; - if (typeof s2 !== "object") { - return false; - } - let r2 = s2.r; - let l2 = s2.l; - let c = Ord.compare(v1, s2.v); - if (c === 0) { - if (!subset(l1, l2)) { - return false; - } - _s2 = r2; - _s1 = r1; - continue; - } - if (c < 0) { - if (!subset({ - TAG: "Node", - l: l1, - v: v1, - r: "Empty", - h: 0 - }, l2)) { - return false; - } - _s1 = r1; - continue; - } - if (!subset({ - TAG: "Node", - l: "Empty", - v: v1, - r: r1, - h: 0 - }, r2)) { - return false; - } - _s1 = l1; - continue; - }; - }; - let iter = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - iter(f, param.l); - f(param.v); - _param = param.r; - continue; - }; - }; - let fold = (f, _s, _accu) => { - while (true) { - let accu = _accu; - let s = _s; - if (typeof s !== "object") { - return accu; - } - _accu = f(s.v, fold(f, s.l, accu)); - _s = s.r; - continue; - }; - }; - let for_all = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return true; - } - if (!p(param.v)) { - return false; - } - if (!for_all(p, param.l)) { - return false; - } - _param = param.r; - continue; - }; - }; - let exists = (p, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return false; - } - if (p(param.v)) { - return true; - } - if (exists(p, param.l)) { - return true; - } - _param = param.r; - continue; - }; - }; - let filter = (p, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = filter(p, l); - let pv = p(v); - let r$p = filter(p, r); - if (pv) { - if (l === l$p && r === r$p) { - return param; - } else { - return join(l$p, v, r$p); - } - } else { - return concat(l$p, r$p); - } - }; - let partition = (p, param) => { - if (typeof param !== "object") { - return [ - "Empty", - "Empty" - ]; - } - let v = param.v; - let match = partition(p, param.l); - let lf = match[1]; - let lt = match[0]; - let pv = p(v); - let match$1 = partition(p, param.r); - let rf = match$1[1]; - let rt = match$1[0]; - if (pv) { - return [ - join(lt, v, rt), - concat(lf, rf) - ]; - } else { - return [ - concat(lt, rt), - join(lf, v, rf) - ]; - } - }; - let cardinal = param => { - if (typeof param !== "object") { - return 0; - } else { - return (cardinal(param.l) + 1 | 0) + cardinal(param.r) | 0; - } - }; - let elements_aux = (_accu, _param) => { - while (true) { - let param = _param; - let accu = _accu; - if (typeof param !== "object") { - return accu; - } - _param = param.l; - _accu = { - hd: param.v, - tl: elements_aux(accu, param.r) - }; - continue; - }; - }; - let elements = s => elements_aux(/* [] */0, s); - let find = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - let c = Ord.compare(x, v); - if (c === 0) { - return v; - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let find_first_aux = (_v0, f, _param) => { - while (true) { - let param = _param; - let v0 = _v0; - if (typeof param !== "object") { - return v0; - } - let v = param.v; - if (f(v)) { - _param = param.l; - _v0 = v; - continue; - } - _param = param.r; - continue; - }; - }; - let find_first = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - return find_first_aux(v, f, param.l); - } - _param = param.r; - continue; - }; - }; - let find_first_opt_aux = (_v0, f, _param) => { - while (true) { - let param = _param; - let v0 = _v0; - if (typeof param !== "object") { - return Caml_option.some(v0); - } - let v = param.v; - if (f(v)) { - _param = param.l; - _v0 = v; - continue; - } - _param = param.r; - continue; - }; - }; - let find_first_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - return find_first_opt_aux(v, f, param.l); - } - _param = param.r; - continue; - }; - }; - let find_last_aux = (_v0, f, _param) => { - while (true) { - let param = _param; - let v0 = _v0; - if (typeof param !== "object") { - return v0; - } - let v = param.v; - if (f(v)) { - _param = param.r; - _v0 = v; - continue; - } - _param = param.l; - continue; - }; - }; - let find_last = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - let v = param.v; - if (f(v)) { - return find_last_aux(v, f, param.r); - } - _param = param.l; - continue; - }; - }; - let find_last_opt_aux = (_v0, f, _param) => { - while (true) { - let param = _param; - let v0 = _v0; - if (typeof param !== "object") { - return Caml_option.some(v0); - } - let v = param.v; - if (f(v)) { - _param = param.r; - _v0 = v; - continue; - } - _param = param.l; - continue; - }; - }; - let find_last_opt = (f, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - if (f(v)) { - return find_last_opt_aux(v, f, param.r); - } - _param = param.l; - continue; - }; - }; - let find_opt = (x, _param) => { - while (true) { - let param = _param; - if (typeof param !== "object") { - return; - } - let v = param.v; - let c = Ord.compare(x, v); - if (c === 0) { - return Caml_option.some(v); - } - _param = c < 0 ? param.l : param.r; - continue; - }; - }; - let try_join = (l, v, r) => { - if ((l === "Empty" || Ord.compare(max_elt(l), v) < 0) && (r === "Empty" || Ord.compare(v, min_elt(r)) < 0)) { - return join(l, v, r); - } else { - return union(l, add(v, r)); - } - }; - let map = (f, param) => { - if (typeof param !== "object") { - return "Empty"; - } - let r = param.r; - let v = param.v; - let l = param.l; - let l$p = map(f, l); - let v$p = f(v); - let r$p = map(f, r); - if (l === l$p && v === v$p && r === r$p) { - return param; - } else { - return try_join(l$p, v$p, r$p); - } - }; - let of_sorted_list = l => { - let sub = (n, l) => { - switch (n) { - case 0 : - return [ - "Empty", - l - ]; - case 1 : - if (l) { - return [ - { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - l.tl - ]; - } - break; - case 2 : - if (l) { - let match = l.tl; - if (match) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match.hd, - r: "Empty", - h: 2 - }, - match.tl - ]; - } - - } - break; - case 3 : - if (l) { - let match$1 = l.tl; - if (match$1) { - let match$2 = match$1.tl; - if (match$2) { - return [ - { - TAG: "Node", - l: { - TAG: "Node", - l: "Empty", - v: l.hd, - r: "Empty", - h: 1 - }, - v: match$1.hd, - r: { - TAG: "Node", - l: "Empty", - v: match$2.hd, - r: "Empty", - h: 1 - }, - h: 2 - }, - match$2.tl - ]; - } - - } - - } - break; - } - let nl = n / 2 | 0; - let match$3 = sub(nl, l); - let l$1 = match$3[1]; - if (l$1) { - let match$4 = sub((n - nl | 0) - 1 | 0, l$1.tl); - return [ - create(match$3[0], l$1.hd, match$4[0]), - match$4[1] - ]; - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "setLabels.res", - 691, - 20 - ], - Error: new Error() - }; - }; - return sub(List.length(l), l)[0]; - }; - let of_list = l => { - if (!l) { - return "Empty"; - } - let match = l.tl; - let x0 = l.hd; - if (!match) { - return singleton(x0); - } - let match$1 = match.tl; - let x1 = match.hd; - if (!match$1) { - return add(x1, singleton(x0)); - } - let match$2 = match$1.tl; - let x2 = match$1.hd; - if (!match$2) { - return add(x2, add(x1, singleton(x0))); - } - let match$3 = match$2.tl; - let x3 = match$2.hd; - if (match$3) { - if (match$3.tl) { - return of_sorted_list(List.sort_uniq(Ord.compare, l)); - } else { - return add(match$3.hd, add(x3, add(x2, add(x1, singleton(x0))))); - } - } else { - return add(x3, add(x2, add(x1, singleton(x0)))); - } - }; - return { - height: height, - create: create, - bal: bal, - add: add, - singleton: singleton, - add_min_element: add_min_element, - add_max_element: add_max_element, - join: join, - min_elt: min_elt, - min_elt_opt: min_elt_opt, - max_elt: max_elt, - max_elt_opt: max_elt_opt, - remove_min_elt: remove_min_elt, - merge: merge, - concat: concat, - split: split, - empty: "Empty", - is_empty: is_empty, - mem: mem, - remove: remove, - union: union, - inter: inter, - diff: diff, - cons_enum: cons_enum, - compare_aux: compare_aux, - compare: compare, - equal: equal, - subset: subset, - iter: iter, - fold: fold, - for_all: for_all, - exists: exists, - filter: filter, - partition: partition, - cardinal: cardinal, - elements_aux: elements_aux, - elements: elements, - choose: min_elt, - choose_opt: min_elt_opt, - find: find, - find_first_aux: find_first_aux, - find_first: find_first, - find_first_opt_aux: find_first_opt_aux, - find_first_opt: find_first_opt, - find_last_aux: find_last_aux, - find_last: find_last, - find_last_opt_aux: find_last_opt_aux, - find_last_opt: find_last_opt, - find_opt: find_opt, - try_join: try_join, - map: map, - of_sorted_list: of_sorted_list, - of_list: of_list - }; -} - -exports.Make = Make; -/* No side effect */ diff --git a/lib/js/sort.js b/lib/js/sort.js deleted file mode 100644 index f065720f4d..0000000000 --- a/lib/js/sort.js +++ /dev/null @@ -1,165 +0,0 @@ -'use strict'; - - -function merge(order, l1, l2) { - if (!l1) { - return l2; - } - if (!l2) { - return l1; - } - let h2 = l2.hd; - let h1 = l1.hd; - if (order(h1, h2)) { - return { - hd: h1, - tl: merge(order, l1.tl, l2) - }; - } else { - return { - hd: h2, - tl: merge(order, l1, l2.tl) - }; - } -} - -function list(order, l) { - let initlist = param => { - if (!param) { - return /* [] */0; - } - let match = param.tl; - let e = param.hd; - if (!match) { - return { - hd: { - hd: e, - tl: /* [] */0 - }, - tl: /* [] */0 - }; - } - let e2 = match.hd; - return { - hd: order(e, e2) ? ({ - hd: e, - tl: { - hd: e2, - tl: /* [] */0 - } - }) : ({ - hd: e2, - tl: { - hd: e, - tl: /* [] */0 - } - }), - tl: initlist(match.tl) - }; - }; - let merge2 = param => { - if (!param) { - return param; - } - let match = param.tl; - if (match) { - return { - hd: merge(order, param.hd, match.hd), - tl: merge2(match.tl) - }; - } else { - return param; - } - }; - let _param = initlist(l); - while (true) { - let param = _param; - if (!param) { - return /* [] */0; - } - if (!param.tl) { - return param.hd; - } - _param = merge2(param); - continue; - }; -} - -function swap(arr, i, j) { - let tmp = arr[i]; - arr[i] = arr[j]; - arr[j] = tmp; -} - -function array(cmp, arr) { - let qsort = (_lo, _hi) => { - while (true) { - let hi = _hi; - let lo = _lo; - if ((hi - lo | 0) < 6) { - return; - } - let mid = ((lo + hi | 0) >>> 1); - if (cmp(arr[mid], arr[lo])) { - swap(arr, mid, lo); - } - if (cmp(arr[hi], arr[mid])) { - swap(arr, mid, hi); - if (cmp(arr[mid], arr[lo])) { - swap(arr, mid, lo); - } - - } - let pivot = arr[mid]; - let i = lo + 1 | 0; - let j = hi - 1 | 0; - if (!cmp(pivot, arr[hi]) || !cmp(arr[lo], pivot)) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "Sort.array", - Error: new Error() - }; - } - while (i < j) { - while (!cmp(pivot, arr[i])) { - i = i + 1 | 0; - }; - while (!cmp(arr[j], pivot)) { - j = j - 1 | 0; - }; - if (i < j) { - swap(arr, i, j); - } - i = i + 1 | 0; - j = j - 1 | 0; - }; - if ((j - lo | 0) <= (hi - i | 0)) { - qsort(lo, j); - _lo = i; - continue; - } - qsort(i, hi); - _hi = j; - continue; - }; - }; - qsort(0, arr.length - 1 | 0); - for (let i = 1, i_finish = arr.length; i < i_finish; ++i) { - let val_i = arr[i]; - if (!cmp(arr[i - 1 | 0], val_i)) { - arr[i] = arr[i - 1 | 0]; - let j = i - 1 | 0; - while (j >= 1 && !cmp(arr[j - 1 | 0], val_i)) { - arr[j] = arr[j - 1 | 0]; - j = j - 1 | 0; - }; - arr[j] = val_i; - } - - } -} - -exports.list = list; -exports.array = array; -exports.merge = merge; -/* No side effect */ diff --git a/lib/js/stack.js b/lib/js/stack.js deleted file mode 100644 index 8e9b67f45e..0000000000 --- a/lib/js/stack.js +++ /dev/null @@ -1,86 +0,0 @@ -'use strict'; - -let List = require("./list.js"); -let Caml_exceptions = require("./caml_exceptions.js"); - -let Empty = /* @__PURE__ */Caml_exceptions.create("Stack.Empty"); - -function create() { - return { - c: /* [] */0, - len: 0 - }; -} - -function clear(s) { - s.c = /* [] */0; - s.len = 0; -} - -function copy(s) { - return { - c: s.c, - len: s.len - }; -} - -function push(x, s) { - s.c = { - hd: x, - tl: s.c - }; - s.len = s.len + 1 | 0; -} - -function pop(s) { - let match = s.c; - if (match) { - s.c = match.tl; - s.len = s.len - 1 | 0; - return match.hd; - } - throw { - RE_EXN_ID: Empty, - Error: new Error() - }; -} - -function top(s) { - let match = s.c; - if (match) { - return match.hd; - } - throw { - RE_EXN_ID: Empty, - Error: new Error() - }; -} - -function is_empty(s) { - return s.c === /* [] */0; -} - -function length(s) { - return s.len; -} - -function iter(f, s) { - List.iter(f, s.c); -} - -function fold(f, acc, s) { - return List.fold_left(f, acc, s.c); -} - -exports.Empty = Empty; -exports.create = create; -exports.push = push; -exports.pop = pop; -exports.top = top; -exports.clear = clear; -exports.copy = copy; -exports.is_empty = is_empty; -exports.length = length; -exports.iter = iter; -exports.fold = fold; -/* No side effect */ diff --git a/lib/js/stdLabels.js b/lib/js/stdLabels.js deleted file mode 100644 index b8942f1839..0000000000 --- a/lib/js/stdLabels.js +++ /dev/null @@ -1,16 +0,0 @@ -'use strict'; - - -let $$Array; - -let Bytes; - -let List; - -let $$String; - -exports.$$Array = $$Array; -exports.Bytes = Bytes; -exports.List = List; -exports.$$String = $$String; -/* No side effect */ diff --git a/lib/js/stream.js b/lib/js/stream.js deleted file mode 100644 index d4c089ee7b..0000000000 --- a/lib/js/stream.js +++ /dev/null @@ -1,469 +0,0 @@ -'use strict'; - -let List = require("./list.js"); -let Caml_bytes = require("./caml_bytes.js"); -let Caml_option = require("./caml_option.js"); -let Caml_string = require("./caml_string.js"); -let Caml_exceptions = require("./caml_exceptions.js"); -let CamlinternalLazy = require("./camlinternalLazy.js"); - -let Failure = /* @__PURE__ */Caml_exceptions.create("Stream.Failure"); - -let $$Error = /* @__PURE__ */Caml_exceptions.create("Stream.Error"); - -function count(param) { - if (param !== undefined) { - return param.count; - } else { - return 0; - } -} - -function data(param) { - if (param !== undefined) { - return param.data; - } else { - return "Sempty"; - } -} - -function get_data(count, _d) { - while (true) { - let d = _d; - if (typeof d !== "object") { - return d; - } - switch (d.TAG) { - case "Scons" : - return d; - case "Sapp" : - let d2 = d._1; - let match = get_data(count, d._0); - if (typeof match !== "object") { - _d = d2; - continue; - } - if (match.TAG === "Scons") { - return { - TAG: "Scons", - _0: match._0, - _1: { - TAG: "Sapp", - _0: match._1, - _1: d2 - } - }; - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "stream.res", - 53, - 13 - ], - Error: new Error() - }; - case "Slazy" : - _d = CamlinternalLazy.force(d._0); - continue; - case "Sgen" : - let g = d._0; - let match$1 = g.curr; - if (match$1 !== undefined) { - let a = Caml_option.valFromOption(match$1); - if (a !== undefined) { - g.curr = undefined; - return { - TAG: "Scons", - _0: Caml_option.valFromOption(a), - _1: d - }; - } else { - return "Sempty"; - } - } - let a$1 = g.func(count); - if (a$1 !== undefined) { - return { - TAG: "Scons", - _0: Caml_option.valFromOption(a$1), - _1: d - }; - } else { - g.curr = Caml_option.some(undefined); - return "Sempty"; - } - } - }; -} - -function peek_data(s) { - while (true) { - let f = s.data; - if (typeof f !== "object") { - return; - } - switch (f.TAG) { - case "Scons" : - return Caml_option.some(f._0); - case "Sapp" : - let d = get_data(s.count, s.data); - if (typeof d !== "object") { - return; - } - if (d.TAG === "Scons") { - s.data = d; - return Caml_option.some(d._0); - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "stream.res", - 83, - 13 - ], - Error: new Error() - }; - case "Slazy" : - s.data = CamlinternalLazy.force(f._0); - continue; - case "Sgen" : - let g = f._0; - let a = g.curr; - if (a !== undefined) { - return Caml_option.valFromOption(a); - } - let x = g.func(s.count); - g.curr = Caml_option.some(x); - return x; - } - }; -} - -function peek(param) { - if (param !== undefined) { - return peek_data(param); - } - -} - -function junk_data(s) { - while (true) { - let g = s.data; - if (typeof g === "object") { - switch (g.TAG) { - case "Scons" : - s.count = s.count + 1 | 0; - s.data = g._1; - return; - case "Sgen" : - let g$1 = g._0; - let match = g$1.curr; - if (match !== undefined) { - s.count = s.count + 1 | 0; - g$1.curr = undefined; - return; - } - break; - } - } - let match$1 = peek_data(s); - if (match$1 === undefined) { - return; - } - continue; - }; -} - -function junk(param) { - if (param !== undefined) { - return junk_data(param); - } - -} - -function nget_data(n, s) { - if (n <= 0) { - return [ - /* [] */0, - s.data, - 0 - ]; - } - let a = peek_data(s); - if (a === undefined) { - return [ - /* [] */0, - s.data, - 0 - ]; - } - let a$1 = Caml_option.valFromOption(a); - junk_data(s); - let match = nget_data(n - 1 | 0, s); - return [ - { - hd: a$1, - tl: match[0] - }, - { - TAG: "Scons", - _0: a$1, - _1: match[1] - }, - match[2] + 1 | 0 - ]; -} - -function npeek(n, param) { - if (param !== undefined) { - let match = nget_data(n, param); - param.count = param.count - match[2] | 0; - param.data = match[1]; - return match[0]; - } else { - return /* [] */0; - } -} - -function next(s) { - let a = peek(s); - if (a !== undefined) { - junk(s); - return Caml_option.valFromOption(a); - } - throw { - RE_EXN_ID: Failure, - Error: new Error() - }; -} - -function empty(s) { - let match = peek(s); - if (match === undefined) { - return; - } - throw { - RE_EXN_ID: Failure, - Error: new Error() - }; -} - -function iter(f, strm) { - let do_rec = () => { - while (true) { - let a = peek(strm); - if (a === undefined) { - return; - } - junk(strm); - f(Caml_option.valFromOption(a)); - continue; - }; - }; - do_rec(); -} - -function from(f) { - return { - count: 0, - data: { - TAG: "Sgen", - _0: { - curr: undefined, - func: f - } - } - }; -} - -function of_list(l) { - return { - count: 0, - data: List.fold_right((x, l) => ({ - TAG: "Scons", - _0: x, - _1: l - }), l, "Sempty") - }; -} - -function of_string(s) { - let count = { - contents: 0 - }; - return from(param => { - let c = count.contents; - if (c < s.length) { - count.contents = count.contents + 1 | 0; - return Caml_string.get(s, c); - } - - }); -} - -function of_bytes(s) { - let count = { - contents: 0 - }; - return from(param => { - let c = count.contents; - if (c < s.length) { - count.contents = count.contents + 1 | 0; - return Caml_bytes.get(s, c); - } - - }); -} - -function iapp(i, s) { - return { - count: 0, - data: { - TAG: "Sapp", - _0: data(i), - _1: data(s) - } - }; -} - -function icons(i, s) { - return { - count: 0, - data: { - TAG: "Scons", - _0: i, - _1: data(s) - } - }; -} - -function ising(i) { - return { - count: 0, - data: { - TAG: "Scons", - _0: i, - _1: "Sempty" - } - }; -} - -function lapp(f, s) { - let f$1 = () => ({ - TAG: "Sapp", - _0: data(f()), - _1: data(s) - }); - return { - count: 0, - data: { - TAG: "Slazy", - _0: CamlinternalLazy.from_fun(() => f$1()) - } - }; -} - -function lcons(f, s) { - let f$1 = () => ({ - TAG: "Scons", - _0: f(), - _1: data(s) - }); - return { - count: 0, - data: { - TAG: "Slazy", - _0: CamlinternalLazy.from_fun(() => f$1()) - } - }; -} - -function lsing(f) { - return { - count: 0, - data: { - TAG: "Slazy", - _0: CamlinternalLazy.from_fun(() => ({ - TAG: "Scons", - _0: f(), - _1: "Sempty" - })) - } - }; -} - -function slazy(f) { - return { - count: 0, - data: { - TAG: "Slazy", - _0: CamlinternalLazy.from_fun(() => data(f())) - } - }; -} - -function dump_data(f, param) { - if (typeof param !== "object") { - console.log("Sempty"); - return; - } - switch (param.TAG) { - case "Scons" : - console.log("Scons ("); - f(param._0); - console.log(", "); - dump_data(f, param._1); - console.log(")"); - return; - case "Sapp" : - console.log("Sapp ("); - dump_data(f, param._0); - console.log(", "); - dump_data(f, param._1); - console.log(")"); - return; - case "Slazy" : - console.log("Slazy"); - return; - case "Sgen" : - console.log("Sgen"); - return; - } -} - -function dump(f, s) { - console.log("{count = "); - let i = count(s); - console.log(String(i)); - console.log("; data = "); - dump_data(f, data(s)); - console.log("}"); - console.log(""); -} - -let sempty; - -exports.Failure = Failure; -exports.$$Error = $$Error; -exports.from = from; -exports.of_list = of_list; -exports.of_string = of_string; -exports.of_bytes = of_bytes; -exports.iter = iter; -exports.next = next; -exports.empty = empty; -exports.peek = peek; -exports.junk = junk; -exports.count = count; -exports.npeek = npeek; -exports.iapp = iapp; -exports.icons = icons; -exports.ising = ising; -exports.lapp = lapp; -exports.lcons = lcons; -exports.lsing = lsing; -exports.sempty = sempty; -exports.slazy = slazy; -exports.dump = dump; -/* No side effect */ diff --git a/lib/js/string.js b/lib/js/string.js index 4da913526c..b9e2c62b0e 100644 --- a/lib/js/string.js +++ b/lib/js/string.js @@ -1,23 +1,50 @@ 'use strict'; -let Caml = require("./caml.js"); +let Char = require("./char.js"); let $$Array = require("./array.js"); -let Bytes = require("./bytes.js"); -let Caml_string = require("./caml_string.js"); -let Caml_js_exceptions = require("./caml_js_exceptions.js"); +let Primitive_exceptions = require("./primitive_exceptions.js"); -function init(n, f) { - return Bytes.unsafe_to_string(Bytes.init(n, f)); -} - -function sub(s, ofs, len) { - return Bytes.unsafe_to_string(Bytes.sub(Bytes.unsafe_of_string(s), ofs, len)); +function apply1(f, bytes) { + if (bytes.length === 0) { + return bytes; + } + let r = bytes.slice(); + r[0] = f(bytes[0]); + return r; } function concat(sep, xs) { return $$Array.of_list(xs).join(sep); } +function length(prim) { + return prim.length; +} + +function get(prim0, prim1) { + return prim0.codePointAt(prim1); +} + +function unsafe_get(prim0, prim1) { + return prim0.codePointAt(prim1); +} + +function bos(str) { + return $$Array.map(str => str.codePointAt(0), Array.from(str)); +} + +function make(len, ch) { + return String.fromCodePoint(ch).repeat(len); +} + +function init(len, f) { + return $$Array.init(len, i => String.fromCodePoint(f(i))).join(""); +} + +function sub(s, ofs, len) { + return String.fromCodePoint(...$$Array.sub(bos(s), ofs, len)); +} + function iter(f, s) { for (let i = 0, i_finish = s.length; i < i_finish; ++i) { f(s.codePointAt(i)); @@ -31,27 +58,11 @@ function iteri(f, s) { } function map(f, s) { - return Bytes.unsafe_to_string(Bytes.map(f, Bytes.unsafe_of_string(s))); + return String.fromCodePoint(...$$Array.map(f, bos(s))); } function mapi(f, s) { - return Bytes.unsafe_to_string(Bytes.mapi(f, Bytes.unsafe_of_string(s))); -} - -function is_space(param) { - if (param > 13 || param < 9) { - return param === 32; - } else { - return param !== 11; - } -} - -function trim(s) { - if (s === "" || !(is_space(s.codePointAt(0)) || is_space(s.codePointAt(s.length - 1 | 0)))) { - return s; - } else { - return Bytes.unsafe_to_string(Bytes.trim(Bytes.unsafe_of_string(s))); - } + return String.fromCodePoint(...$$Array.mapi(f, bos(s))); } function escaped(s) { @@ -79,11 +90,11 @@ function escaped(s) { continue; }; }; - if (needs_escape(0)) { - return Bytes.unsafe_to_string(Bytes.escaped(Bytes.unsafe_of_string(s))); - } else { + if (!needs_escape(0)) { return s; } + let bytes = bos(s); + return $$Array.map(Char.escaped, bytes).join(""); } function index_rec(s, lim, _i, c) { @@ -223,7 +234,7 @@ function contains_from(s, i, c) { index_rec(s, l, i, c); return true; } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + let exn = Primitive_exceptions.internalToException(raw_exn); if (exn.RE_EXN_ID === "Not_found") { return false; } @@ -247,7 +258,7 @@ function rcontains_from(s, i, c) { rindex_rec(s, i, c); return true; } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); + let exn = Primitive_exceptions.internalToException(raw_exn); if (exn.RE_EXN_ID === "Not_found") { return false; } @@ -256,25 +267,23 @@ function rcontains_from(s, i, c) { } function uppercase_ascii(s) { - return Bytes.unsafe_to_string(Bytes.uppercase_ascii(Bytes.unsafe_of_string(s))); + let bytes = bos(s); + return String.fromCodePoint(...$$Array.map(Char.uppercase_ascii, bytes)); } function lowercase_ascii(s) { - return Bytes.unsafe_to_string(Bytes.lowercase_ascii(Bytes.unsafe_of_string(s))); + let bytes = bos(s); + return String.fromCodePoint(...$$Array.map(Char.lowercase_ascii, bytes)); } function capitalize_ascii(s) { - return Bytes.unsafe_to_string(Bytes.capitalize_ascii(Bytes.unsafe_of_string(s))); + let bytes = bos(s); + return String.fromCodePoint(...apply1(Char.uppercase_ascii, bytes)); } function uncapitalize_ascii(s) { - return Bytes.unsafe_to_string(Bytes.uncapitalize_ascii(Bytes.unsafe_of_string(s))); -} - -let compare = Caml.string_compare; - -function equal(a, b) { - return a === b; + let bytes = bos(s); + return String.fromCodePoint(...apply1(Char.lowercase_ascii, bytes)); } function split_on_char(sep, s) { @@ -296,20 +305,16 @@ function split_on_char(sep, s) { }; } -let make = Caml_string.make; - -let blit = Bytes.blit_string; - +exports.length = length; +exports.get = get; exports.make = make; exports.init = init; exports.sub = sub; -exports.blit = blit; exports.concat = concat; exports.iter = iter; exports.iteri = iteri; exports.map = map; exports.mapi = mapi; -exports.trim = trim; exports.escaped = escaped; exports.index = index; exports.index_opt = index_opt; @@ -326,7 +331,6 @@ exports.uppercase_ascii = uppercase_ascii; exports.lowercase_ascii = lowercase_ascii; exports.capitalize_ascii = capitalize_ascii; exports.uncapitalize_ascii = uncapitalize_ascii; -exports.compare = compare; -exports.equal = equal; exports.split_on_char = split_on_char; +exports.unsafe_get = unsafe_get; /* No side effect */ diff --git a/lib/js/stringLabels.js b/lib/js/stringLabels.js deleted file mode 100644 index 9e9861db12..0000000000 --- a/lib/js/stringLabels.js +++ /dev/null @@ -1,332 +0,0 @@ -'use strict'; - -let Caml = require("./caml.js"); -let $$Array = require("./array.js"); -let Bytes = require("./bytes.js"); -let Caml_string = require("./caml_string.js"); -let Caml_js_exceptions = require("./caml_js_exceptions.js"); - -function init(n, f) { - return Bytes.unsafe_to_string(Bytes.init(n, f)); -} - -function sub(s, ofs, len) { - return Bytes.unsafe_to_string(Bytes.sub(Bytes.unsafe_of_string(s), ofs, len)); -} - -let blit = Bytes.blit_string; - -function concat(sep, xs) { - return $$Array.of_list(xs).join(sep); -} - -function iter(f, s) { - for (let i = 0, i_finish = s.length; i < i_finish; ++i) { - f(s.codePointAt(i)); - } -} - -function iteri(f, s) { - for (let i = 0, i_finish = s.length; i < i_finish; ++i) { - f(i, s.codePointAt(i)); - } -} - -function map(f, s) { - return Bytes.unsafe_to_string(Bytes.map(f, Bytes.unsafe_of_string(s))); -} - -function mapi(f, s) { - return Bytes.unsafe_to_string(Bytes.mapi(f, Bytes.unsafe_of_string(s))); -} - -function is_space(param) { - if (param > 13 || param < 9) { - return param === 32; - } else { - return param !== 11; - } -} - -function trim(s) { - if (s === "" || !(is_space(s.codePointAt(0)) || is_space(s.codePointAt(s.length - 1 | 0)))) { - return s; - } else { - return Bytes.unsafe_to_string(Bytes.trim(Bytes.unsafe_of_string(s))); - } -} - -function escaped(s) { - let needs_escape = _i => { - while (true) { - let i = _i; - if (i >= s.length) { - return false; - } - let match = s.codePointAt(i); - if (match < 32) { - return true; - } - if (match > 92 || match < 34) { - if (match >= 127) { - return true; - } - _i = i + 1 | 0; - continue; - } - if (match > 91 || match < 35) { - return true; - } - _i = i + 1 | 0; - continue; - }; - }; - if (needs_escape(0)) { - return Bytes.unsafe_to_string(Bytes.escaped(Bytes.unsafe_of_string(s))); - } else { - return s; - } -} - -function index_rec(s, lim, _i, c) { - while (true) { - let i = _i; - if (i >= lim) { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - if (s.codePointAt(i) === c) { - return i; - } - _i = i + 1 | 0; - continue; - }; -} - -function index(s, c) { - return index_rec(s, s.length, 0, c); -} - -function index_rec_opt(s, lim, _i, c) { - while (true) { - let i = _i; - if (i >= lim) { - return; - } - if (s.codePointAt(i) === c) { - return i; - } - _i = i + 1 | 0; - continue; - }; -} - -function index_opt(s, c) { - return index_rec_opt(s, s.length, 0, c); -} - -function index_from(s, i, c) { - let l = s.length; - if (i < 0 || i > l) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from / Bytes.index_from", - Error: new Error() - }; - } - return index_rec(s, l, i, c); -} - -function index_from_opt(s, i, c) { - let l = s.length; - if (i < 0 || i > l) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from_opt / Bytes.index_from_opt", - Error: new Error() - }; - } - return index_rec_opt(s, l, i, c); -} - -function rindex_rec(s, _i, c) { - while (true) { - let i = _i; - if (i < 0) { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - if (s.codePointAt(i) === c) { - return i; - } - _i = i - 1 | 0; - continue; - }; -} - -function rindex(s, c) { - return rindex_rec(s, s.length - 1 | 0, c); -} - -function rindex_from(s, i, c) { - if (i < -1 || i >= s.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from / Bytes.rindex_from", - Error: new Error() - }; - } - return rindex_rec(s, i, c); -} - -function rindex_rec_opt(s, _i, c) { - while (true) { - let i = _i; - if (i < 0) { - return; - } - if (s.codePointAt(i) === c) { - return i; - } - _i = i - 1 | 0; - continue; - }; -} - -function rindex_opt(s, c) { - return rindex_rec_opt(s, s.length - 1 | 0, c); -} - -function rindex_from_opt(s, i, c) { - if (i < -1 || i >= s.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from_opt / Bytes.rindex_from_opt", - Error: new Error() - }; - } - return rindex_rec_opt(s, i, c); -} - -function contains_from(s, i, c) { - let l = s.length; - if (i < 0 || i > l) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.contains_from / Bytes.contains_from", - Error: new Error() - }; - } - try { - index_rec(s, l, i, c); - return true; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - return false; - } - throw exn; - } -} - -function contains(s, c) { - return contains_from(s, 0, c); -} - -function rcontains_from(s, i, c) { - if (i < 0 || i >= s.length) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "String.rcontains_from / Bytes.rcontains_from", - Error: new Error() - }; - } - try { - rindex_rec(s, i, c); - return true; - } catch (raw_exn) { - let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - return false; - } - throw exn; - } -} - -function uppercase_ascii(s) { - return Bytes.unsafe_to_string(Bytes.uppercase_ascii(Bytes.unsafe_of_string(s))); -} - -function lowercase_ascii(s) { - return Bytes.unsafe_to_string(Bytes.lowercase_ascii(Bytes.unsafe_of_string(s))); -} - -function capitalize_ascii(s) { - return Bytes.unsafe_to_string(Bytes.capitalize_ascii(Bytes.unsafe_of_string(s))); -} - -function uncapitalize_ascii(s) { - return Bytes.unsafe_to_string(Bytes.uncapitalize_ascii(Bytes.unsafe_of_string(s))); -} - -let compare = Caml.string_compare; - -function equal(a, b) { - return a === b; -} - -function split_on_char(sep, s) { - let r = /* [] */0; - let j = s.length; - for (let i = s.length - 1 | 0; i >= 0; --i) { - if (s.codePointAt(i) === sep) { - r = { - hd: sub(s, i + 1 | 0, (j - i | 0) - 1 | 0), - tl: r - }; - j = i; - } - - } - return { - hd: sub(s, 0, j), - tl: r - }; -} - -let make = Caml_string.make; - -exports.make = make; -exports.init = init; -exports.sub = sub; -exports.blit = blit; -exports.concat = concat; -exports.iter = iter; -exports.iteri = iteri; -exports.map = map; -exports.mapi = mapi; -exports.trim = trim; -exports.escaped = escaped; -exports.index = index; -exports.index_opt = index_opt; -exports.rindex = rindex; -exports.rindex_opt = rindex_opt; -exports.index_from = index_from; -exports.index_from_opt = index_from_opt; -exports.rindex_from = rindex_from; -exports.rindex_from_opt = rindex_from_opt; -exports.contains = contains; -exports.contains_from = contains_from; -exports.rcontains_from = rcontains_from; -exports.uppercase_ascii = uppercase_ascii; -exports.lowercase_ascii = lowercase_ascii; -exports.capitalize_ascii = capitalize_ascii; -exports.uncapitalize_ascii = uncapitalize_ascii; -exports.compare = compare; -exports.equal = equal; -exports.split_on_char = split_on_char; -/* No side effect */ diff --git a/lib/js/sys.js b/lib/js/sys.js deleted file mode 100644 index 48a03282b9..0000000000 --- a/lib/js/sys.js +++ /dev/null @@ -1,181 +0,0 @@ -'use strict'; - -let Caml_sys = require("./caml_sys.js"); -let Caml_exceptions = require("./caml_exceptions.js"); - -let match = Caml_sys.sys_get_argv(); - -let os_type = Caml_sys.os_type(); - -let backend_type = { - TAG: "Other", - _0: "BS" -}; - -let big_endian = false; - -let unix = Caml_sys.os_type() === "Unix"; - -let win32 = Caml_sys.os_type() === "Win32"; - -function getenv_opt(s) { - let x = typeof process === "undefined" ? undefined : process; - if (x !== undefined) { - return x.env[s]; - } - -} - -function command(param) { - return 127; -} - -let interactive = { - contents: false -}; - -function signal(param, param$1) { - return "Signal_default"; -} - -function set_signal(sig_num, sig_beh) { - -} - -let Break = /* @__PURE__ */Caml_exceptions.create("Sys.Break"); - -function catch_break(on) { - -} - -function enable_runtime_warnings(param) { - -} - -function runtime_warnings_enabled() { - return false; -} - -let argv = match[1]; - -let executable_name = match[0]; - -let cygwin = false; - -let word_size = 32; - -let int_size = 32; - -let max_string_length = 2147483647; - -let max_array_length = 2147483647; - -let sigabrt = -1; - -let sigalrm = -2; - -let sigfpe = -3; - -let sighup = -4; - -let sigill = -5; - -let sigint = -6; - -let sigkill = -7; - -let sigpipe = -8; - -let sigquit = -9; - -let sigsegv = -10; - -let sigterm = -11; - -let sigusr1 = -12; - -let sigusr2 = -13; - -let sigchld = -14; - -let sigcont = -15; - -let sigstop = -16; - -let sigtstp = -17; - -let sigttin = -18; - -let sigttou = -19; - -let sigvtalrm = -20; - -let sigprof = -21; - -let sigbus = -22; - -let sigpoll = -23; - -let sigsys = -24; - -let sigtrap = -25; - -let sigurg = -26; - -let sigxcpu = -27; - -let sigxfsz = -28; - -let ocaml_version = "4.06.2+BS"; - -exports.argv = argv; -exports.executable_name = executable_name; -exports.getenv_opt = getenv_opt; -exports.command = command; -exports.interactive = interactive; -exports.os_type = os_type; -exports.backend_type = backend_type; -exports.unix = unix; -exports.win32 = win32; -exports.cygwin = cygwin; -exports.word_size = word_size; -exports.int_size = int_size; -exports.big_endian = big_endian; -exports.max_string_length = max_string_length; -exports.max_array_length = max_array_length; -exports.signal = signal; -exports.set_signal = set_signal; -exports.sigabrt = sigabrt; -exports.sigalrm = sigalrm; -exports.sigfpe = sigfpe; -exports.sighup = sighup; -exports.sigill = sigill; -exports.sigint = sigint; -exports.sigkill = sigkill; -exports.sigpipe = sigpipe; -exports.sigquit = sigquit; -exports.sigsegv = sigsegv; -exports.sigterm = sigterm; -exports.sigusr1 = sigusr1; -exports.sigusr2 = sigusr2; -exports.sigchld = sigchld; -exports.sigcont = sigcont; -exports.sigstop = sigstop; -exports.sigtstp = sigtstp; -exports.sigttin = sigttin; -exports.sigttou = sigttou; -exports.sigvtalrm = sigvtalrm; -exports.sigprof = sigprof; -exports.sigbus = sigbus; -exports.sigpoll = sigpoll; -exports.sigsys = sigsys; -exports.sigtrap = sigtrap; -exports.sigurg = sigurg; -exports.sigxcpu = sigxcpu; -exports.sigxfsz = sigxfsz; -exports.Break = Break; -exports.catch_break = catch_break; -exports.ocaml_version = ocaml_version; -exports.enable_runtime_warnings = enable_runtime_warnings; -exports.runtime_warnings_enabled = runtime_warnings_enabled; -/* No side effect */ diff --git a/lib/js/uchar.js b/lib/js/uchar.js deleted file mode 100644 index afb17c438f..0000000000 --- a/lib/js/uchar.js +++ /dev/null @@ -1,131 +0,0 @@ -'use strict'; - -let Caml = require("./caml.js"); -let Caml_format = require("./caml_format.js"); - -function err_not_sv(i) { - return Caml_format.format_int("%X", i) + " is not an Unicode scalar value"; -} - -function err_not_latin1(u) { - return "U+" + (Caml_format.format_int("%04X", u) + " is not a latin1 character"); -} - -function succ(u) { - if (u === 55295) { - return 57344; - } - if (u === 1114111) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "U+10FFFF has no successor", - Error: new Error() - }; - } - return u + 1 | 0; -} - -function pred(u) { - if (u === 57344) { - return 55295; - } - if (u === 0) { - throw { - RE_EXN_ID: "Invalid_argument", - _1: "U+0000 has no predecessor", - Error: new Error() - }; - } - return u - 1 | 0; -} - -function is_valid(i) { - if (0 <= i && i <= 55295) { - return true; - } else if (57344 <= i) { - return i <= 1114111; - } else { - return false; - } -} - -function of_int(i) { - if (is_valid(i)) { - return i; - } - let s = err_not_sv(i); - throw { - RE_EXN_ID: "Invalid_argument", - _1: s, - Error: new Error() - }; -} - -function is_char(u) { - return u < 256; -} - -function of_char(c) { - return c; -} - -function to_char(u) { - if (u <= 255) { - return u; - } - let s = err_not_latin1(u); - throw { - RE_EXN_ID: "Invalid_argument", - _1: s, - Error: new Error() - }; -} - -function unsafe_to_char(prim) { - return prim; -} - -function equal(prim0, prim1) { - return prim0 === prim1; -} - -let compare = Caml.int_compare; - -function hash(prim) { - return prim; -} - -let min = 0; - -let max = 1114111; - -let bom = 65279; - -let rep = 65533; - -function unsafe_of_int(prim) { - return prim; -} - -function to_int(prim) { - return prim; -} - -exports.min = min; -exports.max = max; -exports.bom = bom; -exports.rep = rep; -exports.succ = succ; -exports.pred = pred; -exports.is_valid = is_valid; -exports.of_int = of_int; -exports.unsafe_of_int = unsafe_of_int; -exports.to_int = to_int; -exports.is_char = is_char; -exports.of_char = of_char; -exports.to_char = to_char; -exports.unsafe_to_char = unsafe_to_char; -exports.equal = equal; -exports.compare = compare; -exports.hash = hash; -/* No side effect */ diff --git a/packages/artifacts.txt b/packages/artifacts.txt index dd4d48af97..45baf9eb4c 100644 --- a/packages/artifacts.txt +++ b/packages/artifacts.txt @@ -24,9 +24,7 @@ darwinarm64/rescript.exe darwinarm64/rewatch.exe docs/docson/build-schema.json lib/bstracing -lib/es6/arg.js lib/es6/array.js -lib/es6/arrayLabels.js lib/es6/belt.js lib/es6/belt_Array.js lib/es6/belt_Float.js @@ -70,52 +68,11 @@ lib/es6/belt_internalMapString.js lib/es6/belt_internalSetBuckets.js lib/es6/belt_internalSetInt.js lib/es6/belt_internalSetString.js -lib/es6/buffer.js -lib/es6/bytes.js -lib/es6/bytesLabels.js -lib/es6/callback.js -lib/es6/caml.js -lib/es6/caml_array.js -lib/es6/caml_array_extern.js -lib/es6/caml_bigint.js -lib/es6/caml_bigint_extern.js -lib/es6/caml_bytes.js -lib/es6/caml_exceptions.js -lib/es6/caml_float.js -lib/es6/caml_float_extern.js -lib/es6/caml_format.js -lib/es6/caml_hash.js -lib/es6/caml_hash_primitive.js -lib/es6/caml_int32.js -lib/es6/caml_int64.js -lib/es6/caml_int64_extern.js -lib/es6/caml_js_exceptions.js -lib/es6/caml_lexer.js -lib/es6/caml_md5.js -lib/es6/caml_module.js -lib/es6/caml_nativeint_extern.js -lib/es6/caml_obj.js -lib/es6/caml_option.js -lib/es6/caml_parser.js -lib/es6/caml_string.js -lib/es6/caml_string_extern.js -lib/es6/caml_sys.js -lib/es6/caml_undefined_extern.js -lib/es6/camlinternalLazy.js -lib/es6/camlinternalMod.js lib/es6/char.js -lib/es6/complex.js -lib/es6/curry.js -lib/es6/digest.js lib/es6/dom.js lib/es6/dom_storage.js lib/es6/dom_storage2.js -lib/es6/filename.js -lib/es6/genlex.js lib/es6/hashtbl.js -lib/es6/hashtblLabels.js -lib/es6/int32.js -lib/es6/int64.js lib/es6/js.js lib/es6/js_OO.js lib/es6/js_array.js @@ -127,6 +84,7 @@ lib/es6/js_console.js lib/es6/js_date.js lib/es6/js_dict.js lib/es6/js_exn.js +lib/es6/js_extern.js lib/es6/js_file.js lib/es6/js_float.js lib/es6/js_global.js @@ -157,34 +115,37 @@ lib/es6/jsxDOMStyle.js lib/es6/jsxEvent.js lib/es6/jsxPPXReactSupport.js lib/es6/lazy.js -lib/es6/lexing.js lib/es6/list.js -lib/es6/listLabels.js lib/es6/map.js -lib/es6/mapLabels.js -lib/es6/moreLabels.js lib/es6/obj.js lib/es6/package.json -lib/es6/parsing.js lib/es6/pervasives.js -lib/es6/queue.js -lib/es6/random.js -lib/es6/runtime_deriving.js -lib/es6/runtime_dict.js -lib/es6/runtime_promise.js +lib/es6/primitive_array.js +lib/es6/primitive_array_extern.js +lib/es6/primitive_bigint.js +lib/es6/primitive_bool.js +lib/es6/primitive_char_extern.js +lib/es6/primitive_curry.js +lib/es6/primitive_dict.js +lib/es6/primitive_exceptions.js +lib/es6/primitive_float.js +lib/es6/primitive_float_extern.js +lib/es6/primitive_hash.js +lib/es6/primitive_int.js +lib/es6/primitive_int_extern.js +lib/es6/primitive_js_extern.js +lib/es6/primitive_lazy.js +lib/es6/primitive_module.js +lib/es6/primitive_object.js +lib/es6/primitive_object_extern.js +lib/es6/primitive_option.js +lib/es6/primitive_promise.js +lib/es6/primitive_string.js +lib/es6/primitive_string_extern.js +lib/es6/primitive_util.js lib/es6/set.js -lib/es6/setLabels.js -lib/es6/sort.js -lib/es6/stack.js -lib/es6/stdLabels.js -lib/es6/stream.js lib/es6/string.js -lib/es6/stringLabels.js -lib/es6/sys.js -lib/es6/uchar.js -lib/js/arg.js lib/js/array.js -lib/js/arrayLabels.js lib/js/belt.js lib/js/belt_Array.js lib/js/belt_Float.js @@ -228,52 +189,11 @@ lib/js/belt_internalMapString.js lib/js/belt_internalSetBuckets.js lib/js/belt_internalSetInt.js lib/js/belt_internalSetString.js -lib/js/buffer.js -lib/js/bytes.js -lib/js/bytesLabels.js -lib/js/callback.js -lib/js/caml.js -lib/js/caml_array.js -lib/js/caml_array_extern.js -lib/js/caml_bigint.js -lib/js/caml_bigint_extern.js -lib/js/caml_bytes.js -lib/js/caml_exceptions.js -lib/js/caml_float.js -lib/js/caml_float_extern.js -lib/js/caml_format.js -lib/js/caml_hash.js -lib/js/caml_hash_primitive.js -lib/js/caml_int32.js -lib/js/caml_int64.js -lib/js/caml_int64_extern.js -lib/js/caml_js_exceptions.js -lib/js/caml_lexer.js -lib/js/caml_md5.js -lib/js/caml_module.js -lib/js/caml_nativeint_extern.js -lib/js/caml_obj.js -lib/js/caml_option.js -lib/js/caml_parser.js -lib/js/caml_string.js -lib/js/caml_string_extern.js -lib/js/caml_sys.js -lib/js/caml_undefined_extern.js -lib/js/camlinternalLazy.js -lib/js/camlinternalMod.js lib/js/char.js -lib/js/complex.js -lib/js/curry.js -lib/js/digest.js lib/js/dom.js lib/js/dom_storage.js lib/js/dom_storage2.js -lib/js/filename.js -lib/js/genlex.js lib/js/hashtbl.js -lib/js/hashtblLabels.js -lib/js/int32.js -lib/js/int64.js lib/js/js.js lib/js/js_OO.js lib/js/js_array.js @@ -285,6 +205,7 @@ lib/js/js_console.js lib/js/js_date.js lib/js/js_dict.js lib/js/js_exn.js +lib/js/js_extern.js lib/js/js_file.js lib/js/js_float.js lib/js/js_global.js @@ -315,49 +236,42 @@ lib/js/jsxDOMStyle.js lib/js/jsxEvent.js lib/js/jsxPPXReactSupport.js lib/js/lazy.js -lib/js/lexing.js lib/js/list.js -lib/js/listLabels.js lib/js/map.js -lib/js/mapLabels.js -lib/js/moreLabels.js lib/js/obj.js -lib/js/parsing.js lib/js/pervasives.js -lib/js/queue.js -lib/js/random.js -lib/js/runtime_deriving.js -lib/js/runtime_dict.js -lib/js/runtime_promise.js +lib/js/primitive_array.js +lib/js/primitive_array_extern.js +lib/js/primitive_bigint.js +lib/js/primitive_bool.js +lib/js/primitive_char_extern.js +lib/js/primitive_curry.js +lib/js/primitive_dict.js +lib/js/primitive_exceptions.js +lib/js/primitive_float.js +lib/js/primitive_float_extern.js +lib/js/primitive_hash.js +lib/js/primitive_int.js +lib/js/primitive_int_extern.js +lib/js/primitive_js_extern.js +lib/js/primitive_lazy.js +lib/js/primitive_module.js +lib/js/primitive_object.js +lib/js/primitive_object_extern.js +lib/js/primitive_option.js +lib/js/primitive_promise.js +lib/js/primitive_string.js +lib/js/primitive_string_extern.js +lib/js/primitive_util.js lib/js/set.js -lib/js/setLabels.js -lib/js/sort.js -lib/js/stack.js -lib/js/stdLabels.js -lib/js/stream.js lib/js/string.js -lib/js/stringLabels.js -lib/js/sys.js -lib/js/uchar.js lib/minisocket.js -lib/ocaml/arg.cmi -lib/ocaml/arg.cmj -lib/ocaml/arg.cmt -lib/ocaml/arg.cmti -lib/ocaml/arg.res -lib/ocaml/arg.resi lib/ocaml/array.cmi lib/ocaml/array.cmj lib/ocaml/array.cmt lib/ocaml/array.cmti lib/ocaml/array.res lib/ocaml/array.resi -lib/ocaml/arrayLabels.cmi -lib/ocaml/arrayLabels.cmj -lib/ocaml/arrayLabels.cmt -lib/ocaml/arrayLabels.cmti -lib/ocaml/arrayLabels.res -lib/ocaml/arrayLabels.resi lib/ocaml/belt.cmi lib/ocaml/belt.cmj lib/ocaml/belt.cmt @@ -597,62 +511,12 @@ lib/ocaml/belt_internalSetInt.res lib/ocaml/belt_internalSetString.cmj lib/ocaml/belt_internalSetString.cmt lib/ocaml/belt_internalSetString.res -lib/ocaml/belt_internals.cmti -lib/ocaml/belt_internals.resi -lib/ocaml/buffer.cmi -lib/ocaml/buffer.cmj -lib/ocaml/buffer.cmt -lib/ocaml/buffer.cmti -lib/ocaml/buffer.res -lib/ocaml/buffer.resi -lib/ocaml/bytes.cmi -lib/ocaml/bytes.cmj -lib/ocaml/bytes.cmt -lib/ocaml/bytes.cmti -lib/ocaml/bytes.res -lib/ocaml/bytes.resi -lib/ocaml/bytesLabels.cmi -lib/ocaml/bytesLabels.cmj -lib/ocaml/bytesLabels.cmt -lib/ocaml/bytesLabels.cmti -lib/ocaml/bytesLabels.res -lib/ocaml/bytesLabels.resi -lib/ocaml/callback.cmi -lib/ocaml/callback.cmj -lib/ocaml/callback.cmt -lib/ocaml/callback.cmti -lib/ocaml/callback.res -lib/ocaml/callback.resi -lib/ocaml/camlinternalLazy.cmi -lib/ocaml/camlinternalLazy.cmj -lib/ocaml/camlinternalLazy.cmt -lib/ocaml/camlinternalLazy.cmti -lib/ocaml/camlinternalLazy.res -lib/ocaml/camlinternalLazy.resi -lib/ocaml/camlinternalMod.cmi -lib/ocaml/camlinternalMod.cmj -lib/ocaml/camlinternalMod.cmt -lib/ocaml/camlinternalMod.cmti -lib/ocaml/camlinternalMod.res -lib/ocaml/camlinternalMod.resi lib/ocaml/char.cmi lib/ocaml/char.cmj lib/ocaml/char.cmt lib/ocaml/char.cmti lib/ocaml/char.res lib/ocaml/char.resi -lib/ocaml/complex.cmi -lib/ocaml/complex.cmj -lib/ocaml/complex.cmt -lib/ocaml/complex.cmti -lib/ocaml/complex.res -lib/ocaml/complex.resi -lib/ocaml/digest.cmi -lib/ocaml/digest.cmj -lib/ocaml/digest.cmt -lib/ocaml/digest.cmti -lib/ocaml/digest.res -lib/ocaml/digest.resi lib/ocaml/dom.cmi lib/ocaml/dom.cmj lib/ocaml/dom.cmt @@ -665,40 +529,12 @@ lib/ocaml/dom_storage2.cmi lib/ocaml/dom_storage2.cmj lib/ocaml/dom_storage2.cmt lib/ocaml/dom_storage2.res -lib/ocaml/filename.cmi -lib/ocaml/filename.cmj -lib/ocaml/filename.cmt -lib/ocaml/filename.cmti -lib/ocaml/filename.res -lib/ocaml/filename.resi -lib/ocaml/genlex.cmi -lib/ocaml/genlex.cmj -lib/ocaml/genlex.cmt -lib/ocaml/genlex.cmti -lib/ocaml/genlex.res -lib/ocaml/genlex.resi lib/ocaml/hashtbl.cmi lib/ocaml/hashtbl.cmj lib/ocaml/hashtbl.cmt lib/ocaml/hashtbl.cmti lib/ocaml/hashtbl.res lib/ocaml/hashtbl.resi -lib/ocaml/hashtblLabels.cmi -lib/ocaml/hashtblLabels.cmj -lib/ocaml/hashtblLabels.cmt -lib/ocaml/hashtblLabels.res -lib/ocaml/int32.cmi -lib/ocaml/int32.cmj -lib/ocaml/int32.cmt -lib/ocaml/int32.cmti -lib/ocaml/int32.res -lib/ocaml/int32.resi -lib/ocaml/int64.cmi -lib/ocaml/int64.cmj -lib/ocaml/int64.cmt -lib/ocaml/int64.cmti -lib/ocaml/int64.res -lib/ocaml/int64.resi lib/ocaml/js.cmi lib/ocaml/js.cmj lib/ocaml/js.cmt @@ -749,6 +585,10 @@ lib/ocaml/js_exn.cmt lib/ocaml/js_exn.cmti lib/ocaml/js_exn.res lib/ocaml/js_exn.resi +lib/ocaml/js_extern.cmi +lib/ocaml/js_extern.cmj +lib/ocaml/js_extern.cmt +lib/ocaml/js_extern.res lib/ocaml/js_file.cmi lib/ocaml/js_file.cmj lib/ocaml/js_file.cmt @@ -885,144 +725,140 @@ lib/ocaml/lazy.cmt lib/ocaml/lazy.cmti lib/ocaml/lazy.res lib/ocaml/lazy.resi -lib/ocaml/lexing.cmi -lib/ocaml/lexing.cmj -lib/ocaml/lexing.cmt -lib/ocaml/lexing.cmti -lib/ocaml/lexing.res -lib/ocaml/lexing.resi lib/ocaml/list.cmi lib/ocaml/list.cmj lib/ocaml/list.cmt lib/ocaml/list.cmti lib/ocaml/list.res lib/ocaml/list.resi -lib/ocaml/listLabels.cmi -lib/ocaml/listLabels.cmj -lib/ocaml/listLabels.cmt -lib/ocaml/listLabels.cmti -lib/ocaml/listLabels.res -lib/ocaml/listLabels.resi lib/ocaml/map.cmi lib/ocaml/map.cmj lib/ocaml/map.cmt -lib/ocaml/map.cmti lib/ocaml/map.res -lib/ocaml/map.resi -lib/ocaml/mapLabels.cmi -lib/ocaml/mapLabels.cmj -lib/ocaml/mapLabels.cmt -lib/ocaml/mapLabels.res -lib/ocaml/moreLabels.cmi -lib/ocaml/moreLabels.cmj -lib/ocaml/moreLabels.cmt -lib/ocaml/moreLabels.cmti -lib/ocaml/moreLabels.res -lib/ocaml/moreLabels.resi lib/ocaml/obj.cmi lib/ocaml/obj.cmj lib/ocaml/obj.cmt -lib/ocaml/obj.cmti lib/ocaml/obj.res -lib/ocaml/obj.resi -lib/ocaml/parsing.cmi -lib/ocaml/parsing.cmj -lib/ocaml/parsing.cmt -lib/ocaml/parsing.cmti -lib/ocaml/parsing.res -lib/ocaml/parsing.resi lib/ocaml/pervasives.cmi lib/ocaml/pervasives.cmj lib/ocaml/pervasives.cmt -lib/ocaml/pervasives.cmti lib/ocaml/pervasives.res -lib/ocaml/pervasives.resi -lib/ocaml/queue.cmi -lib/ocaml/queue.cmj -lib/ocaml/queue.cmt -lib/ocaml/queue.cmti -lib/ocaml/queue.res -lib/ocaml/queue.resi -lib/ocaml/random.cmi -lib/ocaml/random.cmj -lib/ocaml/random.cmt -lib/ocaml/random.cmti -lib/ocaml/random.res -lib/ocaml/random.resi -lib/ocaml/runtime_deriving.cmi -lib/ocaml/runtime_deriving.cmj -lib/ocaml/runtime_deriving.cmt -lib/ocaml/runtime_deriving.cmti -lib/ocaml/runtime_deriving.res -lib/ocaml/runtime_deriving.resi -lib/ocaml/runtime_dict.cmi -lib/ocaml/runtime_dict.cmj -lib/ocaml/runtime_dict.cmt -lib/ocaml/runtime_dict.cmti -lib/ocaml/runtime_dict.res -lib/ocaml/runtime_dict.resi -lib/ocaml/runtime_promise.cmi -lib/ocaml/runtime_promise.cmj -lib/ocaml/runtime_promise.cmt -lib/ocaml/runtime_promise.res +lib/ocaml/primitive_array.cmi +lib/ocaml/primitive_array.cmj +lib/ocaml/primitive_array.cmt +lib/ocaml/primitive_array.res +lib/ocaml/primitive_array_extern.cmi +lib/ocaml/primitive_array_extern.cmj +lib/ocaml/primitive_array_extern.cmt +lib/ocaml/primitive_array_extern.res +lib/ocaml/primitive_bigint.cmi +lib/ocaml/primitive_bigint.cmj +lib/ocaml/primitive_bigint.cmt +lib/ocaml/primitive_bigint.res +lib/ocaml/primitive_bool.cmi +lib/ocaml/primitive_bool.cmj +lib/ocaml/primitive_bool.cmt +lib/ocaml/primitive_bool.res +lib/ocaml/primitive_char_extern.cmi +lib/ocaml/primitive_char_extern.cmj +lib/ocaml/primitive_char_extern.cmt +lib/ocaml/primitive_char_extern.res +lib/ocaml/primitive_curry.cmi +lib/ocaml/primitive_curry.cmj +lib/ocaml/primitive_curry.cmt +lib/ocaml/primitive_curry.cmti +lib/ocaml/primitive_curry.res +lib/ocaml/primitive_curry.resi +lib/ocaml/primitive_dict.cmi +lib/ocaml/primitive_dict.cmj +lib/ocaml/primitive_dict.cmt +lib/ocaml/primitive_dict.res +lib/ocaml/primitive_exceptions.cmi +lib/ocaml/primitive_exceptions.cmj +lib/ocaml/primitive_exceptions.cmt +lib/ocaml/primitive_exceptions.cmti +lib/ocaml/primitive_exceptions.res +lib/ocaml/primitive_exceptions.resi +lib/ocaml/primitive_float.cmi +lib/ocaml/primitive_float.cmj +lib/ocaml/primitive_float.cmt +lib/ocaml/primitive_float.res +lib/ocaml/primitive_float_extern.cmi +lib/ocaml/primitive_float_extern.cmj +lib/ocaml/primitive_float_extern.cmt +lib/ocaml/primitive_float_extern.res +lib/ocaml/primitive_hash.cmi +lib/ocaml/primitive_hash.cmj +lib/ocaml/primitive_hash.cmt +lib/ocaml/primitive_hash.cmti +lib/ocaml/primitive_hash.res +lib/ocaml/primitive_hash.resi +lib/ocaml/primitive_int.cmi +lib/ocaml/primitive_int.cmj +lib/ocaml/primitive_int.cmt +lib/ocaml/primitive_int.res +lib/ocaml/primitive_int_extern.cmi +lib/ocaml/primitive_int_extern.cmj +lib/ocaml/primitive_int_extern.cmt +lib/ocaml/primitive_int_extern.res +lib/ocaml/primitive_js_extern.cmi +lib/ocaml/primitive_js_extern.cmj +lib/ocaml/primitive_js_extern.cmt +lib/ocaml/primitive_js_extern.res +lib/ocaml/primitive_lazy.cmi +lib/ocaml/primitive_lazy.cmj +lib/ocaml/primitive_lazy.cmt +lib/ocaml/primitive_lazy.cmti +lib/ocaml/primitive_lazy.res +lib/ocaml/primitive_lazy.resi +lib/ocaml/primitive_module.cmi +lib/ocaml/primitive_module.cmj +lib/ocaml/primitive_module.cmt +lib/ocaml/primitive_module.cmti +lib/ocaml/primitive_module.res +lib/ocaml/primitive_module.resi +lib/ocaml/primitive_object.cmi +lib/ocaml/primitive_object.cmj +lib/ocaml/primitive_object.cmt +lib/ocaml/primitive_object.cmti +lib/ocaml/primitive_object.res +lib/ocaml/primitive_object.resi +lib/ocaml/primitive_object_extern.cmi +lib/ocaml/primitive_object_extern.cmj +lib/ocaml/primitive_object_extern.cmt +lib/ocaml/primitive_object_extern.res +lib/ocaml/primitive_option.cmi +lib/ocaml/primitive_option.cmj +lib/ocaml/primitive_option.cmt +lib/ocaml/primitive_option.cmti +lib/ocaml/primitive_option.res +lib/ocaml/primitive_option.resi +lib/ocaml/primitive_promise.cmi +lib/ocaml/primitive_promise.cmj +lib/ocaml/primitive_promise.cmt +lib/ocaml/primitive_promise.res +lib/ocaml/primitive_string.cmi +lib/ocaml/primitive_string.cmj +lib/ocaml/primitive_string.cmt +lib/ocaml/primitive_string.res +lib/ocaml/primitive_string_extern.cmi +lib/ocaml/primitive_string_extern.cmj +lib/ocaml/primitive_string_extern.cmt +lib/ocaml/primitive_string_extern.res +lib/ocaml/primitive_util.cmi +lib/ocaml/primitive_util.cmj +lib/ocaml/primitive_util.cmt +lib/ocaml/primitive_util.res lib/ocaml/set.cmi lib/ocaml/set.cmj lib/ocaml/set.cmt -lib/ocaml/set.cmti lib/ocaml/set.res -lib/ocaml/set.resi -lib/ocaml/setLabels.cmi -lib/ocaml/setLabels.cmj -lib/ocaml/setLabels.cmt -lib/ocaml/setLabels.res -lib/ocaml/sort.cmi -lib/ocaml/sort.cmj -lib/ocaml/sort.cmt -lib/ocaml/sort.cmti -lib/ocaml/sort.res -lib/ocaml/sort.resi -lib/ocaml/stack.cmi -lib/ocaml/stack.cmj -lib/ocaml/stack.cmt -lib/ocaml/stack.cmti -lib/ocaml/stack.res -lib/ocaml/stack.resi -lib/ocaml/stdLabels.cmi -lib/ocaml/stdLabels.cmj -lib/ocaml/stdLabels.cmt -lib/ocaml/stdLabels.cmti -lib/ocaml/stdLabels.res -lib/ocaml/stdLabels.resi -lib/ocaml/stream.cmi -lib/ocaml/stream.cmj -lib/ocaml/stream.cmt -lib/ocaml/stream.cmti -lib/ocaml/stream.res -lib/ocaml/stream.resi lib/ocaml/string.cmi lib/ocaml/string.cmj lib/ocaml/string.cmt lib/ocaml/string.cmti lib/ocaml/string.res lib/ocaml/string.resi -lib/ocaml/stringLabels.cmi -lib/ocaml/stringLabels.cmj -lib/ocaml/stringLabels.cmt -lib/ocaml/stringLabels.cmti -lib/ocaml/stringLabels.res -lib/ocaml/stringLabels.resi -lib/ocaml/sys.cmi -lib/ocaml/sys.cmj -lib/ocaml/sys.cmt -lib/ocaml/sys.cmti -lib/ocaml/sys.res -lib/ocaml/sys.resi -lib/ocaml/uchar.cmi -lib/ocaml/uchar.cmj -lib/ocaml/uchar.cmt -lib/ocaml/uchar.cmti -lib/ocaml/uchar.res -lib/ocaml/uchar.resi linux/bsb_helper.exe linux/bsc.exe linux/ninja.exe diff --git a/scripts/ninja.js b/scripts/ninja.js index 49251c1314..dabd32c55d 100755 --- a/scripts/ninja.js +++ b/scripts/ninja.js @@ -16,11 +16,10 @@ var jsDir = path.join(__dirname, "..", "lib", "js"); var runtimeFiles = fs.readdirSync(runtimeDir, "ascii"); var runtimeMlFiles = runtimeFiles.filter( - x => !x.startsWith("bs_stdlib_mini") && x.endsWith(".res") && x !== "js.res", + x => !x.startsWith("pervasives") && x.endsWith(".res"), ); var runtimeMliFiles = runtimeFiles.filter( - x => - !x.startsWith("bs_stdlib_mini") && x.endsWith(".resi") && x !== "js.resi", + x => !x.startsWith("pervasives") && x.endsWith(".resi"), ); var runtimeSourceFiles = runtimeMlFiles.concat(runtimeMliFiles); var runtimeJsFiles = [...new Set(runtimeSourceFiles.map(baseName))]; @@ -29,7 +28,6 @@ var commonBsFlags = `-no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-c var js_package = pseudoTarget("js_pkg"); var runtimeTarget = pseudoTarget("runtime"); var othersTarget = pseudoTarget("others"); -var stdlibTarget = pseudoTarget("$stdlib"); var { absolutePath: my_target, bsc_exe, @@ -57,7 +55,6 @@ exports.vendorNinjaPath = vendorNinjaPath; * build.ninja * runtime/build.ninja * others/build.ninja - * $stdlib/build.ninja * test/build.ninja * * files generated for env config @@ -66,7 +63,6 @@ exports.vendorNinjaPath = vendorNinjaPath; * compilerEnv.ninja (no snapshot since env can not provide snapshot) * runtime/env.ninja * others/env.ninja - * $stdlib/env.ninja * test/env.ninja * * In release mode: @@ -74,7 +70,6 @@ exports.vendorNinjaPath = vendorNinjaPath; * release.ninja * runtime/release.ninja * others/release.ninja - * $stdlib/release.ninja * * Like that our snapshot is so robust that * we don't do snapshot in CI, we don't @@ -758,26 +753,23 @@ async function runtimeNinja(devmode = true) { var compilerTarget = pseudoTarget("$bsc"); var externalDeps = devmode ? [compilerTarget] : []; var ninjaOutput = devmode ? "build.ninja" : "release.ninja"; + var bsc_flags = "bsc_flags"; + /** + * @type [string,string][] + */ var templateRuntimeRules = ` -bsc_no_open_flags = ${commonBsFlags} -bs-cross-module-opt -make-runtime -nopervasives -unsafe -w +50 -warn-error A -bsc_flags = $bsc_no_open_flags -open Bs_stdlib_mini +${bsc_flags} = ${commonBsFlags} -bs-cross-module-opt -make-runtime -unsafe -w -3+50 -warn-error A ${ruleCC(ninjaCwd)} ${ninjaQuickBuildList([ + // we make it still depends on external + // to enjoy free ride on dev config for compiler-deps + [ - "bs_stdlib_mini.cmi", - "bs_stdlib_mini.resi", - "cc", - ninjaCwd, - [["bsc_flags", "-nostdlib -nopervasives"]], - [], - externalDeps, - ], - [ - ["js.cmj", "js.cmi"], - "js.res", + ["pervasives.cmj", "pervasives.cmi"], + "pervasives.res", "cc", ninjaCwd, - [["bsc_flags", "$bsc_no_open_flags"]], + [[bsc_flags, `$${bsc_flags} -nopervasives`]], [], externalDeps, ], @@ -788,7 +780,7 @@ ${ninjaQuickBuildList([ */ var depsMap = new Map(); var allTargets = collectTarget([...runtimeMliFiles, ...runtimeMlFiles]); - var manualDeps = ["bs_stdlib_mini.cmi", "js.cmj", "js.cmi"]; + var manualDeps = ["pervasives.cmj", "pervasives.cmi"]; var allFileTargetsInRuntime = scanFileTargets(allTargets, manualDeps); allTargets.forEach((ext, mod) => { switch (ext) { @@ -823,17 +815,11 @@ ${ninjaQuickBuildList([ async function othersNinja(devmode = true) { var compilerTarget = pseudoTarget("$bsc"); - var externalDeps = [ - compilerTarget, - fileTarget("belt_internals.cmi"), - fileTarget("js.cmi"), - ]; var ninjaOutput = devmode ? "build.ninja" : "release.ninja"; var ninjaCwd = "others"; var templateOthersRules = ` -bsc_primitive_flags = ${commonBsFlags} -bs-cross-module-opt -make-runtime -nopervasives -unsafe -w +50 -warn-error A -bsc_flags = $bsc_primitive_flags -open Belt_internals +bsc_flags = ${commonBsFlags} -bs-cross-module-opt -make-runtime -unsafe -w +50 -warn-error A -I runtime ${ruleCC(ninjaCwd)} ${ninjaQuickBuildList([ [ @@ -841,27 +827,9 @@ ${ninjaQuickBuildList([ "belt.res", "cc", ninjaCwd, - [["bsc_flags", "$bsc_primitive_flags"]], [], - [compilerTarget], - ], - [ - ["js.cmj", "js.cmi"], - "js.res", - "cc", - ninjaCwd, - [["bsc_flags", "$bsc_primitive_flags"]], - [], - [compilerTarget], - ], - [ - ["belt_internals.cmi"], - "belt_internals.resi", - "cc", - ninjaCwd, - [["bsc_flags", "$bsc_primitive_flags"]], [], - [compilerTarget], + [compilerTarget, runtimeTarget], ], ])} `; @@ -871,14 +839,12 @@ ${ninjaQuickBuildList([ x.startsWith("js") && (x.endsWith(".res") || x.endsWith(".resi")) && !x.includes(".pp") && - !x.includes("#") && - x !== "js.res", + !x.includes("#"), ); var othersFiles = othersDirFiles.filter( x => !x.startsWith("js") && x !== "belt.res" && - x !== "belt_internals.resi" && (x.endsWith(".res") || x.endsWith(".resi")) && !x.includes("#"), ); @@ -890,7 +856,10 @@ ${ninjaQuickBuildList([ ocamlDepForBscAsync(jsPrefixSourceFiles, othersDir, jsDepsMap), ocamlDepForBscAsync(othersFiles, othersDir, depsMap), ]); - var jsOutput = generateNinja(jsDepsMap, jsTargets, ninjaCwd, externalDeps); + var jsOutput = generateNinja(jsDepsMap, jsTargets, ninjaCwd, [ + compilerTarget, + runtimeTarget, + ]); jsOutput.push(phony(js_package, fileTargets(allJsTargets), ninjaCwd)); // Note compiling belt.res still try to read @@ -905,7 +874,11 @@ ${ninjaQuickBuildList([ s.add(js_package); }); var allOthersTarget = scanFileTargets(beltTargets, []); - var beltOutput = generateNinja(depsMap, beltTargets, ninjaCwd, externalDeps); + var beltOutput = generateNinja(depsMap, beltTargets, ninjaCwd, [ + compilerTarget, + runtimeTarget, + fileTarget("js.cmi"), + ]); beltOutput.push(phony(othersTarget, fileTargets(allOthersTarget), ninjaCwd)); writeFileAscii( path.join(othersDir, ninjaOutput), @@ -916,83 +889,6 @@ ${ninjaQuickBuildList([ "\n", ); } -/** - * - * @param {boolean} devmode - * generate build.ninja/release.ninja for stdlib-402 - */ -async function stdlibNinja(devmode = true) { - var stdlibVersion = "stdlib-406"; - var ninjaCwd = stdlibVersion; - var stdlibDir = path.join(jscompDir, stdlibVersion); - var compilerTarget = pseudoTarget("$bsc"); - var externalDeps = [compilerTarget, othersTarget]; - var ninjaOutput = devmode ? "build.ninja" : "release.ninja"; - var bsc_flags = "bsc_flags"; - /** - * @type [string,string][] - */ - var bsc_builtin_overrides = [[bsc_flags, `$${bsc_flags} -nopervasives`]]; - // It is interesting `-w -a` would generate not great code sometimes - // deprecations diabled due to string_of_float - var warnings = "-w -9-3-106 -warn-error A"; - var templateStdlibRules = ` -${bsc_flags} = ${commonBsFlags} -bs-cross-module-opt -make-runtime ${warnings} -I others -${ruleCC(ninjaCwd)} -${ninjaQuickBuildList([ - // we make it still depends on external - // to enjoy free ride on dev config for compiler-deps - - [ - "pervasives.cmj", - "pervasives.res", - "cc_cmi", - ninjaCwd, - bsc_builtin_overrides, - "pervasives.cmi", - externalDeps, - ], - [ - "pervasives.cmi", - "pervasives.resi", - "cc", - ninjaCwd, - bsc_builtin_overrides, - [], - externalDeps, - ], -])} -`; - var stdlibDirFiles = fs.readdirSync(stdlibDir, "ascii"); - var sources = stdlibDirFiles.filter(x => { - return ( - !x.startsWith("pervasives.") && - (x.endsWith(".res") || x.endsWith(".resi")) - ); - }); - let depsMap = new Map(); - await ocamlDepForBscAsync(sources, stdlibDir, depsMap); - var targets = collectTarget(sources); - var allTargets = scanFileTargets(targets, []); - targets.forEach((ext, mod) => { - switch (ext) { - case "HAS_RESI": - case "HAS_BOTH_RES": - updateDepsKVByFile(mod + ".cmi", "pervasives.cmj", depsMap); - break; - case "HAS_RES": - updateDepsKVByFile(mod + ".cmj", "pervasives.cmj", depsMap); - break; - } - }); - var output = generateNinja(depsMap, targets, ninjaCwd, externalDeps); - output.push(phony(stdlibTarget, fileTargets(allTargets), ninjaCwd)); - - writeFileAscii( - path.join(stdlibDir, ninjaOutput), - templateStdlibRules + output.join("\n") + "\n", - ); -} /** * @@ -1047,7 +943,7 @@ async function testNinja() { var ninjaOutput = "build.ninja"; var ninjaCwd = `test`; var templateTestRules = ` -bsc_flags = -bs-cross-module-opt -make-runtime-test -bs-package-output commonjs:jscomp/test -w -3-6-26-27-29-30-32..40-44-45-52-60-9-106+104 -warn-error A -I runtime -I $stdlib -I others +bsc_flags = -bs-cross-module-opt -make-runtime-test -bs-package-output commonjs:jscomp/test -w -3-6-26-27-29-30-32..40-44-45-52-60-9-106+104 -warn-error A -I runtime -I others ${ruleCC(ninjaCwd)} `; var testDirFiles = fs.readdirSync(testDir, "ascii"); @@ -1061,7 +957,7 @@ ${ruleCC(ninjaCwd)} var targets = collectTarget(sources); var output = generateNinja(depsMap, targets, ninjaCwd, [ runtimeTarget, - stdlibTarget, + othersTarget, pseudoTarget("$bsc"), ]); output.push( @@ -1158,7 +1054,6 @@ function checkEffect() { function updateRelease() { runtimeNinja(false); - stdlibNinja(false); othersNinja(false); } @@ -1166,14 +1061,12 @@ function updateDev() { writeFileAscii( path.join(jscompDir, "build.ninja"), ` -stdlib = stdlib-406 ${BSC_COMPILER} ocamllex = ocamllex.opt subninja runtime/build.ninja subninja others/build.ninja -subninja $stdlib/build.ninja subninja test/build.ninja -o all: phony runtime others $stdlib test +o all: phony runtime others test `, ); writeFileAscii( @@ -1187,7 +1080,6 @@ include body.ninja ); runtimeNinja(); - stdlibNinja(true); if (fs.existsSync(bsc_exe)) { testNinja(); } diff --git a/scripts/prebuilt.js b/scripts/prebuilt.js index 8862c22a93..9637fd67cc 100755 --- a/scripts/prebuilt.js +++ b/scripts/prebuilt.js @@ -64,17 +64,10 @@ function populateLibDir() { const runtime_dir = path.join(jscomp_dir, "runtime"); const others_dir = path.join(jscomp_dir, "others"); const ocaml_dir = path.join(lib_dir, "ocaml"); - const stdlib_dir = path.join(jscomp_dir, "stdlib-406"); if (!fs.existsSync(ocaml_dir)) { fs.mkdirSync(ocaml_dir); } - - installDirBy(runtime_dir, ocaml_dir, function (file) { - var y = path.parse(file); - return y.name === "js"; - }); - // for merlin or other IDE var installed_suffixes = [ ".ml", @@ -86,6 +79,10 @@ function populateLibDir() { ".cmt", ".cmti", ]; + installDirBy(runtime_dir, ocaml_dir, function (file) { + var y = path.parse(file); + return installed_suffixes.includes(y.ext); + }); installDirBy(others_dir, ocaml_dir, file => { var y = path.parse(file); if (y.ext === ".cmi") { @@ -93,10 +90,6 @@ function populateLibDir() { } return installed_suffixes.includes(y.ext) && !y.name.endsWith(".cppo"); }); - installDirBy(stdlib_dir, ocaml_dir, file => { - var y = path.parse(file); - return installed_suffixes.includes(y.ext); - }); } assert(verifyVersion(bsVersion, package_config.version));