Skip to content
Browse files

chris pointed out a bug with nested loops, which is now fixed. also, …

…i want to work on the empty body autocb problem
  • Loading branch information...
1 parent e60d3dc commit bb113f9c3247abb38a0a93f7c1c8717c4d519df7 @maxtaco committed Dec 15, 2011
Showing with 38 additions and 14 deletions.
  1. +2 −1 lib/coffee-script/cake.js
  2. +12 −5 lib/coffee-script/nodes.js
  3. +4 −2 lib/coffee-script/tamelib.js
  4. +6 −6 src/nodes.coffee
  5. +14 −0 test/tame.coffee
View
3 lib/coffee-script/cake.js
@@ -98,7 +98,7 @@
});
exports.run = function(cb) {
- var arg, args, __tame_deferrals, _break, _continue, _i, _len, _ref, _results, _while,
+ var arg, args, __tame_deferrals, _i, _len, _ref, _results, _while,
_this = this;
global.__originalDirname = fs.realpathSync('.');
process.chdir(cakefileDirectory(__originalDirname));
@@ -117,6 +117,7 @@
_len = _ref.length;
_i = 0;
_while = function(__tame_k) {
+ var _break, _continue;
_break = __tame_k;
_continue = function() {
++_i;
View
17 lib/coffee-script/nodes.js
@@ -1507,6 +1507,7 @@
this.context = context;
this.param = options && options.param;
this.subpattern = options && options.subpattern;
+ this.tamelocal = options && options.tamelocal;
}
Assign.prototype.children = ['variable', 'value'];
@@ -1540,8 +1541,8 @@
throw SyntaxError("\"" + (this.variable.compile(o)) + "\" cannot be assigned.");
}
if (!(typeof varBase.hasProperties === "function" ? varBase.hasProperties() : void 0)) {
- if (this.param) {
- o.scope.add(name, 'var');
+ if (this.param || this.tamelocal) {
+ o.scope.add(name, 'var', this.tamelocal);
} else {
o.scope.find(name);
}
@@ -2003,17 +2004,23 @@
top_id = new Value(new Literal(tame["const"].t_while));
k_id = new Value(new Literal(tame["const"].k));
break_id = new Value(new Literal(tame["const"].b_while));
- break_assign = new Assign(break_id, k_id);
+ break_assign = new Assign(break_id, k_id, null, {
+ tamelocal: true
+ });
continue_id = new Value(new Literal(tame["const"].c_while));
continue_block = new Block([new Call(top_id, [k_id])]);
if (d.step) continue_block.unshift(d.step);
continue_body = new Code([], continue_block, 'tamegen');
- continue_assign = new Assign(continue_id, continue_body);
+ continue_assign = new Assign(continue_id, continue_body, null, {
+ tamelocal: true
+ });
cond = new If(condition, body);
cond.addElse(new Block([new Call(break_id, [])]));
top_body = new Block([break_assign, continue_assign, cond]);
top_func = new Code([k_id], top_body, 'tamegen');
- top_assign = new Assign(top_id, top_func);
+ top_assign = new Assign(top_id, top_func, null, {
+ tamelocal: true
+ });
top_call = new Call(top_id, [k_id]);
top_statements = [];
if (d.init) top_statements = top_statements.concat(d.init);
View
6 lib/coffee-script/tamelib.js
@@ -57,10 +57,11 @@
}
Pipeliner.prototype.waitInQueue = function(cb) {
- var __tame_deferrals, _break, _continue, _while,
+ var __tame_deferrals, _while,
_this = this;
(function(__tame_k) {
_while = function(__tame_k) {
+ var _break, _continue;
_break = __tame_k;
_continue = function() {
return _while(__tame_k);
@@ -129,10 +130,11 @@
};
Pipeliner.prototype.flush = function(autocb) {
- var __tame_deferrals, _break, _continue, _while,
+ var __tame_deferrals, _while,
_this = this;
__tame_k = autocb;
_while = function(__tame_k) {
+ var _break, _continue;
_break = __tame_k;
_continue = function() {
return _while(__tame_k);
View
12 src/nodes.coffee
@@ -1245,6 +1245,7 @@ exports.Assign = class Assign extends Base
forbidden = (name = @variable.unwrapAll().value) in STRICT_PROSCRIBED
if forbidden and @context isnt 'object'
throw SyntaxError "variable name may not be \"#{name}\""
+ @tamelocal = options and options.tamelocal
children: ['variable', 'value']
@@ -1271,8 +1272,8 @@ exports.Assign = class Assign extends Base
unless (varBase = @variable.unwrapAll()).isAssignable()
throw SyntaxError "\"#{ @variable.compile o }\" cannot be assigned."
unless varBase.hasProperties?()
- if @param
- o.scope.add name, 'var'
+ if @param or @tamelocal
+ o.scope.add name, 'var', @tamelocal
else
o.scope.find name
if @value instanceof Code and match = METHOD_DEF.exec name
@@ -1662,8 +1663,7 @@ exports.While = class While extends Base
top_id = new Value new Literal tame.const.t_while
k_id = new Value new Literal tame.const.k
break_id = new Value new Literal tame.const.b_while
-
- break_assign = new Assign break_id, k_id
+ break_assign = new Assign break_id, k_id, null, { tamelocal : yes }
# The continue assignment is the increment at the end
# of the loop (if it's there), and also the recursive
@@ -1672,7 +1672,7 @@ exports.While = class While extends Base
continue_block = new Block [ new Call top_id, [ k_id ] ]
continue_block.unshift d.step if d.step
continue_body = new Code [], continue_block, 'tamegen'
- continue_assign = new Assign continue_id, continue_body
+ continue_assign = new Assign continue_id, continue_body, null, { tamelocal : yes }
# The whole body is wrapped in an if, with the positive
# condition being the loop, and the negative condition
@@ -1683,7 +1683,7 @@ exports.While = class While extends Base
# The top of the loop construct.
top_body = new Block [ break_assign, continue_assign, cond ]
top_func = new Code [ k_id ], top_body, 'tamegen'
- top_assign = new Assign top_id, top_func
+ top_assign = new Assign top_id, top_func, null, { tamelocal : yes }
top_call = new Call top_id, [ k_id ]
top_statements = []
top_statements = top_statements.concat d.init if d.init
View
14 test/tame.coffee
@@ -281,3 +281,17 @@ atest "fat arrow versus tame", (cb) ->
await f.useHandler "sleep1", defer(ok1)
await f.useHandler "sleep2", defer(ok2)
cb(ok1 and ok2, {})
+
+ atest "nested loops", (cb) ->
+ val = 0
+ for i in [0..10]
+ await delay(defer(),1)
+ for j in [0..10]
+ await delay(defer(),1)
+ val++
+ cb(val == 100, {})
+
+atest "empty autocb", (cb) ->
+ bar = (autocb) ->
+ await bar defer()
+ cb(true, {})

0 comments on commit bb113f9

Please sign in to comment.
Something went wrong with that request. Please try again.