Permalink
Browse files

this is cool, got some more test cases working.

  • Loading branch information...
maxtaco committed Jan 2, 2012
1 parent aeeb2f7 commit 9463080ea68534b66230170401200c723f9fe350
Showing with 50 additions and 17 deletions.
  1. +20 −4 lib/coffee-script/nodes.js
  2. +3 −9 lib/coffee-script/tamelib.js
  3. +17 −4 src/nodes.coffee
  4. +10 −0 test/tame.coffee
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -72,9 +72,7 @@
__tame_deferrals = new tame.Deferrals(__tame_k);
_this.cb = __tame_deferrals.defer({});
__tame_deferrals._fulfill();
- })(function() {
- return _continue();
- });
+ })(_continue);
} else {
return _break();
}
@@ -88,9 +86,7 @@
__tame_deferrals = new tame.Deferrals(__tame_k);
setTimeout(__tame_deferrals.defer({}), _this.delay);
__tame_deferrals._fulfill();
- })(function() {
- return __tame_k();
- });
+ })(__tame_k);
} else {
return __tame_k();
}
@@ -145,9 +141,7 @@
__tame_deferrals = new tame.Deferrals(__tame_k);
_this.cb = __tame_deferrals.defer({});
__tame_deferrals._fulfill();
- })(function() {
- return _continue();
- });
+ })(_continue);
} else {
return _break();
}
View
@@ -350,6 +350,10 @@ exports.Block = class Block extends Base
unwrap: ->
if @expressions.length is 1 then @expressions[0] else this
+ # Like unwrap, but will return if not a single
+ getSingle : ->
+ if @expressions.length is 1 then @expressions[0] else null
+
# Is this an empty block of code?
isEmpty: ->
not @expressions.length
@@ -2699,13 +2703,19 @@ Closure =
CpsCascade =
wrap: (statement, rest, returnValue, o) ->
- func = new Code [ new Param new Literal tame.const.k ], (Block.wrap [ statement ]), 'tamegen'
- block = Block.wrap [ rest ]
+ func = new Code [ new Param new Literal tame.const.k ],
+ (Block.wrap [ statement ]), 'tamegen'
args = []
if returnValue
returnValue.bindName o
args.push returnValue
- cont = new Code args, block, 'tamegen'
+
+ block = Block.wrap [ rest ]
+ cont = if (e = block.getSingle()) and e instanceof TameTailCall and not e.value
+ e.extractFunc()
+ else
+ new Code args, block, 'tamegen'
+
call = new Call func, [ cont ]
new Block [ call ]
@@ -2724,8 +2734,11 @@ class TameTailCall extends Base
assignValue : (v) ->
@value = v
+ literalFunc: -> new Literal @func
+ extractFunc: -> new Value @literalFunc()
+
compileNode : (o) ->
- f = new Literal @func
+ f = @literalFunc()
out = if o.level is LEVEL_TOP
if @value
new Block [ @value, new Call f ]
View
@@ -364,6 +364,16 @@ atest 'test expressions -- simple, but recursive (2)', (cb) ->
x = await adder 4, defer _
++x
cb(y == 6, {})
+
+atest 'test expressions -- simple, but recursive (3)', (cb) ->
+ adder = (x, cb) ->
+ await delay defer()
+ cb(x+1)
+ y = if true
+ await adder 5, defer _
+ cb(y == 6, {})
+
+#atest 'arrays and objects', (cb) ->
#atest 'arrays and objects', (cb) ->
# id = "image data"

0 comments on commit 9463080

Please sign in to comment.