about summary refs log tree commit diff
path: root/boot/catboot.c
diff options
context:
space:
mode:
authorMel <mel@rnrd.eu>2025-12-29 00:58:21 +0100
committerMel <mel@rnrd.eu>2025-12-29 00:58:21 +0100
commit30b04e4b2a90981570ae04095aeccd746ccdea6a (patch)
tree49be07d48bd74ccf5534f05c9919a512f5aa100b /boot/catboot.c
parent57878200dda049cf7d6f11c9ede6936d184649cb (diff)
downloadcatskill-30b04e4b2a90981570ae04095aeccd746ccdea6a.tar.zst
catskill-30b04e4b2a90981570ae04095aeccd746ccdea6a.zip
Add first bootstrapping transpiler test
Signed-off-by: Mel <mel@rnrd.eu>
Diffstat (limited to 'boot/catboot.c')
-rw-r--r--boot/catboot.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/boot/catboot.c b/boot/catboot.c
index 9afb710..8412ffc 100644
--- a/boot/catboot.c
+++ b/boot/catboot.c
@@ -60,6 +60,7 @@ usage(void)
         "options:\n"
         "        --test-lex <file>\t output token stream for file\n"
         "        --test-parse <file>\t output abstract syntax tree for file in s-expr format\n"
+        "        --test-transpile <file>\t output transpiled c language source from file\n"
         "    -?, --help\t\t\t print this help message\n"
         "    -v, --version\t\t print current version\n");
 }
@@ -112,6 +113,27 @@ debug_parse_pass(struct Source_File source_file)
     return parser_result;
 }
 
+integer
+debug_transpile_pass(struct Source_File source_file)
+{
+    struct Lexer lexer;
+    lexer_new(&lexer, source_file.source);
+
+    struct Parser parser;
+    parser_new(&parser, &lexer, source_file);
+
+    struct Tree tree;
+    int parser_result = parser_do_your_thing(&parser, &tree);
+    if (parser_result != 0) {
+        fprintf(stderr, "parser finished with errors\n");
+        return parser_result;
+    }
+
+    struct Transpiler transpiler;
+    transpiler_new(&transpiler, stdout);
+    return transpiler_catskill_to_c(&transpiler, &tree);
+}
+
 enum Command_Result
 {
     COMMAND_OK,
@@ -164,6 +186,20 @@ test_parse_command(struct Command_Arguments* arguments)
 }
 
 enum Command_Result
+test_transpile_command(struct Command_Arguments* arguments)
+{
+    struct String source = read_file(arguments->input);
+    struct Source_File source_file = {
+        .source = source,
+        .path = string_from_static_c_string(arguments->input),
+    };
+
+    if (debug_transpile_pass(source_file)) return COMMAND_FAIL;
+
+    return COMMAND_OK;
+}
+
+enum Command_Result
 default_command(struct Command_Arguments* arguments)
 {
     enum Command_Result result = COMMAND_OK;
@@ -225,6 +261,8 @@ struct Command_Definition
 struct Command_Definition command_definitions[] = {
     { .name = "test-lex", .function = test_lex_command },
     { .name = "test-parse", .function = test_parse_command },
+    { .name = "test-transpile", .function = test_transpile_command },
+
     { .name = "version", .short_name = 'v', .function = version_command },
     { .name = "help", .short_name = '?', .function = help_command },