diff options
author | Vincent Ambo <mail@tazj.in> | 2021-02-28T13·57+0200 |
---|---|---|
committer | tazjin <mail@tazj.in> | 2021-02-28T14·36+0000 |
commit | c58fe2093e2a2870fc76ea55aa2de8e5aa6dab7d (patch) | |
tree | 74dfeeb43fb7936cc09d92b14ea017c46b5dfccb /users/tazjin/rlox/src/bytecode/compiler.rs | |
parent | 93c30b339c4904e86ac6046bd2a67c0d872a6a3b (diff) |
feat(tazjin/rlox): Implement equality operator r/2255
Change-Id: I5587a11646e228c5af4dc7ca6da026bb4a2592a6 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2574 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
Diffstat (limited to 'users/tazjin/rlox/src/bytecode/compiler.rs')
-rw-r--r-- | users/tazjin/rlox/src/bytecode/compiler.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/users/tazjin/rlox/src/bytecode/compiler.rs b/users/tazjin/rlox/src/bytecode/compiler.rs index 1ab42c705ab4..8eef40f0e669 100644 --- a/users/tazjin/rlox/src/bytecode/compiler.rs +++ b/users/tazjin/rlox/src/bytecode/compiler.rs @@ -120,6 +120,14 @@ fn rule_for<T: Iterator<Item = Token>>(token: &TokenKind) -> ParseRule<T> { ParseRule::new(Some(Compiler::unary), None, Precedence::None) } + TokenKind::BangEqual => { + ParseRule::new(None, Some(Compiler::binary), Precedence::Equality) + } + + TokenKind::EqualEqual => { + ParseRule::new(None, Some(Compiler::binary), Precedence::Equality) + } + _ => ParseRule::new(None, None, Precedence::None), } } @@ -194,6 +202,14 @@ impl<T: Iterator<Item = Token>> Compiler<T> { TokenKind::Plus => self.emit_op(OpCode::OpAdd), TokenKind::Star => self.emit_op(OpCode::OpMultiply), TokenKind::Slash => self.emit_op(OpCode::OpDivide), + + TokenKind::BangEqual => { + self.emit_op(OpCode::OpEqual); + self.emit_op(OpCode::OpNot); + } + + TokenKind::EqualEqual => self.emit_op(OpCode::OpEqual), + _ => unreachable!("only called for binary operator tokens"), } |