diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-08-22 14:02:48 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-08-22 14:02:48 -0400 |
| commit | ad51b208b4924d04f1d6a804178a67994b4f9e59 (patch) | |
| tree | 9ae29e0af02b7406a0cf07fdd8b0dd7fdac0aedf /tomo.c | |
| parent | 2055439be4f5053b9a4d631cefd8bb7c83a8e4e3 (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.c | 44 |
1 files changed, 29 insertions, 15 deletions
@@ -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); |
