summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-06-10 05:02:28 +0200
committerkdx <kikoodx@paranoici.org>2023-06-10 05:06:42 +0200
commiteadc11a1ed56241e565e6ff9744fa692ed8ccd09 (patch)
tree23c4608aa6acb9aabea1638fbf69b535a1b63696 /src
parentc18eda9ff2377f02727910b7cf54b286ea35fa4d (diff)
downloadgolem-eadc11a1ed56241e565e6ff9744fa692ed8ccd09.tar.gz
local variables should be done
Diffstat (limited to 'src')
-rw-r--r--src/main.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/main.c b/src/main.c
index 10e8d5a..4bbe051 100644
--- a/src/main.c
+++ b/src/main.c
@@ -131,7 +131,7 @@ tokenize(char *p)
continue;
}
- if (isalpha(*p)) {
+ if (isalpha(*p) || *p == '_') {
char *q = p;
while (isalnum(*p) || *p == '_')
p += 1;
@@ -549,7 +549,7 @@ static int depth;
static void gen_expr(Node *node);
static void gen_globaldec(Node *node);
static void gen_fncall(Node *node);
-static void gen_globalget(Node *node);
+static void gen_variableget(Node *node);
static void
gen_expr(Node *node)
@@ -566,7 +566,7 @@ gen_expr(Node *node)
}
if (node->type == NOD_WORD) {
- gen_globalget(node);
+ gen_variableget(node);
return;
}
@@ -628,10 +628,18 @@ gen_fncall(Node *node)
}
static void
-gen_globalget(Node *node)
+gen_variableget(Node *node)
{
- printf("\tLIT ,__gl_%.*s\n", node->len, node->loc);
- printf("\tLDA\n");
+ const int found = node_find(locals, node);
+ if (found != -1) {
+ printf("\tLIT ,__stack_ptr LDA\n");
+ if (locals_size - found - 1)
+ printf("\tLIT %04x SUB\n", locals_size - found - 1);
+ printf("\tLDA\n");
+ } else {
+ printf("\tLIT ,__gl_%.*s\n", node->len, node->loc);
+ printf("\tLDA\n");
+ }
depth += 1;
}
@@ -668,7 +676,7 @@ gen_function(Node *node)
const int offset = locals_size + i - argcount;
if (offset)
printf("\tLIT %04x SUB\n", offset);
- printf("\tSWP STA\n");
+ printf("\tSTA\n");
cur = cur->next;
}