Skip to content

Commit 09ba176

Browse files
committed
clean up Js_exp for bigint operations
1 parent 98224d6 commit 09ba176

File tree

3 files changed

+9
-29
lines changed

3 files changed

+9
-29
lines changed

jscomp/core/js_exp_make.ml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,17 +1260,7 @@ let rec int32_band ?comment (e1 : J.expression) (e2 : J.expression) :
12601260
(* let int32_bin ?comment op e1 e2 : J.expression = *)
12611261
(* {expression_desc = Int32_bin(op,e1, e2); comment} *)
12621262

1263-
let bigint_add ?comment (e1: t) (e2:t) = bin ?comment Plus e1 e2
1264-
1265-
let bigint_minus ?comment (e1: t) (e2: t) = bin ?comment Minus e1 e2
1266-
1267-
let bigint_mul ?comment (e1: t) (e2: t) = bin ?comment Mul e1 e2
1268-
1269-
let bigint_div ?comment (e1: t) (e2: t) = bin ?comment Div e1 e2
1270-
1271-
let bigint_mod ?comment (e1: t) (e2: t) = bin ?comment Mod e1 e2
1272-
1273-
let bigint_pow ?comment (e1: t) (e2: t) = bin ?comment Pow e1 e2
1263+
let bigint_op ?comment op (e1: t) (e2: t) = bin ?comment op e1 e2
12741264

12751265
let bigint_comp (cmp : Lam_compat.comparison) ?comment (e0: t) (e1: t) =
12761266
match (cmp, e0.expression_desc, e1.expression_desc) with

jscomp/core/js_exp_make.mli

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -276,17 +276,7 @@ val string_comp : Js_op.binop -> ?comment:string -> t -> t -> t
276276

277277
val float_comp : Lam_compat.comparison -> ?comment:string -> t -> t -> t
278278

279-
val bigint_add : ?comment: string -> t -> t -> t
280-
281-
val bigint_minus : ?comment: string -> t-> t -> t
282-
283-
val bigint_mul : ?comment: string -> t -> t -> t
284-
285-
val bigint_div : ?comment: string -> t -> t -> t
286-
287-
val bigint_mod : ?comment: string -> t -> t -> t
288-
289-
val bigint_pow : ?comment: string -> t -> t -> t
279+
val bigint_op : ?comment: string -> Js_op.binop -> t -> t -> t
290280

291281
val bigint_comp : Lam_compat.comparison -> ?comment:string -> t -> t -> t
292282

jscomp/core/lam_compile_primitive.ml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ let translate output_prefix loc (cxt : Lam_compile_context.t)
183183
E.int32_minus E.zero_int_literal (Ext_list.singleton_exn args)
184184
| Pnegint64 -> Js_long.neg args
185185
| Pnegfloat -> E.float_minus E.zero_float_lit (Ext_list.singleton_exn args)
186-
| Pnegbigint -> E.bigint_minus E.zero_bigint_literal (Ext_list.singleton_exn args)
186+
| Pnegbigint -> E.bigint_op Minus E.zero_bigint_literal (Ext_list.singleton_exn args)
187187
(* Negate boxed int end*)
188188
(* Int addition and subtraction *)
189189
| Paddint -> (
@@ -192,36 +192,36 @@ let translate output_prefix loc (cxt : Lam_compile_context.t)
192192
| Paddfloat -> (
193193
match args with [ e1; e2 ] -> E.float_add e1 e2 | _ -> assert false)
194194
| Paddbigint -> (
195-
match args with [ e1; e2 ] -> E.bigint_add e1 e2 | _ -> assert false)
195+
match args with [ e1; e2 ] -> E.bigint_op Plus e1 e2 | _ -> assert false)
196196
| Psubint -> (
197197
match args with [ e1; e2 ] -> E.int32_minus e1 e2 | _ -> assert false)
198198
| Psubint64 -> Js_long.sub args
199199
| Psubfloat -> (
200200
match args with [ e1; e2 ] -> E.float_minus e1 e2 | _ -> assert false)
201201
| Psubbigint -> (
202-
match args with [ e1; e2 ] -> E.bigint_minus e1 e2 | _ -> assert false)
202+
match args with [ e1; e2 ] -> E.bigint_op Minus e1 e2 | _ -> assert false)
203203
| Pmulint -> (
204204
match args with [ e1; e2 ] -> E.int32_mul e1 e2 | _ -> assert false)
205205
| Pmulint64 -> Js_long.mul args
206206
| Pmulfloat -> (
207207
match args with [ e1; e2 ] -> E.float_mul e1 e2 | _ -> assert false)
208208
| Pmulbigint -> (
209-
match args with [ e1; e2 ] -> E.bigint_mul e1 e2 | _ -> assert false)
209+
match args with [ e1; e2 ] -> E.bigint_op Mul e1 e2 | _ -> assert false)
210210
| Pdivfloat -> (
211211
match args with [ e1; e2 ] -> E.float_div e1 e2 | _ -> assert false)
212212
| Pdivint -> (
213213
match args with
214214
| [ e1; e2 ] -> E.int32_div ~checked:!Js_config.check_div_by_zero e1 e2
215215
| _ -> assert false)
216216
| Pdivint64 -> Js_long.div args
217-
| Pdivbigint -> (match args with [ e1; e2 ] -> E.bigint_div e1 e2 | _ -> assert false)
217+
| Pdivbigint -> (match args with [ e1; e2 ] -> E.bigint_op Div e1 e2 | _ -> assert false)
218218
| Pmodint -> (
219219
match args with
220220
| [ e1; e2 ] -> E.int32_mod ~checked:!Js_config.check_div_by_zero e1 e2
221221
| _ -> assert false)
222222
| Pmodint64 -> Js_long.mod_ args
223-
| Pmodbigint -> (match args with [ e1; e2 ] -> E.bigint_mod e1 e2 | _ -> assert false)
224-
| Ppowbigint -> (match args with [ e1; e2 ] -> E.bigint_pow e1 e2 | _ -> assert false)
223+
| Pmodbigint -> (match args with [ e1; e2 ] -> E.bigint_op Mod e1 e2 | _ -> assert false)
224+
| Ppowbigint -> (match args with [ e1; e2 ] -> E.bigint_op Pow e1 e2 | _ -> assert false)
225225
| Plslint -> (
226226
match args with [ e1; e2 ] -> E.int32_lsl e1 e2 | _ -> assert false)
227227
| Plslint64 -> Js_long.lsl_ args

0 commit comments

Comments
 (0)