diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-06-06 16:28:53 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-06-06 16:28:53 -0400 |
| commit | 8c7d53008072dfda8b9d60be92fae1a8046fae5d (patch) | |
| tree | 769407e0461b3c989c27a740c423827a21adfa91 /environment.c | |
| parent | 31c8d0af1597b6b4996a90808b1b8c0983db309e (diff) | |
Split header compilation into a separate function
Diffstat (limited to 'environment.c')
| -rw-r--r-- | environment.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/environment.c b/environment.c index d5f6a15c..0c37c525 100644 --- a/environment.c +++ b/environment.c @@ -235,6 +235,29 @@ env_t *new_compilation_unit(void) return env; } +env_t *load_module_env(env_t *env, ast_t *ast) +{ + const char *name = file_base_name(ast->file->filename); + env_t *cached = Table$str_get(*env->imports, name); + if (cached) return cached; + env = fresh_scope(env); + env->file_prefix = heap_strf("%s$", name); + Table$str_set(env->imports, name, env); + + for (ast_list_t *stmt = Match(ast, Block)->statements; stmt; stmt = stmt->next) + prebind_statement(env, stmt->ast); + + for (ast_list_t *stmt = Match(ast, Block)->statements; stmt; stmt = stmt->next) { + // Hack: make sure global variables are bound as foo$var: + if (stmt->ast->tag == Declare && Match(Match(stmt->ast, Declare)->var, Var)->name[0] != '_') + env->scope_prefix = heap_strf("%s$", name); + bind_statement(env, stmt->ast); + env->scope_prefix = NULL; + } + Table$str_set(env->imports, name, env); + return env; +} + env_t *global_scope(env_t *env) { env_t *scope = new(env_t); |
