aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compile.c9
-rw-r--r--nextlang.c2
2 files changed, 9 insertions, 2 deletions
diff --git a/compile.c b/compile.c
index 4611305e..6da984ea 100644
--- a/compile.c
+++ b/compile.c
@@ -19,13 +19,18 @@ CORD compile_type(env_t *env, type_ast_t *t)
CORD compile_statement(env_t *env, ast_t *ast)
{
+ CORD stmt;
switch (ast->tag) {
case If: case For: case While: case FunctionDef: case Return: case StructDef: case EnumDef:
case Declare: case Assign: case UpdateAssign: case DocTest:
- return compile(env, ast);
+ stmt = compile(env, ast);
+ break;
default:
- return CORD_asprintf("(void)%r;", compile(env, ast));
+ stmt = CORD_asprintf("(void)%r;", compile(env, ast));
+ break;
}
+ int64_t line = get_line_number(ast->file, ast->start);
+ return stmt ? CORD_asprintf("#line %ld\n%r", line, stmt) : stmt;
}
CORD compile(env_t *env, ast_t *ast)
diff --git a/nextlang.c b/nextlang.c
index 7a0f4e3a..98e54ebb 100644
--- a/nextlang.c
+++ b/nextlang.c
@@ -55,6 +55,7 @@ int main(int argc, char *argv[])
}
CORD program = CORD_asprintf(
+ "#line 0 \"%s\"\n" // file
"// Generated code:\n"
"%r\n" // imports
"%r\n" // typedefs
@@ -74,6 +75,7 @@ int main(int argc, char *argv[])
"__load();\n"
"return 0;\n"
"}\n",
+ f->filename,
env.imports, env.typedefs, env.types, env.staticdefs,
env.funcs, env.main);