Skip to content
Browse files

holy shit, epic battle with the unwrap bugs has been won, for now at …

…least.
  • Loading branch information...
1 parent b8f74f8 commit dc81455584b5345054694cfe5aa774d35d34a106 @maxtaco committed
Showing with 55 additions and 29 deletions.
  1. +16 −10 lib/coffee-script/nodes.js
  2. +16 −10 lib/coffee-script/tamelib.js
  3. +23 −9 src/nodes.coffee
View
26 lib/coffee-script/nodes.js
@@ -380,9 +380,15 @@
};
Base.prototype.tameUnwrap = function(e) {
- e.tameContinuationBlock = this.tameContinuationBlock;
- e.tamePrequels = this.tamePrequels;
- return e;
+ if (e.tameHasContinuation() && this.tameHasContinuation()) {
+ return this;
+ } else {
+ if (this.tameHasContinuation()) {
+ e.tameContinuationBlock = this.tameContinuationBlock;
+ e.tamePrequels = this.tamePrequels;
+ }
+ return e;
+ }
};
Base.prototype.isStatement = NO;
@@ -473,11 +479,12 @@
Block.prototype.tameThreadReturn = function(call) {
var expr, foundReturn, len;
+ call = call || new TameTailCall;
len = this.expressions.length;
foundReturn = false;
while (len--) {
expr = this.expressions[len];
- if (expr.isStatement()) break;
+ if (expr.isStatement() || expr.tameIsCpsPivot()) break;
if (!(expr instanceof Comment) && !(expr instanceof Return)) {
call.assignValue(expr);
this.expressions[len] = call;
@@ -3200,14 +3207,13 @@
};
Switch.prototype.tameCallContinuation = function() {
- var block, code, condition, _i, _len, _ref2, _ref3, _ref4;
- code = new TameTailCall;
+ var block, condition, _i, _len, _ref2, _ref3, _ref4;
_ref2 = this.cases;
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
_ref3 = _ref2[_i], condition = _ref3[0], block = _ref3[1];
- block.push(code);
+ block.tameThreadReturn();
}
- return (_ref4 = this.otherwise) != null ? _ref4.push(code) : void 0;
+ return (_ref4 = this.otherwise) != null ? _ref4.tameThreadReturn() : void 0;
};
Switch.prototype.compileNode = function(o) {
@@ -3280,12 +3286,12 @@
If.prototype.tameCallContinuation = function() {
if (this.elseBody) {
- this.elseBody.tameThreadReturn(new TameTailCall);
+ this.elseBody.tameThreadReturn();
this.isChain = false;
} else {
this.addElse(new TameTailCall);
}
- return this.body.tameThreadReturn(new TameTailCall);
+ return this.body.tameThreadReturn();
};
If.prototype.isStatement = function(o) {
View
26 lib/coffee-script/tamelib.js
@@ -75,9 +75,11 @@
return _continue();
};
if (_this.n_out > _this.window) {
- __tame_deferrals = new tame.Deferrals(__tame_k);
- _this.cb = __tame_deferrals.defer({});
- __tame_deferrals._fulfill();
+ (function(__tame_k) {
+ __tame_deferrals = new tame.Deferrals(__tame_k);
+ _this.cb = __tame_deferrals.defer({});
+ __tame_deferrals._fulfill();
+ })(_next);
} else {
return _break();
}
@@ -87,9 +89,11 @@
_this.n_out++;
(function(__tame_k) {
if (_this.delay) {
- __tame_deferrals = new tame.Deferrals(__tame_k);
- setTimeout(__tame_deferrals.defer({}), _this.delay);
- __tame_deferrals._fulfill();
+ (function(__tame_k) {
+ __tame_deferrals = new tame.Deferrals(__tame_k);
+ setTimeout(__tame_deferrals.defer({}), _this.delay);
+ __tame_deferrals._fulfill();
+ })(__tame_k);
} else {
return __tame_k();
}
@@ -130,7 +134,7 @@
};
Pipeliner.prototype.flush = function(autocb) {
- var __tame_deferrals, __tame_k, _results, _while,
+ var __tame_deferrals, _results, _while,
_this = this;
__tame_k = autocb;
_results = [];
@@ -147,9 +151,11 @@
return _continue();
};
if (_this.n_out) {
- __tame_deferrals = new tame.Deferrals(__tame_k);
- _this.cb = __tame_deferrals.defer({});
- __tame_deferrals._fulfill();
+ (function(__tame_k) {
+ __tame_deferrals = new tame.Deferrals(__tame_k);
+ _this.cb = __tame_deferrals.defer({});
+ __tame_deferrals._fulfill();
+ })(_next);
} else {
return _break();
}
View
32 src/nodes.coffee
@@ -203,8 +203,10 @@ exports.Base = class Base
new Op '!', this
unwrapAll: ->
+ #console.log "pre #{@toString()}"
node = this
continue until node is node = node.unwrap()
+ #console.log "post #{node.toString()}"
node
# Don't try this at home with actual human kids. Added for tame
@@ -327,9 +329,13 @@ exports.Base = class Base
rv
tameUnwrap: (e) ->
- e.tameContinuationBlock = @tameContinuationBlock
- e.tamePrequels = @tamePrequels
- e
+ if e.tameHasContinuation() and @tameHasContinuation()
+ this
+ else
+ if @tameHasContinuation()
+ e.tameContinuationBlock = @tameContinuationBlock
+ e.tamePrequels = @tamePrequels
+ e
isStatement : NO
jumps : NO
@@ -393,16 +399,25 @@ exports.Block = class Block extends Base
return exp if exp.jumps o
tameThreadReturn: (call) ->
+ call = call || new TameTailCall
len = @expressions.length
foundReturn = false
while len--
expr = @expressions[len]
- if expr.isStatement()
+
+ # If the last expression in the block is either a bonafide statement
+ # or if it's going to be pivoted, then don't thread the return value
+ # through the TameTailCall, just bolt it onto the end.
+ if expr.isStatement() or expr.tameIsCpsPivot()
break
+
+ # In this case, we have a value that we're going to return out
+ # of the block, so apply the TameTamilCall onto the value
if expr not instanceof Comment and expr not instanceof Return
call.assignValue expr
@expressions[len] = call
return
+
# if nothing was found, just push the call on
@expressions.push call
@@ -2667,10 +2682,9 @@ exports.Switch = class Switch extends Base
this
tameCallContinuation : ->
- code = new TameTailCall
for [condition,block] in @cases
- block.push code
- @otherwise?.push code
+ block.tameThreadReturn()
+ @otherwise?.tameThreadReturn()
compileNode: (o) ->
idt1 = o.indent + TAB
@@ -2722,11 +2736,11 @@ exports.If = class If extends Base
# fully nested if { .. } else { if { } ..} ..'s
tameCallContinuation : ->
if @elseBody
- @elseBody.tameThreadReturn new TameTailCall
+ @elseBody.tameThreadReturn()
@isChain = false
else
@addElse new TameTailCall
- @body.tameThreadReturn new TameTailCall
+ @body.tameThreadReturn()
# The **If** only compiles into a statement if either of its bodies needs
# to be a statement. Otherwise a conditional operator is safe.

0 comments on commit dc81455

Please sign in to comment.
Something went wrong with that request. Please try again.