commit 1d7177f52d0ab7324ae9476872c8bd745100f0ca
parent de1489a527c685765dff154f4d018b66d87bd821
Author: Nihal Jere <nihal@nihaljere.xyz>
Date: Wed, 15 Dec 2021 12:04:29 -0600
cleanup
move declarations out of case statements, fix tests
Diffstat:
3 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/main.c b/main.c
@@ -223,6 +223,7 @@ typecheck(struct block items)
struct expr *expr;
struct decl *decl;
struct type *type;
+ struct assgn *assgn;
switch (items.data[i].kind) {
case ITEM_DECL:
decl = &items.decls.data[item->idx];
@@ -259,7 +260,7 @@ typecheck(struct block items)
}
break;
case ITEM_ASSGN:
- struct assgn *assgn = &assgns.data[item->idx];
+ assgn = &assgns.data[item->idx];
decl = finddecl(assgn->s);
if (decl == NULL)
error(assgn->start->line, assgn->start->col, "unknown name");
@@ -510,6 +511,7 @@ genblock(char *buf, struct block *block, bool toplevel)
struct expr *expr = &exprs.data[assgns.data[item->idx].val];
struct assgn *assgn = &assgns.data[item->idx];
struct decl *decl = finddecl(assgn->s);
+ enum reg reg;
if (decl == NULL)
error(assgn->start->line, assgn->start->col, "unknown name");
@@ -519,7 +521,7 @@ genblock(char *buf, struct block *block, bool toplevel)
switch (expr->class) {
case C_INT:
// this is sort of an optimization, since we write at compile-time instead of evaluating and storing. should this happen here in the long term?
- enum reg reg = getreg();
+ reg = getreg();
total += genexpr(buf ? buf + total : NULL, assgn->val, reg);
total += decl_fromreg(buf ? buf + total : NULL, decl, reg);
freereg(reg);
diff --git a/test.sh b/test.sh
@@ -14,4 +14,8 @@ do
printf "test %s failed\n" "$file"
exit 1
}
+ chmod +x out && ./out || {
+ printf "test %s failed\n" "$file"
+ exit 1
+ }
done
diff --git a/test/yes.pass.nooc b/test/yes.pass.nooc
@@ -1,7 +1,7 @@
let main proc = proc {
let write i64 = 1
- let stdout i64 = 0
- loop {
- syscall(write, stdout, "y\n", 2)
- }
+ let stdout i64 = 1
+ let count i64 = 0
+ syscall(write, stdout, "y\n", 2)
+ syscall(60, 0)
}