switched from alphabetical __a __b temporary variables, to numeric _1, _2, which will be shorter in most cases

This commit is contained in:
Jeremy Ashkenas
2010-02-15 21:55:57 -05:00
parent 48c501a7a2
commit 4ea8be8e0b
8 changed files with 257 additions and 266 deletions

View File

@@ -1,5 +1,5 @@
(function(){
var Scope, succ;
var Scope;
var __hasProp = Object.prototype.hasOwnProperty;
if (!((typeof process !== "undefined" && process !== null))) {
this.exports = this;
@@ -16,7 +16,7 @@
this.expressions = expressions;
this.method = method;
this.variables = {};
this.temp_variable = this.parent ? this.parent.temp_variable : '__a';
this.temp_variable = this.parent ? this.parent.temp_variable : 1;
return this;
});
// Look up a variable in lexical scope, or declare it if not found.
@@ -47,11 +47,13 @@
};
// Find an available, short, name for a compiler-generated variable.
Scope.prototype.free_variable = function free_variable() {
while (this.check(this.temp_variable)) {
((this.temp_variable = succ(this.temp_variable)));
var id;
id = '_' + this.temp_variable;
while (this.check(id)) {
id = '_' + (this.temp_variable += 1);
}
this.variables[this.temp_variable] = 'var';
return this.temp_variable;
this.variables[id] = 'var';
return id;
};
// Ensure that an assignment is made at the top of scope (or top-level
// scope, if requested).
@@ -76,50 +78,45 @@
};
// Return the list of variables first declared in current scope.
Scope.prototype.declared_variables = function declared_variables() {
var __a, __b, key, val;
var _1, _2, key, val;
return ((function() {
__a = []; __b = this.variables;
for (key in __b) if (__hasProp.call(__b, key)) {
val = __b[key];
_1 = []; _2 = this.variables;
for (key in _2) if (__hasProp.call(_2, key)) {
val = _2[key];
if (val === 'var') {
__a.push(key);
_1.push(key);
}
}
return __a;
return _1;
}).call(this)).sort();
};
// Return the list of variables that are supposed to be assigned at the top
// of scope.
Scope.prototype.assigned_variables = function assigned_variables() {
var __a, __b, key, val;
var _1, _2, key, val;
return ((function() {
__a = []; __b = this.variables;
for (key in __b) if (__hasProp.call(__b, key)) {
val = __b[key];
_1 = []; _2 = this.variables;
for (key in _2) if (__hasProp.call(_2, key)) {
val = _2[key];
if (val.assigned) {
__a.push([key, val.value]);
_1.push([key, val.value]);
}
}
return __a;
return _1;
}).call(this)).sort();
};
Scope.prototype.compiled_declarations = function compiled_declarations() {
return this.declared_variables().join(', ');
};
Scope.prototype.compiled_assignments = function compiled_assignments() {
var __a, __b, __c, t;
var _1, _2, _3, t;
return ((function() {
__a = []; __b = this.assigned_variables();
for (__c = 0; __c < __b.length; __c++) {
t = __b[__c];
__a.push(t[0] + ' = ' + t[1]);
_1 = []; _2 = this.assigned_variables();
for (_3 = 0; _3 < _2.length; _3++) {
t = _2[_3];
_1.push(t[0] + ' = ' + t[1]);
}
return __a;
return _1;
}).call(this)).join(', ');
};
// Helper functions:
// The next character alphabetically, to produce the following string.
succ = function succ(str) {
return str.slice(0, str.length - 1) + String.fromCharCode(str.charCodeAt(str.length - 1) + 1);
};
})();