Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add add lxor (^) unified operator #7216

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions compiler/ml/unified_ops.ml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,19 @@ let entries =
string = None;
};
};
{
path = builtin "^";
name = "%xor";
form = Binary;
specialization =
{
int = Pxorint;
bool = None;
float = None;
bigint = Some Pxorbigint;
string = None;
};
};
|]

let index_by_path =
Expand Down
1 change: 1 addition & 0 deletions runtime/Pervasives.res
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ external \"*": ('a, 'a) => 'a = "%mul"
external \"/": ('a, 'a) => 'a = "%div"
external \"%": ('a, 'a) => 'a = "%mod"
external mod: ('a, 'a) => 'a = "%mod"
external \"^": ('a, 'a) => 'a = "%xor"

/* Comparisons */
/* Note: Later comparisons will be converted to unified operations too */
Expand Down
1 change: 1 addition & 0 deletions runtime/Pervasives_mini.res
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ external \"*": (int, int) => int = "%mulint"
external \"/": (int, int) => int = "%divint"
external \"%": (int, int) => int = "%modint"
external mod: (int, int) => int = "%modint"
external \"^": (int, int) => int = "%xorint"

/* Comparisons */
/* Note: Later comparisons will be converted to unified operations too */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ let x = z |> @attr while condition { () }
let x = a + -1 + -2
let x = a + @attr -1 + @attr -2
let x = a % a == 0
let x = a ^ a == 0

// should be interpreted as binary expression not prefix op
let x = a -b
Expand Down
1 change: 1 addition & 0 deletions tests/syntax_tests/data/printer/expr/binary.res
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ let () = (x: int) |> (print_int: int => unit)
x + y / z
x / y + z
x % y * z
x ^ y + z
100 * x / total
2 / 3 * 10 / 2 + 2
let rotateX = ((range / rect.height) * refY - range / 2) * getXMultiplication(rect.width)
Expand Down
1 change: 1 addition & 0 deletions tests/tests/src/belt_int_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ describe(__MODULE__, () => {
eq(__LOC__, 2 * 3, 6)
eq(__LOC__, 2 / 3, 0)
eq(__LOC__, 2 % 2, 0)
eq(__LOC__, 2 ^ 3, 1)
})
})
2 changes: 2 additions & 0 deletions tests/tests/src/unified_ops_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ let case2 = (a, b) => a + "test" + b

let even = n => n % 2 == 0
let odd = n => n % 2 == 1

let lxor = (a, b: int) => a ^ b
Loading