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 shift(<<, >>, >>>) operator #7183

Draft
wants to merge 4 commits 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
12 changes: 12 additions & 0 deletions compiler/ml/unified_ops.ml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@ let entries =
string = None;
};
};
{
path = builtin "<<";
name = "%lsl";
form = Binary;
specialization = {
int = Plslint;
bool = None;
float = None;
bigint = Some Plslbigint;
string = None;
};
};
{
path = builtin "mod";
name = "%mod";
Expand Down
11 changes: 6 additions & 5 deletions compiler/syntax/src/res_parsetree_viewer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,11 @@ let operator_precedence operator =
| "||" -> 2
| "&&" -> 3
| "=" | "==" | "<" | ">" | "!=" | "<>" | "!==" | "<=" | ">=" | "|>" -> 4
| "+" | "+." | "-" | "-." | "^" -> 5
| "*" | "*." | "/" | "/." | "%" -> 6
| "**" -> 7
| "#" | "##" | "|." | "|.u" -> 8
| "<<" | ">>" | ">>>" -> 5
| "+" | "+." | "-" | "-." | "^" -> 6
| "*" | "*." | "/" | "/." | "%" -> 7
| "**" -> 8
| "#" | "##" | "|." | "|.u" -> 9
| _ -> 0

let is_unary_operator operator =
Expand All @@ -326,7 +327,7 @@ let is_binary_operator operator =
match operator with
| ":=" | "||" | "&&" | "=" | "==" | "<" | ">" | "!=" | "!==" | "<=" | ">="
| "|>" | "+" | "+." | "-" | "-." | "^" | "*" | "*." | "/" | "/." | "**" | "|."
| "|.u" | "<>" | "%" ->
| "|.u" | "<>" | "%" | "<<" ->
true
| _ -> false

Expand Down
4 changes: 3 additions & 1 deletion compiler/syntax/src/res_token.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type t =
| ColonGreaterThan
| GreaterThan
| LessThan
| LessThanLessThan
| LessThanSlash
| Hash
| HashEqual
Expand Down Expand Up @@ -105,7 +106,7 @@ let precedence = function
| Equal | EqualEqual | EqualEqualEqual | LessThan | GreaterThan | BangEqual
| BangEqualEqual | LessEqual | GreaterEqual | BarGreater ->
4
| Plus | PlusDot | Minus | MinusDot | PlusPlus -> 5
| Plus | PlusDot | Minus | MinusDot | PlusPlus | LessThanLessThan -> 5
| Asterisk | AsteriskDot | Forwardslash | ForwardslashDot | Percent -> 6
| Exponentiation -> 7
| MinusGreater -> 8
Expand Down Expand Up @@ -163,6 +164,7 @@ let to_string = function
| HashEqual -> "#="
| GreaterThan -> ">"
| LessThan -> "<"
| LessThanLessThan -> "<<"
| LessThanSlash -> "</"
| Asterisk -> "*"
| AsteriskDot -> "*."
Expand Down
1 change: 1 addition & 0 deletions runtime/Pervasives.res
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ external \"-": ('a, 'a) => 'a = "%sub"
external \"*": ('a, 'a) => 'a = "%mul"
external \"/": ('a, 'a) => 'a = "%div"
external \"%": ('a, 'a) => 'a = "%mod"
external \"<<": ('a, 'a) => 'a = "%lsl"
external mod: ('a, 'a) => 'a = "%mod"

/* Comparisons */
Expand Down
1 change: 1 addition & 0 deletions runtime/Pervasives_mini.res
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ external \"-": (int, int) => int = "%subint"
external \"*": (int, int) => int = "%mulint"
external \"/": (int, int) => int = "%divint"
external \"%": (int, int) => int = "%modint"
external \"<<": (int, int) => int = "%lslint"
external mod: (int, int) => int = "%modint"

/* Comparisons */
Expand Down