From 2b0d4ead061a39da9dbd705c18c9955549c4d405 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Thu, 1 Oct 2026 01:04:30 +0200 Subject: WIP sym --- src/prc1/fn.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'src/prc1/fn.c') diff --git a/src/prc1/fn.c b/src/prc1/fn.c index 03aa11e..84f6c4b 100644 --- a/src/prc1/fn.c +++ b/src/prc1/fn.c @@ -9,6 +9,7 @@ #include "pr.h" #include "stmt.h" #include "storage.h" +#include "sym.h" #include "td.h" #include "ws.h" #include @@ -20,11 +21,8 @@ static int prvfn(const struct lex *l, struct prv *p); static const struct seq fnseq[] = { - {(struct step[]) - {{ID, "public"}, {ID, "function"}, {ID}, {0}}, .fn = pubfn, - .end = fn_end}, - {(struct step[]) - {{ID, "function"}, {ID}, {0}}, .fn = prvfn, .end = fn_end}, + {(struct step[]){{ID, "public"}, {ID, "function"}, {ID}, {0}}, .fn = pubfn}, + {(struct step[]){{ID, "function"}, {ID}, {0}}, .fn = prvfn}, {0} }; @@ -92,8 +90,8 @@ static int pushfn(const struct tk *tk, const struct lex *lex, struct prv *p, if (div_fn(lex, p)) return -1; - dbg("adding %s function %s\n", l == STATIC ? "private" : "public", tk->s); - return 1; + dbg("add %s function %s\n", l == STATIC ? "private" : "public", tk->s); + return 0; } static int pubfn(const struct lex *l, struct prv *p) @@ -229,6 +227,14 @@ void fn_free(struct fn *fn) t = next; } + for (struct sym *s = fn->syms; s;) + { + struct sym *next = s->next; + + sym_free(s); + s = next; + } + storage_free(fn->lk); storage_free(fn->ws); storage_free(fn->gl); @@ -253,14 +259,11 @@ int fn(const struct lex *l, struct prv *p) { struct pos init = { - .seq = fnseq, - .stseq = fnseq, - .step = fnseq->steps + .name = __func__, + .seq = fnseq }; - if (lex_eof(l, p->stk)) - return 0; - else if (lex_eof(l, p->stk + 1)) + if (lex_eof(l, p->stk + 1)) { errloc(p->stk, "incomplete function statement"); return -1; @@ -269,5 +272,5 @@ int fn(const struct lex *l, struct prv *p) return -1; p->stk = p->tk; - return 1; + return 0; } -- cgit v1.2.3