From ebbe0babdb88261d46fb62b05e60701522ee10db Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Mon, 1 Nov 2010 22:32:04 -0400 Subject: [PATCH] reverting ?= optimization, for the repl's sake. --- lib/nodes.js | 13 ++++--------- src/nodes.coffee | 14 +++++++------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/lib/nodes.js b/lib/nodes.js index 0c344684..c35ca15d 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -1069,7 +1069,7 @@ } else { ref = param; if (param.value) { - exprs.push(new Assign(new Value(param.name), param.value, '?=')); + exprs.push(new Op('||', new Literal("" + param.name.value + " != null"), new Assign(param.name, param.value))); } } if (!splats) { @@ -1320,20 +1320,15 @@ return o.level < LEVEL_OP ? code : "(" + code + ")"; }; Op.prototype.compileExistence = function(o) { - var end, fst, ref; - if (this.first.isComplex() && o.level > LEVEL_TOP) { + var fst, ref; + if (this.first.isComplex()) { ref = o.scope.freeVariable('ref'); fst = new Parens(new Assign(new Literal(ref), this.first)); } else { fst = this.first; ref = fst.compile(o); } - if (o.level === LEVEL_TOP) { - end = " || " + (this.second.compile(o, LEVEL_OP)); - } else { - end = " ? " + ref + " : " + (this.second.compile(o, LEVEL_LIST)); - } - return new Existence(fst).compile(o) + end; + return new Existence(fst).compile(o) + (" ? " + ref + " : " + (this.second.compile(o, LEVEL_LIST))); }; Op.prototype.compileUnary = function(o) { var op, parts; diff --git a/src/nodes.coffee b/src/nodes.coffee index b82e8d06..d07e6c46 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -882,7 +882,11 @@ exports.Code = class Code extends Base if param.value then new Op '?', ref, param.value else ref else ref = param - exprs.push new Assign new Value(param.name), param.value, '?=' if param.value + if param.value + exprs.push new Op('||', + new Literal("#{param.name.value} != null"), + new Assign(param.name, param.value) + ) vars.push ref unless splats scope.startLevel() wasEmpty = @body.isEmpty() @@ -1084,17 +1088,13 @@ exports.Op = class Op extends Base if o.level < LEVEL_OP then code else "(#{code})" compileExistence: (o) -> - if @first.isComplex() and o.level > LEVEL_TOP + if @first.isComplex() ref = o.scope.freeVariable 'ref' fst = new Parens new Assign new Literal(ref), @first else fst = @first ref = fst.compile o - if o.level is LEVEL_TOP - end = " || #{@second.compile o, LEVEL_OP}" - else - end = " ? #{ref} : #{@second.compile o, LEVEL_LIST}" - new Existence(fst).compile(o) + end + new Existence(fst).compile(o) + " ? #{ref} : #{ @second.compile o, LEVEL_LIST }" # Compile a unary **Op**. compileUnary: (o) ->