Permalink
Browse files

a lot more renaming, to make it clear what's tame-related

  • Loading branch information...
1 parent 849cd98 commit 0a43c2ad455f91cba7468bbe23fe1975030cf73f @maxtaco committed Dec 13, 2011
Showing with 75 additions and 82 deletions.
  1. +37 −43 lib/coffee-script/nodes.js
  2. +38 −39 src/nodes.coffee
View
80 lib/coffee-script/nodes.js
@@ -1,5 +1,5 @@
(function() {
- var Access, Arr, Assign, Await, Base, Block, CALL_CONTINUATION, Call, Class, Closure, Code, Comment, CpsCascade, Defer, Existence, Extends, For, IDENTIFIER, IDENTIFIER_STR, IS_STRING, If, In, Index, InlineDeferral, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, METHOD_DEF, NEGATE, NO, Obj, Op, Param, Parens, RESERVED, Range, Return, SIMPLENUM, Scope, Slice, Slot, Splat, Switch, TAB, THIS, TameRequire, Throw, Try, UTILITIES, Value, While, YES, compact, del, ends, extend, flatten, last, merge, multident, starts, tame, unfoldSoak, utility, _ref,
+ var Access, Arr, Assign, Await, Base, Block, Call, Class, Closure, Code, Comment, CpsCascade, Defer, Existence, Extends, For, IDENTIFIER, IDENTIFIER_STR, IS_STRING, If, In, Index, InlineDeferral, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, METHOD_DEF, NEGATE, NO, Obj, Op, Param, Parens, RESERVED, Range, Return, SIMPLENUM, Scope, Slice, Slot, Splat, Switch, TAB, TAME_CALL_CONTINUATION, THIS, TameRequire, Throw, Try, UTILITIES, Value, While, YES, compact, del, ends, extend, flatten, last, merge, multident, starts, tame, unfoldSoak, utility, _ref,
__hasProp = Object.prototype.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; },
__indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (__hasProp.call(this, i) && this[i] === item) return i; } return -1; };
@@ -31,7 +31,7 @@
return this;
};
- CALL_CONTINUATION = function() {
+ TAME_CALL_CONTINUATION = function() {
return new Call(new Literal(tame["const"].k, []));
};
@@ -45,7 +45,7 @@
if (lvl) o.level = lvl;
node = this.unfoldSoak(o) || this;
node.tab = o.indent;
- if (node.hasContinuation() && !node.gotCpsSplit && node.isStatement(o)) {
+ if (node.tameHasContinuation() && !node.tameGotCpsSplitFlag && node.isStatement(o)) {
return node.compileCps(o);
} else if (o.level === LEVEL_TOP || !node.isStatement(o)) {
return node.compileNode(o);
@@ -64,7 +64,7 @@
Base.prototype.compileCps = function(o) {
var node, ret;
- this.gotCpsSplit = true;
+ this.tameGotCpsSplitFlag = true;
node = CpsCascade.wrap(this, this.tameContinuationBlock);
ret = node.compile(o);
return ret;
@@ -101,7 +101,7 @@
if (res) {
return new Call(new Literal("" + res + ".push"), [me]);
} else {
- return new Return(me, this.hasAutocb);
+ return new Return(me, this.tameHasAutocbFlag);
}
};
@@ -139,8 +139,8 @@
extras = "";
if (this.tameNodeFlag) extras += "A";
if (this.tameLoopFlag) extras += "L";
- if (this.cpsPivotFlag) extras += "P";
- if (this.hasAutocb) extras += "C";
+ if (this.tameCpsPivotFlag) extras += "P";
+ if (this.tameHasAutocbFlag) extras += "C";
if (extras.length) extras = " (" + extras + ")";
tree = '\n' + idt + name;
if (this.soak) tree += '?';
@@ -232,7 +232,7 @@
Base.prototype.tameMarkAutocbs = function(found) {
var child, _i, _len, _ref2, _results;
- this.hasAutocb = found;
+ this.tameHasAutocbFlag = found;
_ref2 = this.flattenChildren();
_results = [];
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
@@ -266,20 +266,20 @@
Base.prototype.tameWalkCpsPivots = function() {
var child, _i, _len, _ref2;
- if (this.tameNodeFlag || (this.tameLoopFlag && this.isJump())) {
- this.cpsPivotFlag = true;
+ if (this.tameNodeFlag || (this.tameLoopFlag && this.tameIsJump())) {
+ this.tameCpsPivotFlag = true;
}
_ref2 = this.flattenChildren();
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
child = _ref2[_i];
- if (child.tameWalkCpsPivots()) this.cpsPivotFlag = true;
+ if (child.tameWalkCpsPivots()) this.tameCpsPivotFlag = true;
}
- return this.cpsPivotFlag;
+ return this.tameCpsPivotFlag;
};
Base.prototype.tameNeedsDummyContinuation = function() {
var empty, k_id;
- if (!this.gotCpsSplit) {
+ if (!this.tameGotCpsSplitFlag) {
k_id = new Value(new Literal(tame["const"].k));
empty = new Code([], new Block([]));
return new Assign(k_id, empty);
@@ -301,18 +301,18 @@
};
Base.prototype.tameIsCpsPivot = function() {
- return this.cpsPivotFlag;
+ return this.tameCpsPivotFlag;
};
Base.prototype.tameNestContinuationBlock = function(b) {
return this.tameContinuationBlock = b;
};
- Base.prototype.hasContinuation = function() {
+ Base.prototype.tameHasContinuation = function() {
return this.tameContinuationBlock;
};
- Base.prototype.callContinuation = function() {};
+ Base.prototype.tameCallContinuation = function() {};
Base.prototype.isStatement = NO;
@@ -326,23 +326,19 @@
Base.prototype.isControlBreak = NO;
- Base.prototype.isTamedFunc = NO;
-
Base.prototype.isLoop = NO;
- Base.prototype.isAwait = NO;
-
- Base.prototype.isJump = NO;
+ Base.prototype.tameIsJump = NO;
Base.prototype.tameLoopFlag = false;
Base.prototype.tameNodeFlag = false;
- Base.prototype.gotCpsSplit = false;
+ Base.prototype.tameGotCpsSplitFlag = false;
- Base.prototype.cpsPivotFlag = false;
+ Base.prototype.tameCpsPivotFlag = false;
- Base.prototype.hasAutocb = false;
+ Base.prototype.tameHasAutocbFlag = false;
Base.prototype.unwrap = THIS;
@@ -415,7 +411,7 @@
expr = this.expressions[len];
if (!(expr instanceof Comment)) {
this.expressions[len] = expr.makeReturn(res);
- if (expr instanceof Return && !expr.expression && !expr.hasAutocb) {
+ if (expr instanceof Return && !expr.expression && !expr.tameHasAutocbFlag) {
this.expressions.splice(len, 1);
}
break;
@@ -425,7 +421,7 @@
};
Block.prototype.compileCps = function(o) {
- this.gotCpsSplit = true;
+ this.tameGotCpsSplitFlag = true;
if (this.expressions.length > 1) {
return Block.__super__.compileCps.call(this, o);
} else {
@@ -578,12 +574,12 @@
e = rest[_j];
if (e.tameNodeFlag) child.tameNodeFlag = true;
if (e.tameLoopFlag) child.tameLoopFlag = true;
- if (e.cpsPivotFlag) child.cpsPivotFlag = true;
- if (e.hasAutocb) child.hasAutocb = true;
+ if (e.tameCpsPivotFlag) child.tameCpsPivotFlag = true;
+ if (e.tameHasAutocbFlag) child.tameHasAutocbFlag = true;
}
child.tameCpsRotate();
}
- pivot.callContinuation();
+ pivot.tameCallContinuation();
}
Block.__super__.tameCpsRotate.call(this);
return this;
@@ -645,7 +641,7 @@
Literal.prototype.isComplex = NO;
- Literal.prototype.isJump = function() {
+ Literal.prototype.tameIsJump = function() {
return this.isStatement();
};
@@ -674,7 +670,7 @@
Literal.prototype.compileNode = function(o) {
var code, _ref2, _ref3;
- code = this.isUndefined ? o.level >= LEVEL_ACCESS ? '(void 0)' : 'void 0' : this.value === 'this' ? ((_ref2 = o.scope.method) != null ? _ref2.bound : void 0) ? o.scope.method.context : this.value : this.value.reserved && ((_ref3 = "" + this.value) !== 'eval' && _ref3 !== 'arguments') ? "\"" + this.value + "\"" : this.tameLoopFlag && this.isJump() ? this.compileTame(o) : this.value;
+ code = this.isUndefined ? o.level >= LEVEL_ACCESS ? '(void 0)' : 'void 0' : this.value === 'this' ? ((_ref2 = o.scope.method) != null ? _ref2.bound : void 0) ? o.scope.method.context : this.value : this.value.reserved && ((_ref3 = "" + this.value) !== 'eval' && _ref3 !== 'arguments') ? "\"" + this.value + "\"" : this.tameLoopFlag && this.tameIsJump() ? this.compileTame(o) : this.value;
if (this.isStatement()) {
return "" + this.tab + code + ";";
} else {
@@ -693,8 +689,8 @@
__extends(Return, Base);
- function Return(expr, hasAutocb) {
- this.hasAutocb = hasAutocb;
+ function Return(expr, tameHasAutocbFlag) {
+ this.tameHasAutocbFlag = tameHasAutocbFlag;
if (expr && !expr.unwrap().isUndefined) this.expression = expr;
}
@@ -718,7 +714,7 @@
Return.prototype.compileNode = function(o) {
var args, block, call, cb, ret;
- if (this.hasAutocb) {
+ if (this.tameHasAutocbFlag) {
cb = new Value(new Literal(tame["const"].autocb));
args = this.expression ? [this.expression] : [];
call = new Call(cb, args);
@@ -1847,7 +1843,7 @@
Code.prototype.tameWalkCpsPivots = function() {
Code.__super__.tameWalkCpsPivots.call(this);
- return this.cpsPivotFlag = false;
+ return this.tameCpsPivotFlag = false;
};
return Code;
@@ -2031,7 +2027,7 @@
return top_block = new Block(top_statements);
};
- While.prototype.callContinuation = function() {
+ While.prototype.tameCallContinuation = function() {
var k;
k = new Call(new Literal(tame["const"].c_while, []));
return this.body.push(k);
@@ -2453,8 +2449,6 @@
Await.prototype.isStatement = YES;
- Await.prototype.isAwait = YES;
-
Await.prototype.makeReturn = THIS;
Await.prototype.compileNode = function(o) {
@@ -2903,9 +2897,9 @@
return this;
};
- Switch.prototype.callContinuation = function() {
+ Switch.prototype.tameCallContinuation = function() {
var block, code, condition, _i, _len, _ref2, _ref3, _ref4;
- code = CALL_CONTINUATION();
+ code = TAME_CALL_CONTINUATION();
_ref2 = this.cases;
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
_ref3 = _ref2[_i], condition = _ref3[0], block = _ref3[1];
@@ -2980,9 +2974,9 @@
return this;
};
- If.prototype.callContinuation = function() {
+ If.prototype.tameCallContinuation = function() {
var code;
- code = CALL_CONTINUATION();
+ code = TAME_CALL_CONTINUATION();
if (this.elseBody) {
this.elseBody.push(code);
this.isChain = false;
@@ -2994,7 +2988,7 @@
If.prototype.isStatement = function(o) {
var _ref2;
- return (o != null ? o.level : void 0) === LEVEL_TOP || this.bodyNode().isStatement(o) || ((_ref2 = this.elseBodyNode()) != null ? _ref2.isStatement(o) : void 0) || this.hasContinuation();
+ return (o != null ? o.level : void 0) === LEVEL_TOP || this.bodyNode().isStatement(o) || ((_ref2 = this.elseBodyNode()) != null ? _ref2.isStatement(o) : void 0) || this.tameHasContinuation();
};
If.prototype.jumps = function(o) {
View
77 src/nodes.coffee
@@ -19,7 +19,7 @@ NO = -> no
THIS = -> this
NEGATE = -> @negated = not @negated; this
-CALL_CONTINUATION = -> new Call(new Literal tame.const.k, [])
+TAME_CALL_CONTINUATION = -> new Call(new Literal tame.const.k, [])
#### Base
@@ -45,7 +45,7 @@ exports.Base = class Base
o.level = lvl if lvl
node = @unfoldSoak(o) or this
node.tab = o.indent
- if node.hasContinuation() and not node.gotCpsSplit and node.isStatement(o)
+ if node.tameHasContinuation() and not node.tameGotCpsSplitFlag and node.isStatement(o)
node.compileCps o
else if o.level is LEVEL_TOP or not node.isStatement(o)
node.compileNode o
@@ -63,7 +63,7 @@ exports.Base = class Base
# Statements that need CPS translation will have to be split into two
# pieces as so
compileCps : (o) ->
- @gotCpsSplit = true
+ @tameGotCpsSplitFlag = true
node = CpsCascade.wrap(this, @tameContinuationBlock)
ret = node.compile o
ret
@@ -95,7 +95,7 @@ exports.Base = class Base
if res
new Call new Literal("#{res}.push"), [me]
else
- new Return me, @hasAutocb
+ new Return me, @tameHasAutocbFlag
# Does this node, or any of its children, contain a node of a certain kind?
# Recursively traverses down the *children* of the nodes, yielding to a block
@@ -133,8 +133,8 @@ exports.Base = class Base
extras = ""
extras += "A" if @tameNodeFlag
extras += "L" if @tameLoopFlag
- extras += "P" if @cpsPivotFlag
- extras += "C" if @hasAutocb
+ extras += "P" if @tameCpsPivotFlag
+ extras += "C" if @tameHasAutocbFlag
if extras.length
extras = " (" + extras + ")"
tree = '\n' + idt + name
@@ -190,7 +190,7 @@ exports.Base = class Base
return null
tameMarkAutocbs : (found) ->
- @hasAutocb = found
+ @tameHasAutocbFlag = found
for child in @flattenChildren()
child.tameMarkAutocbs(found)
@@ -227,13 +227,13 @@ exports.Base = class Base
# 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).
tameWalkCpsPivots : ->
- @cpsPivotFlag = true if @tameNodeFlag or (@tameLoopFlag and @isJump())
+ @tameCpsPivotFlag = true if @tameNodeFlag or (@tameLoopFlag and @tameIsJump())
for child in @flattenChildren()
- @cpsPivotFlag = true if child.tameWalkCpsPivots()
- @cpsPivotFlag
+ @tameCpsPivotFlag = true if child.tameWalkCpsPivots()
+ @tameCpsPivotFlag
tameNeedsDummyContinuation : ->
- if not @gotCpsSplit
+ if not @tameGotCpsSplitFlag
k_id = new Value new Literal tame.const.k
empty = new Code [], new Block []
new Assign k_id, empty
@@ -251,31 +251,30 @@ exports.Base = class Base
child.tameCpsRotate()
this
- tameIsCpsPivot : -> @cpsPivotFlag
+ tameIsCpsPivot : -> @tameCpsPivotFlag
tameNestContinuationBlock : (b) ->
@tameContinuationBlock = b
- hasContinuation : -> @tameContinuationBlock
+ tameHasContinuation : -> @tameContinuationBlock
- callContinuation : ->
+ tameCallContinuation : ->
isStatement : NO
jumps : NO
isComplex : YES
isChainable : NO
isAssignable : NO
isControlBreak : NO
- isTamedFunc : NO
isLoop : NO
- isAwait : NO
- isJump : NO
+
+ tameIsJump : NO
- tameLoopFlag : false
- tameNodeFlag : false
- gotCpsSplit : false
- cpsPivotFlag : false
- hasAutocb : false
+ tameLoopFlag : false
+ tameNodeFlag : false
+ tameGotCpsSplitFlag : false
+ tameCpsPivotFlag : false
+ tameHasAutocbFlag : false
unwrap : THIS
unfoldSoak : NO
@@ -334,15 +333,16 @@ exports.Block = class Block extends Base
expr = @expressions[len]
if expr not instanceof Comment
@expressions[len] = expr.makeReturn res
- @expressions.splice(len, 1) if expr instanceof Return and not expr.expression and not expr.hasAutocb
+ @expressions.splice(len, 1) if expr instanceof Return and not expr.expression and
+ not expr.tameHasAutocbFlag
break
this
# Optimization!
# Blocks typically don't need their own cpsCascading. This saves
# wasted code.
compileCps : (o) ->
- @gotCpsSplit = true
+ @tameGotCpsSplitFlag = true
if @expressions.length > 1
super o
else
@@ -473,8 +473,8 @@ exports.Block = class Block extends Base
for e in rest
child.tameNodeFlag = true if e.tameNodeFlag
child.tameLoopFlag = true if e.tameLoopFlag
- child.cpsPivotFlag = true if e.cpsPivotFlag
- child.hasAutocb = true if e.hasAutocb
+ child.tameCpsPivotFlag = true if e.tameCpsPivotFlag
+ child.tameHasAutocbFlag = true if e.tameHasAutocbFlag
# now recursive apply the transformation to the new child,
# this being especially import in blocks that have multiple
@@ -484,7 +484,7 @@ exports.Block = class Block extends Base
# The pivot value needs to call the currently active continuation
# after it's all done. For things like if..else.. this does something
# interesting and pushes the continuation down both branches.
- pivot.callContinuation()
+ pivot.tameCallContinuation()
# After we have pivoted this guy, we still need to walk all of the
# expressions, because maybe the expressions that we left still have
@@ -536,7 +536,7 @@ exports.Literal = class Literal extends Base
@value in ['break', 'continue', 'debugger']
isComplex: NO
- isJump : -> @isStatement()
+ tameIsJump : -> @isStatement()
assigns: (name) ->
name is @value
@@ -561,7 +561,7 @@ exports.Literal = class Literal extends Base
if o.scope.method?.bound then o.scope.method.context else @value
else if @value.reserved
"\"#{@value}\""
- else if @tameLoopFlag and @isJump()
+ else if @tameLoopFlag and @tameIsJump()
@compileTame o
else
@value
@@ -575,7 +575,7 @@ exports.Literal = class Literal extends Base
# A `return` is a *pureStatement* -- wrapping it in a closure wouldn't
# make sense.
exports.Return = class Return extends Base
- constructor: (expr, @hasAutocb) ->
+ constructor: (expr, @tameHasAutocbFlag) ->
@expression = expr if expr and not expr.unwrap().isUndefined
children: ['expression']
@@ -589,7 +589,7 @@ exports.Return = class Return extends Base
if expr and expr not instanceof Return then expr.compile o, level else super o, level
compileNode: (o) ->
- if @hasAutocb
+ if @tameHasAutocbFlag
cb = new Value new Literal tame.const.autocb
args = if @expression then [ @expression ] else []
call = new Call cb, args
@@ -1500,7 +1500,7 @@ exports.Code = class Code extends Base
tameWalkCpsPivots: ->
super()
- @cpsPivotFlag = false
+ @tameCpsPivotFlag = false
#### Param
@@ -1665,7 +1665,7 @@ exports.While = class While extends Base
top_statements.unshift k
top_block = new Block top_statements
- callContinuation : ->
+ tameCallContinuation : ->
k = new Call(new Literal tame.const.c_while, [])
@body.push k
@@ -2026,7 +2026,6 @@ exports.Await = class Await extends Base
children: ['body']
isStatement: YES
- isAwait : YES
makeReturn : THIS
compileNode: (o) ->
@@ -2400,8 +2399,8 @@ exports.Switch = class Switch extends Base
@otherwise?.makeReturn res
this
- callContinuation : ->
- code = CALL_CONTINUATION()
+ tameCallContinuation : ->
+ code = TAME_CALL_CONTINUATION()
for [condition,block] in @cases
block.push code
@otherwise?.push code
@@ -2453,8 +2452,8 @@ exports.If = class If extends Base
# propogate the closing continuation call down both branches of the if.
# note this prevents if ...else if... inline chaining, and makes it
# fully nested if { .. } else { if { } ..} ..'s
- callContinuation : ->
- code = CALL_CONTINUATION()
+ tameCallContinuation : ->
+ code = TAME_CALL_CONTINUATION()
if @elseBody
@elseBody.push code
@isChain = false
@@ -2467,7 +2466,7 @@ exports.If = class If extends Base
isStatement: (o) ->
o?.level is LEVEL_TOP or
@bodyNode().isStatement(o) or @elseBodyNode()?.isStatement(o) or
- @hasContinuation()
+ @tameHasContinuation()
jumps: (o) -> @body.jumps(o) or @elseBody?.jumps(o)

0 comments on commit 0a43c2a

Please sign in to comment.