diff --git a/version2.0/nasal_ast.h b/version2.0/nasal_ast.h index 792a989..f11c11a 100644 --- a/version2.0/nasal_ast.h +++ b/version2.0/nasal_ast.h @@ -230,6 +230,10 @@ ast begins in root node: statement_2 ... +note: interpreter in flightgear can recognize 1*(2+(var a=2)) +but this type of expression is meaningless +so this interpreter does not recognize this. + source code: 0xdeadbeef; 'str'; diff --git a/version2.0/nasal_gc.h b/version2.0/nasal_gc.h index f8ecd59..2ff5175 100644 --- a/version2.0/nasal_gc.h +++ b/version2.0/nasal_gc.h @@ -122,6 +122,7 @@ class gc_manager // free_space list is used to store space that is not in use. std::list free_space; std::vector memory; + bool error_occurred; public: void gc_init() { @@ -131,6 +132,7 @@ class gc_manager memory.swap(tmp_vec); // clear the memory capacity by using tmp_vec.~vector() free_space.clear(); + error_occurred=false; return; } int gc_alloc() @@ -156,28 +158,29 @@ class gc_manager // get the reference of the scalar return memory[addr].elem; } - bool place_check(const int place) + bool place_check(const int addr) { // check if this place is in memory // and this place is uncollected // this function is often used when an identifier is calling a space in memory - return (place> [Gc] fatal error: unexpected memory place "; - prt_hex(place); + prt_hex(addr); std::cout<<" ."<> [Gc] fatal error: unexpected memory address: "; prt_hex(addr); std::cout<<" ."< >& loca { int addr=nasal_gc.gc_alloc(); nasal_gc.get_scalar(addr).set_type(scalar_vector); + std::list::iterator call_node=node.get_children().end(); for(std::list::iterator i=node.get_children().begin();i!=node.get_children().end();++i) { int var_type=i->get_node_type(); @@ -99,11 +100,21 @@ int nasal_runtime::vector_generation(std::list >& loca nasal_gc.get_scalar(addr).get_vector().vec_push(function_generation(local_scope,*i)); else if(var_type==__id) nasal_gc.get_scalar(addr).get_vector().vec_push(call_identifier(local_scope,*i)); + else if(var_type==__add_operator || var_type==__sub_operator || var_type==__mul_operator || var_type==__div_operator || var_type==__link_operator || + var_type==__cmp_equal || var_type==__cmp_less || var_type==__cmp_more || var_type==__cmp_not_equal || var_type==__cmp_less_or_equal || var_type==__cmp_more_or_equal || + var_type==__and_operator || var_type==__or_operator || var_type==__ques_mark || + var_type==__equal || var_type==__add_equal || var_type==__sub_equal || var_type==__div_equal || var_type==__mul_equal || var_type==__link_equal) + nasal_gc.get_scalar(addr).get_vector().vec_push(calculation(local_scope,*i)); else { - ; + call_node=i; + break; } } + for(;call_node!=node.get_children().end();++call_node) + { + ; + } return addr; } int nasal_runtime::hash_generation(std::list >& local_scope,abstract_syntax_tree& node) @@ -111,22 +122,26 @@ int nasal_runtime::hash_generation(std::list >& local_ int addr=nasal_gc.gc_alloc(); nasal_gc.get_scalar(addr).set_type(scalar_hash); nasal_gc.get_scalar(addr).get_hash().set_self_addr(addr); + std::list::iterator call_node=node.get_children().end(); for(std::list::iterator i=node.get_children().begin();i!=node.get_children().end();++i) { if(i->get_node_type()!=__hash_member) + { + call_node=i; break; + } else { std::string member_name=i->get_children().front().get_var_string(); int var_type=i->get_children().back().get_node_type(); if(var_type==__number) - ; + nasal_gc.get_scalar(addr).get_hash().hash_push(member_name,number_generation(*i)); else if(var_type==__string) - ; + nasal_gc.get_scalar(addr).get_hash().hash_push(member_name,string_generation(*i)); else if(var_type==__vector) - ; + nasal_gc.get_scalar(addr).get_hash().hash_push(member_name,vector_generation(local_scope,*i)); else if(var_type==__hash) - ; + nasal_gc.get_scalar(addr).get_hash().hash_push(member_name,hash_generation(local_scope,*i)); else if(var_type==__function) { // hash's function must get a parent_hash_addr @@ -134,12 +149,17 @@ int nasal_runtime::hash_generation(std::list >& local_ nasal_gc.get_scalar(addr).get_hash().hash_push(member_name,function_generation(local_scope,i->get_children().back())); nasal_gc.get_scalar(nasal_gc.get_scalar(addr).get_hash().get_hash_member(member_name)).get_function().set_parent_hash_addr(addr); } - else - { - ; - } + else if(var_type==__add_operator || var_type==__sub_operator || var_type==__mul_operator || var_type==__div_operator || var_type==__link_operator || + var_type==__cmp_equal || var_type==__cmp_less || var_type==__cmp_more || var_type==__cmp_not_equal || var_type==__cmp_less_or_equal || var_type==__cmp_more_or_equal || + var_type==__and_operator || var_type==__or_operator || var_type==__ques_mark || + var_type==__equal || var_type==__add_equal || var_type==__sub_equal || var_type==__div_equal || var_type==__mul_equal || var_type==__link_equal) + nasal_gc.get_scalar(addr).get_hash().hash_push(member_name,calculation(local_scope,*i)); } } + for(;call_node!=node.get_children().end();++call_node) + { + ; + } return addr; } int nasal_runtime::function_generation(std::list >& local_scope,abstract_syntax_tree& node) @@ -152,8 +172,21 @@ int nasal_runtime::function_generation(std::list >& lo } int nasal_runtime::calculation(std::list >& local_scope,abstract_syntax_tree& node) { - int operator_type=node.get_node_type(); - if(operator_type==__add_operator) + // calculation will return a value that points to a new area in memory + int node_type=node.get_node_type(); + if(node_type==__number) + return number_generation(node); + else if(node_type==__string) + return string_generation(node); + else if(node_type==__vector) + return vector_generation(local_scope,node); + else if(node_type==__hash) + return hash_generation(local_scope,node); + else if(node_type==__function) + return function_generation(local_scope,node); + else if(node_type==__id) + return call_identifier(local_scope,node); + else if(node_type==__add_operator) { node.get_children().front(); node.get_children().back(); @@ -202,10 +235,12 @@ void nasal_runtime::func_proc(std::list >& local_scope } std::map new_scope; local_scope.push_back(new_scope); + // loading parameters for(std::list::iterator iter=func_root.get_children().front().get_children().begin();iter!=func_root.get_children().front().get_children().end();++iter) { } + // process for(std::list::iterator iter=func_root.get_children().back().get_children().begin();iter!=func_root.get_children().back().get_children().end();++iter) { // use local value node_type to avoid calling function too many times.