diff options
Diffstat (limited to 'users/tazjin/rlox/src/bytecode/compiler.rs')
-rw-r--r-- | users/tazjin/rlox/src/bytecode/compiler.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/users/tazjin/rlox/src/bytecode/compiler.rs b/users/tazjin/rlox/src/bytecode/compiler.rs index 1408f519bb2d..9a8f80ae2b7d 100644 --- a/users/tazjin/rlox/src/bytecode/compiler.rs +++ b/users/tazjin/rlox/src/bytecode/compiler.rs @@ -179,10 +179,10 @@ impl<T: Iterator<Item = Token>> Compiler<T> { fn statement(&mut self) -> LoxResult<()> { if self.match_token(&TokenKind::Print) { - return self.print_statement(); + self.print_statement() + } else { + self.expression_statement() } - - Ok(()) } fn print_statement(&mut self) -> LoxResult<()> { @@ -195,6 +195,16 @@ impl<T: Iterator<Item = Token>> Compiler<T> { Ok(()) } + fn expression_statement(&mut self) -> LoxResult<()> { + self.expression()?; + self.consume( + &TokenKind::Semicolon, + ErrorKind::ExpectedToken("Expected ';' after expression"), + ); + self.emit_op(OpCode::OpPop); + Ok(()) + } + fn number(&mut self) -> LoxResult<()> { if let TokenKind::Number(num) = self.previous().kind { self.emit_constant(Value::Number(num)); |