Skip to content

Commit 2c05e5a

Browse files
committed
migrate other arithmetic operators
1 parent 19e01b7 commit 2c05e5a

File tree

2 files changed

+71
-5
lines changed

2 files changed

+71
-5
lines changed

compiler/ml/unified_ops.ml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,32 @@ let builtin x = Primitive_modules.pervasives ^ "." ^ x
5656

5757
let entries =
5858
[|
59+
{
60+
path = builtin "~+";
61+
name = "%pos";
62+
form = Unary;
63+
specialization =
64+
{
65+
int = Pidentity;
66+
bool = None;
67+
float = Some Pidentity;
68+
bigint = Some Pidentity;
69+
string = None;
70+
};
71+
};
72+
{
73+
path = builtin "~-";
74+
name = "%neg";
75+
form = Unary;
76+
specialization =
77+
{
78+
int = Pnegint;
79+
bool = None;
80+
float = Some Pnegfloat;
81+
bigint = Some Pnegbigint;
82+
string = None;
83+
};
84+
};
5985
{
6086
path = builtin "+";
6187
name = "%add";
@@ -82,6 +108,45 @@ let entries =
82108
string = None;
83109
};
84110
};
111+
{
112+
path = builtin "*";
113+
name = "%mul";
114+
form = Binary;
115+
specialization =
116+
{
117+
int = Pmulint;
118+
bool = None;
119+
float = Some Pmulfloat;
120+
bigint = Some Pmulbigint;
121+
string = None;
122+
};
123+
};
124+
{
125+
path = builtin "/";
126+
name = "%div";
127+
form = Binary;
128+
specialization =
129+
{
130+
int = Pdivint Safe;
131+
bool = None;
132+
float = Some Pdivfloat;
133+
bigint = Some Pdivbigint;
134+
string = None;
135+
};
136+
};
137+
{
138+
path = builtin "mod";
139+
name = "%mod";
140+
form = Binary;
141+
specialization =
142+
{
143+
int = Pmodint Safe;
144+
bool = None;
145+
float = Some Pmodfloat;
146+
bigint = Some Pmodbigint;
147+
string = None;
148+
};
149+
};
85150
|]
86151

87152
let index_by_path =

runtime/Pervasives.res

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,14 @@ external __POS_OF__: 'a => ((string, int, int, int), 'a) = "%loc_POS"
4242

4343
/* Unified operations */
4444

45+
external \"~+": 'a => 'a = "%pos"
46+
external \"~-": 'a => 'a = "%neg"
47+
4548
external \"+": ('a, 'a) => 'a = "%add"
4649
external \"-": ('a, 'a) => 'a = "%sub"
50+
external \"*": ('a, 'a) => 'a = "%mul"
51+
external \"/": ('a, 'a) => 'a = "%div"
52+
external mod: ('a, 'a) => 'a = "%mod"
4753

4854
/* Comparisons */
4955
/* Note: Later comparisons will be converted to unified operations too */
@@ -70,13 +76,8 @@ external \"||": (bool, bool) => bool = "%sequor"
7076

7177
/* Integer operations */
7278

73-
external \"~-": int => int = "%negint"
74-
external \"~+": int => int = "%identity"
7579
external succ: int => int = "%succint"
7680
external pred: int => int = "%predint"
77-
external \"*": (int, int) => int = "%mulint"
78-
external \"/": (int, int) => int = "%divint"
79-
external mod: (int, int) => int = "%modint"
8081

8182
@deprecated("Use Core instead. This will be removed in v13")
8283
let abs = x =>

0 commit comments

Comments
 (0)