diff --git a/jscomp/j.ml b/jscomp/j.ml index dac9da471f..1e3dae1405 100644 --- a/jscomp/j.ml +++ b/jscomp/j.ml @@ -113,6 +113,9 @@ and expression_desc = | Seq of expression * expression | Cond of expression * expression * expression | Bin of binop * expression * expression + + (* [int_op] will guarantee return [int32] bits + https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators *) (* | Int32_bin of int_op * expression * expression *) | FlatCall of expression * expression (* f.apply(null,args) -- Fully applied guaranteed diff --git a/jscomp/j_helper.ml b/jscomp/j_helper.ml index 811f5c0143..2d777104e2 100644 --- a/jscomp/j_helper.ml +++ b/jscomp/j_helper.ml @@ -44,6 +44,8 @@ let oo = "Caml_oo" let no_side_effect = Js_analyzer.no_side_effect_expression +type binary_op = ?comment:string -> J.expression -> J.expression -> J.expression +type unary_op = ?comment:string -> J.expression -> J.expression (* remove pure part of the expression and keep the non-pure part while preserve the semantics @@ -552,7 +554,23 @@ module Exp = struct check: Re-association: avoid integer overflow *) - let rec add ?comment (e1 : t) (e2 : t) = + let rec to_int32 ?comment (e : J.expression) : J.expression = + let expression_desc = e.expression_desc in + match expression_desc with + | Bin(Bor, a, {expression_desc = Number (Int {i = 0}); _}) + -> + to_int32 ?comment a + | _ -> + { comment ; + expression_desc = Bin (Bor, {comment = None; expression_desc }, int 0) + } + + let rec to_uint32 ?comment (e : J.expression) : J.expression = + { comment ; + expression_desc = Bin (Lsr, e , int 0) + } + + let rec float_add ?comment (e1 : t) (e2 : t) = match e1.expression_desc, e2.expression_desc with | Number (Int {i;_}), Number (Int {i = j;_}) -> int ?comment (i + j) @@ -577,15 +595,100 @@ module Exp = struct (* bin ?comment Plus e2 e1 *) | _ -> bin ?comment Plus e1 e2 + let int32_add ?comment e1 e2 = + (* to_int32 @@ *)float_add ?comment e1 e2 - and minus ?comment e1 e2 = + let float_minus ?comment e1 e2 = bin ?comment Minus e1 e2 - and mul ?comment e1 e2 = + let int32_minus ?comment e1 e2 : J.expression = + (* to_int32 @@ *) float_minus ?comment e1 e2 + + let float_mul ?comment e1 e2 = bin ?comment Mul e1 e2 - and div ?comment e1 e2 = + let float_div ?comment e1 e2 = bin ?comment Div e1 e2 + let float_notequal ?comment e1 e2 = + bin ?comment NotEqEq e1 e2 + + let int32_div ?comment e1 e2 : J.expression = + to_int32 (float_div ?comment e1 e2) + + + (* TODO: call primitive *) + let int32_mul ?comment e1 e2 : J.expression = + { comment ; + expression_desc = Bin (Mul, e1,e2) + } + + + (* TODO: check division by zero *) + let int32_mod ?comment e1 e2 : J.expression = + { comment ; + expression_desc = Bin (Mod, e1,e2) + } + + let int32_lsl ?comment e1 e2 : J.expression = + { comment ; + expression_desc = Bin (Lsl, e1,e2) + } + + (* TODO: optimization *) + let int32_lsr ?comment + (e1 : J.expression) + (e2 : J.expression) : J.expression = + match e1.expression_desc, e2.expression_desc with + | Number (Int { i = i1}), Number( Int {i = i2}) + -> + int @@ Int32.to_int + (Int32.shift_right_logical + (Int32.of_int i1) i2) + | _ , Number( Int {i = i2}) + -> + if i2 = 0 then + e1 + else + { comment ; + expression_desc = Bin (Lsr, e1,e2) (* uint32 *) + } + | _, _ -> + to_int32 { comment ; + expression_desc = Bin (Lsr, e1,e2) (* uint32 *) + } + + let int32_asr ?comment e1 e2 : J.expression = + { comment ; + expression_desc = Bin (Asr, e1,e2) + } + + let int32_bxor ?comment e1 e2 : J.expression = + { comment ; + expression_desc = Bin (Bxor, e1,e2) + } + + let rec int32_band ?comment (e1 : J.expression) (e2 : J.expression) : J.expression = + match e1.expression_desc with + | Bin (Bor ,a, {expression_desc = Number (Int {i = 0})}) + -> + (* Note that in JS + {[ -1 >>> 0 & 0xffffffff = -1]} is the same as + {[ (-1 >>> 0 | 0 ) & 0xffffff ]} + *) + int32_band a e2 + | _ -> + { comment ; + expression_desc = Bin (Band, e1,e2) + } + + let int32_bor ?comment e1 e2 : J.expression = + { comment ; + expression_desc = Bin (Bor, e1,e2) + } + + (* let int32_bin ?comment op e1 e2 : J.expression = *) + (* {expression_desc = Int32_bin(op,e1, e2); comment} *) + (* TODO -- alpha conversion remember to add parens.. diff --git a/jscomp/j_helper.mli b/jscomp/j_helper.mli index d5520d6c80..574290f6cc 100644 --- a/jscomp/j_helper.mli +++ b/jscomp/j_helper.mli @@ -63,6 +63,10 @@ val is_constant : J.expression -> bool val extract_non_pure : J.expression -> J.expression option +type binary_op = ?comment:string -> J.expression -> J.expression -> J.expression + +type unary_op = ?comment:string -> J.expression -> J.expression + module Exp : sig type t = J.expression @@ -139,15 +143,23 @@ module Exp : sig val is_type_number : ?comment:string -> t -> t - val bin : ?comment:string -> Js_op.binop -> t -> t -> t - - val int_plus : ?comment:string -> t -> t -> t - - val int_minus : ?comment:string -> t -> t -> t - - val float_plus : ?comment:string -> t -> t -> t + (* val bin : ?comment:string -> Js_op.binary_op -> t -> t -> t *) + val to_int32 : unary_op + val to_uint32 : unary_op + + val int_plus : binary_op + val int_minus : binary_op + val int32_lsl : binary_op + val int32_lsr : binary_op + val int32_asr : binary_op + val int32_mod : binary_op + val int32_bxor : binary_op + val int32_band : binary_op + val int32_bor : binary_op + val float_plus : binary_op + val float_minus : binary_op + val float_notequal : binary_op - val float_minus : ?comment:string -> t -> t -> t (* val un : ?comment:string -> Js_op.unop -> t -> t *) val not : t -> t @@ -219,14 +231,15 @@ module Exp : sig val stringcomp : ?comment:string -> Js_op.binop -> t -> t -> t - val add : ?comment:string -> t -> t -> t - - val minus : ?comment:string -> t -> t -> t - - val mul : ?comment:string -> t -> t -> t - - val div : ?comment:string -> t -> t -> t + val float_add : ?comment:string -> t -> t -> t + val float_minus : ?comment:string -> t -> t -> t + val float_mul : ?comment:string -> t -> t -> t + val float_div : ?comment:string -> t -> t -> t + val int32_div : ?comment:string -> t -> t -> t + val int32_add : ?comment:string -> t -> t -> t + val int32_minus : ?comment:string -> t -> t -> t + val int32_mul : ?comment:string -> t -> t -> t val of_block : ?comment:string -> J.statement list -> J.expression -> t end diff --git a/jscomp/js_fold.ml b/jscomp/js_fold.ml index 88805d5d44..8ad08a8108 100644 --- a/jscomp/js_fold.ml +++ b/jscomp/js_fold.ml @@ -125,6 +125,8 @@ class virtual fold = val log3 : 'a -> 'b -> 'c -> unit *) (* TODO: Add some primitives so that [js inliner] can do a better job *) + (* [int_op] will guarantee return [int32] bits + https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators *) (* | Int32_bin of int_op * expression * expression *) (* f.apply(null,args) -- Fully applied guaranteed TODO: once we know args's shape -- diff --git a/jscomp/js_map.ml b/jscomp/js_map.ml index 4be54729a1..0876e1e456 100644 --- a/jscomp/js_map.ml +++ b/jscomp/js_map.ml @@ -138,6 +138,8 @@ class virtual map = val log3 : 'a -> 'b -> 'c -> unit *) (* TODO: Add some primitives so that [js inliner] can do a better job *) + (* [int_op] will guarantee return [int32] bits + https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators *) (* | Int32_bin of int_op * expression * expression *) (* f.apply(null,args) -- Fully applied guaranteed TODO: once we know args's shape -- diff --git a/jscomp/js_op.ml b/jscomp/js_op.ml index ef6418c315..437e011519 100644 --- a/jscomp/js_op.ml +++ b/jscomp/js_op.ml @@ -52,6 +52,41 @@ type binop = | Div | Mod +(** +note that we don't need raise [Div_by_zero] in ocamlscript + +{[ +let add x y = x + y (* | 0 *) +let minus x y = x - y (* | 0 *) +let mul x y = x * y (* caml_mul | Math.imul *) +let div x y = x / y (* caml_div (x/y|0)*) +let imod x y = x mod y (* caml_mod (x%y) (zero_divide)*) + +let bor x y = x lor y (* x | y *) +let bxor x y = x lxor y (* x ^ y *) +let band x y = x land y (* x & y *) +let ilnot y = lnot y (* let lnot x = x lxor (-1) *) +let ilsl x y = x lsl y (* x << y*) +let ilsr x y = x lsr y (* x >>> y | 0 *) +let iasr x y = x asr y (* x >> y *) +]} + + +Note that js treat unsigned shift 0 bits in a special way + Unsigned shifts convert their left-hand side to Uint32, + signed shifts convert it to Int32. + Shifting by 0 digits returns the converted value. + {[ + function ToUint32(x) { + return x >>> 0; + } + function ToInt32(x) { + return x >> 0; + } + ]} + So in Js, [-1 >>>0] will be the largest Uint32, while [-1>>0] will remain [-1] + and [-1 >>> 0 >> 0 ] will be [-1] +*) type int_op = | Bor @@ -62,10 +97,17 @@ type int_op = | Asr | Plus + (* for [+], given two numbers + x + y | 0 + *) | Minus + (* x - y | 0 *) | Mul + (* *) | Div + (* x / y | 0 *) | Mod + (* x % y *) (* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Bitwise_operators {[ diff --git a/jscomp/js_op_util.ml b/jscomp/js_op_util.ml index 9b11212c29..4efa7cfde6 100644 --- a/jscomp/js_op_util.ml +++ b/jscomp/js_op_util.ml @@ -51,18 +51,34 @@ let op_int_prec (op : Js_op.int_op) = let op_str (op : Js_op.binop) = match op with - | Eq -> "=" - | Or -> "||" - | And -> "&&" | Bor -> "|" | Bxor -> "^" | Band -> "&" + | Lsl -> "<<" + | Lsr -> ">>>" + | Asr -> ">>" + | Plus -> "+" + | Minus -> "-" + | Mul -> "*" + | Div -> "/" + | Mod -> "%" + + | Eq -> "=" + | Or -> "||" + | And -> "&&" | EqEqEq -> "===" | NotEqEq -> "!==" | Lt -> "<" | Le -> "<=" | Gt -> ">" | Ge -> ">=" + + +let op_int_str (op : Js_op.int_op) = + match op with + | Bor -> "|" + | Bxor -> "^" + | Band -> "&" | Lsl -> "<<" | Lsr -> ">>>" | Asr -> ">>" @@ -71,7 +87,7 @@ let op_str (op : Js_op.binop) = | Mul -> "*" | Div -> "/" | Mod -> "%" - + let str_of_used_stats = function | Js_op.Dead_pure -> "Dead_pure" | Dead_non_pure -> "Dead_non_pure" diff --git a/jscomp/js_op_util.mli b/jscomp/js_op_util.mli index 6994183597..9ecaff31e9 100644 --- a/jscomp/js_op_util.mli +++ b/jscomp/js_op_util.mli @@ -26,6 +26,10 @@ val op_prec : Js_op.binop -> int * int * int val op_str : Js_op.binop -> string +val op_int_prec : Js_op.int_op -> int * int * int + +val op_int_str : Js_op.int_op -> string + val str_of_used_stats : Js_op.used_stats -> string val update_used_stats : J.ident_info -> Js_op.used_stats -> unit diff --git a/jscomp/lam_compile_group.ml b/jscomp/lam_compile_group.ml index 96f3411249..058422ee95 100644 --- a/jscomp/lam_compile_group.ml +++ b/jscomp/lam_compile_group.ml @@ -95,9 +95,13 @@ let compile_group ({filename = file_name; env;} as meta : Lam_stats.meta) (x : L J_helper.string "bytes_cat") (** Special handling for values in [Sys] *) - | Single(_, ({name="max_array_length";_} as id) ,_ ), "sys.ml" -> - (* See [js_knowledge] Array size section, can not be expressed by OCaml int *) + | Single(_, ({name="max_array_length" | "max_string_length";_} as id) ,_ ), "sys.ml" -> + (* See [js_knowledge] Array size section, can not be expressed by OCaml int, + note that casual handling of {!Sys.max_string_length} could result into + negative value which could cause wrong behavior of {!Buffer.create} + *) Js_output.of_stmt @@ S.const_variable id ~exp:(E.float "4_294_967_295.") + | Single(_, ({name="max_int";_} as id) ,_ ), ("sys.ml" | "nativeint.ml") -> (* See [js_knowledge] Max int section, (2. ** 53. -. 1.;;) can not be expressed by OCaml int *) Js_output.of_stmt @@ S.const_variable id ~exp:(E.float "9007199254740991.") diff --git a/jscomp/lam_compile_primitive.ml b/jscomp/lam_compile_primitive.ml index 5d8f1c945d..561e28db66 100644 --- a/jscomp/lam_compile_primitive.ml +++ b/jscomp/lam_compile_primitive.ml @@ -69,82 +69,107 @@ let translate E.assign v (E.int_plus v (E.int n)) | _ -> E.unknown_primitive prim end - | Paddint | Paddbint _ | Paddfloat -> + | Paddint | Paddbint _ + -> begin match args with | [e1;e2] -> - E.add e1 e2 + E.int32_add e1 e2 | _ -> E.unknown_primitive prim end - | (Psubint | Psubbint _ | Psubfloat)-> + | Paddfloat + -> begin match args with | [e1;e2] -> - E.minus e1 e2 + E.float_add e1 e2 + | _ -> E.unknown_primitive prim + end + | Psubint | Psubbint _ + -> + begin match args with + | [e1;e2] -> + E.int32_minus e1 e2 | _ -> E.unknown_primitive prim end - - | (Pmulint | Pmulbint _ | Pmulfloat)-> + | Psubfloat + -> + begin match args with + | [e1;e2] -> + E.float_minus e1 e2 + | _ -> E.unknown_primitive prim + end + | Pmulint | Pmulbint _ + -> begin match args with | [e1; e2] -> - E.mul e1 e2 - | _ -> E.unknown_primitive prim end + E.int32_mul e1 e2 + | _ -> E.unknown_primitive prim + end + | Pmulfloat + -> + begin match args with + | [e1; e2] -> + E.float_mul e1 e2 + | _ -> E.unknown_primitive prim + end | Pdivfloat -> begin match args with (* TODO: see ocamljs -- assertion*) - | [e1;e2] -> - (E.div e1 e2) (** 32 bits *) + | [e1;e2] -> E.float_div e1 e2 | _ -> E.unknown_primitive prim end | ( Pdivint | Pdivbint _)-> begin match args with (* TODO: see ocamljs -- assertion*) | [e1;e2] -> - E.bin Bor (E.div e1 e2) (E.int 0) (** 32 bits *) + E.int32_div e1 e2 (** 32 bits *) | _ -> E.unknown_primitive prim end - | (Pmodint | Pmodbint _) -> + | Pmodint | Pmodbint _ -> begin match args with | [e1; e2] -> - E.bin Mod e1 e2 - | _ -> E.unknown_primitive prim end - - | (Plslint | Plslbint _) -> + E.int32_mod e1 e2 + | _ -> E.unknown_primitive prim + end + | Plslint | Plslbint _ -> begin match args with | [e1;e2] -> - E.bin Lsl e1 e2 - | _ -> E.unknown_primitive prim end + E.int32_lsl e1 e2 + | _ -> E.unknown_primitive prim + end | (Plsrint | Plsrbint _) -> begin match args with | [e1; e2] -> - E.bin Lsr e1 e2 + E.int32_lsr e1 e2 | _ -> E.unknown_primitive prim end | (Pasrint | Pasrbint _) -> begin match args with | [e1;e2] -> - E.bin Asr e1 e2 + E.int32_asr e1 e2 | _ -> E.unknown_primitive prim end - | (Pandint | Pandbint _)-> + | Pandint | Pandbint _-> begin match args with | [e1;e2] -> - E.bin Band e1 e2 + E.int32_band e1 e2 | _ -> E.unknown_primitive prim end - | (Porint | Porbint _) -> + | Porint | Porbint _ -> begin match args with | [e1;e2] -> - E.bin Bor e1 e2 + E.int32_bor e1 e2 | _ -> E.unknown_primitive prim end - | (Pxorint | Pxorbint _) -> + | Pxorint | Pxorbint _ -> begin match args with | [e1;e2] -> - E.bin Bxor e1 e2 + E.int32_bxor e1 e2 | _ -> E.unknown_primitive prim end - | Psequand -> + + | Psequand -> (* TODO: rhs is possibly a tail call *) begin match args with | [e1;e2] -> E.and_ e1 e2 | _ -> E.unknown_primitive prim end - | Psequor -> (* rhs is possibly a tail call *) + | Psequor -> (* TODO: rhs is possibly a tail call *) begin match args with | [e1;e2] -> E.or_ e1 e2 @@ -152,10 +177,14 @@ let translate end | Pisout -> begin match args with - (** learn from js_of_ocaml - > range and < 0 + (* predicate: [x > range and x < 0 ] + can be simplified if x is positive , x > range + if x is negative, fine, its uint is for sure larger than range, + the output is not readable, we might change it back. *) - | [range; e] -> E.lt range (E.bin Lsr e (E.int 0)) + | [range; e] -> + (* E.and_ (E.lt) *) + E.lt range (E.to_uint32 e) | _ -> E.unknown_primitive prim end | Pidentity -> diff --git a/jscomp/lam_dispatch_primitive.ml b/jscomp/lam_dispatch_primitive.ml index c60e2728a7..cc721d3129 100644 --- a/jscomp/lam_dispatch_primitive.ml +++ b/jscomp/lam_dispatch_primitive.ml @@ -79,7 +79,7 @@ let query (prim : Lam_compile_env.primitive_description) end |"caml_div_float" -> begin match args with - | [e0;e1] -> E.bin Div e0 e1 + | [e0;e1] -> E.float_div e0 e1 | _ -> assert false end |"caml_sub_float" -> @@ -181,12 +181,12 @@ let query (prim : Lam_compile_env.primitive_description) end | "caml_int32_div"| "caml_nativeint_div" -> begin match args with - | [e0;e1] -> E.bin Bor (E.bin Div e0 e1) (E.int 0) + | [e0;e1] -> E.int32_div e0 e1 | _ -> assert false end | "caml_int32_mul" | "caml_nativeint_mul" -> begin match args with - | [e0;e1] -> E.bin Mul e0 e1 + | [e0;e1] -> E.int32_mul e0 e1 | _ -> assert false end | "caml_int32_of_int" | "caml_nativeint_of_int" @@ -197,7 +197,7 @@ let query (prim : Lam_compile_env.primitive_description) end | "caml_int32_of_float" | "caml_int_of_float"|"caml_nativeint_of_float" -> begin match args with - | [e] -> E.bin Bor e (E.int 0) (* (|) *) + | [e] -> E.to_int32 e | _ -> assert false end | "caml_int32_to_float" | "caml_int32_to_int" | "caml_nativeint_to_int" @@ -213,18 +213,18 @@ let query (prim : Lam_compile_env.primitive_description) end | "caml_int32_xor" | "caml_nativeint_xor" -> begin match args with - | [e0; e1] -> E.bin Bxor e0 e1 + | [e0; e1] -> E.int32_bxor e0 e1 | _ -> assert false end | "caml_int32_and" | "caml_nativeint_and" -> begin match args with - | [e0;e1] -> E.bin Band e0 e1 + | [e0;e1] -> E.int32_band e0 e1 | _ -> assert false end | "caml_int32_or" | "caml_nativeint_or" -> begin match args with - | [e0;e1] -> E.bin Bor e0 e1 + | [e0;e1] -> E.int32_bor e0 e1 | _ -> assert false end | "caml_le_float" -> @@ -246,12 +246,12 @@ let query (prim : Lam_compile_env.primitive_description) end | "caml_neq_float" -> begin match args with - | [e0;e1] -> E.bin NotEqEq e0 e1 + | [e0;e1] -> E.float_notequal e0 e1 | _ -> assert false end | "caml_mul_float" -> begin match args with - | [e0; e1] -> E.bin Mul e0 e1 + | [e0; e1] -> E.float_mul e0 e1 | _ -> assert false end | "caml_int64_bits_of_float" diff --git a/jscomp/stdlib/pervasives.js b/jscomp/stdlib/pervasives.js index 5a363891a6..756eb5b41f 100644 --- a/jscomp/stdlib/pervasives.js +++ b/jscomp/stdlib/pervasives.js @@ -45,7 +45,7 @@ function lnot(x) { return x ^ -1; } -var max_int = (-1 >>> 1); +var max_int = 2147483647; var min_int = max_int + 1; diff --git a/jscomp/stdlib/sys.js b/jscomp/stdlib/sys.js index 48cc7014c9..8f13b7bdf8 100644 --- a/jscomp/stdlib/sys.js +++ b/jscomp/stdlib/sys.js @@ -19,7 +19,7 @@ var cygwin = /* false */0; var max_array_length = 4294967295; -var max_string_length = (word_size / 8 | 0) * max_array_length - 1; +var max_string_length = 4294967295; var interactive = [ 0, diff --git a/jscomp/test/.depend b/jscomp/test/.depend index 7b1c721775..4f0ee28158 100644 --- a/jscomp/test/.depend +++ b/jscomp/test/.depend @@ -60,6 +60,8 @@ demo.cmo : demo.cmx : demo_page.cmo : demo_page.cmx : +empty_obj.cmo : +empty_obj.cmx : equal_exception_test.cmo : ../stdlib/string.cmi mt.cmo ../stdlib/bytes.cmi equal_exception_test.cmx : ../stdlib/string.cmx mt.cmx ../stdlib/bytes.cmx ext_bytes.cmo : ../stdlib/bytes.cmi @@ -392,6 +394,8 @@ demo.cmo : demo.cmo : demo_page.cmo : demo_page.cmo : +empty_obj.cmo : +empty_obj.cmo : equal_exception_test.cmo : ../stdlib/string.cmi mt.cmo ../stdlib/bytes.cmi equal_exception_test.cmo : ../stdlib/string.cmo mt.cmo ../stdlib/bytes.cmo ext_bytes.cmo : ../stdlib/bytes.cmi diff --git a/jscomp/test/buffer_test.js b/jscomp/test/buffer_test.js index f8bf9d3105..0a9eae7ef5 100644 --- a/jscomp/test/buffer_test.js +++ b/jscomp/test/buffer_test.js @@ -92,7 +92,7 @@ var suites = [ suites_002 ]; -Mt.from_suites("buffer", suites); +Mt.from_suites("buffer_test.ml", suites); exports.v = v; exports.bytes_equal = bytes_equal; diff --git a/jscomp/test/buffer_test.ml b/jscomp/test/buffer_test.ml index 4116b10865..307c168472 100644 --- a/jscomp/test/buffer_test.ml +++ b/jscomp/test/buffer_test.ml @@ -25,4 +25,4 @@ let suites = [ ) ] open Mt -;; from_suites "buffer" suites +;; from_suites __FILE__ suites diff --git a/jscomp/test/empty_obj.d.ts b/jscomp/test/empty_obj.d.ts new file mode 100644 index 0000000000..89ba82deb4 --- /dev/null +++ b/jscomp/test/empty_obj.d.ts @@ -0,0 +1,2 @@ +export var v: any ; + diff --git a/jscomp/test/empty_obj.js b/jscomp/test/empty_obj.js new file mode 100644 index 0000000000..55440adc47 --- /dev/null +++ b/jscomp/test/empty_obj.js @@ -0,0 +1,16 @@ +// Generated CODE, PLEASE EDIT WITH CARE +"use strict"; +var CamlinternalOO = require("../stdlib/camlinternalOO"); + +var $$class = CamlinternalOO.create_table(0); + +function obj_init() { + return CamlinternalOO.create_object_opt(0, $$class); +} + +CamlinternalOO.init_class($$class); + +var v = obj_init(0); + +exports.v = v; +/* class Not a pure module */ diff --git a/jscomp/test/empty_obj.ml b/jscomp/test/empty_obj.ml new file mode 100644 index 0000000000..5b3ab74c28 --- /dev/null +++ b/jscomp/test/empty_obj.ml @@ -0,0 +1,2 @@ +let v = object +end diff --git a/jscomp/test/test_per.js b/jscomp/test/test_per.js index c54692803a..88e3637661 100644 --- a/jscomp/test/test_per.js +++ b/jscomp/test/test_per.js @@ -46,7 +46,7 @@ function lnot(x) { return x ^ -1; } -var max_int = (-1 >>> 1); +var max_int = 2147483647; var min_int = max_int + 1;