diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-02-19 16:30:19 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-02-19 16:30:19 -0500 |
| commit | b89291957acbefbb0e9db90421411094ebc6aed8 (patch) | |
| tree | f37c2e971b1322b7e80c3bb8b163fadd16772441 /tomo.c | |
| parent | c4479e4bd61fb2c68fdac2637a20d6d99f7b9552 (diff) | |
Restructure compile_file() so it moves a bit more towards less usage of
side effects
Diffstat (limited to 'tomo.c')
| -rw-r--r-- | tomo.c | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -218,6 +218,27 @@ static void _compile_statement_header_for_library(libheader_info_t *info, ast_t } } +static void _make_typedefs_for_library(libheader_info_t *info, ast_t *ast) +{ + if (ast->tag == StructDef) { + auto def = Match(ast, StructDef); + CORD full_name = CORD_cat(namespace_prefix(info->env, info->env->namespace), def->name); + CORD_put(CORD_all("typedef struct ", full_name, "_s ", full_name, "_t;\n"), info->output); + } else if (ast->tag == EnumDef) { + auto def = Match(ast, EnumDef); + CORD full_name = CORD_cat(namespace_prefix(info->env, info->env->namespace), def->name); + CORD_put(CORD_all("typedef struct ", full_name, "_s ", full_name, "_t;\n"), info->output); + + for (tag_ast_t *tag = def->tags; tag; tag = tag->next) { + if (!tag->fields) continue; + CORD_put(CORD_all("typedef struct ", full_name, "$", tag->name, "_s ", full_name, "$", tag->name, "_t;\n"), info->output); + } + } else if (ast->tag == LangDef) { + auto def = Match(ast, LangDef); + CORD_put(CORD_all("typedef Text_t ", namespace_prefix(info->env, info->env->namespace), def->name, "_t;\n"), info->output); + } +} + static void _compile_file_header_for_library(env_t *env, Text_t filename, Table_t *visited_files, Table_t *used_imports, FILE *output) { if (Table$get(*visited_files, &filename, Table$info(&Text$info, &Text$info))) @@ -250,6 +271,8 @@ static void _compile_file_header_for_library(env_t *env, Text_t filename, Table_ } visit_topologically( + Match(file_ast, Block)->statements, (Closure_t){.fn=(void*)_make_typedefs_for_library, &info}); + visit_topologically( Match(file_ast, Block)->statements, (Closure_t){.fn=(void*)_compile_statement_header_for_library, &info}); CORD_fprintf(output, "void %r$initialize(void);\n", namespace_prefix(module_env, module_env->namespace)); |
