Fixed up scope-diving equation.
This commit is contained in:
@@ -45,13 +45,19 @@ class BoxedCPP_System
|
|||||||
template<typename Class>
|
template<typename Class>
|
||||||
void set_object(const std::string &name, const Class &obj)
|
void set_object(const std::string &name, const Class &obj)
|
||||||
{
|
{
|
||||||
try {
|
for (int i = m_scopes.size()-1; i >= 0; --i)
|
||||||
get_object(name) = Boxed_Value(obj);
|
{
|
||||||
} catch (const std::range_error &) {
|
std::map<std::string, Boxed_Value>::const_iterator itr = m_scopes[i].find(name);
|
||||||
add_object(name, obj);
|
if (itr != m_scopes[i].end())
|
||||||
|
{
|
||||||
|
m_scopes[i][name] = Boxed_Value(obj);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
add_object(name, obj);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename Class>
|
template<typename Class>
|
||||||
void add_object(const std::string &name, const Class &obj)
|
void add_object(const std::string &name, const Class &obj)
|
||||||
{
|
{
|
||||||
@@ -75,7 +81,7 @@ class BoxedCPP_System
|
|||||||
|
|
||||||
Boxed_Value get_object(const std::string &name) const
|
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);
|
std::map<std::string, Boxed_Value>::const_iterator itr = m_scopes[i].find(name);
|
||||||
if (itr != m_scopes[i].end())
|
if (itr != m_scopes[i].end())
|
||||||
|
@@ -150,7 +150,7 @@ Boxed_Value eval_token(BoxedCPP_System &ss, TokenPtr node) {
|
|||||||
if (node->children.size() > 1) {
|
if (node->children.size() > 1) {
|
||||||
for (i = node->children.size()-3; ((int)i) >= 0; i -= 2) {
|
for (i = node->children.size()-3; ((int)i) >= 0; i -= 2) {
|
||||||
if (node->children[i+1]->text == "=") {
|
if (node->children[i+1]->text == "=") {
|
||||||
ss.add_object(node->children[i]->text, retval);
|
ss.set_object(node->children[i]->text, retval);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Param_List_Builder plb;
|
Param_List_Builder plb;
|
||||||
|
Reference in New Issue
Block a user