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 2 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
2 changes: 1 addition & 1 deletion compiler/syntax/src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2221,7 +2221,7 @@ and parse_binary_expr ?(context = OrdinaryExpr) ?a p prec =
*
* First case is unary, second is a binary operator.
* See Scanner.isBinaryOp *)
| (Minus | MinusDot | LessThan | Percent)
| (Minus | MinusDot | LessThan | Percent | LessThanLessThan)
gwansikk marked this conversation as resolved.
Show resolved Hide resolved
when (not
(Scanner.is_binary_op p.scanner.src p.start_pos.pos_cnum
p.end_pos.pos_cnum))
Expand Down
4 changes: 2 additions & 2 deletions compiler/syntax/src/res_parsetree_viewer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ let operator_precedence operator =
| "||" -> 2
| "&&" -> 3
| "=" | "==" | "<" | ">" | "!=" | "<>" | "!==" | "<=" | ">=" | "|>" -> 4
| "+" | "+." | "-" | "-." | "^" -> 5
| "+" | "+." | "-" | "-." | "^" | "<<" -> 5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to dedicate precedence for shift operators, according to JS' one

| "*" | "*." | "/" | "/." | "%" -> 6
| "**" -> 7
| "#" | "##" | "|." | "|.u" -> 8
Expand All @@ -326,7 +326,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
Loading