diff options
author | Vincent Ambo <mail@tazj.in> | 2021-10-02T12·55+0300 |
---|---|---|
committer | tazjin <mail@tazj.in> | 2021-10-19T12·58+0000 |
commit | ad7e591c8046d6e179476192ef9928d5fae78422 (patch) | |
tree | 52347fd8cdd8f7d888746abbd6f66a3a2946de83 /users/tazjin/rlox/src/bytecode/vm.rs | |
parent | 6a38600ce88bbf2d9fa9a3821d7df3ebd8e0d4f3 (diff) |
feat(tazjin/rlox): Global variable assignment r/2977
Needed for example code compatibility. Change-Id: Id83210eaaad7dcfef5aa238dd3a7ec159f6935e9 Reviewed-on: https://cl.tvl.fyi/c/depot/+/3684 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
Diffstat (limited to 'users/tazjin/rlox/src/bytecode/vm.rs')
-rw-r--r-- | users/tazjin/rlox/src/bytecode/vm.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/users/tazjin/rlox/src/bytecode/vm.rs b/users/tazjin/rlox/src/bytecode/vm.rs index 0cd0853764e0..4432473ee649 100644 --- a/users/tazjin/rlox/src/bytecode/vm.rs +++ b/users/tazjin/rlox/src/bytecode/vm.rs @@ -181,6 +181,19 @@ impl VM { self.push(val) }); } + + OpCode::OpSetGlobal(name_idx) => { + let name = self.chunk.constant(*name_idx).clone(); + let new_val = self.pop(); + with_type!(self, name, Value::String(name), { + match self.globals.get_mut(&name) { + None => unimplemented!("variable not found error"), + Some(val) => { + *val = new_val; + } + } + }); + } } #[cfg(feature = "disassemble")] |