Add scope around condition in for/while

* solves issue with rapidly expanding memory usage if
   function variable use stack is growing rapidly
This commit is contained in:
Jason Turner 2016-12-01 13:42:40 -07:00
parent 940e0c2d86
commit f17439a9d3

View File

@ -96,6 +96,11 @@ namespace chaiscript
{
}
static bool get_scoped_bool_condition(const AST_Node_Impl<T> &node, const chaiscript::detail::Dispatch_State &t_ss) {
chaiscript::eval::detail::Scope_Push_Pop spp(t_ss);
return get_bool_condition(node.eval(t_ss), t_ss);
}
std::vector<AST_NodePtr> get_children() const final {
return {children.begin(), children.end()};
@ -746,7 +751,7 @@ namespace chaiscript
chaiscript::eval::detail::Scope_Push_Pop spp(t_ss);
try {
while (this->get_bool_condition(this->children[0]->eval(t_ss), t_ss)) {
while (this->get_scoped_bool_condition(*this->children[0], t_ss)) {
try {
this->children[1]->eval(t_ss);
} catch (detail::Continue_Loop &) {
@ -889,7 +894,7 @@ namespace chaiscript
try {
for (
this->children[0]->eval(t_ss);
this->get_bool_condition(this->children[1]->eval(t_ss), t_ss);
this->get_scoped_bool_condition(*this->children[1], t_ss);
this->children[2]->eval(t_ss)
) {
try {