From 8620f4eaf9f66c19c03a8e5e3e51a839199421fe Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Wed, 26 Aug 2009 02:02:41 +0000 Subject: [PATCH] Fix for issue 23, makes for and while loops live in their own deeper scope --- include/chaiscript/language/chaiscript_eval.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 8629844..fb93800 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -570,10 +570,14 @@ namespace chaiscript template Boxed_Value eval_while(Eval_System &ss, TokenPtr node) { bool cond; + + ss.new_scope(); + try { cond = boxed_cast(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(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(); }