From c498b7090e1ac148ac018f466504a2169c46f33e Mon Sep 17 00:00:00 2001 From: matehat Date: Tue, 30 Mar 2010 18:14:51 -0400 Subject: [PATCH] Removed `__splice` in the same manner --- lib/nodes.js | 8 +++++--- lib/utilities.js | 1 - src/nodes.coffee | 6 ++++-- src/utilities.coffee | 6 ------ 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/nodes.js b/lib/nodes.js index c2d7d58a..e99d40ed 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -736,14 +736,16 @@ return ".slice(" + from + ", " + to + plus_part + ")"; }; SliceNode.prototype.compile_splice = function compile_splice(o) { - var _a, _b, array, call, exclusive, from, ref, replace, to; + var _a, _b, args, array, call, exclusive, from, replace, rng, to, v; array = del(o, 'array'); replace = del(o, 'replace'); from = (typeof (_a = this.range.from) !== "undefined" && _a !== null) ? this.range.from : literal('null'); to = (typeof (_b = this.range.to) !== "undefined" && _b !== null) ? this.range.to : literal('null'); exclusive = this.range.exclusive ? 'true' : 'false'; - ref = new ValueNode(literal(o.scope.utility('splice'))); - call = new CallNode(ref, [literal(array), from, to, literal(exclusive), replace]); + v = o.scope.free_variable(); + rng = new CallNode(new ValueNode(literal(o.scope.utility('range'))), [literal(array), from, to, literal(exclusive)]); + args = literal("[(" + v + " = " + (rng.compile(o)) + ")[0], " + v + "[1] - " + v + "[0]].concat(" + (replace.compile(o)) + ")"); + call = new CallNode(new ValueNode(literal(array), [literal('.splice.apply')]), [literal(array), args]); return call.compile(o); }; SliceNode.prototype.compile_slice = function compile_slice(o) { diff --git a/lib/utilities.js b/lib/utilities.js index 883afc80..026b7cf4 100644 --- a/lib/utilities.js +++ b/lib/utilities.js @@ -19,7 +19,6 @@ extend: "function(child, parent) {\n var ctor = function(){ };\n ctor.prototype = parent.prototype;\n child.__superClass__ = parent.prototype;\n child.prototype = new ctor();\n child.prototype.constructor = child;\n}", bind: "function(func, obj, args) {\n obj = obj || {};\n return (typeof args !== 'undefined' && args !== null) ? function() {\n return func.apply(obj, args.concat(" + (utilities.key('arraySlice')) + ".call(arguments, 0)));\n } : function() {\n return func.apply(obj, arguments);\n };\n}", range: "function(array, from, to, exclusive) {\n return [\n (from < 0 ? from + array.length : from || 0),\n (to < 0 ? to + array.length : to || array.length) + (exclusive ? 0 : 1)\n ];\n}", - splice: "function(array, from, to, exclusive, replace) {\n return array.splice.apply(array, [(_a = " + (utilities.key('range')) + "(array, from, to, exclusive))[0], \n _a[1] - _a[0]].concat(replace));\n}", hasProp: 'Object.prototype.hasOwnProperty', arraySlice: 'Array.prototype.slice' }; diff --git a/src/nodes.coffee b/src/nodes.coffee index 5ce6447c..5cf43e2e 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -546,8 +546,10 @@ exports.SliceNode: class SliceNode extends BaseNode from: if @range.from? then @range.from else literal('null') to: if @range.to? then @range.to else literal('null') exclusive: if @range.exclusive then 'true' else 'false' - ref: new ValueNode literal(o.scope.utility('splice')) - call: new CallNode ref, [literal(array), from, to, literal(exclusive), replace] + v: o.scope.free_variable() + rng: new CallNode new ValueNode(literal(o.scope.utility('range'))), [literal(array), from, to, literal(exclusive)] + args: literal "[($v = ${rng.compile(o)})[0], $v[1] - $v[0]].concat(${replace.compile(o)})" + call: new CallNode new ValueNode(literal(array), [literal('.splice.apply')]), [literal(array), args] call.compile(o) compile_slice: (o) -> diff --git a/src/utilities.coffee b/src/utilities.coffee index aafb839e..47943a4b 100644 --- a/src/utilities.coffee +++ b/src/utilities.coffee @@ -40,12 +40,6 @@ exports.utilities: class utilities ]; } """ - splice: """ - function(array, from, to, exclusive, replace) { - return array.splice.apply(array, [(_a = ${utilities.key('range')}(array, from, to, exclusive))[0], - _a[1] - _a[0]].concat(replace)); - } - """ hasProp: 'Object.prototype.hasOwnProperty' arraySlice: 'Array.prototype.slice' } \ No newline at end of file