running test_compiler on it self will complete now, though the resulting C has many errors
This commit is contained in:
@@ -408,7 +408,9 @@ obj ast_transformation (Object) {
|
||||
ast_node::adt_def(backing) return backing.self_type->clone_with_indirection(indirection, is_ref)
|
||||
}
|
||||
}
|
||||
error("no types found for " + type_syntax_str)
|
||||
// error("no types found for " + type_syntax_str)
|
||||
println("no types found for " + type_syntax_str)
|
||||
return type_ptr(base_type::none(), indirection, is_ref)
|
||||
}
|
||||
}
|
||||
fun transform(node: *tree<symbol>, scope: *ast_node, template_replacements: map<string, *type>): *ast_node return transform(node, scope, search_type::none(), template_replacements)
|
||||
@@ -881,6 +883,7 @@ obj ast_transformation (Object) {
|
||||
var first_param = transform(node->children[0], scope, template_replacements)
|
||||
var second_param = null<ast_node>()
|
||||
if (func_name == "." || func_name == "->") {
|
||||
println("PRE VANILLA TRY FOR SECOND PARAM")
|
||||
second_param = transform(node->children[2], get_ast_type(first_param)->type_def, searching_for, template_replacements)
|
||||
// template member functions
|
||||
// XXX add in template inst if it exists
|
||||
@@ -890,14 +893,15 @@ obj ast_transformation (Object) {
|
||||
var inherited_replacements = map<string, *type>()
|
||||
var parent = get_ast_scope(get_ast_type(first_param)->type_def)->get(string("~enclosing_scope"))[0]
|
||||
if (is_template(parent)) {
|
||||
println("TEMPLATE type PARENT IS TEMPLATE")
|
||||
for (var i = 0; i < parent->template.template_types.size; i++;)
|
||||
inherited_replacements[parent->template.template_types[i]] = parent->template.instantiated_map.reverse_get(get_ast_type(first_param)->type_def)[i].clone()
|
||||
} else {
|
||||
println("TEMPLATE type PARENT IS NOT TEMPLATE")
|
||||
}
|
||||
var method_name = concat_symbol_tree(node->children[2])
|
||||
if (template_inst)
|
||||
second_param = find_or_instantiate_template_function(method_name, template_inst, get_ast_type(first_param)->type_def, type_vec, template_replacements, inherited_replacements);
|
||||
else
|
||||
second_param = find_or_instantiate_template_function(method_name, null<tree<symbol>>(), get_ast_type(first_param)->type_def, type_vec, template_replacements, inherited_replacements);
|
||||
println("PRE TEMPLATE TRY FOR SECOND PARAM")
|
||||
second_param = find_or_instantiate_template_function(method_name, template_inst, get_ast_type(first_param)->type_def, type_vec, template_replacements, inherited_replacements);
|
||||
if (!second_param) {
|
||||
error("Could not find method " + method_name + " on the right side of (. or ->) " + concat_symbol_tree(node->children[0]) +
|
||||
", whole string: " + concat_symbol_tree(node) + ", left type: " + get_ast_type(first_param)->to_string())
|
||||
@@ -1122,10 +1126,12 @@ fun unify_type(template_type: *tree<symbol>, param_type: *type, new_map: *map<st
|
||||
println("TEMPLATE inference hit different sizes")
|
||||
}
|
||||
} else {
|
||||
error("TEMPLATE inference hit non parent template")
|
||||
// error("TEMPLATE inference hit non parent template")
|
||||
println("TEMPLATE inference hit non parent template")
|
||||
}
|
||||
} else {
|
||||
error("TEMPLATE inference hit non object")
|
||||
// error("TEMPLATE inference hit non object")
|
||||
println("TEMPLATE inference hit non object")
|
||||
}
|
||||
} else {
|
||||
println(template_type->children[0]->data.name)
|
||||
|
||||
@@ -234,7 +234,7 @@ obj c_generator (Object) {
|
||||
function_definitions += "/*no inner data*/\n"
|
||||
else {
|
||||
var param = backing.parameters[0]
|
||||
if (option_type->is_adt() || (option_type->is_object() && has_method(option_type->type_def, "copy_construct", vector(option_type->clone_with_increased_indirection())))) {
|
||||
if (option_type->indirection == 0 && (option_type->is_adt() || (option_type->is_object() && has_method(option_type->type_def, "copy_construct", vector(option_type->clone_with_increased_indirection()))))) {
|
||||
function_definitions += generate(ast_statement_ptr(make_method_call(make_operator_call(".", vector(to_ret_ident, option_ident)), "copy_construct", vector(make_operator_call("&", vector(param))))), null<ast_node>(), null<ast_node>(), &defer_stack, false).one_string()
|
||||
function_definitions += generate_from_defer_stack(&defer_stack, -1, enclosing_object, child).one_string()
|
||||
} else {
|
||||
@@ -257,7 +257,7 @@ obj c_generator (Object) {
|
||||
if (option_type->is_empty_adt_option()) {
|
||||
function_definitions += "return true;"
|
||||
} else {
|
||||
if (option_type->is_adt() || (option_type->is_object() && has_method(option_type->type_def, "operator==", vector(option_type)))) {
|
||||
if (option_type->indirection == 0 && (option_type->is_adt() || (option_type->is_object() && has_method(option_type->type_def, "operator==", vector(option_type))))) {
|
||||
defer_stack.push(make_pair(false, stack<*ast_node>()))
|
||||
var equals_res = generate(ast_statement_ptr(make_method_call(make_operator_call("->", vector(adt_this, option)), "operator==", vector(make_operator_call(".", vector(param, option))))), null<ast_node>(), null<ast_node>(), &defer_stack, false)
|
||||
equals_res.value = string("bool result = ") + equals_res.value + ";\n"
|
||||
@@ -289,7 +289,7 @@ obj c_generator (Object) {
|
||||
if (option_type->is_empty_adt_option()) {
|
||||
function_definitions += "/*no data to copy*/;"
|
||||
} else {
|
||||
if (option_type->is_adt() || (option_type->is_object() && has_method(option_type->type_def, "copy_construct", vector(option_type->clone_with_increased_indirection())))) {
|
||||
if (option_type->indirection == 0 && (option_type->is_adt() || (option_type->is_object() && has_method(option_type->type_def, "copy_construct", vector(option_type->clone_with_increased_indirection()))))) {
|
||||
// don't really need the defer_stack
|
||||
function_definitions += generate(ast_statement_ptr(make_method_call(make_operator_call("->", vector(adt_this, option)), "copy_construct", vector(make_operator_call("&", vector(make_operator_call("->", vector(param, option))))))), null<ast_node>(), null<ast_node>(), &defer_stack, false).one_string()
|
||||
} else {
|
||||
@@ -312,7 +312,7 @@ obj c_generator (Object) {
|
||||
enclosing_object->adt_def.options.for_each(fun(option: *ast_node) {
|
||||
var option_type = option->identifier.type
|
||||
function_definitions += string("if (this->flag == ") + string("enum_opt_") + generate_identifier(option, null<ast_node>(), null<ast_node>()).one_string() + ") {\n"
|
||||
if (option_type->is_adt() || (option_type->is_object() && has_method(option_type->type_def, "destruct", vector<*type>()))) {
|
||||
if (option_type->indirection == 0 && (option_type->is_adt() || (option_type->is_object() && has_method(option_type->type_def, "destruct", vector<*type>())))) {
|
||||
// don't really need the defer_stack
|
||||
function_definitions += generate(ast_statement_ptr(make_method_call(make_operator_call("->", vector(adt_this, option)), "destruct", vector<*ast_node>())), null<ast_node>(), null<ast_node>(), &defer_stack, false).one_string()
|
||||
}
|
||||
@@ -477,7 +477,7 @@ obj c_generator (Object) {
|
||||
// we only make it first if it's a function type though, so that global levels still work
|
||||
var to_ret = code_triple(type_to_c(identifier->identifier.type) + " " + get_name(identifier), string(), string())
|
||||
if (node->declaration_statement.expression) {
|
||||
if (ident_type->is_adt() || (ident_type->is_object() && has_method(ident_type->type_def, "copy_construct", vector(get_ast_type(node->declaration_statement.expression)->clone_with_increased_indirection())))) {
|
||||
if (ident_type->indirection == 0 && (ident_type->is_adt() || (ident_type->is_object() && has_method(ident_type->type_def, "copy_construct", vector(get_ast_type(node->declaration_statement.expression)->clone_with_increased_indirection()))))) {
|
||||
to_ret.pre += ";\n"
|
||||
to_ret += generate(ast_statement_ptr(make_method_call(identifier, "copy_construct", vector(make_operator_call("&", vector(node->declaration_statement.expression))))), enclosing_object, enclosing_func, defer_stack, false)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user