aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-07-29 06:09:06 +0900
committernsfisis <nsfisis@gmail.com>2025-08-15 10:04:35 +0900
commitf91a10ae153f41c46729605ecf0023d11ada07b8 (patch)
tree0bf858a43490f88e20fd4006543e069cfa54b43d
parentbd5bbdebf116bb03da335d0e18a55a5597b55548 (diff)
downloadducc-f91a10ae153f41c46729605ecf0023d11ada07b8.tar.gz
ducc-f91a10ae153f41c46729605ecf0023d11ada07b8.tar.zst
ducc-f91a10ae153f41c46729605ecf0023d11ada07b8.zip
feat: implement empty statements (only semicolon)
-rw-r--r--ast.c1
-rw-r--r--codegen.c5
-rw-r--r--parse.c7
-rw-r--r--tests/064.sh6
-rw-r--r--tests/065.sh8
5 files changed, 23 insertions, 4 deletions
diff --git a/ast.c b/ast.c
index ad5b83f..70ccb20 100644
--- a/ast.c
+++ b/ast.c
@@ -84,6 +84,7 @@ int type_alignof(Type* ty) {
enum AstNodeKind {
AstNodeKind_unknown,
+ AstNodeKind_nop,
AstNodeKind_assign_expr,
AstNodeKind_binary_expr,
diff --git a/codegen.c b/codegen.c
index d290e95..4bb15e2 100644
--- a/codegen.c
+++ b/codegen.c
@@ -400,6 +400,9 @@ void codegen_expr_stmt(CodeGen* g, AstNode* ast) {
void codegen_var_decl(CodeGen* g, AstNode* ast) {
}
+void codegen_nop(CodeGen* g, AstNode* ast) {
+}
+
void codegen_block_stmt(CodeGen* g, AstNode* ast) {
int i;
for (i = 0; i < ast->node_len; ++i) {
@@ -427,6 +430,8 @@ void codegen_stmt(CodeGen* g, AstNode* ast) {
codegen_expr_stmt(g, ast);
} else if (ast->kind == AstNodeKind_lvar_decl) {
codegen_var_decl(g, ast);
+ } else if (ast->kind == AstNodeKind_nop) {
+ codegen_nop(g, ast);
} else {
unreachable();
}
diff --git a/parse.c b/parse.c
index 9c635be..469ed49 100644
--- a/parse.c
+++ b/parse.c
@@ -703,6 +703,11 @@ AstNode* parse_block_stmt(Parser* p) {
return list;
}
+AstNode* parse_empty_stmt(Parser* p) {
+ next_token(p);
+ return ast_new(AstNodeKind_nop);
+}
+
AstNode* parse_stmt(Parser* p) {
Token* t = peek_token(p);
if (t->kind == TokenKind_keyword_return) {
@@ -721,6 +726,8 @@ AstNode* parse_stmt(Parser* p) {
return parse_continue_stmt(p);
} else if (t->kind == TokenKind_brace_l) {
return parse_block_stmt(p);
+ } else if (t->kind == TokenKind_semicolon) {
+ return parse_empty_stmt(p);
} else if (is_type_token(p, t)) {
return parse_var_decl(p);
} else {
diff --git a/tests/064.sh b/tests/064.sh
index 80fba4f..c3b6028 100644
--- a/tests/064.sh
+++ b/tests/064.sh
@@ -14,9 +14,7 @@ EOF
bash ../../test_exit_code.sh 0 <<'EOF'
int main() {
- if (1) {
- } else {
- return 1;
- }
+ if (1);
+ else return 1;
}
EOF
diff --git a/tests/065.sh b/tests/065.sh
new file mode 100644
index 0000000..b644bed
--- /dev/null
+++ b/tests/065.sh
@@ -0,0 +1,8 @@
+set -e
+
+cat <<'EOF' > expected
+EOF
+
+bash ../../test_diff.sh <<'EOF'
+int main() { ; }
+EOF