Skip to content

Commit 44a0c90

Browse files
committed
little cleanup, but that's still SO dirty
1 parent d3223ce commit 44a0c90

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

lib/ast.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2720,7 +2720,7 @@ exports.While = While = (function(superclass){
27202720
}
27212721
return code + ret;
27222722
};
2723-
prototype.setLet = function(){
2723+
prototype.makeLet = function(){
27242724
throw Error('unimplemented');
27252725
};
27262726
return While;
@@ -2742,14 +2742,14 @@ exports.For = For = (function(superclass){
27422742
prototype.compileNode = function(o){
27432743
var temps, idx, ref$, pvar, step, tvar, tail, fvar, vars, eq, cond, svar, srcPart, lvar, head, that, body;
27442744
o.loop = true;
2745-
temps = this.temps = [];
27462745
if (this['let']) {
27472746
this.capture = [];
27482747
}
2748+
temps = this.temps = [];
27492749
if (idx = this.idx = this.index) {
27502750
o.scope.declare(idx, this);
27512751
} else {
2752-
temps.push(idx = this.idx = o.scope.temporary('i'));
2752+
temps.push(idx = o.scope.temporary('i'));
27532753
}
27542754
if (!this.object) {
27552755
ref$ = (this.step || Literal(1)).compileLoopReference(o, 'step'), pvar = ref$[0], step = ref$[1];
@@ -2798,6 +2798,9 @@ exports.For = For = (function(superclass){
27982798
head += that + " = true, ";
27992799
}
28002800
if (this.object) {
2801+
if (this['let']) {
2802+
this.capture.push(idx);
2803+
}
28012804
head += srcPart;
28022805
} else {
28032806
step === pvar || (vars += ', ' + step);
@@ -2813,7 +2816,7 @@ exports.For = For = (function(superclass){
28132816
o.indent += TAB;
28142817
if (this.item && !this.item.isEmpty()) {
28152818
if (this['let']) {
2816-
this.capture = this.item.compile(o, LEVEL_PAREN);
2819+
this.capture.push(this.item.compile(o, LEVEL_PAREN));
28172820
}
28182821
head += '\n' + o.indent + Assign(this.item, JS(svar + "[" + idx + "]")).compile(o, LEVEL_TOP) + ';';
28192822
}
@@ -2826,7 +2829,7 @@ exports.For = For = (function(superclass){
28262829
}
28272830
return head + body;
28282831
};
2829-
prototype.setLet = function(){
2832+
prototype.makeLet = function(){
28302833
this['let'] = true;
28312834
return this;
28322835
};

lib/grammar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ bnf = {
2525
}), o('LET CALL( ArgList OptComma )CALL Block', function(){
2626
return Chain(Call['let']($3, $6));
2727
}), o('LET LoopHead Block', function(){
28-
return $2.setLet().addBody($3);
28+
return $2.makeLet().addBody($3);
2929
}), o('WITH Expression Block', function(){
3030
return Chain(Pipe($2, $3, 'with'));
3131
}), o('FOR Expression Block', function(){

lib/parser.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ast.co

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,7 +1674,7 @@ class exports.While extends Node
16741674
o.scope.free yet
16751675
code + ret
16761676

1677-
setLet: -> ...
1677+
makeLet: -> ...
16781678

16791679
#### For
16801680
# Coco's replacements for the `for` loop are array, object or range iterators.
@@ -1691,11 +1691,11 @@ class exports.For extends While
16911691

16921692
compileNode: (o) ->
16931693
o.loop = true
1694-
temps = @temps = []
16951694
@capture = [] if @let
1695+
temps = @temps = []
16961696
if idx = @idx = @index
16971697
then o.scope.declare idx, this
1698-
else temps.push idx = @idx = o.scope.temporary \i
1698+
else temps.push idx = o.scope.temporary \i
16991699
unless @object
17001700
[pvar, step] = (@step or Literal 1)compileLoopReference o, \step
17011701
pvar is step or temps.push pvar
@@ -1731,6 +1731,7 @@ class exports.For extends While
17311731
head += "#idx in " if @object
17321732
head += "#that = true, " if @yet
17331733
if @object
1734+
@capture.push idx if @let
17341735
head += srcPart
17351736
else
17361737
step is pvar or vars += ', ' + step
@@ -1745,15 +1746,15 @@ class exports.For extends While
17451746
@infuseIIFE!
17461747
o.indent += TAB
17471748
if @item and not @item.isEmpty!
1748-
@capture = @item.compile o, LEVEL_PAREN if @let
1749+
@capture.push @item.compile o, LEVEL_PAREN if @let
17491750
head += \\n + o.indent +
17501751
Assign(@item, JS "#svar[#idx]")compile(o, LEVEL_TOP) + \;
17511752
o.ref = @item.value if @ref
17521753
body = @compileBody o
17531754
head += \\n + @tab if @item and \} is body.charAt 0
17541755
head + body
17551756

1756-
setLet: ->
1757+
makeLet: ->
17571758
@let = true
17581759
this
17591760

src/grammar.co

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ bnf =
6767
o 'Chain ?' -> Chain Existence $1.unwrap!
6868

6969
o 'LET CALL( ArgList OptComma )CALL Block' -> Chain Call.let $3, $6
70-
o 'LET LoopHead Block' -> $2.setLet!addBody $3
70+
o 'LET LoopHead Block' -> $2.makeLet!addBody $3
7171

7272
o 'WITH Expression Block' -> Chain Pipe $2, $3, \with
7373
o 'FOR Expression Block' -> Chain new For source: $2, body: $3, ref: true

0 commit comments

Comments
 (0)