This commit is contained in:
Valk Richard Li 2019-11-24 18:09:19 +08:00 committed by GitHub
parent 4fb40c2281
commit 1d8408c13d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 15 deletions

View File

@ -953,17 +953,25 @@ var abstract_syntax_tree::run_func(std::list<var> parameter,var self_func)
{
std::list<var>::iterator i=parameter.begin();
var* array_addr=scope.append_get_addr(i->get_name());
if(array_addr!=&error_var)
if(array_addr->get_type()==__var_array)
{
++i;
for(;i!=parameter.end();++i)
array_addr->append_array(*i);
if(array_addr!=&error_var)
{
++i;
for(;i!=parameter.end();++i)
array_addr->append_array(*i);
}
else
{
std::cout<<">>[Runtime-error] line "<<line<<": cannot find a var named \'"<<parameter.begin()->get_name()<<"\'."<<std::endl;
exit_type=__find_var_failure;
}
}
else
{
std::cout<<">>[Runtime-error] line "<<line<<": cannot find a var named \'"<<parameter.begin()->get_name()<<"\'."<<std::endl;
exit_type=__find_var_failure;
}
std::cout<<">>[Runtime-error] line "<<line<<": called var's type is not an array."<<std::endl;
exit_type=__error_value_type;
}
}
else
{

View File

@ -1,6 +1,20 @@
#ifndef __BALLOON_SCOPE_H__
#define __BALLOON_SCOPE_H__
/*
when running a balloon process
there will be two types of blocks:
root block
if-else block
loop block
function block
and many types of local scopes:
if-else local scope
loop local scope
local scopes must be put in a block
values in different blocks cannot call each other
*/
class balloon_scope
{
private:
@ -25,7 +39,9 @@ class balloon_scope
{
if(!scope_list.empty() && !scope_list.back().empty())
{
// check the last scope
// check the last block scope
// redefinition only occurs in last block scope
// if scope list is empty ,then check the global scope
std::list<std::list<var> >::iterator i=scope_list.back().end();
--i;
for(std::list<var>::iterator j=i->begin();j!=i->end();++j)
@ -46,6 +62,7 @@ class balloon_scope
{
if(!scope_list.empty() && !scope_list.back().empty())
{
// get the last block
std::list<std::list<var> >::iterator i=scope_list.back().end();
--i;
for(;;--i)
@ -72,6 +89,7 @@ class balloon_scope
{
if(!scope_list.empty() && !scope_list.back().empty())
{
// get the last block and the get the last local scope in this blcok
std::list<std::list<var> >::iterator i=scope_list.back().end();
--i;
i->push_back(t);
@ -179,34 +197,31 @@ class balloon_scope
var* get_addr(std::string name)
{
var* addr=NULL;
if(!scope_list.empty())
if(!scope_list.empty() && !scope_list.back().empty())
{
// get the last block
std::list<std::list<var> >::iterator i=scope_list.back().end();
--i;
for(;;--i)
{
if(!i->empty())// avoid sigsegv
{
for(std::list<var>::iterator j=i->begin();j!=i->end();++j)
if(j->get_name()==name)
{
addr=&(*j);
return addr;
}
if(i==scope_list.back().begin())
break;
}
if(i==scope_list.back().begin())
break;
}
}
if(!global.empty())
{
for(std::list<var>::iterator i=global.begin();i!=global.end();++i)
if(i->get_name()==name)
{
addr=&(*i);
return addr;
}
}
return &error_var;
}
void add_new_block_scope()