Skip to content

Commit

Permalink
closes #149; quit overloading +
Browse files Browse the repository at this point in the history
  • Loading branch information
satyr committed Jul 12, 2012
1 parent bc95d4c commit ff9f887
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 43 deletions.
12 changes: 1 addition & 11 deletions lib/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -1483,15 +1483,6 @@ exports.Binary = Binary = (function(superclass){
switch (op) {
case 'of':
return new Of(first, second);
case '+':
if (first instanceof Arr) {
first.items.push(Splat(second));
return first;
}
if (second instanceof Arr || second instanceof While && (second = Arr([Splat(second)]))) {
second.items.unshift(Splat(first));
return second;
}
}
__this.op = op;
__this.first = first;
Expand Down Expand Up @@ -1744,7 +1735,6 @@ exports.Assign = Assign = (function(superclass){
switch (this.op) {
case '=':
case ':=':
case '+=':
return this.right.isArray();
case '/=':
return this.right.isMatcher();
Expand Down Expand Up @@ -1806,7 +1796,7 @@ exports.Assign = Assign = (function(superclass){
if (op === '<?=' || op === '>?=') {
return this.compileMinMax(o, left, right);
}
if (op === '**=' || op === '+=' && (right instanceof Arr || right instanceof While) || op === '*=' && right.isString() || (op === '-=' || op === '/=') && right.isMatcher()) {
if (op === '**=' || op === '*=' && right.isString() || (op === '-=' || op === '/=') && right.isMatcher()) {
__ref = Chain(left).cacheReference(o), left = __ref[0], reft = __ref[1];
right = Binary(op.slice(0, -1), reft, right);
op = ':=';
Expand Down
21 changes: 6 additions & 15 deletions src/ast.co
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class exports.Block extends Node
code = @compileWithDeclarations o
# Wrap everything in a safety closure unless requested not to.
bare or code = "(function(){\n#code\n}).call(this);\n"
([prefix]) + code
[prefix] + code

# Compile to a function body.
compileWithDeclarations: (o) ->
Expand Down Expand Up @@ -368,7 +368,7 @@ class exports.Index extends Node

children: [\key]

show: -> ([\? if @soak]) + @symbol
show: -> [\? if @soak] + @symbol

isComplex: -> @key.isComplex!

Expand Down Expand Up @@ -578,7 +578,7 @@ class exports.Call extends Node

children: [\args]

show: -> ([@new]) + ([@method]) + ([\? if @soak])
show: -> [@new] + [@method] + [\? if @soak]

compile: (o) ->
code = (@method or '') + \(
Expand Down Expand Up @@ -798,7 +798,7 @@ class exports.Unary extends Node

children: [\it]

show: -> ([\@ if @post]) + @op
show: -> [\@ if @post] + @op

isCallable: -> @op of <[ do new delete ]>

Expand Down Expand Up @@ -884,14 +884,6 @@ class exports.Binary extends Node
(op, first, second) ~>
switch op
case \of then return new Of first, second
case \+
if first instanceof Arr
first.items.push Splat second
return first
if second instanceof Arr
or second instanceof While and second = Arr [Splat second]
second.items.unshift Splat first
return second
import {op, first, second}

children: <[ first second ]>
Expand Down Expand Up @@ -1043,8 +1035,8 @@ class exports.Assign extends Node
::delegate <[ isCallable isRegex ]> -> @op of <[ = := ]> and @right[it]!

isArray: -> switch @op
case \= \:= \+= then @right.isArray!
case \/= then @right.isMatcher!
case \= \:= then @right.isArray!
case \/= then @right.isMatcher!

isString: -> switch @op
case \= \:= \+= \*= then @right.isString!
Expand Down Expand Up @@ -1077,7 +1069,6 @@ class exports.Assign extends Node
{op, right} = this
return @compileMinMax o, left, right if op of <[ <?= >?= ]>
if op is \**=
or op is \+= and right instanceof [Arr, While]
or op is \*= and right.isString!
or op of <[ -= /= ]> and right.isMatcher!
[left, reft] = Chain(left)cacheReference o
Expand Down
2 changes: 1 addition & 1 deletion test/literal.co
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ a = [] <<<
a +=
4
5
eq '0,1,2,3,4,5' ''+a
eq '0,1,2,34,5' a

eq '0,1' ''+ do ->
return
Expand Down
17 changes: 1 addition & 16 deletions test/operator.co
Original file line number Diff line number Diff line change
Expand Up @@ -428,22 +428,7 @@ eq '8,9' ''+ -~[7 8]


### Overloaded
a = [0 1]
b = ''

#### Concat
eq '0,1,2' String a + [2]
eq '3,4,5' String [3 4] + {0: 5, length: 1}
eq '0,1' ''+ b += [0 1]
ok b instanceof a..

x = [6]
y = [7 to 10]
[[] ...x, []] += y
eq '6,8,9' ''+ x

x += for i til 2 then i
eq '6,8,9,0,1' ''+ x
a = b = [0 1]

#### Join
eq '0==1' a * \==
Expand Down

0 comments on commit ff9f887

Please sign in to comment.