Implemented scopes

This commit is contained in:
2024-10-27 13:44:09 +11:00
parent d22b18ed17
commit c5206daaea
10 changed files with 90 additions and 9 deletions

View File

@@ -48,7 +48,7 @@ int test_sizeof_ast_32bit() {
//run for each type
TEST_SIZEOF(Toy_AstType, 4);
TEST_SIZEOF(Toy_AstBlock, 16);
TEST_SIZEOF(Toy_AstBlock, 20);
TEST_SIZEOF(Toy_AstValue, 12);
TEST_SIZEOF(Toy_AstUnary, 12);
TEST_SIZEOF(Toy_AstBinary, 16);
@@ -61,7 +61,7 @@ int test_sizeof_ast_32bit() {
TEST_SIZEOF(Toy_AstPass, 4);
TEST_SIZEOF(Toy_AstError, 4);
TEST_SIZEOF(Toy_AstEnd, 4);
TEST_SIZEOF(Toy_Ast, 16);
TEST_SIZEOF(Toy_Ast, 20);
#undef TEST_SIZEOF

View File

@@ -0,0 +1,19 @@
//shadowing
var answer = 42;
print answer; //42
{
var answer = 7;
print answer; //7
}
print answer; //42
//rebinding
var question = 42;
print question; //42
{
var question = question;
print question; //42
}
print question; //42
//TODO: scope test case

View File

@@ -7,15 +7,13 @@ var empty;
//assign a previously existing variable
answer = 6 * 9;
//access a variable
answer = answer + 1;
//compound assignments
answer += 5;
answer -= 5;
answer *= 9;
answer /= 2;
answer %= 10;