aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-06-16 18:40:34 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-06-16 18:40:34 -0400
commit28de9aeb84e4257773b6d7f4c4cb04a0c1e10d40 (patch)
tree8830f7455c423aed6bbd7879fe7f47447e8f9d59
parent4724d40e413c953b77ff4ff26d128a6a5daac874 (diff)
Deprecate '-l' as a command line flag but instead support 'use -lblah'
-rw-r--r--compile.c5
-rw-r--r--tomo.c28
-rw-r--r--typecheck.c3
3 files changed, 15 insertions, 21 deletions
diff --git a/compile.c b/compile.c
index 4e41729f..83d99804 100644
--- a/compile.c
+++ b/compile.c
@@ -2320,7 +2320,10 @@ CORD compile_statement_header(env_t *env, ast_t *ast)
}
case Use: {
const char *name = Match(ast, Use)->name;
- return CORD_all("#include <tomo/lib", name, ".h>\n");
+ if (strncmp(name, "-l", 2) == 0)
+ return CORD_EMPTY;
+ else
+ return CORD_all("#include <tomo/lib", name, ".h>\n");
}
default:
return CORD_EMPTY;
diff --git a/tomo.c b/tomo.c
index 9b8d696a..a40c033b 100644
--- a/tomo.c
+++ b/tomo.c
@@ -126,10 +126,6 @@ int main(int argc, char *argv[])
table_t to_link = {};
for (int i = after_flags; i < argc; i++) {
- if (strncmp(argv[i], "-l", 2) == 0) {
- ldlibs = CORD_all(ldlibs, " ", argv[i]);
- continue;
- }
const char *resolved = resolve_path(argv[i], ".", ".");
if (!resolved) errx(1, "Couldn't resolve path: %s", argv[i]);
build_file_dependency_graph(resolved, &dependency_files, &to_link);
@@ -139,8 +135,6 @@ int main(int argc, char *argv[])
int status;
// Non-lazily (re)compile header files for each source file passed to the compiler:
for (int i = after_flags; i < argc; i++) {
- if (strncmp(argv[i], "-l", 2) == 0)
- continue;
const char *filename = argv[i];
status = transpile_header(env, filename, true);
if (status != 0) return status;
@@ -157,8 +151,6 @@ int main(int argc, char *argv[])
// Non-lazily (re)compile object files for each source file passed to the compiler:
for (int i = after_flags; i < argc; i++) {
- if (strncmp(argv[i], "-l", 2) == 0)
- continue;
const char *filename = argv[i];
status = transpile_code(env, filename, true);
if (status != 0) return status;
@@ -203,8 +195,6 @@ int main(int argc, char *argv[])
FILE *header_prog = CORD_RUN(autofmt ? autofmt : "cat", " 2>/dev/null >", h_filename);
fputs("#pragma once\n", header_prog);
for (int i = after_flags; i < argc; i++) {
- if (strncmp(argv[i], "-l", 2) == 0)
- continue;
const char *filename = argv[i];
file_t *f = load_file(filename);
if (!f) errx(1, "No such file: %s", filename);
@@ -227,8 +217,6 @@ int main(int argc, char *argv[])
if (!files_file)
errx(1, "Couldn't open file: %s", files_filename);
for (int i = after_flags; i < argc; i++) {
- if (strncmp(argv[i], "-l", 2) == 0)
- continue;
fprintf(files_file, "%s\n", argv[i]);
}
if (fclose(files_file))
@@ -238,8 +226,6 @@ int main(int argc, char *argv[])
unlink("symbol_renames.txt");
FILE *prog;
for (int i = after_flags; i < argc; i++) {
- if (strncmp(argv[i], "-l", 2) == 0)
- continue;
prog = CORD_RUN("nm -U -fjust-symbols ", argv[i], ".o | sed 's/.*/\\0 ", libname_id, "$\\0/' >>symbol_renames.txt");
status = pclose(prog);
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
@@ -280,8 +266,6 @@ int main(int argc, char *argv[])
}
return 0;
} else {
- while (after_flags < argc && strncmp(argv[after_flags], "-l", 2) == 0)
- ++after_flags;
const char *filename = argv[after_flags];
int executable_status = compile_executable(env, filename, object_files);
if (mode == MODE_COMPILE_EXE || executable_status != 0)
@@ -335,10 +319,14 @@ void build_file_dependency_graph(const char *filename, table_t *to_compile, tabl
build_file_dependency_graph(path, to_compile, to_link);
} 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);
+ 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);
+ }
}
}
free(file_dir);
diff --git a/typecheck.c b/typecheck.c
index f7f4ccc7..d3ce2da6 100644
--- a/typecheck.c
+++ b/typecheck.c
@@ -351,6 +351,9 @@ void bind_statement(env_t *env, ast_t *statement)
break;
}
case Use: case Import: {
+ if (statement->tag == Use && strncmp(Match(statement, Use)->name, "-l", 2) == 0)
+ break;
+
env_t *module_env = load_module(env, statement);
for (table_t *bindings = module_env->locals; bindings != module_env->globals; bindings = bindings->fallback) {
for (int64_t i = 1; i <= Table$length(*bindings); i++) {