From 21f957195a740726806b2ae3162cab0367361cfb Mon Sep 17 00:00:00 2001 From: Nathan Braswell Date: Fri, 20 Jan 2017 01:31:28 -0500 Subject: [PATCH] Fix dreferencing function_call refs. Now need to make sure new pass method works with defer_lower, which currently does very crazy defer double stack chains --- stdlib/ref_lower.krak | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/stdlib/ref_lower.krak b/stdlib/ref_lower.krak index 6c66841..884e386 100644 --- a/stdlib/ref_lower.krak +++ b/stdlib/ref_lower.krak @@ -38,7 +38,7 @@ fun remove_ref(t: *type) { fun ref_lower(name_ast_map: *map,*ast_node>>, ast_to_syntax: *map<*ast_node, *tree>) { var remove_ref_type_set = set>() - var modify_identifier_set = set>() + var modify_reference_use_set = set>() var modify_return_set = set<*ast_node>() var visited = set<*ast_node>() name_ast_map->for_each(fun(name: string, syntax_ast_pair: pair<*tree,*ast_node>) { @@ -46,7 +46,7 @@ fun ref_lower(name_ast_map: *map,*ast_node>>, ast_to_ match(*node) { ast_node::identifier(backing) { if (backing.type->is_ref) - modify_identifier_set.add(make_pair(node, parent_chain->top())) + modify_reference_use_set.add(make_pair(node, parent_chain->top())) if (has_ref_inside(backing.type)) { remove_ref_type_set.add(make_pair("identifier: " + backing.name, backing.type)) } @@ -65,6 +65,9 @@ fun ref_lower(name_ast_map: *map,*ast_node>>, ast_to_ for (var i = 0; i < func_type_params.size; i++;) if (func_type_params[i]->is_ref) backing.parameters[i] = make_operator_call("&", vector(backing.parameters[i])) + // add the function call to the modify_reference_use set if the function returns a ref + if (get_ast_type(backing.func)->return_type->is_ref) + modify_reference_use_set.add(make_pair(node, parent_chain->top())) } ast_node::return_statement(backing) { // check to see if it's returning a ref, if so add in the & @@ -81,15 +84,15 @@ fun ref_lower(name_ast_map: *map,*ast_node>>, ast_to_ remove_ref(t) println("after" + p.first + ": " + t->to_string()) }) - modify_identifier_set.for_each(fun(p: pair<*ast_node, *ast_node>) { + modify_reference_use_set.for_each(fun(p: pair<*ast_node, *ast_node>) { // if we haven't modified it's indirection yet - if (p.first->identifier.type->is_ref) { + if (is_identifier(p.first) && p.first->identifier.type->is_ref) { // remove ref, add 1 to indirection p.first->identifier.type = p.first->identifier.type->clone_with_increased_indirection(1, false); } // note that we definitly want to replace the type for unused parameters, but we don't want to add the * for paramters // in function declarations or declaration statements - if (!is_function(p.second) && !is_declaration_statement(p.second)) + if (!is_identifier(p.first) || (!is_function(p.second) && !is_declaration_statement(p.second))) replace_with_in(p.first, make_operator_call("*", vector(p.first)), p.second); }) modify_return_set.for_each(fun(r: *ast_node) {