diff --git a/components/lox-compile/src/compile.rs b/components/lox-compile/src/compile.rs index 555a033..ffcfd1f 100644 --- a/components/lox-compile/src/compile.rs +++ b/components/lox-compile/src/compile.rs @@ -120,7 +120,7 @@ impl Compiler { syntax::Expr::Variable(word) => { let name = word.as_str(db); if let Some(index) = self.resolve_local(name) { - chunk.emit_byte(Code::LocalVariable(index)) + chunk.emit_byte(Code::ReadLocalVariable(index)) } else { chunk.emit_byte(Code::GlobalVariable(name.to_string())) } diff --git a/components/lox-execute/src/vm.rs b/components/lox-execute/src/vm.rs index bdab0a2..4bc146a 100644 --- a/components/lox-execute/src/vm.rs +++ b/components/lox-execute/src/vm.rs @@ -238,7 +238,7 @@ impl VM { let value = self.peek(); self.globals.insert(name, value.clone()); } - bytecode::Code::LocalVariable(index) => { + bytecode::Code::ReadLocalVariable(index) => { let value = self.stack[index].clone(); self.push(value); } diff --git a/components/lox-ir/src/bytecode.rs b/components/lox-ir/src/bytecode.rs index aaee9ac..2e27508 100644 --- a/components/lox-ir/src/bytecode.rs +++ b/components/lox-ir/src/bytecode.rs @@ -20,7 +20,7 @@ pub enum Code { Print, GlobalVarDeclaration(String), // name of the variable GlobalVariable(String), // name of the variable - LocalVariable(usize), // index of the variable in the stack + ReadLocalVariable(usize), // index of the variable in the stack Nil, Assign(String), Pop, diff --git a/lox_tests/local_var/bytecode b/lox_tests/local_var/bytecode index 50559d9..f75aadf 100644 --- a/lox_tests/local_var/bytecode +++ b/lox_tests/local_var/bytecode @@ -10,12 +10,12 @@ Chunk { 2.0, ), ), - LocalVariable( + ReadLocalVariable( 1, ), Print, Pop, - LocalVariable( + ReadLocalVariable( 0, ), Print, diff --git a/lox_tests/local_var/execute b/lox_tests/local_var/execute index 2dc1ffd..c431902 100644 --- a/lox_tests/local_var/execute +++ b/lox_tests/local_var/execute @@ -23,7 +23,7 @@ stack: [ ), ] -execute: LocalVariable( +execute: ReadLocalVariable( 1, ) stack: [ @@ -55,7 +55,7 @@ stack: [ ), ] -execute: LocalVariable( +execute: ReadLocalVariable( 0, ) stack: [