aboutsummaryrefslogtreecommitdiff
path: root/bootstrap
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-08-05 20:01:39 +0200
committerlemon <lsof@mailbox.org>2022-08-05 20:01:39 +0200
commit4ebbafbb19455d71cd185504cdef992e1a91db7e (patch)
treeb02de90b14492acfcd00ae5248c4f1199ae81912 /bootstrap
parenta2e4d0a565a8e756f36177003a51e224aca238b9 (diff)
call functin pointers directly
Diffstat (limited to 'bootstrap')
-rw-r--r--bootstrap/parse.c21
-rw-r--r--bootstrap/test.cff4
2 files changed, 17 insertions, 8 deletions
diff --git a/bootstrap/parse.c b/bootstrap/parse.c
index 9c6f5a8..d55339d 100644
--- a/bootstrap/parse.c
+++ b/bootstrap/parse.c
@@ -940,22 +940,27 @@ pexpostfix(struct parser *P) {
for (;;) if (lexmatch(P, &tok, '(')) {
vec_t(struct expr) args = {0};
- int i = 0, n = ex.ty->fn.params.n;
+ const struct type *ty = ex.ty;
+ int i = 0;
+
+ if (ty->t == TYptr)
+ ty = ty->child;
- if (ex.ty->t != TYfn)
- fatal(P, ex.span, "callee is not a function (is %t)", ex.ty);
+ if (ty->t != TYfn)
+ fatal(P, ex.span, "callee is not a function (is %t)", ty);
while (!lexmatch(P, NULL, ')')) {
+ int n = ty->fn.params.n;
struct expr arg;
- if (i == n && ! ex.ty->fn.variadic)
+ if (i == n && ! ty->fn.variadic)
fatal(P, arg.span, "too many args for call: (expected %d)", n);
if (i < n)
- P->targty = ex.ty->fn.params.d[i];
+ P->targty = ty->fn.params.d[i];
arg = parseexpr(P);
- if (i < n && !typeof2(arg.ty, ex.ty->fn.params.d[i++]))
+ if (i < n && !typeof2(arg.ty, ty->fn.params.d[i++]))
fatal(P, arg.span,
"call argument #%d type mismatch (%t, expected %t)",
- i, arg.ty, ex.ty->fn.params.d[i - 1]);
+ i, arg.ty, ty->fn.params.d[i - 1]);
vec_push(&args, arg);
if (!lexmatch(P, NULL, ',')) {
@@ -966,7 +971,7 @@ pexpostfix(struct parser *P) {
ex.call.callee = exprdup(ex);
ex.t = Ecall;
ex.span = tok.span;
- ex.ty = ex.call.callee->ty->fn.retty;
+ ex.ty = ty->fn.retty;
vec_slice_cpy(&ex.call.args, &args);
} else if (lexmatch(P, &tok, '[')) {
struct expr lhs = ex,
diff --git a/bootstrap/test.cff b/bootstrap/test.cff
index d7f86bf..fb1741d 100644
--- a/bootstrap/test.cff
+++ b/bootstrap/test.cff
@@ -27,6 +27,10 @@ fn isort(xs *int, n usize) void {
return lhs - rhs;
}
qsort(xs, n, 4, &icmp);
+
+ fn foo() void {}
+ let x= &foo;
+ x();
}
extern fn main (argc int, argv **u8) int {