aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/compile.c20
-rw-r--r--src/environment.c3
-rw-r--r--src/environment.h3
-rw-r--r--src/repl.c2
-rw-r--r--src/tomo.c13
5 files changed, 23 insertions, 18 deletions
diff --git a/src/compile.c b/src/compile.c
index f1c3aa07..95a79ec5 100644
--- a/src/compile.c
+++ b/src/compile.c
@@ -67,9 +67,9 @@ CORD promote_to_optional(type_t *t, CORD code)
}
}
-static CORD with_source_info(ast_t *ast, CORD code)
+static CORD with_source_info(env_t *env, ast_t *ast, CORD code)
{
- if (code == CORD_EMPTY || !ast || !ast->file)
+ if (code == CORD_EMPTY || !ast || !ast->file || !env->do_source_mapping)
return code;
int64_t line = get_line_number(ast->file, ast->start);
return CORD_asprintf("\n#line %ld\n%r", line, code);
@@ -1878,7 +1878,7 @@ static CORD _compile_statement(env_t *env, ast_t *ast)
auto use = Match(ast, Use);
if (use->what == USE_LOCAL) {
CORD name = file_base_id(Match(ast, Use)->path);
- return with_source_info(ast, CORD_all("_$", name, "$$initialize();\n"));
+ return with_source_info(env, ast, CORD_all("_$", name, "$$initialize();\n"));
} else if (use->what == USE_MODULE) {
glob_t tm_files;
if (glob(String("~/.local/share/tomo/installed/", use->path, "/[!._0-9]*.tm"), GLOB_TILDE, NULL, &tm_files) != 0)
@@ -1896,7 +1896,7 @@ static CORD _compile_statement(env_t *env, ast_t *ast)
const char *filename = tm_files.gl_pathv[i];
initialization = CORD_all(
initialization,
- with_source_info(ast, CORD_all("_$", lib_id, "$", file_base_id(filename), "$$initialize();\n")));
+ with_source_info(env, ast, CORD_all("_$", lib_id, "$", file_base_id(filename), "$$initialize();\n")));
}
globfree(&tm_files);
return initialization;
@@ -1914,7 +1914,7 @@ static CORD _compile_statement(env_t *env, ast_t *ast)
CORD compile_statement(env_t *env, ast_t *ast) {
CORD stmt = _compile_statement(env, ast);
- return with_source_info(ast, stmt);
+ return with_source_info(env, ast, stmt);
}
CORD expr_as_text(CORD expr, type_t *t, CORD color)
@@ -4113,7 +4113,7 @@ CORD compile_function(env_t *env, CORD name_code, ast_t *ast, CORD *staticdefs)
}
CORD body_code = CORD_all("{\n", compile_inline_block(body_scope, body), "}\n");
- CORD definition = with_source_info(ast, CORD_all(code, " ", body_code, "\n"));
+ CORD definition = with_source_info(env, ast, CORD_all(code, " ", body_code, "\n"));
if (cache && args == NULL) { // no-args cache just uses a static var
CORD wrapper = CORD_all(
@@ -4329,7 +4329,7 @@ static void initialize_vars_and_statics(env_t *env, ast_t *ast)
env->code->variable_initializers = CORD_all(
env->code->variable_initializers,
with_source_info(
- stmt->ast,
+ env, stmt->ast,
CORD_all(
full_name, " = ", val_code, ",\n",
full_name, "$initialized = true;\n")));
@@ -4371,7 +4371,7 @@ CORD compile_file(env_t *env, ast_t *ast)
const char *name = file_base_name(ast->file->filename);
return CORD_all(
- "#line 1 ", CORD_quoted(ast->file->filename), "\n",
+ env->do_source_mapping ? CORD_all("#line 1 ", CORD_quoted(ast->file->filename), "\n") : CORD_EMPTY,
"#define __SOURCE_FILE__ ", CORD_quoted(ast->file->filename), "\n",
"#include <tomo/tomo.h>\n"
"#include \"", name, ".tm.h\"\n\n",
@@ -4607,8 +4607,8 @@ static void _define_types_and_funcs(compile_typedef_info_t *info, ast_t *ast)
CORD compile_file_header(env_t *env, Path_t header_path, ast_t *ast)
{
CORD header = CORD_all(
- "#pragma once\n"
- "#line 1 ", CORD_quoted(ast->file->filename), "\n",
+ "#pragma once\n",
+ env->do_source_mapping ? CORD_all("#line 1 ", CORD_quoted(ast->file->filename), "\n") : CORD_EMPTY,
"#include <tomo/tomo.h>\n");
compile_typedef_info_t info = {.env=env, .header=&header, .header_path=header_path};
diff --git a/src/environment.c b/src/environment.c
index f32471a4..ea056bb0 100644
--- a/src/environment.c
+++ b/src/environment.c
@@ -48,7 +48,7 @@ static type_t *bind_type(env_t *env, const char *name, type_t *type)
return type;
}
-env_t *global_env(void)
+env_t *global_env(bool source_mapping)
{
static env_t *_global_env = NULL;
if (_global_env != NULL) return _global_env;
@@ -59,6 +59,7 @@ env_t *global_env(void)
env->globals = new(Table_t);
env->locals = env->globals;
env->imports = new(Table_t);
+ env->do_source_mapping = source_mapping;
TEXT_TYPE = bind_type(env, "Text", Type(TextType, .lang="Text", .env=namespace_env(env, "Text")));
(void)bind_type(env, "Int", Type(BigIntType));
diff --git a/src/environment.h b/src/environment.h
index f9ddd6b0..1c6d52a5 100644
--- a/src/environment.h
+++ b/src/environment.h
@@ -51,6 +51,7 @@ typedef struct env_s {
CORD libname; // Currently compiling library name (if any)
namespace_t *namespace;
Closure_t *comprehension_action;
+ bool do_source_mapping:1;
} env_t;
typedef struct {
@@ -58,7 +59,7 @@ typedef struct {
CORD code;
} binding_t;
-env_t *global_env(void);
+env_t *global_env(bool source_mapping);
env_t *load_module_env(env_t *env, ast_t *ast);
CORD namespace_prefix(env_t *env, namespace_t *ns);
env_t *get_namespace_by_type(env_t *env, type_t *t);
diff --git a/src/repl.c b/src/repl.c
index bd08a3e4..aae80b2c 100644
--- a/src/repl.c
+++ b/src/repl.c
@@ -42,7 +42,7 @@ static PUREFUNC repl_binding_t *get_repl_binding(env_t *env, const char *name)
void repl(void)
{
- env_t *env = global_env();
+ env_t *env = global_env(true);
size_t buf_size = 0;
char *line = NULL;
ssize_t len = 0;
diff --git a/src/tomo.c b/src/tomo.c
index 61f2ed3d..865af840 100644
--- a/src/tomo.c
+++ b/src/tomo.c
@@ -55,7 +55,8 @@ static OptionalBool_t verbose = false,
compile_exe = false,
should_install = false,
run_repl = false,
- clean_build = false;
+ clean_build = false,
+ source_mapping = true;
static OptionalText_t
show_codegen = NONE_TEXT,
@@ -178,6 +179,8 @@ int main(int argc, char *argv[])
{"O", false, &Text$info, &optimization},
{"force-rebuild", false, &Bool$info, &clean_build},
{"f", false, &Bool$info, &clean_build},
+ {"source-mapping", false, &Bool$info, &source_mapping},
+ {"m", false, &Bool$info, &source_mapping},
);
bool is_gcc = (system(String(cc, " -v 2>&1 | grep 'gcc version' >/dev/null")) == 0);
@@ -254,7 +257,7 @@ int main(int argc, char *argv[])
pid_t child = fork();
if (child == 0) {
- env_t *env = global_env();
+ env_t *env = global_env(source_mapping);
List_t object_files = {},
extra_ldlibs = {};
compile_files(env, files, &object_files, &extra_ldlibs);
@@ -411,7 +414,7 @@ static void _compile_file_header_for_library(env_t *env, Path_t header_path, Pat
void build_library(Text_t lib_dir_name)
{
List_t tm_files = Path$glob(Path("./[!._0-9]*.tm"));
- env_t *env = fresh_scope(global_env());
+ env_t *env = fresh_scope(global_env(source_mapping));
List_t object_files = {},
extra_ldlibs = {};
@@ -718,8 +721,8 @@ void transpile_code(env_t *base_env, Path_t path)
", but it should not have any return value!");
CORD_put(CORD_all(
- "int ", main_binding->code, "$parse_and_run(int argc, char *argv[]) {\n"
- "#line 1\n"
+ "int ", main_binding->code, "$parse_and_run(int argc, char *argv[]) {\n",
+ module_env->do_source_mapping ? "#line 1\n" : CORD_EMPTY,
"tomo_init();\n",
"_$", module_env->namespace->name, "$$initialize();\n"
"\n",