summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-06-10 03:53:00 +0200
committerkdx <kikoodx@paranoici.org>2023-06-10 03:53:00 +0200
commit1f5785079299da2f3485203eceb7bc7038d8dc45 (patch)
treebb1fdaf3a811d49c8ee7e3018c23a766251b226d
parent996fbcefb3339707bf0dad2e0a33ae744f9cf5c3 (diff)
downloadgolem-1f5785079299da2f3485203eceb7bc7038d8dc45.tar.gz
argcount
-rw-r--r--src/main.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c
index 0c2f5ef..fb90340 100644
--- a/src/main.c
+++ b/src/main.c
@@ -177,6 +177,17 @@ struct Node {
int len;
};
+static int
+node_size(const Node *node)
+{
+ int size = 0;
+ while (node != NULL) {
+ size += 1;
+ node = node->next;
+ }
+ return size;
+}
+
static bool
node_equal(const Node *node, const char *op)
{
@@ -241,6 +252,8 @@ static Node *add(Token **rest, Token *tok);
static Node *mul(Token **rest, Token *tok);
static Node *primary(Token **rest, Token *tok);
+static Node *locals;
+
static Node *
function(Token **rest, Token *tok)
{
@@ -257,10 +270,11 @@ function(Token **rest, Token *tok)
if (equal(tok, ","))
tok = tok->next;
}
- node->lhs->next = cur;
+ node->lhs->next = head.next;
tok = skip(tok, ")");
tok = skip(tok, "{");
+ head.next = NULL;
cur = &head;
while (tok->type != TOK_EOF && !equal(tok, "}"))
cur = cur->next = stmt(&tok, tok);
@@ -588,6 +602,10 @@ gen_function(Node *node)
{
printf("@__fn_%.*s\n", node->lhs->len, node->lhs->loc);
+ /* GOTO */
+ locals = node->lhs->next;
+ fprintf(stderr, "argcount %d\n", node_size(locals));
+
node = node->rhs;
while (node != NULL) {
switch (node->type) {