bug fixed
This commit is contained in:
parent
85c4ce8946
commit
bc5ae6384b
|
@ -7,6 +7,7 @@ int exit_type=0;
|
||||||
std::stack<var> ret_stack; // for function ret use(especially the recursion)
|
std::stack<var> ret_stack; // for function ret use(especially the recursion)
|
||||||
int recursion_depth=0; // avoid deep recursion to sigsegv
|
int recursion_depth=0; // avoid deep recursion to sigsegv
|
||||||
std::string str_for_input; // avoid stack overflow
|
std::string str_for_input; // avoid stack overflow
|
||||||
|
var* append_addr; // used in append function
|
||||||
|
|
||||||
var abstract_syntax_tree::calculation()
|
var abstract_syntax_tree::calculation()
|
||||||
{
|
{
|
||||||
|
@ -518,7 +519,14 @@ var abstract_syntax_tree::call_identifier()
|
||||||
self.set_type(__var_function);
|
self.set_type(__var_function);
|
||||||
self.set_name(temp.get_name());
|
self.set_name(temp.get_name());
|
||||||
self.set_function(temp.get_function());
|
self.set_function(temp.get_function());
|
||||||
|
if(temp.get_name()=="append")
|
||||||
|
{
|
||||||
|
append_addr=NULL;
|
||||||
|
if(!i->children.empty())
|
||||||
|
append_addr=i->children.begin()->get_var_addr();
|
||||||
|
}
|
||||||
std::list<var> parameter;
|
std::list<var> parameter;
|
||||||
|
if(!i->children.empty())
|
||||||
for(std::list<abstract_syntax_tree>::iterator j=i->children.begin();j!=i->children.end();++j)
|
for(std::list<abstract_syntax_tree>::iterator j=i->children.begin();j!=i->children.end();++j)
|
||||||
parameter.push_back(j->calculation());
|
parameter.push_back(j->calculation());
|
||||||
temp=temp.get_function().run_func(parameter,self);
|
temp=temp.get_function().run_func(parameter,self);
|
||||||
|
@ -958,24 +966,20 @@ var abstract_syntax_tree::run_func(std::list<var> parameter,var self_func)
|
||||||
}
|
}
|
||||||
else if(self_func.get_name()=="append")
|
else if(self_func.get_name()=="append")
|
||||||
{
|
{
|
||||||
if(!parameter.empty())
|
if(append_addr)
|
||||||
{
|
{
|
||||||
std::list<var>::iterator i=parameter.begin();
|
std::list<var>::iterator i=parameter.begin();
|
||||||
var* array_addr=scope.append_get_addr(i->get_name());
|
if(append_addr->get_type()==__var_array)
|
||||||
if(array_addr->get_type()==__var_array)
|
|
||||||
{
|
|
||||||
if(array_addr!=&error_var)
|
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
for(;i!=parameter.end();++i)
|
for(;i!=parameter.end();++i)
|
||||||
array_addr->append_array(*i);
|
append_addr->append_array(*i);
|
||||||
}
|
}
|
||||||
else
|
else if(append_addr->get_type()==__null_type)
|
||||||
{
|
{
|
||||||
std::cout<<">>[Runtime-error] line "<<line<<": cannot find a var named \'"<<parameter.begin()->get_name()<<"\'."<<std::endl;
|
std::cout<<">>[Runtime-error] line "<<line<<": cannot find a var named \'"<<parameter.begin()->get_name()<<"\'."<<std::endl;
|
||||||
exit_type=__find_var_failure;
|
exit_type=__find_var_failure;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout<<">>[Runtime-error] line "<<line<<": called var's type is not an array."<<std::endl;
|
std::cout<<">>[Runtime-error] line "<<line<<": called var's type is not an array."<<std::endl;
|
||||||
|
|
|
@ -52,5 +52,6 @@ void alert_sound()
|
||||||
std::stack<var> ret_stack; // for function ret use
|
std::stack<var> ret_stack; // for function ret use
|
||||||
int recursion_depth; // avoid too deep recursion
|
int recursion_depth; // avoid too deep recursion
|
||||||
std::string str_for_input // global value str to avoid stack overflow
|
std::string str_for_input // global value str to avoid stack overflow
|
||||||
|
var* append_addr // used in append function , to get a correct addr of all kinds of arrays
|
||||||
*/
|
*/
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue