diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-02-11 14:17:01 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-02-11 14:17:01 -0500 |
| commit | 536c161b7489c7922eecd7c389db11383448dbee (patch) | |
| tree | 66f9a9370c256a9dabe2ad91a5c4d214a924124c | |
| parent | ba52a428a1ad5f2d106e51a238afa0985121cefd (diff) | |
Output tweaks
| -rw-r--r-- | nextlang.c | 22 |
1 files changed, 11 insertions, 11 deletions
@@ -44,39 +44,39 @@ int main(int argc, char *argv[]) fclose(out); } - CORD header = "#include \"nextlang.h\"\n\n"; + CORD header = "#include \"nextlang.h\"\n"; // Predeclare types: for (ast_list_t *stmt = Match(ast, Block)->statements; stmt; stmt = stmt->next) { switch (stmt->ast->tag) { case StructDef: case EnumDef: { - header = CORD_cat(header, compile(stmt->ast)); + CORD_sprintf(&header, "%r\n%r", header, compile(stmt->ast)); break; } default: break; } } + CORD program = CORD_cat(header, "\n/////////////////////////////////////////////////////////////////////////\n\n" + "bool USE_COLOR = true;\n"); + // Predeclare funcs: for (ast_list_t *stmt = Match(ast, Block)->statements; stmt; stmt = stmt->next) { switch (stmt->ast->tag) { case FunctionDef: { auto fndef = Match(stmt->ast, FunctionDef); - CORD_sprintf(&header, "%rstatic %r %r(", header, fndef->ret_type ? compile_type(fndef->ret_type) : "void", compile(fndef->name)); + CORD_sprintf(&program, "%rstatic %r %r(", program, fndef->ret_type ? compile_type(fndef->ret_type) : "void", compile(fndef->name)); for (arg_ast_t *arg = fndef->args; arg; arg = arg->next) { - CORD_sprintf(&header, "%r%r %s", header, compile_type(arg->type), arg->name); - if (arg->next) header = CORD_cat(header, ", "); + CORD_sprintf(&program, "%r%r %s", program, compile_type(arg->type), arg->name); + if (arg->next) program = CORD_cat(program, ", "); } - header = CORD_cat(header, ");\n"); + program = CORD_cat(program, ");\n"); break; } default: break; } } - CORD program = CORD_cat(header, "\n/////////////////////////////////////////////////////////////////////////\n\n" - "bool USE_COLOR = true;"); - // Declare funcs: for (ast_list_t *stmt = Match(ast, Block)->statements; stmt; stmt = stmt->next) { switch (stmt->ast->tag) { @@ -95,7 +95,7 @@ int main(int argc, char *argv[]) "(void)argv;\n" "GC_INIT();\n" "USE_COLOR = getenv(\"COLOR\") ? strcmp(getenv(\"COLOR\"), \"1\") == 0 : isatty(STDOUT_FILENO);\n" - "\n"); + "// User code:\n"); for (ast_list_t *stmt = Match(ast, Block)->statements; stmt; stmt = stmt->next) { switch (stmt->ast->tag) { case FunctionDef: case StructDef: case EnumDef: break; @@ -106,7 +106,7 @@ int main(int argc, char *argv[]) } } } - program = CORD_cat(program, "\nreturn 0;\n}\n"); + program = CORD_cat(program, "return 0;\n}\n"); if (verbose) { FILE *out = popen(autofmt, "w"); |
