aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-03-19 14:30:40 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-03-19 14:30:40 -0400
commit80ea0f85079eaac027b930b7d54df46e2039e7c3 (patch)
treefaf06bea2f06a91abeb89545ae82ea86d0ddce56
parent71f4da18f27e488035e872f1dc1527b727acdcae (diff)
Corecursive modules
-rw-r--r--compile.c1
-rw-r--r--typecheck.c6
2 files changed, 7 insertions, 0 deletions
diff --git a/compile.c b/compile.c
index 0567dc7d..5ebbf93e 100644
--- a/compile.c
+++ b/compile.c
@@ -1768,6 +1768,7 @@ module_code_t compile_file(ast_t *ast)
const char *name = file_base_name(ast->file->filename);
env->file_prefix = heap_strf("%s$", name);
+ Table_str_set(env->imports, name, env);
CORD_appendf(&env->code->imports, "#include <tomo/tomo.h>\n");
diff --git a/typecheck.c b/typecheck.c
index eacf4264..eee5f6f3 100644
--- a/typecheck.c
+++ b/typecheck.c
@@ -208,8 +208,14 @@ void bind_statement(env_t *env, ast_t *statement)
case Use: {
auto use = Match(statement, Use);
const char *name = file_base_name(use->path);
+ if (Table_str_get(*env->imports, name))
+ break;
+
env_t *module_env = new_compilation_unit();
module_env->file_prefix = heap_strf("%s$", name);
+ Table_str_set(module_env->imports, name, module_env);
+ const char *my_name = heap_strn(CORD_to_const_char_star(env->file_prefix), CORD_len(env->file_prefix)-1);
+ Table_str_set(module_env->imports, my_name, env);
file_t *f = load_file(use->path);
if (!f) errx(1, "No such file: %s", use->path);