diff --git a/version3.0/nasal_ast.h b/version3.0/nasal_ast.h index 3f496c8..671cf42 100644 --- a/version3.0/nasal_ast.h +++ b/version3.0/nasal_ast.h @@ -117,13 +117,8 @@ void nasal_ast::print_ast(int depth) for(int i=0;itype); std::cout<type) - { - case ast_number: std::cout<<":"<str;break; - case ast_string: std::cout<<":"<str;break; - case ast_identifier:std::cout<<":"<str;break; - case ast_call_hash: std::cout<<":"<str;break; - } + if(this->type==ast_number || this->type==ast_string || this->type==ast_identifier || this->type==ast_dynamic_id || this->type==ast_call_hash) + std::cout<<":"<str; std::cout<children.size(); for(int i=0;i> [vm] nasal_hash:get_value_address: "<=0) + break; + } + } + } + return ret_value_addr; } int nasal_hash::get_mem_address(std::string key) { + int ret_mem_addr=-1; if(elems.find(key)!=elems.end()) return elems[key]; - else - std::cout<<">> [vm] nasal_hash:get_mem_address: "<=0) + break; + } + } + } + return ret_mem_addr; } void nasal_hash::deepcopy(nasal_hash& tmp) { @@ -298,6 +337,7 @@ void nasal_hash::deepcopy(nasal_hash& tmp) /*functions of nasal_function*/ nasal_function::nasal_function() { + is_builtin=false; closure_addr=-1; argument_list.clear(); function_expr.clear(); @@ -311,6 +351,15 @@ nasal_function::~nasal_function() function_expr.clear(); return; } +void nasal_function::set_builtin_func() +{ + is_builtin=true; + return; +} +bool nasal_function::check_builtin() +{ + return is_builtin; +} void nasal_function::set_closure_addr(int value_address) { closure_addr=value_address; @@ -325,11 +374,19 @@ void nasal_function::set_arguments(nasal_ast& node) argument_list=node; return; } +nasal_ast& nasal_function::get_arguments() +{ + return argument_list; +} void nasal_function::set_run_block(nasal_ast& node) { function_expr=node; return; } +nasal_ast& nasal_function::get_run_block() +{ + return function_expr; +} void nasal_function::deepcopy(nasal_function& tmp) { this->closure_addr=nasal_vm.gc_alloc(); diff --git a/version3.0/nasal_parse.h b/version3.0/nasal_parse.h index 98119b1..8bba1e7 100644 --- a/version3.0/nasal_parse.h +++ b/version3.0/nasal_parse.h @@ -347,6 +347,7 @@ nasal_ast nasal_parse::hash_member_gen() if(ptr>=tok_list_size || (tok_list[ptr].type!=tok_identifier && tok_list[ptr].type!=tok_string)) { error_info(error_line,lack_identifier); + ++error; return node; } node.set_line(tok_list[ptr].line); diff --git a/version3.0/nasal_runtime.h b/version3.0/nasal_runtime.h index 5f42693..241562d 100644 --- a/version3.0/nasal_runtime.h +++ b/version3.0/nasal_runtime.h @@ -51,7 +51,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 call_function(nasal_ast&,int,int,int); // get scalars' memory place in complex data structure like vector/hash/function/closure(scope) int call_scalar_mem(nasal_ast&,int); int call_vector_mem(nasal_ast&,int,int); @@ -173,9 +173,16 @@ int nasal_runtime::function_generation(nasal_ast& node,int local_scope_addr) ref_of_this_function.set_run_block(node.get_children()[1]); if(local_scope_addr>=0) { + // codes here make closure nasal_vm.add_reference(local_scope_addr); ref_of_this_function.set_closure_addr(local_scope_addr); } + else + { + int new_closure_addr=nasal_vm.gc_alloc(); + nasal_vm.gc_get(new_closure_addr).set_type(vm_closure); + ref_of_this_function.set_closure_addr(new_closure_addr); + } return new_addr; } int nasal_runtime::main_progress() @@ -229,6 +236,9 @@ int nasal_runtime::main_progress() case ast_continue: ret_state=rt_continue; break; + case ast_return: + ret_state=rt_return; + break; } switch(ret_state) { @@ -240,6 +250,10 @@ int nasal_runtime::main_progress() std::cout<<">> [runtime] main_progress: cannot use continue in main progress."<> [runtime] main_progress: cannot use return in main progress."<> [runtime] main_progress: error occurred when executing main progress."<> [runtime] block_progress: error occurred when executing sub-progress."<> [runtime] call_function: incorrect value type,expected a function."<