diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-04-23 17:50:28 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-04-23 17:50:28 -0400 |
| commit | e3a79d45f641a7cd866cb53e766b8606a72b2ba1 (patch) | |
| tree | 4a5a1742f17cb65e20db47bb4acbb2694aed8b16 | |
| parent | 864515595e8798273f55979fcb28040c4c7f50e5 (diff) | |
Bugfix for `use ./foo.c` putting the #include below lambda definitions
| -rw-r--r-- | src/compile.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/compile.c b/src/compile.c index 8d6a4d60..15853256 100644 --- a/src/compile.c +++ b/src/compile.c @@ -4315,11 +4315,11 @@ CORD compile_top_level_code(env_t *env, ast_t *ast) switch (ast->tag) { case Use: { - DeclareMatch(use, ast, Use); - if (use->what == USE_C_CODE) { - Path_t path = Path$relative_to(Path$from_str(use->path), Path(".build")); - return CORD_all("#include \"", Path$as_c_string(path), "\"\n"); - } + // DeclareMatch(use, ast, Use); + // if (use->what == USE_C_CODE) { + // Path_t path = Path$relative_to(Path$from_str(use->path), Path(".build")); + // return CORD_all("#include \"", Path$as_c_string(path), "\"\n"); + // } return CORD_EMPTY; } case Declare: { @@ -4451,12 +4451,20 @@ static void initialize_vars_and_statics(env_t *env, ast_t *ast) CORD compile_file(env_t *env, ast_t *ast) { CORD top_level_code = compile_top_level_code(env, ast); + CORD includes = CORD_EMPTY; CORD use_imports = CORD_EMPTY; // First prepare variable initializers to prevent unitialized access: for (ast_list_t *stmt = Match(ast, Block)->statements; stmt; stmt = stmt->next) { - if (stmt->ast->tag == Use) + if (stmt->ast->tag == Use) { use_imports = CORD_all(use_imports, compile_statement(env, stmt->ast)); + + DeclareMatch(use, stmt->ast, Use); + if (use->what == USE_C_CODE) { + Path_t path = Path$relative_to(Path$from_str(use->path), Path(".build")); + includes = CORD_all(includes, "#include \"", Path$as_c_string(path), "\"\n"); + } + } } initialize_vars_and_statics(env, ast); @@ -4467,6 +4475,7 @@ CORD compile_file(env_t *env, ast_t *ast) "#define __SOURCE_FILE__ ", CORD_quoted(ast->file->filename), "\n", "#include <tomo/tomo.h>\n" "#include \"", name, ".tm.h\"\n\n", + includes, env->code->local_typedefs, "\n", env->code->lambdas, "\n", env->code->staticdefs, "\n", |
