From cdddf2422553f1f21c8d2c57cd382b8362dc80fb Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 7 Feb 2026 15:42:00 +0900 Subject: feat: support function calls via function pointers The two-pass parsing of function pointer declaration is referenced from chibicc: https://github.com/rui314/chibicc --- src/codegen_wasm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/codegen_wasm.c') diff --git a/src/codegen_wasm.c b/src/codegen_wasm.c index cb48f38..01dfe42 100644 --- a/src/codegen_wasm.c +++ b/src/codegen_wasm.c @@ -62,12 +62,19 @@ static void codegen_lvar(CodeGen* g, LvarNode* lvar, GenMode) { } static void codegen_func_call(CodeGen* g, FuncCallNode* call) { + const char* func_name; + if (call->func->kind == AstNodeKind_func) { + func_name = call->func->as.func->name; + } else { + unimplemented(); + } + AstNode* args = call->args; for (int i = 0; i < args->as.list->len; ++i) { AstNode* arg = args->as.list->items + i; codegen_expr(g, arg, GenMode_rval); } - fprintf(g->out, " call $%s\n", call->name); + fprintf(g->out, " call $%s\n", func_name); } static void codegen_expr(CodeGen* g, AstNode* ast, GenMode gen_mode) { -- cgit v1.3-1-g0d28