Add #link(lib) intrinsic, used in SquidPong
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
Goal = translation_unit ;
|
Goal = translation_unit ;
|
||||||
cast_expression = "\(" WS boolean_expression WS "\)" WS "cast" WS type ;
|
cast_expression = "\(" WS boolean_expression WS "\)" WS "cast" WS type ;
|
||||||
translation_unit = WS unorderd_list_part WS ;
|
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 ;
|
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 ;
|
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 ;
|
||||||
|
|||||||
@@ -124,6 +124,8 @@ obj ast_transformation (Object) {
|
|||||||
} else if (child->data.name == "declaration_statement") {
|
} 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?)...
|
// 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<string, *type>()))
|
translation_unit->translation_unit.children.add(transform_declaration_statement(child, translation_unit, map<string, *type>()))
|
||||||
|
} else if (child->data.name == "compiler_intrinsic") {
|
||||||
|
translation_unit->translation_unit.children.add(transform_compiler_intrinsic(child, translation_unit, map<string, *type>()))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// work on the ones already started
|
// work on the ones already started
|
||||||
|
|||||||
@@ -374,6 +374,8 @@ obj c_generator (Object) {
|
|||||||
}
|
}
|
||||||
ast_node::simple_passthrough(backing) top_level_c_passthrough += generate_simple_passthrough(child, true)
|
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<ast_node>(), null<ast_node>(), null<stack<pair<bool,stack<*ast_node>>>>(), false).one_string() + ";\n" // false - don't do defer
|
ast_node::declaration_statement(backing) variable_declarations += generate_declaration_statement(child, null<ast_node>(), null<ast_node>(), null<stack<pair<bool,stack<*ast_node>>>>(), 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) {
|
ast_node::function(backing) {
|
||||||
// check for and add to parameters if a closure
|
// check for and add to parameters if a closure
|
||||||
generate_function_definition(child, null<ast_node>(), false)
|
generate_function_definition(child, null<ast_node>(), false)
|
||||||
@@ -678,7 +680,7 @@ obj c_generator (Object) {
|
|||||||
return to_ret
|
return to_ret
|
||||||
}
|
}
|
||||||
fun generate_cast(node: *ast_node, enclosing_object: *ast_node, enclosing_func: *ast_node, defer_stack: *stack<pair<bool,stack<*ast_node>>>, need_variable: bool): code_triple {
|
fun generate_cast(node: *ast_node, enclosing_object: *ast_node, enclosing_func: *ast_node, defer_stack: *stack<pair<bool,stack<*ast_node>>>, 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 {
|
fun generate_value(node: *ast_node, need_variable: bool): code_triple {
|
||||||
var value = node->value.string_value
|
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)
|
if (node->compiler_intrinsic.parameters.size || node->compiler_intrinsic.type_parameters.size != 1)
|
||||||
error("wrong parameters to sizeof compiler intrinsic")
|
error("wrong parameters to sizeof compiler intrinsic")
|
||||||
return code_triple("sizeof(") + type_to_c(node->compiler_intrinsic.type_parameters[0]) + ")"
|
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")
|
error(node->compiler_intrinsic.intrinsic + ": unknown intrinsic")
|
||||||
return code_triple("ERROR")
|
return code_triple("ERROR")
|
||||||
|
|||||||
BIN
tests/test_math
BIN
tests/test_math
Binary file not shown.
Reference in New Issue
Block a user