summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-06-17 07:11:13 +0200
committerkdx <kikoodx@paranoici.org>2023-06-17 07:11:13 +0200
commit5a144e00385fad7d6bbe07db6125dfd3a66a48a9 (patch)
treefa08e99a232a9e6addea601b11c2a0b11d1aef6c
parent04f2e54f7eac3bde22ccb6085bdd7663b125b16a (diff)
downloadgolem-5a144e00385fad7d6bbe07db6125dfd3a66a48a9.tar.gz
constexpr for global init
-rw-r--r--src/main.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/main.c b/src/main.c
index aa23df3..3ace3c2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -488,6 +488,8 @@ define(Token **rest, Token *tok)
defines = store;
}
+static int const_expr(Node *node);
+
static Node *
global(Token **rest, Token *tok)
{
@@ -511,8 +513,7 @@ global(Token **rest, Token *tok)
if (equal(tok, "=")) {
tok = tok->next;
- cur->val = get_number(tok);
- tok = tok->next;
+ cur->val = const_expr(expr(&tok, tok));
}
if (equal(tok, ","))
@@ -1040,8 +1041,6 @@ gen_expr(Node *node)
printf("\t%s\n", op);
}
-static int const_expr(Node *node);
-
static void
gen_globaldec(Node *node)
{
@@ -1374,7 +1373,7 @@ gen_function(Node *node)
cur = cur->next;
}
- for (cur = localdecshead.next; cur != NULL; cur = cur->next)
+ for (cur = localdecshead.next; cur != NULL && cur->type == NOD_LOCAL; cur = cur->next)
gen_localdec(cur);
while (node != NULL) {