Fix for issue 23, makes for and while loops live in their own deeper scope
This commit is contained in:
@@ -570,10 +570,14 @@ namespace chaiscript
|
|||||||
template <typename Eval_System>
|
template <typename Eval_System>
|
||||||
Boxed_Value eval_while(Eval_System &ss, TokenPtr node) {
|
Boxed_Value eval_while(Eval_System &ss, TokenPtr node) {
|
||||||
bool cond;
|
bool cond;
|
||||||
|
|
||||||
|
ss.new_scope();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cond = boxed_cast<bool &>(eval_token(ss, node->children[0]));
|
cond = boxed_cast<bool &>(eval_token(ss, node->children[0]));
|
||||||
}
|
}
|
||||||
catch (const bad_boxed_cast &) {
|
catch (const bad_boxed_cast &) {
|
||||||
|
ss.pop_scope();
|
||||||
throw Eval_Error("While condition not boolean", node->children[0]);
|
throw Eval_Error("While condition not boolean", node->children[0]);
|
||||||
}
|
}
|
||||||
while (cond) {
|
while (cond) {
|
||||||
@@ -583,6 +587,7 @@ namespace chaiscript
|
|||||||
cond = boxed_cast<bool &>(eval_token(ss, node->children[0]));
|
cond = boxed_cast<bool &>(eval_token(ss, node->children[0]));
|
||||||
}
|
}
|
||||||
catch (const bad_boxed_cast &) {
|
catch (const bad_boxed_cast &) {
|
||||||
|
ss.pop_scope();
|
||||||
throw Eval_Error("While condition not boolean", node->children[0]);
|
throw Eval_Error("While condition not boolean", node->children[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -590,6 +595,7 @@ namespace chaiscript
|
|||||||
cond = false;
|
cond = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ss.pop_scope();
|
||||||
return Boxed_Value();
|
return Boxed_Value();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -600,6 +606,8 @@ namespace chaiscript
|
|||||||
Boxed_Value eval_for(Eval_System &ss, TokenPtr node) {
|
Boxed_Value eval_for(Eval_System &ss, TokenPtr node) {
|
||||||
bool cond;
|
bool cond;
|
||||||
|
|
||||||
|
ss.new_scope();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (node->children.size() == 4) {
|
if (node->children.size() == 4) {
|
||||||
eval_token(ss, node->children[0]);
|
eval_token(ss, node->children[0]);
|
||||||
@@ -610,6 +618,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const bad_boxed_cast &) {
|
catch (const bad_boxed_cast &) {
|
||||||
|
ss.pop_scope();
|
||||||
throw Eval_Error("For condition not boolean", node);
|
throw Eval_Error("For condition not boolean", node);
|
||||||
}
|
}
|
||||||
while (cond) {
|
while (cond) {
|
||||||
@@ -626,12 +635,14 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const bad_boxed_cast &) {
|
catch (const bad_boxed_cast &) {
|
||||||
|
ss.pop_scope();
|
||||||
throw Eval_Error("For condition not boolean", node);
|
throw Eval_Error("For condition not boolean", node);
|
||||||
}
|
}
|
||||||
catch (Break_Loop &) {
|
catch (Break_Loop &) {
|
||||||
cond = false;
|
cond = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ss.pop_scope();
|
||||||
return Boxed_Value();
|
return Boxed_Value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user