[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

@@ -76,6 +76,7 @@ impl VM {
match instr {
Op::Return => print!("{:?}", self.pop()?),
Op::Constant { offset } => self.push(chunk.constants[offset]),
Op::Nil => self.push(Value::Nil),
Op::Negate => {
let new_val = -self.pop_num()?;
self.push(new_val.into());
@@ -144,9 +145,9 @@ mod tests {
#[test]
fn runtime_type_error() {
let chunk = Chunk::new_with(
vec![Op::Constant { offset: 0 }, Op::Negate],
vec![Op::Nil, Op::Negate],
vec![],
vec![],
vec![Value::Nil],
);
let mut vm = VM::new();