This commit is contained in:
Nathan Braswell
2017-12-27 16:10:36 -05:00
parent 7ddbecaf1d
commit d414459313

View File

@@ -38,7 +38,7 @@ fun obj_lower(name_ast_map: *map<string, pair<*tree<symbol>,*ast_node>>, ast_to_
var all_type_defs = set<*ast_node>() var all_type_defs = set<*ast_node>()
name_ast_map->for_each(fun(name: string, syntax_ast_pair: pair<*tree<symbol>,*ast_node>) { name_ast_map->for_each(fun(name: string, syntax_ast_pair: pair<*tree<symbol>,*ast_node>) {
// Pass 1 // Pass 1
var ensure_block_and_munge = fun(node: *ast_node, parent_chain: *stack<*ast_node>) { var ensure_block_and_munge: fun(*ast_node,*stack<*ast_node>,*hash_set<*ast_node>):bool = fun(node: *ast_node, parent_chain: *stack<*ast_node>, visited: *hash_set<*ast_node>):bool {
match(*node) { match(*node) {
ast_node::type_def(backing) all_type_defs.add(node) ast_node::type_def(backing) all_type_defs.add(node)
ast_node::function(backing) if (backing.body_statement && !is_code_block(backing.body_statement)) { ast_node::function(backing) if (backing.body_statement && !is_code_block(backing.body_statement)) {
@@ -102,40 +102,12 @@ fun obj_lower(name_ast_map: *map<string, pair<*tree<symbol>,*ast_node>>, ast_to_
condition_if->if_statement.then_part = ast_branching_statement_ptr(branching_type::break_stmt()) condition_if->if_statement.then_part = ast_branching_statement_ptr(branching_type::break_stmt())
backing.body->code_block.children.add(3, condition_if) backing.body->code_block.children.add(3, condition_if)
} }
ast_node::return_statement(backing) {
var block = parent_chain->top()
if (!is_code_block(block))
error("Isn't block in return statement obj munging")
/*var block = ast_code_block_ptr()*/
/*add_to_scope("~enclosing_scope", parent_chain->item_from_top_satisfying(fun(i: *ast_node): bool return is_code_block(i) || is_function(i);), block)*/
/*replace_with_in(node, block, parent_chain)*/
var return_value = backing.return_value
var enclosing_function = parent_chain->item_from_top_satisfying(is_function)
if (!is_code_block(enclosing_function->function.body_statement))
error("this would by unusual")
if (return_value) {
if (get_ast_type(enclosing_function)->return_type->is_ref)
return_value = make_operator_call("&", vector(return_value))
var temp_return = ast_identifier_ptr("temp_boom_return", get_ast_type(return_value)->clone_without_ref(), block)
add_to_scope("temp_boom_return", temp_return, block)
add_to_scope("~enclosing_scope", block, temp_return)
/*block->code_block.children.add(ast_declaration_statement_ptr(temp_return, null<ast_node>()))*/
/*block->code_block.children.add(assign_or_copy_construct_statement(temp_return, return_value))*/
add_before_in(ast_declaration_statement_ptr(temp_return, null<ast_node>()), node, block)
add_before_in(assign_or_copy_construct_statement(temp_return, return_value), node, block)
// dereference so that the real ref can take it back
if (get_ast_type(enclosing_function)->return_type->is_ref)
temp_return = make_operator_call("*", vector(temp_return))
backing.return_value = temp_return
}
if (!is_code_block(enclosing_function->function.body_statement))
error("is this would by unusual")
/*block->code_block.children.add(node)*/
}
} }
return true
} }
run_on_tree(ensure_block_and_munge, empty_pass_second_half(), syntax_ast_pair.second, &visited1) run_on_tree(ensure_block_and_munge, empty_pass_second_half(), syntax_ast_pair.second, &visited1)
}) })
// make sure all blockes munged before we move ahead // make sure all blockes munged before we move ahead
name_ast_map->for_each(fun(name: string, syntax_ast_pair: pair<*tree<symbol>,*ast_node>) { name_ast_map->for_each(fun(name: string, syntax_ast_pair: pair<*tree<symbol>,*ast_node>) {
var visit = hash_set<*ast_node>() var visit = hash_set<*ast_node>()
@@ -301,6 +273,31 @@ fun obj_lower(name_ast_map: *map<string, pair<*tree<symbol>,*ast_node>>, ast_to_
backing.init_method_call = null<ast_node>() backing.init_method_call = null<ast_node>()
} }
} }
ast_node::return_statement(backing) {
var block = parent_chain->top()
if (!is_code_block(block))
error("Isn't block in return statement obj munging")
var return_value = backing.return_value
var enclosing_function = parent_chain->item_from_top_satisfying(is_function)
if (!is_code_block(enclosing_function->function.body_statement))
error("this would by unusual")
if (return_value) {
if (get_ast_type(enclosing_function)->return_type->is_ref)
return_value = make_operator_call("&", vector(return_value))
var temp_return = ast_identifier_ptr("temp_boom_return", get_ast_type(return_value)->clone_without_ref(), block)
add_to_scope("temp_boom_return", temp_return, block)
add_to_scope("~enclosing_scope", block, temp_return)
var declaration_statement = ast_declaration_statement_ptr(temp_return, null<ast_node>())
var assign_statement = assign_or_copy_construct_statement(temp_return, return_value)
add_before_in(declaration_statement, node, block)
add_before_in(assign_statement, node, block)
// dereference so that the real ref can take it back
if (get_ast_type(enclosing_function)->return_type->is_ref)
temp_return = make_operator_call("*", vector(temp_return))
backing.return_value = temp_return
}
}
} }
} }
run_on_tree(empty_pass_first_half(), construct_in_destruct_out, syntax_ast_pair.second, &visited3) run_on_tree(empty_pass_first_half(), construct_in_destruct_out, syntax_ast_pair.second, &visited3)