Use closure stuff for making built in *_rule functions, simplifying the code.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@990 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2008-06-18 22:17:56 +00:00
parent 296cf8197a
commit 864903bc0c
3 changed files with 49 additions and 51 deletions
+13
View File
@@ -241,6 +241,19 @@ int Context::getVariableScope(Variable var) {
else return -1;
}
ScriptValueP Context::makeClosure(const ScriptValueP& fun) {
intrusive_ptr<ScriptClosure> closure(new ScriptClosure(fun));
// we can find out which variables are in the last level by looking at shadowed
// these variables will be at the end of the list
for (size_t i = shadowed.size() - 1 ; i + 1 > 0 ; --i) {
Variable var = shadowed[i].variable;
assert(variables[var].value);
if (variables[var].level < level) break;
closure->addBinding(var, variables[var].value);
}
return closure;
}
size_t Context::openScope() {
level += 1;