diff options
author | kdx <kikoodx@paranoici.org> | 2023-06-09 20:14:14 +0200 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2023-06-09 20:14:14 +0200 |
commit | a82211bc77beb8ee7469f08a568481157ea56f6c (patch) | |
tree | d928125279e2656f93d80b21a816cd6283d1c6b2 | |
parent | b951fda40057cca936867f9d8240f676fa3639ec (diff) | |
download | golem-a82211bc77beb8ee7469f08a568481157ea56f6c.tar.gz |
discard stack & testing suite
-rw-r--r-- | src/main.c | 19 | ||||
-rwxr-xr-x | testing.sh | 14 |
2 files changed, 26 insertions, 7 deletions
@@ -142,6 +142,7 @@ typedef enum { NOD_LE, // <= NOD_NUM, // integer NOD_EXPR_STMT, + NOD_FUN_STMT, } NodeType; typedef struct Node Node; @@ -381,7 +382,14 @@ gen_expr(Node *node) static void codegen(Node *node) { - gen_expr(node); + while (node != NULL) { + gen_expr(node->lhs); + while (depth) { + printf("\tPOP ( discard stack )\n"); + depth -= 1; + } + node = node->next; + } } // program = stmt* @@ -403,15 +411,12 @@ main(int argc, char **argv) Token *tok = tokenize(argv[1]); - Node *node = expr(&tok, tok); - - if (tok->type != TOK_EOF) - error("extra token"); + Node *node = parse(tok); - printf("main:\n"); + printf("\tJMP ,main\n"); codegen(node); printf("\tRET\n"); - assert(depth == 1); + assert(depth == 0); return 0; } diff --git a/testing.sh b/testing.sh new file mode 100755 index 0000000..1d636b1 --- /dev/null +++ b/testing.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +function test() { + CODE="$1" + echo "--- $CODE ---" + ./build/golem "$CODE" >"build/tmp.orgaasm" + orgaasm "build/tmp.orgaasm" "build/tmp.rom" + orgaemu "build/tmp.rom" +} + +tup || exit 1 +test '5 + 2;' +test '6 + 3;' +rm -f build/tmp.* |