We have a VERY SILL KRAKEN COMPILER\! simple_passthroughs are now emitted by the c_generator and test_compiler has been extended to write the C to a file and then call cc on it, so the self-hosted Kraken compiler can compile its very first thing\! (though that thing is a hello world C program written entirely in a simple_passthrough...
This commit is contained in:
@@ -20,7 +20,7 @@ obj c_generator (Object) {
|
||||
}
|
||||
fun destruct() {
|
||||
}
|
||||
fun generate(name_ast_map: map<string, pair<*tree<symbol>,*ast_node>>): pair<string,string> {
|
||||
fun generate_c(name_ast_map: map<string, pair<*tree<symbol>,*ast_node>>): pair<string,string> {
|
||||
var linker_string:string = ""
|
||||
var prequal: string = "#include <stdbool.h>\n#include <stdlib.h>\n#include <stdio.h>\n"
|
||||
var plain_typedefs: string = ""
|
||||
@@ -40,8 +40,12 @@ obj c_generator (Object) {
|
||||
// assert translation_unit?
|
||||
tree_pair.second->translation_unit.children.for_each(fun(child: *ast_node) {
|
||||
match (*child) {
|
||||
ast_node::if_comp(backing) top_level_c_passthrough += "got an if_comp\n"
|
||||
ast_node::simple_passthrough(backing) top_level_c_passthrough += "got a simple_passthrough\n"
|
||||
// should really check the genrator
|
||||
ast_node::if_comp(backing) {
|
||||
if (is_simple_passthrough(backing.statement->statement.child))
|
||||
top_level_c_passthrough += generate_simple_passthrough(backing.statement->statement.child)
|
||||
}
|
||||
ast_node::simple_passthrough(backing) top_level_c_passthrough += generate_simple_passthrough(child)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -49,6 +53,16 @@ obj c_generator (Object) {
|
||||
var function_definitions: string = ""
|
||||
return make_pair(prequal+plain_typedefs+top_level_c_passthrough+variable_extern_declarations+structs+function_typedef_string_pre+function_typedef_string+function_prototypes+variable_declarations+function_definitions, linker_string)
|
||||
}
|
||||
fun generate_simple_passthrough(node: *ast_node): string {
|
||||
// deal with all the passthrough params
|
||||
return node->simple_passthrough.passthrough_str
|
||||
}
|
||||
// for now, anyway
|
||||
fun generate(node: *ast_node): string {
|
||||
match (*node) {
|
||||
ast_node::simple_passthrough(backing) return generate_simple_passthrough(node)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user