diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d38d8f0df..ba2a0b5c2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,6 +71,7 @@ - Cleanup: remove tracking of uncurried state in parser/printer. https://github.com/rescript-lang/rescript-compiler/pull/6888 - Remove `%opaque` primitive. https://github.com/rescript-lang/rescript-compiler/pull/6892 - Reunify JsxC/JsxU -> Jsx etc. https://github.com/rescript-lang/rescript-compiler/pull/6895 +- Remove the transformation of `foo(1,2)` into `Js.Internal.opaqueFullApply(Internal.opaque(f), 1, 2)`, and change the back-end to treat all applications as uncurried. https://github.com/rescript-lang/rescript-compiler/pull/6893 #### :nail_care: Polish diff --git a/jscomp/core/lam_compile.ml b/jscomp/core/lam_compile.ml index 8161894bf9..4065d9c27f 100644 --- a/jscomp/core/lam_compile.ml +++ b/jscomp/core/lam_compile.ml @@ -1531,15 +1531,10 @@ and compile_prim (prim_info : Lam.prim_info) check the arity of fn before wrapping it we need mark something that such eta-conversion can not be simplified in some cases *) - | { - primitive = Pjs_unsafe_downgrade { name = property; setter }; - args = [ obj ]; - } -> ( - (* - either a getter {[ x #. height ]} or {[ x ## method_call ]} - *) - assert (not setter); - + | { primitive = Pjs_unsafe_downgrade { name = property; setter=false }; + args = [ obj ]; + } -> ( + (* getter {[ x #. height ]} *) match compile_lambda { lambda_cxt with continuation = NeedValue Not_tail } obj with @@ -1555,18 +1550,10 @@ and compile_prim (prim_info : Lam.prim_info) in Js_output.output_of_block_and_expression lambda_cxt.continuation blocks ret) - | { - primitive = Pfull_apply; - args = - [ - Lprim - { - primitive = Pjs_unsafe_downgrade { name = property; setter = true }; - args = [ obj ]; - }; - setter_val; - ]; - } -> ( + | { primitive = Pjs_unsafe_downgrade { name = property; setter = true }; + args = [ obj; setter_val ]; + } -> ( + (* setter {[ x ## method_call ]} *) let need_value_no_return_cxt = { lambda_cxt with continuation = NeedValue Not_tail } in @@ -1589,10 +1576,7 @@ and compile_prim (prim_info : Lam.prim_info) | Some (obj_code, obj) -> cont obj_block arg_block (Some obj_code) (E.seq (E.assign (E.dot (E.var obj) property) value) E.unit))) - | { - primitive = Pfull_apply; - args = Lprim { primitive = Pjs_unsafe_downgrade { setter = true } } :: _; - } -> + | { primitive = Pjs_unsafe_downgrade _; args } -> assert false | { primitive = Pfull_apply | Pvoid_run; args; loc } -> ( (* 1. uncurried call should not do eta-conversion diff --git a/jscomp/core/lam_convert.ml b/jscomp/core/lam_convert.ml index 3131bedcd0..442dfe4ab1 100644 --- a/jscomp/core/lam_convert.ml +++ b/jscomp/core/lam_convert.ml @@ -161,7 +161,7 @@ let unit = Lam.unit let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t = match p with | Pidentity -> Ext_list.singleton_exn args - | Puncurried_apply | Pccall _ -> assert false + | Pccall _ -> assert false | Prevapply -> assert false | Pdirapply -> assert false | Ploc _ -> assert false (* already compiled away here*) @@ -527,11 +527,29 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) : match lam with | Lvar x -> Lam.var (Hash_ident.find_default alias_tbl x x) | Lconst x -> Lam.const (Lam_constant_convert.convert_constant x) + | Lapply { ap_func = ((Lsend (name, obj, loc))); ap_args } when Ext_string.ends_with name Literals.setter_suffix -> + let obj = convert_aux obj in + let args = obj :: (Ext_list.map ap_args convert_aux) in + let property = + (String.sub name 0 + (String.length name - Literals.setter_suffix_len)) + in + prim + ~primitive:(Pjs_unsafe_downgrade { name = property; setter=true }) + ~args loc + | Lsend (name, obj, loc) -> + let obj = convert_aux obj in + let args = [ obj ] in + let setter = Ext_string.ends_with name Literals.setter_suffix in + let _ = assert (not setter) in + prim + ~primitive:(Pjs_unsafe_downgrade { name; setter }) + ~args loc | Lapply { ap_func = fn; ap_args = args; ap_loc = loc; ap_inlined } -> (* we need do this eargly in case [aux fn] add some wrapper *) Lam.apply (convert_aux fn) (Ext_list.map args convert_aux) - { ap_loc = loc; ap_inlined; ap_status = App_na } + { ap_loc = loc; ap_inlined; ap_status = App_uncurry } | Lfunction { params; body; attr } -> let new_map, body = rename_optional_parameters Map_ident.empty params body @@ -566,16 +584,6 @@ 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 - ( Puncurried_apply, - [ Lapply { ap_func; ap_args } ], - loc ) -> - let ap_func = convert_aux ap_func in - let ap_args = Ext_list.map ap_args convert_aux in - prim ~primitive:Pfull_apply ~args:(ap_func :: ap_args) loc - (* There may be some optimization opportunities here - for cases like `(fun [@bs] a b -> a + b ) 1 2 [@bs]` *) - | Lprim (Puncurried_apply, _, _) -> assert false | Lprim (primitive, args, loc) -> let args = Ext_list.map args (convert_aux ~dynamic_import) in lam_prim ~primitive ~args loc @@ -611,19 +619,6 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) : | Lfor (id, from_, to_, dir, loop) -> Lam.for_ id (convert_aux from_) (convert_aux to_) dir (convert_aux loop) | Lassign (id, body) -> Lam.assign id (convert_aux body) - | Lsend (name, obj, loc) -> - let obj = convert_aux obj in - let args = [ obj ] in - let setter = Ext_string.ends_with name Literals.setter_suffix in - let property = - if setter then - (String.sub name 0 - (String.length name - Literals.setter_suffix_len)) - else name - in - prim - ~primitive:(Pjs_unsafe_downgrade { name = property; setter }) - ~args loc and convert_let (kind : Lam_compat.let_kind) id (e : Lambda.lambda) body : Lam.t = match (kind, e) with diff --git a/jscomp/frontend/ast_literal.ml b/jscomp/frontend/ast_literal.ml index 5ee13ec6aa..af71328945 100644 --- a/jscomp/frontend/ast_literal.ml +++ b/jscomp/frontend/ast_literal.ml @@ -49,10 +49,6 @@ module Lid = struct let type_bool : t = Lident "bool" (* use *predef* *) - (* TODO should be renamed in to {!Js.fn} *) - (* TODO should be moved into {!Js.t} Later *) - let js_internal : t = Ldot (Lident "Js", "Internal") - let js_oo : t = Lident "Js_OO" let js_meth_callback : t = Ldot (js_oo, "Callback") diff --git a/jscomp/frontend/ast_literal.mli b/jscomp/frontend/ast_literal.mli index 9e8d1cbdee..059b178dac 100644 --- a/jscomp/frontend/ast_literal.mli +++ b/jscomp/frontend/ast_literal.mli @@ -56,8 +56,6 @@ module Lid : sig val js_null_undefined : t val js_re_id : t - - val js_internal : t end type expression_lit = Parsetree.expression lit diff --git a/jscomp/gentype_tests/typescript-react-example/src/ImmutableArray.res.js b/jscomp/gentype_tests/typescript-react-example/src/ImmutableArray.res.js index 630eccaa40..8f0f909427 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/ImmutableArray.res.js +++ b/jscomp/gentype_tests/typescript-react-example/src/ImmutableArray.res.js @@ -18,13 +18,9 @@ function size(a) { return a.length; } -function get(a, x) { - return Belt_Array.get(a, x); -} +let get = Belt_Array.get; -function getExn(a, x) { - return Belt_Array.getExn(a, x); -} +let getExn = Belt_Array.getExn; function getUnsafe(a, x) { return a[x]; @@ -34,13 +30,9 @@ function getUndefined(a, x) { return a[x]; } -function shuffle(x) { - return Belt_Array.shuffle(x); -} +let shuffle = Belt_Array.shuffle; -function reverse(x) { - return Belt_Array.reverse(x); -} +let reverse = Belt_Array.reverse; function makeUninitialized(x) { return new Array(x); @@ -50,21 +42,13 @@ function makeUninitializedUnsafe(x) { return new Array(x); } -function make(x, y) { - return Belt_Array.make(x, y); -} +let make = Belt_Array.make; -function range(x, y) { - return Belt_Array.range(x, y); -} +let range = Belt_Array.range; -function rangeBy(x, y, step) { - return Belt_Array.rangeBy(x, y, step); -} +let rangeBy = Belt_Array.rangeBy; -function makeByU(c, f) { - return Belt_Array.makeByU(c, f); -} +let makeByU = Belt_Array.makeByU; function makeBy(c, f) { return Belt_Array.makeBy(c, (function (x) { @@ -72,9 +56,7 @@ function makeBy(c, f) { })); } -function makeByAndShuffleU(c, f) { - return Belt_Array.makeByAndShuffleU(c, f); -} +let makeByAndShuffleU = Belt_Array.makeByAndShuffleU; function makeByAndShuffle(c, f) { return Belt_Array.makeByAndShuffle(c, (function (x) { @@ -82,13 +64,9 @@ function makeByAndShuffle(c, f) { })); } -function zip(a1, a2) { - return Belt_Array.zip(a1, a2); -} +let zip = Belt_Array.zip; -function zipByU(a1, a2, f) { - return Belt_Array.zipByU(a1, a2, f); -} +let zipByU = Belt_Array.zipByU; function zipBy(a1, a2, f) { return Belt_Array.zipBy(a1, a2, (function (x, y) { @@ -96,33 +74,21 @@ function zipBy(a1, a2, f) { })); } -function unzip(a) { - return Belt_Array.unzip(a); -} +let unzip = Belt_Array.unzip; -function concat(a1, a2) { - return Belt_Array.concat(a1, a2); -} +let concat = Belt_Array.concat; -function concatMany(a) { - return Belt_Array.concatMany(a); -} +let concatMany = Belt_Array.concatMany; -function slice(a, offset, len) { - return Belt_Array.slice(a, offset, len); -} +let slice = Belt_Array.slice; -function sliceToEnd(a, b) { - return Belt_Array.sliceToEnd(a, b); -} +let sliceToEnd = Belt_Array.sliceToEnd; function copy(a) { return a.slice(0); } -function forEachU(a, f) { - Belt_Array.forEachU(a, f); -} +let forEachU = Belt_Array.forEachU; function forEach(a, f) { Belt_Array.forEach(a, (function (x) { @@ -130,9 +96,7 @@ function forEach(a, f) { })); } -function mapU(a, f) { - return Belt_Array.mapU(a, f); -} +let mapU = Belt_Array.mapU; function map(a, f) { return Belt_Array.map(a, (function (x) { @@ -140,9 +104,7 @@ function map(a, f) { })); } -function keepWithIndexU(a, f) { - return Belt_Array.keepWithIndexU(a, f); -} +let keepWithIndexU = Belt_Array.keepWithIndexU; function keepWithIndex(a, f) { return Belt_Array.keepWithIndex(a, (function (x, y) { @@ -150,9 +112,7 @@ function keepWithIndex(a, f) { })); } -function keepMapU(a, f) { - return Belt_Array.keepMapU(a, f); -} +let keepMapU = Belt_Array.keepMapU; function keepMap(a, f) { return Belt_Array.keepMap(a, (function (x) { @@ -160,9 +120,7 @@ function keepMap(a, f) { })); } -function forEachWithIndexU(a, f) { - Belt_Array.forEachWithIndexU(a, f); -} +let forEachWithIndexU = Belt_Array.forEachWithIndexU; function forEachWithIndex(a, f) { Belt_Array.forEachWithIndex(a, (function (x, y) { @@ -170,9 +128,7 @@ function forEachWithIndex(a, f) { })); } -function mapWithIndexU(a, f) { - return Belt_Array.mapWithIndexU(a, f); -} +let mapWithIndexU = Belt_Array.mapWithIndexU; function mapWithIndex(a, f) { return Belt_Array.mapWithIndex(a, (function (x, y) { @@ -180,9 +136,7 @@ function mapWithIndex(a, f) { })); } -function partitionU(a, f) { - return Belt_Array.partitionU(a, f); -} +let partitionU = Belt_Array.partitionU; function partition(a, f) { return Belt_Array.partition(a, (function (x) { @@ -190,9 +144,7 @@ function partition(a, f) { })); } -function reduceU(a, b, f) { - return Belt_Array.reduceU(a, b, f); -} +let reduceU = Belt_Array.reduceU; function reduce(a, b, f) { return Belt_Array.reduce(a, b, (function (x, y) { @@ -200,9 +152,7 @@ function reduce(a, b, f) { })); } -function reduceReverseU(a, b, f) { - return Belt_Array.reduceReverseU(a, b, f); -} +let reduceReverseU = Belt_Array.reduceReverseU; function reduceReverse(a, b, f) { return Belt_Array.reduceReverse(a, b, (function (x, y) { @@ -210,9 +160,7 @@ function reduceReverse(a, b, f) { })); } -function reduceReverse2U(a1, a2, c, f) { - return Belt_Array.reduceReverse2U(a1, a2, c, f); -} +let reduceReverse2U = Belt_Array.reduceReverse2U; function reduceReverse2(a1, a2, c, f) { return Belt_Array.reduceReverse2(a1, a2, c, (function (x, y, z) { @@ -220,9 +168,7 @@ function reduceReverse2(a1, a2, c, f) { })); } -function someU(a, f) { - return Belt_Array.someU(a, f); -} +let someU = Belt_Array.someU; function some(a, f) { return Belt_Array.some(a, (function (x) { @@ -230,9 +176,7 @@ function some(a, f) { })); } -function everyU(a, f) { - return Belt_Array.everyU(a, f); -} +let everyU = Belt_Array.everyU; function every(a, f) { return Belt_Array.every(a, (function (x) { @@ -240,9 +184,7 @@ function every(a, f) { })); } -function every2U(a1, a2, f) { - return Belt_Array.every2U(a1, a2, f); -} +let every2U = Belt_Array.every2U; function every2(a1, a2, f) { return Belt_Array.every2(a1, a2, (function (x, y) { @@ -250,9 +192,7 @@ function every2(a1, a2, f) { })); } -function some2U(a1, a2, f) { - return Belt_Array.some2U(a1, a2, f); -} +let some2U = Belt_Array.some2U; function some2(a1, a2, f) { return Belt_Array.some2(a1, a2, (function (x, y) { @@ -260,9 +200,7 @@ function some2(a1, a2, f) { })); } -function cmpU(a1, a2, f) { - return Belt_Array.cmpU(a1, a2, f); -} +let cmpU = Belt_Array.cmpU; function cmp(a1, a2, f) { return Belt_Array.cmp(a1, a2, (function (x, y) { @@ -270,9 +208,7 @@ function cmp(a1, a2, f) { })); } -function eqU(a1, a2, f) { - return Belt_Array.eqU(a1, a2, f); -} +let eqU = Belt_Array.eqU; function eq(a1, a2, f) { return Belt_Array.eq(a1, a2, (function (x, y) { 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 04f88e58dd..36bff49322 100644 --- a/jscomp/gentype_tests/typescript-react-example/src/Records.res.js +++ b/jscomp/gentype_tests/typescript-react-example/src/Records.res.js @@ -19,12 +19,10 @@ function coord2d(x, y) { }; } -function getOpt(opt, $$default, foo) { - return Belt_Option.mapWithDefault(opt, $$default, foo); -} +let getOpt = Belt_Option.mapWithDefault; function findAddress(business) { - return getOpt(business.address, /* [] */0, (function (a) { + return Belt_Option.mapWithDefault(business.address, /* [] */0, (function (a) { return { hd: a, tl: /* [] */0 @@ -34,13 +32,13 @@ function findAddress(business) { function findAllAddresses(businesses) { return Belt_List.toArray(Belt_List.flatten(Belt_List.fromArray(Belt_Array.map(businesses, (function (business) { - return Belt_List.concat(getOpt(business.address, /* [] */0, (function (a) { + return Belt_List.concat(Belt_Option.mapWithDefault(business.address, /* [] */0, (function (a) { return { hd: a, tl: /* [] */0 }; - })), getOpt(business.owner, /* [] */0, (function (p) { - return getOpt(p.address, /* [] */0, (function (a) { + })), Belt_Option.mapWithDefault(business.owner, /* [] */0, (function (p) { + return Belt_Option.mapWithDefault(p.address, /* [] */0, (function (a) { return { hd: a, tl: /* [] */0 @@ -77,7 +75,7 @@ function getPayloadRecordPlusOne(param) { } function findAddress2(business) { - return getOpt(Caml_option.nullable_to_opt(business.address2), /* [] */0, (function (a) { + return Belt_Option.mapWithDefault(Caml_option.nullable_to_opt(business.address2), /* [] */0, (function (a) { return { hd: a, tl: /* [] */0 diff --git a/jscomp/ml/lambda.ml b/jscomp/ml/lambda.ml index 64dec28df1..8b7489402f 100644 --- a/jscomp/ml/lambda.ml +++ b/jscomp/ml/lambda.ml @@ -266,7 +266,6 @@ type primitive = | Pasrbint of boxed_integer | Pbintcomp of boxed_integer * comparison | Pctconst of compile_time_constant - | Puncurried_apply | Pcreate_extension of string and comparison = Ceq | Cneq | Clt | Cgt | Cle | Cge diff --git a/jscomp/ml/lambda.mli b/jscomp/ml/lambda.mli index 37452ed423..87125870c5 100644 --- a/jscomp/ml/lambda.mli +++ b/jscomp/ml/lambda.mli @@ -233,7 +233,6 @@ type primitive = | Pasrbint of boxed_integer | Pbintcomp of boxed_integer * comparison | Pctconst of compile_time_constant - | Puncurried_apply | Pcreate_extension of string and comparison = Ceq | Cneq | Clt | Cgt | Cle | Cge diff --git a/jscomp/ml/printlambda.ml b/jscomp/ml/printlambda.ml index dfb7203b30..4dc4e7705e 100644 --- a/jscomp/ml/printlambda.ml +++ b/jscomp/ml/printlambda.ml @@ -121,7 +121,6 @@ let print_taginfo ppf = function -> fprintf ppf "[%s]" (String.concat ";" (Array.to_list ss) ) let primitive ppf = function - | Puncurried_apply -> fprintf ppf "@app" | Pidentity -> fprintf ppf "id" | Pbytes_to_string -> fprintf ppf "bytes_to_string" | Pignore -> fprintf ppf "ignore" @@ -253,7 +252,6 @@ let primitive ppf = function | Pbintcomp(bi, Cge) -> print_boxed_integer ">=" ppf bi | Pcreate_extension s -> fprintf ppf "extension[%s]" s let name_of_primitive = function - | Puncurried_apply -> "Puncurried_apply" | Pidentity -> "Pidentity" | Pbytes_to_string -> "Pbytes_to_string" | Pignore -> "Pignore" diff --git a/jscomp/ml/translcore.ml b/jscomp/ml/translcore.ml index 6723662971..c0f72ed7f3 100644 --- a/jscomp/ml/translcore.ml +++ b/jscomp/ml/translcore.ml @@ -422,7 +422,6 @@ let primitives_table = ("%int64_to_int32", Pcvtbint (Pint64, Pint32)); ("%int64_of_bigint", Pcvtbint (Pbigint, Pint64)); ("%int64_to_bigint", Pcvtbint (Pint64, Pbigint)); - ("%uncurried_apply", Puncurried_apply); ] let find_primitive prim_name = Hashtbl.find primitives_table prim_name @@ -1037,14 +1036,8 @@ and transl_cases_try cases = List.map transl_case_try cases and transl_apply ?(inlined = Default_inline) ?(uncurried_partial_application=None) lam sargs loc = - let lapply funct args = - match funct with - (* Attention: This may not be what we need to change the application arity*) - | Lapply ap -> Lapply { ap with ap_args = ap.ap_args @ args; ap_loc = loc } - | lexp -> - Lapply - { ap_loc = loc; ap_func = lexp; ap_args = args; ap_inlined = inlined } - in + let lapply ap_func ap_args = + Lapply { ap_loc = loc; ap_func; ap_args; ap_inlined = inlined } in let rec build_apply lam args = function | (None, optional) :: l -> let defs = ref [] in @@ -1101,11 +1094,10 @@ and transl_apply ?(inlined = Default_inline) ?(uncurried_partial_application=Non let extra_args = Ext_list.map extra_ids (fun id -> Lvar id) in let ap_args = args @ extra_args in let l0 = Lapply { ap_func = lam; ap_args; ap_inlined = inlined; ap_loc = loc } in - let l1 = Lprim (Puncurried_apply, [l0], loc) in Lfunction { params = List.rev_append !none_ids extra_ids ; - body = l1; + body = l0; attr = default_function_attribute; loc; } diff --git a/jscomp/ml/typecore.ml b/jscomp/ml/typecore.ml index c6f20c1706..7a76507dc4 100644 --- a/jscomp/ml/typecore.ml +++ b/jscomp/ml/typecore.ml @@ -2153,18 +2153,6 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg=Rejected) env sexp ty end_def (); unify_var env (newvar()) funct.exp_type; - let mk_exp ?(loc=Location.none) exp_desc exp_type = - { exp_desc; - exp_loc = loc; exp_extra = []; - exp_type; - exp_attributes = []; - exp_env = env } in - let apply_internal name e = - let lid:Longident.t = Ldot (Ldot (Lident "Js", "Internal"), name) in - let (path, desc) = Env.lookup_value lid env in - let id = mk_exp (Texp_ident(path, {txt=lid; loc=Location.none}, desc)) desc.val_type in - mk_exp ~loc:e.exp_loc (Texp_apply(id, [(Nolabel, Some e)])) e.exp_type in - let mk_apply funct args = rue { exp_desc = Texp_apply(funct, args); @@ -2178,7 +2166,7 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg=Rejected) env sexp ty | _ -> false in if fully_applied && not is_primitive then - rue (apply_internal "opaqueFullApply" (mk_apply funct args)) + rue (mk_apply funct args) else rue (mk_apply funct args) | Pexp_match(sarg, caselist) -> diff --git a/jscomp/others/js.res b/jscomp/others/js.res index 862e8a8f52..10ce264026 100644 --- a/jscomp/others/js.res +++ b/jscomp/others/js.res @@ -77,13 +77,6 @@ Prefer `Js.Array2` over `Js.Array`, `Js.String2` over `Js.String`, etc. The latt /** JS object type */ type t<'a> = {..} as 'a -module Internal = { - external opaqueFullApply: 'a => 'a = "%uncurried_apply" - - /* Use opaque instead of [._n] to prevent some optimizations happening */ - external run: ((. unit) => 'a) => 'a = "#run" -} - /** Nullable value of this type can be either null or 'a. This type is equivalent to Js.Null.t. */ diff --git a/jscomp/runtime/js.res b/jscomp/runtime/js.res index 8356872162..420be9c836 100644 --- a/jscomp/runtime/js.res +++ b/jscomp/runtime/js.res @@ -77,13 +77,6 @@ Prefer `Js.Array2` over `Js.Array`, `Js.String2` over `Js.String`, etc. The latt /** JS object type */ type t<'a> = {..} as 'a -module Internal = { - external opaqueFullApply: 'a => 'a = "%uncurried_apply" - - /* Use opaque instead of [._n] to prevent some optimizations happening */ - external run: ((. unit) => 'a) => 'a = "#run" -} - /** Nullable value of this type can be either null or 'a. This type is equivalent to Js.Null.t. */ diff --git a/jscomp/test/UncurriedAlways.js b/jscomp/test/UncurriedAlways.js index 6180b31cac..4b284ff2ca 100644 --- a/jscomp/test/UncurriedAlways.js +++ b/jscomp/test/UncurriedAlways.js @@ -72,7 +72,11 @@ function ptl$1(none, extra) { ]; } -let a1 = ptl$1("x", "z"); +let a1 = [ + "x", + "y", + "z" +]; console.log("a1:", a1); @@ -158,21 +162,17 @@ function fn(cb) { return cb(); } -((function (s) { - console.log({ - NAME: "foo", - VAL: s - }); - })()); +console.log({ + NAME: "foo", + VAL: undefined +}); function fn1(a, b, param) { return a() + b | 0; } function a$1(__x) { - return fn1((function () { - return 1; - }), 2, __x); + return 3; } function f3(x, y, z) { @@ -224,12 +224,10 @@ function f(a, b, c) { function f2(a, b, c, d, e) { let __tuple_internal_obj = a(b); - let param = [ - c(__tuple_internal_obj, d), - d(__tuple_internal_obj, 1, 2), - e(__tuple_internal_obj) - ]; - return (param[0] + param[1] | 0) + param[2] | 0; + let param_0 = c(__tuple_internal_obj, d); + let param_1 = d(__tuple_internal_obj, 1, 2); + let param_2 = e(__tuple_internal_obj); + return (param_0 + param_1 | 0) + param_2 | 0; } function f3$1(foo, x) { diff --git a/jscomp/test/a_filename_test.js b/jscomp/test/a_filename_test.js index 309864fbda..5fe5fd915f 100644 --- a/jscomp/test/a_filename_test.js +++ b/jscomp/test/a_filename_test.js @@ -44,49 +44,49 @@ if (process.platform !== "win32") { "/a/tmp.txt", "/a/tmp.txt/subdir/file.txt" ]); - eq("File \"a_filename_test.res\", line 28, characters 5-12", test({ + 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", test({ + 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", test({ + 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", test({ + 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", test({ + 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", test({ + 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", test({ + eq("File \"a_filename_test.res\", line 50, characters 5-12", Ext_filename_test.node_relative_path(true, { NAME: "Dir", VAL: "./a/" }, { diff --git a/jscomp/test/a_recursive_type.js b/jscomp/test/a_recursive_type.js index e46f155b06..7727b37026 100644 --- a/jscomp/test/a_recursive_type.js +++ b/jscomp/test/a_recursive_type.js @@ -11,9 +11,7 @@ let loop = g({ _0: g }); -let non_terminate = (function (x) { - return x._0(x); -})({ +let non_terminate = g({ TAG: "A", _0: g }); diff --git a/jscomp/test/a_scope_bug.js b/jscomp/test/a_scope_bug.js index 353958d34b..f80dcfef42 100644 --- a/jscomp/test/a_scope_bug.js +++ b/jscomp/test/a_scope_bug.js @@ -13,9 +13,7 @@ function odd(_z) { }; } -function even(y) { - return odd(y); -} +let even = odd; exports.odd = odd; exports.even = even; diff --git a/jscomp/test/ari_regress_test.js b/jscomp/test/ari_regress_test.js index 55e9383ea1..da79d0742c 100644 --- a/jscomp/test/ari_regress_test.js +++ b/jscomp/test/ari_regress_test.js @@ -3,9 +3,7 @@ let Mt = require("./mt.js"); -let g = (function (extra) { - return 3 + extra | 0; -})(4); +let g = 7; let h = { contents: 0 @@ -21,9 +19,7 @@ function g1(x, y) { let u = 8; -let x = (function (z) { - return u + z | 0; -})(6); +let x = u + 6 | 0; function v(__x) { return g1(3, 4)(6, __x); @@ -85,4 +81,4 @@ let suites = { Mt.from_pair_suites("Ari_regress_test", suites); -/* g Not a pure module */ +/* Not a pure module */ diff --git a/jscomp/test/arity_deopt.js b/jscomp/test/arity_deopt.js index 9424711c78..72352a0e4b 100644 --- a/jscomp/test/arity_deopt.js +++ b/jscomp/test/arity_deopt.js @@ -52,17 +52,11 @@ function f3(x) { eq("File \"arity_deopt.res\", line 47, characters 11-18", 6, 6); -eq("File \"arity_deopt.res\", line 48, characters 11-18", 6, (function (y, z) { - return (1 + y | 0) + z | 0; -})(2, 3)); +eq("File \"arity_deopt.res\", line 48, characters 11-18", 6, 6); -eq("File \"arity_deopt.res\", line 49, characters 11-18", 6, (function (z) { - return 3 + z | 0; -})(3)); +eq("File \"arity_deopt.res\", line 49, characters 11-18", 6, 6); -eq("File \"arity_deopt.res\", line 50, characters 11-18", 6, (function (y, z) { - return (1 + y | 0) + z | 0; -})(2, 3)); +eq("File \"arity_deopt.res\", line 50, characters 11-18", 6, 6); Mt.from_pair_suites("Arity_deopt", suites.contents); diff --git a/jscomp/test/async_inline.js b/jscomp/test/async_inline.js index 423dc97bb3..e08f9e8df5 100644 --- a/jscomp/test/async_inline.js +++ b/jscomp/test/async_inline.js @@ -27,9 +27,7 @@ async function doSomethingAsync(someAsyncFunction) { return await someAsyncFunction(); } -function broken(someAsyncFunction) { - return doSomethingAsync(someAsyncFunction); -} +let broken = doSomethingAsync; let M = { broken: broken @@ -39,9 +37,7 @@ async function broken$1(someAsyncFunction) { return await someAsyncFunction(); } -function broken$2(someAsyncFunction) { - return broken$1(someAsyncFunction); -} +let broken$2 = broken$1; function curriedId(x) { return x; diff --git a/jscomp/test/bdd.js b/jscomp/test/bdd.js index 71c28192b9..db7281675d 100644 --- a/jscomp/test/bdd.js +++ b/jscomp/test/bdd.js @@ -338,16 +338,16 @@ function xor(n1, n2) { function hwb(n) { let h = function (i, j) { if (i === j) { - return mkVar(i); + return mkNode("Zero", i, "One"); } else { - return xor(and2(not(mkVar(j)), h(i, j - 1 | 0)), and2(mkVar(j), g(i, j - 1 | 0))); + return xor(and2(not(mkNode("Zero", j, "One")), h(i, j - 1 | 0)), and2(mkNode("Zero", j, "One"), g(i, j - 1 | 0))); } }; let g = function (i, j) { if (i === j) { - return mkVar(i); + return mkNode("Zero", i, "One"); } else { - return xor(and2(not(mkVar(i)), h(i + 1 | 0, j)), and2(mkVar(i), g(i + 1 | 0, j))); + return xor(and2(not(mkNode("Zero", i, "One")), h(i + 1 | 0, j)), and2(mkNode("Zero", i, "One"), g(i + 1 | 0, j))); } }; return h(0, n - 1 | 0); diff --git a/jscomp/test/bs_array_test.js b/jscomp/test/bs_array_test.js index 9190d85d7f..c2abc8919b 100644 --- a/jscomp/test/bs_array_test.js +++ b/jscomp/test/bs_array_test.js @@ -194,11 +194,7 @@ let u = Belt_Array.shuffle(v$5); neq("File \"bs_array_test.res\", line 85, characters 6-13", u, v$5); -function sum(x) { - return Belt_Array.reduce(x, 0, add); -} - -eq("File \"bs_array_test.res\", line 87, characters 5-12", sum(u), sum(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), [ 0, diff --git a/jscomp/test/bs_hashmap_test.js b/jscomp/test/bs_hashmap_test.js index 41e07fbb6e..e44cd0452e 100644 --- a/jscomp/test/bs_hashmap_test.js +++ b/jscomp/test/bs_hashmap_test.js @@ -9,6 +9,7 @@ let Belt_Array = require("../../lib/js/belt_Array.js"); let Belt_HashMap = require("../../lib/js/belt_HashMap.js"); let Belt_SortArray = require("../../lib/js/belt_SortArray.js"); let Array_data_util = require("./array_data_util.js"); +let Belt_internalBucketsType = require("../../lib/js/belt_internalBucketsType.js"); let suites = { contents: /* [] */0 @@ -30,15 +31,13 @@ function eq(x, y) { return x === y; } -function hash(x) { - return Hashtbl.hash(x); -} +let hash = Hashtbl.hash; let cmp = Caml.int_compare; let Y = Belt_Id.hashable(hash, eq); -let empty = Belt_HashMap.make(30, Y); +let empty = Belt_internalBucketsType.make(Y.hash, Y.eq, 30); function add(prim0, prim1) { return prim0 + prim1 | 0; @@ -79,7 +78,7 @@ eqx("File \"bs_hashmap_test.res\", line 42, characters 6-13", Belt_SortArray.sta let u$1 = Belt_Array.concat(Array_data_util.randomRange(0, 100000), Array_data_util.randomRange(0, 100)); -let v$1 = Belt_HashMap.make(40, Y); +let v$1 = Belt_internalBucketsType.make(Y.hash, Y.eq, 40); Belt_HashMap.mergeMany(v$1, Belt_Array.zip(u$1, u$1)); diff --git a/jscomp/test/bs_hashset_int_test.js b/jscomp/test/bs_hashset_int_test.js index c7647d3d44..3abb87e389 100644 --- a/jscomp/test/bs_hashset_int_test.js +++ b/jscomp/test/bs_hashset_int_test.js @@ -7,6 +7,7 @@ let Belt_SetInt = require("../../lib/js/belt_SetInt.js"); let Array_data_util = require("./array_data_util.js"); let Belt_HashSetInt = require("../../lib/js/belt_HashSetInt.js"); let Belt_SortArrayInt = require("../../lib/js/belt_SortArrayInt.js"); +let Belt_internalBucketsType = require("../../lib/js/belt_internalBucketsType.js"); let suites = { contents: /* [] */0 @@ -54,7 +55,7 @@ eq("File \"bs_hashset_int_test.res\", line 25, characters 5-12", sum2(v), 6825); let u$1 = Belt_Array.concat(Array_data_util.randomRange(0, 100000), Array_data_util.randomRange(0, 100)); -let v$1 = Belt_HashSetInt.make(40); +let v$1 = Belt_internalBucketsType.make(undefined, undefined, 40); Belt_HashSetInt.mergeMany(v$1, u$1); diff --git a/jscomp/test/bs_hashtbl_string_test.js b/jscomp/test/bs_hashtbl_string_test.js index ab60ab5044..7b5b7014be 100644 --- a/jscomp/test/bs_hashtbl_string_test.js +++ b/jscomp/test/bs_hashtbl_string_test.js @@ -10,6 +10,7 @@ let Belt_HashMapInt = require("../../lib/js/belt_HashMapInt.js"); let Belt_HashSetInt = require("../../lib/js/belt_HashSetInt.js"); let Belt_HashMapString = require("../../lib/js/belt_HashMapString.js"); let Caml_hash_primitive = require("../../lib/js/caml_hash_primitive.js"); +let Belt_internalBucketsType = require("../../lib/js/belt_internalBucketsType.js"); function hash_string(s) { return Caml_hash_primitive.hash_final_mix(Caml_hash_primitive.hash_mix_string(0, s)); @@ -42,7 +43,7 @@ let Int = Belt_Id.hashable(Hashtbl.hash, (function (x, y) { return x === y; })); -let empty = Belt_HashMap.make(500000, Int); +let empty = Belt_internalBucketsType.make(Int.hash, Int.eq, 500000); function bench() { for(let i = 0; i <= 1000000; ++i){ @@ -67,7 +68,7 @@ function bench() { } function bench2(m) { - let empty = Belt_HashMap.make(1000000, m); + let empty = Belt_internalBucketsType.make(m.hash, m.eq, 1000000); for(let i = 0; i <= 1000000; ++i){ Belt_HashMap.set(empty, String(i), i); } @@ -147,7 +148,7 @@ function bench3(m) { let Sx = Belt_Id.comparable(Caml.string_compare); function bench4() { - let table = Belt_HashMapString.make(1000000); + let table = Belt_internalBucketsType.make(undefined, undefined, 1000000); for(let i = 0; i <= 1000000; ++i){ Belt_HashMapString.set(table, String(i), i); } @@ -185,7 +186,7 @@ function bench4() { } function bench5() { - let table = Belt_HashMap.make(1000000, Int); + let table = Belt_internalBucketsType.make(Int.hash, Int.eq, 1000000); console.time("bs_hashtbl_string_test.res 112"); for(let i = 0; i <= 1000000; ++i){ Belt_HashMap.set(table, i, i); @@ -229,7 +230,7 @@ function bench5() { } function bench6() { - let table = Belt_HashMapInt.make(1000000); + let table = Belt_internalBucketsType.make(undefined, undefined, 1000000); for(let i = 0; i <= 1000000; ++i){ Belt_HashMapInt.set(table, i, i); } @@ -267,7 +268,7 @@ function bench6() { } function bench7() { - let table = Belt_HashSetInt.make(2000000); + let table = Belt_internalBucketsType.make(undefined, undefined, 2000000); for(let i = 0; i <= 1000000; ++i){ Belt_HashSetInt.add(table, i); } diff --git a/jscomp/test/bs_list_test.js b/jscomp/test/bs_list_test.js index 52d626d882..3d5f260957 100644 --- a/jscomp/test/bs_list_test.js +++ b/jscomp/test/bs_list_test.js @@ -110,11 +110,7 @@ eq("File \"bs_list_test.res\", line 33, characters 5-12", Belt_List.getBy({ return x % 5 === 0; })), undefined); -function $eq$tilde(extra, extra$1) { - return eq("FLATTEN", extra, extra$1); -} - -$eq$tilde(Belt_List.flatten({ +eq("FLATTEN", Belt_List.flatten({ hd: { hd: 1, tl: /* [] */0 @@ -163,9 +159,9 @@ $eq$tilde(Belt_List.flatten({ } }); -$eq$tilde(Belt_List.flatten(/* [] */0), /* [] */0); +eq("FLATTEN", Belt_List.flatten(/* [] */0), /* [] */0); -$eq$tilde(Belt_List.flatten({ +eq("FLATTEN", Belt_List.flatten({ hd: /* [] */0, tl: { hd: /* [] */0, @@ -203,11 +199,7 @@ $eq$tilde(Belt_List.flatten({ } }); -function $eq$tilde$1(extra, extra$1) { - return eq("CONCATMANY", extra, extra$1); -} - -$eq$tilde$1(Belt_List.concatMany([ +eq("CONCATMANY", Belt_List.concatMany([ { hd: 1, tl: /* [] */0 @@ -247,9 +239,9 @@ $eq$tilde$1(Belt_List.concatMany([ } }); -$eq$tilde$1(Belt_List.concatMany([]), /* [] */0); +eq("CONCATMANY", Belt_List.concatMany([]), /* [] */0); -$eq$tilde$1(Belt_List.concatMany([ +eq("CONCATMANY", Belt_List.concatMany([ /* [] */0, /* [] */0, { @@ -276,7 +268,7 @@ $eq$tilde$1(Belt_List.concatMany([ } }); -$eq$tilde$1(Belt_List.concatMany([ +eq("CONCATMANY", Belt_List.concatMany([ /* [] */0, /* [] */0, { @@ -309,7 +301,7 @@ $eq$tilde$1(Belt_List.concatMany([ } }); -$eq$tilde$1(Belt_List.concatMany([{ +eq("CONCATMANY", Belt_List.concatMany([{ hd: 1, tl: { hd: 2, @@ -339,11 +331,7 @@ eq("File \"bs_list_test.res\", line 66, characters 2-9", Belt_List.toArray(Belt_ return i; })))); -function $eq$tilde$2(extra, extra$1) { - return eq("APPEND", extra, extra$1); -} - -$eq$tilde$2(Belt_List.concat({ +eq("APPEND", Belt_List.concat({ hd: 1, tl: /* [] */0 }, /* [] */0), { @@ -351,7 +339,7 @@ $eq$tilde$2(Belt_List.concat({ tl: /* [] */0 }); -$eq$tilde$2(Belt_List.concat(/* [] */0, { +eq("APPEND", Belt_List.concat(/* [] */0, { hd: 1, tl: /* [] */0 }), { @@ -359,11 +347,7 @@ $eq$tilde$2(Belt_List.concat(/* [] */0, { tl: /* [] */0 }); -function $eq$tilde$3(extra, extra$1) { - return eq("ZIP", extra, extra$1); -} - -$eq$tilde$3(Belt_List.zip({ +eq("ZIP", Belt_List.zip({ hd: 1, tl: { hd: 2, @@ -392,14 +376,14 @@ $eq$tilde$3(Belt_List.zip({ } }); -$eq$tilde$3(Belt_List.zip(/* [] */0, { +eq("ZIP", Belt_List.zip(/* [] */0, { hd: 1, tl: /* [] */0 }), /* [] */0); -$eq$tilde$3(Belt_List.zip(/* [] */0, /* [] */0), /* [] */0); +eq("ZIP", Belt_List.zip(/* [] */0, /* [] */0), /* [] */0); -$eq$tilde$3(Belt_List.zip({ +eq("ZIP", Belt_List.zip({ hd: 1, tl: { hd: 2, @@ -410,7 +394,7 @@ $eq$tilde$3(Belt_List.zip({ } }, /* [] */0), /* [] */0); -$eq$tilde$3(Belt_List.zip({ +eq("ZIP", Belt_List.zip({ hd: 1, tl: { hd: 2, @@ -456,11 +440,7 @@ function evenIndex(_x, i) { return i % 2 === 0; } -function $eq$tilde$4(extra, extra$1) { - return eq("PARTITION", extra, extra$1); -} - -$eq$tilde$4(Belt_List.partition({ +eq("PARTITION", Belt_List.partition({ hd: 1, tl: { hd: 2, @@ -501,7 +481,7 @@ $eq$tilde$4(Belt_List.partition({ } ]); -$eq$tilde$4(Belt_List.partition({ +eq("PARTITION", Belt_List.partition({ hd: 2, tl: { hd: 2, @@ -530,7 +510,7 @@ $eq$tilde$4(Belt_List.partition({ /* [] */0 ]); -$eq$tilde$4(Belt_List.partition({ +eq("PARTITION", Belt_List.partition({ hd: 2, tl: { hd: 2, @@ -561,21 +541,17 @@ $eq$tilde$4(Belt_List.partition({ } ]); -$eq$tilde$4(Belt_List.partition(/* [] */0, mod2), [ +eq("PARTITION", Belt_List.partition(/* [] */0, mod2), [ /* [] */0, /* [] */0 ]); -function $eq$tilde$5(extra, extra$1) { - return eq("UNZIP", extra, extra$1); -} - -$eq$tilde$5(Belt_List.unzip(/* [] */0), [ +eq("UNZIP", Belt_List.unzip(/* [] */0), [ /* [] */0, /* [] */0 ]); -$eq$tilde$5(Belt_List.unzip({ +eq("UNZIP", Belt_List.unzip({ hd: [ 1, 2 @@ -592,7 +568,7 @@ $eq$tilde$5(Belt_List.unzip({ } ]); -$eq$tilde$5(Belt_List.unzip({ +eq("UNZIP", Belt_List.unzip({ hd: [ 1, 2 @@ -621,11 +597,7 @@ $eq$tilde$5(Belt_List.unzip({ } ]); -function $eq$tilde$6(extra, extra$1) { - return eq("FILTER", extra, extra$1); -} - -$eq$tilde$6(Belt_List.keep({ +eq("FILTER", Belt_List.keep({ hd: 1, tl: { hd: 2, @@ -645,7 +617,7 @@ $eq$tilde$6(Belt_List.keep({ } }); -$eq$tilde$6(Belt_List.keep({ +eq("FILTER", Belt_List.keep({ hd: 1, tl: { hd: 3, @@ -656,9 +628,9 @@ $eq$tilde$6(Belt_List.keep({ } }, mod2), /* [] */0); -$eq$tilde$6(Belt_List.keep(/* [] */0, mod2), /* [] */0); +eq("FILTER", Belt_List.keep(/* [] */0, mod2), /* [] */0); -$eq$tilde$6(Belt_List.keep({ +eq("FILTER", Belt_List.keep({ hd: 2, tl: { hd: 2, @@ -690,13 +662,9 @@ $eq$tilde$6(Belt_List.keep({ } }); -function $eq$tilde$7(extra, extra$1) { - return eq("FILTER2", extra, extra$1); -} - -$eq$tilde$7(Belt_List.keepWithIndex(/* [] */0, evenIndex), /* [] */0); +eq("FILTER2", Belt_List.keepWithIndex(/* [] */0, evenIndex), /* [] */0); -$eq$tilde$7(Belt_List.keepWithIndex({ +eq("FILTER2", Belt_List.keepWithIndex({ hd: 1, tl: { hd: 2, @@ -716,7 +684,7 @@ $eq$tilde$7(Belt_List.keepWithIndex({ } }); -$eq$tilde$7(Belt_List.keepWithIndex({ +eq("FILTER2", Belt_List.keepWithIndex({ hd: 0, tl: { hd: 1, @@ -758,11 +726,7 @@ function id(x) { return x; } -function $eq$tilde$8(extra, extra$1) { - return eq("MAP", extra, extra$1); -} - -$eq$tilde$8(Belt_List.map(Belt_List.makeBy(5, id), (function (x) { +eq("MAP", Belt_List.map(Belt_List.makeBy(5, id), (function (x) { return (x << 1); })), { hd: 0, @@ -781,9 +745,9 @@ $eq$tilde$8(Belt_List.map(Belt_List.makeBy(5, id), (function (x) { } }); -$eq$tilde$8(Belt_List.map(/* [] */0, id), /* [] */0); +eq("MAP", Belt_List.map(/* [] */0, id), /* [] */0); -$eq$tilde$8(Belt_List.map({ +eq("MAP", Belt_List.map({ hd: 1, tl: /* [] */0 }, (function (x) { @@ -801,33 +765,25 @@ let length_10_id = Belt_List.makeBy(10, id); let length_8_id = Belt_List.makeBy(8, id); -function $eq$tilde$9(extra, extra$1) { - return eq("MAP2", extra, extra$1); -} - let d = Belt_List.makeBy(10, (function (x) { return (x << 1); })); -function map2_add(x, y) { - return Belt_List.zipBy(x, y, add); -} - -$eq$tilde$9(map2_add(length_10_id, length_10_id), d); +eq("MAP2", Belt_List.zipBy(length_10_id, length_10_id, add), d); -$eq$tilde$9(map2_add(/* [] */0, { +eq("MAP2", Belt_List.zipBy(/* [] */0, { hd: 1, tl: /* [] */0 -}), /* [] */0); +}, add), /* [] */0); -$eq$tilde$9(map2_add({ +eq("MAP2", Belt_List.zipBy({ hd: 1, tl: /* [] */0 -}, /* [] */0), /* [] */0); +}, /* [] */0, add), /* [] */0); -$eq$tilde$9(map2_add(/* [] */0, /* [] */0), /* [] */0); +eq("MAP2", Belt_List.zipBy(/* [] */0, /* [] */0, add), /* [] */0); -$eq$tilde$9(map2_add(length_10_id, length_10_id), Belt_List.concat(Belt_List.map(length_8_id, (function (x) { +eq("MAP2", Belt_List.zipBy(length_10_id, length_10_id, add), Belt_List.concat(Belt_List.map(length_8_id, (function (x) { return (x << 1); })), { hd: 16, @@ -837,11 +793,11 @@ $eq$tilde$9(map2_add(length_10_id, length_10_id), Belt_List.concat(Belt_List.map } })); -$eq$tilde$9(map2_add(length_10_id, length_8_id), Belt_List.mapWithIndex(length_8_id, (function (i, x) { +eq("MAP2", Belt_List.zipBy(length_10_id, length_8_id, add), Belt_List.mapWithIndex(length_8_id, (function (i, x) { return i + x | 0; }))); -$eq$tilde$9(Belt_List.reverse(Belt_List.mapReverse2(length_10_id, length_10_id, add)), Belt_List.map(length_10_id, (function (x) { +eq("MAP2", Belt_List.reverse(Belt_List.mapReverse2(length_10_id, length_10_id, add)), Belt_List.map(length_10_id, (function (x) { return (x << 1); }))); @@ -849,9 +805,9 @@ let xs = Belt_List.reverse(Belt_List.mapReverse2(length_8_id, length_10_id, add) eq("File \"bs_list_test.res\", line 163, characters 5-12", Belt_List.length(xs), 8); -$eq$tilde$9(xs, Belt_List.zipBy(length_10_id, length_8_id, add)); +eq("MAP2", xs, Belt_List.zipBy(length_10_id, length_8_id, add)); -$eq$tilde$9(Belt_List.mapReverse2({ +eq("MAP2", Belt_List.mapReverse2({ hd: 1, tl: { hd: 2, @@ -876,11 +832,7 @@ $eq$tilde$9(Belt_List.mapReverse2({ } }); -function $eq$tilde$10(extra, extra$1) { - return eq("TAKE", extra, extra$1); -} - -$eq$tilde$10(Belt_List.take({ +eq("TAKE", Belt_List.take({ hd: 1, tl: { hd: 2, @@ -897,9 +849,9 @@ $eq$tilde$10(Belt_List.take({ } }); -$eq$tilde$10(Belt_List.take(/* [] */0, 1), undefined); +eq("TAKE", Belt_List.take(/* [] */0, 1), undefined); -$eq$tilde$10(Belt_List.take({ +eq("TAKE", Belt_List.take({ hd: 1, tl: { hd: 2, @@ -907,7 +859,7 @@ $eq$tilde$10(Belt_List.take({ } }, 3), undefined); -$eq$tilde$10(Belt_List.take({ +eq("TAKE", Belt_List.take({ hd: 1, tl: { hd: 2, @@ -921,19 +873,15 @@ $eq$tilde$10(Belt_List.take({ } }); -$eq$tilde$10(Belt_List.take(length_10_id, 8), length_8_id); +eq("TAKE", Belt_List.take(length_10_id, 8), length_8_id); -$eq$tilde$10(Belt_List.take(length_10_id, 0), /* [] */0); +eq("TAKE", Belt_List.take(length_10_id, 0), /* [] */0); -$eq$tilde$10(Belt_List.take(length_8_id, -2), undefined); +eq("TAKE", Belt_List.take(length_8_id, -2), undefined); -function $eq$tilde$11(extra, extra$1) { - return eq("DROP", extra, extra$1); -} - -$eq$tilde$11(Belt_List.drop(length_10_id, 10), /* [] */0); +eq("DROP", Belt_List.drop(length_10_id, 10), /* [] */0); -$eq$tilde$11(Belt_List.drop(length_10_id, 8), { +eq("DROP", Belt_List.drop(length_10_id, 8), { hd: 8, tl: { hd: 9, @@ -941,26 +889,22 @@ $eq$tilde$11(Belt_List.drop(length_10_id, 8), { } }); -$eq$tilde$11(Belt_List.drop(length_10_id, 0), length_10_id); +eq("DROP", Belt_List.drop(length_10_id, 0), length_10_id); -$eq$tilde$11(Belt_List.drop(length_8_id, -1), undefined); - -function $eq$tilde$12(extra, extra$1) { - return eq("SPLIT", extra, extra$1); -} +eq("DROP", Belt_List.drop(length_8_id, -1), undefined); let a = Belt_List.makeBy(5, id); -$eq$tilde$12(Belt_List.splitAt(/* [] */0, 1), undefined); +eq("SPLIT", Belt_List.splitAt(/* [] */0, 1), undefined); -$eq$tilde$12(Belt_List.splitAt(a, 6), undefined); +eq("SPLIT", Belt_List.splitAt(a, 6), undefined); -$eq$tilde$12(Belt_List.splitAt(a, 5), [ +eq("SPLIT", Belt_List.splitAt(a, 5), [ a, /* [] */0 ]); -$eq$tilde$12(Belt_List.splitAt(a, 4), [ +eq("SPLIT", Belt_List.splitAt(a, 4), [ { hd: 0, tl: { @@ -980,7 +924,7 @@ $eq$tilde$12(Belt_List.splitAt(a, 4), [ } ]); -$eq$tilde$12(Belt_List.splitAt(a, 3), [ +eq("SPLIT", Belt_List.splitAt(a, 3), [ { hd: 0, tl: { @@ -1000,7 +944,7 @@ $eq$tilde$12(Belt_List.splitAt(a, 3), [ } ]); -$eq$tilde$12(Belt_List.splitAt(a, 2), [ +eq("SPLIT", Belt_List.splitAt(a, 2), [ { hd: 0, tl: { @@ -1020,7 +964,7 @@ $eq$tilde$12(Belt_List.splitAt(a, 2), [ } ]); -$eq$tilde$12(Belt_List.splitAt(a, 1), [ +eq("SPLIT", Belt_List.splitAt(a, 1), [ { hd: 0, tl: /* [] */0 @@ -1040,21 +984,17 @@ $eq$tilde$12(Belt_List.splitAt(a, 1), [ } ]); -$eq$tilde$12(Belt_List.splitAt(a, 0), [ +eq("SPLIT", Belt_List.splitAt(a, 0), [ /* [] */0, a ]); -$eq$tilde$12(Belt_List.splitAt(a, -1), undefined); +eq("SPLIT", Belt_List.splitAt(a, -1), undefined); function succx(x) { return x + 1 | 0; } -function $eq$tilde$13(extra, extra$1) { - return eq("REMOVEASSOQ", extra, extra$1); -} - function eqx(x, y) { return x === y; } @@ -1125,7 +1065,7 @@ b("File \"bs_list_test.res\", line 207, characters 4-11", Belt_List.hasAssoc({ return (x + 1 | 0) === y; }))); -$eq$tilde$13(Belt_List.removeAssoc({ +eq("REMOVEASSOQ", Belt_List.removeAssoc({ hd: [ 1, "1" @@ -1159,7 +1099,7 @@ $eq$tilde$13(Belt_List.removeAssoc({ } }); -$eq$tilde$13(Belt_List.removeAssoc({ +eq("REMOVEASSOQ", Belt_List.removeAssoc({ hd: [ 1, "1" @@ -1193,7 +1133,7 @@ $eq$tilde$13(Belt_List.removeAssoc({ } }); -$eq$tilde$13(Belt_List.removeAssoc({ +eq("REMOVEASSOQ", Belt_List.removeAssoc({ hd: [ 1, "1" @@ -1227,7 +1167,7 @@ $eq$tilde$13(Belt_List.removeAssoc({ } }); -$eq$tilde$13(Belt_List.removeAssoc({ +eq("REMOVEASSOQ", Belt_List.removeAssoc({ hd: [ 1, "1" @@ -1267,7 +1207,7 @@ $eq$tilde$13(Belt_List.removeAssoc({ } }); -$eq$tilde$13(Belt_List.removeAssoc({ +eq("REMOVEASSOQ", Belt_List.removeAssoc({ hd: [ 1, "1" @@ -1299,7 +1239,7 @@ $eq$tilde$13(Belt_List.removeAssoc({ } }); -$eq$tilde$13(Belt_List.removeAssoc({ +eq("REMOVEASSOQ", Belt_List.removeAssoc({ hd: [ 1, "1" @@ -1331,7 +1271,7 @@ $eq$tilde$13(Belt_List.removeAssoc({ } }); -$eq$tilde$13(Belt_List.removeAssoc({ +eq("REMOVEASSOQ", Belt_List.removeAssoc({ hd: [ 1, "1" @@ -1363,7 +1303,7 @@ $eq$tilde$13(Belt_List.removeAssoc({ } }); -$eq$tilde$13(Belt_List.removeAssoc(/* [] */0, 2, eqx), /* [] */0); +eq("REMOVEASSOQ", Belt_List.removeAssoc(/* [] */0, 2, eqx), /* [] */0); let ll = { hd: [ @@ -2354,15 +2294,11 @@ makeTest(2); makeTest(3); -function $eq$tilde$14(extra, extra$1) { - return eq("SORT", extra, extra$1); -} - function cmp(a, b) { return a - b | 0; } -$eq$tilde$14(Belt_List.sort({ +eq("SORT", Belt_List.sort({ hd: 5, tl: { hd: 4, @@ -2388,7 +2324,7 @@ $eq$tilde$14(Belt_List.sort({ } }); -$eq$tilde$14(Belt_List.sort({ +eq("SORT", Belt_List.sort({ hd: 3, tl: { hd: 9, diff --git a/jscomp/test/bs_map_set_dict_test.js b/jscomp/test/bs_map_set_dict_test.js index c3b367a6f5..0f22228a21 100644 --- a/jscomp/test/bs_map_set_dict_test.js +++ b/jscomp/test/bs_map_set_dict_test.js @@ -65,7 +65,7 @@ let m2 = { data: undefined }; -let data = undefined; +let data; Belt_Map.getId(m2); @@ -75,11 +75,13 @@ for(let i = 0; i <= 100000; ++i){ data = Belt_MapDict.set(data, i, i, m_dict.cmp); } +let data$1 = data; + let newm_cmp = m_dict.cmp; let newm = { cmp: newm_cmp, - data: data + data: data$1 }; console.log(newm); @@ -92,13 +94,13 @@ let m_dict$1 = Belt_Map.getId(m); let cmp = m_dict$1.cmp; -let data$1 = undefined; +let data$2; for(let i$1 = 0; i$1 <= 100000; ++i$1){ - data$1 = Belt_SetDict.add(data$1, i$1, cmp); + data$2 = Belt_SetDict.add(data$2, i$1, cmp); } -console.log(data$1); +console.log(data$2); function f(none) { return Belt_Map.fromArray(none, Icmp); @@ -110,14 +112,12 @@ function $eq$tilde(a, b) { }; } -let none = Belt_Array.map(Array_data_util.randomRange(0, 39), (function (x) { +let u0 = Belt_Map.fromArray(Belt_Array.map(Array_data_util.randomRange(0, 39), (function (x) { return [ x, x ]; -})); - -let u0 = Belt_Map.fromArray(none, Icmp); +})), Icmp); let u1 = Belt_Map.set(u0, 39, 120); @@ -151,14 +151,12 @@ eq("File \"bs_map_set_dict_test.res\", line 84, characters 5-12", Belt_Map.get(u eq("File \"bs_map_set_dict_test.res\", line 85, characters 5-12", Belt_Map.get(u1, 39), 120); -let none$1 = Belt_Array.makeByAndShuffle(10000, (function (x) { +let u = Belt_Map.fromArray(Belt_Array.makeByAndShuffle(10000, (function (x) { return [ x, x ]; -})); - -let u = Belt_Map.fromArray(none$1, Icmp); +})), Icmp); eq("File \"bs_map_set_dict_test.res\", line 90, characters 5-12", Belt_Array.makeBy(10000, (function (x) { return [ diff --git a/jscomp/test/bs_map_test.js b/jscomp/test/bs_map_test.js index dd79a0faba..689645a29f 100644 --- a/jscomp/test/bs_map_test.js +++ b/jscomp/test/bs_map_test.js @@ -47,13 +47,9 @@ function b(loc, v) { }; } -function mapOfArray(x) { - return Belt_MapInt.fromArray(x); -} +let mapOfArray = Belt_MapInt.fromArray; -function setOfArray(x) { - return Belt_SetInt.fromArray(x); -} +let setOfArray = Belt_SetInt.fromArray; function emptyMap() { diff --git a/jscomp/test/bs_mutable_set_test.js b/jscomp/test/bs_mutable_set_test.js index 615216b6a4..16d171bb1f 100644 --- a/jscomp/test/bs_mutable_set_test.js +++ b/jscomp/test/bs_mutable_set_test.js @@ -55,7 +55,7 @@ for(let i = 0 ,i_finish = r.length; i < i_finish; ++i){ Belt_MutableSetInt.remove(u, r[i]); } -b("File \"bs_mutable_set_test.res\", line 33, characters 8-15", u.data === undefined); +b("File \"bs_mutable_set_test.res\", line 33, characters 8-15", Belt_MutableSetInt.isEmpty(u)); Belt_MutableSetInt.add(u, 0); @@ -67,13 +67,13 @@ Belt_MutableSetInt.add(u, 0); eq("File \"bs_mutable_set_test.res\", line 38, characters 9-16", Belt_internalAVLset.size(u.data), 3); -b("File \"bs_mutable_set_test.res\", line 39, characters 8-15", u.data !== undefined); +b("File \"bs_mutable_set_test.res\", line 39, characters 8-15", !Belt_MutableSetInt.isEmpty(u)); for(let i$1 = 0; i$1 <= 3; ++i$1){ Belt_MutableSetInt.remove(u, i$1); } -b("File \"bs_mutable_set_test.res\", line 43, characters 8-15", u.data === undefined); +b("File \"bs_mutable_set_test.res\", line 43, characters 8-15", Belt_MutableSetInt.isEmpty(u)); Belt_MutableSetInt.mergeMany(u, Array_data_util.randomRange(0, 20000)); @@ -101,11 +101,11 @@ Belt_MutableSetInt.removeMany(u, Array_data_util.randomRange(10000, 19999)); eq("File \"bs_mutable_set_test.res\", line 56, characters 9-16", Belt_internalAVLset.size(u.data), 1); -b("File \"bs_mutable_set_test.res\", line 57, characters 8-15", Belt_MutableSetInt.has(u, 20000)); +b("File \"bs_mutable_set_test.res\", line 57, characters 8-15", Belt_internalSetInt.has(u.data, 20000)); Belt_MutableSetInt.removeMany(u, Array_data_util.randomRange(10000, 30000)); -b("File \"bs_mutable_set_test.res\", line 59, characters 8-15", u.data === undefined); +b("File \"bs_mutable_set_test.res\", line 59, characters 8-15", Belt_MutableSetInt.isEmpty(u)); let xs$1 = Array_data_util.randomRange(1000, 2000); @@ -145,11 +145,9 @@ eq("File \"bs_mutable_set_test.res\", line 82, characters 9-16", indeedAded, 100 eq("File \"bs_mutable_set_test.res\", line 83, characters 9-16", Belt_internalAVLset.size(v.data), 1501); -let d = { +b("File \"bs_mutable_set_test.res\", line 84, characters 8-15", Belt_MutableSetInt.isEmpty({ data: undefined -}; - -b("File \"bs_mutable_set_test.res\", line 84, characters 8-15", d.data === undefined); +})); eq("File \"bs_mutable_set_test.res\", line 85, characters 9-16", Belt_internalAVLset.minimum(v.data), 500); @@ -173,9 +171,9 @@ eq("File \"bs_mutable_set_test.res\", line 91, characters 9-16", Belt_internalAV Belt_internalAVLset.checkInvariantInternal(v.data); -eq("File \"bs_mutable_set_test.res\", line 93, characters 9-16", Belt_MutableSetInt.get(v, 3), undefined); +eq("File \"bs_mutable_set_test.res\", line 93, characters 9-16", Belt_internalSetInt.get(v.data, 3), undefined); -eq("File \"bs_mutable_set_test.res\", line 94, characters 9-16", Belt_MutableSetInt.get(v, 1200), 1200); +eq("File \"bs_mutable_set_test.res\", line 94, characters 9-16", Belt_internalSetInt.get(v.data, 1200), 1200); let match = Belt_MutableSetInt.split(v, 1000); @@ -199,9 +197,7 @@ b("File \"bs_mutable_set_test.res\", line 99, characters 8-15", Belt_MutableSetI b("File \"bs_mutable_set_test.res\", line 100, characters 8-15", Belt_MutableSetInt.subset(bb, v)); -let d$1 = Belt_MutableSetInt.intersect(aa, bb); - -b("File \"bs_mutable_set_test.res\", line 101, characters 8-15", d$1.data === undefined); +b("File \"bs_mutable_set_test.res\", line 101, characters 8-15", Belt_MutableSetInt.isEmpty(Belt_MutableSetInt.intersect(aa, bb))); let c = Belt_MutableSetInt.removeCheck(v, 1000); @@ -229,9 +225,7 @@ b("File \"bs_mutable_set_test.res\", line 108, characters 8-15", Belt_MutableSet b("File \"bs_mutable_set_test.res\", line 109, characters 8-15", Belt_MutableSetInt.subset(bb$1, v)); -let d$2 = Belt_MutableSetInt.intersect(aa$1, bb$1); - -b("File \"bs_mutable_set_test.res\", line 110, characters 8-15", d$2.data === undefined); +b("File \"bs_mutable_set_test.res\", line 110, characters 8-15", Belt_MutableSetInt.isEmpty(Belt_MutableSetInt.intersect(aa$1, bb$1))); let xs$2 = Array_data_util.randomRange(0, 100); @@ -434,7 +428,7 @@ for(let i$2 = 0; i$2 <= 100000; ++i$2){ Belt_internalAVLset.checkInvariantInternal(v$1.data); b("File \"bs_mutable_set_test.res\", line 188, characters 10-17", Belt_Range.every(0, 100000, (function (i) { - return Belt_MutableSetInt.has(v$1, i); + return Belt_internalSetInt.has(v$1.data, i); }))); eq("File \"bs_mutable_set_test.res\", line 189, characters 5-12", Belt_internalAVLset.size(v$1.data), 100001); @@ -475,7 +469,7 @@ for(let i$4 = 0 ,i_finish$2 = vv.length; i$4 < i_finish$2; ++i$4){ eq("File \"bs_mutable_set_test.res\", line 216, characters 5-12", Belt_internalAVLset.size(v$3.data), 0); -b("File \"bs_mutable_set_test.res\", line 217, characters 4-11", v$3.data === undefined); +b("File \"bs_mutable_set_test.res\", line 217, characters 4-11", Belt_MutableSetInt.isEmpty(v$3)); let xs$25 = Belt_Array.makeBy(30, (function (i) { return i; @@ -658,11 +652,11 @@ let xs$30 = Belt_Array.map(Array_data_util.randomRange(0, 1000), (function (x) { return (x << 1); })); -let d$3 = { +let d = { data: Belt_internalSetInt.fromArray(xs$30) }; -let match$8 = Belt_MutableSetInt.split(d$3, 1001); +let match$8 = Belt_MutableSetInt.split(d, 1001); let match$9 = match$8[0]; diff --git a/jscomp/test/bs_poly_map_test.js b/jscomp/test/bs_poly_map_test.js index 0865fa4cc5..d0aaf258eb 100644 --- a/jscomp/test/bs_poly_map_test.js +++ b/jscomp/test/bs_poly_map_test.js @@ -51,8 +51,7 @@ function mergeInter(s1, s2) { } })); - let x = Belt_MapDict.keysToArray(m.data); - return Belt_Set.fromArray(x, Icmp); + return Belt_Set.fromArray(Belt_MapDict.keysToArray(m.data), Icmp); } function mergeUnion(s1, s2) { @@ -62,8 +61,7 @@ function mergeUnion(s1, s2) { } })); - let x = Belt_MapDict.keysToArray(m.data); - return Belt_Set.fromArray(x, Icmp); + return Belt_Set.fromArray(Belt_MapDict.keysToArray(m.data), Icmp); } function mergeDiff(s1, s2) { @@ -73,8 +71,7 @@ function mergeDiff(s1, s2) { } })); - let x = Belt_MapDict.keysToArray(m.data); - return Belt_Set.fromArray(x, Icmp); + return Belt_Set.fromArray(Belt_MapDict.keysToArray(m.data), Icmp); } function randomRange(i, j) { @@ -86,33 +83,19 @@ function randomRange(i, j) { })); } -let x = randomRange(0, 100); - -let u0 = Belt_Map.fromArray(x, Icmp); - -let x$1 = randomRange(30, 120); - -let u1 = Belt_Map.fromArray(x$1, Icmp); - -let x$2 = Array_data_util.range(30, 100); - -b("File \"bs_poly_map_test.res\", line 64, characters 4-11", Belt_Set.eq(mergeInter(u0, u1), Belt_Set.fromArray(x$2, Icmp))); +let u0 = Belt_Map.fromArray(randomRange(0, 100), Icmp); -let x$3 = Array_data_util.range(0, 120); +let u1 = Belt_Map.fromArray(randomRange(30, 120), Icmp); -b("File \"bs_poly_map_test.res\", line 65, characters 4-11", Belt_Set.eq(mergeUnion(u0, u1), Belt_Set.fromArray(x$3, Icmp))); +b("File \"bs_poly_map_test.res\", line 64, characters 4-11", Belt_Set.eq(mergeInter(u0, u1), Belt_Set.fromArray(Array_data_util.range(30, 100), Icmp))); -let x$4 = Array_data_util.range(0, 29); +b("File \"bs_poly_map_test.res\", line 65, characters 4-11", Belt_Set.eq(mergeUnion(u0, u1), Belt_Set.fromArray(Array_data_util.range(0, 120), Icmp))); -b("File \"bs_poly_map_test.res\", line 66, characters 4-11", Belt_Set.eq(mergeDiff(u0, u1), Belt_Set.fromArray(x$4, Icmp))); +b("File \"bs_poly_map_test.res\", line 66, characters 4-11", Belt_Set.eq(mergeDiff(u0, u1), Belt_Set.fromArray(Array_data_util.range(0, 29), Icmp))); -let x$5 = Array_data_util.range(101, 120); +b("File \"bs_poly_map_test.res\", line 67, characters 4-11", Belt_Set.eq(mergeDiff(u1, u0), Belt_Set.fromArray(Array_data_util.range(101, 120), Icmp))); -b("File \"bs_poly_map_test.res\", line 67, characters 4-11", Belt_Set.eq(mergeDiff(u1, u0), Belt_Set.fromArray(x$5, Icmp))); - -let x$6 = randomRange(0, 10); - -let a0 = Belt_Map.fromArray(x$6, Icmp); +let a0 = Belt_Map.fromArray(randomRange(0, 10), Icmp); let a1 = Belt_Map.set(a0, 3, 33); @@ -176,9 +159,7 @@ let a8 = Belt_Map.removeMany(a7, Array_data_util.randomRange(0, 100)); b("File \"bs_poly_map_test.res\", line 101, characters 4-11", Belt_MapDict.isEmpty(a8.data)); -let x$7 = randomRange(0, 100); - -let u0$1 = Belt_Map.fromArray(x$7, Icmp); +let u0$1 = Belt_Map.fromArray(randomRange(0, 100), Icmp); let u1$1 = Belt_Map.set(u0$1, 3, 32); @@ -207,14 +188,12 @@ let m = { let m1 = acc(m, Belt_Array.concat(Array_data_util.randomRange(0, 20), Array_data_util.randomRange(10, 30))); -let x$8 = Belt_Array.makeBy(31, (function (i) { +b("File \"bs_poly_map_test.res\", line 126, characters 4-11", Belt_Map.eq(m1, Belt_Map.fromArray(Belt_Array.makeBy(31, (function (i) { return [ i, i >= 10 && i <= 20 ? 2 : 1 ]; -})); - -b("File \"bs_poly_map_test.res\", line 126, characters 4-11", Belt_Map.eq(m1, Belt_Map.fromArray(x$8, Icmp), (function (x, y) { +})), Icmp), (function (x, y) { return x === y; }))); @@ -232,14 +211,12 @@ let v1 = Belt_Map.mergeMany(v0, Belt_Array.map(Array_data_util.randomRange(0, 10 ]; }))); -let x$9 = Belt_Array.map(Array_data_util.randomRange(0, 10000), (function (x) { +let v2 = Belt_Map.fromArray(Belt_Array.map(Array_data_util.randomRange(0, 10000), (function (x) { return [ x, x ]; -})); - -let v2 = Belt_Map.fromArray(x$9, Icmp); +})), Icmp); b("File \"bs_poly_map_test.res\", line 150, characters 4-11", Belt_Map.eq(v1, v2, (function (x, y) { return x === y; diff --git a/jscomp/test/bs_poly_mutable_map_test.js b/jscomp/test/bs_poly_mutable_map_test.js index 3bbcd3dbfa..9563788e47 100644 --- a/jscomp/test/bs_poly_mutable_map_test.js +++ b/jscomp/test/bs_poly_mutable_map_test.js @@ -45,9 +45,7 @@ function randomRange(i, j) { })); } -let x = randomRange(0, 10); - -let a0 = Belt_MutableMap.fromArray(x, Icmp); +let a0 = Belt_MutableMap.fromArray(randomRange(0, 10), Icmp); Belt_MutableMap.set(a0, 3, 33); @@ -74,11 +72,9 @@ eq("File \"bs_poly_mutable_map_test.res\", line 29, characters 5-12", Belt_inter Belt_MutableMap.removeMany(a0, Array_data_util.randomRange(0, 100)); -b("File \"bs_poly_mutable_map_test.res\", line 31, characters 4-11", a0.data === undefined); - -let x$1 = randomRange(0, 10000); +b("File \"bs_poly_mutable_map_test.res\", line 31, characters 4-11", Belt_MutableMap.isEmpty(a0)); -let a0$1 = Belt_MutableMap.fromArray(x$1, Icmp); +let a0$1 = Belt_MutableMap.fromArray(randomRange(0, 10000), Icmp); Belt_MutableMap.set(a0$1, 2000, 33); diff --git a/jscomp/test/bs_poly_mutable_set_test.js b/jscomp/test/bs_poly_mutable_set_test.js index 676ec6ca82..33a00591d1 100644 --- a/jscomp/test/bs_poly_mutable_set_test.js +++ b/jscomp/test/bs_poly_mutable_set_test.js @@ -39,9 +39,7 @@ function empty() { }; } -let none = Array_data_util.range(0, 30); - -let u = Belt_MutableSet.fromArray(none, IntCmp); +let u = Belt_MutableSet.fromArray(Array_data_util.range(0, 30), IntCmp); b("File \"bs_poly_mutable_set_test.res\", line 16, characters 4-11", Belt_MutableSet.removeCheck(u, 0)); @@ -65,7 +63,7 @@ for(let i = 0 ,i_finish = r.length; i < i_finish; ++i){ Belt_MutableSet.remove(u, r[i]); } -b("File \"bs_poly_mutable_set_test.res\", line 28, characters 4-11", u.data === undefined); +b("File \"bs_poly_mutable_set_test.res\", line 28, characters 4-11", Belt_MutableSet.isEmpty(u)); Belt_MutableSet.add(u, 0); @@ -77,13 +75,13 @@ Belt_MutableSet.add(u, 0); eq("File \"bs_poly_mutable_set_test.res\", line 33, characters 5-12", Belt_internalAVLset.size(u.data), 3); -b("File \"bs_poly_mutable_set_test.res\", line 34, characters 4-11", u.data !== undefined); +b("File \"bs_poly_mutable_set_test.res\", line 34, characters 4-11", !Belt_MutableSet.isEmpty(u)); for(let i$1 = 0; i$1 <= 3; ++i$1){ Belt_MutableSet.remove(u, i$1); } -b("File \"bs_poly_mutable_set_test.res\", line 38, characters 4-11", u.data === undefined); +b("File \"bs_poly_mutable_set_test.res\", line 38, characters 4-11", Belt_MutableSet.isEmpty(u)); Belt_MutableSet.mergeMany(u, Array_data_util.randomRange(0, 20000)); @@ -115,11 +113,9 @@ b("File \"bs_poly_mutable_set_test.res\", line 52, characters 4-11", Belt_Mutabl Belt_MutableSet.removeMany(u, Array_data_util.randomRange(10000, 30000)); -b("File \"bs_poly_mutable_set_test.res\", line 54, characters 4-11", u.data === undefined); - -let none$1 = Array_data_util.randomRange(1000, 2000); +b("File \"bs_poly_mutable_set_test.res\", line 54, characters 4-11", Belt_MutableSet.isEmpty(u)); -let v = Belt_MutableSet.fromArray(none$1, IntCmp); +let v = Belt_MutableSet.fromArray(Array_data_util.randomRange(1000, 2000), IntCmp); let bs = Belt_Array.map(Array_data_util.randomRange(500, 1499), (function (x) { return Belt_MutableSet.removeCheck(v, x); @@ -153,12 +149,10 @@ eq("File \"bs_poly_mutable_set_test.res\", line 77, characters 5-12", indeedAded eq("File \"bs_poly_mutable_set_test.res\", line 78, characters 5-12", Belt_internalAVLset.size(v.data), 1501); -let d = { +b("File \"bs_poly_mutable_set_test.res\", line 79, characters 4-11", Belt_MutableSet.isEmpty({ cmp: IntCmp.cmp, data: undefined -}; - -b("File \"bs_poly_mutable_set_test.res\", line 79, characters 4-11", d.data === undefined); +})); eq("File \"bs_poly_mutable_set_test.res\", line 80, characters 5-12", Belt_internalAVLset.minimum(v.data), 500); @@ -208,9 +202,7 @@ b("File \"bs_poly_mutable_set_test.res\", line 94, characters 4-11", Belt_Mutabl b("File \"bs_poly_mutable_set_test.res\", line 95, characters 4-11", Belt_MutableSet.subset(bb, v)); -let d$1 = Belt_MutableSet.intersect(aa, bb); - -b("File \"bs_poly_mutable_set_test.res\", line 96, characters 4-11", d$1.data === undefined); +b("File \"bs_poly_mutable_set_test.res\", line 96, characters 4-11", Belt_MutableSet.isEmpty(Belt_MutableSet.intersect(aa, bb))); let c = Belt_MutableSet.removeCheck(v, 1000); @@ -238,52 +230,28 @@ b("File \"bs_poly_mutable_set_test.res\", line 103, characters 4-11", Belt_Mutab b("File \"bs_poly_mutable_set_test.res\", line 104, characters 4-11", Belt_MutableSet.subset(bb$1, v)); -let d$2 = Belt_MutableSet.intersect(aa$1, bb$1); - -b("File \"bs_poly_mutable_set_test.res\", line 105, characters 4-11", d$2.data === undefined); - -let none$2 = Array_data_util.randomRange(0, 100); +b("File \"bs_poly_mutable_set_test.res\", line 105, characters 4-11", Belt_MutableSet.isEmpty(Belt_MutableSet.intersect(aa$1, bb$1))); -let aa$2 = Belt_MutableSet.fromArray(none$2, IntCmp); +let aa$2 = Belt_MutableSet.fromArray(Array_data_util.randomRange(0, 100), IntCmp); -let none$3 = Array_data_util.randomRange(40, 120); - -let bb$2 = Belt_MutableSet.fromArray(none$3, IntCmp); +let bb$2 = Belt_MutableSet.fromArray(Array_data_util.randomRange(40, 120), IntCmp); let cc = Belt_MutableSet.union(aa$2, bb$2); -let none$4 = Array_data_util.randomRange(0, 120); - -b("File \"bs_poly_mutable_set_test.res\", line 115, characters 4-11", Belt_MutableSet.eq(cc, Belt_MutableSet.fromArray(none$4, IntCmp))); - -let none$5 = Array_data_util.randomRange(0, 20); - -let none$6 = Array_data_util.randomRange(21, 40); +b("File \"bs_poly_mutable_set_test.res\", line 115, characters 4-11", Belt_MutableSet.eq(cc, Belt_MutableSet.fromArray(Array_data_util.randomRange(0, 120), IntCmp))); -let none$7 = Array_data_util.randomRange(0, 40); - -b("File \"bs_poly_mutable_set_test.res\", line 118, characters 4-11", Belt_MutableSet.eq(Belt_MutableSet.union(Belt_MutableSet.fromArray(none$5, IntCmp), Belt_MutableSet.fromArray(none$6, IntCmp)), Belt_MutableSet.fromArray(none$7, IntCmp))); +b("File \"bs_poly_mutable_set_test.res\", line 118, characters 4-11", Belt_MutableSet.eq(Belt_MutableSet.union(Belt_MutableSet.fromArray(Array_data_util.randomRange(0, 20), IntCmp), Belt_MutableSet.fromArray(Array_data_util.randomRange(21, 40), IntCmp)), Belt_MutableSet.fromArray(Array_data_util.randomRange(0, 40), IntCmp))); let dd = Belt_MutableSet.intersect(aa$2, bb$2); -let none$8 = Array_data_util.randomRange(40, 100); - -b("File \"bs_poly_mutable_set_test.res\", line 122, characters 4-11", Belt_MutableSet.eq(dd, Belt_MutableSet.fromArray(none$8, IntCmp))); - -let none$9 = Array_data_util.randomRange(0, 20); +b("File \"bs_poly_mutable_set_test.res\", line 122, characters 4-11", Belt_MutableSet.eq(dd, Belt_MutableSet.fromArray(Array_data_util.randomRange(40, 100), IntCmp))); -let none$10 = Array_data_util.randomRange(21, 40); - -b("File \"bs_poly_mutable_set_test.res\", line 124, characters 4-11", Belt_MutableSet.eq(Belt_MutableSet.intersect(Belt_MutableSet.fromArray(none$9, IntCmp), Belt_MutableSet.fromArray(none$10, IntCmp)), { +b("File \"bs_poly_mutable_set_test.res\", line 124, characters 4-11", Belt_MutableSet.eq(Belt_MutableSet.intersect(Belt_MutableSet.fromArray(Array_data_util.randomRange(0, 20), IntCmp), Belt_MutableSet.fromArray(Array_data_util.randomRange(21, 40), IntCmp)), { cmp: IntCmp.cmp, data: undefined })); -let none$11 = Array_data_util.randomRange(21, 40); - -let none$12 = Array_data_util.randomRange(0, 20); - -b("File \"bs_poly_mutable_set_test.res\", line 128, characters 4-11", Belt_MutableSet.eq(Belt_MutableSet.intersect(Belt_MutableSet.fromArray(none$11, IntCmp), Belt_MutableSet.fromArray(none$12, IntCmp)), { +b("File \"bs_poly_mutable_set_test.res\", line 128, characters 4-11", Belt_MutableSet.eq(Belt_MutableSet.intersect(Belt_MutableSet.fromArray(Array_data_util.randomRange(21, 40), IntCmp), Belt_MutableSet.fromArray(Array_data_util.randomRange(0, 20), IntCmp)), { cmp: IntCmp.cmp, data: undefined })); @@ -307,41 +275,17 @@ b("File \"bs_poly_mutable_set_test.res\", line 131, characters 4-11", Belt_Mutab 5 ], IntCmp))); -let none$13 = Array_data_util.randomRange(0, 39); - -b("File \"bs_poly_mutable_set_test.res\", line 132, characters 4-11", Belt_MutableSet.eq(Belt_MutableSet.diff(aa$2, bb$2), Belt_MutableSet.fromArray(none$13, IntCmp))); - -let none$14 = Array_data_util.randomRange(101, 120); - -b("File \"bs_poly_mutable_set_test.res\", line 133, characters 4-11", Belt_MutableSet.eq(Belt_MutableSet.diff(bb$2, aa$2), Belt_MutableSet.fromArray(none$14, IntCmp))); - -let none$15 = Array_data_util.randomRange(21, 40); - -let none$16 = Array_data_util.randomRange(0, 20); - -let none$17 = Array_data_util.randomRange(21, 40); - -b("File \"bs_poly_mutable_set_test.res\", line 135, characters 4-11", Belt_MutableSet.eq(Belt_MutableSet.diff(Belt_MutableSet.fromArray(none$15, IntCmp), Belt_MutableSet.fromArray(none$16, IntCmp)), Belt_MutableSet.fromArray(none$17, IntCmp))); - -let none$18 = Array_data_util.randomRange(0, 20); - -let none$19 = Array_data_util.randomRange(21, 40); - -let none$20 = Array_data_util.randomRange(0, 20); - -b("File \"bs_poly_mutable_set_test.res\", line 142, characters 4-11", Belt_MutableSet.eq(Belt_MutableSet.diff(Belt_MutableSet.fromArray(none$18, IntCmp), Belt_MutableSet.fromArray(none$19, IntCmp)), Belt_MutableSet.fromArray(none$20, IntCmp))); - -let none$21 = Array_data_util.randomRange(0, 20); +b("File \"bs_poly_mutable_set_test.res\", line 132, characters 4-11", Belt_MutableSet.eq(Belt_MutableSet.diff(aa$2, bb$2), Belt_MutableSet.fromArray(Array_data_util.randomRange(0, 39), IntCmp))); -let none$22 = Array_data_util.randomRange(0, 40); +b("File \"bs_poly_mutable_set_test.res\", line 133, characters 4-11", Belt_MutableSet.eq(Belt_MutableSet.diff(bb$2, aa$2), Belt_MutableSet.fromArray(Array_data_util.randomRange(101, 120), IntCmp))); -let none$23 = Array_data_util.randomRange(0, -1); +b("File \"bs_poly_mutable_set_test.res\", line 135, characters 4-11", Belt_MutableSet.eq(Belt_MutableSet.diff(Belt_MutableSet.fromArray(Array_data_util.randomRange(21, 40), IntCmp), Belt_MutableSet.fromArray(Array_data_util.randomRange(0, 20), IntCmp)), Belt_MutableSet.fromArray(Array_data_util.randomRange(21, 40), IntCmp))); -b("File \"bs_poly_mutable_set_test.res\", line 150, characters 4-11", Belt_MutableSet.eq(Belt_MutableSet.diff(Belt_MutableSet.fromArray(none$21, IntCmp), Belt_MutableSet.fromArray(none$22, IntCmp)), Belt_MutableSet.fromArray(none$23, IntCmp))); +b("File \"bs_poly_mutable_set_test.res\", line 142, characters 4-11", Belt_MutableSet.eq(Belt_MutableSet.diff(Belt_MutableSet.fromArray(Array_data_util.randomRange(0, 20), IntCmp), Belt_MutableSet.fromArray(Array_data_util.randomRange(21, 40), IntCmp)), Belt_MutableSet.fromArray(Array_data_util.randomRange(0, 20), IntCmp))); -let none$24 = Array_data_util.randomRange(0, 1000); +b("File \"bs_poly_mutable_set_test.res\", line 150, characters 4-11", Belt_MutableSet.eq(Belt_MutableSet.diff(Belt_MutableSet.fromArray(Array_data_util.randomRange(0, 20), IntCmp), Belt_MutableSet.fromArray(Array_data_util.randomRange(0, 40), IntCmp)), Belt_MutableSet.fromArray(Array_data_util.randomRange(0, -1), IntCmp))); -let a0 = Belt_MutableSet.fromArray(none$24, IntCmp); +let a0 = Belt_MutableSet.fromArray(Array_data_util.randomRange(0, 1000), IntCmp); let a1 = Belt_MutableSet.keep(a0, (function (x) { return x % 2 === 0; diff --git a/jscomp/test/bs_queue_test.js b/jscomp/test/bs_queue_test.js index 432d8a9bdb..a57ca4a829 100644 --- a/jscomp/test/bs_queue_test.js +++ b/jscomp/test/bs_queue_test.js @@ -56,7 +56,7 @@ if (!(Caml_obj.equal(Belt_MutableQueue.toArray(q), []) && q.length === 0)) { }); } -if (!(Caml_obj.equal(Belt_MutableQueue.toArray($plus$plus(q, 1)), [1]) && q.length === 1)) { +if (!(Caml_obj.equal(Belt_MutableQueue.toArray((Belt_MutableQueue.add(q, 1), q)), [1]) && q.length === 1)) { throw new Error("Assert_failure", { cause: { RE_EXN_ID: "Assert_failure", @@ -69,7 +69,7 @@ if (!(Caml_obj.equal(Belt_MutableQueue.toArray($plus$plus(q, 1)), [1]) && q.leng }); } -if (!(Caml_obj.equal(Belt_MutableQueue.toArray($plus$plus(q, 2)), [ +if (!(Caml_obj.equal(Belt_MutableQueue.toArray((Belt_MutableQueue.add(q, 2), q)), [ 1, 2 ]) && q.length === 2)) { @@ -85,7 +85,7 @@ if (!(Caml_obj.equal(Belt_MutableQueue.toArray($plus$plus(q, 2)), [ }); } -if (!(Caml_obj.equal(Belt_MutableQueue.toArray($plus$plus(q, 3)), [ +if (!(Caml_obj.equal(Belt_MutableQueue.toArray((Belt_MutableQueue.add(q, 3), q)), [ 1, 2, 3 @@ -102,7 +102,7 @@ if (!(Caml_obj.equal(Belt_MutableQueue.toArray($plus$plus(q, 3)), [ }); } -if (!(Caml_obj.equal(Belt_MutableQueue.toArray($plus$plus(q, 4)), [ +if (!(Caml_obj.equal(Belt_MutableQueue.toArray((Belt_MutableQueue.add(q, 4), q)), [ 1, 2, 3, @@ -250,7 +250,7 @@ let q$1 = { last: undefined }; -if (Belt_MutableQueue.popExn($plus$plus(q$1, 1)) !== 1) { +if (Belt_MutableQueue.popExn((Belt_MutableQueue.add(q$1, 1), q$1)) !== 1) { throw new Error("Assert_failure", { cause: { RE_EXN_ID: "Assert_failure", @@ -276,7 +276,7 @@ if (!does_raise(Belt_MutableQueue.popExn, q$1)) { }); } -if (Belt_MutableQueue.popExn($plus$plus(q$1, 2)) !== 2) { +if (Belt_MutableQueue.popExn((Belt_MutableQueue.add(q$1, 2), q$1)) !== 2) { throw new Error("Assert_failure", { cause: { RE_EXN_ID: "Assert_failure", @@ -321,7 +321,7 @@ let q$2 = { last: undefined }; -if (Belt_MutableQueue.peekExn($plus$plus(q$2, 1)) !== 1) { +if (Belt_MutableQueue.peekExn((Belt_MutableQueue.add(q$2, 1), q$2)) !== 1) { throw new Error("Assert_failure", { cause: { RE_EXN_ID: "Assert_failure", @@ -334,7 +334,7 @@ if (Belt_MutableQueue.peekExn($plus$plus(q$2, 1)) !== 1) { }); } -if (Belt_MutableQueue.peekExn($plus$plus(q$2, 2)) !== 1) { +if (Belt_MutableQueue.peekExn((Belt_MutableQueue.add(q$2, 2), q$2)) !== 1) { throw new Error("Assert_failure", { cause: { RE_EXN_ID: "Assert_failure", @@ -347,7 +347,7 @@ if (Belt_MutableQueue.peekExn($plus$plus(q$2, 2)) !== 1) { }); } -if (Belt_MutableQueue.peekExn($plus$plus(q$2, 3)) !== 1) { +if (Belt_MutableQueue.peekExn((Belt_MutableQueue.add(q$2, 3), q$2)) !== 1) { throw new Error("Assert_failure", { cause: { RE_EXN_ID: "Assert_failure", @@ -1371,4 +1371,4 @@ exports.b = b; exports.Q = Q; exports.does_raise = does_raise; exports.$plus$plus = $plus$plus; -/* q Not a pure module */ +/* Not a pure module */ diff --git a/jscomp/test/bs_set_int_test.js b/jscomp/test/bs_set_int_test.js index 83bfef16e5..80039fd7d5 100644 --- a/jscomp/test/bs_set_int_test.js +++ b/jscomp/test/bs_set_int_test.js @@ -52,7 +52,7 @@ let u = Belt_SetInt.intersect(Belt_SetInt.fromArray([ 5 ])); -b("File \"bs_set_int_test.res\", line 27, characters 11-18", $eq$tilde(u, [3])); +b("File \"bs_set_int_test.res\", line 27, characters 11-18", Belt_SetInt.eq(Belt_SetInt.fromArray([3]), u)); function range(i, j) { return $$Array.init((j - i | 0) + 1 | 0, (function (k) { @@ -68,7 +68,9 @@ function revRange(i, j) { let v = Belt_SetInt.fromArray($$Array.append(range(100, 1000), revRange(400, 1500))); -b("File \"bs_set_int_test.res\", line 37, characters 4-11", $eq$tilde(v, range(100, 1500))); +let i = range(100, 1500); + +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, (function (x) { return x % 3 === 0; @@ -78,11 +80,11 @@ let l; let r; -for(let i = 100; i <= 1500; ++i){ - if (i % 3 === 0) { - l = Belt_SetInt.add(l, i); +for(let i$1 = 100; i$1 <= 1500; ++i$1){ + if (i$1 % 3 === 0) { + l = Belt_SetInt.add(l, i$1); } else { - r = Belt_SetInt.add(r, i); + r = Belt_SetInt.add(r, i$1); } } @@ -94,17 +96,41 @@ b("File \"bs_set_int_test.res\", line 50, characters 4-11", Belt_SetInt.eq(match b("File \"bs_set_int_test.res\", line 51, characters 4-11", Belt_SetInt.eq(match[1], nr)); -b("File \"bs_set_int_test.res\", line 55, characters 2-9", $eq$tilde(Belt_SetInt.intersect(Belt_SetInt.fromArray(range(1, 100)), Belt_SetInt.fromArray(range(50, 200))), range(50, 100))); +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 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 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 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 88, characters 2-9", Belt_SetInt.eq(Belt_SetInt.fromArray(i$5), s$3)); + +let i$6 = revRange(1, 200); -b("File \"bs_set_int_test.res\", line 66, characters 2-9", $eq$tilde(Belt_SetInt.union(Belt_SetInt.fromArray(range(1, 100)), Belt_SetInt.fromArray(range(50, 200))), range(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 77, characters 2-9", $eq$tilde(Belt_SetInt.diff(Belt_SetInt.fromArray(range(1, 100)), Belt_SetInt.fromArray(range(50, 200))), range(1, 49))); +b("File \"bs_set_int_test.res\", line 99, characters 2-9", Belt_SetInt.eq(Belt_SetInt.fromArray(i$6), s$4)); -b("File \"bs_set_int_test.res\", line 88, characters 2-9", $eq$tilde(Belt_SetInt.intersect(Belt_SetInt.fromArray(revRange(1, 100)), Belt_SetInt.fromArray(revRange(50, 200))), revRange(50, 100))); +let i$7 = revRange(1, 49); -b("File \"bs_set_int_test.res\", line 99, characters 2-9", $eq$tilde(Belt_SetInt.union(Belt_SetInt.fromArray(revRange(1, 100)), Belt_SetInt.fromArray(revRange(50, 200))), revRange(1, 200))); +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 110, characters 2-9", $eq$tilde(Belt_SetInt.diff(Belt_SetInt.fromArray(revRange(1, 100)), Belt_SetInt.fromArray(revRange(50, 200))), revRange(1, 49))); +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, diff --git a/jscomp/test/bs_unwrap_test.js b/jscomp/test/bs_unwrap_test.js index 25e7a582d8..9280a5b7ba 100644 --- a/jscomp/test/bs_unwrap_test.js +++ b/jscomp/test/bs_unwrap_test.js @@ -48,9 +48,7 @@ console.log(5, Caml_option.option_unwrap(some_arg)); console.log(6, undefined); -console.log(7, Caml_option.option_unwrap((function () { - console.log("trace"); -})())); +console.log(7, Caml_option.option_unwrap((console.log("trace"), undefined))); function dyn_log3(prim0, prim1, prim2) { console.log(prim0.VAL, Caml_option.option_unwrap(prim1)); diff --git a/jscomp/test/caml_format_test.js b/jscomp/test/caml_format_test.js index 6fee11065f..f184d33bb2 100644 --- a/jscomp/test/caml_format_test.js +++ b/jscomp/test/caml_format_test.js @@ -423,7 +423,7 @@ let of_string_data = [ ] ]; -let extra = Pervasives.$at(suites, Pervasives.$at($$Array.to_list($$Array.mapi((function (i, param) { +Mt.from_pair_suites("Caml_format_test", Pervasives.$at(suites, Pervasives.$at($$Array.to_list($$Array.mapi((function (i, param) { let str_result = param[2]; let f = param[1]; let fmt = param[0]; @@ -450,9 +450,7 @@ let extra = Pervasives.$at(suites, Pervasives.$at($$Array.to_list($$Array.mapi(( }; }) ]; -}), of_string_data))))); - -Mt.from_pair_suites("Caml_format_test", extra); +}), of_string_data)))))); let float_suites = { hd: "float_nan", diff --git a/jscomp/test/coercion_module_alias_test.js b/jscomp/test/coercion_module_alias_test.js index 42b9423056..996ebb34db 100644 --- a/jscomp/test/coercion_module_alias_test.js +++ b/jscomp/test/coercion_module_alias_test.js @@ -24,9 +24,7 @@ let prim$2 = Char.chr(66); console.log(prim$2); -function f(x) { - return List.length(x); -} +let f = List.length; function g(x) { return List.length(List.map((function (prim) { diff --git a/jscomp/test/complex_if_test.js b/jscomp/test/complex_if_test.js index 6fc7e2d7c5..ac9d60a393 100644 --- a/jscomp/test/complex_if_test.js +++ b/jscomp/test/complex_if_test.js @@ -127,7 +127,7 @@ let suites_0 = [ (function (param) { return { TAG: "Eq", - _0: 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"), + _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" }; }) diff --git a/jscomp/test/digest_test.js b/jscomp/test/digest_test.js index 645a59a61f..f6f053b4cc 100644 --- a/jscomp/test/digest_test.js +++ b/jscomp/test/digest_test.js @@ -145,7 +145,7 @@ let ref = [ "b325dc1c6f5e7a2b7cf465b9feab7948" ]; -let extra = Pervasives.$at({ +Mt.from_pair_suites("Digest_test", Pervasives.$at({ hd: [ "File \"digest_test.res\", line 9, characters 9-16", (function () { @@ -228,9 +228,7 @@ let extra = Pervasives.$at({ }; }) ]; -}), Ext_array_test.range(0, 129)))); - -Mt.from_pair_suites("Digest_test", extra); +}), Ext_array_test.range(0, 129))))); exports.f = f; -/* extra Not a pure module */ +/* Not a pure module */ diff --git a/jscomp/test/event_ffi.js b/jscomp/test/event_ffi.js index c1a9fb070f..d4144f53a3 100644 --- a/jscomp/test/event_ffi.js +++ b/jscomp/test/event_ffi.js @@ -34,8 +34,7 @@ function h34(x) { } function ocaml_run(b, c) { - let x = 1; - return (x + b | 0) + c | 0; + return (1 + b | 0) + c | 0; } function a0() { diff --git a/jscomp/test/ext_array_test.js b/jscomp/test/ext_array_test.js index 6e74676a71..de2c274cb2 100644 --- a/jscomp/test/ext_array_test.js +++ b/jscomp/test/ext_array_test.js @@ -104,32 +104,32 @@ function filter_map(f, a) { } function range(from, to_) { - if (from <= to_) { - return $$Array.init((to_ - from | 0) + 1 | 0, (function (i) { - return i + from | 0; - })); + if (from > to_) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Ext_array_test.range" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Ext_array_test.range" - } - }); + return $$Array.init((to_ - from | 0) + 1 | 0, (function (i) { + return i + from | 0; + })); } function map2i(f, a, b) { let len = a.length; - if (len === b.length) { - return $$Array.mapi((function (i, a) { - return f(i, a, b[i]); - }), a); + if (len !== b.length) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Ext_array_test.map2i" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Ext_array_test.map2i" - } - }); + return $$Array.mapi((function (i, a) { + return f(i, a, b[i]); + }), a); } function tolist_aux(a, f, _i, _res) { diff --git a/jscomp/test/ext_bytes_test.js b/jscomp/test/ext_bytes_test.js index 9c496d4a89..6e333d5bf1 100644 --- a/jscomp/test/ext_bytes_test.js +++ b/jscomp/test/ext_bytes_test.js @@ -5,7 +5,6 @@ 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 $$String = require("../../lib/js/string.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"); @@ -158,25 +157,21 @@ function starts_with(xs, prefix, p) { } } -let a = Bytes.init(100, (function (i) { - return Char.chr(i); -})); +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, (function (i) { - return Char.chr(i); -})); +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 a$2 = $$String.init(100, (function (i) { - return Char.chr(i); -})); +let f = Char.chr; + +let a$2 = Bytes.unsafe_to_string(Bytes.init(100, f)); let b = Bytes.init(100, (function (i) { return /* '\000' */0; @@ -196,7 +191,7 @@ let s2 = Bytes.of_string(s1); eq("File \"ext_bytes_test.res\", line 153, characters 5-12", s, s2); -function f(a, b) { +function f$1(a, b) { return [ Caml_bytes.bytes_greaterthan(a, b), Caml_bytes.bytes_greaterequal(a, b), @@ -223,6 +218,6 @@ exports.test_id = test_id; exports.eq = eq; exports.escaped = escaped; exports.starts_with = starts_with; -exports.f = f; +exports.f = f$1; exports.f_0 = f_0; /* a Not a pure module */ diff --git a/jscomp/test/ext_filename_test.js b/jscomp/test/ext_filename_test.js index af53b2859e..b4df9c0f72 100644 --- a/jscomp/test/ext_filename_test.js +++ b/jscomp/test/ext_filename_test.js @@ -2,9 +2,9 @@ 'use strict'; let Sys = require("../../lib/js/sys.js"); -let Lazy = require("../../lib/js/lazy.js"); let List = require("../../lib/js/list.js"); -let $$String = require("../../lib/js/string.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"); @@ -19,7 +19,7 @@ let node_parent = ".."; let node_current = "."; -let cwd = Lazy.from_fun(function () { +let cwd = CamlinternalLazy.from_fun(function () { return Caml_sys.sys_getcwd(); }); @@ -63,10 +63,11 @@ function chop_extension(locOpt, 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 new Error("Invalid_argument", { cause: { RE_EXN_ID: "Invalid_argument", - _1: "Filename.chop_extension ( " + loc + " : " + name + " )" + _1: s } }); } @@ -114,13 +115,13 @@ function relative_path(file_or_dir_1, file_or_dir_2) { }; let ys = go(dir1, dir2); if (ys && ys.hd === node_parent) { - return $$String.concat(node_sep, ys); + return $$Array.of_list(ys).join(node_sep); } - let __x = { + let xs = { hd: node_current, tl: ys }; - return $$String.concat(node_sep, __x); + return $$Array.of_list(xs).join(node_sep); } function node_relative_path(node_modules_shorten, file1, dep_file) { @@ -146,10 +147,11 @@ function node_relative_path(node_modules_shorten, file1, dep_file) { while(true) { let i = _i; if (i >= len) { + let s = "invalid path: " + file2; throw new Error("Failure", { cause: { RE_EXN_ID: "Failure", - _1: "invalid path: " + file2 + _1: s } }); } @@ -175,10 +177,11 @@ function find_root_filename(_cwd, filename) { _cwd = cwd$p; continue; } + let s = filename + " not found from " + cwd; throw new Error("Failure", { cause: { RE_EXN_ID: "Failure", - _1: filename + " not found from " + cwd + _1: s } }); }; @@ -188,17 +191,19 @@ function find_package_json_dir(cwd) { return find_root_filename(cwd, Test_literals.bsconfig_json); } -let package_dir = Lazy.from_fun(function () { +let package_dir = CamlinternalLazy.from_fun(function () { let cwd$1 = CamlinternalLazy.force(cwd); return find_root_filename(cwd$1, Test_literals.bsconfig_json); }); function module_name_of_file(file) { - return $$String.capitalize_ascii(Filename.chop_extension(Filename.basename(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) { - return $$String.capitalize_ascii(chop_extension_if_any(Filename.basename(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) { @@ -254,9 +259,7 @@ function rel_normalized_absolute_path(from, to_) { let xss = _xss; if (!xss) { if (yss) { - return List.fold_left((function (acc, x) { - return Filename.concat(acc, x); - }), yss.hd, yss.tl); + return List.fold_left(Filename.concat, yss.hd, yss.tl); } else { return Ext_string_test.empty; } @@ -275,9 +278,7 @@ function rel_normalized_absolute_path(from, to_) { let start = List.fold_left((function (acc, param) { return Filename.concat(acc, Ext_string_test.parent_dir_lit); }), Ext_string_test.parent_dir_lit, xs); - return List.fold_left((function (acc, v) { - return Filename.concat(acc, v); - }), start, yss); + return List.fold_left(Filename.concat, start, yss); }; } @@ -354,10 +355,11 @@ if (Sys.unix) { } 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 new Error("Failure", { cause: { RE_EXN_ID: "Failure", - _1: "Unknown OS : " + Sys.os_type + _1: s } }); } @@ -387,4 +389,4 @@ 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; -/* cwd Not a pure module */ +/* simple_convert_node_path_to_os_path Not a pure module */ diff --git a/jscomp/test/ext_list_test.js b/jscomp/test/ext_list_test.js index d2870ed0bd..f502e1c310 100644 --- a/jscomp/test/ext_list_test.js +++ b/jscomp/test/ext_list_test.js @@ -303,15 +303,15 @@ function flat_map2(f, lx, ly) { } }); } - if (!ly$1) { - return List.rev(acc); + if (ly$1) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Ext_list_test.flat_map2" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Ext_list_test.flat_map2" - } - }); + return List.rev(acc); }; } @@ -431,15 +431,15 @@ function fold_right2_last(f, l1, l2, accu) { } }); } - if (!l2) { - return accu; + if (l2) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "List.fold_right2" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_right2" - } - }); + return accu; } function init(n, f) { @@ -449,18 +449,18 @@ function init(n, f) { function take(n, l) { let arr = $$Array.of_list(l); let arr_length = arr.length; - if (arr_length >= n) { - return [ - $$Array.to_list($$Array.sub(arr, 0, n)), - $$Array.to_list($$Array.sub(arr, n, arr_length - n | 0)) - ]; + if (arr_length < n) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Ext_list_test.take" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Ext_list_test.take" - } - }); + 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) { diff --git a/jscomp/test/ext_string_test.js b/jscomp/test/ext_string_test.js index 53b4cc582a..9939699352 100644 --- a/jscomp/test/ext_string_test.js +++ b/jscomp/test/ext_string_test.js @@ -216,15 +216,15 @@ function unsafe_for_all_range(s, _start, finish, p) { function for_all_range(s, start, finish, p) { let len = s.length; - if (!(start < 0 || finish >= len)) { - return unsafe_for_all_range(s, start, finish, p); + if (start < 0 || finish >= len) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Ext_string_test.for_all_range" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Ext_string_test.for_all_range" - } - }); + return unsafe_for_all_range(s, start, finish, p); } function for_all(p, s) { @@ -300,27 +300,27 @@ function contain_substring(s, sub) { function non_overlap_count(sub, s) { let sub_len = sub.length; - if (sub.length !== 0) { - 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; - }; + if (sub.length === 0) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Ext_string_test.non_overlap_count" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Ext_string_test.non_overlap_count" - } - }); + 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) { @@ -553,15 +553,15 @@ function unsafe_no_char_idx(x, ch, _i, last_idx) { function no_char(x, ch, i, len) { let str_len = x.length; - if (!(i < 0 || i >= str_len || len >= str_len)) { - return unsafe_no_char(x, ch, i, len); + if (i < 0 || i >= str_len || len >= str_len) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Ext_string_test.no_char" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Ext_string_test.no_char" - } - }); + return unsafe_no_char(x, ch, i, len); } function no_slash(x) { diff --git a/jscomp/test/ffi_arity_test.js b/jscomp/test/ffi_arity_test.js index 71cf9a5704..eb3eb30760 100644 --- a/jscomp/test/ffi_arity_test.js +++ b/jscomp/test/ffi_arity_test.js @@ -63,9 +63,7 @@ function abc(x, y, z) { return (x + y | 0) + z | 0; } -function abc_u(x, y, z) { - return abc(x, y, z); -} +let abc_u = abc; fff(); diff --git a/jscomp/test/float_test.js b/jscomp/test/float_test.js index 9968b2483c..7998fe9d09 100644 --- a/jscomp/test/float_test.js +++ b/jscomp/test/float_test.js @@ -322,7 +322,7 @@ let b = match$4[1]; let a = match$4[0]; -let extra = Pervasives.$at({ +Mt.from_pair_suites("Float_test", Pervasives.$at({ hd: [ "mod_float", (function () { @@ -370,9 +370,7 @@ let extra = Pervasives.$at({ } } } -}, Pervasives.$at(from_pairs(results), suites.contents)); - -Mt.from_pair_suites("Float_test", extra); +}, Pervasives.$at(from_pairs(results), suites.contents))); exports.test_id = test_id; exports.suites = suites; diff --git a/jscomp/test/for_loop_test.js b/jscomp/test/for_loop_test.js index 03b984a4c1..167938029a 100644 --- a/jscomp/test/for_loop_test.js +++ b/jscomp/test/for_loop_test.js @@ -164,9 +164,6 @@ function for_9() { tl: v.contents }; }; - let get = function () { - return $$Array.of_list(List.rev(v.contents)); - }; let vv = { contents: 0 }; @@ -203,7 +200,7 @@ function for_9() { }), arr2); return [[ vv.contents, - get(), + $$Array.of_list(List.rev(v.contents)), vv2.contents ]]; } diff --git a/jscomp/test/format_test.js b/jscomp/test/format_test.js index 9c7de3c192..e7dbc96ed5 100644 --- a/jscomp/test/format_test.js +++ b/jscomp/test/format_test.js @@ -3,7 +3,7 @@ let Mt = require("./mt.js"); let List = require("../../lib/js/list.js"); -let $$String = require("../../lib/js/string.js"); +let Bytes = require("../../lib/js/bytes.js"); let Pervasives = require("../../lib/js/pervasives.js"); let Caml_format = require("../../lib/js/caml_format.js"); @@ -174,7 +174,9 @@ let literals = { aux_list("File \"format_test.res\", line 72, characters 18-25", literals); -eq("File \"format_test.res\", line 74, characters 12-19", $$String.uppercase_ascii(Caml_format.hexstring_of_float(7.875, -1, /* '-' */45)), "0X1.F8P+2"); +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); diff --git a/jscomp/test/functors.js b/jscomp/test/functors.js index 7af4f0d308..f56f95b996 100644 --- a/jscomp/test/functors.js +++ b/jscomp/test/functors.js @@ -20,7 +20,7 @@ function F(X, Y) { return Y.foo(X.foo(x)); }; let sheep = function (x) { - return 1 + cow(x) | 0; + return 1 + Y.foo(X.foo(x)) | 0; }; return { cow: cow, @@ -29,11 +29,8 @@ function F(X, Y) { } function F1(X, Y) { - let cow = function (x) { - return Y.foo(X.foo(x)); - }; let sheep = function (x) { - return 1 + cow(x) | 0; + return 1 + Y.foo(X.foo(x)) | 0; }; return { sheep: sheep @@ -41,11 +38,8 @@ function F1(X, Y) { } function F2(X, Y) { - let cow = function (x) { - return Y.foo(X.foo(x)); - }; let sheep = function (x) { - return 1 + cow(x) | 0; + return 1 + Y.foo(X.foo(x)) | 0; }; return { sheep: sheep @@ -54,11 +48,8 @@ function F2(X, Y) { let M = { F: (function (funarg, funarg$1) { - let cow = function (x) { - return funarg$1.foo(funarg.foo(x)); - }; let sheep = function (x) { - return 1 + cow(x) | 0; + return 1 + funarg$1.foo(funarg.foo(x)) | 0; }; return { sheep: sheep diff --git a/jscomp/test/gpr_1154_test.js b/jscomp/test/gpr_1154_test.js index 96e585681a..b951f6fc97 100644 --- a/jscomp/test/gpr_1154_test.js +++ b/jscomp/test/gpr_1154_test.js @@ -52,7 +52,7 @@ function g2(x) { return Caml_int64.or_(x, (v.contents = v.contents + 1 | 0, x)); } -let a = g2(Int64.one); +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); diff --git a/jscomp/test/gpr_1423_app_test.js b/jscomp/test/gpr_1423_app_test.js index fee9718e51..da8edcbc0e 100644 --- a/jscomp/test/gpr_1423_app_test.js +++ b/jscomp/test/gpr_1423_app_test.js @@ -40,9 +40,7 @@ function foo2(f) { return f("a1", undefined); } -eq("File \"gpr_1423_app_test.res\", line 15, characters 12-19", (function (none, extra) { - return none + "a2"; -})("a1", undefined), "a1a2"); +eq("File \"gpr_1423_app_test.res\", line 15, characters 12-19", "a1a2", "a1a2"); Mt.from_pair_suites("Gpr_1423_app_test", suites.contents); diff --git a/jscomp/test/gpr_1667_test.js b/jscomp/test/gpr_1667_test.js index 75efb35a82..a1f9c44493 100644 --- a/jscomp/test/gpr_1667_test.js +++ b/jscomp/test/gpr_1667_test.js @@ -28,10 +28,6 @@ function eq(loc, x, y) { }; } -(function (z) { - return 0; -})(false) === 0; - eq("File \"gpr_1667_test.res\", line 24, characters 5-12", 0, 0); Mt.from_pair_suites("Gpr_1667_test", suites.contents); diff --git a/jscomp/test/gpr_1692_test.js b/jscomp/test/gpr_1692_test.js index ba792ec3b4..884c49a7dc 100644 --- a/jscomp/test/gpr_1692_test.js +++ b/jscomp/test/gpr_1692_test.js @@ -2,10 +2,8 @@ 'use strict'; -(function (x) { - return function (f) { +((function (f) { return 0; - }; -})("")(""); + })("")); /* Not a pure module */ diff --git a/jscomp/test/gpr_3697_test.js b/jscomp/test/gpr_3697_test.js index 1d38845ec9..884b7b1a50 100644 --- a/jscomp/test/gpr_3697_test.js +++ b/jscomp/test/gpr_3697_test.js @@ -1,13 +1,14 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Lazy = require("../../lib/js/lazy.js"); let CamlinternalLazy = require("../../lib/js/camlinternalLazy.js"); function fix() { return { TAG: "Fix", - _0: Lazy.from_fun(fix) + _0: CamlinternalLazy.from_fun(function () { + return fix(); + }) }; } diff --git a/jscomp/test/gpr_3875_test.js b/jscomp/test/gpr_3875_test.js index abb933adc3..51d9d0db8d 100644 --- a/jscomp/test/gpr_3875_test.js +++ b/jscomp/test/gpr_3875_test.js @@ -17,32 +17,33 @@ let Xx = { function compilerBug(a, b, c, f) { let exit = 0; - let exit$1 = 0; - if (a === "x") { + if (a !== "x") { exit = 2; - } else { - exit$1 = 3; - } - if (exit$1 === 3) { - exit = b === "x" ? 2 : 1; } - switch (exit) { - case 1 : - if (c) { - result.contents = "No x, c is true"; - } else { - result.contents = "No x, c is false"; - } - return; - case 2 : - if (f()) { - result.contents = "Some x, f returns true"; - } else { - result.contents = "Some x, f returns false"; - } - return; + if (exit === 2) { + if (b === undefined) { + if (c) { + result.contents = "No x, c is true"; + } else { + result.contents = "No x, c is false"; + } + return; + } + if (b !== "x") { + if (c) { + result.contents = "No x, c is true"; + } else { + result.contents = "No x, c is false"; + } + return; + } } + if (f()) { + result.contents = "Some x, f returns true"; + } else { + result.contents = "Some x, f returns false"; + } } let suites = { diff --git a/jscomp/test/gpr_405_test.js b/jscomp/test/gpr_405_test.js index a27fad4498..de96727ae0 100644 --- a/jscomp/test/gpr_405_test.js +++ b/jscomp/test/gpr_405_test.js @@ -125,4 +125,4 @@ function Make(funarg) { } exports.Make = Make; -/* Hashtbl Not a pure module */ +/* No side effect */ diff --git a/jscomp/test/gpr_4265_test.js b/jscomp/test/gpr_4265_test.js index f40f38c687..56b6ad3757 100644 --- a/jscomp/test/gpr_4265_test.js +++ b/jscomp/test/gpr_4265_test.js @@ -3,6 +3,7 @@ let Mt = require("./mt.js"); let Belt_MutableMapInt = require("../../lib/js/belt_MutableMapInt.js"); +let Belt_internalMapInt = require("../../lib/js/belt_internalMapInt.js"); let suites = { contents: /* [] */0 @@ -37,7 +38,7 @@ add(486); Belt_MutableMapInt.remove(mockMap, 1726); -let n1 = Belt_MutableMapInt.getExn(mockMap, 6667); +let n1 = Belt_internalMapInt.getExn(mockMap.data, 6667); eq("File \"gpr_4265_test.res\", line 18, characters 3-10", n, n1); @@ -51,4 +52,4 @@ exports.add = add; exports.remove = remove; exports.n = n; exports.n1 = n1; -/* mockMap Not a pure module */ +/* Not a pure module */ diff --git a/jscomp/test/hashtbl_test.js b/jscomp/test/hashtbl_test.js index c64c09f5b9..979cf206eb 100644 --- a/jscomp/test/hashtbl_test.js +++ b/jscomp/test/hashtbl_test.js @@ -39,10 +39,9 @@ function g(count) { Hashtbl.replace(tbl, (i$1 << 1), String(i$1)); } let v = to_list(tbl); - let v$1 = List.sort((function (param, param$1) { + return $$Array.of_list(List.sort((function (param, param$1) { return Caml.int_compare(param[0], param$1[0]); - }), v); - return $$Array.of_list(v$1); + }), v)); } let suites_0 = [ diff --git a/jscomp/test/inline_string_test.js b/jscomp/test/inline_string_test.js index 09713e1294..c81d1e60ac 100644 --- a/jscomp/test/inline_string_test.js +++ b/jscomp/test/inline_string_test.js @@ -22,19 +22,7 @@ console.log([ console.log([ "A", - (function (x) { - switch (x.TAG) { - case "A" : - return "A"; - case "B" : - return "B"; - default: - return "?"; - } - })({ - TAG: "A", - _0: 3 - }) + "A" ]); /* Not a pure module */ diff --git a/jscomp/test/int64_mul_div_test.js b/jscomp/test/int64_mul_div_test.js index 6935d118e7..0b3755be19 100644 --- a/jscomp/test/int64_mul_div_test.js +++ b/jscomp/test/int64_mul_div_test.js @@ -1600,7 +1600,7 @@ function from_to_string(xs) { }), $$Array.to_list(xs)); } -let extra = Pervasives.$at(from_pairs("random", pairs), Pervasives.$at(from_pairs("small", small_pairs), Pervasives.$at(List.mapi((function (i, param) { +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((function (i, param) { let f = param[1]; let i64 = param[0]; return [ @@ -1676,9 +1676,7 @@ let extra = Pervasives.$at(from_pairs("random", pairs), Pervasives.$at(from_pair tl: /* [] */0 } } -}))))))); - -Mt.from_pair_suites("Int64_mul_div_test", extra); +})))))))); exports.commutative_mul = commutative_mul; exports.pairs = pairs; @@ -1693,4 +1691,4 @@ exports.to_string = to_string; exports.int64_compare_tests = int64_compare_tests; exports.from_compare = from_compare; exports.from_to_string = from_to_string; -/* extra Not a pure module */ +/* Not a pure module */ diff --git a/jscomp/test/int_hashtbl_test.js b/jscomp/test/int_hashtbl_test.js index d6c1d924b2..bf32e0b592 100644 --- a/jscomp/test/int_hashtbl_test.js +++ b/jscomp/test/int_hashtbl_test.js @@ -42,15 +42,12 @@ function g(H, count) { tl: acc }; }), tbl, /* [] */0); - let v$1 = List.sort((function (param, param$1) { + return $$Array.of_list(List.sort((function (param, param$1) { return Caml.int_compare(param[0], param$1[0]); - }), v); - return $$Array.of_list(v$1); + }), v)); } -function hash(x) { - return Hashtbl.hash(x); -} +let hash = Hashtbl.hash; function equal(x, y) { return x === y; diff --git a/jscomp/test/js_json_test.js b/jscomp/test/js_json_test.js index e9533d4cbb..92bd902fb2 100644 --- a/jscomp/test/js_json_test.js +++ b/jscomp/test/js_json_test.js @@ -82,34 +82,21 @@ add_test("File \"js_json_test.res\", line 22, characters 11-18", (function () { }; } let ty2 = Js_json.classify(v$1); - if (typeof ty2 !== "object" || ty2.TAG !== "JSONArray") { + if (typeof ty2 !== "object") { return { TAG: "Ok", _0: false }; - } else { - return (function () { - return { - TAG: "Ok", - _0: true - }; - })((ty2._0.forEach(function (x) { - let ty3 = Js_json.classify(x); - if (typeof ty3 !== "object") { - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "js_json_test.res", - 37, - 19 - ] - } - }); - } - if (ty3.TAG === "JSONNumber") { - return; - } + } + if (ty2.TAG !== "JSONArray") { + return { + TAG: "Ok", + _0: false + }; + } + ty2._0.forEach(function (x) { + let ty3 = Js_json.classify(x); + if (typeof ty3 !== "object") { throw new Error("Assert_failure", { cause: { RE_EXN_ID: "Assert_failure", @@ -120,8 +107,25 @@ add_test("File \"js_json_test.res\", line 22, characters 11-18", (function () { ] } }); - }), undefined)); - } + } + if (ty3.TAG === "JSONNumber") { + return; + } + throw new Error("Assert_failure", { + cause: { + RE_EXN_ID: "Assert_failure", + _1: [ + "js_json_test.res", + 37, + 19 + ] + } + }); + }); + return { + TAG: "Ok", + _0: true + }; })); eq("File \"js_json_test.res\", line 48, characters 5-12", Js_json.test(v, "Object"), true); @@ -740,7 +744,7 @@ function id(obj) { } function idtest(obj) { - eq("File \"js_json_test.res\", line 355, characters 23-30", obj, id(obj)); + eq("File \"js_json_test.res\", line 355, characters 23-30", obj, Js_json.deserializeUnsafe(Js_json.serializeExn(obj))); } idtest(undefined); diff --git a/jscomp/test/lazy_demo.js b/jscomp/test/lazy_demo.js index d950f3be7d..1d4fa28466 100644 --- a/jscomp/test/lazy_demo.js +++ b/jscomp/test/lazy_demo.js @@ -1,15 +1,14 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; -let Lazy = require("../../lib/js/lazy.js"); let CamlinternalLazy = require("../../lib/js/camlinternalLazy.js"); -let lazy1 = Lazy.from_fun(function () { +let lazy1 = CamlinternalLazy.from_fun(function () { console.log("Hello, lazy"); return 1; }); -let lazy2 = Lazy.from_fun(function () { +let lazy2 = CamlinternalLazy.from_fun(function () { return 3; }); @@ -25,4 +24,4 @@ exports.lazy1 = lazy1; exports.lazy2 = lazy2; exports.la = la; exports.lb = lb; -/* lazy1 Not a pure module */ +/* Not a pure module */ diff --git a/jscomp/test/lazy_test.js b/jscomp/test/lazy_test.js index b8e3f1dc4e..217632df99 100644 --- a/jscomp/test/lazy_test.js +++ b/jscomp/test/lazy_test.js @@ -9,7 +9,7 @@ let u = { contents: 3 }; -let v = Lazy.from_fun(function () { +let v = CamlinternalLazy.from_fun(function () { u.contents = 32; }); @@ -27,7 +27,7 @@ let u_v = { contents: 0 }; -let u$1 = Lazy.from_fun(function () { +let u$1 = CamlinternalLazy.from_fun(function () { u_v.contents = 2; }); @@ -35,27 +35,31 @@ CamlinternalLazy.force(u$1); let exotic = CamlinternalLazy.force; -let l_from_fun = Lazy.from_fun(function () { +let l_from_fun = CamlinternalLazy.from_fun(function () { return 3; }); -let forward_test = Lazy.from_fun(function () { +function f() { let u = 3; u = u + 1 | 0; return u; +} + +let forward_test = CamlinternalLazy.from_fun(function () { + return f(); }); -let f005 = Lazy.from_fun(function () { +let f005 = CamlinternalLazy.from_fun(function () { return 6; }); -let f006 = Lazy.from_fun(function () { +let f006 = CamlinternalLazy.from_fun(function () { return function () { return 3; }; }); -let f007 = Lazy.from_fun(function () { +let f007 = CamlinternalLazy.from_fun(function () { throw new Error("Not_found", { cause: { RE_EXN_ID: "Not_found" @@ -63,18 +67,20 @@ let f007 = Lazy.from_fun(function () { }); }); -let f008 = Lazy.from_fun(function () { +function f$1() { console.log("hi"); throw new Error("Not_found", { cause: { RE_EXN_ID: "Not_found" } }); +} + +let f008 = CamlinternalLazy.from_fun(function () { + return f$1(); }); -function a2(x) { - return CamlinternalLazy.from_val(x); -} +let a2 = CamlinternalLazy.from_val; let a3 = CamlinternalLazy.from_val(3); @@ -139,12 +145,11 @@ Mt.from_pair_suites("Lazy_test", { hd: [ "lazy_from_val2", (function () { - let v = Lazy.from_fun(function () { - return 3; - }); return { TAG: "Eq", - _0: CamlinternalLazy.force(CamlinternalLazy.force(CamlinternalLazy.from_val(v))), + _0: CamlinternalLazy.force(CamlinternalLazy.force(CamlinternalLazy.from_val(CamlinternalLazy.from_fun(function () { + return 3; + })))), _1: 3 }; }) @@ -210,7 +215,7 @@ Mt.from_pair_suites("Lazy_test", { (function () { return { TAG: "Ok", - _0: !Lazy.is_val(Lazy.from_fun(function () { + _0: !Lazy.is_val(CamlinternalLazy.from_fun(function () { throw new Error("Not_found", { cause: { RE_EXN_ID: "Not_found" @@ -251,4 +256,4 @@ exports.a5 = a5; exports.a6 = a6; exports.a7 = a7; exports.a8 = a8; -/* v Not a pure module */ +/* Not a pure module */ diff --git a/jscomp/test/map_find_test.js b/jscomp/test/map_find_test.js index 10193d80f0..31ef48ae2c 100644 --- a/jscomp/test/map_find_test.js +++ b/jscomp/test/map_find_test.js @@ -367,36 +367,30 @@ let s = List.fold_left((function (acc, param) { } }); -let extra_0 = [ - "int", - (function () { - return { - TAG: "Eq", - _0: find(10, m), - _1: /* 'a' */97 - }; - }) -]; - -let extra_1 = { +Mt.from_pair_suites("Map_find_test", { hd: [ - "string", + "int", (function () { return { TAG: "Eq", - _0: find$1("10", s), + _0: find(10, m), _1: /* 'a' */97 }; }) ], - tl: /* [] */0 -}; - -let extra = { - hd: extra_0, - tl: extra_1 -}; - -Mt.from_pair_suites("Map_find_test", extra); + tl: { + hd: [ + "string", + (function () { + return { + TAG: "Eq", + _0: find$1("10", s), + _1: /* 'a' */97 + }; + }) + ], + tl: /* [] */0 + } +}); /* m Not a pure module */ diff --git a/jscomp/test/mario_game.js b/jscomp/test/mario_game.js index e9159f4930..635e2e3132 100644 --- a/jscomp/test/mario_game.js +++ b/jscomp/test/mario_game.js @@ -702,7 +702,11 @@ function make_type$1(typ, ctx) { switch (typ) { case "BrickChunkL" : case "BrickChunkR" : - break; + return { + sprite: make_particle$1(typ, ctx), + rot: 0, + lifetime: 300 + }; default: return { sprite: make_particle$1(typ, ctx), @@ -710,11 +714,6 @@ function make_type$1(typ, ctx) { lifetime: 30 }; } - return { - sprite: make_particle$1(typ, ctx), - rot: 0, - lifetime: 300 - }; } function make$1(velOpt, accOpt, part_type, pos, ctx) { @@ -1652,10 +1651,9 @@ function process_collision(dir, c1, c2, state) { let o1$2; let t2$1; let o2$2; - let o1$3; switch (c1.TAG) { case "Player" : - let o1$4 = c1._2; + let o1$3 = c1._2; let s1$2 = c1._1; switch (c2.TAG) { case "Player" : @@ -1669,14 +1667,14 @@ function process_collision(dir, c1, c2, state) { let typ$1 = c2._0; if (dir === "South") { s1 = s1$2; - o1 = o1$4; + o1 = o1$3; typ = typ$1; s2 = s2$2; o2 = o2$3; exit = 1; } else { s1$1 = s1$2; - o1$1 = o1$4; + o1$1 = o1$3; t2 = typ$1; s2$1 = s2$2; o2$1 = o2$3; @@ -1684,7 +1682,7 @@ function process_collision(dir, c1, c2, state) { } break; case "Item" : - o1$2 = o1$4; + o1$2 = o1$3; t2$1 = c2._0; o2$2 = c2._2; exit = 3; @@ -1697,14 +1695,14 @@ function process_collision(dir, c1, c2, state) { switch (t) { case "Brick" : if (c1._0 === "BigM") { - collide_block(undefined, dir, o1$4); + collide_block(undefined, dir, o1$3); dec_health(o2$4); return [ undefined, undefined ]; } else { - collide_block(undefined, dir, o1$4); + collide_block(undefined, dir, o1$3); return [ undefined, undefined @@ -1717,7 +1715,7 @@ function process_collision(dir, c1, c2, state) { undefined ]; default: - collide_block(undefined, dir, o1$4); + collide_block(undefined, dir, o1$3); return [ undefined, undefined @@ -1725,8 +1723,8 @@ function process_collision(dir, c1, c2, state) { } } else { let updated_block = evolve_block(o2$4, context); - let spawned_item = spawn_above(o1$4.dir, o2$4, t._0, context); - collide_block(undefined, dir, o1$4); + let spawned_item = spawn_above(o1$3.dir, o2$4, t._0, context); + collide_block(undefined, dir, o1$3); return [ spawned_item, updated_block @@ -1742,20 +1740,20 @@ function process_collision(dir, c1, c2, state) { undefined ]; } - exit$1 = 5; + exit$1 = 4; } else { - exit$1 = 5; + exit$1 = 4; } - if (exit$1 === 5) { + if (exit$1 === 4) { if (dir === "South") { state.multiplier = 1; - collide_block(undefined, dir, o1$4); + collide_block(undefined, dir, o1$3); return [ undefined, undefined ]; } - collide_block(undefined, dir, o1$4); + collide_block(undefined, dir, o1$3); return [ undefined, undefined @@ -1768,26 +1766,26 @@ function process_collision(dir, c1, c2, state) { } break; case "Enemy" : - let o1$5 = c1._2; + let o1$4 = c1._2; let s1$3 = c1._1; let t1 = c1._0; switch (c2.TAG) { case "Player" : - let o1$6 = c2._2; + let o1$5 = c2._2; let s1$4 = c2._1; if (dir === "North") { s1 = s1$4; - o1 = o1$6; + o1 = o1$5; typ = t1; s2 = s1$3; - o2 = o1$5; + o2 = o1$4; exit = 1; } else { s1$1 = s1$4; - o1$1 = o1$6; + o1$1 = o1$5; t2 = t1; s2$1 = s1$3; - o2$1 = o1$5; + o2$1 = o1$4; exit = 2; } break; @@ -1839,7 +1837,7 @@ function process_collision(dir, c1, c2, state) { } if (exit$3 === 4) { - rev_dir(o1$5, t1, s1$3); + rev_dir(o1$4, t1, s1$3); rev_dir(o2$5, t2$2, s2$3); return [ undefined, @@ -1851,14 +1849,14 @@ function process_collision(dir, c1, c2, state) { } switch (exit$2) { case 1 : - dec_health(o1$5); + dec_health(o1$4); dec_health(o2$5); return [ undefined, undefined ]; case 2 : - if (o1$5.vel.x === 0) { + if (o1$4.vel.x === 0) { rev_dir(o2$5, t2$2, s2$3); return [ undefined, @@ -1873,13 +1871,13 @@ function process_collision(dir, c1, c2, state) { } case 3 : if (o2$5.vel.x === 0) { - rev_dir(o1$5, t1, s1$3); + rev_dir(o1$4, t1, s1$3); return [ undefined, undefined ]; } else { - dec_health(o1$5); + dec_health(o1$4); return [ undefined, undefined @@ -1899,56 +1897,67 @@ function process_collision(dir, c1, c2, state) { switch (dir) { case "North" : case "South" : - o1$3 = o1$5; - exit = 4; - break; + collide_block(undefined, dir, o1$4); + return [ + undefined, + undefined + ]; case "East" : case "West" : - exit$4 = 5; + exit$4 = 4; break; } - if (exit$4 === 5) { + if (exit$4 === 4) { let exit$5 = 0; let typ$2; switch (t1) { case "GKoopaShell" : if (typeof t2$3 !== "object") { - exit$5 = t2$3 === "Brick" ? 7 : 6; + if (t2$3 === "Brick") { + dec_health(o2$6); + reverse_left_right(o1$4); + return [ + undefined, + undefined + ]; + } + exit$5 = 5; } else { typ$2 = t2$3._0; - exit$5 = 8; + exit$5 = 6; } break; case "RKoopaShell" : if (typeof t2$3 !== "object") { - exit$5 = t2$3 === "Brick" ? 7 : 6; + if (t2$3 === "Brick") { + dec_health(o2$6); + reverse_left_right(o1$4); + return [ + undefined, + undefined + ]; + } + exit$5 = 5; } else { typ$2 = t2$3._0; - exit$5 = 8; + exit$5 = 6; } break; default: - exit$5 = 6; + exit$5 = 5; } switch (exit$5) { - case 6 : - rev_dir(o1$5, t1, s1$3); - return [ - undefined, - undefined - ]; - case 7 : - dec_health(o2$6); - reverse_left_right(o1$5); + case 5 : + rev_dir(o1$4, t1, s1$3); return [ undefined, undefined ]; - case 8 : + case 6 : let updated_block$1 = evolve_block(o2$6, context); - let spawned_item$1 = spawn_above(o1$5.dir, o2$6, typ$2, context); - rev_dir(o1$5, t1, s1$3); + let spawned_item$1 = spawn_above(o1$4.dir, o2$6, typ$2, context); + rev_dir(o1$4, t1, s1$3); return [ updated_block$1, spawned_item$1 @@ -1979,9 +1988,11 @@ function process_collision(dir, c1, c2, state) { switch (dir) { case "North" : case "South" : - o1$3 = o2$7; - exit = 4; - break; + collide_block(undefined, dir, o2$7); + return [ + undefined, + undefined + ]; case "East" : case "West" : reverse_left_right(o2$7); @@ -1991,7 +2002,6 @@ function process_collision(dir, c1, c2, state) { ]; } - break; } break; @@ -2076,7 +2086,7 @@ function process_collision(dir, c1, c2, state) { ]; case "FireFlower" : case "Star" : - exit$6 = 5; + exit$6 = 4; break; case "Coin" : state.coins = state.coins + 1 | 0; @@ -2088,7 +2098,7 @@ function process_collision(dir, c1, c2, state) { ]; } - if (exit$6 === 5) { + if (exit$6 === 4) { dec_health(o2$2); update_score(state, 1000); return [ @@ -2097,12 +2107,6 @@ function process_collision(dir, c1, c2, state) { ]; } break; - case 4 : - collide_block(undefined, dir, o1$3); - return [ - undefined, - undefined - ]; } } diff --git a/jscomp/test/marshal.js b/jscomp/test/marshal.js index dc884923cd..5a1dcc9aff 100644 --- a/jscomp/test/marshal.js +++ b/jscomp/test/marshal.js @@ -5,27 +5,27 @@ let Bytes = require("../../lib/js/bytes.js"); let Caml_external_polyfill = require("../../lib/js/caml_external_polyfill.js"); function to_buffer(buff, ofs, len, v, flags) { - if (!(ofs < 0 || len < 0 || ofs > (buff.length - len | 0))) { - return Caml_external_polyfill.resolve("output_value_to_buffer")(buff, ofs, len, v, flags); + if (ofs < 0 || len < 0 || ofs > (buff.length - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Marshal.to_buffer: substring out of bounds" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Marshal.to_buffer: substring out of bounds" - } - }); + return Caml_external_polyfill.resolve("output_value_to_buffer")(buff, ofs, len, v, flags); } function data_size(buff, ofs) { - if (!(ofs < 0 || ofs > (buff.length - 20 | 0))) { - return Caml_external_polyfill.resolve("marshal_data_size")(buff, ofs); + if (ofs < 0 || ofs > (buff.length - 20 | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Marshal.data_size" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Marshal.data_size" - } - }); + return Caml_external_polyfill.resolve("marshal_data_size")(buff, ofs); } function total_size(buff, ofs) { @@ -42,15 +42,15 @@ function from_bytes(buff, ofs) { }); } let len = Caml_external_polyfill.resolve("marshal_data_size")(buff, ofs); - if (ofs <= (buff.length - (20 + len | 0) | 0)) { - return Caml_external_polyfill.resolve("input_value_from_string")(buff, ofs); + if (ofs > (buff.length - (20 + len | 0) | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Marshal.from_bytes" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Marshal.from_bytes" - } - }); + return Caml_external_polyfill.resolve("input_value_from_string")(buff, ofs); } function from_string(buff, ofs) { diff --git a/jscomp/test/mpr_6033_test.js b/jscomp/test/mpr_6033_test.js index a0b19a29a0..9c1d14ef49 100644 --- a/jscomp/test/mpr_6033_test.js +++ b/jscomp/test/mpr_6033_test.js @@ -2,7 +2,6 @@ 'use strict'; let Mt = require("./mt.js"); -let Lazy = require("../../lib/js/lazy.js"); let CamlinternalLazy = require("../../lib/js/camlinternalLazy.js"); let suites = { @@ -34,7 +33,7 @@ function f(x) { return CamlinternalLazy.force(x) + "abc"; } -let x = Lazy.from_fun(function () { +let x = CamlinternalLazy.from_fun(function () { return "def"; }); @@ -51,4 +50,4 @@ exports.test_id = test_id; exports.eq = eq; exports.f = f; exports.u = u; -/* x Not a pure module */ +/* Not a pure module */ diff --git a/jscomp/test/number_lexer.js b/jscomp/test/number_lexer.js index 74309374ea..abd9c0a68c 100644 --- a/jscomp/test/number_lexer.js +++ b/jscomp/test/number_lexer.js @@ -120,10 +120,6 @@ let __ocaml_lex_tables = { lex_code: "" }; -function token(l, lexbuf) { - __ocaml_lex_token_rec(l, lexbuf, 0); -} - function __ocaml_lex_token_rec(l, lexbuf, ___ocaml_lex_state) { while(true) { let __ocaml_lex_state = ___ocaml_lex_state; @@ -131,33 +127,42 @@ function __ocaml_lex_token_rec(l, lexbuf, ___ocaml_lex_state) { switch (__ocaml_lex_state$1) { case 0 : l("new line"); - return token(l, lexbuf); + ___ocaml_lex_state = 0; + continue; case 1 : l("number"); l(Lexing.lexeme(lexbuf)); - return token(l, lexbuf); + ___ocaml_lex_state = 0; + continue; case 2 : l("ident"); l(Lexing.lexeme(lexbuf)); - return token(l, lexbuf); + ___ocaml_lex_state = 0; + continue; case 3 : l("+"); - return token(l, lexbuf); + ___ocaml_lex_state = 0; + continue; case 4 : l("-"); - return token(l, lexbuf); + ___ocaml_lex_state = 0; + continue; case 5 : l("*"); - return token(l, lexbuf); + ___ocaml_lex_state = 0; + continue; case 6 : l("/"); - return token(l, lexbuf); + ___ocaml_lex_state = 0; + continue; case 7 : l("("); - return token(l, lexbuf); + ___ocaml_lex_state = 0; + continue; case 8 : l(")"); - return token(l, lexbuf); + ___ocaml_lex_state = 0; + continue; case 9 : return l("eof"); default: @@ -168,6 +173,10 @@ function __ocaml_lex_token_rec(l, lexbuf, ___ocaml_lex_state) { }; } +function token(l, lexbuf) { + __ocaml_lex_token_rec(l, lexbuf, 0); +} + exports.l = l; exports.__ocaml_lex_tables = __ocaml_lex_tables; exports.token = token; diff --git a/jscomp/test/ocaml_re_test.js b/jscomp/test/ocaml_re_test.js index 4db87f87cc..dfcd0828f2 100644 --- a/jscomp/test/ocaml_re_test.js +++ b/jscomp/test/ocaml_re_test.js @@ -211,10 +211,6 @@ function single(c) { }; } -function add(c, l) { - return union(single(c), l); -} - function seq(c, c$p) { if (Caml_obj.lessequal(c, c$p)) { return { @@ -384,7 +380,7 @@ function bal(l, x, d, r) { }); } -function add$1(x, data, param) { +function add(x, data, param) { if (typeof param !== "object") { return { TAG: "Node", @@ -415,14 +411,14 @@ function add$1(x, data, param) { } } if (c < 0) { - let ll = add$1(x, data, l); + let ll = add(x, data, l); if (l === ll) { return param; } else { return bal(ll, v, d, r); } } - let rr = add$1(x, data, r); + let rr = add(x, data, r); if (r === rr) { return param; } else { @@ -430,10 +426,6 @@ function add$1(x, data, param) { } } -function fold_right(t, init, f) { - return List.fold_right(f, t, init); -} - let cany = { hd: [ 0, @@ -586,7 +578,7 @@ function bal$1(l, v, r) { }); } -function add$2(x, param) { +function add$1(x, param) { if (typeof param !== "object") { return { TAG: "Node", @@ -604,14 +596,14 @@ function add$2(x, param) { return param; } if (c < 0) { - let ll = add$2(x, l); + let ll = add$1(x, l); if (l === ll) { return param; } else { return bal$1(ll, v, r); } } - let rr = add$2(x, r); + let rr = add$1(x, r); if (r === rr) { return param; } else { @@ -781,20 +773,6 @@ function rep(ids, kind, sem, x) { }); } -function mark(ids, m) { - return mk_expr(ids, { - TAG: "Mark", - _0: m - }); -} - -function pmark(ids, i) { - return mk_expr(ids, { - TAG: "Pmark", - _0: i - }); -} - function erase(ids, m, m$p) { return mk_expr(ids, { TAG: "Erase", @@ -803,20 +781,6 @@ function erase(ids, m, m$p) { }); } -function before(ids, c) { - return mk_expr(ids, { - TAG: "Before", - _0: c - }); -} - -function after(ids, c) { - return mk_expr(ids, { - TAG: "After", - _0: c - }); -} - function rename(ids, x) { let l = x.def; if (typeof l !== "object") { @@ -1109,7 +1073,12 @@ function split_at_match_rec(_l$p, _x) { switch (x$1.TAG) { case "TSeq" : case "TExp" : - break; + _x = x.tl; + _l$p = { + hd: x$1, + tl: l$p + }; + continue; case "TMatch" : return [ List.rev(l$p), @@ -1117,23 +1086,18 @@ function split_at_match_rec(_l$p, _x) { ]; } - _x = x.tl; - _l$p = { - hd: x$1, - tl: l$p - }; - continue; + } else { + throw new Error("Assert_failure", { + cause: { + RE_EXN_ID: "Assert_failure", + _1: [ + "ocaml_re_test.res", + 816, + 16 + ] + } + }); } - throw new Error("Assert_failure", { - cause: { - RE_EXN_ID: "Assert_failure", - _1: [ - "ocaml_re_test.res", - 816, - 16 - ] - } - }); }; } @@ -1380,7 +1344,7 @@ function delta_1(marks, c, next_cat, prev_cat, x, rem) { } case "Pmark" : let marks_marks$1 = marks.marks; - let marks_pmarks$1 = add$2(s._0, marks.pmarks); + let marks_pmarks$1 = add$1(s._0, marks.pmarks); let marks$2 = { marks: marks_marks$1, pmarks: marks_pmarks$1 @@ -1768,7 +1732,7 @@ function scan_str(info, s, initial_state, groups) { } function cadd(c, s) { - return add(c, s); + return union(single(c), s); } function trans_set(cache, cm, s) { @@ -1803,10 +1767,10 @@ function trans_set(cache, cm, s) { catch (raw_exn){ let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); if (exn.RE_EXN_ID === "Not_found") { - let l = fold_right(s, /* [] */0, (function (param, l) { + let l = List.fold_right((function (param, l) { return union(seq(Caml_bytes.get(cm, param[0]), Caml_bytes.get(cm, param[1])), l); - })); - cache.contents = add$1(v, l, cache.contents); + }), s, /* [] */0); + cache.contents = add(v, l, cache.contents); return l; } throw new Error(exn.RE_EXN_ID, { @@ -1836,7 +1800,7 @@ function is_charset(_x) { case "Alternative" : case "Intersection" : case "Complement" : - break; + return List.for_all(is_charset, x._0); case "Difference" : if (!is_charset(x._0)) { return false; @@ -1846,7 +1810,6 @@ function is_charset(_x) { default: return false; } - return List.for_all(is_charset, x._0); }; } @@ -1893,7 +1856,13 @@ let cdigit = seq(/* '0' */48, /* '9' */57); let calnum = union(calpha, cdigit); -let cword = add(/* '_' */95, calnum); +let cword = union({ + hd: [ + /* '_' */95, + /* '_' */95 + ], + tl: /* [] */0 +}, calnum); function colorize(c, regexp) { let lnl = { @@ -2334,31 +2303,67 @@ function translate(ids, kind, _ign_group, ign_case, _greedy, pos, cache, c, _x) 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 [ - after(ids, Re_automata_Category.$plus$plus(Re_automata_Category.inexistant, Re_automata_Category.newline)), + 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 [ - before(ids, Re_automata_Category.$plus$plus(Re_automata_Category.inexistant, Re_automata_Category.newline)), + 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", after(ids, Re_automata_Category.$plus$plus(Re_automata_Category.inexistant, Re_automata_Category.not_letter)), before(ids, Re_automata_Category.$plus$plus(Re_automata_Category.inexistant, Re_automata_Category.letter))), + 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", after(ids, Re_automata_Category.$plus$plus(Re_automata_Category.inexistant, Re_automata_Category.letter)), before(ids, Re_automata_Category.$plus$plus(Re_automata_Category.inexistant, Re_automata_Category.not_letter))), + 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", after(ids, Re_automata_Category.letter), before(ids, Re_automata_Category.letter)), + 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", after(ids, Re_automata_Category.letter), before(ids, Re_automata_Category.letter)), + 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 } }), @@ -2366,27 +2371,43 @@ function translate(ids, kind, _ign_group, ign_case, _greedy, pos, cache, c, _x) ]; case "Beg_of_str" : return [ - after(ids, Re_automata_Category.inexistant), + mk_expr(ids, { + TAG: "After", + _0: Re_automata_Category.inexistant + }), kind ]; case "End_of_str" : return [ - before(ids, Re_automata_Category.inexistant), + 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 [ - before(ids, Re_automata_Category.$plus$plus(Re_automata_Category.inexistant, Re_automata_Category.lastnewline)), + mk_expr(ids, { + TAG: "Before", + _0: c$7 + }), kind ]; case "Start" : return [ - after(ids, Re_automata_Category.search_boundary), + mk_expr(ids, { + TAG: "After", + _0: Re_automata_Category.search_boundary + }), kind ]; case "Stop" : return [ - before(ids, Re_automata_Category.search_boundary), + mk_expr(ids, { + TAG: "Before", + _0: Re_automata_Category.search_boundary + }), kind ]; @@ -2475,7 +2496,13 @@ function translate(ids, kind, _ign_group, ign_case, _greedy, pos, cache, c, _x) 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", mark(ids, p), seq$1(ids, "First", match$3[0], mark(ids, p + 1 | 0))), + 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" : @@ -2502,7 +2529,10 @@ function translate(ids, kind, _ign_group, ign_case, _greedy, pos, cache, c, _x) case "Pmark" : let match$5 = translate(ids, kind, ign_group, ign_case, greedy, pos, cache, c, x._1); return [ - seq$1(ids, "First", pmark(ids, x._0), match$5[0]), + seq$1(ids, "First", mk_expr(ids, { + TAG: "Pmark", + _0: x._0 + }), match$5[0]), match$5[1] ]; default: @@ -2808,18 +2838,6 @@ function repn(r, i, j) { }; } -function rep$1(r) { - return repn(r, 0, undefined); -} - -function rep1(r) { - return repn(r, 1, undefined); -} - -function opt(r) { - return repn(r, 0, 1); -} - function set(str) { let s = /* [] */0; for(let i = 0 ,i_finish = str.length; i < i_finish; ++i){ @@ -2831,13 +2849,6 @@ function set(str) { }; } -function rg(c, c$p) { - return { - TAG: "Set", - _0: seq(c, c$p) - }; -} - function compl(l) { let r = { TAG: "Complement", @@ -2871,7 +2882,10 @@ let notnl = { }; let lower = alt$1({ - hd: rg(/* 'a' */97, /* 'z' */122), + hd: { + TAG: "Set", + _0: seq(/* 'a' */97, /* 'z' */122) + }, tl: { hd: { TAG: "Set", @@ -2884,9 +2898,15 @@ let lower = alt$1({ } }, tl: { - hd: rg(/* '\223' */223, /* '\246' */246), + hd: { + TAG: "Set", + _0: seq(/* '\223' */223, /* '\246' */246) + }, tl: { - hd: rg(/* '\248' */248, /* '\255' */255), + hd: { + TAG: "Set", + _0: seq(/* '\248' */248, /* '\255' */255) + }, tl: /* [] */0 } } @@ -2894,11 +2914,20 @@ let lower = alt$1({ }); let upper = alt$1({ - hd: rg(/* 'A' */65, /* 'Z' */90), + hd: { + TAG: "Set", + _0: seq(/* 'A' */65, /* 'Z' */90) + }, tl: { - hd: rg(/* '\192' */192, /* '\214' */214), + hd: { + TAG: "Set", + _0: seq(/* '\192' */192, /* '\214' */214) + }, tl: { - hd: rg(/* '\216' */216, /* '\222' */222), + hd: { + TAG: "Set", + _0: seq(/* '\216' */216, /* '\222' */222) + }, tl: /* [] */0 } } @@ -2936,7 +2965,10 @@ let alpha = alt$1({ } }); -let digit = rg(/* '0' */48, /* '9' */57); +let digit = { + TAG: "Set", + _0: seq(/* '0' */48, /* '9' */57) +}; let alnum = alt$1({ hd: alpha, @@ -2963,50 +2995,95 @@ let wordc = alt$1({ } }); -let ascii = rg(/* '\000' */0, /* '\127' */127); +let ascii = { + TAG: "Set", + _0: seq(/* '\000' */0, /* '\127' */127) +}; let blank = set("\t "); let cntrl = alt$1({ - hd: rg(/* '\000' */0, /* '\031' */31), + hd: { + TAG: "Set", + _0: seq(/* '\000' */0, /* '\031' */31) + }, tl: { - hd: rg(/* '\127' */127, /* '\159' */159), + hd: { + TAG: "Set", + _0: seq(/* '\127' */127, /* '\159' */159) + }, tl: /* [] */0 } }); let graph = alt$1({ - hd: rg(/* '!' */33, /* '~' */126), + hd: { + TAG: "Set", + _0: seq(/* '!' */33, /* '~' */126) + }, tl: { - hd: rg(/* '\160' */160, /* '\255' */255), + hd: { + TAG: "Set", + _0: seq(/* '\160' */160, /* '\255' */255) + }, tl: /* [] */0 } }); let print = alt$1({ - hd: rg(/* ' ' */32, /* '~' */126), + hd: { + TAG: "Set", + _0: seq(/* ' ' */32, /* '~' */126) + }, tl: { - hd: rg(/* '\160' */160, /* '\255' */255), + hd: { + TAG: "Set", + _0: seq(/* '\160' */160, /* '\255' */255) + }, tl: /* [] */0 } }); let punct = alt$1({ - hd: rg(/* '!' */33, /* '/' */47), + hd: { + TAG: "Set", + _0: seq(/* '!' */33, /* '/' */47) + }, tl: { - hd: rg(/* ':' */58, /* '@' */64), + hd: { + TAG: "Set", + _0: seq(/* ':' */58, /* '@' */64) + }, tl: { - hd: rg(/* '[' */91, /* '`' */96), + hd: { + TAG: "Set", + _0: seq(/* '[' */91, /* '`' */96) + }, tl: { - hd: rg(/* '{' */123, /* '~' */126), + hd: { + TAG: "Set", + _0: seq(/* '{' */123, /* '~' */126) + }, tl: { - hd: rg(/* '\160' */160, /* '\169' */169), + hd: { + TAG: "Set", + _0: seq(/* '\160' */160, /* '\169' */169) + }, tl: { - hd: rg(/* '\171' */171, /* '\180' */180), + hd: { + TAG: "Set", + _0: seq(/* '\171' */171, /* '\180' */180) + }, tl: { - hd: rg(/* '\182' */182, /* '\185' */185), + hd: { + TAG: "Set", + _0: seq(/* '\182' */182, /* '\185' */185) + }, tl: { - hd: rg(/* '\187' */187, /* '\191' */191), + hd: { + TAG: "Set", + _0: seq(/* '\187' */187, /* '\191' */191) + }, tl: { hd: { TAG: "Set", @@ -3053,7 +3130,10 @@ let space = alt$1({ } }, tl: { - hd: rg(/* '\t' */9, /* '\r' */13), + hd: { + TAG: "Set", + _0: seq(/* '\t' */9, /* '\r' */13) + }, tl: /* [] */0 } }); @@ -3061,14 +3141,73 @@ let space = alt$1({ let xdigit = alt$1({ hd: digit, tl: { - hd: rg(/* 'a' */97, /* 'f' */102), + hd: { + TAG: "Set", + _0: seq(/* 'a' */97, /* 'f' */102) + }, tl: { - hd: rg(/* 'A' */65, /* 'F' */70), + 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; @@ -3205,10 +3344,11 @@ function posix_class_of_string(x) { case "xdigit" : return xdigit; default: + let s = "Invalid pcre class: " + x; throw new Error("Invalid_argument", { cause: { RE_EXN_ID: "Invalid_argument", - _1: "Invalid pcre class: " + x + _1: s } }); } @@ -3290,8 +3430,7 @@ function parse(multiline, dollar_endonly, dotall, ungreedy, s) { }; } }; - let regexp = function () { - let _left = branch$p(/* [] */0); + let regexp$p = function (_left) { while(true) { let left = _left; if (!accept(/* '|' */124)) { @@ -3331,7 +3470,7 @@ function parse(multiline, dollar_endonly, dotall, ungreedy, s) { if (accept(/* '(' */40)) { if (accept(/* '?' */63)) { if (accept(/* ':' */58)) { - let r = regexp(); + let r = regexp$p(branch()); if (!accept(/* ')' */41)) { throw new Error(Parse_error, { cause: { @@ -3350,7 +3489,7 @@ function parse(multiline, dollar_endonly, dotall, ungreedy, s) { } }); } - let r$1 = regexp(); + let r$1 = regexp$p(branch()); if (!accept(/* ')' */41)) { throw new Error(Parse_error, { cause: { @@ -3619,13 +3758,13 @@ function parse(multiline, dollar_endonly, dotall, ungreedy, s) { let piece = function () { let r = atom(); if (accept(/* '*' */42)) { - return greedy_mod(rep$1(r)); + return greedy_mod(repn(r, 0, undefined)); } if (accept(/* '+' */43)) { - return greedy_mod(rep1(r)); + return greedy_mod(repn(r, 1, undefined)); } if (accept(/* '?' */63)) { - return greedy_mod(opt(r)); + return greedy_mod(repn(r, 0, 1)); } if (!accept(/* '{' */123)) { return r; @@ -4015,7 +4154,10 @@ function parse(multiline, dollar_endonly, dotall, ungreedy, s) { }; } _s = { - hd: rg(c, match$1.VAL), + hd: { + TAG: "Set", + _0: seq(c, match$1.VAL) + }, tl: s }; continue; @@ -4036,6 +4178,9 @@ function parse(multiline, dollar_endonly, dotall, ungreedy, s) { continue; }; }; + let branch = function () { + return branch$p(/* [] */0); + }; let comment = function () { while(true) { if (accept(/* ')' */41)) { @@ -4046,7 +4191,7 @@ function parse(multiline, dollar_endonly, dotall, ungreedy, s) { continue; }; }; - let res = regexp(); + let res = regexp$p(branch()); if (i.contents !== l) { throw new Error(Parse_error, { cause: { @@ -4088,60 +4233,6 @@ function re(flagsOpt, pat) { } } -function regexp(flags, pat) { - let r = re(flags, pat); - let regexp$1 = anchored(r) ? ({ - TAG: "Group", - _0: r - }) : seq$2({ - hd: { - TAG: "Sem", - _0: "Shortest", - _1: rep$1(any) - }, - tl: { - hd: { - TAG: "Group", - _0: r - }, - tl: /* [] */0 - } - }); - let regexp$2 = handle_case(false, regexp$1); - let c = Bytes.make(257, /* '\000' */0); - let need_lnl = colorize(c, regexp$2); - 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$2); - 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(rex, pos, s) { let len; let substr = exec_internal("Re.exec", pos, len, true, rex, s); @@ -4164,7 +4255,7 @@ function exec(rex, pos, s) { let s = "a".repeat(1048575) + "b"; -eq("File \"ocaml_re_test.res\", line 3843, characters 7-14", get(exec(regexp(undefined, "aa?b"), undefined, s), 0), "aab"); +eq("File \"ocaml_re_test.res\", line 3843, characters 7-14", get(exec(compile(re(undefined, "aa?b")), undefined, s), 0), "aab"); Mt.from_pair_suites("Ocaml_re_test", suites.contents); diff --git a/jscomp/test/pipe_syntax.js b/jscomp/test/pipe_syntax.js index 868d41895b..79f97aeb38 100644 --- a/jscomp/test/pipe_syntax.js +++ b/jscomp/test/pipe_syntax.js @@ -43,12 +43,10 @@ function f2(a, b, c, d) { function f3(a, b, c, d, e) { let __tuple_internal_obj = a(b); - let param = [ - c(__tuple_internal_obj, d), - d(__tuple_internal_obj, 1, 2), - e(__tuple_internal_obj) - ]; - return (param[0] + param[1] | 0) + param[2] | 0; + let param_0 = c(__tuple_internal_obj, d); + let param_1 = d(__tuple_internal_obj, 1, 2); + let param_2 = e(__tuple_internal_obj); + return (param_0 + param_1 | 0) + param_2 | 0; } function f4(a, b, c) { diff --git a/jscomp/test/ppx_apply_test.js b/jscomp/test/ppx_apply_test.js index e3c501ddfe..c8d27383ce 100644 --- a/jscomp/test/ppx_apply_test.js +++ b/jscomp/test/ppx_apply_test.js @@ -56,4 +56,4 @@ exports.nullary = nullary; exports.unary = unary; exports.xx = xx; exports.h = h; -/* u Not a pure module */ +/* Not a pure module */ diff --git a/jscomp/test/random_test.js b/jscomp/test/random_test.js index 2aa27ff159..c17e6947e0 100644 --- a/jscomp/test/random_test.js +++ b/jscomp/test/random_test.js @@ -33,9 +33,7 @@ function approx(f) { }; } -((function (extra, extra$1) { - return Mt_global.collect_neq(id, suites, "File \"random_test.res\", line 9, characters 2-9", extra, extra$1); - })((Random.self_init(), Random.int(10000)), (Random.self_init(), Random.int(1000)))); +Mt_global.collect_neq(id, suites, "File \"random_test.res\", line 9, characters 2-9", (Random.self_init(), Random.int(10000)), (Random.self_init(), Random.int(1000))); Random.init(0); @@ -45,20 +43,18 @@ for(let i = 0; i <= 9; ++i){ Caml_array.set(v, i, Random.bool()); } -((function (extra, extra$1) { - return Mt_global.collect_eq(id, suites, "File \"random_test.res\", line 28, characters 12-19", extra, extra$1); - })(v, [ - true, - true, - true, - true, - true, - false, - true, - true, - true, - false - ])); +Mt_global.collect_eq(id, suites, "File \"random_test.res\", line 28, characters 12-19", v, [ + true, + true, + true, + true, + true, + false, + true, + true, + true, + false +]); let f = Random.int64(Int64.max_int); diff --git a/jscomp/test/raw_output_test.js b/jscomp/test/raw_output_test.js index 9322ea7fd8..156dcbbf3f 100644 --- a/jscomp/test/raw_output_test.js +++ b/jscomp/test/raw_output_test.js @@ -8,9 +8,7 @@ function mk(fn) { (((_)=> console.log('should works'))()); -console.log((function () { - return 1; -})()); +console.log(1); exports.mk = mk; /* Not a pure module */ diff --git a/jscomp/test/reasonReact.js b/jscomp/test/reasonReact.js index fcd2352d0f..49bd1161a1 100644 --- a/jscomp/test/reasonReact.js +++ b/jscomp/test/reasonReact.js @@ -56,21 +56,13 @@ function basicComponent(debugName) { }; } -function statelessComponent(debugName) { - return basicComponent(debugName); -} +let statelessComponent = basicComponent; -function statelessComponentWithRetainedProps(debugName) { - return basicComponent(debugName); -} +let statelessComponentWithRetainedProps = basicComponent; -function reducerComponent(debugName) { - return basicComponent(debugName); -} +let reducerComponent = basicComponent; -function reducerComponentWithRetainedProps(debugName) { - return basicComponent(debugName); -} +let reducerComponentWithRetainedProps = basicComponent; function element(keyOpt, refOpt, component) { let key = keyOpt !== undefined ? keyOpt : undefined; diff --git a/jscomp/test/reasonReactCompat.js b/jscomp/test/reasonReactCompat.js index cde9d8b3ad..43f178a76d 100644 --- a/jscomp/test/reasonReactCompat.js +++ b/jscomp/test/reasonReactCompat.js @@ -3,13 +3,9 @@ let ReasonReact = require("./reasonReact.js"); -function wrapReactForReasonReact(component, props, children) { - return ReasonReact.wrapJsForReason(component, props, children); -} +let wrapReactForReasonReact = ReasonReact.wrapJsForReason; -function wrapReasonReactForReact(component, propsConverter) { - return ReasonReact.wrapReasonForJs(component, propsConverter); -} +let wrapReasonReactForReact = ReasonReact.wrapReasonForJs; exports.wrapReactForReasonReact = wrapReactForReasonReact; exports.wrapReasonReactForReact = wrapReasonReactForReact; diff --git a/jscomp/test/recursive_module.js b/jscomp/test/recursive_module.js index c28f063fcd..4efd37878f 100644 --- a/jscomp/test/recursive_module.js +++ b/jscomp/test/recursive_module.js @@ -70,7 +70,7 @@ let Intb = Caml_module.init_mod([ ]] }); -let a = Lazy.from_fun(function () { +let a = CamlinternalLazy.from_fun(function () { return CamlinternalLazy.force(Intb.a); }); @@ -84,7 +84,7 @@ Caml_module.update_mod({ a: a }); -let a$1 = Lazy.from_fun(function () { +let a$1 = CamlinternalLazy.from_fun(function () { return CamlinternalLazy.force(Inta.a) + 1 | 0; }); @@ -140,7 +140,7 @@ let Intb$1 = Caml_module.init_mod([ ]] }); -let a$2 = Lazy.from_fun(function () { +let a$2 = CamlinternalLazy.from_fun(function () { return CamlinternalLazy.force(Intb$1.a) + 1 | 0; }); @@ -154,7 +154,7 @@ Caml_module.update_mod({ a: a$2 }); -let a$3 = Lazy.from_fun(function () { +let a$3 = CamlinternalLazy.from_fun(function () { return 2; }); diff --git a/jscomp/test/sexp.js b/jscomp/test/sexp.js index cc631d3a3a..ec021c83c3 100644 --- a/jscomp/test/sexp.js +++ b/jscomp/test/sexp.js @@ -12,9 +12,7 @@ let equal = Caml_obj.equal; let compare = Caml_obj.compare; -function hash(a) { - return Hashtbl.hash(a); -} +let hash = Hashtbl.hash; function of_int(x) { return { @@ -370,20 +368,39 @@ function get_field(name) { return; } let match = l.hd; - if (typeof match === "object" && match.NAME === "List") { - let match$1 = match.VAL; - if (match$1) { - let match$2 = match$1.hd; - if (typeof match$2 === "object" && match$2.NAME === "Atom") { - let match$3 = match$1.tl; - if (match$3 && !match$3.tl && Caml_obj.equal(name, match$2.VAL)) { - return match$3.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; @@ -406,16 +423,30 @@ function _get_field_list(name, _l) { return; } let match = l.hd; - if (typeof match === "object" && match.NAME === "List") { - let match$1 = match.VAL; - if (match$1) { - let match$2 = match$1.hd; - if (typeof match$2 === "object" && match$2.NAME === "Atom" && Caml_obj.equal(name, match$2.VAL)) { - return match$1.tl; + 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; @@ -521,4 +552,4 @@ exports.of_variant = of_variant; exports.of_field = of_field; exports.of_record = of_record; exports.Traverse = Traverse; -/* Hashtbl Not a pure module */ +/* No side effect */ diff --git a/jscomp/test/sexpm.js b/jscomp/test/sexpm.js index 44de13f8fd..9ac601aa21 100644 --- a/jscomp/test/sexpm.js +++ b/jscomp/test/sexpm.js @@ -302,7 +302,22 @@ function expr_list(acc, k, t) { } return expr_starting_with(c, (function (last, e) { if (last !== undefined) { - if (last === 40) { + 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, (function (param, l) { return expr_list({ hd: l, @@ -310,21 +325,12 @@ function expr_list(acc, k, t) { }, k, t); }), t); } - if (last === 41) { - return k(undefined, { - NAME: "List", - VAL: List.rev({ - hd: e, - tl: acc - }) - }); - } - + } else { + return expr_list({ + hd: e, + tl: acc + }, k, t); } - return expr_list({ - hd: e, - tl: acc - }, k, t); }), t); }; } diff --git a/jscomp/test/stack_comp_test.js b/jscomp/test/stack_comp_test.js index 5f384a3582..dabb3ee849 100644 --- a/jscomp/test/stack_comp_test.js +++ b/jscomp/test/stack_comp_test.js @@ -2,6 +2,7 @@ '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"); @@ -30,12 +31,12 @@ function to_list(s) { let l = { contents: /* [] */0 }; - Stack.iter((function (x) { + List.iter((function (x) { l.contents = { hd: x, tl: l.contents }; - }), s); + }), s.c); return l.contents; } @@ -358,10 +359,10 @@ let i$7 = { contents: 1 }; -Stack.iter((function (j) { +List.iter((function (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); +}), s$5.c); let s1$1 = { c: /* [] */0, diff --git a/jscomp/test/stream_parser_test.js b/jscomp/test/stream_parser_test.js index 63128f88f2..d8c949d0ee 100644 --- a/jscomp/test/stream_parser_test.js +++ b/jscomp/test/stream_parser_test.js @@ -35,7 +35,7 @@ function parse(token) { switch (n.TAG) { case "Kwd" : if (n._0 === "(") { - let v = parse_expr(); + let v = parse_expr_aux(parse_term()); let match = token$1(); if (match.TAG === "Kwd") { if (match._0 === ")") { @@ -75,14 +75,16 @@ function parse(token) { } }; let parse_term = function () { - let e1 = parse_atom(); + return parse_term_aux(parse_atom()); + }; + let parse_expr_aux = function (e1) { let e = token$1(); if (e.TAG === "Kwd") { switch (e._0) { - case "*" : - return Math.imul(e1, parse_term()); - case "/" : - return Caml_int32.div(e1, parse_term()); + 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; @@ -92,15 +94,14 @@ function parse(token) { return e1; } }; - let parse_expr = function () { - let e1 = parse_term(); + let parse_term_aux = function (e1) { let e = token$1(); if (e.TAG === "Kwd") { switch (e._0) { - case "+" : - return e1 + parse_expr() | 0; - case "-" : - return e1 - parse_expr() | 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; @@ -110,7 +111,7 @@ function parse(token) { return e1; } }; - let r = parse_expr(); + let r = parse_expr_aux(parse_term()); return [ r, Queue.fold((function (acc, x) { @@ -169,58 +170,12 @@ function l_parse(token) { }; } }; - let parse_e = function () { - let _a = parse_t(); - while(true) { - let a = _a; - let t = token$1(); - if (t.TAG === "Kwd") { - switch (t._0) { - case "+" : - _a = a + parse_t() | 0; - continue; - case "-" : - _a = a - parse_t() | 0; - continue; - default: - Queue.push(t, look_ahead); - return a; - } - } else { - Queue.push(t, look_ahead); - return a; - } - }; - }; - let parse_t = function () { - let _a = parse_f(); - 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_f = function () { let i = token$1(); switch (i.TAG) { case "Kwd" : if (i._0 === "(") { - let v = parse_e(); + let v = parse_t_aux(parse_t()); let t = token$1(); if (t.TAG === "Kwd") { if (t._0 === ")") { @@ -257,7 +212,54 @@ function l_parse(token) { }); } }; - let r = parse_e(); + let parse_f_aux = function (_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 = function (_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 = function () { + return parse_f_aux(parse_f()); + }; + let r = parse_t_aux(parse_t()); return [ r, Queue.fold((function (acc, x) { diff --git a/jscomp/test/string_runtime_test.js b/jscomp/test/string_runtime_test.js index e875088074..f63935b895 100644 --- a/jscomp/test/string_runtime_test.js +++ b/jscomp/test/string_runtime_test.js @@ -4,7 +4,6 @@ let Mt = require("./mt.js"); let List = require("../../lib/js/list.js"); let Bytes = require("../../lib/js/bytes.js"); -let $$String = require("../../lib/js/string.js"); let Test_char = require("./test_char.js"); let Caml_bytes = require("../../lib/js/caml_bytes.js"); @@ -28,9 +27,9 @@ let suites_1 = { Bytes.fill(b, 0, x, /* 'c' */99); return [ Bytes.to_string(b), - $$String.init(x, (function (param) { + Bytes.unsafe_to_string(Bytes.init(x, (function (param) { return /* 'c' */99; - })) + }))) ]; }), { hd: 1000, diff --git a/jscomp/test/string_set.js b/jscomp/test/string_set.js index 985bc64571..7103bdbfba 100644 --- a/jscomp/test/string_set.js +++ b/jscomp/test/string_set.js @@ -165,7 +165,7 @@ function compare(s1, s2) { } function equal(s1, s2) { - return compare(s1, s2) === 0; + return Set_gen.compare($$String.compare, s1, s2) === 0; } function subset(_s1, _s2) { diff --git a/jscomp/test/string_test.js b/jscomp/test/string_test.js index b26b614d53..23f7e57812 100644 --- a/jscomp/test/string_test.js +++ b/jscomp/test/string_test.js @@ -3,6 +3,7 @@ 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"); @@ -126,10 +127,10 @@ function xsplit(delim, s) { } function string_of_chars(x) { - let extra = List.map((function (prim) { + let xs = List.map((function (prim) { return String.fromCharCode(prim); }), x); - return $$String.concat("", extra); + return $$Array.of_list(xs).join(""); } Mt.from_pair_suites("String_test", { diff --git a/jscomp/test/test_array_primitive.js b/jscomp/test/test_array_primitive.js index 69819d9239..d1dc53858d 100644 --- a/jscomp/test/test_array_primitive.js +++ b/jscomp/test/test_array_primitive.js @@ -12,27 +12,27 @@ function caml_array_sub(x, offset, len) { } function caml_array_set(xs, index, newval) { - if (!(index < 0 || index >= xs.length)) { - return Caml_array.set(xs, index, newval); + if (index < 0 || index >= xs.length) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "index out of bounds" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "index out of bounds" - } - }); + Caml_array.set(xs, index, newval); } function caml_array_get(xs, index) { - if (!(index < 0 || index >= xs.length)) { - return Caml_array.get(xs, index); + if (index < 0 || index >= xs.length) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "index out of bounds" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "index out of bounds" - } - }); + return Caml_array.get(xs, index); } function caml_make_vect(len, init) { diff --git a/jscomp/test/test_bytes.js b/jscomp/test/test_bytes.js index b48ab6d8c8..9d625d0f65 100644 --- a/jscomp/test/test_bytes.js +++ b/jscomp/test/test_bytes.js @@ -3,9 +3,7 @@ let Bytes = require("../../lib/js/bytes.js"); -function f(v) { - return Bytes.unsafe_to_string(v); -} +let f = Bytes.unsafe_to_string; let ff = Bytes.to_string; diff --git a/jscomp/test/test_demo.js b/jscomp/test/test_demo.js index 0724edaa9a..4a5a6409e0 100644 --- a/jscomp/test/test_demo.js +++ b/jscomp/test/test_demo.js @@ -59,14 +59,11 @@ function g1(x, y) { let u = 8; -let x = (function (z) { - return u + z | 0; -})(6); +let x = u + 6 | 0; function v(extra) { let u = 7; - let xx = 6; - return (xx + extra | 0) + u | 0; + return (6 + extra | 0) + u | 0; } let nil = "Nil"; @@ -84,4 +81,4 @@ exports.g = g; exports.g1 = g1; exports.x = x; exports.v = v; -/* x Not a pure module */ +/* No side effect */ diff --git a/jscomp/test/test_google_closure.js b/jscomp/test/test_google_closure.js index 4867382b5a..521a669292 100644 --- a/jscomp/test/test_google_closure.js +++ b/jscomp/test/test_google_closure.js @@ -27,7 +27,9 @@ let arr = $$Array.init(2, (function (param) { })); for(let i = 0; i <= 1; ++i){ - let f3$1 = f2(i); + let f3$1 = function (extra) { + return i + 1 | 0; + }; Caml_array.set(arr, i, f3$1(2)); } diff --git a/jscomp/test/test_list.js b/jscomp/test/test_list.js index 36532409f3..564d252d74 100644 --- a/jscomp/test/test_list.js +++ b/jscomp/test/test_list.js @@ -250,15 +250,15 @@ function rev_map2(f, l1, l2) { } }); } - if (!l2$1) { - return accu; + if (l2$1) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "List.rev_map2" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.rev_map2" - } - }); + return accu; }; } @@ -311,15 +311,15 @@ function fold_left2(f, _accu, _l1, _l2) { } }); } - if (!l2) { - return accu; + if (l2) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "List.fold_left2" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_left2" - } - }); + return accu; }; } @@ -335,15 +335,15 @@ function fold_right2(f, l1, l2, accu) { } }); } - if (!l2) { - return accu; + if (l2) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "List.fold_right2" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_right2" - } - }); + return accu; } function for_all(p, _x) { diff --git a/jscomp/test/test_unsupported_primitive.js b/jscomp/test/test_unsupported_primitive.js index 9de4f418a1..ac85e30558 100644 --- a/jscomp/test/test_unsupported_primitive.js +++ b/jscomp/test/test_unsupported_primitive.js @@ -4,15 +4,15 @@ let Caml_external_polyfill = require("../../lib/js/caml_external_polyfill.js"); function to_buffer(buff, ofs, len, v, flags) { - if (!(ofs < 0 || len < 0 || ofs > (buff.length - len | 0))) { - return Caml_external_polyfill.resolve("caml_output_value_to_buffer")(buff, ofs, len, v, flags); + if (ofs < 0 || len < 0 || ofs > (buff.length - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Marshal.to_buffer: substring out of bounds" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Marshal.to_buffer: substring out of bounds" - } - }); + return Caml_external_polyfill.resolve("caml_output_value_to_buffer")(buff, ofs, len, v, flags); } exports.to_buffer = to_buffer; diff --git a/jscomp/test/ticker.js b/jscomp/test/ticker.js index 80e119537a..c785f5687c 100644 --- a/jscomp/test/ticker.js +++ b/jscomp/test/ticker.js @@ -1293,21 +1293,21 @@ function process_input_line(ticker_map, all_tickers, line) { if (match$4) { let match$5 = match$4.tl; if (match$5) { - if (!match$5.tl) { - return [ - { - hd: make_binary_op(ticker_name, match$4.hd, match$5.hd, "PLUS"), - tl: all_tickers - }, - ticker_map - ]; + if (match$5.tl) { + throw new Error("Failure", { + cause: { + RE_EXN_ID: "Failure", + _1: "Invalid input line" + } + }); } - throw new Error("Failure", { - cause: { - RE_EXN_ID: "Failure", - _1: "Invalid input line" - } - }); + return [ + { + hd: make_binary_op(ticker_name, match$4.hd, match$5.hd, "PLUS"), + tl: all_tickers + }, + ticker_map + ]; } throw new Error("Failure", { cause: { @@ -1327,21 +1327,21 @@ function process_input_line(ticker_map, all_tickers, line) { if (match$6) { let match$7 = match$6.tl; if (match$7) { - if (!match$7.tl) { - return [ - { - hd: make_binary_op(ticker_name, match$6.hd, match$7.hd, "MINUS"), - tl: all_tickers - }, - ticker_map - ]; + if (match$7.tl) { + throw new Error("Failure", { + cause: { + RE_EXN_ID: "Failure", + _1: "Invalid input line" + } + }); } - throw new Error("Failure", { - cause: { - RE_EXN_ID: "Failure", - _1: "Invalid input line" - } - }); + return [ + { + hd: make_binary_op(ticker_name, match$6.hd, match$7.hd, "MINUS"), + tl: all_tickers + }, + ticker_map + ]; } throw new Error("Failure", { cause: { @@ -1357,26 +1357,26 @@ function process_input_line(ticker_map, all_tickers, line) { } }); case "S" : - if (!match$3.tl) { - return [ - { - hd: { - value: undefined, - rank: "Uninitialized", - ticker_name: ticker_name, - type_: "Market" - }, - tl: all_tickers - }, - ticker_map - ]; + if (match$3.tl) { + throw new Error("Failure", { + cause: { + RE_EXN_ID: "Failure", + _1: "Invalid input line" + } + }); } - throw new Error("Failure", { - cause: { - RE_EXN_ID: "Failure", - _1: "Invalid input line" - } - }); + return [ + { + hd: { + value: undefined, + rank: "Uninitialized", + ticker_name: ticker_name, + type_: "Market" + }, + tl: all_tickers + }, + ticker_map + ]; default: throw new Error("Failure", { cause: { diff --git a/jscomp/test/to_string_test.js b/jscomp/test/to_string_test.js index 58bf0132ca..1e2099db17 100644 --- a/jscomp/test/to_string_test.js +++ b/jscomp/test/to_string_test.js @@ -4,9 +4,7 @@ let Mt = require("./mt.js"); let Pervasives = require("../../lib/js/pervasives.js"); -function ff(v) { - return Pervasives.string_of_float(v); -} +let ff = Pervasives.string_of_float; function f(v) { return String(v); diff --git a/jscomp/test/topsort_test.js b/jscomp/test/topsort_test.js index 8f6ce9ba4a..d9f7b1d719 100644 --- a/jscomp/test/topsort_test.js +++ b/jscomp/test/topsort_test.js @@ -409,21 +409,16 @@ function unsafe_topsort(graph) { let visited = { contents: /* [] */0 }; - let sort_nodes = function (nodes) { - List.iter((function (node) { - sort_node(node); - }), nodes); - }; let sort_node = function (node) { - if (!List.mem(node, visited.contents)) { - sort_nodes(nexts(node, graph)); - visited.contents = { - hd: node, - tl: visited.contents - }; + if (List.mem(node, visited.contents)) { return; } - + let nodes = nexts(node, graph); + List.iter(sort_node, nodes); + visited.contents = { + hd: node, + tl: visited.contents + }; }; List.iter((function (param) { sort_node(param[0]); diff --git a/jscomp/test/uncurried_cast.js b/jscomp/test/uncurried_cast.js index 486ea7e6cc..56e3fa54c2 100644 --- a/jscomp/test/uncurried_cast.js +++ b/jscomp/test/uncurried_cast.js @@ -10,9 +10,7 @@ function raise(e) { }); } -function map(l, f) { - return Belt_List.mapU(l, f); -} +let map = Belt_List.mapU; let List = { map: map diff --git a/lib/es6/array.js b/lib/es6/array.js index 01edc6755a..c027a50579 100644 --- a/lib/es6/array.js +++ b/lib/es6/array.js @@ -57,15 +57,15 @@ function append(a1, a2) { } function sub(a, ofs, len) { - if (!(ofs < 0 || len < 0 || ofs > (a.length - len | 0))) { - return Caml_array.sub(a, ofs, len); + if (ofs < 0 || len < 0 || ofs > (a.length - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Array.sub" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Array.sub" - } - }); + return Caml_array.sub(a, ofs, len); } function fill(a, ofs, len, v) { @@ -83,15 +83,15 @@ function fill(a, ofs, len, 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))) { - return Caml_array.blit(a1, ofs1, a2, ofs2, len); + if (len < 0 || ofs1 < 0 || ofs1 > (a1.length - len | 0) || ofs2 < 0 || ofs2 > (a2.length - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Array.blit" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Array.blit" - } - }); + Caml_array.blit(a1, ofs1, a2, ofs2, len); } function iter(f, a) { diff --git a/lib/es6/arrayLabels.js b/lib/es6/arrayLabels.js index a0d1264e04..cf122ba8dd 100644 --- a/lib/es6/arrayLabels.js +++ b/lib/es6/arrayLabels.js @@ -57,15 +57,15 @@ function append(a1, a2) { } function sub(a, ofs, len) { - if (!(ofs < 0 || len < 0 || ofs > (a.length - len | 0))) { - return Caml_array.sub(a, ofs, len); + if (ofs < 0 || len < 0 || ofs > (a.length - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Array.sub" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Array.sub" - } - }); + return Caml_array.sub(a, ofs, len); } function fill(a, ofs, len, v) { @@ -83,15 +83,15 @@ function fill(a, ofs, len, 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))) { - return Caml_array.blit(a1, ofs1, a2, ofs2, len); + if (len < 0 || ofs1 < 0 || ofs1 > (a1.length - len | 0) || ofs2 < 0 || ofs2 > (a2.length - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Array.blit" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Array.blit" - } - }); + Caml_array.blit(a1, ofs1, a2, ofs2, len); } function iter(f, a) { diff --git a/lib/es6/belt_Array.js b/lib/es6/belt_Array.js index 8a0069be35..ddfd231929 100644 --- a/lib/es6/belt_Array.js +++ b/lib/es6/belt_Array.js @@ -325,9 +325,9 @@ function flatMapU(a, f) { } function flatMap(a, f) { - return flatMapU(a, (function (a) { + return concatMany(mapU(a, (function (a) { return f(a); - })); + }))); } function getByU(a, p) { diff --git a/lib/es6/belt_HashMapInt.js b/lib/es6/belt_HashMapInt.js index 905f88bcd7..2d1d6c8537 100644 --- a/lib/es6/belt_HashMapInt.js +++ b/lib/es6/belt_HashMapInt.js @@ -193,7 +193,7 @@ function size(h) { function fromArray(arr) { let len = arr.length; - let v = make(len); + let v = Belt_internalBucketsType.make(undefined, undefined, len); for(let i = 0; i < len; ++i){ let match = arr[i]; set(v, match[0], match[1]); diff --git a/lib/es6/belt_HashMapString.js b/lib/es6/belt_HashMapString.js index 041b2e8ace..c4352164cb 100644 --- a/lib/es6/belt_HashMapString.js +++ b/lib/es6/belt_HashMapString.js @@ -193,7 +193,7 @@ function size(h) { function fromArray(arr) { let len = arr.length; - let v = make(len); + let v = Belt_internalBucketsType.make(undefined, undefined, len); for(let i = 0; i < len; ++i){ let match = arr[i]; set(v, match[0], match[1]); diff --git a/lib/es6/belt_Map.js b/lib/es6/belt_Map.js index 9c811ba7fe..095b87f0a7 100644 --- a/lib/es6/belt_Map.js +++ b/lib/es6/belt_Map.js @@ -112,7 +112,7 @@ function findFirstByU(m, f) { } function findFirstBy(m, f) { - return findFirstByU(m, (function (a, b) { + return Belt_MapDict.findFirstByU(m.data, (function (a, b) { return f(a, b); })); } @@ -122,7 +122,7 @@ function forEachU(m, f) { } function forEach(m, f) { - forEachU(m, (function (a, b) { + Belt_MapDict.forEachU(m.data, (function (a, b) { f(a, b); })); } @@ -142,7 +142,7 @@ function everyU(m, f) { } function every(m, f) { - return everyU(m, (function (a, b) { + return Belt_MapDict.everyU(m.data, (function (a, b) { return f(a, b); })); } @@ -152,7 +152,7 @@ function someU(m, f) { } function some(m, f) { - return someU(m, (function (a, b) { + return Belt_MapDict.someU(m.data, (function (a, b) { return f(a, b); })); } diff --git a/lib/es6/belt_MutableMap.js b/lib/es6/belt_MutableMap.js index df575d99d5..009ef39219 100644 --- a/lib/es6/belt_MutableMap.js +++ b/lib/es6/belt_MutableMap.js @@ -153,7 +153,8 @@ function clear(m) { } function isEmpty(d) { - return d.data === undefined; + let x = d.data; + return x === undefined; } function minKey(m) { @@ -193,7 +194,7 @@ function forEachU(d, f) { } function forEach(d, f) { - forEachU(d, (function (a, b) { + Belt_internalAVLtree.forEachU(d.data, (function (a, b) { f(a, b); })); } @@ -213,7 +214,7 @@ function everyU(d, p) { } function every(d, p) { - return everyU(d, (function (a, b) { + return Belt_internalAVLtree.everyU(d.data, (function (a, b) { return p(a, b); })); } @@ -223,7 +224,7 @@ function someU(d, p) { } function some(d, p) { - return someU(d, (function (a, b) { + return Belt_internalAVLtree.someU(d.data, (function (a, b) { return p(a, b); })); } diff --git a/lib/es6/belt_MutableMapInt.js b/lib/es6/belt_MutableMapInt.js index dc792430ed..f1549c8441 100644 --- a/lib/es6/belt_MutableMapInt.js +++ b/lib/es6/belt_MutableMapInt.js @@ -11,7 +11,8 @@ function make() { } function isEmpty(m) { - return m.data === undefined; + let x = m.data; + return x === undefined; } function clear(m) { @@ -65,7 +66,7 @@ function forEachU(d, f) { } function forEach(d, f) { - forEachU(d, (function (a, b) { + Belt_internalAVLtree.forEachU(d.data, (function (a, b) { f(a, b); })); } @@ -109,7 +110,7 @@ function everyU(d, f) { } function every(d, f) { - return everyU(d, (function (a, b) { + return Belt_internalAVLtree.everyU(d.data, (function (a, b) { return f(a, b); })); } @@ -119,7 +120,7 @@ function someU(d, f) { } function some(d, f) { - return someU(d, (function (a, b) { + return Belt_internalAVLtree.someU(d.data, (function (a, b) { return f(a, b); })); } diff --git a/lib/es6/belt_MutableMapString.js b/lib/es6/belt_MutableMapString.js index b0d77bb7e7..60243c3480 100644 --- a/lib/es6/belt_MutableMapString.js +++ b/lib/es6/belt_MutableMapString.js @@ -11,7 +11,8 @@ function make() { } function isEmpty(m) { - return m.data === undefined; + let x = m.data; + return x === undefined; } function clear(m) { @@ -65,7 +66,7 @@ function forEachU(d, f) { } function forEach(d, f) { - forEachU(d, (function (a, b) { + Belt_internalAVLtree.forEachU(d.data, (function (a, b) { f(a, b); })); } @@ -109,7 +110,7 @@ function everyU(d, f) { } function every(d, f) { - return everyU(d, (function (a, b) { + return Belt_internalAVLtree.everyU(d.data, (function (a, b) { return f(a, b); })); } @@ -119,7 +120,7 @@ function someU(d, f) { } function some(d, f) { - return someU(d, (function (a, b) { + return Belt_internalAVLtree.someU(d.data, (function (a, b) { return f(a, b); })); } diff --git a/lib/es6/belt_MutableSet.js b/lib/es6/belt_MutableSet.js index 05ed011852..49ca11d976 100644 --- a/lib/es6/belt_MutableSet.js +++ b/lib/es6/belt_MutableSet.js @@ -192,7 +192,8 @@ function make(id) { } function isEmpty(d) { - return d.data === undefined; + let n = d.data; + return n === undefined; } function minimum(d) { @@ -216,7 +217,7 @@ function forEachU(d, f) { } function forEach(d, f) { - forEachU(d, (function (a) { + Belt_internalAVLset.forEachU(d.data, (function (a) { f(a); })); } @@ -236,7 +237,7 @@ function everyU(d, p) { } function every(d, p) { - return everyU(d, (function (a) { + return Belt_internalAVLset.everyU(d.data, (function (a) { return p(a); })); } @@ -246,7 +247,7 @@ function someU(d, p) { } function some(d, p) { - return someU(d, (function (a) { + return Belt_internalAVLset.someU(d.data, (function (a) { return p(a); })); } diff --git a/lib/es6/belt_MutableSetInt.js b/lib/es6/belt_MutableSetInt.js index 47ff473614..1507932c69 100644 --- a/lib/es6/belt_MutableSetInt.js +++ b/lib/es6/belt_MutableSetInt.js @@ -189,7 +189,8 @@ function make() { } function isEmpty(d) { - return d.data === undefined; + let n = d.data; + return n === undefined; } function minimum(d) { @@ -213,7 +214,7 @@ function forEachU(d, f) { } function forEach(d, f) { - forEachU(d, (function (a) { + Belt_internalAVLset.forEachU(d.data, (function (a) { f(a); })); } @@ -233,7 +234,7 @@ function everyU(d, p) { } function every(d, p) { - return everyU(d, (function (a) { + return Belt_internalAVLset.everyU(d.data, (function (a) { return p(a); })); } @@ -243,7 +244,7 @@ function someU(d, p) { } function some(d, p) { - return someU(d, (function (a) { + return Belt_internalAVLset.someU(d.data, (function (a) { return p(a); })); } diff --git a/lib/es6/belt_MutableSetString.js b/lib/es6/belt_MutableSetString.js index d8a217d1ef..004803ecb6 100644 --- a/lib/es6/belt_MutableSetString.js +++ b/lib/es6/belt_MutableSetString.js @@ -189,7 +189,8 @@ function make() { } function isEmpty(d) { - return d.data === undefined; + let n = d.data; + return n === undefined; } function minimum(d) { @@ -213,7 +214,7 @@ function forEachU(d, f) { } function forEach(d, f) { - forEachU(d, (function (a) { + Belt_internalAVLset.forEachU(d.data, (function (a) { f(a); })); } @@ -233,7 +234,7 @@ function everyU(d, p) { } function every(d, p) { - return everyU(d, (function (a) { + return Belt_internalAVLset.everyU(d.data, (function (a) { return p(a); })); } @@ -243,7 +244,7 @@ function someU(d, p) { } function some(d, p) { - return someU(d, (function (a) { + return Belt_internalAVLset.someU(d.data, (function (a) { return p(a); })); } diff --git a/lib/es6/belt_Set.js b/lib/es6/belt_Set.js index c68c9f5b85..e2046a6ac2 100644 --- a/lib/es6/belt_Set.js +++ b/lib/es6/belt_Set.js @@ -127,7 +127,7 @@ function forEachU(m, f) { } function forEach(m, f) { - forEachU(m, (function (a) { + Belt_SetDict.forEachU(m.data, (function (a) { f(a); })); } @@ -147,7 +147,7 @@ function everyU(m, f) { } function every(m, f) { - return everyU(m, (function (a) { + return Belt_SetDict.everyU(m.data, (function (a) { return f(a); })); } @@ -157,7 +157,7 @@ function someU(m, f) { } function some(m, f) { - return someU(m, (function (a) { + return Belt_SetDict.someU(m.data, (function (a) { return f(a); })); } diff --git a/lib/es6/belt_internalBuckets.js b/lib/es6/belt_internalBuckets.js index 43299a9adc..7842375964 100644 --- a/lib/es6/belt_internalBuckets.js +++ b/lib/es6/belt_internalBuckets.js @@ -3,19 +3,6 @@ import * as Belt_Array from "./belt_Array.js"; import * as Caml_option from "./caml_option.js"; -function copyBucket(c) { - if (c === undefined) { - return c; - } - let head = { - key: c.key, - value: c.value, - next: undefined - }; - copyAuxCont(c.next, head); - return head; -} - function copyAuxCont(_c, _prec) { while(true) { let prec = _prec; @@ -35,6 +22,19 @@ function copyAuxCont(_c, _prec) { }; } +function copyBucket(c) { + if (c === undefined) { + return c; + } + let head = { + key: c.key, + value: c.value, + next: undefined + }; + copyAuxCont(c.next, head); + return head; +} + function copyBuckets(buckets) { let len = buckets.length; let newBuckets = new Array(len); diff --git a/lib/es6/buffer.js b/lib/es6/buffer.js index 5a3d7c2b44..a396c734a2 100644 --- a/lib/es6/buffer.js +++ b/lib/es6/buffer.js @@ -25,39 +25,39 @@ function to_bytes(b) { } function sub(b, ofs, len) { - if (!(ofs < 0 || len < 0 || ofs > (b.position - len | 0))) { - return Bytes.sub_string(b.buffer, ofs, len); + if (ofs < 0 || len < 0 || ofs > (b.position - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Buffer.sub" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Buffer.sub" - } - }); + 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))) { - return Bytes.blit(src.buffer, srcoff, dst, dstoff, len); + if (len < 0 || srcoff < 0 || srcoff > (src.position - len | 0) || dstoff < 0 || dstoff > (dst.length - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Buffer.blit" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Buffer.blit" - } - }); + Bytes.blit(src.buffer, srcoff, dst, dstoff, len); } function nth(b, ofs) { - if (!(ofs < 0 || ofs >= b.position)) { - return b.buffer[ofs]; + if (ofs < 0 || ofs >= b.position) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Buffer.nth" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Buffer.nth" - } - }); + return b.buffer[ofs]; } function length(b) { @@ -454,16 +454,15 @@ function add_substitute(b, f, s) { } function truncate(b, len) { - if (!(len < 0 || len > b.position)) { - b.position = len; - return; + if (len < 0 || len > b.position) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Buffer.truncate" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Buffer.truncate" - } - }); + b.position = len; } export { diff --git a/lib/es6/bytes.js b/lib/es6/bytes.js index c0ae45e111..39bf696da3 100644 --- a/lib/es6/bytes.js +++ b/lib/es6/bytes.js @@ -148,15 +148,15 @@ function $plus$plus(a, b) { if (match$1) { return c; } - if (!match$2) { - return c; + if (match$2) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Bytes.extend" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Bytes.extend" - } - }); + return c; } function extend(s, left, right) { @@ -179,55 +179,54 @@ function extend(s, left, right) { } function fill(s, ofs, len, c) { - if (!(ofs < 0 || len < 0 || ofs > (s.length - len | 0))) { - return unsafe_fill(s, ofs, len, c); + if (ofs < 0 || len < 0 || ofs > (s.length - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.fill / Bytes.fill" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.fill / Bytes.fill" - } - }); + 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))) { - return unsafe_blit(s1, ofs1, s2, ofs2, len); + if (len < 0 || ofs1 < 0 || ofs1 > (s1.length - len | 0) || ofs2 < 0 || ofs2 > (s2.length - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Bytes.blit" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Bytes.blit" - } - }); + 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))) { - 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; + if (len < 0 || ofs1 < 0 || ofs1 > (s1.length - len | 0) || ofs2 < 0 || ofs2 > (s2.length - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.blit / Bytes.blit_string" + } + }); + } + 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; } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.blit / Bytes.blit_string" - } - }); + 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) { @@ -530,28 +529,28 @@ function index_opt(s, c) { function index_from(s, i, c) { let l = s.length; - if (!(i < 0 || i > l)) { - return index_rec(s, l, i, c); + if (i < 0 || i > l) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.index_from / Bytes.index_from" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from / Bytes.index_from" - } - }); + return index_rec(s, l, i, c); } function index_from_opt(s, i, c) { let l = s.length; - if (!(i < 0 || i > l)) { - return index_rec_opt(s, l, i, c); + if (i < 0 || i > l) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.index_from_opt / Bytes.index_from_opt" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from_opt / Bytes.index_from_opt" - } - }); + return index_rec_opt(s, l, i, c); } function rindex_rec(s, _i, c) { @@ -577,15 +576,15 @@ function rindex(s, c) { } function rindex_from(s, i, c) { - if (!(i < -1 || i >= s.length)) { - return rindex_rec(s, i, c); + if (i < -1 || i >= s.length) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.rindex_from / Bytes.rindex_from" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from / Bytes.rindex_from" - } - }); + return rindex_rec(s, i, c); } function rindex_rec_opt(s, _i, c) { @@ -607,15 +606,15 @@ function rindex_opt(s, c) { } function rindex_from_opt(s, i, c) { - if (!(i < -1 || i >= s.length)) { - return rindex_rec_opt(s, i, c); + if (i < -1 || i >= s.length) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.rindex_from_opt / Bytes.rindex_from_opt" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from_opt / Bytes.rindex_from_opt" - } - }); + return rindex_rec_opt(s, i, c); } function contains_from(s, i, c) { diff --git a/lib/es6/bytesLabels.js b/lib/es6/bytesLabels.js index c0ae45e111..39bf696da3 100644 --- a/lib/es6/bytesLabels.js +++ b/lib/es6/bytesLabels.js @@ -148,15 +148,15 @@ function $plus$plus(a, b) { if (match$1) { return c; } - if (!match$2) { - return c; + if (match$2) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Bytes.extend" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Bytes.extend" - } - }); + return c; } function extend(s, left, right) { @@ -179,55 +179,54 @@ function extend(s, left, right) { } function fill(s, ofs, len, c) { - if (!(ofs < 0 || len < 0 || ofs > (s.length - len | 0))) { - return unsafe_fill(s, ofs, len, c); + if (ofs < 0 || len < 0 || ofs > (s.length - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.fill / Bytes.fill" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.fill / Bytes.fill" - } - }); + 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))) { - return unsafe_blit(s1, ofs1, s2, ofs2, len); + if (len < 0 || ofs1 < 0 || ofs1 > (s1.length - len | 0) || ofs2 < 0 || ofs2 > (s2.length - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Bytes.blit" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Bytes.blit" - } - }); + 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))) { - 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; + if (len < 0 || ofs1 < 0 || ofs1 > (s1.length - len | 0) || ofs2 < 0 || ofs2 > (s2.length - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.blit / Bytes.blit_string" + } + }); + } + 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; } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.blit / Bytes.blit_string" - } - }); + 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) { @@ -530,28 +529,28 @@ function index_opt(s, c) { function index_from(s, i, c) { let l = s.length; - if (!(i < 0 || i > l)) { - return index_rec(s, l, i, c); + if (i < 0 || i > l) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.index_from / Bytes.index_from" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from / Bytes.index_from" - } - }); + return index_rec(s, l, i, c); } function index_from_opt(s, i, c) { let l = s.length; - if (!(i < 0 || i > l)) { - return index_rec_opt(s, l, i, c); + if (i < 0 || i > l) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.index_from_opt / Bytes.index_from_opt" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from_opt / Bytes.index_from_opt" - } - }); + return index_rec_opt(s, l, i, c); } function rindex_rec(s, _i, c) { @@ -577,15 +576,15 @@ function rindex(s, c) { } function rindex_from(s, i, c) { - if (!(i < -1 || i >= s.length)) { - return rindex_rec(s, i, c); + if (i < -1 || i >= s.length) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.rindex_from / Bytes.rindex_from" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from / Bytes.rindex_from" - } - }); + return rindex_rec(s, i, c); } function rindex_rec_opt(s, _i, c) { @@ -607,15 +606,15 @@ function rindex_opt(s, c) { } function rindex_from_opt(s, i, c) { - if (!(i < -1 || i >= s.length)) { - return rindex_rec_opt(s, i, c); + if (i < -1 || i >= s.length) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.rindex_from_opt / Bytes.rindex_from_opt" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from_opt / Bytes.rindex_from_opt" - } - }); + return rindex_rec_opt(s, i, c); } function contains_from(s, i, c) { diff --git a/lib/es6/caml.js b/lib/es6/caml.js index 65242212b2..a85e2555f3 100644 --- a/lib/es6/caml.js +++ b/lib/es6/caml.js @@ -166,10 +166,10 @@ function i64_le(x, y) { } function i64_min(x, y) { - if (i64_lt(x, y)) { - return x; - } else { + if (i64_ge(x, y)) { return y; + } else { + return x; } } diff --git a/lib/es6/char.js b/lib/es6/char.js index 3c49e01262..3e41fcddf6 100644 --- a/lib/es6/char.js +++ b/lib/es6/char.js @@ -3,15 +3,15 @@ import * as Bytes from "./bytes.js"; function chr(n) { - if (!(n < 0 || n > 255)) { - return n; + if (n < 0 || n > 255) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Char.chr" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Char.chr" - } - }); + return n; } function escaped(param) { diff --git a/lib/es6/digest.js b/lib/es6/digest.js index 8025c68591..d321133827 100644 --- a/lib/es6/digest.js +++ b/lib/es6/digest.js @@ -16,15 +16,15 @@ function bytes(b) { } function substring(str, ofs, len) { - if (!(ofs < 0 || len < 0 || ofs > (str.length - len | 0))) { - return Caml_md5.md5_string(str, ofs, len); + if (ofs < 0 || len < 0 || ofs > (str.length - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Digest.substring" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Digest.substring" - } - }); + return Caml_md5.md5_string(str, ofs, len); } function subbytes(b, ofs, len) { diff --git a/lib/es6/filename.js b/lib/es6/filename.js index f894484288..1c278eaa94 100644 --- a/lib/es6/filename.js +++ b/lib/es6/filename.js @@ -1,6 +1,7 @@ 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"; @@ -193,7 +194,7 @@ function check_suffix$1(name, suff) { return false; } let s = $$String.sub(name, name.length - suff.length | 0, suff.length); - return $$String.lowercase_ascii(s) === $$String.lowercase_ascii(suff); + 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; @@ -382,15 +383,15 @@ function concat(dirname, filename) { function chop_suffix(name, suff) { let n = name.length - suff.length | 0; - if (n >= 0) { - return $$String.sub(name, 0, n); + if (n < 0) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Filename.chop_suffix" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Filename.chop_suffix" - } - }); + return $$String.sub(name, 0, n); } function extension_len(name) { @@ -430,15 +431,15 @@ function extension(name) { function chop_extension(name) { let l = extension_len(name); - if (l !== 0) { - return $$String.sub(name, 0, name.length - l | 0); + if (l === 0) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Filename.chop_extension" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Filename.chop_extension" - } - }); + return $$String.sub(name, 0, name.length - l | 0); } function remove_extension(name) { diff --git a/lib/es6/genlex.js b/lib/es6/genlex.js index 5a0b8ed711..db2acdd716 100644 --- a/lib/es6/genlex.js +++ b/lib/es6/genlex.js @@ -105,8 +105,8 @@ function make_lexer(keywords) { case 13 : case 26 : case 32 : - exit = 2; - break; + Stream.junk(strm__); + continue; case 34 : Stream.junk(strm__); reset_buffer(); @@ -175,10 +175,11 @@ function make_lexer(keywords) { store(/* '-' */45); store(c$2); return number(strm__); + } else { + reset_buffer(); + store(/* '-' */45); + return ident2(strm__); } - reset_buffer(); - store(/* '-' */45); - return ident2(strm__); case 48 : case 49 : case 50 : @@ -189,7 +190,7 @@ function make_lexer(keywords) { case 55 : case 56 : case 57 : - exit = 5; + exit = 4; break; case 0 : case 1 : @@ -238,7 +239,7 @@ function make_lexer(keywords) { case 62 : case 63 : case 64 : - exit = 4; + exit = 3; break; } @@ -247,7 +248,7 @@ function make_lexer(keywords) { switch (c) { case 92 : case 94 : - exit = 4; + exit = 3; break; case 91 : case 93 : @@ -255,14 +256,14 @@ function make_lexer(keywords) { exit = 1; break; default: - exit = 3; + exit = 2; } } } else { exit = c >= 127 ? ( - c > 255 || c < 192 ? 1 : 3 + c > 255 || c < 192 ? 1 : 2 ) : ( - c !== 125 ? 4 : 1 + c !== 125 ? 3 : 1 ); } switch (exit) { @@ -270,49 +271,42 @@ function make_lexer(keywords) { Stream.junk(strm__); return keyword_or_error(c); case 2 : - Stream.junk(strm__); - continue; - case 3 : Stream.junk(strm__); reset_buffer(); store(c); while(true) { let c$3 = Stream.peek(strm__); - if (c$3 !== undefined) { - let exit$1 = 0; - if (c$3 >= 91) { - if (c$3 > 122 || c$3 < 95) { - if (!(c$3 > 255 || c$3 < 192)) { - exit$1 = 2; - } - - } else if (c$3 !== 96) { - exit$1 = 2; - } - - } else if (c$3 >= 48) { - if (c$3 > 64 || c$3 < 58) { - exit$1 = 2; + 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 === 39) { - exit$1 = 2; + } else if (c$3 === 96) { + return ident_or_keyword(get_string()); } - if (exit$1 === 2) { - Stream.junk(strm__); - store(c$3); - continue; + + } 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()); } - return ident_or_keyword(get_string()); + Stream.junk(strm__); + store(c$3); + continue; }; - case 4 : + case 3 : Stream.junk(strm__); reset_buffer(); store(c); return ident2(strm__); - case 5 : + case 4 : Stream.junk(strm__); reset_buffer(); store(c); @@ -324,81 +318,80 @@ function make_lexer(keywords) { let ident2 = function (strm__) { while(true) { let c = Stream.peek(strm__); - if (c !== undefined) { - let exit = 0; - if (c >= 94) { - if (c > 125 || c < 95) { - if (c < 127) { - exit = 2; - } - - } else if (c === 124) { - exit = 2; - } - - } else if (c >= 65) { - if (c === 92) { - exit = 2; + 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 >= 33) { - 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 : - break; - 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 : - exit = 2; - break; - - } + } else if (c !== 124) { + return ident_or_keyword(get_string()); } - if (exit === 2) { - Stream.junk(strm__); - store(c); - continue; + + } 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; + + } } - return ident_or_keyword(get_string()); + Stream.junk(strm__); + store(c); + continue; }; }; let number = function (strm__) { while(true) { let c = Stream.peek(strm__); if (c !== undefined) { - let exit = 0; if (c >= 58) { if (!(c !== 69 && c !== 101)) { - exit = 2; + Stream.junk(strm__); + store(/* 'E' */69); + return exponent_part(strm__); } } else if (c !== 46) { @@ -434,12 +427,6 @@ function make_lexer(keywords) { }; }; } - if (exit === 2) { - Stream.junk(strm__); - store(/* 'E' */69); - return exponent_part(strm__); - } - } return { TAG: "Int", @@ -449,15 +436,13 @@ function make_lexer(keywords) { }; let exponent_part = function (strm__) { let c = Stream.peek(strm__); - if (c === undefined) { + if (c !== undefined && !(c !== 43 && c !== 45)) { + Stream.junk(strm__); + store(c); return end_exponent_part(strm__); - } - if (c !== 43 && c !== 45) { + } else { return end_exponent_part(strm__); } - Stream.junk(strm__); - store(c); - return end_exponent_part(strm__); }; let end_exponent_part = function (strm__) { while(true) { @@ -692,4 +677,4 @@ function make_lexer(keywords) { export { make_lexer, } -/* Hashtbl Not a pure module */ +/* No side effect */ diff --git a/lib/es6/hashtbl.js b/lib/es6/hashtbl.js index ca21010481..c0ea9129b9 100644 --- a/lib/es6/hashtbl.js +++ b/lib/es6/hashtbl.js @@ -1,7 +1,6 @@ import * as Caml from "./caml.js"; -import * as Lazy from "./lazy.js"; import * as $$Array from "./array.js"; import * as Random from "./random.js"; import * as Caml_obj from "./caml_obj.js"; @@ -39,7 +38,7 @@ function is_randomized() { return randomized.contents; } -let prng = Lazy.from_fun(function () { +let prng = CamlinternalLazy.from_fun(function () { return Random.State.make_self_init(); }); @@ -1142,4 +1141,4 @@ export { hash_param, seeded_hash_param, } -/* prng Not a pure module */ +/* No side effect */ diff --git a/lib/es6/hashtblLabels.js b/lib/es6/hashtblLabels.js index 9b3a3844a1..7c623f7274 100644 --- a/lib/es6/hashtblLabels.js +++ b/lib/es6/hashtblLabels.js @@ -196,4 +196,4 @@ export { MakeSeeded, Make, } -/* Hashtbl Not a pure module */ +/* No side effect */ diff --git a/lib/es6/js.js b/lib/es6/js.js index bc89eac524..59a50d1787 100644 --- a/lib/es6/js.js +++ b/lib/es6/js.js @@ -1,8 +1,6 @@ -let Internal = {}; - let Null; let Undefined; @@ -70,7 +68,6 @@ let $$Map; let $$WeakMap; export { - Internal, Null, Undefined, Nullable, diff --git a/lib/es6/lazy.js b/lib/es6/lazy.js index 9153ac974b..14e2ebd88b 100644 --- a/lib/es6/lazy.js +++ b/lib/es6/lazy.js @@ -8,9 +8,7 @@ function from_fun(f) { }); } -function from_val(v) { - return CamlinternalLazy.from_val(v); -} +let from_val = CamlinternalLazy.from_val; let Undefined = CamlinternalLazy.Undefined; diff --git a/lib/es6/list.js b/lib/es6/list.js index 75645dc081..02a588f97a 100644 --- a/lib/es6/list.js +++ b/lib/es6/list.js @@ -155,19 +155,19 @@ function init_aux(i, n, f) { } function init(len, f) { - if (len >= 0) { - if (len > 10000) { - return rev_append(init_tailrec_aux(/* [] */0, 0, len, f), /* [] */0); - } else { - return init_aux(0, len, f); - } + if (len < 0) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "List.init" + } + }); + } + if (len > 10000) { + return rev_append(init_tailrec_aux(/* [] */0, 0, len, f), /* [] */0); + } else { + return init_aux(0, len, f); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.init" - } - }); } function flatten(param) { @@ -323,15 +323,15 @@ function rev_map2(f, l1, l2) { } }); } - if (!l2$1) { - return accu; + if (l2$1) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "List.rev_map2" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.rev_map2" - } - }); + return accu; }; } @@ -384,15 +384,15 @@ function fold_left2(f, _accu, _l1, _l2) { } }); } - if (!l2) { - return accu; + if (l2) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "List.fold_left2" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_left2" - } - }); + return accu; }; } @@ -408,15 +408,15 @@ function fold_right2(f, l1, l2, accu) { } }); } - if (!l2) { - return accu; + if (l2) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "List.fold_right2" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_right2" - } - }); + return accu; } function for_all(p, _param) { diff --git a/lib/es6/listLabels.js b/lib/es6/listLabels.js index 85bb33989a..a12d7fcd6d 100644 --- a/lib/es6/listLabels.js +++ b/lib/es6/listLabels.js @@ -155,19 +155,19 @@ function init_aux(i, n, f) { } function init(len, f) { - if (len >= 0) { - if (len > 10000) { - return rev_append(init_tailrec_aux(/* [] */0, 0, len, f), /* [] */0); - } else { - return init_aux(0, len, f); - } + if (len < 0) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "List.init" + } + }); + } + if (len > 10000) { + return rev_append(init_tailrec_aux(/* [] */0, 0, len, f), /* [] */0); + } else { + return init_aux(0, len, f); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.init" - } - }); } function flatten(param) { @@ -323,15 +323,15 @@ function rev_map2(f, l1, l2) { } }); } - if (!l2$1) { - return accu; + if (l2$1) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "List.rev_map2" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.rev_map2" - } - }); + return accu; }; } @@ -384,15 +384,15 @@ function fold_left2(f, _accu, _l1, _l2) { } }); } - if (!l2) { - return accu; + if (l2) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "List.fold_left2" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_left2" - } - }); + return accu; }; } @@ -408,15 +408,15 @@ function fold_right2(f, l1, l2, accu) { } }); } - if (!l2) { - return accu; + if (l2) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "List.fold_right2" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_right2" - } - }); + return accu; } function for_all(p, _param) { diff --git a/lib/es6/moreLabels.js b/lib/es6/moreLabels.js index bb08f475a0..d90e8d2957 100644 --- a/lib/es6/moreLabels.js +++ b/lib/es6/moreLabels.js @@ -1977,4 +1977,4 @@ export { $$Map, $$Set, } -/* HashtblLabels Not a pure module */ +/* No side effect */ diff --git a/lib/es6/pervasives.js b/lib/es6/pervasives.js index e211c20bee..255eeeffc4 100644 --- a/lib/es6/pervasives.js +++ b/lib/es6/pervasives.js @@ -185,7 +185,7 @@ function print_int(i) { } function print_float(i) { - console.log(string_of_float(i)); + console.log(valid_float_lexem(Caml_format.format_float("%.12g", i))); } function print_string(prim) { diff --git a/lib/es6/random.js b/lib/es6/random.js index c0e7284cf1..e2e703067e 100644 --- a/lib/es6/random.js +++ b/lib/es6/random.js @@ -74,65 +74,65 @@ function bits(s) { } function int(s, bound) { - if (!(bound > 1073741823 || bound <= 0)) { - while(true) { - let r = bits(s); - let v = r % bound; - if ((r - v | 0) <= ((1073741823 - bound | 0) + 1 | 0)) { - return v; - } - continue; - }; + if (bound > 1073741823 || bound <= 0) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Random.int" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Random.int" - } - }); + 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) { - 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; - }; + if (bound <= 0) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Random.int32" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Random.int32" - } - }); + 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)) { - 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; - }; + if (Caml.i64_le(bound, Caml_int64.zero)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Random.int64" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Random.int64" - } - }); + 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) { @@ -227,7 +227,7 @@ function int64$1(bound) { } function float$1(scale) { - return float($$default, scale); + return rawfloat($$default) * scale; } function bool$1() { diff --git a/lib/es6/stream.js b/lib/es6/stream.js index c1fffd51dc..5d6058b378 100644 --- a/lib/es6/stream.js +++ b/lib/es6/stream.js @@ -1,6 +1,5 @@ -import * as Lazy from "./lazy.js"; import * as List from "./list.js"; import * as Caml_bytes from "./caml_bytes.js"; import * as Caml_option from "./caml_option.js"; @@ -362,32 +361,38 @@ function ising(i) { } function lapp(f, s) { + let f$1 = function () { + return { + TAG: "Sapp", + _0: data(f()), + _1: data(s) + }; + }; return { count: 0, data: { TAG: "Slazy", - _0: Lazy.from_fun(function () { - return { - TAG: "Sapp", - _0: data(f()), - _1: data(s) - }; + _0: CamlinternalLazy.from_fun(function () { + return f$1(); }) } }; } function lcons(f, s) { + let f$1 = function () { + return { + TAG: "Scons", + _0: f(), + _1: data(s) + }; + }; return { count: 0, data: { TAG: "Slazy", - _0: Lazy.from_fun(function () { - return { - TAG: "Scons", - _0: f(), - _1: data(s) - }; + _0: CamlinternalLazy.from_fun(function () { + return f$1(); }) } }; @@ -398,7 +403,7 @@ function lsing(f) { count: 0, data: { TAG: "Slazy", - _0: Lazy.from_fun(function () { + _0: CamlinternalLazy.from_fun(function () { return { TAG: "Scons", _0: f(), @@ -414,7 +419,7 @@ function slazy(f) { count: 0, data: { TAG: "Slazy", - _0: Lazy.from_fun(function () { + _0: CamlinternalLazy.from_fun(function () { return data(f()); }) } diff --git a/lib/es6/string.js b/lib/es6/string.js index 8fd3ca5035..80b4bd8637 100644 --- a/lib/es6/string.js +++ b/lib/es6/string.js @@ -128,28 +128,28 @@ function index_opt(s, c) { function index_from(s, i, c) { let l = s.length; - if (!(i < 0 || i > l)) { - return index_rec(s, l, i, c); + if (i < 0 || i > l) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.index_from / Bytes.index_from" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from / Bytes.index_from" - } - }); + return index_rec(s, l, i, c); } function index_from_opt(s, i, c) { let l = s.length; - if (!(i < 0 || i > l)) { - return index_rec_opt(s, l, i, c); + if (i < 0 || i > l) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.index_from_opt / Bytes.index_from_opt" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from_opt / Bytes.index_from_opt" - } - }); + return index_rec_opt(s, l, i, c); } function rindex_rec(s, _i, c) { @@ -175,15 +175,15 @@ function rindex(s, c) { } function rindex_from(s, i, c) { - if (!(i < -1 || i >= s.length)) { - return rindex_rec(s, i, c); + if (i < -1 || i >= s.length) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.rindex_from / Bytes.rindex_from" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from / Bytes.rindex_from" - } - }); + return rindex_rec(s, i, c); } function rindex_rec_opt(s, _i, c) { @@ -205,15 +205,15 @@ function rindex_opt(s, c) { } function rindex_from_opt(s, i, c) { - if (!(i < -1 || i >= s.length)) { - return rindex_rec_opt(s, i, c); + if (i < -1 || i >= s.length) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.rindex_from_opt / Bytes.rindex_from_opt" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from_opt / Bytes.rindex_from_opt" - } - }); + return rindex_rec_opt(s, i, c); } function contains_from(s, i, c) { diff --git a/lib/es6/stringLabels.js b/lib/es6/stringLabels.js index 3db2216ab3..38232f9ba9 100644 --- a/lib/es6/stringLabels.js +++ b/lib/es6/stringLabels.js @@ -14,9 +14,7 @@ function sub(s, ofs, len) { return Bytes.unsafe_to_string(Bytes.sub(Bytes.unsafe_of_string(s), ofs, len)); } -function blit(src, src_pos, dst, dst_pos, len) { - Bytes.blit_string(src, src_pos, dst, dst_pos, len); -} +let blit = Bytes.blit_string; function concat(sep, xs) { return $$Array.of_list(xs).join(sep); @@ -132,28 +130,28 @@ function index_opt(s, c) { function index_from(s, i, c) { let l = s.length; - if (!(i < 0 || i > l)) { - return index_rec(s, l, i, c); + if (i < 0 || i > l) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.index_from / Bytes.index_from" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from / Bytes.index_from" - } - }); + return index_rec(s, l, i, c); } function index_from_opt(s, i, c) { let l = s.length; - if (!(i < 0 || i > l)) { - return index_rec_opt(s, l, i, c); + if (i < 0 || i > l) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.index_from_opt / Bytes.index_from_opt" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from_opt / Bytes.index_from_opt" - } - }); + return index_rec_opt(s, l, i, c); } function rindex_rec(s, _i, c) { @@ -179,15 +177,15 @@ function rindex(s, c) { } function rindex_from(s, i, c) { - if (!(i < -1 || i >= s.length)) { - return rindex_rec(s, i, c); + if (i < -1 || i >= s.length) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.rindex_from / Bytes.rindex_from" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from / Bytes.rindex_from" - } - }); + return rindex_rec(s, i, c); } function rindex_rec_opt(s, _i, c) { @@ -209,15 +207,15 @@ function rindex_opt(s, c) { } function rindex_from_opt(s, i, c) { - if (!(i < -1 || i >= s.length)) { - return rindex_rec_opt(s, i, c); + if (i < -1 || i >= s.length) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.rindex_from_opt / Bytes.rindex_from_opt" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from_opt / Bytes.rindex_from_opt" - } - }); + return rindex_rec_opt(s, i, c); } function contains_from(s, i, c) { diff --git a/lib/es6/sys.js b/lib/es6/sys.js index 7ddb3c3ddd..1ded50c6ab 100644 --- a/lib/es6/sys.js +++ b/lib/es6/sys.js @@ -45,20 +45,7 @@ function set_signal(sig_num, sig_beh) { let Break = /* @__PURE__ */Caml_exceptions.create("Sys.Break"); function catch_break(on) { - if (on) { - return set_signal(-6, { - TAG: "Signal_handle", - _0: (function (param) { - throw new Error(Break, { - cause: { - RE_EXN_ID: Break - } - }); - }) - }); - } else { - return set_signal(-6, "Signal_default"); - } + } function enable_runtime_warnings(param) { diff --git a/lib/es6/uchar.js b/lib/es6/uchar.js index cfb8c42324..f98c218a31 100644 --- a/lib/es6/uchar.js +++ b/lib/es6/uchar.js @@ -15,30 +15,30 @@ function succ(u) { if (u === 55295) { return 57344; } - if (u !== 1114111) { - return u + 1 | 0; + if (u === 1114111) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "U+10FFFF has no successor" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "U+10FFFF has no successor" - } - }); + return u + 1 | 0; } function pred(u) { if (u === 57344) { return 55295; } - if (u !== 0) { - return u - 1 | 0; + if (u === 0) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "U+0000 has no predecessor" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "U+0000 has no predecessor" - } - }); + return u - 1 | 0; } function is_valid(i) { diff --git a/lib/js/array.js b/lib/js/array.js index 5580be4143..9407d2ffc0 100644 --- a/lib/js/array.js +++ b/lib/js/array.js @@ -57,15 +57,15 @@ function append(a1, a2) { } function sub(a, ofs, len) { - if (!(ofs < 0 || len < 0 || ofs > (a.length - len | 0))) { - return Caml_array.sub(a, ofs, len); + if (ofs < 0 || len < 0 || ofs > (a.length - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Array.sub" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Array.sub" - } - }); + return Caml_array.sub(a, ofs, len); } function fill(a, ofs, len, v) { @@ -83,15 +83,15 @@ function fill(a, ofs, len, 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))) { - return Caml_array.blit(a1, ofs1, a2, ofs2, len); + if (len < 0 || ofs1 < 0 || ofs1 > (a1.length - len | 0) || ofs2 < 0 || ofs2 > (a2.length - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Array.blit" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Array.blit" - } - }); + Caml_array.blit(a1, ofs1, a2, ofs2, len); } function iter(f, a) { diff --git a/lib/js/arrayLabels.js b/lib/js/arrayLabels.js index 961b8f8729..c486cfe363 100644 --- a/lib/js/arrayLabels.js +++ b/lib/js/arrayLabels.js @@ -57,15 +57,15 @@ function append(a1, a2) { } function sub(a, ofs, len) { - if (!(ofs < 0 || len < 0 || ofs > (a.length - len | 0))) { - return Caml_array.sub(a, ofs, len); + if (ofs < 0 || len < 0 || ofs > (a.length - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Array.sub" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Array.sub" - } - }); + return Caml_array.sub(a, ofs, len); } function fill(a, ofs, len, v) { @@ -83,15 +83,15 @@ function fill(a, ofs, len, 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))) { - return Caml_array.blit(a1, ofs1, a2, ofs2, len); + if (len < 0 || ofs1 < 0 || ofs1 > (a1.length - len | 0) || ofs2 < 0 || ofs2 > (a2.length - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Array.blit" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Array.blit" - } - }); + Caml_array.blit(a1, ofs1, a2, ofs2, len); } function iter(f, a) { diff --git a/lib/js/belt_Array.js b/lib/js/belt_Array.js index 905ed7fa04..596da5e5c6 100644 --- a/lib/js/belt_Array.js +++ b/lib/js/belt_Array.js @@ -325,9 +325,9 @@ function flatMapU(a, f) { } function flatMap(a, f) { - return flatMapU(a, (function (a) { + return concatMany(mapU(a, (function (a) { return f(a); - })); + }))); } function getByU(a, p) { diff --git a/lib/js/belt_HashMapInt.js b/lib/js/belt_HashMapInt.js index 69e651f5a1..7c91e287d5 100644 --- a/lib/js/belt_HashMapInt.js +++ b/lib/js/belt_HashMapInt.js @@ -193,7 +193,7 @@ function size(h) { function fromArray(arr) { let len = arr.length; - let v = make(len); + let v = Belt_internalBucketsType.make(undefined, undefined, len); for(let i = 0; i < len; ++i){ let match = arr[i]; set(v, match[0], match[1]); diff --git a/lib/js/belt_HashMapString.js b/lib/js/belt_HashMapString.js index ee4a0d8f31..258b989a29 100644 --- a/lib/js/belt_HashMapString.js +++ b/lib/js/belt_HashMapString.js @@ -193,7 +193,7 @@ function size(h) { function fromArray(arr) { let len = arr.length; - let v = make(len); + let v = Belt_internalBucketsType.make(undefined, undefined, len); for(let i = 0; i < len; ++i){ let match = arr[i]; set(v, match[0], match[1]); diff --git a/lib/js/belt_Map.js b/lib/js/belt_Map.js index 3db312ce0c..dfbf259132 100644 --- a/lib/js/belt_Map.js +++ b/lib/js/belt_Map.js @@ -112,7 +112,7 @@ function findFirstByU(m, f) { } function findFirstBy(m, f) { - return findFirstByU(m, (function (a, b) { + return Belt_MapDict.findFirstByU(m.data, (function (a, b) { return f(a, b); })); } @@ -122,7 +122,7 @@ function forEachU(m, f) { } function forEach(m, f) { - forEachU(m, (function (a, b) { + Belt_MapDict.forEachU(m.data, (function (a, b) { f(a, b); })); } @@ -142,7 +142,7 @@ function everyU(m, f) { } function every(m, f) { - return everyU(m, (function (a, b) { + return Belt_MapDict.everyU(m.data, (function (a, b) { return f(a, b); })); } @@ -152,7 +152,7 @@ function someU(m, f) { } function some(m, f) { - return someU(m, (function (a, b) { + return Belt_MapDict.someU(m.data, (function (a, b) { return f(a, b); })); } diff --git a/lib/js/belt_MutableMap.js b/lib/js/belt_MutableMap.js index 13e20ff3c9..9da165b978 100644 --- a/lib/js/belt_MutableMap.js +++ b/lib/js/belt_MutableMap.js @@ -153,7 +153,8 @@ function clear(m) { } function isEmpty(d) { - return d.data === undefined; + let x = d.data; + return x === undefined; } function minKey(m) { @@ -193,7 +194,7 @@ function forEachU(d, f) { } function forEach(d, f) { - forEachU(d, (function (a, b) { + Belt_internalAVLtree.forEachU(d.data, (function (a, b) { f(a, b); })); } @@ -213,7 +214,7 @@ function everyU(d, p) { } function every(d, p) { - return everyU(d, (function (a, b) { + return Belt_internalAVLtree.everyU(d.data, (function (a, b) { return p(a, b); })); } @@ -223,7 +224,7 @@ function someU(d, p) { } function some(d, p) { - return someU(d, (function (a, b) { + return Belt_internalAVLtree.someU(d.data, (function (a, b) { return p(a, b); })); } diff --git a/lib/js/belt_MutableMapInt.js b/lib/js/belt_MutableMapInt.js index abc68b02b1..fed12a58e2 100644 --- a/lib/js/belt_MutableMapInt.js +++ b/lib/js/belt_MutableMapInt.js @@ -11,7 +11,8 @@ function make() { } function isEmpty(m) { - return m.data === undefined; + let x = m.data; + return x === undefined; } function clear(m) { @@ -65,7 +66,7 @@ function forEachU(d, f) { } function forEach(d, f) { - forEachU(d, (function (a, b) { + Belt_internalAVLtree.forEachU(d.data, (function (a, b) { f(a, b); })); } @@ -109,7 +110,7 @@ function everyU(d, f) { } function every(d, f) { - return everyU(d, (function (a, b) { + return Belt_internalAVLtree.everyU(d.data, (function (a, b) { return f(a, b); })); } @@ -119,7 +120,7 @@ function someU(d, f) { } function some(d, f) { - return someU(d, (function (a, b) { + return Belt_internalAVLtree.someU(d.data, (function (a, b) { return f(a, b); })); } diff --git a/lib/js/belt_MutableMapString.js b/lib/js/belt_MutableMapString.js index 0db5237044..50346ce2ce 100644 --- a/lib/js/belt_MutableMapString.js +++ b/lib/js/belt_MutableMapString.js @@ -11,7 +11,8 @@ function make() { } function isEmpty(m) { - return m.data === undefined; + let x = m.data; + return x === undefined; } function clear(m) { @@ -65,7 +66,7 @@ function forEachU(d, f) { } function forEach(d, f) { - forEachU(d, (function (a, b) { + Belt_internalAVLtree.forEachU(d.data, (function (a, b) { f(a, b); })); } @@ -109,7 +110,7 @@ function everyU(d, f) { } function every(d, f) { - return everyU(d, (function (a, b) { + return Belt_internalAVLtree.everyU(d.data, (function (a, b) { return f(a, b); })); } @@ -119,7 +120,7 @@ function someU(d, f) { } function some(d, f) { - return someU(d, (function (a, b) { + return Belt_internalAVLtree.someU(d.data, (function (a, b) { return f(a, b); })); } diff --git a/lib/js/belt_MutableSet.js b/lib/js/belt_MutableSet.js index 6b94e54528..bc44cafdd5 100644 --- a/lib/js/belt_MutableSet.js +++ b/lib/js/belt_MutableSet.js @@ -192,7 +192,8 @@ function make(id) { } function isEmpty(d) { - return d.data === undefined; + let n = d.data; + return n === undefined; } function minimum(d) { @@ -216,7 +217,7 @@ function forEachU(d, f) { } function forEach(d, f) { - forEachU(d, (function (a) { + Belt_internalAVLset.forEachU(d.data, (function (a) { f(a); })); } @@ -236,7 +237,7 @@ function everyU(d, p) { } function every(d, p) { - return everyU(d, (function (a) { + return Belt_internalAVLset.everyU(d.data, (function (a) { return p(a); })); } @@ -246,7 +247,7 @@ function someU(d, p) { } function some(d, p) { - return someU(d, (function (a) { + return Belt_internalAVLset.someU(d.data, (function (a) { return p(a); })); } diff --git a/lib/js/belt_MutableSetInt.js b/lib/js/belt_MutableSetInt.js index 691e015f3e..830f3b4e26 100644 --- a/lib/js/belt_MutableSetInt.js +++ b/lib/js/belt_MutableSetInt.js @@ -189,7 +189,8 @@ function make() { } function isEmpty(d) { - return d.data === undefined; + let n = d.data; + return n === undefined; } function minimum(d) { @@ -213,7 +214,7 @@ function forEachU(d, f) { } function forEach(d, f) { - forEachU(d, (function (a) { + Belt_internalAVLset.forEachU(d.data, (function (a) { f(a); })); } @@ -233,7 +234,7 @@ function everyU(d, p) { } function every(d, p) { - return everyU(d, (function (a) { + return Belt_internalAVLset.everyU(d.data, (function (a) { return p(a); })); } @@ -243,7 +244,7 @@ function someU(d, p) { } function some(d, p) { - return someU(d, (function (a) { + return Belt_internalAVLset.someU(d.data, (function (a) { return p(a); })); } diff --git a/lib/js/belt_MutableSetString.js b/lib/js/belt_MutableSetString.js index c13ba1c2dc..f7a1bbd568 100644 --- a/lib/js/belt_MutableSetString.js +++ b/lib/js/belt_MutableSetString.js @@ -189,7 +189,8 @@ function make() { } function isEmpty(d) { - return d.data === undefined; + let n = d.data; + return n === undefined; } function minimum(d) { @@ -213,7 +214,7 @@ function forEachU(d, f) { } function forEach(d, f) { - forEachU(d, (function (a) { + Belt_internalAVLset.forEachU(d.data, (function (a) { f(a); })); } @@ -233,7 +234,7 @@ function everyU(d, p) { } function every(d, p) { - return everyU(d, (function (a) { + return Belt_internalAVLset.everyU(d.data, (function (a) { return p(a); })); } @@ -243,7 +244,7 @@ function someU(d, p) { } function some(d, p) { - return someU(d, (function (a) { + return Belt_internalAVLset.someU(d.data, (function (a) { return p(a); })); } diff --git a/lib/js/belt_Set.js b/lib/js/belt_Set.js index f159790896..621ccdf2ef 100644 --- a/lib/js/belt_Set.js +++ b/lib/js/belt_Set.js @@ -127,7 +127,7 @@ function forEachU(m, f) { } function forEach(m, f) { - forEachU(m, (function (a) { + Belt_SetDict.forEachU(m.data, (function (a) { f(a); })); } @@ -147,7 +147,7 @@ function everyU(m, f) { } function every(m, f) { - return everyU(m, (function (a) { + return Belt_SetDict.everyU(m.data, (function (a) { return f(a); })); } @@ -157,7 +157,7 @@ function someU(m, f) { } function some(m, f) { - return someU(m, (function (a) { + return Belt_SetDict.someU(m.data, (function (a) { return f(a); })); } diff --git a/lib/js/belt_internalBuckets.js b/lib/js/belt_internalBuckets.js index 21423c0177..bde6492a04 100644 --- a/lib/js/belt_internalBuckets.js +++ b/lib/js/belt_internalBuckets.js @@ -3,19 +3,6 @@ let Belt_Array = require("./belt_Array.js"); let Caml_option = require("./caml_option.js"); -function copyBucket(c) { - if (c === undefined) { - return c; - } - let head = { - key: c.key, - value: c.value, - next: undefined - }; - copyAuxCont(c.next, head); - return head; -} - function copyAuxCont(_c, _prec) { while(true) { let prec = _prec; @@ -35,6 +22,19 @@ function copyAuxCont(_c, _prec) { }; } +function copyBucket(c) { + if (c === undefined) { + return c; + } + let head = { + key: c.key, + value: c.value, + next: undefined + }; + copyAuxCont(c.next, head); + return head; +} + function copyBuckets(buckets) { let len = buckets.length; let newBuckets = new Array(len); diff --git a/lib/js/buffer.js b/lib/js/buffer.js index 160c5a977f..1841872741 100644 --- a/lib/js/buffer.js +++ b/lib/js/buffer.js @@ -25,39 +25,39 @@ function to_bytes(b) { } function sub(b, ofs, len) { - if (!(ofs < 0 || len < 0 || ofs > (b.position - len | 0))) { - return Bytes.sub_string(b.buffer, ofs, len); + if (ofs < 0 || len < 0 || ofs > (b.position - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Buffer.sub" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Buffer.sub" - } - }); + 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))) { - return Bytes.blit(src.buffer, srcoff, dst, dstoff, len); + if (len < 0 || srcoff < 0 || srcoff > (src.position - len | 0) || dstoff < 0 || dstoff > (dst.length - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Buffer.blit" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Buffer.blit" - } - }); + Bytes.blit(src.buffer, srcoff, dst, dstoff, len); } function nth(b, ofs) { - if (!(ofs < 0 || ofs >= b.position)) { - return b.buffer[ofs]; + if (ofs < 0 || ofs >= b.position) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Buffer.nth" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Buffer.nth" - } - }); + return b.buffer[ofs]; } function length(b) { @@ -454,16 +454,15 @@ function add_substitute(b, f, s) { } function truncate(b, len) { - if (!(len < 0 || len > b.position)) { - b.position = len; - return; + if (len < 0 || len > b.position) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Buffer.truncate" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Buffer.truncate" - } - }); + b.position = len; } exports.create = create; diff --git a/lib/js/bytes.js b/lib/js/bytes.js index c8dd7b3cac..e1a49076b5 100644 --- a/lib/js/bytes.js +++ b/lib/js/bytes.js @@ -148,15 +148,15 @@ function $plus$plus(a, b) { if (match$1) { return c; } - if (!match$2) { - return c; + if (match$2) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Bytes.extend" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Bytes.extend" - } - }); + return c; } function extend(s, left, right) { @@ -179,55 +179,54 @@ function extend(s, left, right) { } function fill(s, ofs, len, c) { - if (!(ofs < 0 || len < 0 || ofs > (s.length - len | 0))) { - return unsafe_fill(s, ofs, len, c); + if (ofs < 0 || len < 0 || ofs > (s.length - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.fill / Bytes.fill" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.fill / Bytes.fill" - } - }); + 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))) { - return unsafe_blit(s1, ofs1, s2, ofs2, len); + if (len < 0 || ofs1 < 0 || ofs1 > (s1.length - len | 0) || ofs2 < 0 || ofs2 > (s2.length - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Bytes.blit" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Bytes.blit" - } - }); + 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))) { - 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; + if (len < 0 || ofs1 < 0 || ofs1 > (s1.length - len | 0) || ofs2 < 0 || ofs2 > (s2.length - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.blit / Bytes.blit_string" + } + }); + } + 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; } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.blit / Bytes.blit_string" - } - }); + 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) { @@ -530,28 +529,28 @@ function index_opt(s, c) { function index_from(s, i, c) { let l = s.length; - if (!(i < 0 || i > l)) { - return index_rec(s, l, i, c); + if (i < 0 || i > l) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.index_from / Bytes.index_from" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from / Bytes.index_from" - } - }); + return index_rec(s, l, i, c); } function index_from_opt(s, i, c) { let l = s.length; - if (!(i < 0 || i > l)) { - return index_rec_opt(s, l, i, c); + if (i < 0 || i > l) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.index_from_opt / Bytes.index_from_opt" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from_opt / Bytes.index_from_opt" - } - }); + return index_rec_opt(s, l, i, c); } function rindex_rec(s, _i, c) { @@ -577,15 +576,15 @@ function rindex(s, c) { } function rindex_from(s, i, c) { - if (!(i < -1 || i >= s.length)) { - return rindex_rec(s, i, c); + if (i < -1 || i >= s.length) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.rindex_from / Bytes.rindex_from" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from / Bytes.rindex_from" - } - }); + return rindex_rec(s, i, c); } function rindex_rec_opt(s, _i, c) { @@ -607,15 +606,15 @@ function rindex_opt(s, c) { } function rindex_from_opt(s, i, c) { - if (!(i < -1 || i >= s.length)) { - return rindex_rec_opt(s, i, c); + if (i < -1 || i >= s.length) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.rindex_from_opt / Bytes.rindex_from_opt" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from_opt / Bytes.rindex_from_opt" - } - }); + return rindex_rec_opt(s, i, c); } function contains_from(s, i, c) { diff --git a/lib/js/bytesLabels.js b/lib/js/bytesLabels.js index c8dd7b3cac..e1a49076b5 100644 --- a/lib/js/bytesLabels.js +++ b/lib/js/bytesLabels.js @@ -148,15 +148,15 @@ function $plus$plus(a, b) { if (match$1) { return c; } - if (!match$2) { - return c; + if (match$2) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Bytes.extend" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Bytes.extend" - } - }); + return c; } function extend(s, left, right) { @@ -179,55 +179,54 @@ function extend(s, left, right) { } function fill(s, ofs, len, c) { - if (!(ofs < 0 || len < 0 || ofs > (s.length - len | 0))) { - return unsafe_fill(s, ofs, len, c); + if (ofs < 0 || len < 0 || ofs > (s.length - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.fill / Bytes.fill" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.fill / Bytes.fill" - } - }); + 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))) { - return unsafe_blit(s1, ofs1, s2, ofs2, len); + if (len < 0 || ofs1 < 0 || ofs1 > (s1.length - len | 0) || ofs2 < 0 || ofs2 > (s2.length - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Bytes.blit" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Bytes.blit" - } - }); + 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))) { - 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; + if (len < 0 || ofs1 < 0 || ofs1 > (s1.length - len | 0) || ofs2 < 0 || ofs2 > (s2.length - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.blit / Bytes.blit_string" + } + }); + } + 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; } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.blit / Bytes.blit_string" - } - }); + 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) { @@ -530,28 +529,28 @@ function index_opt(s, c) { function index_from(s, i, c) { let l = s.length; - if (!(i < 0 || i > l)) { - return index_rec(s, l, i, c); + if (i < 0 || i > l) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.index_from / Bytes.index_from" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from / Bytes.index_from" - } - }); + return index_rec(s, l, i, c); } function index_from_opt(s, i, c) { let l = s.length; - if (!(i < 0 || i > l)) { - return index_rec_opt(s, l, i, c); + if (i < 0 || i > l) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.index_from_opt / Bytes.index_from_opt" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from_opt / Bytes.index_from_opt" - } - }); + return index_rec_opt(s, l, i, c); } function rindex_rec(s, _i, c) { @@ -577,15 +576,15 @@ function rindex(s, c) { } function rindex_from(s, i, c) { - if (!(i < -1 || i >= s.length)) { - return rindex_rec(s, i, c); + if (i < -1 || i >= s.length) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.rindex_from / Bytes.rindex_from" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from / Bytes.rindex_from" - } - }); + return rindex_rec(s, i, c); } function rindex_rec_opt(s, _i, c) { @@ -607,15 +606,15 @@ function rindex_opt(s, c) { } function rindex_from_opt(s, i, c) { - if (!(i < -1 || i >= s.length)) { - return rindex_rec_opt(s, i, c); + if (i < -1 || i >= s.length) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.rindex_from_opt / Bytes.rindex_from_opt" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from_opt / Bytes.rindex_from_opt" - } - }); + return rindex_rec_opt(s, i, c); } function contains_from(s, i, c) { diff --git a/lib/js/caml.js b/lib/js/caml.js index 15e8b80485..c3729dc091 100644 --- a/lib/js/caml.js +++ b/lib/js/caml.js @@ -166,10 +166,10 @@ function i64_le(x, y) { } function i64_min(x, y) { - if (i64_lt(x, y)) { - return x; - } else { + if (i64_ge(x, y)) { return y; + } else { + return x; } } diff --git a/lib/js/char.js b/lib/js/char.js index d4dd8308c7..2ae5bbaca9 100644 --- a/lib/js/char.js +++ b/lib/js/char.js @@ -3,15 +3,15 @@ let Bytes = require("./bytes.js"); function chr(n) { - if (!(n < 0 || n > 255)) { - return n; + if (n < 0 || n > 255) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Char.chr" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Char.chr" - } - }); + return n; } function escaped(param) { diff --git a/lib/js/digest.js b/lib/js/digest.js index d62b9b57a8..51307ddf23 100644 --- a/lib/js/digest.js +++ b/lib/js/digest.js @@ -16,15 +16,15 @@ function bytes(b) { } function substring(str, ofs, len) { - if (!(ofs < 0 || len < 0 || ofs > (str.length - len | 0))) { - return Caml_md5.md5_string(str, ofs, len); + if (ofs < 0 || len < 0 || ofs > (str.length - len | 0)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Digest.substring" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Digest.substring" - } - }); + return Caml_md5.md5_string(str, ofs, len); } function subbytes(b, ofs, len) { diff --git a/lib/js/filename.js b/lib/js/filename.js index 8b1245ba55..530e6fe8cf 100644 --- a/lib/js/filename.js +++ b/lib/js/filename.js @@ -1,6 +1,7 @@ '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"); @@ -193,7 +194,7 @@ function check_suffix$1(name, suff) { return false; } let s = $$String.sub(name, name.length - suff.length | 0, suff.length); - return $$String.lowercase_ascii(s) === $$String.lowercase_ascii(suff); + 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; @@ -382,15 +383,15 @@ function concat(dirname, filename) { function chop_suffix(name, suff) { let n = name.length - suff.length | 0; - if (n >= 0) { - return $$String.sub(name, 0, n); + if (n < 0) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Filename.chop_suffix" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Filename.chop_suffix" - } - }); + return $$String.sub(name, 0, n); } function extension_len(name) { @@ -430,15 +431,15 @@ function extension(name) { function chop_extension(name) { let l = extension_len(name); - if (l !== 0) { - return $$String.sub(name, 0, name.length - l | 0); + if (l === 0) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Filename.chop_extension" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Filename.chop_extension" - } - }); + return $$String.sub(name, 0, name.length - l | 0); } function remove_extension(name) { diff --git a/lib/js/genlex.js b/lib/js/genlex.js index d7603a2256..55f524893e 100644 --- a/lib/js/genlex.js +++ b/lib/js/genlex.js @@ -105,8 +105,8 @@ function make_lexer(keywords) { case 13 : case 26 : case 32 : - exit = 2; - break; + Stream.junk(strm__); + continue; case 34 : Stream.junk(strm__); reset_buffer(); @@ -175,10 +175,11 @@ function make_lexer(keywords) { store(/* '-' */45); store(c$2); return number(strm__); + } else { + reset_buffer(); + store(/* '-' */45); + return ident2(strm__); } - reset_buffer(); - store(/* '-' */45); - return ident2(strm__); case 48 : case 49 : case 50 : @@ -189,7 +190,7 @@ function make_lexer(keywords) { case 55 : case 56 : case 57 : - exit = 5; + exit = 4; break; case 0 : case 1 : @@ -238,7 +239,7 @@ function make_lexer(keywords) { case 62 : case 63 : case 64 : - exit = 4; + exit = 3; break; } @@ -247,7 +248,7 @@ function make_lexer(keywords) { switch (c) { case 92 : case 94 : - exit = 4; + exit = 3; break; case 91 : case 93 : @@ -255,14 +256,14 @@ function make_lexer(keywords) { exit = 1; break; default: - exit = 3; + exit = 2; } } } else { exit = c >= 127 ? ( - c > 255 || c < 192 ? 1 : 3 + c > 255 || c < 192 ? 1 : 2 ) : ( - c !== 125 ? 4 : 1 + c !== 125 ? 3 : 1 ); } switch (exit) { @@ -270,49 +271,42 @@ function make_lexer(keywords) { Stream.junk(strm__); return keyword_or_error(c); case 2 : - Stream.junk(strm__); - continue; - case 3 : Stream.junk(strm__); reset_buffer(); store(c); while(true) { let c$3 = Stream.peek(strm__); - if (c$3 !== undefined) { - let exit$1 = 0; - if (c$3 >= 91) { - if (c$3 > 122 || c$3 < 95) { - if (!(c$3 > 255 || c$3 < 192)) { - exit$1 = 2; - } - - } else if (c$3 !== 96) { - exit$1 = 2; - } - - } else if (c$3 >= 48) { - if (c$3 > 64 || c$3 < 58) { - exit$1 = 2; + 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 === 39) { - exit$1 = 2; + } else if (c$3 === 96) { + return ident_or_keyword(get_string()); } - if (exit$1 === 2) { - Stream.junk(strm__); - store(c$3); - continue; + + } 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()); } - return ident_or_keyword(get_string()); + Stream.junk(strm__); + store(c$3); + continue; }; - case 4 : + case 3 : Stream.junk(strm__); reset_buffer(); store(c); return ident2(strm__); - case 5 : + case 4 : Stream.junk(strm__); reset_buffer(); store(c); @@ -324,81 +318,80 @@ function make_lexer(keywords) { let ident2 = function (strm__) { while(true) { let c = Stream.peek(strm__); - if (c !== undefined) { - let exit = 0; - if (c >= 94) { - if (c > 125 || c < 95) { - if (c < 127) { - exit = 2; - } - - } else if (c === 124) { - exit = 2; - } - - } else if (c >= 65) { - if (c === 92) { - exit = 2; + 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 >= 33) { - 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 : - break; - 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 : - exit = 2; - break; - - } + } else if (c !== 124) { + return ident_or_keyword(get_string()); } - if (exit === 2) { - Stream.junk(strm__); - store(c); - continue; + + } 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; + + } } - return ident_or_keyword(get_string()); + Stream.junk(strm__); + store(c); + continue; }; }; let number = function (strm__) { while(true) { let c = Stream.peek(strm__); if (c !== undefined) { - let exit = 0; if (c >= 58) { if (!(c !== 69 && c !== 101)) { - exit = 2; + Stream.junk(strm__); + store(/* 'E' */69); + return exponent_part(strm__); } } else if (c !== 46) { @@ -434,12 +427,6 @@ function make_lexer(keywords) { }; }; } - if (exit === 2) { - Stream.junk(strm__); - store(/* 'E' */69); - return exponent_part(strm__); - } - } return { TAG: "Int", @@ -449,15 +436,13 @@ function make_lexer(keywords) { }; let exponent_part = function (strm__) { let c = Stream.peek(strm__); - if (c === undefined) { + if (c !== undefined && !(c !== 43 && c !== 45)) { + Stream.junk(strm__); + store(c); return end_exponent_part(strm__); - } - if (c !== 43 && c !== 45) { + } else { return end_exponent_part(strm__); } - Stream.junk(strm__); - store(c); - return end_exponent_part(strm__); }; let end_exponent_part = function (strm__) { while(true) { @@ -690,4 +675,4 @@ function make_lexer(keywords) { } exports.make_lexer = make_lexer; -/* Hashtbl Not a pure module */ +/* No side effect */ diff --git a/lib/js/hashtbl.js b/lib/js/hashtbl.js index e06bff9294..e882bc97c2 100644 --- a/lib/js/hashtbl.js +++ b/lib/js/hashtbl.js @@ -1,7 +1,6 @@ 'use strict'; let Caml = require("./caml.js"); -let Lazy = require("./lazy.js"); let $$Array = require("./array.js"); let Random = require("./random.js"); let Caml_obj = require("./caml_obj.js"); @@ -39,7 +38,7 @@ function is_randomized() { return randomized.contents; } -let prng = Lazy.from_fun(function () { +let prng = CamlinternalLazy.from_fun(function () { return Random.State.make_self_init(); }); @@ -1140,4 +1139,4 @@ exports.hash = hash; exports.seeded_hash = seeded_hash; exports.hash_param = hash_param; exports.seeded_hash_param = seeded_hash_param; -/* prng Not a pure module */ +/* No side effect */ diff --git a/lib/js/hashtblLabels.js b/lib/js/hashtblLabels.js index 57c37b4f41..6aa7894bbb 100644 --- a/lib/js/hashtblLabels.js +++ b/lib/js/hashtblLabels.js @@ -194,4 +194,4 @@ exports.filter_map_inplace = filter_map_inplace; exports.fold = fold; exports.MakeSeeded = MakeSeeded; exports.Make = Make; -/* Hashtbl Not a pure module */ +/* No side effect */ diff --git a/lib/js/js.js b/lib/js/js.js index 78030e36c4..de368b57e7 100644 --- a/lib/js/js.js +++ b/lib/js/js.js @@ -1,8 +1,6 @@ 'use strict'; -let Internal = {}; - let Null; let Undefined; @@ -69,7 +67,6 @@ let $$Map; let $$WeakMap; -exports.Internal = Internal; exports.Null = Null; exports.Undefined = Undefined; exports.Nullable = Nullable; diff --git a/lib/js/lazy.js b/lib/js/lazy.js index 30aefe8c5e..fe1b4b9d8b 100644 --- a/lib/js/lazy.js +++ b/lib/js/lazy.js @@ -8,9 +8,7 @@ function from_fun(f) { }); } -function from_val(v) { - return CamlinternalLazy.from_val(v); -} +let from_val = CamlinternalLazy.from_val; let Undefined = CamlinternalLazy.Undefined; diff --git a/lib/js/list.js b/lib/js/list.js index 436c025ee2..033c5376c2 100644 --- a/lib/js/list.js +++ b/lib/js/list.js @@ -155,19 +155,19 @@ function init_aux(i, n, f) { } function init(len, f) { - if (len >= 0) { - if (len > 10000) { - return rev_append(init_tailrec_aux(/* [] */0, 0, len, f), /* [] */0); - } else { - return init_aux(0, len, f); - } + if (len < 0) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "List.init" + } + }); + } + if (len > 10000) { + return rev_append(init_tailrec_aux(/* [] */0, 0, len, f), /* [] */0); + } else { + return init_aux(0, len, f); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.init" - } - }); } function flatten(param) { @@ -323,15 +323,15 @@ function rev_map2(f, l1, l2) { } }); } - if (!l2$1) { - return accu; + if (l2$1) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "List.rev_map2" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.rev_map2" - } - }); + return accu; }; } @@ -384,15 +384,15 @@ function fold_left2(f, _accu, _l1, _l2) { } }); } - if (!l2) { - return accu; + if (l2) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "List.fold_left2" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_left2" - } - }); + return accu; }; } @@ -408,15 +408,15 @@ function fold_right2(f, l1, l2, accu) { } }); } - if (!l2) { - return accu; + if (l2) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "List.fold_right2" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_right2" - } - }); + return accu; } function for_all(p, _param) { diff --git a/lib/js/listLabels.js b/lib/js/listLabels.js index 6f81e7afde..287a2c0f3a 100644 --- a/lib/js/listLabels.js +++ b/lib/js/listLabels.js @@ -155,19 +155,19 @@ function init_aux(i, n, f) { } function init(len, f) { - if (len >= 0) { - if (len > 10000) { - return rev_append(init_tailrec_aux(/* [] */0, 0, len, f), /* [] */0); - } else { - return init_aux(0, len, f); - } + if (len < 0) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "List.init" + } + }); + } + if (len > 10000) { + return rev_append(init_tailrec_aux(/* [] */0, 0, len, f), /* [] */0); + } else { + return init_aux(0, len, f); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.init" - } - }); } function flatten(param) { @@ -323,15 +323,15 @@ function rev_map2(f, l1, l2) { } }); } - if (!l2$1) { - return accu; + if (l2$1) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "List.rev_map2" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.rev_map2" - } - }); + return accu; }; } @@ -384,15 +384,15 @@ function fold_left2(f, _accu, _l1, _l2) { } }); } - if (!l2) { - return accu; + if (l2) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "List.fold_left2" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_left2" - } - }); + return accu; }; } @@ -408,15 +408,15 @@ function fold_right2(f, l1, l2, accu) { } }); } - if (!l2) { - return accu; + if (l2) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "List.fold_right2" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "List.fold_right2" - } - }); + return accu; } function for_all(p, _param) { diff --git a/lib/js/moreLabels.js b/lib/js/moreLabels.js index aec5317d26..baee384c01 100644 --- a/lib/js/moreLabels.js +++ b/lib/js/moreLabels.js @@ -1975,4 +1975,4 @@ let $$Set = { exports.Hashtbl = Hashtbl; exports.$$Map = $$Map; exports.$$Set = $$Set; -/* HashtblLabels Not a pure module */ +/* No side effect */ diff --git a/lib/js/pervasives.js b/lib/js/pervasives.js index 851b6b0782..f849b7806a 100644 --- a/lib/js/pervasives.js +++ b/lib/js/pervasives.js @@ -185,7 +185,7 @@ function print_int(i) { } function print_float(i) { - console.log(string_of_float(i)); + console.log(valid_float_lexem(Caml_format.format_float("%.12g", i))); } function print_string(prim) { diff --git a/lib/js/random.js b/lib/js/random.js index 68552595f8..bf7a70c1b7 100644 --- a/lib/js/random.js +++ b/lib/js/random.js @@ -74,65 +74,65 @@ function bits(s) { } function int(s, bound) { - if (!(bound > 1073741823 || bound <= 0)) { - while(true) { - let r = bits(s); - let v = r % bound; - if ((r - v | 0) <= ((1073741823 - bound | 0) + 1 | 0)) { - return v; - } - continue; - }; + if (bound > 1073741823 || bound <= 0) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Random.int" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Random.int" - } - }); + 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) { - 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; - }; + if (bound <= 0) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Random.int32" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Random.int32" - } - }); + 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)) { - 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; - }; + if (Caml.i64_le(bound, Caml_int64.zero)) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "Random.int64" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "Random.int64" - } - }); + 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) { @@ -227,7 +227,7 @@ function int64$1(bound) { } function float$1(scale) { - return float($$default, scale); + return rawfloat($$default) * scale; } function bool$1() { diff --git a/lib/js/stream.js b/lib/js/stream.js index 8912267e9e..2ee0c6b4be 100644 --- a/lib/js/stream.js +++ b/lib/js/stream.js @@ -1,6 +1,5 @@ 'use strict'; -let Lazy = require("./lazy.js"); let List = require("./list.js"); let Caml_bytes = require("./caml_bytes.js"); let Caml_option = require("./caml_option.js"); @@ -362,32 +361,38 @@ function ising(i) { } function lapp(f, s) { + let f$1 = function () { + return { + TAG: "Sapp", + _0: data(f()), + _1: data(s) + }; + }; return { count: 0, data: { TAG: "Slazy", - _0: Lazy.from_fun(function () { - return { - TAG: "Sapp", - _0: data(f()), - _1: data(s) - }; + _0: CamlinternalLazy.from_fun(function () { + return f$1(); }) } }; } function lcons(f, s) { + let f$1 = function () { + return { + TAG: "Scons", + _0: f(), + _1: data(s) + }; + }; return { count: 0, data: { TAG: "Slazy", - _0: Lazy.from_fun(function () { - return { - TAG: "Scons", - _0: f(), - _1: data(s) - }; + _0: CamlinternalLazy.from_fun(function () { + return f$1(); }) } }; @@ -398,7 +403,7 @@ function lsing(f) { count: 0, data: { TAG: "Slazy", - _0: Lazy.from_fun(function () { + _0: CamlinternalLazy.from_fun(function () { return { TAG: "Scons", _0: f(), @@ -414,7 +419,7 @@ function slazy(f) { count: 0, data: { TAG: "Slazy", - _0: Lazy.from_fun(function () { + _0: CamlinternalLazy.from_fun(function () { return data(f()); }) } diff --git a/lib/js/string.js b/lib/js/string.js index 75ba5054f7..e26e35272b 100644 --- a/lib/js/string.js +++ b/lib/js/string.js @@ -128,28 +128,28 @@ function index_opt(s, c) { function index_from(s, i, c) { let l = s.length; - if (!(i < 0 || i > l)) { - return index_rec(s, l, i, c); + if (i < 0 || i > l) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.index_from / Bytes.index_from" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from / Bytes.index_from" - } - }); + return index_rec(s, l, i, c); } function index_from_opt(s, i, c) { let l = s.length; - if (!(i < 0 || i > l)) { - return index_rec_opt(s, l, i, c); + if (i < 0 || i > l) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.index_from_opt / Bytes.index_from_opt" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from_opt / Bytes.index_from_opt" - } - }); + return index_rec_opt(s, l, i, c); } function rindex_rec(s, _i, c) { @@ -175,15 +175,15 @@ function rindex(s, c) { } function rindex_from(s, i, c) { - if (!(i < -1 || i >= s.length)) { - return rindex_rec(s, i, c); + if (i < -1 || i >= s.length) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.rindex_from / Bytes.rindex_from" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from / Bytes.rindex_from" - } - }); + return rindex_rec(s, i, c); } function rindex_rec_opt(s, _i, c) { @@ -205,15 +205,15 @@ function rindex_opt(s, c) { } function rindex_from_opt(s, i, c) { - if (!(i < -1 || i >= s.length)) { - return rindex_rec_opt(s, i, c); + if (i < -1 || i >= s.length) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.rindex_from_opt / Bytes.rindex_from_opt" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from_opt / Bytes.rindex_from_opt" - } - }); + return rindex_rec_opt(s, i, c); } function contains_from(s, i, c) { diff --git a/lib/js/stringLabels.js b/lib/js/stringLabels.js index af81310fe7..66077dc73c 100644 --- a/lib/js/stringLabels.js +++ b/lib/js/stringLabels.js @@ -14,9 +14,7 @@ function sub(s, ofs, len) { return Bytes.unsafe_to_string(Bytes.sub(Bytes.unsafe_of_string(s), ofs, len)); } -function blit(src, src_pos, dst, dst_pos, len) { - Bytes.blit_string(src, src_pos, dst, dst_pos, len); -} +let blit = Bytes.blit_string; function concat(sep, xs) { return $$Array.of_list(xs).join(sep); @@ -132,28 +130,28 @@ function index_opt(s, c) { function index_from(s, i, c) { let l = s.length; - if (!(i < 0 || i > l)) { - return index_rec(s, l, i, c); + if (i < 0 || i > l) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.index_from / Bytes.index_from" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from / Bytes.index_from" - } - }); + return index_rec(s, l, i, c); } function index_from_opt(s, i, c) { let l = s.length; - if (!(i < 0 || i > l)) { - return index_rec_opt(s, l, i, c); + if (i < 0 || i > l) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.index_from_opt / Bytes.index_from_opt" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.index_from_opt / Bytes.index_from_opt" - } - }); + return index_rec_opt(s, l, i, c); } function rindex_rec(s, _i, c) { @@ -179,15 +177,15 @@ function rindex(s, c) { } function rindex_from(s, i, c) { - if (!(i < -1 || i >= s.length)) { - return rindex_rec(s, i, c); + if (i < -1 || i >= s.length) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.rindex_from / Bytes.rindex_from" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from / Bytes.rindex_from" - } - }); + return rindex_rec(s, i, c); } function rindex_rec_opt(s, _i, c) { @@ -209,15 +207,15 @@ function rindex_opt(s, c) { } function rindex_from_opt(s, i, c) { - if (!(i < -1 || i >= s.length)) { - return rindex_rec_opt(s, i, c); + if (i < -1 || i >= s.length) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "String.rindex_from_opt / Bytes.rindex_from_opt" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "String.rindex_from_opt / Bytes.rindex_from_opt" - } - }); + return rindex_rec_opt(s, i, c); } function contains_from(s, i, c) { diff --git a/lib/js/sys.js b/lib/js/sys.js index 8239622f87..48a03282b9 100644 --- a/lib/js/sys.js +++ b/lib/js/sys.js @@ -45,20 +45,7 @@ function set_signal(sig_num, sig_beh) { let Break = /* @__PURE__ */Caml_exceptions.create("Sys.Break"); function catch_break(on) { - if (on) { - return set_signal(-6, { - TAG: "Signal_handle", - _0: (function (param) { - throw new Error(Break, { - cause: { - RE_EXN_ID: Break - } - }); - }) - }); - } else { - return set_signal(-6, "Signal_default"); - } + } function enable_runtime_warnings(param) { diff --git a/lib/js/uchar.js b/lib/js/uchar.js index 27e3a6e7ac..87523c8fb6 100644 --- a/lib/js/uchar.js +++ b/lib/js/uchar.js @@ -15,30 +15,30 @@ function succ(u) { if (u === 55295) { return 57344; } - if (u !== 1114111) { - return u + 1 | 0; + if (u === 1114111) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "U+10FFFF has no successor" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "U+10FFFF has no successor" - } - }); + return u + 1 | 0; } function pred(u) { if (u === 57344) { return 55295; } - if (u !== 0) { - return u - 1 | 0; + if (u === 0) { + throw new Error("Invalid_argument", { + cause: { + RE_EXN_ID: "Invalid_argument", + _1: "U+0000 has no predecessor" + } + }); } - throw new Error("Invalid_argument", { - cause: { - RE_EXN_ID: "Invalid_argument", - _1: "U+0000 has no predecessor" - } - }); + return u - 1 | 0; } function is_valid(i) {