Permalink
Browse files

Various renames, in preparation for pull request

  • Loading branch information...
1 parent 1adf300 commit 849cd98f32df517617ebfa3fef9a04b930bd2e3d @maxtaco committed Dec 13, 2011
Showing with 92 additions and 88 deletions.
  1. +45 −43 lib/coffee-script/nodes.js
  2. +47 −45 src/nodes.coffee
View
88 lib/coffee-script/nodes.js
@@ -210,74 +210,74 @@
return out;
};
- Base.prototype.needsRuntime = function() {
+ Base.prototype.tameNeedsRuntime = function() {
var child, _i, _len, _ref2;
_ref2 = this.flattenChildren();
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
child = _ref2[_i];
- if (child.needsRuntime()) return true;
+ if (child.tameNeedsRuntime()) return true;
}
return false;
};
- Base.prototype.findTameRequire = function() {
+ Base.prototype.tameFindRequire = function() {
var child, r, _i, _len, _ref2;
_ref2 = this.flattenChildren();
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
child = _ref2[_i];
- if ((r = child.findTameRequire())) return r;
+ if ((r = child.tameFindRequire())) return r;
}
return null;
};
- Base.prototype.markAutocbs = function(found) {
+ Base.prototype.tameMarkAutocbs = function(found) {
var child, _i, _len, _ref2, _results;
this.hasAutocb = found;
_ref2 = this.flattenChildren();
_results = [];
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
child = _ref2[_i];
- _results.push(child.markAutocbs(found));
+ _results.push(child.tameMarkAutocbs(found));
}
return _results;
};
- Base.prototype.walkAstTame = function() {
+ Base.prototype.tameWalkAst = function() {
var child, _i, _len, _ref2;
_ref2 = this.flattenChildren();
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
child = _ref2[_i];
- if (child.walkAstTame()) this.tameNodeFlag = true;
+ if (child.tameWalkAst()) this.tameNodeFlag = true;
}
return this.tameNodeFlag;
};
- Base.prototype.walkAstTamedLoop = function(flood) {
+ Base.prototype.tameWalkAstLoops = function(flood) {
var child, _i, _len, _ref2;
if (this.isLoop() && this.tameNodeFlag) flood = true;
this.tameLoopFlag = flood;
_ref2 = this.flattenChildren();
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
child = _ref2[_i];
- if (child.walkAstTamedLoop(flood)) this.tameLoopFlag = true;
+ if (child.tameWalkAstLoops(flood)) this.tameLoopFlag = true;
}
return this.tameLoopFlag;
};
- Base.prototype.walkCpsPivots = function() {
+ Base.prototype.tameWalkCpsPivots = function() {
var child, _i, _len, _ref2;
if (this.tameNodeFlag || (this.tameLoopFlag && this.isJump())) {
this.cpsPivotFlag = true;
}
_ref2 = this.flattenChildren();
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
child = _ref2[_i];
- if (child.walkCpsPivots()) this.cpsPivotFlag = true;
+ if (child.tameWalkCpsPivots()) this.cpsPivotFlag = true;
}
return this.cpsPivotFlag;
};
- Base.prototype.needsDummyContinuation = function() {
+ Base.prototype.tameNeedsDummyContinuation = function() {
var empty, k_id;
if (!this.gotCpsSplit) {
k_id = new Value(new Literal(tame["const"].k));
@@ -290,17 +290,17 @@
Base.prototype.tameContinuationBlock = null;
- Base.prototype.cpsRotate = function() {
+ Base.prototype.tameCpsRotate = function() {
var child, _i, _len, _ref2;
_ref2 = this.flattenChildren();
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
child = _ref2[_i];
- child.cpsRotate();
+ child.tameCpsRotate();
}
return this;
};
- Base.prototype.isCpsPivot = function() {
+ Base.prototype.tameIsCpsPivot = function() {
return this.cpsPivotFlag;
};
@@ -552,16 +552,16 @@
return code + post;
};
- Block.prototype.cpsRotate = function() {
+ Block.prototype.tameCpsRotate = function() {
var child, e, i, pivot, rest, _i, _j, _len, _len2, _ref2;
pivot = null;
child = null;
- if (this.isCpsPivot()) {
+ if (this.tameIsCpsPivot()) {
i = 0;
_ref2 = this.expressions;
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
e = _ref2[_i];
- if (e.isCpsPivot()) {
+ if (e.tameIsCpsPivot()) {
pivot = e;
break;
}
@@ -581,11 +581,11 @@
if (e.cpsPivotFlag) child.cpsPivotFlag = true;
if (e.hasAutocb) child.hasAutocb = true;
}
- child.cpsRotate();
+ child.tameCpsRotate();
}
pivot.callContinuation();
}
- Block.__super__.cpsRotate.call(this);
+ Block.__super__.tameCpsRotate.call(this);
return this;
};
@@ -599,17 +599,19 @@
return ((_ref2 = this.expressions) != null ? _ref2.length : void 0) === 1 && this.expressions[0] instanceof Await;
};
- Block.prototype.addRuntime = function() {
+ Block.prototype.tameAddRuntime = function() {
return this.expressions.unshift(new TameRequire());
};
Block.prototype.tameTransform = function() {
- this.walkAstTame();
- if (this.needsRuntime() && !this.findTameRequire()) this.addRuntime();
- this.walkAstTamedLoop(false);
- this.walkCpsPivots();
- this.markAutocbs();
- this.cpsRotate();
+ this.tameWalkAst();
+ if (this.tameNeedsRuntime() && !this.tameFindRequire()) {
+ this.tameAddRuntime();
+ }
+ this.tameWalkAstLoops(false);
+ this.tameWalkCpsPivots();
+ this.tameMarkAutocbs();
+ this.tameCpsRotate();
return this;
};
@@ -1726,7 +1728,7 @@
Code.prototype.jumps = NO;
- Code.prototype.markAutocbs = function(found) {
+ Code.prototype.tameMarkAutocbs = function(found) {
var p, _i, _len, _ref2;
found = false;
_ref2 = this.params;
@@ -1738,7 +1740,7 @@
}
}
if (found && this.body.isOnlyAwait()) this.body.push(new Return(null, true));
- return Code.__super__.markAutocbs.call(this, found);
+ return Code.__super__.tameMarkAutocbs.call(this, found);
};
Code.prototype.compileNode = function(o) {
@@ -1831,20 +1833,20 @@
}
};
- Code.prototype.walkAstTame = function() {
- if (Code.__super__.walkAstTame.call(this)) this.tameNodeFlag = true;
+ Code.prototype.tameWalkAst = function() {
+ if (Code.__super__.tameWalkAst.call(this)) this.tameNodeFlag = true;
return false;
};
- Code.prototype.walkAstTamedLoop = function(flood) {
- if (Code.__super__.walkAstTamedLoop.call(this, false)) {
+ Code.prototype.tameWalkAstLoops = function(flood) {
+ if (Code.__super__.tameWalkAstLoops.call(this, false)) {
this.tameLoopFlag = true;
}
return false;
};
- Code.prototype.walkCpsPivots = function() {
- Code.__super__.walkCpsPivots.call(this);
+ Code.prototype.tameWalkCpsPivots = function() {
+ Code.__super__.tameWalkCpsPivots.call(this);
return this.cpsPivotFlag = false;
};
@@ -2025,7 +2027,7 @@
top_statements = [];
if (d.init) top_statements = top_statements.concat(d.init);
top_statements = top_statements.concat([top_assign, top_call]);
- if (k = this.needsDummyContinuation()) top_statements.unshift(k);
+ if (k = this.tameNeedsDummyContinuation()) top_statements.unshift(k);
return top_block = new Block(top_statements);
};
@@ -2413,7 +2415,7 @@
return call.compile(o);
};
- Defer.prototype.needsRuntime = function() {
+ Defer.prototype.tameNeedsRuntime = function() {
return true;
};
@@ -2440,7 +2442,7 @@
rhs = new Op("new", call);
assign = new Assign(lhs, rhs);
body.unshift(assign);
- if (k = this.needsDummyContinuation()) body.unshift(k);
+ if (k = this.tameNeedsDummyContinuation()) body.unshift(k);
meth = lhs.copy().add(new Access(new Value(new Literal(tame["const"].fulfill))));
call = new Call(meth, []);
body.push(call);
@@ -2460,8 +2462,8 @@
return this.body.compile(o);
};
- Await.prototype.walkAstTame = function() {
- Await.__super__.walkAstTame.call(this);
+ Await.prototype.tameWalkAst = function() {
+ Await.__super__.tameWalkAst.call(this);
return this.tameNodeFlag = true;
};
@@ -2507,7 +2509,7 @@
children = ['typ'];
- TameRequire.prototype.findTameRequire = function() {
+ TameRequire.prototype.tameFindRequire = function() {
return this;
};
@@ -3001,7 +3003,7 @@
};
If.prototype.compileNode = function(o) {
- if (this.isStatement(o || this.isCpsPivot())) {
+ if (this.isStatement(o || this.tameIsCpsPivot())) {
return this.compileStatement(o);
} else {
return this.compileExpression(o);
View
92 src/nodes.coffee
@@ -125,8 +125,9 @@ exports.Base = class Base
#
# Add some Tame-specific additions --- the 'A' flag if this node
# is an await or its ancestor; the 'L' flag, if this node is a tamed
- # loop or its descendant; and a 'P' flag if this node is going to be
- # a 'pivot' in the CPS tree rotation.
+ # loop or its descendant; a 'P' flag if this node is going to be
+ # a 'pivot' in the CPS tree rotation; a 'C' flag if this node is inside
+ # a function with an autocb.
#
toString: (idt = '', name = @constructor.name) ->
extras = ""
@@ -167,30 +168,31 @@ exports.Base = class Base
continue until node is node = node.unwrap()
node
- # Don't try this at home with actual human kids
+ # Don't try this at home with actual human kids. Added for tame
+ # for slightly different tree traversal mechanics.
flattenChildren : ->
out = []
for attr in @children when @[attr]
for child in flatten [@[attr]]
out.push (child)
out
- # needsRuntime, findTameRequires and markAutocbs are
+ # tameNeedsRuntime, tameFindRequires and tameMarkAutocbs are
# various traversals of the AST for tame attributes
- needsRuntime : ->
+ tameNeedsRuntime : ->
for child in @flattenChildren()
- return true if child.needsRuntime()
+ return true if child.tameNeedsRuntime()
return false
- findTameRequire : ->
+ tameFindRequire : ->
for child in @flattenChildren()
- return r if (r = child.findTameRequire())
+ return r if (r = child.tameFindRequire())
return null
- markAutocbs : (found) ->
+ tameMarkAutocbs : (found) ->
@hasAutocb = found
for child in @flattenChildren()
- child.markAutocbs(found)
+ child.tameMarkAutocbs(found)
#
# AST Walking Routines for CPS Pivots, etc.
@@ -200,37 +202,37 @@ exports.Base = class Base
# 2. Find loops found in #1, and flood downward
# 3. Find break/continue found in #2, and trace upward
#
- # walkAstTame
+ # tameWalkAst
# 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 : ->
+ tameWalkAst : ->
for child in @flattenChildren()
- @tameNodeFlag = true if child.walkAstTame()
+ @tameNodeFlag = true if child.tameWalkAst()
@tameNodeFlag
- # walkAstTamedLoop
+ # tameWalkAstLoops
# 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"
- walkAstTamedLoop : (flood) ->
+ tameWalkAstLoops : (flood) ->
flood = true if @isLoop() and @tameNodeFlag
@tameLoopFlag = flood
for child in @flattenChildren()
- @tameLoopFlag = true if child.walkAstTamedLoop flood
+ @tameLoopFlag = true if child.tameWalkAstLoops flood
@tameLoopFlag
- # walkCpsPivots
+ # tameWalkCpsPivots
# A node is marked as a "cpsPivot" of it is (a) a 'tamed' node,
# (b) a jump node in a tamed while loop; or (c) an ancestor of (a) or (b).
- walkCpsPivots : ->
+ tameWalkCpsPivots : ->
@cpsPivotFlag = true if @tameNodeFlag or (@tameLoopFlag and @isJump())
for child in @flattenChildren()
- @cpsPivotFlag = true if child.walkCpsPivots()
+ @cpsPivotFlag = true if child.tameWalkCpsPivots()
@cpsPivotFlag
- needsDummyContinuation : ->
+ tameNeedsDummyContinuation : ->
if not @gotCpsSplit
k_id = new Value new Literal tame.const.k
empty = new Code [], new Block []
@@ -244,12 +246,12 @@ exports.Base = class Base
tameContinuationBlock : null
# A generic tame AST rotation is just to push down to its children
- cpsRotate: ->
+ tameCpsRotate: ->
for child in @flattenChildren()
- child.cpsRotate()
+ child.tameCpsRotate()
this
- isCpsPivot : -> @cpsPivotFlag
+ tameIsCpsPivot : -> @cpsPivotFlag
tameNestContinuationBlock : (b) ->
@tameContinuationBlock = b
@@ -434,22 +436,22 @@ exports.Block = class Block extends Base
code + post
#
- # cpsRotate -- This is the key abstract syntax tree rotation of the
+ # tameCpsRotate -- This is the key abstract syntax tree rotation of the
# CPS translation. Take a block with a bunch of sequential statements
# and "pivot" the AST on the first available pivot. The expressions
# on the LHS of the pivot stay where the are. The expressions on the RHS
# of the pivot become the pivot's continuation. And the process is applied
# recursively.
#
- cpsRotate : ->
+ tameCpsRotate : ->
pivot = null
child = null
# If this Block has taming, then we go ahead and look for a pivot
- if @isCpsPivot()
+ if @tameIsCpsPivot()
i = 0
for e in @expressions
- if e.isCpsPivot()
+ if e.tameIsCpsPivot()
pivot = e
break
i++
@@ -477,7 +479,7 @@ exports.Block = class Block extends Base
# now recursive apply the transformation to the new child,
# this being especially import in blocks that have multiple
# awaits on the same level
- child.cpsRotate()
+ child.tameCpsRotate()
# The pivot value needs to call the currently active continuation
# after it's all done. For things like if..else.. this does something
@@ -503,17 +505,17 @@ exports.Block = class Block extends Base
isOnlyAwait : ->
return @expressions?.length == 1 and @expressions[0] instanceof Await
- addRuntime : ->
+ tameAddRuntime : ->
@expressions.unshift new TameRequire()
# Perform all steps of the Tame transform
tameTransform : ->
- @walkAstTame()
- @addRuntime() if @needsRuntime() and not @findTameRequire()
- @walkAstTamedLoop(false)
- @walkCpsPivots()
- @markAutocbs()
- @cpsRotate()
+ @tameWalkAst()
+ @tameAddRuntime() if @tameNeedsRuntime() and not @tameFindRequire()
+ @tameWalkAstLoops(false)
+ @tameWalkCpsPivots()
+ @tameMarkAutocbs()
+ @tameCpsRotate()
this
#### Literal
@@ -1407,7 +1409,7 @@ exports.Code = class Code extends Base
jumps: NO
- markAutocbs: (found) ->
+ tameMarkAutocbs: (found) ->
found = false
for p in @params
if p.name instanceof Literal and p.name.value == tame.const.autocb
@@ -1488,15 +1490,15 @@ exports.Code = class Code extends Base
# we are taming as a feature of all of our children. However, if we
# are tamed, it's not the case that our parent is tamed!
- walkAstTame : ->
+ tameWalkAst : ->
@tameNodeFlag = true if super()
false
- walkAstTamedLoop : (flood) ->
+ tameWalkAstLoops : (flood) ->
@tameLoopFlag = true if super(false)
false
- walkCpsPivots: ->
+ tameWalkCpsPivots: ->
super()
@cpsPivotFlag = false
@@ -1659,7 +1661,7 @@ exports.While = class While extends Base
top_statements = []
top_statements = top_statements.concat d.init if d.init
top_statements = top_statements.concat [ top_assign, top_call ]
- if k = @needsDummyContinuation()
+ if k = @tameNeedsDummyContinuation()
top_statements.unshift k
top_block = new Block top_statements
@@ -1995,7 +1997,7 @@ exports.Defer = class Defer extends Base
scope.add name, 'var'
call.compile o
- needsRuntime : -> true
+ tameNeedsRuntime : -> true
#### Await
@@ -2014,7 +2016,7 @@ exports.Await = class Await extends Base
rhs = new Op "new", call
assign = new Assign lhs, rhs
body.unshift assign
- if k = @needsDummyContinuation()
+ if k = @tameNeedsDummyContinuation()
body.unshift (k)
meth = lhs.copy().add new Access new Value new Literal tame.const.fulfill
call = new Call meth, []
@@ -2034,7 +2036,7 @@ exports.Await = class Await extends Base
# We still need to walk our children to see if there are any embedded
# function which might also be tamed. But we're always going to report
# to our parent that we are tamed, since we are!
- walkAstTame : ->
+ tameWalkAst : ->
super()
@tameNodeFlag = true
@@ -2078,7 +2080,7 @@ exports.TameRequire = class TameRequire extends Base
children = [ 'typ']
- findTameRequire: -> this
+ tameFindRequire: -> this
#### Try
@@ -2470,7 +2472,7 @@ exports.If = class If extends Base
jumps: (o) -> @body.jumps(o) or @elseBody?.jumps(o)
compileNode: (o) ->
- if @isStatement o or @isCpsPivot() then @compileStatement o else @compileExpression o
+ if @isStatement o or @tameIsCpsPivot() then @compileStatement o else @compileExpression o
makeReturn: (res) ->
@elseBody or= new Block [new Literal 'void 0'] if res

0 comments on commit 849cd98

Please sign in to comment.