Added generator for custom free variable types, e.g., '_cache',

'_cache2', and so on.
This commit is contained in:
Stan Angeloff
2010-09-19 14:55:19 +03:00
parent 1f2c6c77fd
commit fe68261bc2
2 changed files with 31 additions and 13 deletions

View File

@@ -58,14 +58,25 @@
}
return !!(this.parent && this.parent.check(name));
};
Scope.prototype.freeVariable = function() {
var ordinal;
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');
Scope.prototype.freeVariable = function(type) {
var next;
if (type) {
next = function(prev) {
return '_' + type + ((prev && Number(prev.match(/\d+$/) || 1) + 1) || '');
};
} else {
type = 'general';
next = function(prev) {
var ordinal;
ordinal = 1 + parseInt(prev.substr(1), 36);
return '_' + ordinal.toString(36).replace(/\d/g, 'a');
};
}
this.variables[this.tempVars.general] = 'var';
return this.tempVars.general;
while (this.check(this.tempVars[type] || (this.tempVars[type] = next()))) {
this.tempVars[type] = next(this.tempVars[type]);
}
this.variables[this.tempVars[type]] = 'var';
return this.tempVars[type];
};
Scope.prototype.assign = function(name, value) {
return (this.variables[name] = {