From 17fa6a71b96b8ad64de09367c6432ec9def98326 Mon Sep 17 00:00:00 2001 From: Valk Richard Li <48872266+ValKmjolnir@users.noreply.github.com> Date: Wed, 9 Sep 2020 22:24:05 -0700 Subject: [PATCH] bug fixed --- version3.0/nasal_gc.h | 6 ++-- version3.0/nasal_runtime.h | 61 ++++++++++++++++++++++---------------- 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/version3.0/nasal_gc.h b/version3.0/nasal_gc.h index d719d6b..6b50bcd 100644 --- a/version3.0/nasal_gc.h +++ b/version3.0/nasal_gc.h @@ -379,8 +379,10 @@ nasal_ast& nasal_function::get_run_block() } void nasal_function::deepcopy(nasal_function& tmp) { - this->closure_addr=nasal_vm.gc_alloc(); - nasal_vm.gc_get(this->closure_addr).deepcopy(nasal_vm.gc_get(tmp.closure_addr)); + if(this->closure_addr>=0) + nasal_vm.del_reference(this->closure_addr); + this->closure_addr=tmp.closure_addr; + nasal_vm.add_reference(tmp.closure_addr); this->argument_list=tmp.argument_list; this->function_expr=tmp.function_expr; return; diff --git a/version3.0/nasal_runtime.h b/version3.0/nasal_runtime.h index 982b108..0eb3492 100644 --- a/version3.0/nasal_runtime.h +++ b/version3.0/nasal_runtime.h @@ -62,7 +62,7 @@ private: int call_scalar(nasal_ast&,int); int call_vector(nasal_ast&,int,int); int call_hash(nasal_ast&,int,int); - int call_function(nasal_ast&,int,int,int); + int call_function(nasal_ast&,std::string,int,int,int); int call_builtin_function(nasal_ast&,int); // get scalars' memory place in complex data structure like vector/hash/function/closure(scope) int call_scalar_mem(nasal_ast&,int); @@ -242,27 +242,36 @@ int nasal_runtime::block_progress(nasal_ast& node,int local_scope_addr,bool allo int process_returned_value_addr=-1; for(int i=0;i> [runtime] block_progress: return expression is not allowed here."<=0) - value_address=nasal_vm.gc_get(local_scope_addr).get_closure().get_value_address(node.get_children()[0].get_str()); + value_address=nasal_vm.gc_get(local_scope_addr).get_closure().get_value_address(val_name); if(value_address<0) - value_address=nasal_vm.gc_get(global_scope_address).get_closure().get_value_address(node.get_children()[0].get_str()); + value_address=nasal_vm.gc_get(global_scope_address).get_closure().get_value_address(val_name); if(value_address<0) { value_address=call_builtin_function(node.get_children()[0],local_scope_addr); @@ -535,7 +545,7 @@ int nasal_runtime::call_scalar(nasal_ast& node,int local_scope_addr) } if(value_address<0) { - std::cout<<">> [runtime] call_nasal_scalar: cannot find value named \'"<> [runtime] call_nasal_scalar: cannot find value named \'"<=0) { @@ -1361,22 +1380,12 @@ int nasal_runtime::calculation(nasal_ast& node,int local_scope_addr) else if(calculation_type==ast_trinocular) { int condition_addr=calculation(node.get_children()[0],local_scope_addr); - int ret_1_addr=calculation(node.get_children()[1],local_scope_addr); - int ret_2_addr=calculation(node.get_children()[2],local_scope_addr); - int check_null=nasal_scalar_calculator.nasal_scalar_unary_not(condition_addr); - if(nasal_vm.gc_get(check_null).get_number()!=0) - { - ret_address=ret_1_addr; - nasal_vm.del_reference(ret_2_addr); - } + if(check_condition(condition_addr)) + ret_address=calculation(node.get_children()[1],local_scope_addr); else - { - ret_address=ret_2_addr; - nasal_vm.del_reference(ret_1_addr); - } + ret_address=calculation(node.get_children()[2],local_scope_addr); // delete the reference of temporary values nasal_vm.del_reference(condition_addr); - nasal_vm.del_reference(check_null); } else if(calculation_type==ast_equal) {