about summary refs log tree commit diff
path: root/users/tazjin/rlox/src/bytecode/vm.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2021-03-05T20·35+0200
committertazjin <mail@tazj.in>2021-03-06T11·52+0000
commit4162186a1963b0dcf3dc47946a1cd8ad81467ac4 (patch)
tree01dac61eeee9362d3e71c2a1e966da0b01180bfc /users/tazjin/rlox/src/bytecode/vm.rs
parent29b2a547055ba1adaf3f0d79055b7d7657eb3a5e (diff)
feat(tazjin/rlox): Implement global variable access r/2274
This also includes a fix for an issue where the identifiers of
variables were pushed onto the stack, which is incorrect.

Change-Id: Id89b388268efad295f29978d767aa4b33c4ded14
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2594
Reviewed-by: tazjin <mail@tazj.in>
Tested-by: BuildkiteCI
Diffstat (limited to 'users/tazjin/rlox/src/bytecode/vm.rs')
-rw-r--r--users/tazjin/rlox/src/bytecode/vm.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/users/tazjin/rlox/src/bytecode/vm.rs b/users/tazjin/rlox/src/bytecode/vm.rs
index 53431a083785..0cd0853764e0 100644
--- a/users/tazjin/rlox/src/bytecode/vm.rs
+++ b/users/tazjin/rlox/src/bytecode/vm.rs
@@ -170,6 +170,17 @@ impl VM {
                         self.globals.insert(name, val);
                     });
                 }
+
+                OpCode::OpGetGlobal(name_idx) => {
+                    let name = self.chunk.constant(*name_idx);
+                    with_type!(self, name, Value::String(name), {
+                        let val = match self.globals.get(name) {
+                            None => unimplemented!("variable not found error"),
+                            Some(val) => val.clone(),
+                        };
+                        self.push(val)
+                    });
+                }
             }
 
             #[cfg(feature = "disassemble")]