Fixed up scope-diving equation.

This commit is contained in:
Jonathan Turner 2009-06-06 16:52:35 +00:00
parent 9ca43e6290
commit e0af874078
2 changed files with 12 additions and 6 deletions

View File

@ -45,11 +45,17 @@ class BoxedCPP_System
template<typename Class>
void set_object(const std::string &name, const Class &obj)
{
try {
get_object(name) = Boxed_Value(obj);
} catch (const std::range_error &) {
add_object(name, obj);
for (int i = m_scopes.size()-1; i >= 0; --i)
{
std::map<std::string, Boxed_Value>::const_iterator itr = m_scopes[i].find(name);
if (itr != m_scopes[i].end())
{
m_scopes[i][name] = Boxed_Value(obj);
return;
}
}
add_object(name, obj);
}
template<typename Class>
@ -75,7 +81,7 @@ class BoxedCPP_System
Boxed_Value get_object(const std::string &name) const
{
for (size_t i = m_scopes.size()-1; i >= 0; --i)
for (int i = m_scopes.size()-1; i >= 0; --i)
{
std::map<std::string, Boxed_Value>::const_iterator itr = m_scopes[i].find(name);
if (itr != m_scopes[i].end())

View File

@ -150,7 +150,7 @@ Boxed_Value eval_token(BoxedCPP_System &ss, TokenPtr node) {
if (node->children.size() > 1) {
for (i = node->children.size()-3; ((int)i) >= 0; i -= 2) {
if (node->children[i+1]->text == "=") {
ss.add_object(node->children[i]->text, retval);
ss.set_object(node->children[i]->text, retval);
}
else {
Param_List_Builder plb;