diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-08-24 17:48:31 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-08-24 17:48:31 -0400 |
| commit | 9095599bc5184239fdc3dd35bc5bbbb89452b5c6 (patch) | |
| tree | b58dd0887d4dfb28d8a457b93c976b0bd98af7e9 /src/compile/assignments.c | |
| parent | eadd5ac512aa9b9ac9d045cf402242c79ee4cb0b (diff) | |
Split declarations into a file
Diffstat (limited to 'src/compile/assignments.c')
| -rw-r--r-- | src/compile/assignments.c | 43 |
1 files changed, 1 insertions, 42 deletions
diff --git a/src/compile/assignments.c b/src/compile/assignments.c index a31aee56..c7e61e26 100644 --- a/src/compile/assignments.c +++ b/src/compile/assignments.c @@ -7,6 +7,7 @@ #include "../stdlib/text.h" #include "../stdlib/util.h" #include "../typecheck.h" +#include "declarations.h" #include "integers.h" #include "pointers.h" #include "promotions.h" @@ -85,48 +86,6 @@ Text_t compile_update_assignment(env_t *env, ast_t *ast) { } public -Text_t compile_declaration(type_t *t, Text_t name) { - if (t->tag == FunctionType) { - DeclareMatch(fn, t, FunctionType); - Text_t code = Texts(compile_type(fn->ret), " (*", name, ")("); - for (arg_t *arg = fn->args; arg; arg = arg->next) { - code = Texts(code, compile_type(arg->type)); - if (arg->next) code = Texts(code, ", "); - } - if (!fn->args) code = Texts(code, "void"); - return Texts(code, ")"); - } else if (t->tag != ModuleType) { - return Texts(compile_type(t), " ", name); - } else { - return EMPTY_TEXT; - } -} - -public -Text_t compile_declared_value(env_t *env, ast_t *declare_ast) { - DeclareMatch(decl, declare_ast, Declare); - type_t *t = decl->type ? parse_type_ast(env, decl->type) : get_type(env, decl->value); - - if (t->tag == AbortType || t->tag == VoidType || t->tag == ReturnType) - code_err(declare_ast, "You can't declare a variable with a ", type_to_str(t), " value"); - - if (decl->value) { - Text_t val_code = compile_maybe_incref(env, decl->value, t); - if (t->tag == FunctionType) { - assert(promote(env, decl->value, &val_code, t, Type(ClosureType, t))); - t = Type(ClosureType, t); - } - return val_code; - } else { - Text_t val_code = compile_empty(t); - if (val_code.length == 0) - code_err(declare_ast, "This type (", type_to_str(t), - ") cannot be uninitialized. You must provide a value."); - return val_code; - } -} - -public Text_t compile_assignment(env_t *env, ast_t *target, Text_t value) { return Texts(compile_lvalue(env, target), " = ", value); } |
