diff --git a/src/script/context.cpp b/src/script/context.cpp index cd8c12f9..b630daf4 100644 --- a/src/script/context.cpp +++ b/src/script/context.cpp @@ -265,12 +265,22 @@ ScriptValueP Context::makeClosure(const ScriptValueP& fun) { size_t Context::openScope() { level += 1; + #ifdef _DEBUG + scopes.push_back(shadowed.size()); + assert(scopes.size() == level); + #endif return shadowed.size(); } void Context::closeScope(size_t scope) { assert(level > 0); assert(scope <= shadowed.size()); level -= 1; + #ifdef _DEBUG + assert(!scopes.empty()); + assert(scopes.back() == scope); + scopes.pop_back(); + assert(scopes.size() == level); + #endif // restore shadowed variables while (shadowed.size() > scope) { variables[shadowed.back().variable] = shadowed.back().value; diff --git a/src/script/context.hpp b/src/script/context.hpp index cc034eff..81da61a9 100644 --- a/src/script/context.hpp +++ b/src/script/context.hpp @@ -102,7 +102,11 @@ class Context { /// Number of scopes opened unsigned int level; /// Stack of values - vector stack; + vector stack; + #ifdef _DEBUG + /// The opened scopes, for sanity checking + vector scopes; + #endif // utility types for dependency analysis struct Jump; diff --git a/src/script/dependency.cpp b/src/script/dependency.cpp index ab4038df..7b22c3ef 100644 --- a/src/script/dependency.cpp +++ b/src/script/dependency.cpp @@ -159,7 +159,7 @@ ScriptValueP Context::dependencies(const Dependency& dep, const Script& script) } // unify bindings FOR_EACH(v, j->bindings) { - unify(variables[v.variable].value, v.value.value); + setVariable(v.variable, unified(variables[v.variable].value, v.value.value) ); } delete j; } @@ -368,9 +368,8 @@ void Context::getBindings(size_t scope, vector& bindings) { } void Context::resetBindings(size_t scope) { - // same as closeScope() - while (shadowed.size() > scope) { - variables[shadowed.back().variable] = shadowed.back().value; - shadowed.pop_back(); - } + // close and re-open the scope + closeScope(scope); + size_t same_scope = openScope(); + assert(scope == same_scope); }