Part of previous commit: updating how temporary variables are generated.

We no longer need to store the name of the last generated variable,
instead we store the index.
This commit is contained in:
Stan Angeloff
2010-09-19 15:50:17 +03:00
parent 408833daef
commit 65fa0411b4
2 changed files with 8 additions and 14 deletions

View File

@@ -57,15 +57,12 @@
return !!(this.parent && this.parent.check(name));
};
Scope.prototype.freeVariable = function(type) {
var next;
next = function(prev) {
return '_' + type + ((prev && Number(prev.match(/\d+$/) || 1) + 1) || '');
};
while (this.check(this.tempVars[type] || (this.tempVars[type] = next()))) {
this.tempVars[type] = next(this.tempVars[type]);
var temp;
while (this.check(temp = '_' + type + ((this.tempVars[type] || (this.tempVars[type] = 1)) > 1 ? this.tempVars[type] : ''))) {
this.tempVars[type]++;
}
this.variables[this.tempVars[type]] = 'var';
return this.tempVars[type];
this.variables[temp] = 'var';
return temp;
};
Scope.prototype.assign = function(name, value) {
return (this.variables[name] = {

View File

@@ -54,12 +54,9 @@ exports.Scope = class Scope
# If we need to store an intermediate result, find an available name for a
# compiler-generated variable. `_var`, `_var2`, and so on...
freeVariable: (type) ->
next = (prev) ->
'_' + type + ((prev and Number(prev.match(/\d+$/) or 1) + 1) or '')
while @check @tempVars[type] or= next()
@tempVars[type] = next @tempVars[type]
@variables[@tempVars[type]] = 'var'
@tempVars[type]
@tempVars[type]++ while @check temp = '_' + type + (if (@tempVars[type] or= 1) > 1 then @tempVars[type] else '')
@variables[temp] = 'var'
temp
# Ensure that an assignment is made at the top of this scope
# (or at the top-level scope, if requested).