diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-09-03 20:27:16 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-09-03 20:27:16 +0900 |
| commit | f3a1ea57244608c1795e7f90cb3077c6a01686a9 (patch) | |
| tree | bfa3d91dd15d5d42043c2ed8fbd717614931d748 /src/ast.c | |
| parent | 5541c597cb68f76d1fc53e01b931eb870856843c (diff) | |
| download | ducc-f3a1ea57244608c1795e7f90cb3077c6a01686a9.tar.gz ducc-f3a1ea57244608c1795e7f90cb3077c6a01686a9.tar.zst ducc-f3a1ea57244608c1795e7f90cb3077c6a01686a9.zip | |
feat: rewrite function declaration parsing
Diffstat (limited to 'src/ast.c')
| -rw-r--r-- | src/ast.c | 21 |
1 files changed, 14 insertions, 7 deletions
@@ -45,6 +45,8 @@ const char* type_kind_stringify(TypeKind k) { return "<pointer>"; else if (k == TypeKind_array) return "<array>"; + else if (k == TypeKind_func) + return "<function>"; else unreachable(); } @@ -60,16 +62,14 @@ Type* type_new(TypeKind kind) { } Type* type_new_ptr(Type* base) { - Type* ty = calloc(1, sizeof(Type)); - ty->kind = TypeKind_ptr; + Type* ty = type_new(TypeKind_ptr); ty->base = base; return ty; } -Type* type_new_array(Type* elem, int size) { - Type* ty = calloc(1, sizeof(Type)); - ty->kind = TypeKind_array; - ty->base = elem; +Type* type_new_array(Type* base, int size) { + Type* ty = type_new(TypeKind_array); + ty->base = base; ty->array_size = size; return ty; } @@ -82,8 +82,15 @@ Type* type_array_to_ptr(Type* ty) { return type_new_ptr(ty->base); } +Type* type_new_func(Type* result, AstNode* params) { + Type* ty = type_new(TypeKind_func); + ty->result = result; + ty->params = params; + return ty; +} + BOOL type_is_unsized(Type* ty) { - return ty->kind == TypeKind_void; + return ty->kind == TypeKind_void || ty->kind == TypeKind_func; } int type_sizeof(Type* ty) { |
