diff options
| author | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-12 21:48:19 +0000 |
|---|---|---|
| committer | Zuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian> | 2026-01-12 21:48:45 +0000 |
| commit | 291650f52893682bfdb00a359461b6e4d5907a17 (patch) | |
| tree | 00f0dac5ba9ea5825367b4c1122daab4afbb3c58 /src/main.c | |
| parent | d0c9e962937c63bae9d101660dcc05cd38515dd0 (diff) | |
Added mode.
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -28,6 +28,7 @@ void print_usage() printf(" build Compile to executable\n"); printf(" check Check for errors only\n"); printf(" repl Start Interactive REPL\n"); + printf(" transpile Transpile to C code only (no compilation)\n"); printf(" lsp Start Language Server\n"); printf("Options:\n"); printf(" -o <file> Output executable name\n"); @@ -66,6 +67,11 @@ int main(int argc, char **argv) run_repl(argv[0]); // Pass self path for recursive calls return 0; } + else if (strcmp(command, "transpile") == 0) + { + g_config.mode_transpile = 1; + g_config.emit_c = 1; // Transpile implies emitting C + } else if (strcmp(command, "run") == 0) { g_config.mode_run = 1; @@ -266,6 +272,32 @@ int main(int argc, char **argv) codegen_node(&ctx, root, out); fclose(out); + if (g_config.mode_transpile) + { + if (g_config.output_file) + { + // If user specified -o, rename out.c to that + if (rename("out.c", g_config.output_file) != 0) + { + perror("rename out.c"); + return 1; + } + if (!g_config.quiet) + { + printf("[zc] Transpiled to %s\n", g_config.output_file); + } + } + else + { + if (!g_config.quiet) + { + printf("[zc] Transpiled to out.c\n"); + } + } + // Done, no C compilation + return 0; + } + // Compile C char cmd[8192]; char *outfile = g_config.output_file ? g_config.output_file : "a.out"; |
