[rlox] Add dedicated instruction for Nil

This commit is contained in:
ctsk
2023-10-08 20:30:43 +02:00
parent 68b165bebe
commit ef7c53a55c
3 changed files with 8 additions and 6 deletions

View File

@@ -352,7 +352,7 @@ impl<'src> Parser<'src> {
ttype: TokenType::Nil,
span: _,
} => {
chunk.add_constant(Value::Nil, 0);
chunk.add_op(Op::Nil, 0);
}
Token {
ttype: TokenType::LeftParen,
@@ -497,9 +497,9 @@ mod tests {
use crate::bc::Op::*;
let expected = Chunk::new_with(
vec![Constant { offset: 0 }, Constant { offset: 1 }, Add],
vec![Nil, Nil, Add],
vec![],
vec![],
vec![Value::Nil, Value::Nil],
);
assert!(chunk.instr_eq(&expected));