diff --git a/jscomp/js_config.ml b/jscomp/js_config.ml index 8e933328d7..93167bcd95 100644 --- a/jscomp/js_config.ml +++ b/jscomp/js_config.ml @@ -146,7 +146,7 @@ let runtime_set = String_set.of_list [ let prim = "Caml_primitive" let builtin_exceptions = "Caml_builtin_exceptions" - +let exceptions = "Caml_exceptions" let io = "Caml_io" diff --git a/jscomp/js_config.mli b/jscomp/js_config.mli index 8e455ac62a..67803e6f7f 100644 --- a/jscomp/js_config.mli +++ b/jscomp/js_config.mli @@ -37,7 +37,7 @@ val stdlib_set : String_set.t val prim : string val builtin_exceptions : string - +val exceptions : string val io : string val oo : string diff --git a/jscomp/js_of_lam_exception.ml b/jscomp/js_of_lam_exception.ml index 740e9cc774..b67258015f 100644 --- a/jscomp/js_of_lam_exception.ml +++ b/jscomp/js_of_lam_exception.ml @@ -39,20 +39,15 @@ let match_exception_def (args : J.expression list) = None | _ -> None -(* Sync up with [caml_set_oo_id] *) +(* Sync up with [caml_set_oo_id] + Note if we inline {!Caml_exceptions.create}, + it seems can be useful for optimizations in theory, + in practice, it never happen, since the pattern match + never dig into it internally, so maybe {!Obj.set_tag} + is not necessary at all +*) let make_exception exception_str mutable_flag : J.expression = - { expression_desc = - Caml_block ( - [exception_str ; - E.runtime_call Js_config.builtin_exceptions "get_id" [] - ], - mutable_flag, - (* TODO: combined with `_001` optimization *) - E.obj_int_tag_literal (* (Obj.object_tag) *), - Blk_na - ); - comment = None - } + E.runtime_call Js_config.exceptions Literals.create [exception_str] @@ -70,5 +65,5 @@ let caml_set_oo_id args = If we can guarantee this code path is never hit, we can do a better job for encoding of exception and extension? *) - E.runtime_call Js_config.builtin_exceptions "caml_set_oo_id" args + E.runtime_call Js_config.exceptions "caml_set_oo_id" args end diff --git a/jscomp/literals.ml b/jscomp/literals.ml index 126e18b482..3e9a7bd709 100644 --- a/jscomp/literals.ml +++ b/jscomp/literals.ml @@ -30,3 +30,5 @@ let prim = "prim" let param = "param" let partial_arg = "partial_arg" let tmp = "tmp" + +let create = "create" (* {!Caml_exceptions.create}*) diff --git a/jscomp/literals.mli b/jscomp/literals.mli index df0cb036db..f3045aebcd 100644 --- a/jscomp/literals.mli +++ b/jscomp/literals.mli @@ -31,3 +31,5 @@ val prim : string (**temporary varaible used in {!Js_ast_util} *) val tmp : string + +val create : string diff --git a/jscomp/runtime/.depend b/jscomp/runtime/.depend index 70b3df2c7e..99e2ae35fa 100644 --- a/jscomp/runtime/.depend +++ b/jscomp/runtime/.depend @@ -1,6 +1,7 @@ caml_array.cmi : caml_bigarray.cmi : caml_builtin_exceptions.cmi : +caml_exceptions.cmi : caml_builtin_exceptions.cmi caml_float.cmi : caml_format.cmi : caml_hash.cmi : @@ -23,6 +24,8 @@ caml_builtin_exceptions.cmo : caml_builtin_exceptions.cmi caml_builtin_exceptions.cmx : caml_builtin_exceptions.cmi caml_curry.cmo : js.cmo caml_oo.cmi caml_curry.cmx : js.cmx caml_oo.cmx +caml_exceptions.cmo : caml_builtin_exceptions.cmi caml_exceptions.cmi +caml_exceptions.cmx : caml_builtin_exceptions.cmx caml_exceptions.cmi caml_float.cmo : typed_array.cmo js.cmo caml_float.cmi caml_float.cmx : typed_array.cmx js.cmx caml_float.cmi caml_format.cmo : js.cmo caml_utils.cmi caml_format.cmi @@ -69,6 +72,8 @@ caml_builtin_exceptions.cmo : caml_builtin_exceptions.cmi caml_builtin_exceptions.cmj : caml_builtin_exceptions.cmi caml_curry.cmo : js.cmo caml_oo.cmi caml_curry.cmj : js.cmj caml_oo.cmj +caml_exceptions.cmo : caml_builtin_exceptions.cmi caml_exceptions.cmi +caml_exceptions.cmj : caml_builtin_exceptions.cmj caml_exceptions.cmi caml_float.cmo : typed_array.cmo js.cmo caml_float.cmi caml_float.cmj : typed_array.cmj js.cmj caml_float.cmi caml_format.cmo : js.cmo caml_utils.cmi caml_format.cmi diff --git a/jscomp/runtime/caml_builtin_exceptions.js b/jscomp/runtime/caml_builtin_exceptions.js index 10fe3322b1..39f578692b 100644 --- a/jscomp/runtime/caml_builtin_exceptions.js +++ b/jscomp/runtime/caml_builtin_exceptions.js @@ -2,87 +2,62 @@ 'use strict'; -var id = [0]; - -function caml_set_oo_id(b) { - b[1] = id[0]; - id[0] += 1; - return b; -} - -function get_id() { - id[0] += 1; - return id[0]; -} - var out_of_memory = /* tuple */[ - 248, "Out_of_memory", 0 ]; var sys_error = /* tuple */[ - 248, "Sys_error", -1 ]; var failure = /* tuple */[ - 248, "Failure", -2 ]; var invalid_argument = /* tuple */[ - 248, "Invalid_argument", -3 ]; var end_of_file = /* tuple */[ - 248, "End_of_file", -4 ]; var division_by_zero = /* tuple */[ - 248, "Division_by_zero", -5 ]; var not_found = /* tuple */[ - 248, "Not_found", -6 ]; var match_failure = /* tuple */[ - 248, "Match_failure", -7 ]; var stack_overflow = /* tuple */[ - 248, "Stack_overflow", -8 ]; var sys_blocked_io = /* tuple */[ - 248, "Sys_blocked_io", -9 ]; var assert_failure = /* tuple */[ - 248, "Assert_failure", -10 ]; var undefined_recursive_module = /* tuple */[ - 248, "Undefined_recursive_module", -11 ]; @@ -99,6 +74,4 @@ exports.stack_overflow = stack_overflow; exports.sys_blocked_io = sys_blocked_io; exports.assert_failure = assert_failure; exports.undefined_recursive_module = undefined_recursive_module; -exports.caml_set_oo_id = caml_set_oo_id; -exports.get_id = get_id; /* No side effect */ diff --git a/jscomp/runtime/caml_builtin_exceptions.ml b/jscomp/runtime/caml_builtin_exceptions.ml index 92799b88a9..41ac6000a3 100644 --- a/jscomp/runtime/caml_builtin_exceptions.ml +++ b/jscomp/runtime/caml_builtin_exceptions.ml @@ -18,43 +18,23 @@ (* Author: Hongbo Zhang *) -type exception_block = int * string * int -let out_of_memory = 248, "Out_of_memory", 0 -let sys_error = 248, "Sys_error", -1 -let failure = 248, "Failure", -2 -let invalid_argument = 248, "Invalid_argument", -3 -let end_of_file = 248, "End_of_file",-4 -let division_by_zero = 248, "Division_by_zero", -5 -let not_found = 248, "Not_found", -6 -let match_failure = 248, "Match_failure", -7 -let stack_overflow = 248, "Stack_overflow",-8 -let sys_blocked_io = 248, "Sys_blocked_io", -9 -let assert_failure = 248, "Assert_failure", -10 -let undefined_recursive_module = 248, "Undefined_recursive_module", -11 - - - -(* Exported for better inlining *) -(* It's common that we have a = caml_set_oo_id([248,"string",0]) *) -(* This can be inlined as a = caml_set_oo_id([248,"tag", caml_oo_last_id++]) *) - (* @type {number} *) - -let id = ref 0n - - -(* see #251 - {[ - CAMLprim value caml_set_oo_id (value obj) { - Field(obj, 1) = oo_last_id; - oo_last_id += 2; - return obj; - } - - ]}*) -let caml_set_oo_id (b : exception_block) = - Obj.set_field (Obj.repr b) 1 (Obj.repr !id); - id := Nativeint.add !id 1n; - b - -let get_id () = - id := Nativeint.add !id 1n; !id +type exception_block = string * nativeint + + +let out_of_memory = "Out_of_memory", 0n +let sys_error = "Sys_error", -1n +let failure = "Failure", -2n +let invalid_argument = "Invalid_argument", -3n +let end_of_file = "End_of_file",-4n +let division_by_zero = "Division_by_zero", -5n +let not_found = "Not_found", -6n +let match_failure = "Match_failure", -7n +let stack_overflow = "Stack_overflow",-8n +let sys_blocked_io = "Sys_blocked_io", -9n +let assert_failure = "Assert_failure", -10n +let undefined_recursive_module = "Undefined_recursive_module", -11n + +(* TODO: + 1. is it necessary to tag [248] here + 2. is it okay to remove the negative value +*) diff --git a/jscomp/runtime/caml_builtin_exceptions.mli b/jscomp/runtime/caml_builtin_exceptions.mli index 95ced5fe03..b03b74718b 100644 --- a/jscomp/runtime/caml_builtin_exceptions.mli +++ b/jscomp/runtime/caml_builtin_exceptions.mli @@ -1,4 +1,4 @@ -type exception_block = int * string * int +type exception_block = string * nativeint val out_of_memory : exception_block val sys_error : exception_block val failure : exception_block @@ -12,6 +12,5 @@ val sys_blocked_io : exception_block val assert_failure : exception_block val undefined_recursive_module : exception_block -val caml_set_oo_id : exception_block -> exception_block -val get_id : unit -> nativeint + diff --git a/jscomp/runtime/caml_exceptions.js b/jscomp/runtime/caml_exceptions.js index c55c31c6b0..3680da98a5 100644 --- a/jscomp/runtime/caml_exceptions.js +++ b/jscomp/runtime/caml_exceptions.js @@ -1,56 +1,31 @@ // Generated CODE, PLEASE EDIT WITH CARE 'use strict'; -var Caml_builtin_exceptions = require("./caml_builtin_exceptions"); -function caml_raise_sys_error(msg) { - throw [ - Caml_builtin_exceptions.sys_error, - msg - ]; -} - -function caml_failwith(s) { - throw [ - Caml_builtin_exceptions.failure, - s - ]; -} - -function caml_invalid_argument(s) { - throw [ - Caml_builtin_exceptions.invalid_argument, - s - ]; -} - -function caml_array_bound_error() { - throw [ - Caml_builtin_exceptions.invalid_argument, - "index out of bounds" - ]; -} +var id = [0]; -function caml_raise_zero_divide() { - throw Caml_builtin_exceptions.division_by_zero; +function caml_set_oo_id(b) { + b[1] = id[0]; + id[0] += 1; + return b; } -function caml_raise_not_found() { - throw Caml_builtin_exceptions.not_found; +function get_id() { + id[0] += 1; + return id[0]; } -function caml_undef_module(loc) { - throw [ - Caml_builtin_exceptions.undefined_recursive_module, - loc - ]; +function create(str) { + var v_001 = get_id(/* () */0); + var v = /* tuple */[ + str, + v_001 + ]; + v.tag = 248; + return v; } -exports.caml_raise_sys_error = caml_raise_sys_error; -exports.caml_failwith = caml_failwith; -exports.caml_invalid_argument = caml_invalid_argument; -exports.caml_array_bound_error = caml_array_bound_error; -exports.caml_raise_zero_divide = caml_raise_zero_divide; -exports.caml_raise_not_found = caml_raise_not_found; -exports.caml_undef_module = caml_undef_module; +exports.caml_set_oo_id = caml_set_oo_id; +exports.get_id = get_id; +exports.create = create; /* No side effect */ diff --git a/jscomp/runtime/caml_exceptions.ml b/jscomp/runtime/caml_exceptions.ml new file mode 100644 index 0000000000..0ed32cd981 --- /dev/null +++ b/jscomp/runtime/caml_exceptions.ml @@ -0,0 +1,52 @@ +(* BuckleScript compiler + * Copyright (C) 2015-2016 Bloomberg Finance L.P. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, with linking exception; + * either version 2.1 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *) + +(* Author: Hongbo Zhang *) + +(** + Could be exported for better inlining + It's common that we have + {[ a = caml_set_oo_id([248,"string",0]) ]} + This can be inlined as + {[ a = caml_set_oo_id([248,"tag", caml_oo_last_id++]) ]} +*) + +let id = ref 0n + + +(* see #251 + {[ + CAMLprim value caml_set_oo_id (value obj) { + Field(obj, 1) = oo_last_id; + oo_last_id += 2; + return obj; + } + + ]}*) +let caml_set_oo_id (b : Caml_builtin_exceptions.exception_block) = + Obj.set_field (Obj.repr b) 1 (Obj.repr !id); + id := Nativeint.add !id 1n; + b + +let get_id () = + id := Nativeint.add !id 1n; !id + +let create (str : string) : Caml_builtin_exceptions.exception_block = + let v = ( str, get_id ()) in + Obj.set_tag (Obj.repr v) 248 (* Obj.object_tag*); + v diff --git a/jscomp/runtime/caml_exceptions.mli b/jscomp/runtime/caml_exceptions.mli new file mode 100644 index 0000000000..decac8faa4 --- /dev/null +++ b/jscomp/runtime/caml_exceptions.mli @@ -0,0 +1,27 @@ +(* BuckleScript compiler + * Copyright (C) 2015-2016 Bloomberg Finance L.P. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, with linking exception; + * either version 2.1 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *) + +(* Author: Hongbo Zhang *) + + +val caml_set_oo_id : + Caml_builtin_exceptions.exception_block -> Caml_builtin_exceptions.exception_block + +val get_id : unit -> nativeint + +val create : string -> Caml_builtin_exceptions.exception_block diff --git a/jscomp/runtime/runtime.mllib b/jscomp/runtime/runtime.mllib index b901a85033..b2eec47125 100644 --- a/jscomp/runtime/runtime.mllib +++ b/jscomp/runtime/runtime.mllib @@ -5,6 +5,7 @@ caml_oo caml_obj caml_int64 caml_builtin_exceptions +caml_exceptions caml_utils caml_sys caml_io diff --git a/jscomp/stdlib/arg.js b/jscomp/stdlib/arg.js index cb7917d1a1..21b7ef0e9f 100644 --- a/jscomp/stdlib/arg.js +++ b/jscomp/stdlib/arg.js @@ -1,9 +1,10 @@ // Generated CODE, PLEASE EDIT WITH CARE 'use strict'; -var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); var Caml_obj = require("../runtime/caml_obj"); +var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); var Bytes = require("./bytes"); +var Caml_exceptions = require("../runtime/caml_exceptions"); var Pervasives = require("./pervasives"); var Caml_format = require("../runtime/caml_format"); var Sys = require("./sys"); @@ -14,26 +15,11 @@ var $$String = require("./string"); var List = require("./list"); var Caml_string = require("../runtime/caml_string"); -var Bad = { - 0: "Arg.Bad", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Bad = Caml_exceptions.create("Arg.Bad"); -var Help = { - 0: "Arg.Help", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Help = Caml_exceptions.create("Arg.Help"); -var Stop = { - 0: "Arg.Stop", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Stop = Caml_exceptions.create("Arg.Stop"); function assoc3(x, _l) { while(true) { diff --git a/jscomp/stdlib/array.js b/jscomp/stdlib/array.js index d26055b79b..e60ed6a016 100644 --- a/jscomp/stdlib/array.js +++ b/jscomp/stdlib/array.js @@ -2,6 +2,7 @@ 'use strict'; var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); +var Caml_exceptions = require("../runtime/caml_exceptions"); var Caml_array = require("../runtime/caml_array"); var Caml_curry = require("../runtime/caml_curry"); @@ -218,12 +219,7 @@ function fold_right(f, a, x) { return r; } -var Bottom = { - 0: "Array.Bottom", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Bottom = Caml_exceptions.create("Array.Bottom"); function sort(cmp, a) { var maxson = function (l, i) { diff --git a/jscomp/stdlib/camlinternalFormat.js b/jscomp/stdlib/camlinternalFormat.js index 504ed470a6..b26a26e0ec 100644 --- a/jscomp/stdlib/camlinternalFormat.js +++ b/jscomp/stdlib/camlinternalFormat.js @@ -7,6 +7,7 @@ var Caml_obj = require("../runtime/caml_obj"); var Caml_io = require("../runtime/caml_io"); var Caml_float = require("../runtime/caml_float"); var Pervasives = require("./pervasives"); +var Caml_exceptions = require("../runtime/caml_exceptions"); var Caml_format = require("../runtime/caml_format"); var Char = require("./char"); var Sys = require("./sys"); @@ -2236,12 +2237,7 @@ function fmtty_of_precision_fmtty(prec, fmtty) { } } -var Type_mismatch = { - 0: "CamlinternalFormat.Type_mismatch", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Type_mismatch = Caml_exceptions.create("CamlinternalFormat.Type_mismatch"); function type_padding(pad, fmtty) { if (typeof pad === "number") { diff --git a/jscomp/stdlib/camlinternalLazy.js b/jscomp/stdlib/camlinternalLazy.js index 5da5446b5f..ac002f8df1 100644 --- a/jscomp/stdlib/camlinternalLazy.js +++ b/jscomp/stdlib/camlinternalLazy.js @@ -1,16 +1,11 @@ // Generated CODE, PLEASE EDIT WITH CARE 'use strict'; -var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); -var Obj = require("./obj"); -var Caml_curry = require("../runtime/caml_curry"); +var Obj = require("./obj"); +var Caml_exceptions = require("../runtime/caml_exceptions"); +var Caml_curry = require("../runtime/caml_curry"); -var Undefined = { - 0: "CamlinternalLazy.Undefined", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Undefined = Caml_exceptions.create("CamlinternalLazy.Undefined"); function raise_undefined() { throw Undefined; diff --git a/jscomp/stdlib/camlinternalOO.js b/jscomp/stdlib/camlinternalOO.js index c04aaa82e9..dbf9328b0a 100644 --- a/jscomp/stdlib/camlinternalOO.js +++ b/jscomp/stdlib/camlinternalOO.js @@ -1,9 +1,10 @@ // Generated CODE, PLEASE EDIT WITH CARE 'use strict'; -var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); var Caml_obj = require("../runtime/caml_obj"); +var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); var Obj = require("./obj"); +var Caml_exceptions = require("../runtime/caml_exceptions"); var Caml_oo = require("../runtime/caml_oo"); var Sys = require("./sys"); var Caml_primitive = require("../runtime/caml_primitive"); @@ -14,7 +15,7 @@ var Caml_string = require("../runtime/caml_string"); var List = require("./list"); function copy(o) { - return Caml_builtin_exceptions.caml_set_oo_id(Caml_obj.caml_obj_dup(o)); + return Caml_exceptions.caml_set_oo_id(Caml_obj.caml_obj_dup(o)); } var params = /* record */[ @@ -878,7 +879,7 @@ function create_object(table) { tag: Obj.object_tag }; obj[0] = table[/* methods */1]; - return Caml_builtin_exceptions.caml_set_oo_id(obj); + return Caml_exceptions.caml_set_oo_id(obj); } function create_object_opt(obj_0, table) { @@ -891,7 +892,7 @@ function create_object_opt(obj_0, table) { tag: Obj.object_tag }; obj[0] = table[/* methods */1]; - return Caml_builtin_exceptions.caml_set_oo_id(obj); + return Caml_exceptions.caml_set_oo_id(obj); } } diff --git a/jscomp/stdlib/format.js b/jscomp/stdlib/format.js index cc448a1433..43c6a19228 100644 --- a/jscomp/stdlib/format.js +++ b/jscomp/stdlib/format.js @@ -1,10 +1,11 @@ // Generated CODE, PLEASE EDIT WITH CARE 'use strict'; -var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); var Caml_obj = require("../runtime/caml_obj"); +var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); var Bytes = require("./bytes"); var Caml_io = require("../runtime/caml_io"); +var Caml_exceptions = require("../runtime/caml_exceptions"); var Pervasives = require("./pervasives"); var Buffer = require("./buffer"); var Caml_curry = require("../runtime/caml_curry"); @@ -30,12 +31,7 @@ function add_queue(x, q) { } } -var Empty_queue = { - 0: "Format.Empty_queue", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Empty_queue = Caml_exceptions.create("Format.Empty_queue"); function peek_queue(param) { var match = param[/* body */1]; diff --git a/jscomp/stdlib/parsing.js b/jscomp/stdlib/parsing.js index 8c7d78a927..a8d7f7ea9e 100644 --- a/jscomp/stdlib/parsing.js +++ b/jscomp/stdlib/parsing.js @@ -1,27 +1,17 @@ // Generated CODE, PLEASE EDIT WITH CARE 'use strict'; -var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); -var Caml_obj = require("../runtime/caml_obj"); -var Caml_parser = require("../runtime/caml_parser"); -var Lexing = require("./lexing"); -var Caml_array = require("../runtime/caml_array"); -var $$Array = require("./array"); -var Caml_curry = require("../runtime/caml_curry"); - -var YYexit = { - 0: "Parsing.YYexit", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; - -var Parse_error = { - 0: "Parsing.Parse_error", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Caml_obj = require("../runtime/caml_obj"); +var Caml_parser = require("../runtime/caml_parser"); +var Caml_exceptions = require("../runtime/caml_exceptions"); +var Lexing = require("./lexing"); +var Caml_array = require("../runtime/caml_array"); +var $$Array = require("./array"); +var Caml_curry = require("../runtime/caml_curry"); + +var YYexit = Caml_exceptions.create("Parsing.YYexit"); + +var Parse_error = Caml_exceptions.create("Parsing.Parse_error"); var env = /* record */[ Caml_array.caml_make_vect(100, 0), diff --git a/jscomp/stdlib/pervasives.js b/jscomp/stdlib/pervasives.js index 560e15979f..9bd2f8ac0a 100644 --- a/jscomp/stdlib/pervasives.js +++ b/jscomp/stdlib/pervasives.js @@ -4,6 +4,7 @@ var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); var Caml_obj = require("../runtime/caml_obj"); var Caml_io = require("../runtime/caml_io"); +var Caml_exceptions = require("../runtime/caml_exceptions"); var Caml_format = require("../runtime/caml_format"); var Caml_primitive = require("../runtime/caml_primitive"); var CamlinternalFormatBasics = require("./camlinternalFormatBasics"); @@ -24,12 +25,7 @@ function invalid_arg(s) { ]; } -var Exit = { - 0: "Pervasives.Exit", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Exit = Caml_exceptions.create("Pervasives.Exit"); function min(x, y) { if (Caml_obj.caml_lessequal(x, y)) { diff --git a/jscomp/stdlib/queue.js b/jscomp/stdlib/queue.js index 22fd910d01..8a48388f85 100644 --- a/jscomp/stdlib/queue.js +++ b/jscomp/stdlib/queue.js @@ -1,16 +1,11 @@ // Generated CODE, PLEASE EDIT WITH CARE 'use strict'; -var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); -var Caml_obj = require("../runtime/caml_obj"); -var Caml_curry = require("../runtime/caml_curry"); - -var Empty = { - 0: "Queue.Empty", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Caml_obj = require("../runtime/caml_obj"); +var Caml_exceptions = require("../runtime/caml_exceptions"); +var Caml_curry = require("../runtime/caml_curry"); + +var Empty = Caml_exceptions.create("Queue.Empty"); function create() { return /* record */[ diff --git a/jscomp/stdlib/scanf.js b/jscomp/stdlib/scanf.js index cc1cc00684..8df89edd9c 100644 --- a/jscomp/stdlib/scanf.js +++ b/jscomp/stdlib/scanf.js @@ -4,6 +4,7 @@ var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); var Bytes = require("./bytes"); var Pervasives = require("./pervasives"); +var Caml_exceptions = require("../runtime/caml_exceptions"); var Caml_format = require("../runtime/caml_format"); var Printf = require("./printf"); var Caml_primitive = require("../runtime/caml_primitive"); @@ -268,12 +269,7 @@ function close_in(ib) { } } -var Scan_failure = { - 0: "Scanf.Scan_failure", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Scan_failure = Caml_exceptions.create("Scanf.Scan_failure"); function bad_input_escape(c) { var s = Caml_curry.app1(Printf.sprintf(/* Format */[ diff --git a/jscomp/stdlib/stack.js b/jscomp/stdlib/stack.js index 2ca6f0dc01..6a9df079f0 100644 --- a/jscomp/stdlib/stack.js +++ b/jscomp/stdlib/stack.js @@ -1,15 +1,10 @@ // Generated CODE, PLEASE EDIT WITH CARE 'use strict'; -var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); -var List = require("./list"); +var Caml_exceptions = require("../runtime/caml_exceptions"); +var List = require("./list"); -var Empty = { - 0: "Stack.Empty", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Empty = Caml_exceptions.create("Stack.Empty"); function create() { return /* record */[/* [] */0]; diff --git a/jscomp/stdlib/stream.js b/jscomp/stdlib/stream.js index 4278baac07..1893143372 100644 --- a/jscomp/stdlib/stream.js +++ b/jscomp/stdlib/stream.js @@ -3,23 +3,14 @@ var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); var CamlinternalLazy = require("./camlinternalLazy"); +var Caml_exceptions = require("../runtime/caml_exceptions"); var Pervasives = require("./pervasives"); var Caml_curry = require("../runtime/caml_curry"); var List = require("./list"); -var Failure = { - 0: "Stream.Failure", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Failure = Caml_exceptions.create("Stream.Failure"); -var $$Error = { - 0: "Stream.Error", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var $$Error = Caml_exceptions.create("Stream.Error"); function fill_buff(b) { b[/* len */2] = Pervasives.input(b[/* ic */0], b[/* buff */1], 0, b[/* buff */1].length); diff --git a/jscomp/stdlib/sys.js b/jscomp/stdlib/sys.js index f0174402d3..98ba66f521 100644 --- a/jscomp/stdlib/sys.js +++ b/jscomp/stdlib/sys.js @@ -1,7 +1,7 @@ // Generated CODE, PLEASE EDIT WITH CARE 'use strict'; -var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); +var Caml_exceptions = require("../runtime/caml_exceptions"); var is_js = /* true */1; @@ -28,12 +28,7 @@ function set_signal(sig_num, sig_beh) { return sig_beh; } -var Break = { - 0: "Sys.Break", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Break = Caml_exceptions.create("Sys.Break"); function catch_break(on) { if (on) { diff --git a/jscomp/stdlib/unix.js b/jscomp/stdlib/unix.js index ad2b121965..c0d33a17cf 100644 --- a/jscomp/stdlib/unix.js +++ b/jscomp/stdlib/unix.js @@ -4,6 +4,7 @@ var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); var Caml_io = require("../runtime/caml_io"); var Caml_sys = require("../runtime/caml_sys"); +var Caml_exceptions = require("../runtime/caml_exceptions"); var Pervasives = require("./pervasives"); var Hashtbl = require("./hashtbl"); var Caml_format = require("../runtime/caml_format"); @@ -18,12 +19,7 @@ var Caml_curry = require("../runtime/caml_curry"); var Caml_string = require("../runtime/caml_string"); var List = require("./list"); -var Unix_error = { - 0: "Unix.Unix_error", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Unix_error = Caml_exceptions.create("Unix.Unix_error"); Callback.register_exception("Unix.Unix_error", [ Unix_error, diff --git a/jscomp/test/.depend b/jscomp/test/.depend index 7546423c4f..c0d716f0d1 100644 --- a/jscomp/test/.depend +++ b/jscomp/test/.depend @@ -132,6 +132,8 @@ event_ffi.cmo : ../lib/js.cmo ../lib/fn.cmo event_ffi.cmx : ../lib/js.cmx ../lib/fn.cmx exception_raise_test.cmo : mt.cmi exception_raise_test.cmx : mt.cmx +exception_value_test.cmo : +exception_value_test.cmx : ext_array.cmo : ../stdlib/list.cmi ../stdlib/array.cmi ext_array.cmx : ../stdlib/list.cmx ../stdlib/array.cmx ext_bytes.cmo : ../stdlib/bytes.cmi @@ -682,6 +684,8 @@ event_ffi.cmo : ../lib/js.cmo ../lib/fn.cmo event_ffi.cmj : ../lib/js.cmj ../lib/fn.cmj exception_raise_test.cmo : mt.cmi exception_raise_test.cmj : mt.cmj +exception_value_test.cmo : +exception_value_test.cmj : ext_array.cmo : ../stdlib/list.cmi ../stdlib/array.cmi ext_array.cmj : ../stdlib/list.cmj ../stdlib/array.cmj ext_bytes.cmo : ../stdlib/bytes.cmi diff --git a/jscomp/test/class6_test.js b/jscomp/test/class6_test.js index b79e186231..6c26ba307f 100644 --- a/jscomp/test/class6_test.js +++ b/jscomp/test/class6_test.js @@ -3,6 +3,7 @@ var Caml_obj = require("../runtime/caml_obj"); var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); +var Caml_exceptions = require("../runtime/caml_exceptions"); var Mt = require("./mt"); var CamlinternalOO = require("../stdlib/camlinternalOO"); var Caml_curry = require("../runtime/caml_curry"); @@ -203,7 +204,7 @@ function functional_point_init($$class) { }, move, function (self$neg6, d) { - var copy = Caml_builtin_exceptions.caml_set_oo_id(Caml_obj.caml_obj_dup(self$neg6)); + var copy = Caml_exceptions.caml_set_oo_id(Caml_obj.caml_obj_dup(self$neg6)); copy[x] = self$neg6[x] + d | 0; return copy; } diff --git a/jscomp/test/class7_test.js b/jscomp/test/class7_test.js index 45c1f503fa..32e9a59473 100644 --- a/jscomp/test/class7_test.js +++ b/jscomp/test/class7_test.js @@ -1,12 +1,12 @@ // Generated CODE, PLEASE EDIT WITH CARE 'use strict'; -var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); -var Caml_obj = require("../runtime/caml_obj"); -var Mt = require("./mt"); -var CamlinternalOO = require("../stdlib/camlinternalOO"); -var Caml_curry = require("../runtime/caml_curry"); -var Oo = require("../stdlib/oo"); +var Caml_obj = require("../runtime/caml_obj"); +var Caml_exceptions = require("../runtime/caml_exceptions"); +var Mt = require("./mt"); +var CamlinternalOO = require("../stdlib/camlinternalOO"); +var Caml_curry = require("../runtime/caml_curry"); +var Oo = require("../stdlib/oo"); var shared = ["copy"]; @@ -134,7 +134,7 @@ function backup_init($$class) { CamlinternalOO.set_methods($$class, /* array */[ save, function (self$neg3) { - var copy$1 = Caml_builtin_exceptions.caml_set_oo_id(Caml_obj.caml_obj_dup(self$neg3)); + var copy$1 = Caml_exceptions.caml_set_oo_id(Caml_obj.caml_obj_dup(self$neg3)); self$neg3[copy] = /* Some */[(copy$1[copy] = /* None */0, copy$1)]; return /* () */0; }, @@ -257,7 +257,7 @@ function backup2_init($$class) { CamlinternalOO.set_methods($$class, /* array */[ save, function (self$neg5) { - self$neg5[copy] = /* Some */[Caml_builtin_exceptions.caml_set_oo_id(Caml_obj.caml_obj_dup(self$neg5))]; + self$neg5[copy] = /* Some */[Caml_exceptions.caml_set_oo_id(Caml_obj.caml_obj_dup(self$neg5))]; return /* () */0; }, restore, diff --git a/jscomp/test/class8_test.js b/jscomp/test/class8_test.js index ada747793f..8c6600dfa4 100644 --- a/jscomp/test/class8_test.js +++ b/jscomp/test/class8_test.js @@ -1,11 +1,11 @@ // Generated CODE, PLEASE EDIT WITH CARE 'use strict'; -var Caml_obj = require("../runtime/caml_obj"); -var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); -var Mt = require("./mt"); -var CamlinternalOO = require("../stdlib/camlinternalOO"); -var Caml_curry = require("../runtime/caml_curry"); +var Caml_obj = require("../runtime/caml_obj"); +var Caml_exceptions = require("../runtime/caml_exceptions"); +var Mt = require("./mt"); +var CamlinternalOO = require("../stdlib/camlinternalOO"); +var Caml_curry = require("../runtime/caml_curry"); var shared = [ "leq", @@ -91,7 +91,7 @@ function money2_init($$class) { var obj_init = inh[0]; var repr = inh[1]; CamlinternalOO.set_method($$class, times, function (self$neg3, k) { - var copy = Caml_builtin_exceptions.caml_set_oo_id(Caml_obj.caml_obj_dup(self$neg3)); + var copy = Caml_exceptions.caml_set_oo_id(Caml_obj.caml_obj_dup(self$neg3)); copy[repr] = k * self$neg3[repr]; return copy; }); diff --git a/jscomp/test/equal_exception_test.js b/jscomp/test/equal_exception_test.js index a606987421..617dc538ce 100644 --- a/jscomp/test/equal_exception_test.js +++ b/jscomp/test/equal_exception_test.js @@ -3,6 +3,7 @@ var Bytes = require("../stdlib/bytes"); var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); +var Caml_exceptions = require("../runtime/caml_exceptions"); var Mt = require("./mt"); var v = "gso"; @@ -70,12 +71,7 @@ function is_exception() { } function is_normal_exception() { - var A = { - 0: "A", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 - }; + var A = Caml_exceptions.create("A"); var v = [ A, 3 @@ -99,12 +95,7 @@ function is_normal_exception() { } function is_arbitrary_exception() { - var A = { - 0: "A", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 - }; + var A = Caml_exceptions.create("A"); try { throw A; } diff --git a/jscomp/test/exception_raise_test.js b/jscomp/test/exception_raise_test.js index 558a8b96b9..6e189e37dd 100644 --- a/jscomp/test/exception_raise_test.js +++ b/jscomp/test/exception_raise_test.js @@ -2,44 +2,20 @@ 'use strict'; var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); +var Caml_exceptions = require("../runtime/caml_exceptions"); var Mt = require("./mt"); var Caml_curry = require("../runtime/caml_curry"); -var Local = { - 0: "Exception_raise_test.Local", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Local = Caml_exceptions.create("Exception_raise_test.Local"); -var B = { - 0: "Exception_raise_test.B", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var B = Caml_exceptions.create("Exception_raise_test.B"); -var C = { - 0: "Exception_raise_test.C", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var C = Caml_exceptions.create("Exception_raise_test.C"); -var D = { - 0: "Exception_raise_test.D", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var D = Caml_exceptions.create("Exception_raise_test.D"); function appf(g, x) { - var A = { - 0: "A", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 - }; + var A = Caml_exceptions.create("A"); try { return Caml_curry.app1(g, x); } @@ -93,12 +69,7 @@ function appf(g, x) { } } -var A = { - 0: "Exception_raise_test.A", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var A = Caml_exceptions.create("Exception_raise_test.A"); var f; diff --git a/jscomp/test/exception_value_test.js b/jscomp/test/exception_value_test.js new file mode 100644 index 0000000000..d26e5e1ce0 --- /dev/null +++ b/jscomp/test/exception_value_test.js @@ -0,0 +1,31 @@ +// Generated CODE, PLEASE EDIT WITH CARE +'use strict'; + +var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); + +function f() { + throw Caml_builtin_exceptions.not_found; +} + +function assert_f(x) { + if (x <= 3) { + throw [ + Caml_builtin_exceptions.assert_failure, + [ + "exception_value_test.ml", + 9, + 12 + ] + ]; + } + return 3; +} + +function hh() { + throw Caml_builtin_exceptions.not_found; +} + +exports.f = f; +exports.assert_f = assert_f; +exports.hh = hh; +/* No side effect */ diff --git a/jscomp/test/exception_value_test.ml b/jscomp/test/exception_value_test.ml new file mode 100644 index 0000000000..4fd6d30d9b --- /dev/null +++ b/jscomp/test/exception_value_test.ml @@ -0,0 +1,16 @@ + + +let f () = + raise Not_found + + + +let assert_f x = + let () = assert (x > 3) in + 3 + + +let hh () = + let v = raise Not_found in + v + 3 + (* TODO: comment for line column number *) diff --git a/jscomp/test/ext_string.js b/jscomp/test/ext_string.js index 96ca21da7d..60c89c4c67 100644 --- a/jscomp/test/ext_string.js +++ b/jscomp/test/ext_string.js @@ -3,6 +3,7 @@ var Bytes = require("../stdlib/bytes"); var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); +var Caml_exceptions = require("../runtime/caml_exceptions"); var Caml_primitive = require("../runtime/caml_primitive"); var Ext_bytes = require("./ext_bytes"); var $$String = require("../stdlib/string"); @@ -214,12 +215,7 @@ function find($staropt$star, sub, s) { var start = $staropt$star ? $staropt$star[0] : 0; var n = sub.length; var i = start; - var Exit = { - 0: "Exit", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 - }; + var Exit = Caml_exceptions.create("Exit"); try { while((i + n | 0) <= s.length) { if (_is_sub(sub, 0, s, i, n)) { @@ -242,12 +238,7 @@ function find($staropt$star, sub, s) { function rfind(sub, s) { var n = sub.length; var i = s.length - n | 0; - var Exit = { - 0: "Exit", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 - }; + var Exit = Caml_exceptions.create("Exit"); try { while(i >= 0) { if (_is_sub(sub, 0, s, i, n)) { diff --git a/jscomp/test/extensible_variant_test.js b/jscomp/test/extensible_variant_test.js index bdf04482ec..ac073ce5eb 100644 --- a/jscomp/test/extensible_variant_test.js +++ b/jscomp/test/extensible_variant_test.js @@ -2,30 +2,16 @@ 'use strict'; var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); +var Caml_exceptions = require("../runtime/caml_exceptions"); var Mt = require("./mt"); -var Str = { - 0: "Extensible_variant_test.Str", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Str = Caml_exceptions.create("Extensible_variant_test.Str"); -var Int = { - 0: "Extensible_variant_test.N.Int", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Int = Caml_exceptions.create("Extensible_variant_test.N.Int"); var N = /* module */[Int]; -var Int$1 = { - 0: "Extensible_variant_test.Int", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Int$1 = Caml_exceptions.create("Extensible_variant_test.Int"); function to_int(x) { if (x[0] === Str) { diff --git a/jscomp/test/local_exception_test.js b/jscomp/test/local_exception_test.js index 152c567544..1724d1ae4b 100644 --- a/jscomp/test/local_exception_test.js +++ b/jscomp/test/local_exception_test.js @@ -1,14 +1,9 @@ // Generated CODE, PLEASE EDIT WITH CARE 'use strict'; -var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); +var Caml_exceptions = require("../runtime/caml_exceptions"); -var A = { - 0: "Local_exception_test.A", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var A = Caml_exceptions.create("Local_exception_test.A"); var v = [ A, @@ -16,31 +11,16 @@ var v = [ /* true */1 ]; -var B = { - 0: "Local_exception_test.B", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var B = Caml_exceptions.create("Local_exception_test.B"); -var D = { - 0: "Local_exception_test.D", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var D = Caml_exceptions.create("Local_exception_test.D"); var d = [ D, 3 ]; -var A$1 = { - 0: "Local_exception_test.A", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var A$1 = Caml_exceptions.create("Local_exception_test.A"); var x = [ A$1, diff --git a/jscomp/test/pq_test.js b/jscomp/test/pq_test.js index bb2d596cbd..50c41d2d91 100644 --- a/jscomp/test/pq_test.js +++ b/jscomp/test/pq_test.js @@ -1,7 +1,7 @@ // Generated CODE, PLEASE EDIT WITH CARE 'use strict'; -var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); +var Caml_exceptions = require("../runtime/caml_exceptions"); function insert(queue, prio, elt) { if (queue) { @@ -36,12 +36,7 @@ function insert(queue, prio, elt) { } } -var Queue_is_empty = { - 0: "Pq_test.PrioQueue.Queue_is_empty", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Queue_is_empty = Caml_exceptions.create("Pq_test.PrioQueue.Queue_is_empty"); function remove_top(param) { if (param) { diff --git a/jscomp/test/test.mllib b/jscomp/test/test.mllib index ca4343b1a8..d52ba92d4d 100644 --- a/jscomp/test/test.mllib +++ b/jscomp/test/test.mllib @@ -242,9 +242,10 @@ class7_test class8_test class_repr - +pq_test mt_global event_ffi -hash_test \ No newline at end of file +hash_test +exception_value_test \ No newline at end of file diff --git a/jscomp/test/test_common.js b/jscomp/test/test_common.js index 6d5220a243..1231e95e09 100644 --- a/jscomp/test/test_common.js +++ b/jscomp/test/test_common.js @@ -1,21 +1,11 @@ // Generated CODE, PLEASE EDIT WITH CARE 'use strict'; -var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); +var Caml_exceptions = require("../runtime/caml_exceptions"); -var U = { - 0: "Test_common.U", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var U = Caml_exceptions.create("Test_common.U"); -var H = { - 0: "Test_common.H", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var H = Caml_exceptions.create("Test_common.H"); exports.U = U; exports.H = H; diff --git a/jscomp/test/test_exception.js b/jscomp/test/test_exception.js index 532a729d22..caccaff5a6 100644 --- a/jscomp/test/test_exception.js +++ b/jscomp/test/test_exception.js @@ -2,14 +2,10 @@ 'use strict'; var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); +var Caml_exceptions = require("../runtime/caml_exceptions"); var Test_common = require("./test_common"); -var Local = { - 0: "Test_exception.Local", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Local = Caml_exceptions.create("Test_exception.Local"); function f() { throw [ diff --git a/jscomp/test/test_exception_escape.js b/jscomp/test/test_exception_escape.js index 139a1fff26..1bbea3056d 100644 --- a/jscomp/test/test_exception_escape.js +++ b/jscomp/test/test_exception_escape.js @@ -1,14 +1,9 @@ // Generated CODE, PLEASE EDIT WITH CARE 'use strict'; -var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); +var Caml_exceptions = require("../runtime/caml_exceptions"); -var A = { - 0: "Test_exception_escape.N.A", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var A = Caml_exceptions.create("Test_exception_escape.N.A"); var f; diff --git a/jscomp/test/test_internalOO.js b/jscomp/test/test_internalOO.js index 72c02f09fe..80ff4aace5 100644 --- a/jscomp/test/test_internalOO.js +++ b/jscomp/test/test_internalOO.js @@ -1,9 +1,10 @@ // Generated CODE, PLEASE EDIT WITH CARE 'use strict'; -var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); var Caml_obj = require("../runtime/caml_obj"); +var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); var Obj = require("../stdlib/obj"); +var Caml_exceptions = require("../runtime/caml_exceptions"); var Caml_oo = require("../runtime/caml_oo"); var Sys = require("../stdlib/sys"); var Caml_primitive = require("../runtime/caml_primitive"); @@ -14,7 +15,7 @@ var Caml_string = require("../runtime/caml_string"); var List = require("../stdlib/list"); function copy(o) { - return Caml_builtin_exceptions.caml_set_oo_id(Caml_obj.caml_obj_dup(o)); + return Caml_exceptions.caml_set_oo_id(Caml_obj.caml_obj_dup(o)); } var params = /* record */[ @@ -2690,7 +2691,7 @@ function create_object(table) { tag: Obj.object_tag }; obj[0] = table[/* methods */1]; - return Caml_builtin_exceptions.caml_set_oo_id(obj); + return Caml_exceptions.caml_set_oo_id(obj); } function create_object_opt(obj_0, table) { @@ -2703,7 +2704,7 @@ function create_object_opt(obj_0, table) { tag: Obj.object_tag }; obj[0] = table[/* methods */1]; - return Caml_builtin_exceptions.caml_set_oo_id(obj); + return Caml_exceptions.caml_set_oo_id(obj); } } diff --git a/jscomp/test/test_literal.js b/jscomp/test/test_literal.js index c080a757b3..aab367534d 100644 --- a/jscomp/test/test_literal.js +++ b/jscomp/test/test_literal.js @@ -1,14 +1,9 @@ // Generated CODE, PLEASE EDIT WITH CARE 'use strict'; -var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); - -var Custom_inline = { - 0: "Test_literal.Custom_inline", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Caml_exceptions = require("../runtime/caml_exceptions"); + +var Custom_inline = Caml_exceptions.create("Test_literal.Custom_inline"); var v = [ Custom_inline, diff --git a/jscomp/test/test_per.js b/jscomp/test/test_per.js index f0ae19a588..8da7a1836d 100644 --- a/jscomp/test/test_per.js +++ b/jscomp/test/test_per.js @@ -4,6 +4,7 @@ var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); var Caml_obj = require("../runtime/caml_obj"); var Caml_io = require("../runtime/caml_io"); +var Caml_exceptions = require("../runtime/caml_exceptions"); var Caml_format = require("../runtime/caml_format"); var Caml_primitive = require("../runtime/caml_primitive"); var CamlinternalFormatBasics = require("../stdlib/camlinternalFormatBasics"); @@ -24,12 +25,7 @@ function invalid_arg(s) { ]; } -var Exit = { - 0: "Test_per.Exit", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Exit = Caml_exceptions.create("Test_per.Exit"); function min(x, y) { if (Caml_obj.caml_lessequal(x, y)) { diff --git a/jscomp/test/test_seq.js b/jscomp/test/test_seq.js index 8b545802aa..a9925977d6 100644 --- a/jscomp/test/test_seq.js +++ b/jscomp/test/test_seq.js @@ -1,31 +1,17 @@ // Generated CODE, PLEASE EDIT WITH CARE 'use strict'; -var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); var Caml_obj = require("../runtime/caml_obj"); +var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); +var Caml_exceptions = require("../runtime/caml_exceptions"); var Pervasives = require("../stdlib/pervasives"); var Caml_curry = require("../runtime/caml_curry"); -var Bad = { - 0: "Test_seq.Bad", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Bad = Caml_exceptions.create("Test_seq.Bad"); -var Help = { - 0: "Test_seq.Help", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Help = Caml_exceptions.create("Test_seq.Help"); -var Stop = { - 0: "Test_seq.Stop", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Stop = Caml_exceptions.create("Test_seq.Stop"); function assoc3(x, _l) { while(true) { diff --git a/jscomp/test/test_static_catch_ident.js b/jscomp/test/test_static_catch_ident.js index 313fc9deff..d91caa9bf5 100644 --- a/jscomp/test/test_static_catch_ident.js +++ b/jscomp/test/test_static_catch_ident.js @@ -2,13 +2,9 @@ 'use strict'; var Caml_builtin_exceptions = require("../runtime/caml_builtin_exceptions"); +var Caml_exceptions = require("../runtime/caml_exceptions"); -var Scan_failure = { - 0: "Test_static_catch_ident.Scan_failure", - 1: Caml_builtin_exceptions.get_id(), - length: 2, - tag: 248 -}; +var Scan_failure = Caml_exceptions.create("Test_static_catch_ident.Scan_failure"); function scanf_bad_input(_, x) { var exit = 0;