Skip to content

Commit d31cd0c

Browse files
committed
add add lxor (^) unified operator
1 parent 2470f75 commit d31cd0c

File tree

7 files changed

+20
-0
lines changed

7 files changed

+20
-0
lines changed

compiler/ml/unified_ops.ml

+13
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,19 @@ let entries =
161161
string = None;
162162
};
163163
};
164+
{
165+
path = builtin "^";
166+
name = "%xor";
167+
form = Binary;
168+
specialization =
169+
{
170+
int = Pxorint;
171+
bool = None;
172+
float = None;
173+
bigint = Some Pxorbigint;
174+
string = None;
175+
};
176+
};
164177
|]
165178

166179
let index_by_path =

runtime/Pervasives.res

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ external \"*": ('a, 'a) => 'a = "%mul"
5151
external \"/": ('a, 'a) => 'a = "%div"
5252
external \"%": ('a, 'a) => 'a = "%mod"
5353
external mod: ('a, 'a) => 'a = "%mod"
54+
external \"^": ('a, 'a) => 'a = "%xor"
5455

5556
/* Comparisons */
5657
/* Note: Later comparisons will be converted to unified operations too */

runtime/Pervasives_mini.res

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ external \"*": (int, int) => int = "%mulint"
3030
external \"/": (int, int) => int = "%divint"
3131
external \"%": (int, int) => int = "%modint"
3232
external mod: (int, int) => int = "%modint"
33+
external \"^": (int, int) => int = "%xorint"
3334

3435
/* Comparisons */
3536
/* Note: Later comparisons will be converted to unified operations too */

tests/syntax_tests/data/parsing/grammar/expressions/binary.res

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ let x = z |> @attr while condition { () }
2828
let x = a + -1 + -2
2929
let x = a + @attr -1 + @attr -2
3030
let x = a % a == 0
31+
let x = a ^ a == 0
3132

3233
// should be interpreted as binary expression not prefix op
3334
let x = a -b

tests/syntax_tests/data/printer/expr/binary.res

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ let () = (x: int) |> (print_int: int => unit)
5454
x + y / z
5555
x / y + z
5656
x % y * z
57+
x ^ y + z
5758
100 * x / total
5859
2 / 3 * 10 / 2 + 2
5960
let rotateX = ((range / rect.height) * refY - range / 2) * getXMultiplication(rect.width)

tests/tests/src/belt_int_test.res

+1
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ describe(__MODULE__, () => {
4141
eq(__LOC__, 2 * 3, 6)
4242
eq(__LOC__, 2 / 3, 0)
4343
eq(__LOC__, 2 % 2, 0)
44+
eq(__LOC__, 2 ^ 3, 1)
4445
})
4546
})

tests/tests/src/unified_ops_test.res

+2
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ let case2 = (a, b) => a + "test" + b
2020

2121
let even = n => n % 2 == 0
2222
let odd = n => n % 2 == 1
23+
24+
let lxor = (a, b: int) => a ^ b

0 commit comments

Comments
 (0)