aboutsummaryrefslogtreecommitdiff
path: root/src/prc1/fn.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/prc1/fn.c')
-rw-r--r--src/prc1/fn.c31
1 files changed, 17 insertions, 14 deletions
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 <stdlib.h>
@@ -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;
}