s/tempVars/tempVars.general/ This should allow us to store more than one
category of temporary variables.
This commit is contained in:
parent
08e1101c1f
commit
1f2c6c77fd
23
lib/scope.js
23
lib/scope.js
|
@ -6,17 +6,24 @@
|
|||
}
|
||||
exports.Scope = (function() {
|
||||
Scope = function(parent, expressions, method) {
|
||||
var _a;
|
||||
var _a, _b, k, val;
|
||||
_a = [parent, expressions, method];
|
||||
this.parent = _a[0];
|
||||
this.expressions = _a[1];
|
||||
this.method = _a[2];
|
||||
this.variables = {};
|
||||
this.tempVars = {
|
||||
general: '_a'
|
||||
};
|
||||
if (this.parent) {
|
||||
this.tempVar = this.parent.tempVar;
|
||||
_b = this.parent.tempVars;
|
||||
for (k in _b) {
|
||||
if (!__hasProp.call(_b, k)) continue;
|
||||
val = _b[k];
|
||||
(this.tempVars[k] = val);
|
||||
}
|
||||
} else {
|
||||
Scope.root = this;
|
||||
this.tempVar = '_a';
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
@ -53,12 +60,12 @@
|
|||
};
|
||||
Scope.prototype.freeVariable = function() {
|
||||
var ordinal;
|
||||
while (this.check(this.tempVar)) {
|
||||
ordinal = 1 + parseInt(this.tempVar.substr(1), 36);
|
||||
this.tempVar = '_' + ordinal.toString(36).replace(/\d/g, 'a');
|
||||
while (this.check(this.tempVars.general)) {
|
||||
ordinal = 1 + parseInt(this.tempVars.general.substr(1), 36);
|
||||
this.tempVars.general = '_' + ordinal.toString(36).replace(/\d/g, 'a');
|
||||
}
|
||||
this.variables[this.tempVar] = 'var';
|
||||
return this.tempVar;
|
||||
this.variables[this.tempVars.general] = 'var';
|
||||
return this.tempVars.general;
|
||||
};
|
||||
Scope.prototype.assign = function(name, value) {
|
||||
return (this.variables[name] = {
|
||||
|
|
|
@ -20,11 +20,12 @@ exports.Scope = class Scope
|
|||
constructor: (parent, expressions, method) ->
|
||||
[@parent, @expressions, @method] = [parent, expressions, method]
|
||||
@variables = {}
|
||||
@tempVars =
|
||||
general: '_a'
|
||||
if @parent
|
||||
@tempVar = @parent.tempVar
|
||||
(@tempVars[k] = val) for k, val of @parent.tempVars
|
||||
else
|
||||
Scope.root = this
|
||||
@tempVar = '_a'
|
||||
|
||||
# Look up a variable name in lexical scope, and declare it if it does not
|
||||
# already exist.
|
||||
|
@ -54,11 +55,11 @@ exports.Scope = class Scope
|
|||
# If we need to store an intermediate result, find an available name for a
|
||||
# compiler-generated variable. `_a`, `_b`, and so on...
|
||||
freeVariable: ->
|
||||
while @check @tempVar
|
||||
ordinal = 1 + parseInt @tempVar.substr(1), 36
|
||||
@tempVar = '_' + ordinal.toString(36).replace(/\d/g, 'a')
|
||||
@variables[@tempVar] = 'var'
|
||||
@tempVar
|
||||
while @check @tempVars.general
|
||||
ordinal = 1 + parseInt @tempVars.general.substr(1), 36
|
||||
@tempVars.general = '_' + ordinal.toString(36).replace(/\d/g, 'a')
|
||||
@variables[@tempVars.general] = 'var'
|
||||
@tempVars.general
|
||||
|
||||
# Ensure that an assignment is made at the top of this scope
|
||||
# (or at the top-level scope, if requested).
|
||||
|
|
Loading…
Reference in New Issue