aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/codegen_wasm.c
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-02-07 15:42:00 +0900
committernsfisis <nsfisis@gmail.com>2026-02-07 17:33:55 +0900
commitcdddf2422553f1f21c8d2c57cd382b8362dc80fb (patch)
tree3053026498552aecda2e4889c8455298ad70c8cb /src/codegen_wasm.c
parente1042a6373773830297dfd5718938c12f21ae624 (diff)
downloadducc-cdddf2422553f1f21c8d2c57cd382b8362dc80fb.tar.gz
ducc-cdddf2422553f1f21c8d2c57cd382b8362dc80fb.tar.zst
ducc-cdddf2422553f1f21c8d2c57cd382b8362dc80fb.zip
feat: support function calls via function pointers
The two-pass parsing of function pointer declaration is referenced from chibicc: https://github.com/rui314/chibicc
Diffstat (limited to 'src/codegen_wasm.c')
-rw-r--r--src/codegen_wasm.c9
1 files changed, 8 insertions, 1 deletions
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) {