summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-07-03 11:15:34 +0100
committerubq323 <ubq323@ubq323.website>2024-07-03 11:15:34 +0100
commit70c782292f48358fc4d3ac3874ac1951b405de48 (patch)
tree6d39dfa6a1c8aac57a7322d233eb98c284f8d177
parent033a9cbb66d65a0918e2c095d12937afb82fd4b2 (diff)
compile each file like a body, allowing def at file toplevel
-rw-r--r--com.c9
-rw-r--r--tests/def.bth5
-rw-r--r--tests/def.out2
3 files changed, 12 insertions, 4 deletions
diff --git a/com.c b/com.c
index cd097df..dbf07a4 100644
--- a/com.c
+++ b/com.c
@@ -712,14 +712,15 @@ int main(int argc, char **argv) {
exit(1);
}
- AstNode an;
- memset(&an, 0, sizeof an);
+ AstNode an = { 0 };
+ AstNode top = astnode_new_list();
pcc_context_t *parser = pcc_create(infile);
while (pcc_parse(parser, &an)) {
- compile_node(&com, an, 0);
- astnode_free(&an);
+ astnode_append(&top, an);
}
pcc_destroy(parser);
+ compile_body(&com, top.as.list, 0, 0);
+ astnode_free(&top);
}
diff --git a/tests/def.bth b/tests/def.bth
new file mode 100644
index 0000000..d4a7d74
--- /dev/null
+++ b/tests/def.bth
@@ -0,0 +1,5 @@
+(def a 100)
+(def b 200)
+(def c 300)
+(say b)
+(let (q 10 r 20 s 30) (say r))
diff --git a/tests/def.out b/tests/def.out
new file mode 100644
index 0000000..f774a6f
--- /dev/null
+++ b/tests/def.out
@@ -0,0 +1,2 @@
+200
+20