17
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
19
* GNU Lesser General Public License for more details.
20
- *
20
+ *
21
21
* You should have received a copy of the GNU Lesser General Public License
22
22
* along with this program; if not, write to the Free Software
23
23
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
@@ -29,7 +29,7 @@ type t = J.expression
29
29
(*
30
30
[remove_pure_sub_exp x]
31
31
Remove pure part of the expression (minor optimization)
32
- and keep the non-pure part while preserve the semantics
32
+ and keep the non-pure part while preserve the semantics
33
33
(modulo return value)
34
34
It will return None if [x] is pure
35
35
*)
@@ -86,8 +86,8 @@ let runtime_var_dot ?comment (x : string) (e1 : string) : J.expression =
86
86
let ml_var_dot ?comment ?(dynamic_import = false ) (id : Ident.t ) e : J.expression =
87
87
{ expression_desc = Var (Qualified ({ id; kind = Ml ; dynamic_import }, Some e)); comment }
88
88
89
- (* *
90
- module as a value
89
+ (* *
90
+ module as a value
91
91
{[
92
92
var http = require("http")
93
93
]}
@@ -182,7 +182,7 @@ let instanceof ?comment (e0 : t) (e1: t) : t =
182
182
let is_array (e0 : t ) : t =
183
183
let f = str " Array.isArray" ~delim: DNoQuotes in
184
184
{ expression_desc = Call (f, [e0], Js_call_info. ml_full_call); comment= None }
185
-
185
+
186
186
let new_ ?comment e0 args : t =
187
187
{ expression_desc = New (e0, Some args); comment }
188
188
@@ -455,7 +455,7 @@ let assign_by_exp (e : t) index value : t =
455
455
| Array _
456
456
(*
457
457
Temporary block -- address not held
458
- Optimize cases like this which is really
458
+ Optimize cases like this which is really
459
459
rare {[
460
460
(ref x) := 3
461
461
]}
@@ -474,7 +474,7 @@ let record_assign (e : t) (pos : int32) (name : string) (value : t) =
474
474
| Array _
475
475
(*
476
476
Temporary block -- address not held
477
- Optimize cases like this which is really
477
+ Optimize cases like this which is really
478
478
rare {[
479
479
(ref x) := 3
480
480
]}
@@ -492,7 +492,7 @@ let extension_assign (e : t) (pos : int32) name (value : t) =
492
492
| Array _
493
493
(*
494
494
Temporary block -- address not held
495
- Optimize cases like this which is really
495
+ Optimize cases like this which is really
496
496
rare {[
497
497
(ref x) := 3
498
498
]}
@@ -809,7 +809,7 @@ let tag_type = function
809
809
| Ast_untagged_variants. String s -> str s ~delim: DStarJ
810
810
| Int i -> small_int i
811
811
| Float f -> float f
812
- | BigInt i ->
812
+ | BigInt i ->
813
813
let sign, i = Bigint_utils. parse_bigint i in
814
814
bigint sign i
815
815
| Bool b -> bool b
@@ -841,7 +841,7 @@ let rec emit_check (check : t Ast_untagged_variants.DynamicChecks.t) = match che
841
841
| IsInstanceOf (Array, x ) -> is_array (emit_check x)
842
842
| IsInstanceOf (instance , x ) ->
843
843
let instance_name = Ast_untagged_variants.Instance. to_string instance in
844
- instanceof (emit_check x) (str instance_name ~delim: DNoQuotes )
844
+ instanceof (emit_check x) (str instance_name ~delim: DNoQuotes )
845
845
| Not x -> not (emit_check x)
846
846
| Expr x -> x
847
847
@@ -1266,14 +1266,36 @@ let rec int32_band ?comment (e1 : J.expression) (e2 : J.expression) :
1266
1266
let bigint_op ?comment op (e1 : t ) (e2 : t ) = bin ?comment op e1 e2
1267
1267
1268
1268
let bigint_comp (cmp : Lam_compat.comparison ) ?comment (e0 : t ) (e1 : t ) =
1269
- bin ?comment (Lam_compile_util. jsop_of_comp cmp) e0 e1
1269
+ let normalize s =
1270
+ let len = String. length s in
1271
+ let buf = Buffer. create len in
1272
+ let trim = ref false in
1273
+ s |> String. iteri (fun i c -> (
1274
+ match (c, i, ! trim) with
1275
+ | ('0' , 0 , _ ) -> trim := true
1276
+ | ('0' , _ , true ) -> ()
1277
+ | ('_' , _ , _ ) -> ()
1278
+ | _ -> (
1279
+ trim := false ;
1280
+ Buffer. add_char buf c
1281
+ )
1282
+ ));
1283
+ buf |> Buffer. to_bytes |> Bytes. to_string
1284
+ in
1285
+ match (cmp, e0.expression_desc, e1.expression_desc) with
1286
+ | Ceq , Number (BigInt { positive = p1 ; value = v1 } ), Number (BigInt { positive = p2 ; value = v2 } ) ->
1287
+ bool (p1 = p2 && String. equal (normalize v1) (normalize v2))
1288
+ | Cneq , Number (BigInt { positive = p1 ; value = v1 } ), Number (BigInt { positive = p2 ; value = v2 } ) ->
1289
+ not (bool (p1 = p2 && String. equal (normalize v1) (normalize v2)))
1290
+ | _ ->
1291
+ bin ?comment (Lam_compile_util. jsop_of_comp cmp) e0 e1
1270
1292
1271
1293
let bigint_div ~checked ?comment (e0 : t ) (e1 : t ) =
1272
1294
if checked then
1273
1295
runtime_call Js_runtime_modules. bigint " div" [e0; e1]
1274
1296
else
1275
1297
bigint_op ?comment Div e0 e1
1276
-
1298
+
1277
1299
let bigint_mod ~checked ?comment (e0 : t ) (e1 : t ) =
1278
1300
if checked then
1279
1301
runtime_call Js_runtime_modules. bigint " mod_" [e0; e1]
0 commit comments