aboutsummaryrefslogtreecommitdiffhomepage
path: root/codegen.c
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-08-02 14:19:07 +0900
committernsfisis <nsfisis@gmail.com>2025-08-15 10:06:21 +0900
commitbb484d2310acf5c31792cfc16b887f4746a64816 (patch)
treef3c4f588210edb3f19a114f8b9606896c7b69f1d /codegen.c
parent000e9d54435081bd40f877b319658e44dc45c7e0 (diff)
downloadducc-bb484d2310acf5c31792cfc16b887f4746a64816.tar.gz
ducc-bb484d2310acf5c31792cfc16b887f4746a64816.tar.zst
ducc-bb484d2310acf5c31792cfc16b887f4746a64816.zip
feat: implement postfix increment/decrement operator
Diffstat (limited to 'codegen.c')
-rw-r--r--codegen.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/codegen.c b/codegen.c
index 1ee007a..d15fb4c 100644
--- a/codegen.c
+++ b/codegen.c
@@ -335,6 +335,19 @@ void codegen_gvar(CodeGen* g, AstNode* ast, GenMode gen_mode) {
printf(" push rax\n");
}
+void codegen_composite_expr(CodeGen* g, AstNode* ast) {
+ // Standard C does not have composite expression, but ducc internally has.
+ int i;
+ for (i = 0; i < ast->node_len; ++i) {
+ AstNode* expr = ast->node_items + i;
+ codegen_expr(g, expr, GenMode_rval);
+ if (i != ast->node_len - 1) {
+ // TODO: the expression on the stack can be more than 8 bytes.
+ printf(" pop rax\n");
+ }
+ }
+}
+
void codegen_expr(CodeGen* g, AstNode* ast, GenMode gen_mode) {
if (ast->kind == AstNodeKind_int_expr) {
codegen_int_expr(g, ast);
@@ -358,6 +371,8 @@ 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_list) {
+ codegen_composite_expr(g, ast);
} else {
unreachable();
}