Permalink
Browse files

totally busted, can't figure out this bug.

  • Loading branch information...
1 parent 9463080 commit 88f9dedf4dbf5f892f86503e36f047aa84fb1165 @maxtaco committed Jan 2, 2012
Showing with 92 additions and 54 deletions.
  1. +41 −25 lib/coffee-script/nodes.js
  2. +41 −24 src/nodes.coffee
  3. +10 −5 test/tame.coffee
View

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

Oops, something went wrong.
View
@@ -69,19 +69,25 @@ exports.Base = class Base
# 'this'.
compileCps : (o) ->
@tameGotCpsSplitFlag = true
- if @tamePrequelBlock
- first = @tamePrequelBlock
+
+ if (l = @tamePrequelBlocks.length)
+ console.log "yo"
if @tameContinuationBlock
- second = @tameContinuationBlock
- second.unshift this
+ k = @tameContinuationBlock
+ k.unshift this
else
- second = this
+ k = this
+
+ while l--
+ console.log "yuck"
+ pb = @tamePrequelBlocks[l]
+ k = CpsCascade.wrap pb.block, k, pb.retval, o
+ code = k
+
else
- first = this
- second = @tameContinuationBlock
- node = CpsCascade.wrap(first, second, @tameReturnValue, o)
- ret = node.compile o
- ret
+ code = CpsCascade.wrap this, @tameContinuationBlock, null, o
+
+ code.compile o
# If the code generation wishes to use the result of a complex expression
# in multiple places, ensure that the expression is only ever evaluated once,
@@ -155,10 +161,10 @@ exports.Base = class Base
tree = '\n' + idt + name
tree += '?' if @soak
tree += extras
- if @tamePrequelBlock
+ for b in @tamePrequelBlocks
pidt = idt + TAB
tree += '\n' + pidt + "Prequel"
- tree += @tamePrequelBlock.toString pidt + TAB
+ tree += b.block.toString pidt + TAB
@eachChild (node) -> tree += node.toString idt + TAB
if @tameContinuationBlock
idt += TAB
@@ -270,7 +276,7 @@ exports.Base = class Base
# A potential for a nested tame continuation here
tameContinuationBlock : null
- tamePrequelBlock : null
+ tamePrequelBlocks : []
# A generic tame AST rotation is just to push down to its children
tameCpsRotate: ->
@@ -286,17 +292,23 @@ exports.Base = class Base
v.tameCpsRotate() # do our children first, regardless...
if doRotate
@tameNestPrequelBlock v
- @tameReturnValue = new TameReturnValue()
else
null
tameIsCpsPivot : -> @tameCpsPivotFlag
tameNestContinuationBlock : (b) -> @tameContinuationBlock = b
- tameNestPrequelBlock : (b) -> @tamePrequelBlock = b
- tameHasContinuation : -> !!@tameContinuationBlock || !!@tamePrequelBlock
+ tameHasContinuation : -> (!!@tameContinuationBlock or @tamePrequelBlocks.length)
tameCallContinuation : ->
tameIsJump : NO
tameIsTamedExpr : -> (this not instanceof Code) and @tameNodeFlag
+ tameNestPrequelBlock: (bb) ->
+ console.log "call with #{bb.toString()}"
+ rv = new TameReturnValue()
+ console.log "trv done #{bb.toString()}"
+ @tamePrequelBlocks.push { block : bb, retval : rv }
+ console.log "call done #{bb}"
+ console.log "len: #{@tamePrequelBlocks.length} #{bb.toString()}"
+ rv
isStatement : NO
jumps : NO
@@ -381,11 +393,6 @@ exports.Block = class Block extends Base
# if nothing was found, just push the call on
@expressions.push call
- # Optimization!
- # Blocks typically don't need their own cpsCascading. This saves
- # wasted code.
- compileCps : (o) ->
-
# A Block node does not return its entire body, rather it
# ensures that the final expression is returned.
makeReturn: (res) ->
@@ -1861,6 +1868,11 @@ exports.Op = class Op extends Base
isChainable: ->
@operator in ['<', '>', '>=', '<=', '===', '!==']
+ # this is F'ed up!!
+ #tameCpsRotate : ->
+ # @first = nv if @first and (nv = @tameCpsExprRotate @first)
+ # @second = nv if @second and (nv = @tameCpsExprRotate @second)
+
invert: ->
if @isChainable() and @first.isChainable()
allInvertable = yes
@@ -2711,10 +2723,15 @@ CpsCascade =
args.push returnValue
block = Block.wrap [ rest ]
- cont = if (e = block.getSingle()) and e instanceof TameTailCall and not e.value
- e.extractFunc()
+
+ # This is both for optimization and for correctness. If the continuation
+ # block is just a tail call to another continuation, then we just pass
+ # that call directly. This will also thread values through the
+ # call chain.
+ if (e = block.getSingle()) and e instanceof TameTailCall and not e.value
+ cont = e.extractFunc()
else
- new Code args, block, 'tamegen'
+ cont = new Code args, block, 'tamegen'
call = new Call func, [ cont ]
new Block [ call ]
View
@@ -343,20 +343,20 @@ atest "until", (cb) ->
out += i--
cb(out is 55, {})
-atest 'tame expressions -- simple assignment', (cb) ->
+atest 'expressions -- simple assignment', (cb) ->
adder = (x, cb) ->
await delay defer()
cb(x+1)
ret = await adder 5, defer _
cb(ret == 6, {})
-atest 'test expressions -- simple, but recursive', (cb) ->
+atest 'expressions -- simple, but recursive', (cb) ->
y = if true
await delay defer()
10
cb(y == 10, {})
-atest 'test expressions -- simple, but recursive (2)', (cb) ->
+atest 'expressions -- simple, but recursive (2)', (cb) ->
adder = (x, cb) ->
await delay defer()
cb(x+1)
@@ -365,15 +365,20 @@ atest 'test expressions -- simple, but recursive (2)', (cb) ->
++x
cb(y == 6, {})
-atest 'test expressions -- simple, but recursive (3)', (cb) ->
+atest 'expressions -- pass value of tail calls', (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 'expressions -- addition', (cb) ->
+ slowAdd = (a, b, autocb) ->
+ await delay defer()
+ a+b
+ y = (await slowAdd 10, 20, defer _) + (await slowAdd 30, 40, defer _)
+ cb(y == 100, {})
#atest 'arrays and objects', (cb) ->
# id = "image data"

0 comments on commit 88f9ded

Please sign in to comment.