Skip to content

Commit

Permalink
fixed #185; hushed named function should evaluate to itself
Browse files Browse the repository at this point in the history
  • Loading branch information
satyr committed Oct 31, 2012

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 8327a08 commit 7987103
Showing 3 changed files with 14 additions and 13 deletions.
14 changes: 7 additions & 7 deletions lib/ast.js
Original file line number Diff line number Diff line change
@@ -972,15 +972,15 @@ exports.Call = Call = (function(superclass){
Call.back = function(params, node, bound){
var fun, args, index, len$, a;
fun = Fun(params, void 8, bound);
if (fun['void'] = node.op === '!') {
if (fun.hushed = node.op === '!') {
node = node.it;
}
if (node instanceof Label) {
fun.name = node.label;
fun.labeled = true;
node = node.it;
}
if (!fun['void'] && (fun['void'] = node.op === '!')) {
if (!fun.hushed && (fun.hushed = node.op === '!')) {
node = node.it;
}
args = (node.getCall() || (node = Chain(node).add(Call())).getCall()).args;
@@ -1180,7 +1180,7 @@ exports.Prop = Prop = (function(superclass){
this$.val = that;
for (i$ = 0, len$ = that.length; i$ < len$; ++i$) {
fun = that[i$];
fun.x = (fun['void'] = fun.params.length) ? 's' : 'g';
fun.x = (fun.hushed = fun.params.length) ? 's' : 'g';
}
this$['accessor'] = 'accessor';
}
@@ -1302,8 +1302,8 @@ exports.Unary = Unary = (function(superclass){
if (flag) {
break;
}
if (it instanceof Fun && !it['void']) {
return it['void'] = true, it;
if (it instanceof Fun && !it.hushed) {
return it.hushed = true, it;
}
return it.invert();
case '++':
@@ -2214,7 +2214,7 @@ exports.Fun = Fun = (function(superclass){
if (this.statement || name && this.labeled) {
code += ' ' + scope.add(name, 'function', this);
}
this['void'] || this.ctor || this.newed || body.makeReturn();
this.hushed || this.ctor || this.newed || body.makeReturn();
code += "(" + this.compileParams(scope) + "){";
if (that = body.compileWithDeclarations(o)) {
code += "\n" + that + "\n" + tab;
@@ -2425,7 +2425,7 @@ exports.Parens = Parens = (function(superclass){
it = this.it;
it.cond || (it.cond = this.cond), it['void'] || (it['void'] = this['void']);
if (this.calling && (!level || this['void'])) {
it.head['void'] = true;
it.head.hushed = true;
}
if (!(this.keep || this.newed || level >= LEVEL_OP + PREC[it.op])) {
return (it.front = this.front, it).compile(o, level || LEVEL_PAREN);
12 changes: 6 additions & 6 deletions src/ast.co
Original file line number Diff line number Diff line change
@@ -597,11 +597,11 @@ class exports.Call extends Node

@back = (params, node, bound) ->
fun = Fun params,, bound
node.=it if fun.void = node.op is \!
node.=it if fun.hushed = node.op is \!
if node instanceof Label
fun <<< {name: node.label, +labeled}
node.=it
node.=it if not fun.void and fun.void = node.op is \!
node.=it if not fun.hushed and fun.hushed = node.op is \!
{args} = node.getCall! or (node = Chain node .add Call!)getCall!
break if a.filler for a, index of args
node <<< back: (args[index] = fun)body
@@ -716,7 +716,7 @@ class exports.Prop extends Node
if val.getAccessors!
@val = that
for fun of that
fun.x = if fun.void = fun.params.length then \s else \g
fun.x = if fun.hushed = fun.params.length then \s else \g
import {\accessor}

children: <[ key val ]>
@@ -787,7 +787,7 @@ class exports.Unary extends Node
switch op
case \!
break if flag
return it <<< {+void} if it instanceof Fun and not it.void
return it <<< {+hushed} if it instanceof Fun and not it.hushed
return it.invert!
case \++ \-- then @post = true if flag
case \new
@@ -1354,7 +1354,7 @@ class exports.Fun extends Node
pscope.add name, \function, this
if @statement or name and @labeled
code += ' ' + scope.add name, \function, this
@void or @ctor or @newed or body.makeReturn!
@hushed or @ctor or @newed or body.makeReturn!
code += "(#{ @compileParams scope }){"
code += "\n#that\n#tab" if body.compileWithDeclarations o
code += \}
@@ -1475,7 +1475,7 @@ class exports.Parens extends Node
compile: (o, level ? o.level) ->
{it} = this
it{cond, \void} ||= this
it.head.void = true if @calling and (not level or @void)
it.head.hushed = true if @calling and (not level or @void)
unless @keep or @newed or level >= LEVEL_OP + PREC[it.op]
return (it <<< {@front})compile o, level || LEVEL_PAREN
if it.isStatement!
1 change: 1 addition & 0 deletions test/function.co
Original file line number Diff line number Diff line change
@@ -471,6 +471,7 @@ eq void do
<~! M
!function C then C
ok new C instanceof C
eq void do not function f => f
true
eq false !!->

0 comments on commit 7987103

Please sign in to comment.