mirror of
https://github.com/ValKmjolnir/Nasal-Interpreter.git
synced 2026-07-26 21:08:45 +08:00
Update
This commit is contained in:
@@ -953,6 +953,8 @@ var abstract_syntax_tree::run_func(std::list<var> parameter,var self_func)
|
|||||||
{
|
{
|
||||||
std::list<var>::iterator i=parameter.begin();
|
std::list<var>::iterator i=parameter.begin();
|
||||||
var* array_addr=scope.append_get_addr(i->get_name());
|
var* array_addr=scope.append_get_addr(i->get_name());
|
||||||
|
if(array_addr->get_type()==__var_array)
|
||||||
|
{
|
||||||
if(array_addr!=&error_var)
|
if(array_addr!=&error_var)
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
@@ -966,6 +968,12 @@ var abstract_syntax_tree::run_func(std::list<var> parameter,var self_func)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
std::cout<<">>[Runtime-error] line "<<line<<": called var's type is not an array."<<std::endl;
|
||||||
|
exit_type=__error_value_type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
exit_type=__lack_parameter;
|
exit_type=__lack_parameter;
|
||||||
std::cout<<">>[Runtime-error] line "<<line<<": lack parameter(s)."<<std::endl;
|
std::cout<<">>[Runtime-error] line "<<line<<": lack parameter(s)."<<std::endl;
|
||||||
|
|||||||
+21
-6
@@ -1,6 +1,20 @@
|
|||||||
#ifndef __BALLOON_SCOPE_H__
|
#ifndef __BALLOON_SCOPE_H__
|
||||||
#define __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
|
class balloon_scope
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@@ -25,7 +39,9 @@ class balloon_scope
|
|||||||
{
|
{
|
||||||
if(!scope_list.empty() && !scope_list.back().empty())
|
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();
|
std::list<std::list<var> >::iterator i=scope_list.back().end();
|
||||||
--i;
|
--i;
|
||||||
for(std::list<var>::iterator j=i->begin();j!=i->end();++j)
|
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())
|
if(!scope_list.empty() && !scope_list.back().empty())
|
||||||
{
|
{
|
||||||
|
// get the last block
|
||||||
std::list<std::list<var> >::iterator i=scope_list.back().end();
|
std::list<std::list<var> >::iterator i=scope_list.back().end();
|
||||||
--i;
|
--i;
|
||||||
for(;;--i)
|
for(;;--i)
|
||||||
@@ -72,6 +89,7 @@ class balloon_scope
|
|||||||
{
|
{
|
||||||
if(!scope_list.empty() && !scope_list.back().empty())
|
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();
|
std::list<std::list<var> >::iterator i=scope_list.back().end();
|
||||||
--i;
|
--i;
|
||||||
i->push_back(t);
|
i->push_back(t);
|
||||||
@@ -179,14 +197,14 @@ class balloon_scope
|
|||||||
var* get_addr(std::string name)
|
var* get_addr(std::string name)
|
||||||
{
|
{
|
||||||
var* addr=NULL;
|
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();
|
std::list<std::list<var> >::iterator i=scope_list.back().end();
|
||||||
--i;
|
--i;
|
||||||
for(;;--i)
|
for(;;--i)
|
||||||
{
|
{
|
||||||
if(!i->empty())// avoid sigsegv
|
if(!i->empty())// avoid sigsegv
|
||||||
{
|
|
||||||
for(std::list<var>::iterator j=i->begin();j!=i->end();++j)
|
for(std::list<var>::iterator j=i->begin();j!=i->end();++j)
|
||||||
if(j->get_name()==name)
|
if(j->get_name()==name)
|
||||||
{
|
{
|
||||||
@@ -197,16 +215,13 @@ class balloon_scope
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if(!global.empty())
|
if(!global.empty())
|
||||||
{
|
|
||||||
for(std::list<var>::iterator i=global.begin();i!=global.end();++i)
|
for(std::list<var>::iterator i=global.begin();i!=global.end();++i)
|
||||||
if(i->get_name()==name)
|
if(i->get_name()==name)
|
||||||
{
|
{
|
||||||
addr=&(*i);
|
addr=&(*i);
|
||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return &error_var;
|
return &error_var;
|
||||||
}
|
}
|
||||||
void add_new_block_scope()
|
void add_new_block_scope()
|
||||||
|
|||||||
Reference in New Issue
Block a user