feat(tazjin/rlox): Implement global variable access

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
This commit is contained in:
Vincent Ambo 2021-03-05 22:35:02 +02:00 committed by tazjin
parent 29b2a54705
commit 4162186a19
4 changed files with 48 additions and 6 deletions

View file

@ -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")]