Bugfix - properly use old enclosing_object to interpret parameters to method, use new_enclosing_object for interpreting the actual function itself

This commit is contained in:
Nathan Braswell
2016-05-22 12:17:17 -07:00
parent c239f8acb1
commit a64e79c789
2 changed files with 4 additions and 8 deletions

View File

@@ -511,7 +511,7 @@ obj interpreter (Object) {
var var_stack = stack<map<string, value>>() var var_stack = stack<map<string, value>>()
var_stack.push(map<string,value>()) var_stack.push(map<string,value>())
var defer_stack = stack<*ast_node>() var defer_stack = stack<*ast_node>()
var result = call_function(results[0], vector<value>(), vector<*ast_node>(), &var_stack, &defer_stack, value::void_nothing(), null<ast_node>()) var result = call_function(results[0], vector<value>(), vector<*ast_node>(), &var_stack, &defer_stack, value::void_nothing(), value::void_nothing(), null<ast_node>())
println("=============") println("=============")
println("Main returned: ") println("Main returned: ")
print_value(result) print_value(result)
@@ -538,8 +538,6 @@ obj interpreter (Object) {
new_enclosing_object = enclosing_object new_enclosing_object = enclosing_object
} }
} }
// check if it's a same method method call and do the right new_enclosing_object
// new_enclosing_object = enclosing_object
var func_name = func_call_func->function.name var func_name = func_call_func->function.name
// some of these have to be done before parameters are evaluated (&&, ||, ., ->) // some of these have to be done before parameters are evaluated (&&, ||, ., ->)
if (func_name == "&&" || func_name == "||") { if (func_name == "&&" || func_name == "||") {
@@ -610,12 +608,12 @@ obj interpreter (Object) {
// not the operator & and at least one object like parameter // not the operator & and at least one object like parameter
parameter_sources = func_call_parameters parameter_sources = func_call_parameters
} }
return make_pair(call_function(func_call_func, parameters, parameter_sources, var_stack, defer_stack, new_enclosing_object, enclosing_func), control_flow::nor()) return make_pair(call_function(func_call_func, parameters, parameter_sources, var_stack, defer_stack, enclosing_object, new_enclosing_object, enclosing_func), control_flow::nor())
} }
// call_function can be called with either parameter values in parameters or ast expressions in parameter_sources // call_function can be called with either parameter values in parameters or ast expressions in parameter_sources
// this is to allow easy function calling if we already have the values (for main, say, or to make our job if it's not // this is to allow easy function calling if we already have the values (for main, say, or to make our job if it's not
// an operator easier), but we need to be able to be called with ast_expressions too so we can properly copy_construct once // an operator easier), but we need to be able to be called with ast_expressions too so we can properly copy_construct once
fun call_function(func: *ast_node, parameters: vector<value>, parameter_sources: vector<*ast_node>, var_stack: *stack<map<string, value>>, defer_stack: *stack<*ast_node>, enclosing_object: value, enclosing_func: *ast_node): value { fun call_function(func: *ast_node, parameters: vector<value>, parameter_sources: vector<*ast_node>, var_stack: *stack<map<string, value>>, defer_stack: *stack<*ast_node>, enclosing_object: value, new_enclosing_object: value, enclosing_func: *ast_node): value {
// will need adjustment // will need adjustment
if (!is_function(func)) if (!is_function(func))
error("Can't handle not function function calls (can do regular method, is this chained or something?)") error("Can't handle not function function calls (can do regular method, is this chained or something?)")
@@ -673,7 +671,7 @@ obj interpreter (Object) {
} }
} }
} }
var to_ret = interpret(func->function.body_statement, &new_var_stack, enclosing_object, func, &new_defer_stack).first var to_ret = interpret(func->function.body_statement, &new_var_stack, new_enclosing_object, func, &new_defer_stack).first
// handle destructing params // handle destructing params
interpret_from_defer_stack(&new_defer_stack, &new_var_stack, enclosing_object, enclosing_func) interpret_from_defer_stack(&new_defer_stack, &new_var_stack, enclosing_object, enclosing_func)
// to_ret is on the new_var_stack, likely // to_ret is on the new_var_stack, likely

View File

@@ -172,8 +172,6 @@ obj string (Object, Serializable) {
} }
fun operator+(str: ref string): string { fun operator+(str: ref string): string {
/*var newStr.construct(str):string*/
/*var ret.construct(data + newStr.data):string*/
var ret.construct(data + str.data):string var ret.construct(data + str.data):string
return ret return ret
} }