tweaks to scope

This commit is contained in:
Jeremy Ashkenas
2010-10-20 23:09:06 -04:00
parent f229f791a9
commit bb080130b9
2 changed files with 21 additions and 26 deletions

View File

@@ -7,12 +7,7 @@
this.method = _arg3;
this.expressions = _arg2;
this.parent = _arg;
this.variables = [
{
name: 'arguments',
type: 'arguments'
}
];
this.variables = [];
this.positions = {};
if (this.parent) {
this.garbage = this.parent.garbage;
@@ -25,14 +20,14 @@
return Scope;
})();
Scope.root = null;
Scope.prototype.setVar = function(name, type) {
Scope.prototype.add = function(name, type) {
if (this.positions.hasOwnProperty(name)) {
this.variables[this.positions[name]].type = type;
} else {
this.positions[name] = -1 + this.variables.push({
this.positions[name] = this.variables.push({
name: name,
type: type
});
}) - 1;
}
return this;
};
@@ -45,7 +40,7 @@
for (_i = 0, _len = (_ref2 = this.garbage.pop()).length; _i < _len; _i++) {
name = _ref2[_i];
if (this.type(name) === 'var') {
this.setVar(name, 'reuse');
this.add(name, 'reuse');
}
}
return this;
@@ -54,7 +49,7 @@
if (this.check(name, options)) {
return true;
}
this.setVar(name, 'var');
this.add(name, 'var');
return false;
};
Scope.prototype.any = function(fn) {
@@ -68,7 +63,7 @@
return false;
};
Scope.prototype.parameter = function(name) {
return this.setVar(name, 'param');
return this.add(name, 'param');
};
Scope.prototype.check = function(name, options) {
var _ref2, immediate;
@@ -97,12 +92,12 @@
while (this.check(temp = this.temporary(type, index)) && this.type(temp) !== 'reuse') {
index++;
}
this.setVar(temp, 'var');
this.add(temp, 'var');
((_ref2 = last(this.garbage)) != null) ? _ref2.push(temp) : undefined;
return temp;
};
Scope.prototype.assign = function(name, value) {
return this.setVar(name, {
return this.add(name, {
value: value,
assigned: true
});