diff options
| author | 2022-08-05 16:51:31 +0200 | |
|---|---|---|
| committer | 2022-08-05 16:51:31 +0200 | |
| commit | d95555f87eced5fcb3458d76c765afe2de89bdcb (patch) | |
| tree | 13d796696a7c42112b5ba224716e8a6b4a2caeae | |
| parent | fb2346ba50eec07c35d8bc2f7d7a6b9d7b3d1a2a (diff) | |
be lazier
| -rw-r--r-- | bootstrap/libc.hff | 3 | ||||
| -rw-r--r-- | bootstrap/parse.c | 27 |
2 files changed, 16 insertions, 14 deletions
diff --git a/bootstrap/libc.hff b/bootstrap/libc.hff index 0667b3f..58ff6b0 100644 --- a/bootstrap/libc.hff +++ b/bootstrap/libc.hff @@ -1,2 +1,3 @@ extern fn printf(fmt *const u8, ...) int; -extern fn qsort(base *void, nmemb usize, size usize, compar *fn(l *const void, r *const void, _ *void) int) void; +extern fn qsort(base *void, nmemb usize, size usize, + compar *fn(l *const void, r *const void, _ *void) int) void; diff --git a/bootstrap/parse.c b/bootstrap/parse.c index 99c9310..3f854d7 100644 --- a/bootstrap/parse.c +++ b/bootstrap/parse.c @@ -785,6 +785,18 @@ parsearrini(struct parser *P, const struct type *ty) { return ex; } +static const struct type * +fntype(const struct fn *fn) { + struct type ty = { TYfn, 0, g_targ.sizesize }; + vec_t(const struct type *) params = {0}; + ty.fn.retty = fn->retty; + for (int i = 0; i < fn->params.n; ++i) + vec_push(¶ms, fn->params.d[i].ty); + vec_slice_cpy(&ty.fn.params, ¶ms); + ty.fn.variadic = fn->variadic; + return interntype(ty); +} + static struct expr pexprimary(struct parser *P) { struct expr ex = {0}; @@ -861,6 +873,8 @@ pexprimary(struct parser *P) { } else if (decl->t == Dstatic) { ex.ty = decl->var.ty; } else if (decl->t == Dfn) { + if (!decl->fn.selfty) + ((struct decl *)decl)->fn.selfty = fntype(&decl->fn); ex.ty = decl->fn.selfty; } else assert(0); } @@ -1764,18 +1778,6 @@ parseblock(struct parser *P) { return st; } -static const struct type * -fntype(const struct fn *fn) { - struct type ty = { TYfn, 0, g_targ.sizesize }; - vec_t(const struct type *) params = {0}; - ty.fn.retty = fn->retty; - for (int i = 0; i < fn->params.n; ++i) - vec_push(¶ms, fn->params.d[i].ty); - vec_slice_cpy(&ty.fn.params, ¶ms); - ty.fn.variadic = fn->variadic; - return interntype(ty); -} - static void parsefn(struct decl *decl, struct parser *P) { vec_t(struct fnparam) params = {0}; @@ -1812,7 +1814,6 @@ parsefn(struct decl *decl, struct parser *P) { fatal(P, tok.span, "return type is incomplete (%t)", fn->retty); } - fn->selfty = fntype(fn); if (!lexmatch(P, &tok, ';')) { struct env *env = xcalloc(1, sizeof *env); static int id; |