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

@ -108,3 +108,13 @@ fn strings() {
expect_str("\"hello\";", "hello");
expect_str("\"hello\" + \" world\";", "hello world");
}
#[test]
fn variables() {
expect_num("var a = 5; a;", 5.0);
expect_num("var a = 5; var b = 2; a * b;", 10.0);
expect_str(
"var greeting = \"hello\"; var name = \"Zubnog\"; greeting + \" \" + name;",
"hello Zubnog",
);
}