aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/codegen.c
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-09-28 15:37:52 +0900
committernsfisis <nsfisis@gmail.com>2025-10-04 15:31:34 +0900
commit7e11675136edf8136f812c85cd45bc88ba405533 (patch)
tree61dcda3287f409b8c54f61e29adc9afc32a772d1 /src/codegen.c
parent5a16856f8ff4dbf801b4a622ca7053b77e8a0214 (diff)
downloadducc-7e11675136edf8136f812c85cd45bc88ba405533.tar.gz
ducc-7e11675136edf8136f812c85cd45bc88ba405533.tar.zst
ducc-7e11675136edf8136f812c85cd45bc88ba405533.zip
feat: implement goto statement
Diffstat (limited to 'src/codegen.c')
-rw-r--r--src/codegen.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/codegen.c b/src/codegen.c
index f02a38c..4387449 100644
--- a/src/codegen.c
+++ b/src/codegen.c
@@ -578,6 +578,15 @@ static void codegen_continue_stmt(CodeGen* g, AstNode* ast) {
fprintf(g->out, " jmp .Lcontinue%d\n", label);
}
+static void codegen_goto_stmt(CodeGen* g, AstNode* ast) {
+ fprintf(g->out, " jmp .L%s__%s\n", g->current_func->name, ast->name);
+}
+
+static void codegen_label_stmt(CodeGen* g, AstNode* ast) {
+ fprintf(g->out, ".L%s__%s:\n", g->current_func->name, ast->name);
+ codegen_stmt(g, ast->node_body);
+}
+
// Helper to collect case values from the switch body
static void collect_cases(AstNode* stmt, int* case_values, int* case_labels, int* n_cases) {
if (!stmt)
@@ -694,6 +703,10 @@ static void codegen_stmt(CodeGen* g, AstNode* ast) {
codegen_break_stmt(g, ast);
} else if (ast->kind == AstNodeKind_continue_stmt) {
codegen_continue_stmt(g, ast);
+ } else if (ast->kind == AstNodeKind_goto_stmt) {
+ codegen_goto_stmt(g, ast);
+ } else if (ast->kind == AstNodeKind_label_stmt) {
+ codegen_label_stmt(g, ast);
} else if (ast->kind == AstNodeKind_expr_stmt) {
codegen_expr_stmt(g, ast);
} else if (ast->kind == AstNodeKind_lvar_decl) {