Fix for issue 23, makes for and while loops live in their own deeper scope

This commit is contained in:
Jonathan Turner
2009-08-26 02:02:41 +00:00
parent 59ecf32f9b
commit 8620f4eaf9

View File

@@ -570,10 +570,14 @@ namespace chaiscript
template <typename Eval_System>
Boxed_Value eval_while(Eval_System &ss, TokenPtr node) {
bool cond;
ss.new_scope();
try {
cond = boxed_cast<bool &>(eval_token(ss, node->children[0]));
}
catch (const bad_boxed_cast &) {
ss.pop_scope();
throw Eval_Error("While condition not boolean", node->children[0]);
}
while (cond) {
@@ -583,6 +587,7 @@ namespace chaiscript
cond = boxed_cast<bool &>(eval_token(ss, node->children[0]));
}
catch (const bad_boxed_cast &) {
ss.pop_scope();
throw Eval_Error("While condition not boolean", node->children[0]);
}
}
@@ -590,6 +595,7 @@ namespace chaiscript
cond = false;
}
}
ss.pop_scope();
return Boxed_Value();
}
@@ -600,6 +606,8 @@ namespace chaiscript
Boxed_Value eval_for(Eval_System &ss, TokenPtr node) {
bool cond;
ss.new_scope();
try {
if (node->children.size() == 4) {
eval_token(ss, node->children[0]);
@@ -610,6 +618,7 @@ namespace chaiscript
}
}
catch (const bad_boxed_cast &) {
ss.pop_scope();
throw Eval_Error("For condition not boolean", node);
}
while (cond) {
@@ -626,12 +635,14 @@ namespace chaiscript
}
}
catch (const bad_boxed_cast &) {
ss.pop_scope();
throw Eval_Error("For condition not boolean", node);
}
catch (Break_Loop &) {
cond = false;
}
}
ss.pop_scope();
return Boxed_Value();
}