aboutsummaryrefslogtreecommitdiff
path: root/tomo.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-06-13 13:17:51 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-06-13 13:17:51 -0400
commitdab2c399f1b574b598c908124acebaa06c80938a (patch)
tree16cfc4ea17a35155a67d663c2f41f5834cf1d6f0 /tomo.c
parent5d682df66c96c4f718a01cb5a738986e3510fcf9 (diff)
Split import/use into separate concepts
Diffstat (limited to 'tomo.c')
-rw-r--r--tomo.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/tomo.c b/tomo.c
index 667a497e..8c011f33 100644
--- a/tomo.c
+++ b/tomo.c
@@ -258,26 +258,23 @@ void build_file_dependency_graph(const char *filename, table_t *to_compile, tabl
char *file_dir = realpath(filename, NULL);
dirname(file_dir);
for (ast_list_t *stmt = Match(ast, Block)->statements; stmt; stmt = stmt->next) {
- const char *use_path = NULL;
- if (stmt->ast->tag == Use) {
- use_path = Match(stmt->ast, Use)->raw_path;
- } else if (stmt->ast->tag == Declare) {
- auto decl = Match(stmt->ast, Declare);
- if (decl->value->tag == Use)
- use_path = Match(decl->value, Use)->raw_path;
- }
- if (!use_path) continue;
- if (use_path[0] == '/' || strncmp(use_path, "~/", 2) == 0 || strncmp(use_path, "./", 2) == 0 || strncmp(use_path, "../", 3) == 0) {
- const char *path = resolve_path(heap_strf("%s.tm", use_path), filename, "");
- if (!path) errx(1, "Couldn't resolve import: %s", use_path);
+ ast_t *stmt_ast = stmt->ast;
+ if (stmt_ast->tag == Declare)
+ stmt_ast = Match(stmt_ast, Declare)->value;
+
+ if (stmt_ast->tag == Import) {
+ const char *path = Match(stmt_ast, Import)->path;
+ path = resolve_path(heap_strf("%s.tm", path), filename, "");
+ if (!path) errx(1, "Couldn't resolve import: %s", path);
if (Table$str_get(*to_compile, path))
continue;
Table$str_set(to_compile, path, path);
build_file_dependency_graph(path, to_compile, to_link);
- } else {
- const char *libfile = resolve_path(heap_strf("%s/lib%s.so", use_path, use_path), filename, getenv("TOMO_IMPORT_PATH"));
- if (!libfile) errx(1, "Couldn't resolve path: %s", use_path);
- const char *lib = heap_strf("-l%s", use_path);
+ } else if (stmt_ast->tag == Use) {
+ const char *name = Match(stmt_ast, Use)->name;
+ const char *libfile = resolve_path(heap_strf("%s/lib%s.so", name, name), filename, getenv("TOMO_IMPORT_PATH"));
+ if (!libfile) errx(1, "Couldn't resolve path: %s", name);
+ const char *lib = heap_strf("-l%s", name);
Table$str_set(to_link, lib, lib);
}
}