diff --git a/krakenGrammer.kgm b/krakenGrammer.kgm index 28a1f9d..99b7401 100644 --- a/krakenGrammer.kgm +++ b/krakenGrammer.kgm @@ -1,7 +1,7 @@ Goal = translation_unit ; cast_expression = "\(" WS boolean_expression WS "\)" WS "cast" WS type ; translation_unit = WS unorderd_list_part WS ; -unorderd_list_part = import WS unorderd_list_part | function WS unorderd_list_part | type_def line_end WS unorderd_list_part | adt_def line_end WS unorderd_list_part | if_comp WS unorderd_list_part | simple_passthrough WS unorderd_list_part | declaration_statement line_end WS unorderd_list_part | import | function | type_def line_end | adt_def line_end | if_comp | simple_passthrough | declaration_statement line_end ; +unorderd_list_part = import WS unorderd_list_part | function WS unorderd_list_part | type_def line_end WS unorderd_list_part | adt_def line_end WS unorderd_list_part | if_comp WS unorderd_list_part | simple_passthrough WS unorderd_list_part | declaration_statement line_end WS unorderd_list_part | compiler_intrinsic line_end WS unorderd_list_part | import | function | type_def line_end | adt_def line_end | if_comp | simple_passthrough | declaration_statement line_end | compiler_intrinsic line_end ; type = "ref" WS pre_reffed | pre_reffed ; pre_reffed = "\*" WS pre_reffed | "void" | "char" | "uchar" | "short" | "ushort" | "int" | "uint" | "long" | "ulong" | "float" | "double" | scoped_identifier | scoped_identifier WS template_inst | function_type ; diff --git a/stdlib/ast_transformation.krak b/stdlib/ast_transformation.krak index 2eccf91..116e1d6 100644 --- a/stdlib/ast_transformation.krak +++ b/stdlib/ast_transformation.krak @@ -124,6 +124,8 @@ obj ast_transformation (Object) { } else if (child->data.name == "declaration_statement") { // second pass declaration can actually just call a normal transform (but maybe should be it's own method to do so because typedef has to do it too?)... translation_unit->translation_unit.children.add(transform_declaration_statement(child, translation_unit, map())) + } else if (child->data.name == "compiler_intrinsic") { + translation_unit->translation_unit.children.add(transform_compiler_intrinsic(child, translation_unit, map())) } }) // work on the ones already started diff --git a/stdlib/c_generator.krak b/stdlib/c_generator.krak index 7943f93..f36deb3 100644 --- a/stdlib/c_generator.krak +++ b/stdlib/c_generator.krak @@ -374,6 +374,8 @@ obj c_generator (Object) { } ast_node::simple_passthrough(backing) top_level_c_passthrough += generate_simple_passthrough(child, true) ast_node::declaration_statement(backing) variable_declarations += generate_declaration_statement(child, null(), null(), null>>>(), false).one_string() + ";\n" // false - don't do defer + // shouldn't need to do anything with return, as the intrinsic should be something like link + ast_node::compiler_intrinsic(backing) generate_compiler_intrinsic(child) ast_node::function(backing) { // check for and add to parameters if a closure generate_function_definition(child, null(), false) @@ -678,7 +680,7 @@ obj c_generator (Object) { return to_ret } fun generate_cast(node: *ast_node, enclosing_object: *ast_node, enclosing_func: *ast_node, defer_stack: *stack>>, need_variable: bool): code_triple { - return code_triple("(") + type_to_c(node->cast.to_type) + ")(" + generate(node->cast.value, enclosing_object, enclosing_func, defer_stack, false) + ")" + return code_triple("((") + type_to_c(node->cast.to_type) + ")(" + generate(node->cast.value, enclosing_object, enclosing_func, defer_stack, false) + "))" } fun generate_value(node: *ast_node, need_variable: bool): code_triple { var value = node->value.string_value @@ -932,6 +934,11 @@ obj c_generator (Object) { if (node->compiler_intrinsic.parameters.size || node->compiler_intrinsic.type_parameters.size != 1) error("wrong parameters to sizeof compiler intrinsic") return code_triple("sizeof(") + type_to_c(node->compiler_intrinsic.type_parameters[0]) + ")" + } else if (node->compiler_intrinsic.intrinsic == "link") { + node->compiler_intrinsic.parameters.for_each(fun(str: string) { + linker_string += string("-l") + str + " " + }) + return code_triple() } error(node->compiler_intrinsic.intrinsic + ": unknown intrinsic") return code_triple("ERROR") diff --git a/tests/test_math b/tests/test_math deleted file mode 100755 index 6b7426d..0000000 Binary files a/tests/test_math and /dev/null differ