Add in address_of_ensure_variable_lower.krak that makes sure & can always take a reference, even of a constant, etc, and start the cleanup of c_generator that this allows

This commit is contained in:
Nathan Braswell
2017-10-22 21:41:58 -04:00
parent 73faf50053
commit e70d31a51c
6 changed files with 103 additions and 121 deletions

View File

@@ -155,12 +155,15 @@ fun obj_lower(name_ast_map: *map<string, pair<*tree<symbol>,*ast_node>>, ast_to_
}
}
var func_return_type = func_type->return_type
if (!func_return_type->is_ref && func_return_type->indirection == 0 && (func_return_type->is_object() && has_method(func_return_type->type_def, "destruct", vector<*type>()))) {
/*if (!func_return_type->is_ref && func_return_type->indirection == 0 && (func_return_type->is_object() && has_method(func_return_type->type_def, "destruct", vector<*type>()))) {*/
if (!func_return_type->is_ref && func_return_type->indirection == 0 && func_return_type->is_object()) {
var temp_return = ast_identifier_ptr("temporary_return_boomchaka", func_return_type, null<ast_node>())
var declaration = ast_declaration_statement_ptr(temp_return, node)
add_before_in(declaration, replace_before, replace_in)
add_before_in(ast_defer_statement_ptr(make_method_call(temp_return, "destruct", vector<*ast_node>())),
replace_before, replace_in)
if (has_method(func_return_type->type_def, "destruct", vector<*type>())) {
add_before_in(ast_defer_statement_ptr(make_method_call(temp_return, "destruct", vector<*ast_node>())),
replace_before, replace_in)
}
replace_with_in(node, temp_return, parent_chain)
}
}