Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xffxff committed Sep 25, 2023
1 parent cb4e428 commit 6de2773
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lox_tests/local_var.lox
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
var a = 1;
{
var a = 2;
print a;
}
print a;
}
10 changes: 10 additions & 0 deletions lox_tests/local_var/bytecode
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ Chunk {
1.0,
),
),
Constant(
F64(
2.0,
),
),
LocalVariable(
1,
),
Print,
Pop,
LocalVariable(
0,
),
Expand Down
46 changes: 46 additions & 0 deletions lox_tests/local_var/execute
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
11 changes: 11 additions & 0 deletions lox_tests/local_var/syntax
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand Down
53 changes: 51 additions & 2 deletions lox_tests/local_var/token
Original file line number Diff line number Diff line change
@@ -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(' '),
Expand All @@ -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),
Expand Down

0 comments on commit 6de2773

Please sign in to comment.