aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/codegen.c
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-09-28 15:24:28 +0900
committernsfisis <nsfisis@gmail.com>2025-09-28 15:24:28 +0900
commit1b208f7f0a3b7d6b72c2a431d9fcd6e18fe76f5d (patch)
tree4902e2907f39cb0ae05439365e70d5628396a6fc /src/codegen.c
parent235969b792bf11e8b7927318cf01b5ef5705177b (diff)
downloadducc-1b208f7f0a3b7d6b72c2a431d9fcd6e18fe76f5d.tar.gz
ducc-1b208f7f0a3b7d6b72c2a431d9fcd6e18fe76f5d.tar.zst
ducc-1b208f7f0a3b7d6b72c2a431d9fcd6e18fe76f5d.zip
feat: support using function as a value
Diffstat (limited to 'src/codegen.c')
-rw-r--r--src/codegen.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/codegen.c b/src/codegen.c
index 36f854d..34f6c23 100644
--- a/src/codegen.c
+++ b/src/codegen.c
@@ -439,6 +439,11 @@ static void codegen_gvar(CodeGen* g, AstNode* ast, GenMode gen_mode) {
}
}
+static void codegen_func_ref(CodeGen* g, AstNode* ast) {
+ fprintf(g->out, " lea rax, %s[rip]\n", ast->name);
+ fprintf(g->out, " push rax\n");
+}
+
static void codegen_composite_expr(CodeGen* g, AstNode* ast) {
// Standard C does not have composite expression, but ducc internally has.
for (int i = 0; i < ast->node_len; ++i) {
@@ -478,6 +483,8 @@ static void codegen_expr(CodeGen* g, AstNode* ast, GenMode gen_mode) {
codegen_lvar(g, ast, gen_mode);
} else if (ast->kind == AstNodeKind_gvar) {
codegen_gvar(g, ast, gen_mode);
+ } else if (ast->kind == AstNodeKind_func) {
+ codegen_func_ref(g, ast);
} else if (ast->kind == AstNodeKind_list) {
codegen_composite_expr(g, ast);
} else {