Skip to content

Commit 81fef79

Browse files
committed
added %modfloat primitive, added Pervasives.mod_float compat
1 parent 0eaf76e commit 81fef79

13 files changed

+22
-10
lines changed

jscomp/core/lam_analysis.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
6565
| Pintorder | Pintmin | Pintmax
6666
(* float primitives *)
6767
| Pintoffloat | Pfloatofint | Pnegfloat
68-
| Paddfloat | Psubfloat | Pmulfloat | Pdivfloat
68+
| Paddfloat | Psubfloat | Pmulfloat | Pdivfloat | Pmodfloat
6969
| Pfloatcomp _ | Pjscomp _ | Pfloatorder | Pfloatmin | Pfloatmax
7070
(* bigint primitives *)
7171
| Pnegbigint | Paddbigint | Psubbigint | Pmulbigint | Ppowbigint

jscomp/core/lam_compile_primitive.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ let translate output_prefix loc (cxt : Lam_compile_context.t)
204204
match args with [ e1; e2 ] -> E.bigint_op Mul e1 e2 | _ -> assert false)
205205
| Pdivfloat -> (
206206
match args with [ e1; e2 ] -> E.float_div e1 e2 | _ -> assert false)
207+
| Pmodfloat -> (
208+
match args with [ e1; e2 ] -> E.float_mod e1 e2 | _ -> assert false)
207209
| Pdivint -> (
208210
match args with
209211
| [ e1; e2 ] -> E.int32_div ~checked:!Js_config.check_div_by_zero e1 e2

jscomp/core/lam_convert.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t =
287287
| Psubfloat -> prim ~primitive:Psubfloat ~args loc
288288
| Pmulfloat -> prim ~primitive:Pmulfloat ~args loc
289289
| Pdivfloat -> prim ~primitive:Pdivfloat ~args loc
290+
| Pmodfloat -> prim ~primitive:Pmodfloat ~args loc
290291
| Pfloatorder -> prim ~primitive:Pfloatorder ~args loc
291292
| Pfloatmin -> prim ~primitive:Pfloatmin ~args loc
292293
| Pfloatmax -> prim ~primitive:Pfloatmax ~args loc

jscomp/core/lam_primitive.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ type t =
102102
| Psubfloat
103103
| Pmulfloat
104104
| Pdivfloat
105+
| Pmodfloat
105106
| Pfloatcomp of Lam_compat.comparison
106107
| Pfloatorder
107108
| Pfloatmin
@@ -246,6 +247,7 @@ let eq_primitive_approx (lhs : t) (rhs : t) =
246247
| Psubfloat
247248
| Pmulfloat
248249
| Pdivfloat
250+
| Pmodfloat
249251
| Pfloatorder
250252
| Pfloatmin
251253
| Pfloatmax

jscomp/core/lam_primitive.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ type t =
9292
| Psubfloat
9393
| Pmulfloat
9494
| Pdivfloat
95+
| Pmodfloat
9596
| Pfloatcomp of Lam_compat.comparison
9697
| Pfloatorder
9798
| Pfloatmin

jscomp/core/lam_print.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ let primitive ppf (prim : Lam_primitive.t) =
140140
| Psubfloat -> fprintf ppf "-."
141141
| Pmulfloat -> fprintf ppf "*."
142142
| Pdivfloat -> fprintf ppf "/."
143+
| Pmodfloat -> fprintf ppf "mod"
143144
| Pfloatcomp Ceq -> fprintf ppf "==."
144145
| Pfloatcomp Cneq -> fprintf ppf "!=."
145146
| Pfloatcomp Clt -> fprintf ppf "<."

jscomp/ml/lambda.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ type primitive =
221221
| Poffsetref of int
222222
(* Float operations *)
223223
| Pintoffloat | Pfloatofint
224-
| Pnegfloat | Pabsfloat
224+
| Pnegfloat | Pabsfloat | Pmodfloat
225225
| Paddfloat | Psubfloat | Pmulfloat | Pdivfloat
226226
| Pfloatcomp of comparison
227227
| Pfloatorder | Pfloatmin | Pfloatmax

jscomp/ml/lambda.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ type primitive =
196196
| Poffsetref of int
197197
(* Float operations *)
198198
| Pintoffloat | Pfloatofint
199-
| Pnegfloat | Pabsfloat
199+
| Pnegfloat | Pabsfloat | Pmodfloat
200200
| Paddfloat | Psubfloat | Pmulfloat | Pdivfloat
201201
| Pfloatcomp of comparison
202202
| Pfloatorder | Pfloatmin | Pfloatmax

jscomp/ml/printlambda.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ let primitive ppf = function
179179
| Psubfloat -> fprintf ppf "-."
180180
| Pmulfloat -> fprintf ppf "*."
181181
| Pdivfloat -> fprintf ppf "/."
182+
| Pmodfloat -> fprintf ppf "mod"
182183
| Pfloatcomp(Ceq) -> fprintf ppf "==."
183184
| Pfloatcomp(Cneq) -> fprintf ppf "!=."
184185
| Pfloatcomp(Clt) -> fprintf ppf "<."

jscomp/ml/translcore.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ let primitives_table =
280280
("%subfloat", Psubfloat);
281281
("%mulfloat", Pmulfloat);
282282
("%divfloat", Pdivfloat);
283+
("%modfloat", Pmodfloat);
283284
("%eqfloat", Pfloatcomp Ceq);
284285
("%noteqfloat", Pfloatcomp Cneq);
285286
("%ltfloat", Pfloatcomp Clt);

jscomp/runtime/pervasives.res

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ module Pervasives = {
165165
@deprecated("Use Core or Js instead. This will be removed in v13") @val @scope("Math")
166166
external abs_float: float => float = "abs"
167167

168+
@deprecated("Use Core instead. This will be removed in v13")
169+
external mod_float: float => float = "%modfloat"
170+
168171
@deprecated("Use Core instead. This will be removed in v13")
169172
external float: int => float = "%floatofint"
170173

jscomp/runtime/release.ninja

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,31 @@ rule cc_cmi
1010

1111
o runtime/pervasives.cmj runtime/pervasives.cmi : cc runtime/pervasives.res
1212
bsc_flags = $bsc_flags -nopervasives
13-
o runtime/array.cmj : cc_cmi runtime/array.res | runtime/array.cmi runtime/list.cmj
13+
o runtime/array.cmj : cc_cmi runtime/array.res | runtime/array.cmi runtime/list.cmj runtime/primitive_array.cmj runtime/primitive_exceptions.cmj
1414
o runtime/array.cmi : cc runtime/array.resi | runtime/pervasives.cmi runtime/pervasives.cmj
1515
o runtime/char.cmj : cc_cmi runtime/char.res | runtime/char.cmi runtime/primitive_array_extern.cmj
1616
o runtime/char.cmi : cc runtime/char.resi | runtime/pervasives.cmi runtime/pervasives.cmj
17-
o runtime/hashtbl.cmj : cc_cmi runtime/hashtbl.res | runtime/hashtbl.cmi
17+
o runtime/hashtbl.cmj : cc_cmi runtime/hashtbl.res | runtime/hashtbl.cmi runtime/primitive_hash.cmj
1818
o runtime/hashtbl.cmi : cc runtime/hashtbl.resi | runtime/pervasives.cmi runtime/pervasives.cmj
1919
o runtime/lazy.cmj : cc_cmi runtime/lazy.res | runtime/lazy.cmi runtime/primitive_lazy.cmj
2020
o runtime/lazy.cmi : cc runtime/lazy.resi | runtime/pervasives.cmi runtime/pervasives.cmj
21-
o runtime/list.cmj : cc_cmi runtime/list.res | runtime/list.cmi
21+
o runtime/list.cmj : cc_cmi runtime/list.res | runtime/list.cmi runtime/pervasives.cmj runtime/primitive_option.cmj
2222
o runtime/list.cmi : cc runtime/list.resi | runtime/pervasives.cmi runtime/pervasives.cmj
2323
o runtime/primitive_curry.cmj : cc_cmi runtime/primitive_curry.res | runtime/array.cmj runtime/obj.cmj runtime/primitive_array_extern.cmj runtime/primitive_curry.cmi runtime/primitive_js_extern.cmj runtime/primitive_object_extern.cmj
2424
o runtime/primitive_curry.cmi : cc runtime/primitive_curry.resi | runtime/pervasives.cmi runtime/pervasives.cmj
2525
o runtime/primitive_exceptions.cmj : cc_cmi runtime/primitive_exceptions.res | runtime/obj.cmj runtime/primitive_exceptions.cmi runtime/primitive_js_extern.cmj runtime/primitive_object_extern.cmj
2626
o runtime/primitive_exceptions.cmi : cc runtime/primitive_exceptions.resi | runtime/pervasives.cmi runtime/pervasives.cmj
2727
o runtime/primitive_hash.cmj : cc_cmi runtime/primitive_hash.res | runtime/obj.cmj runtime/primitive_float_extern.cmj runtime/primitive_hash.cmi runtime/primitive_js_extern.cmj runtime/primitive_object_extern.cmj runtime/primitive_string_extern.cmj runtime/string.cmj
2828
o runtime/primitive_hash.cmi : cc runtime/primitive_hash.resi | runtime/pervasives.cmi runtime/pervasives.cmj runtime/primitive_object.cmi
29-
o runtime/primitive_lazy.cmj : cc_cmi runtime/primitive_lazy.res | runtime/primitive_lazy.cmi
29+
o runtime/primitive_lazy.cmj : cc_cmi runtime/primitive_lazy.res | runtime/primitive_exceptions.cmj runtime/primitive_lazy.cmi
3030
o runtime/primitive_lazy.cmi : cc runtime/primitive_lazy.resi | runtime/pervasives.cmi runtime/pervasives.cmj
3131
o runtime/primitive_module.cmj : cc_cmi runtime/primitive_module.res | runtime/array.cmj runtime/lazy.cmj runtime/obj.cmj runtime/primitive_array_extern.cmj runtime/primitive_module.cmi runtime/primitive_object_extern.cmj
3232
o runtime/primitive_module.cmi : cc runtime/primitive_module.resi | runtime/pervasives.cmi runtime/pervasives.cmj runtime/primitive_object.cmi
33-
o runtime/primitive_object.cmj : cc_cmi runtime/primitive_object.res | runtime/array.cmj runtime/primitive_array_extern.cmj runtime/primitive_js_extern.cmj runtime/primitive_object.cmi runtime/primitive_object_extern.cmj runtime/primitive_option.cmj
33+
o runtime/primitive_object.cmj : cc_cmi runtime/primitive_object.res | runtime/array.cmj runtime/primitive_array_extern.cmj runtime/primitive_bool.cmj runtime/primitive_float.cmj runtime/primitive_int.cmj runtime/primitive_js_extern.cmj runtime/primitive_object.cmi runtime/primitive_object_extern.cmj runtime/primitive_option.cmj runtime/primitive_string.cmj
3434
o runtime/primitive_object.cmi : cc runtime/primitive_object.resi | runtime/pervasives.cmi runtime/pervasives.cmj runtime/primitive_object_extern.cmj
3535
o runtime/primitive_option.cmj : cc_cmi runtime/primitive_option.res | runtime/primitive_js_extern.cmj runtime/primitive_object_extern.cmj runtime/primitive_option.cmi
3636
o runtime/primitive_option.cmi : cc runtime/primitive_option.resi | runtime/pervasives.cmi runtime/pervasives.cmj runtime/primitive_js_extern.cmj runtime/primitive_object_extern.cmj
37-
o runtime/string.cmj : cc_cmi runtime/string.res | runtime/array.cmj runtime/char.cmj runtime/primitive_string_extern.cmj runtime/string.cmi
37+
o runtime/string.cmj : cc_cmi runtime/string.res | runtime/array.cmj runtime/char.cmj runtime/primitive_exceptions.cmj runtime/primitive_string_extern.cmj runtime/string.cmi
3838
o runtime/string.cmi : cc runtime/string.resi | runtime/pervasives.cmi runtime/pervasives.cmj
3939
o runtime/map.cmi runtime/map.cmj : cc runtime/map.res | runtime/pervasives.cmi runtime/pervasives.cmj
4040
o runtime/obj.cmi runtime/obj.cmj : cc runtime/obj.res | runtime/pervasives.cmi runtime/pervasives.cmj runtime/primitive_object_extern.cmj

jscomp/test/test_per.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ external ceil: float => float = "?ceil_float"
121121
external floor: float => float = "?floor_float"
122122
external abs_float: float => float = "%absfloat"
123123
external copysign: (float, float) => float = "?copysign_float"
124-
external mod_float: (float, float) => float = "?fmod_float"
124+
external mod_float: (float, float) => float = "%modfloat"
125125
external frexp: float => (float, int) = "?frexp_float"
126126
external ldexp: (float, int) => float = "?ldexp_float"
127127
external modf: float => (float, float) = "?modf_float"

0 commit comments

Comments
 (0)