diff --git a/lox_tests/local_var.lox b/lox_tests/local_var.lox index 206c108..5f73bf5 100644 --- a/lox_tests/local_var.lox +++ b/lox_tests/local_var.lox @@ -1,4 +1,8 @@ { var a = 1; + { + var a = 2; + print a; + } print a; } \ No newline at end of file diff --git a/lox_tests/local_var/bytecode b/lox_tests/local_var/bytecode index cdb326c..50559d9 100644 --- a/lox_tests/local_var/bytecode +++ b/lox_tests/local_var/bytecode @@ -5,6 +5,16 @@ Chunk { 1.0, ), ), + Constant( + F64( + 2.0, + ), + ), + LocalVariable( + 1, + ), + Print, + Pop, LocalVariable( 0, ), diff --git a/lox_tests/local_var/execute b/lox_tests/local_var/execute index 355204c..2dc1ffd 100644 --- a/lox_tests/local_var/execute +++ b/lox_tests/local_var/execute @@ -9,6 +9,52 @@ stack: [ ), ] +execute: Constant( + F64( + 2.0, + ), +) +stack: [ + Number( + 1.0, + ), + Number( + 2.0, + ), +] + +execute: LocalVariable( + 1, +) +stack: [ + Number( + 1.0, + ), + Number( + 2.0, + ), + Number( + 2.0, + ), +] + +execute: Print +stack: [ + Number( + 1.0, + ), + Number( + 2.0, + ), +] + +execute: Pop +stack: [ + Number( + 1.0, + ), +] + execute: LocalVariable( 0, ) diff --git a/lox_tests/local_var/syntax b/lox_tests/local_var/syntax index be6e817..b5c9814 100644 --- a/lox_tests/local_var/syntax +++ b/lox_tests/local_var/syntax @@ -5,6 +5,17 @@ Block { NumberLiteral(1), ), }, + stmt: Block { + stmt: Var { + name: "a", + initializer: Some( + NumberLiteral(2), + ), + }, + stmt: Print { + expr: Variable(a), + }, + }, stmt: Print { expr: Variable(a), }, diff --git a/lox_tests/local_var/token b/lox_tests/local_var/token index b133e07..1af887c 100644 --- a/lox_tests/local_var/token +++ b/lox_tests/local_var/token @@ -1,10 +1,10 @@ TokenTree { - source text: "{\n var a = 1;\n print a;\n}", + source text: "{\n var a = 1;\n {\n var a = 2;\n print a;\n }\n print a;\n}", tokens: [ Delimiter({), Tree( TokenTree { - source text: "{\n var a = 1;\n print a;\n}", + source text: "{\n var a = 1;\n {\n var a = 2;\n print a;\n }\n print a;\n}", tokens: [ Whitespace('\n'), Whitespace(' '), @@ -24,6 +24,55 @@ TokenTree { Whitespace(' '), Whitespace(' '), Whitespace(' '), + Delimiter({), + Tree( + TokenTree { + source text: "{\n var a = 1;\n {\n var a = 2;\n print a;\n }\n print a;\n}", + tokens: [ + Whitespace('\n'), + Whitespace(' '), + Whitespace(' '), + Whitespace(' '), + Whitespace(' '), + Whitespace(' '), + Whitespace(' '), + Whitespace(' '), + Whitespace(' '), + Alphabetic(var), + Whitespace(' '), + Alphabetic(a), + Whitespace(' '), + Op(=), + Whitespace(' '), + Number(2), + Semicolon, + Whitespace('\n'), + Whitespace(' '), + Whitespace(' '), + Whitespace(' '), + Whitespace(' '), + Whitespace(' '), + Whitespace(' '), + Whitespace(' '), + Whitespace(' '), + Alphabetic(print), + Whitespace(' '), + Alphabetic(a), + Semicolon, + Whitespace('\n'), + Whitespace(' '), + Whitespace(' '), + Whitespace(' '), + Whitespace(' '), + ], + }, + ), + Delimiter(}), + Whitespace('\n'), + Whitespace(' '), + Whitespace(' '), + Whitespace(' '), + Whitespace(' '), Alphabetic(print), Whitespace(' '), Alphabetic(a),