Skip to content

Commit 95782dd

Browse files
MiryangJungcometkim
authored andcommitted
add add lxor (^) unified operator
1 parent 9c6856d commit 95782dd

File tree

7 files changed

+20
-0
lines changed

7 files changed

+20
-0
lines changed

compiler/ml/unified_ops.ml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,19 @@ let entries =
172172
float = Some Ppowfloat;
173173
bigint = Some Ppowbigint;
174174
string = None;
175+
}
176+
};
177+
{
178+
path = builtin "^";
179+
name = "%xor";
180+
form = Binary;
181+
specialization =
182+
{
183+
int = Pxorint;
184+
bool = None;
185+
float = None;
186+
bigint = Some Pxorbigint;
187+
string = None;
175188
};
176189
};
177190
|]

runtime/Pervasives.res

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ external \"/": ('a, 'a) => 'a = "%div"
5252
external \"%": ('a, 'a) => 'a = "%mod"
5353
external mod: ('a, 'a) => 'a = "%mod"
5454
external \"**": ('a, 'a) => 'a = "%pow"
55+
external \"^": ('a, 'a) => 'a = "%xor"
5556

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

runtime/Pervasives_mini.res

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ external \"/": (int, int) => int = "%divint"
3131
external \"%": (int, int) => int = "%modint"
3232
external mod: (int, int) => int = "%modint"
3333
external \"**": (int, int) => int = "%powint"
34+
external \"^": (int, int) => int = "%xorint"
3435

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

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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ let pow2 = 2. ** 2.
2626
let pow3 = 2n ** 2n
2727

2828
let pow_overflow = 2147483647 ** 2
29+
30+
let lxor = (a, b: int) => a ^ b

0 commit comments

Comments
 (0)