Skip to content

Commit

Permalink
This commit fixes bug maxtaco#3, the arguments/_arguments mix-up.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtaco committed Jan 31, 2012
1 parent 111121d commit 142d044
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/coffee-script/browser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffee-script/cake.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffee-script/coffee-script.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffee-script/command.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffee-script/grammar.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffee-script/helpers.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffee-script/iced.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffee-script/icedlib.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffee-script/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffee-script/lexer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 25 additions & 4 deletions lib/coffee-script/nodes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffee-script/optparse.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffee-script/repl.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffee-script/rewriter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffee-script/scope.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 26 additions & 6 deletions src/nodes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ exports.Base = class Base
@icedGotCpsSplitFlag = false
@icedCpsPivotFlag = false
@icedHasAutocbFlag = false
@icedFoundArguments = false

@icedParentAwait = null
@icedCallContinuationFlag = false
Expand Down Expand Up @@ -204,6 +205,7 @@ exports.Base = class Base
extras += "P" if @icedCpsPivotFlag
extras += "C" if @icedHasAutocbFlag
extras += "D" if @icedParentAwait
extras += "G" if @icedFoundArguments
if extras.length
extras = " (" + extras + ")"
tree = '\n' + idt + name
Expand Down Expand Up @@ -275,10 +277,12 @@ exports.Base = class Base
# copies, to push information up and down the AST. This parameter is
# used with subfields:
#
# o.foundAutocb -- on if the parent function has an autocb
# o.foundDefer -- on if defer() was found anywhere in the AST
# o.foundAwait -- on if await... was found anywhere in the AST
# o.currFunc -- the current func we're in
# o.foundAutocb -- on if the parent function has an autocb
# o.foundDefer -- on if defer() was found anywhere in the AST
# o.foundAwait -- on if await... was found anywhere in the AST
# o.foundAwaitFunc -- on if await found in this func
# o.currFunc -- the current func we're in
# o.foundArguments -- on if we found reference to 'arguments'
#
icedWalkAst : (p, o) ->
@icedParentAwait = p
Expand Down Expand Up @@ -669,7 +673,7 @@ exports.Block = class Block extends Base
# JavaScript without translation, such as: strings, numbers,
# `true`, `false`, `null`...
exports.Literal = class Literal extends Base
constructor: (@value) ->
constructor: (@value, @tag) ->
super()

makeReturn: ->
Expand All @@ -687,6 +691,12 @@ exports.Literal = class Literal extends Base
assigns: (name) ->
name is @value

icedWalkAst : (parent, o) ->
if @value is 'arguments' and o.foundAwaitFunc
o.foundArguments = true
@value = "_arguments"
false

compileIced: (o) ->
d =
'continue' : iced.const.c_while
Expand Down Expand Up @@ -1657,6 +1667,9 @@ exports.Code = class Code extends Base
throw SyntaxError "multiple parameters named '#{name}'" if name in uniqs
uniqs.push name

if @icedFoundArguments and @icedNodeFlag
o.scope.assign '_arguments', 'arguments'

wasEmpty = false if @icedHasAutocbFlag
@body.makeReturn() unless wasEmpty or @noReturn
if @bound
Expand Down Expand Up @@ -1718,14 +1731,21 @@ exports.Code = class Code extends Base
@icedParentAwait = parent
fa_prev = o.foundAutocb
cf_prev = o.currFunc
fg_prev = o.foundArguments
faf_prev = o.foundAwaitFunc
o.foundAutocb = false
o.foundArguments = false
o.foundAwaitFunc = false
o.currFunc = @
for param in @params
if param.name instanceof Literal and param.name.value is iced.const.autocb
o.foundAutocb = true
break
@icedHasAutocbFlag = o.foundAutocb
super parent, o
@icedFoundArguments = o.foundArguments
o.foundAwaitFunc = faf_prev
o.foundArguments = fg_prev
o.foundAutocb = fa_prev
o.currFunc = cf_prev
false
Expand Down Expand Up @@ -2394,7 +2414,7 @@ exports.Await = class Await extends Base
p = p || this
@icedParentAwait = p
super p, o
@icedNodeFlag = o.foundAwait = true
@icedNodeFlag = o.foundAwaitFunc = o.foundAwait = true

#### IcedRuntime
#
Expand Down
7 changes: 7 additions & 0 deletions test/iced.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -576,3 +576,10 @@ atest "defer and object assignment", (cb) ->
when 1 then baz defer { b : out[i] }
when 2 then baz defer { a : out[i] }
cb( out[0] is 3 and out[1] is 2 and out[2] is 1, {} )

atest 'defer + arguments', (cb) ->
bar = (i, cb) ->
await delay defer()
arguments[1](arguments[0])
await bar 10, defer x
cb(10 is x, {})

0 comments on commit 142d044

Please sign in to comment.