aboutsummaryrefslogtreecommitdiff
path: root/src/compile.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-05-17 16:13:55 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-05-17 16:13:55 -0400
commit13e7d04a74f7ad0b9b9dc96f681d091b65dce5ec (patch)
tree321c63e528b939beab2f6f2c46192ab507546735 /src/compile.c
parent8febea9aebe05644731bb68c297d3d13649a8dcb (diff)
Add `modules.ini` file for import aliases, as well as default aliases
for the built-in modules.
Diffstat (limited to 'src/compile.c')
-rw-r--r--src/compile.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/compile.c b/src/compile.c
index 98c0bdb0..410ee364 100644
--- a/src/compile.c
+++ b/src/compile.c
@@ -1976,8 +1976,9 @@ static CORD _compile_statement(env_t *env, ast_t *ast)
CORD suffix = get_id_suffix(Path$as_c_string(path));
return with_source_info(env, ast, CORD_all("$initialize", suffix, "();\n"));
} else if (use->what == USE_MODULE) {
+ const char *name = module_alias(ast);
glob_t tm_files;
- if (glob(String(TOMO_PREFIX"/share/tomo_"TOMO_VERSION"/installed/", use->path, "/[!._0-9]*.tm"), GLOB_TILDE, NULL, &tm_files) != 0)
+ if (glob(String(TOMO_PREFIX"/share/tomo_"TOMO_VERSION"/installed/", name, "/[!._0-9]*.tm"), GLOB_TILDE, NULL, &tm_files) != 0)
code_err(ast, "Could not find library");
CORD initialization = CORD_EMPTY;
@@ -4483,16 +4484,17 @@ CORD compile_statement_type_header(env_t *env, Path_t header_path, ast_t *ast)
Path_t build_dir = Path$resolved(Path$parent(header_path), Path$current_dir());
switch (use->what) {
case USE_MODULE: {
+ const char *name = module_alias(ast);
glob_t tm_files;
- if (glob(String(TOMO_PREFIX"/share/tomo_"TOMO_VERSION"/installed/", use->path, "/[!._0-9]*.tm"), GLOB_TILDE, NULL, &tm_files) != 0)
+ if (glob(String(TOMO_PREFIX"/share/tomo_"TOMO_VERSION"/installed/", name, "/[!._0-9]*.tm"), GLOB_TILDE, NULL, &tm_files) != 0)
code_err(ast, "Could not find library");
CORD includes = CORD_EMPTY;
for (size_t i = 0; i < tm_files.gl_pathc; i++) {
const char *filename = tm_files.gl_pathv[i];
Path_t tm_file = Path$from_str(filename);
- Path_t lib_build_dir = Path$with_component(Path$parent(tm_file), Text(".build"));
- Path_t header = Path$with_component(lib_build_dir, Texts(Path$base_name(tm_file), Text(".h")));
+ Path_t lib_build_dir = Path$sibling(tm_file, Text(".build"));
+ Path_t header = Path$child(lib_build_dir, Texts(Path$base_name(tm_file), Text(".h")));
includes = CORD_all(includes, "#include \"", Path$as_c_string(header), "\"\n");
}
globfree(&tm_files);
@@ -4500,8 +4502,8 @@ CORD compile_statement_type_header(env_t *env, Path_t header_path, ast_t *ast)
}
case USE_LOCAL: {
Path_t used_path = Path$resolved(Path$from_str(use->path), source_dir);
- Path_t used_build_dir = Path$with_component(Path$parent(used_path), Text(".build"));
- Path_t used_header_path = Path$with_component(used_build_dir, Texts(Path$base_name(used_path), Text(".h")));
+ Path_t used_build_dir = Path$sibling(used_path, Text(".build"));
+ Path_t used_header_path = Path$child(used_build_dir, Texts(Path$base_name(used_path), Text(".h")));
return CORD_all("#include \"", Path$as_c_string(Path$relative_to(used_header_path, build_dir)), "\"\n");
}
case USE_HEADER: