aboutsummaryrefslogtreecommitdiff
path: root/tomo.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-08-22 14:02:48 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-08-22 14:02:48 -0400
commitad51b208b4924d04f1d6a804178a67994b4f9e59 (patch)
tree9ae29e0af02b7406a0cf07fdd8b0dd7fdac0aedf /tomo.c
parent2055439be4f5053b9a4d631cefd8bb7c83a8e4e3 (diff)
Overhaul of import syntax. Now everything uses `use`: `use foo`, `use
./foo.tm`, `use <foo.h>`, `use libfoo.so`
Diffstat (limited to 'tomo.c')
-rw-r--r--tomo.c44
1 files changed, 29 insertions, 15 deletions
diff --git a/tomo.c b/tomo.c
index 78ab833a..8b69f1f4 100644
--- a/tomo.c
+++ b/tomo.c
@@ -216,6 +216,7 @@ int main(int argc, char *argv[])
CORD h = compile_statement_definitions(env, stmt->ast);
if (h) CORD_put(h, header_prog);
}
+ fprintf(header_prog, "void %s$%s$$initialize(void);\n", libname, file_base_name(filename));
}
if (pclose(header_prog) == -1)
errx(1, "Failed to run autoformat program on header file: %s", autofmt);
@@ -316,24 +317,37 @@ void build_file_dependency_graph(const char *filename, table_t *to_compile, tabl
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 (stmt_ast->tag != Use) continue;
+ auto use = Match(stmt_ast, Use);
+
+ switch (use->what) {
+ case USE_LOCAL: {
+ const char *path = use->name;
+ path = resolve_path(path, filename, "");
+ if (!path) errx(1, "Couldn't resolve import: %s", use->name);
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 if (stmt_ast->tag == Use) {
- const char *name = Match(stmt_ast, Use)->name;
- if (strncmp(name, "-l", 2) == 0) {
- Table$str_set(to_link, name, name);
- } else {
- 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);
- }
+ Table$str_set(to_compile, path, path);
+ break;
+ }
+ case USE_MODULE: {
+ const char *base_name = file_base_name(use->name);
+ const char *lib_path = heap_strf("%s/lib%s.so", base_name, base_name);
+ const char *libfile = resolve_path(lib_path, filename, getenv("TOMO_IMPORT_PATH"));
+ if (!libfile) errx(1, "Couldn't resolve path: %s", lib_path);
+ const char *lib = heap_strf("-l%s", use->name);
+ Table$str_set(to_link, lib, lib);
+ break;
+ }
+ case USE_SHARED_OBJECT: {
+ const char *lib = heap_strf("-l:%s", use->name);
+ Table$str_set(to_link, lib, lib);
+ break;
+ }
+ case USE_HEADER: {
+ break;
+ }
}
}
free(file_dir);