aboutsummaryrefslogtreecommitdiff
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
parent57878200dda049cf7d6f11c9ede6936d184649cb (diff)
downloadcatskill-30b04e4b2a90981570ae04095aeccd746ccdea6a.tar.zst
catskill-30b04e4b2a90981570ae04095aeccd746ccdea6a.zip
Add first bootstrapping transpiler test
Signed-off-by: Mel <mel@rnrd.eu>
-rw-r--r--boot/catboot.c38
-rw-r--r--boot/tests/test.c2
-rw-r--r--boot/tests/transpile/basic.cskt16
3 files changed, 55 insertions, 1 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 },
diff --git a/boot/tests/test.c b/boot/tests/test.c
index b8db80c..841df09 100644
--- a/boot/tests/test.c
+++ b/boot/tests/test.c
@@ -535,7 +535,7 @@ struct Result_Summary
transpile_tests(bool adjust)
{
const ascii* base_path = "./boot/tests/transpile/";
- const ascii* base_command = "./build/catboot";
+ const ascii* base_command = "./build/catboot --test-transpile";
return tests(base_path, base_command, adjust);
}
diff --git a/boot/tests/transpile/basic.cskt b/boot/tests/transpile/basic.cskt
new file mode 100644
index 0000000..f904259
--- /dev/null
+++ b/boot/tests/transpile/basic.cskt
@@ -0,0 +1,16 @@
+the transpiler has to follow a simple pattern of
+the files it creates to make viable c source.
+here we check that the simplest possible file has
+all of the expected parts needed.
+
+<<<
+
+main = fun () {
+}
+
+>>>
+
+#include "boot/runtime/core.c"
+void catskill_main(void) {
+}
+#include "boot/runtime/runtime.c" \ No newline at end of file