Skip to content

Commit

Permalink
comments and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtaco committed Jan 24, 2012
1 parent 0e8a9df commit d5a9e84
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
20 changes: 10 additions & 10 deletions lib/coffee-script/nodes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 27 additions & 14 deletions src/nodes.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -162,24 +162,14 @@ exports.Base = class Base
continue until node is node = node.unwrap() continue until node is node = node.unwrap()
node node


# Don't try this at home with actually human kids # Don't try this at home with actual human kids
flattenChildren : -> flattenChildren : ->
out = [] out = []
for attr in @children when @[attr] for attr in @children when @[attr]
for child in flatten [@[attr]] for child in flatten [@[attr]]
out.push (child) out.push (child)
out 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 : -> needsRuntime : ->
for child in @flattenChildren() for child in @flattenChildren()
return true if child.needsRuntime() return true if child.needsRuntime()
Expand All @@ -188,11 +178,28 @@ exports.Base = class Base
findTameRequire : -> findTameRequire : ->
for child in @flattenChildren() for child in @flattenChildren()
return r if (r = child.findTameRequire()) 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 # Walk all loops that are marked as "tamed" and mark their children
# as being children in a tamed loop. They'll need more translations # 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) -> walkAstTamedLoop : (flood) ->
flood = true if @isLoop() and @tameNodeFlag flood = true if @isLoop() and @tameNodeFlag
@tameLoopFlag = flood @tameLoopFlag = flood
Expand All @@ -208,6 +215,9 @@ exports.Base = class Base
@cpsPivotFlag = true if child.walkCpsPivots() @cpsPivotFlag = true if child.walkCpsPivots()
@cpsPivotFlag @cpsPivotFlag


#
#-----------------------------------------------------------------------

needsDummyContinuation : -> needsDummyContinuation : ->
if not @gotCpsSplit if not @gotCpsSplit
k_id = new Value new Literal tame.const.k k_id = new Value new Literal tame.const.k
Expand Down Expand Up @@ -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 # We find a pivot if this node has taming, and it's not an Await
# itself # itself
if pivot if pivot
# include the pivot in this slice!
rest = @expressions.slice(i+1) rest = @expressions.slice(i+1)

# Leave the pivot in the list of expressions
@expressions = @expressions.slice(0,i+1) @expressions = @expressions.slice(0,i+1)

# If there are elements in rest, then we need to nest a continuation block
if rest.length if rest.length
child = new Block rest child = new Block rest
pivot.tameNestContinuationBlock child pivot.tameNestContinuationBlock child
Expand Down

0 comments on commit d5a9e84

Please sign in to comment.