diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-03-24 15:06:59 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-03-24 15:06:59 -0400 |
| commit | 5157988efa388f956d3ea8204e496baf6db11b52 (patch) | |
| tree | b1cc89f2244d21de4811a3467b4bc15f795b7019 /typecheck.c | |
| parent | a29d2ed6d1735d4f12dd250900785db4271edeca (diff) | |
Implement 'extern' functionality
Diffstat (limited to 'typecheck.c')
| -rw-r--r-- | typecheck.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/typecheck.c b/typecheck.c index 615abe74..5a05d122 100644 --- a/typecheck.c +++ b/typecheck.c @@ -233,6 +233,14 @@ void bind_statement(env_t *env, ast_t *statement) Table_str_set(env->imports, name, module_env); break; } + case Extern: { + auto ext = Match(statement, Extern); + type_t *t = parse_type_ast(env, ext->type); + if (t->tag == ClosureType) + t = Match(t, ClosureType)->fn; + set_binding(env, ext->name, new(binding_t, .type=t, .code=ext->name)); + break; + } default: break; } } @@ -471,8 +479,6 @@ type_t *get_type(env_t *env, ast_t *ast) } case FunctionCall: { auto call = Match(ast, FunctionCall); - if (call->extern_return_type) - return parse_type_ast(env, call->extern_return_type); type_t *fn_type_t = get_type(env, call->fn); if (!fn_type_t) code_err(call->fn, "I couldn't find this function"); @@ -547,8 +553,7 @@ type_t *get_type(env_t *env, ast_t *ast) return get_type(block_env, last->ast); } case Extern: { - type_t *t = parse_type_ast(env, Match(ast, Extern)->type); - return Match(ast, Extern)->address ? Type(PointerType, .pointed=t, .is_optional=false) : t; + return parse_type_ast(env, Match(ast, Extern)->type); } case Declare: case Assign: case DocTest: case LinkerDirective: { return Type(VoidType); |
