reenabled stricter caching on For compilation as well as reduced a line from it

This commit is contained in:
satyr
2010-10-07 12:24:32 +09:00
parent 30a18fdaeb
commit 95bc4c5eeb
11 changed files with 100 additions and 119 deletions

View File

@@ -99,8 +99,8 @@
var _i, _len, _ref2, _result, child, children, klass;
idt || (idt = '');
children = (function() {
_result = []; _ref2 = this.collectChildren();
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
_result = [];
for (_i = 0, _len = (_ref2 = this.collectChildren()).length; _i < _len; _i++) {
child = _ref2[_i];
_result.push(child.toString(idt + TAB));
}
@@ -114,12 +114,11 @@
if (!(this.children)) {
return;
}
_result = []; _ref2 = this.children;
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
_result = [];
for (_i = 0, _len = (_ref2 = this.children).length; _i < _len; _i++) {
attr = _ref2[_i];
if (this[attr]) {
_ref3 = flatten([this[attr]]);
for (_j = 0, _len2 = _ref3.length; _j < _len2; _j++) {
for (_j = 0, _len2 = (_ref3 = flatten([this[attr]])).length; _j < _len2; _j++) {
child = _ref3[_j];
if (func(child) === false) {
return;
@@ -196,8 +195,8 @@
Expressions.prototype.compileNode = function(o) {
var _i, _len, _ref2, _result, node;
return (function() {
_result = []; _ref2 = this.expressions;
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
_result = [];
for (_i = 0, _len = (_ref2 = this.expressions).length; _i < _len; _i++) {
node = _ref2[_i];
_result.push(this.compileExpression(node, merge(o)));
}
@@ -401,8 +400,7 @@
Array.prototype.push.apply(this.base.body.properties, this.properties);
return this.base;
}
_ref2 = this.properties;
for (i = 0, _len = _ref2.length; i < _len; i++) {
for (i = 0, _len = (_ref2 = this.properties).length; i < _len; i++) {
prop = _ref2[i];
if (prop.soakNode) {
prop.soakNode = false;
@@ -510,8 +508,7 @@
break;
}
}
_ref2 = list.reverse();
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
for (_i = 0, _len = (_ref2 = list.reverse()).length; _i < _len; _i++) {
call = _ref2[_i];
if (node) {
if (call.variable instanceof Call) {
@@ -545,16 +542,15 @@
rite = rite.compile(o);
return ("(" + left + " ? undefined : " + rite + ")");
}
_ref3 = this.args;
for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
for (_i = 0, _len = (_ref3 = this.args).length; _i < _len; _i++) {
arg = _ref3[_i];
if (arg instanceof Splat) {
return this.compileSplat(o);
}
}
args = (function() {
_result = []; _ref4 = this.args;
for (_j = 0, _len2 = _ref4.length; _j < _len2; _j++) {
_result = [];
for (_j = 0, _len2 = (_ref4 = this.args).length; _j < _len2; _j++) {
arg = _ref4[_j];
_result.push((arg.parenthetical = true) && arg.compile(o));
}
@@ -590,8 +586,7 @@
argvar = function(node) {
return node instanceof Literal && node.value === 'arguments';
};
_ref2 = this.args;
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
for (_i = 0, _len = (_ref2 = this.args).length; _i < _len; _i++) {
arg = _ref2[_i];
if (arg.contains(argvar)) {
call = 'apply(this, arguments)';
@@ -694,13 +689,11 @@
if (this.from !== this.fromVar) {
parts.push(this.from);
}
if (this.to !== this.toVar) {
parts.push(this.to);
}
return parts.length ? ("" + (parts.join('; ')) + "; ") : '';
return this.to !== this.toVar ? parts.push(this.to) : undefined;
};
Range.prototype.compileNode = function(o) {
var compare, idx, incr, intro, step, stepPart, vars;
this.compileVariables(o);
if (!(o.index)) {
return this.compileArray(o);
}
@@ -709,7 +702,7 @@
}
idx = del(o, 'index');
step = del(o, 'step');
vars = ("" + idx + " = " + (this.fromVar));
vars = ("" + idx + " = " + (this.from)) + (this.to !== this.toVar ? (", " + (this.to)) : '');
intro = ("(" + (this.fromVar) + " <= " + (this.toVar) + " ? " + idx);
compare = ("" + intro + " <" + (this.equals) + " " + (this.toVar) + " : " + idx + " >" + (this.equals) + " " + (this.toVar) + ")");
stepPart = step ? step.compile(o) : '1';
@@ -726,14 +719,10 @@
};
Range.prototype.compileArray = function(o) {
var _i, _ref2, _ref3, _result, body, clause, i, idt, post, pre, range, result, vars;
idt = this.idt(1);
vars = this.compileVariables(merge(o, {
indent: idt
}));
if (this.fromNum && this.toNum && (Math.abs(this.fromNum - this.toNum) <= 20)) {
range = (function() {
_result = []; _ref2 = +this.fromNum; _ref3 = +this.toNum;
for (var _i = _ref2; _ref2 <= _ref3 ? _i <= _ref3 : _i >= _ref3; _ref2 <= _ref3 ? _i += 1 : _i -= 1){ _result.push(_i); }
_result = [];
for (var _i = _ref2 = +this.fromNum, _ref3 = +this.toNum; _ref2 <= _ref3 ? _i <= _ref3 : _i >= _ref3; _ref2 <= _ref3 ? _i += 1 : _i -= 1){ _result.push(_i); }
return _result;
}).call(this);
if (this.exclusive) {
@@ -741,15 +730,17 @@
}
return ("[" + (range.join(', ')) + "]");
}
idt = this.idt(1);
i = o.scope.freeVariable('i');
result = o.scope.freeVariable('result');
pre = ("\n" + idt + result + " = []; " + vars);
pre = ("\n" + idt + result + " = [];");
if (this.fromNum && this.toNum) {
o.index = i;
body = this.compileSimple(o);
} else {
vars = ("" + i + " = " + (this.from)) + (this.to !== this.toVar ? (", " + (this.to)) : '');
clause = ("" + (this.fromVar) + " <= " + (this.toVar) + " ?");
body = ("var " + i + " = " + (this.fromVar) + "; " + clause + " " + i + " <" + (this.equals) + " " + (this.toVar) + " : " + i + " >" + (this.equals) + " " + (this.toVar) + "; " + clause + " " + i + " += 1 : " + i + " -= 1");
body = ("var " + vars + "; " + clause + " " + i + " <" + (this.equals) + " " + (this.toVar) + " : " + i + " >" + (this.equals) + " " + (this.toVar) + "; " + clause + " " + i + " += 1 : " + i + " -= 1");
}
post = ("{ " + result + ".push(" + i + "); }\n" + idt + "return " + result + ";\n" + (o.indent));
return "(function() {" + pre + "\n" + idt + "for (" + body + ")" + post + "}).call(this)";
@@ -794,8 +785,8 @@
top = del(o, 'top');
o.indent = this.idt(1);
nonComments = (function() {
_result = []; _ref2 = this.properties;
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
_result = [];
for (_i = 0, _len = (_ref2 = this.properties).length; _i < _len; _i++) {
prop = _ref2[_i];
if (!(prop instanceof Comment)) {
_result.push(prop);
@@ -805,8 +796,8 @@
}).call(this);
lastNoncom = last(nonComments);
props = (function() {
_result = []; _ref2 = this.properties;
for (i = 0, _len = _ref2.length; i < _len; i++) {
_result = [];
for (i = 0, _len = (_ref2 = this.properties).length; i < _len; i++) {
prop = _ref2[i];
_result.push((function() {
join = ",\n";
@@ -851,8 +842,7 @@
var _len, _ref2, code, i, obj, objects;
o.indent = this.idt(1);
objects = [];
_ref2 = this.objects;
for (i = 0, _len = _ref2.length; i < _len; i++) {
for (i = 0, _len = (_ref2 = this.objects).length; i < _len; i++) {
obj = _ref2[i];
code = obj.compile(o);
if (obj instanceof Splat) {
@@ -907,8 +897,7 @@
} else {
constructor = new Code;
}
_ref2 = this.properties;
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
for (_i = 0, _len = (_ref2 = this.properties).length; _i < _len; _i++) {
prop = _ref2[_i];
_ref3 = [prop.variable, prop.value], pvar = _ref3[0], func = _ref3[1];
if (pvar && pvar.base.value === 'constructor') {
@@ -1118,8 +1107,7 @@
del(o, 'globals');
splat = undefined;
params = [];
_ref2 = this.params;
for (i = 0, _len = _ref2.length; i < _len; i++) {
for (i = 0, _len = (_ref2 = this.params).length; i < _len; i++) {
param = _ref2[i];
if (splat) {
if (param.attach) {
@@ -1235,8 +1223,7 @@
variadic = o.scope.freeVariable('result');
o.scope.assign(variadic, len + ' >= ' + this.arglength);
end = this.trailings.length ? (", " + len + " - " + (this.trailings.length)) : undefined;
_ref2 = this.trailings;
for (idx = 0, _len = _ref2.length; idx < _len; idx++) {
for (idx = 0, _len = (_ref2 = this.trailings).length; idx < _len; idx++) {
trailing = _ref2[idx];
if (trailing.attach) {
assign = trailing.assign;
@@ -1478,8 +1465,8 @@
In.prototype.compileOrTest = function(o) {
var _len, _ref2, _result, i, item, tests;
tests = (function() {
_result = []; _ref2 = this.array.base.objects;
for (i = 0, _len = _ref2.length; i < _len; i++) {
_result = [];
for (i = 0, _len = (_ref2 = this.array.base.objects).length; i < _len; i++) {
item = _ref2[i];
_result.push("" + (item.compile(o)) + " === " + (i ? this.obj2 : this.obj1));
}
@@ -1646,7 +1633,7 @@
return '';
};
For.prototype.compileNode = function(o) {
var _ref2, body, codeInBody, forPart, guardPart, idt1, index, ivar, lvar, name, namePart, range, returnResult, rvar, scope, source, sourcePart, stepPart, svar, topLevel, varPart, vars;
var body, codeInBody, forPart, guardPart, idt1, index, ivar, lvar, name, namePart, range, ref, resultPart, returnResult, rvar, scope, source, sourcePart, stepPart, svar, topLevel, varPart, vars;
topLevel = del(o, 'top') && !this.returns;
range = this.source instanceof Value && this.source.base instanceof Range && !this.source.properties.length;
source = range ? this.source.base : this.source;
@@ -1678,29 +1665,33 @@
body = Expressions.wrap([this.body]);
idt1 = this.idt(1);
if (range) {
sourcePart = source.compileVariables(o);
forPart = source.compile(merge(o, {
index: ivar,
step: this.step
}));
} else {
_ref2 = this.source.compileReference(merge(o, {
top: true
}), {
precompile: true
}), sourcePart = _ref2[0], svar = _ref2[1];
sourcePart = sourcePart === svar ? '' : ("" + sourcePart + ";");
svar = this.source.compile(o);
if (IDENTIFIER.test(svar) && scope.check(svar, {
immediate: true
})) {
sourcePart = svar;
} else {
sourcePart = ("" + (ref = scope.freeVariable('ref')) + " = " + svar);
if (!(this.object)) {
sourcePart = ("(" + sourcePart + ")");
}
svar = ref;
}
namePart = this.pattern ? new Assign(this.name, literal("" + svar + "[" + ivar + "]")).compile(merge(o, {
top: true
})) : (name ? ("" + name + " = " + svar + "[" + ivar + "]") : undefined);
if (!(this.object)) {
lvar = scope.freeVariable('len');
stepPart = this.step ? ("" + ivar + " += " + (this.step.compile(o))) : ("" + ivar + "++");
forPart = ("" + ivar + " = 0, " + lvar + " = " + svar + ".length; " + ivar + " < " + lvar + "; " + stepPart);
forPart = ("" + ivar + " = 0, " + lvar + " = " + sourcePart + ".length; " + ivar + " < " + lvar + "; " + stepPart);
}
}
sourcePart = (rvar ? ("" + rvar + " = []; ") : '') + sourcePart;
sourcePart = sourcePart ? ("" + (this.tab) + sourcePart + "\n" + (this.tab)) : this.tab;
resultPart = rvar ? ("" + (this.tab) + rvar + " = [];\n") : '';
returnResult = this.compileReturnValue(rvar, o);
if (!(topLevel)) {
body = Push.wrap(rvar, body);
@@ -1725,7 +1716,7 @@
}
}
if (this.object) {
forPart = ("" + ivar + " in " + svar);
forPart = ("" + ivar + " in " + sourcePart);
if (!(this.raw)) {
guardPart = ("\n" + idt1 + "if (!" + (utility('hasProp')) + ".call(" + svar + ", " + ivar + ")) continue;");
}
@@ -1735,7 +1726,7 @@
top: true
}));
vars = range ? name : ("" + name + ", " + ivar);
return "" + sourcePart + "for (" + forPart + ") {" + guardPart + "\n" + varPart + body + "\n" + (this.tab) + "}" + returnResult;
return "" + resultPart + (this.tab) + "for (" + forPart + ") {" + guardPart + "\n" + varPart + body + "\n" + (this.tab) + "}" + returnResult;
};
return For;
})();
@@ -1756,8 +1747,7 @@
Switch.prototype.isStatement = YES;
Switch.prototype.makeReturn = function() {
var _i, _len, _ref2, pair;
_ref2 = this.cases;
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
for (_i = 0, _len = (_ref2 = this.cases).length; _i < _len; _i++) {
pair = _ref2[_i];
pair[1].makeReturn();
}
@@ -1771,13 +1761,11 @@
idt = (o.indent = this.idt(2));
o.top = true;
code = ("" + (this.tab) + "switch (" + (this.subject.compile(o)) + ") {");
_ref2 = this.cases;
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
for (_i = 0, _len = (_ref2 = this.cases).length; _i < _len; _i++) {
pair = _ref2[_i];
_ref3 = pair, conditions = _ref3[0], block = _ref3[1];
exprs = block.expressions;
_ref4 = flatten([conditions]);
for (_j = 0, _len2 = _ref4.length; _j < _len2; _j++) {
for (_j = 0, _len2 = (_ref4 = flatten([conditions])).length; _j < _len2; _j++) {
condition = _ref4[_j];
if (this.tags.subjectless) {
condition = new Op('!!', new Parenthetical(condition));