Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xffxff committed Sep 24, 2023
1 parent 3f55d28 commit 37351bc
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lox_tests/var.lox
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
var a = 1;
var b;
print a;
print a;
var str1 = "hello";
var str2 = "world";
print str1 + str2;
20 changes: 20 additions & 0 deletions lox_tests/var/bytecode
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,25 @@ Chunk {
"a",
),
Print,
String(
"hello",
),
VarDeclaration(
"str1",
),
String(
"world",
),
VarDeclaration(
"str2",
),
Variable(
"str1",
),
Variable(
"str2",
),
Add,
Print,
],
}
59 changes: 59 additions & 0 deletions lox_tests/var/execute
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,62 @@ stack: [
execute: Print
stack: []

execute: String(
"hello",
)
stack: [
String(
"hello",
),
]

execute: VarDeclaration(
"str1",
)
stack: []

execute: String(
"world",
)
stack: [
String(
"world",
),
]

execute: VarDeclaration(
"str2",
)
stack: []

execute: Variable(
"str1",
)
stack: [
String(
"hello",
),
]

execute: Variable(
"str2",
)
stack: [
String(
"hello",
),
String(
"world",
),
]

execute: Add
stack: [
String(
"helloworld",
),
]

execute: Print
stack: []

19 changes: 19 additions & 0 deletions lox_tests/var/syntax
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,22 @@ Var {
Print {
expr: Variable(a),
}
Var {
name: "str1",
initializer: Some(
StringLiteral(hello),
),
}
Var {
name: "str2",
initializer: Some(
StringLiteral(world),
),
}
Print {
expr: BinaryOp {
left: Variable(str1),
op: Plus,
right: Variable(str2),
},
}
29 changes: 28 additions & 1 deletion lox_tests/var/token
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TokenTree {
source text: "var a = 1;\nvar b;\nprint a;",
source text: "var a = 1;\nvar b;\nprint a;\nvar str1 = \"hello\";\nvar str2 = \"world\";\nprint str1 + str2;",
tokens: [
Alphabetic(var),
Whitespace(' '),
Expand All @@ -19,5 +19,32 @@ TokenTree {
Whitespace(' '),
Alphabetic(a),
Semicolon,
Whitespace('\n'),
Alphabetic(var),
Whitespace(' '),
Alphabetic(str1),
Whitespace(' '),
Op(=),
Whitespace(' '),
String(hello),
Semicolon,
Whitespace('\n'),
Alphabetic(var),
Whitespace(' '),
Alphabetic(str2),
Whitespace(' '),
Op(=),
Whitespace(' '),
String(world),
Semicolon,
Whitespace('\n'),
Alphabetic(print),
Whitespace(' '),
Alphabetic(str1),
Whitespace(' '),
Op(+),
Whitespace(' '),
Alphabetic(str2),
Semicolon,
],
}

0 comments on commit 37351bc

Please sign in to comment.