Permalink
Browse files

comments and clean up

  • Loading branch information...
maxtaco committed Dec 8, 2011
1 parent 0e8a9df commit d5a9e8480c80bf1025170e98cdc9b0acc7e05694
Showing with 37 additions and 24 deletions.
  1. +10 −10 lib/coffee-script/nodes.js
  2. +27 −14 src/nodes.coffee
View

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

Oops, something went wrong.
View
@@ -162,24 +162,14 @@ exports.Base = class Base
continue until node is node = node.unwrap()
node
- # Don't try this at home with actually human kids
+ # Don't try this at home with actual human kids
flattenChildren : ->
out = []
for attr in @children when @[attr]
for child in flatten [@[attr]]
out.push (child)
out
- # Walk the AST looking for taming. Mark a node as with tame flags
- # if any of its children are tamed, but don't cross scope boundary
- # when considering the children.
- # We consider two types of nodes -- blocks who have a child that's
- # tamed, and all other nodes who have a child that's tamed
- walkAstTame : ->
- for child in @flattenChildren()
- @tameNodeFlag = true if child.walkAstTame()
- @tameNodeFlag
-
needsRuntime : ->
for child in @flattenChildren()
return true if child.needsRuntime()
@@ -188,11 +178,28 @@ exports.Base = class Base
findTameRequire : ->
for child in @flattenChildren()
return r if (r = child.findTameRequire())
- return null
+ return null
+
+ #-----------------------------------------------------------------------
+ # AST Walking Routines for CPS Pivots, etc.
+ #
+ # There are three passes:
+ # 1. Find await's and trace upward.
+ # 2. Find loops found in #1, and flood downward
+ # 3. Find break/continue found in #2, and trace upward
+ #
+
+ # Walk the AST looking for taming. Mark a node as with tame flags
+ # if any of its children are tamed, but don't cross scope boundary
+ # when considering the children.
+ walkAstTame : ->
+ for child in @flattenChildren()
+ @tameNodeFlag = true if child.walkAstTame()
+ @tameNodeFlag
# Walk all loops that are marked as "tamed" and mark their children
# as being children in a tamed loop. They'll need more translations
- # than other nodes. Eventually, "switch" statements might also be "loops
+ # than other nodes. Eventually, "switch" statements might also be "loops"
walkAstTamedLoop : (flood) ->
flood = true if @isLoop() and @tameNodeFlag
@tameLoopFlag = flood
@@ -208,6 +215,9 @@ exports.Base = class Base
@cpsPivotFlag = true if child.walkCpsPivots()
@cpsPivotFlag
+ #
+ #-----------------------------------------------------------------------
+
needsDummyContinuation : ->
if not @gotCpsSplit
k_id = new Value new Literal tame.const.k
@@ -426,9 +436,12 @@ exports.Block = class Block extends Base
# We find a pivot if this node has taming, and it's not an Await
# itself
if pivot
- # include the pivot in this slice!
rest = @expressions.slice(i+1)
+
+ # Leave the pivot in the list of expressions
@expressions = @expressions.slice(0,i+1)
+
+ # If there are elements in rest, then we need to nest a continuation block
if rest.length
child = new Block rest
pivot.tameNestContinuationBlock child

0 comments on commit d5a9e84

Please sign in to comment.