From 1d8408c13de9423aa2a8d3ef5b33826ef0c89243 Mon Sep 17 00:00:00 2001 From: Valk Richard Li <48872266+ValKmjolnir@users.noreply.github.com> Date: Sun, 24 Nov 2019 18:09:19 +0800 Subject: [PATCH] Update --- balloon/abstract_syntax_tree.cpp | 22 +++++++++++++++------- balloon/balloon_scope.h | 31 +++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/balloon/abstract_syntax_tree.cpp b/balloon/abstract_syntax_tree.cpp index 55389e0..bc55e08 100644 --- a/balloon/abstract_syntax_tree.cpp +++ b/balloon/abstract_syntax_tree.cpp @@ -953,17 +953,25 @@ var abstract_syntax_tree::run_func(std::list parameter,var self_func) { std::list::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 "<get_name()<<"\'."<>[Runtime-error] line "<get_name()<<"\'."<>[Runtime-error] line "< >::iterator i=scope_list.back().end(); --i; for(std::list::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 >::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 >::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 >::iterator i=scope_list.back().end(); --i; for(;;--i) { if(!i->empty())// avoid sigsegv - { for(std::list::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::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()