From 408833daef62e39dadafa2ea943e7994460d5fbc Mon Sep 17 00:00:00 2001 From: Stan Angeloff Date: Sun, 19 Sep 2010 15:37:26 +0300 Subject: [PATCH] Removing code added during the migration. `freeVariable(..)` is called with a `type` at all times. --- lib/scope.js | 19 ++++--------------- src/scope.coffee | 15 ++++----------- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/lib/scope.js b/lib/scope.js index 4b2e9619..f819024f 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -12,9 +12,7 @@ this.expressions = _cache[1]; this.method = _cache[2]; this.variables = {}; - this.tempVars = { - general: '_a' - }; + this.tempVars = {}; if (this.parent) { _cache2 = this.parent.tempVars; for (k in _cache2) { @@ -60,18 +58,9 @@ }; 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'); - }; - } + 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]); } diff --git a/src/scope.coffee b/src/scope.coffee index ef610067..660eddb2 100644 --- a/src/scope.coffee +++ b/src/scope.coffee @@ -20,8 +20,7 @@ exports.Scope = class Scope constructor: (parent, expressions, method) -> [@parent, @expressions, @method] = [parent, expressions, method] @variables = {} - @tempVars = - general: '_a' + @tempVars = {} if @parent (@tempVars[k] = val) for k, val of @parent.tempVars else @@ -53,16 +52,10 @@ exports.Scope = class Scope !!(@parent and @parent.check(name)) # If we need to store an intermediate result, find an available name for a - # compiler-generated variable. `_a`, `_b`, and so on... + # compiler-generated variable. `_var`, `_var2`, and so on... freeVariable: (type) -> - if type - next = (prev) -> - '_' + type + ((prev and Number(prev.match(/\d+$/) or 1) + 1) or '') - else - type = 'general' - next = (prev) -> - ordinal = 1 + parseInt prev.substr(1), 36 - '_' + ordinal.toString(36).replace /\d/g, 'a' + 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'