From 3d8679f9fdab5d6d0790ae104a64bf7f7149b540 Mon Sep 17 00:00:00 2001 From: Maxwell Krohn Date: Tue, 31 Jan 2012 18:35:03 -0500 Subject: [PATCH] This commit fixes bug #3, the arguments/_arguments mix-up. --- lib/coffee-script/browser.js | 2 +- lib/coffee-script/cake.js | 2 +- lib/coffee-script/coffee-script.js | 2 +- lib/coffee-script/command.js | 2 +- lib/coffee-script/grammar.js | 2 +- lib/coffee-script/helpers.js | 2 +- lib/coffee-script/iced.js | 2 +- lib/coffee-script/icedlib.js | 2 +- lib/coffee-script/index.js | 2 +- lib/coffee-script/lexer.js | 2 +- lib/coffee-script/nodes.js | 29 +++++++++++++++++++++++---- lib/coffee-script/optparse.js | 2 +- lib/coffee-script/repl.js | 2 +- lib/coffee-script/rewriter.js | 2 +- lib/coffee-script/scope.js | 2 +- src/nodes.coffee | 32 ++++++++++++++++++++++++------ test/iced.coffee | 7 +++++++ 17 files changed, 72 insertions(+), 24 deletions(-) diff --git a/lib/coffee-script/browser.js b/lib/coffee-script/browser.js index 6497456b0c..8682be9533 100644 --- a/lib/coffee-script/browser.js +++ b/lib/coffee-script/browser.js @@ -1,4 +1,4 @@ -// Generated by IcedCoffeeScript 1.2.0i +// Generated by IcedCoffeeScript 1.2.0j (function() { var CoffeeScript, runScripts; diff --git a/lib/coffee-script/cake.js b/lib/coffee-script/cake.js index ce2abf538c..81d4fd5942 100644 --- a/lib/coffee-script/cake.js +++ b/lib/coffee-script/cake.js @@ -1,4 +1,4 @@ -// Generated by IcedCoffeeScript 1.2.0i +// Generated by IcedCoffeeScript 1.2.0j (function() { var CoffeeScript, cakefileDirectory, fatalError, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks; diff --git a/lib/coffee-script/coffee-script.js b/lib/coffee-script/coffee-script.js index d41b8b4ddc..b4db4561c1 100644 --- a/lib/coffee-script/coffee-script.js +++ b/lib/coffee-script/coffee-script.js @@ -1,4 +1,4 @@ -// Generated by IcedCoffeeScript 1.2.0i +// Generated by IcedCoffeeScript 1.2.0j (function() { var EXTENSIONS, Lexer, RESERVED, compile, e, fs, iced, isCoffeeFile, lexer, parser, path, vm, _i, _j, _len, _len2, _ref, __hasProp = {}.hasOwnProperty; diff --git a/lib/coffee-script/command.js b/lib/coffee-script/command.js index 4941a83b3a..21f6ed98e4 100644 --- a/lib/coffee-script/command.js +++ b/lib/coffee-script/command.js @@ -1,4 +1,4 @@ -// Generated by IcedCoffeeScript 1.2.0i +// Generated by IcedCoffeeScript 1.2.0j (function() { var BANNER, CoffeeScript, EventEmitter, SWITCHES, compileJoin, compileOptions, compilePath, compileScript, compileStdio, exec, forkNode, fs, handleIcedOptions, helpers, iced, joinTimeout, lint, loadRequires, notSources, optionParser, optparse, opts, outputPath, parseOptions, path, printLine, printTokens, printWarn, removeSource, runtime_modes_str, sourceCode, sources, spawn, timeLog, unwatchDir, usage, version, wait, watch, watchDir, watchers, writeJs, _ref, __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; diff --git a/lib/coffee-script/grammar.js b/lib/coffee-script/grammar.js index 2b6abd8597..94dd30a0e6 100644 --- a/lib/coffee-script/grammar.js +++ b/lib/coffee-script/grammar.js @@ -1,4 +1,4 @@ -// Generated by IcedCoffeeScript 1.2.0i +// Generated by IcedCoffeeScript 1.2.0j (function() { var Parser, alt, alternatives, grammar, name, o, operators, token, tokens, unwrap; diff --git a/lib/coffee-script/helpers.js b/lib/coffee-script/helpers.js index 6e67f2a0de..d7b97d2778 100644 --- a/lib/coffee-script/helpers.js +++ b/lib/coffee-script/helpers.js @@ -1,4 +1,4 @@ -// Generated by IcedCoffeeScript 1.2.0i +// Generated by IcedCoffeeScript 1.2.0j (function() { var extend, flatten; diff --git a/lib/coffee-script/iced.js b/lib/coffee-script/iced.js index b9eb87a14b..b86743c42a 100644 --- a/lib/coffee-script/iced.js +++ b/lib/coffee-script/iced.js @@ -1,4 +1,4 @@ -// Generated by IcedCoffeeScript 1.2.0i +// Generated by IcedCoffeeScript 1.2.0j (function() { var C, Deferrals, Rendezvous, catchExceptions, exceptionHandler, findDeferral, makeDeferReturn, stackWalk, tickCounter, __active_trace, __c, __slice = [].slice; diff --git a/lib/coffee-script/icedlib.js b/lib/coffee-script/icedlib.js index 7188a61679..5e0766c383 100644 --- a/lib/coffee-script/icedlib.js +++ b/lib/coffee-script/icedlib.js @@ -1,4 +1,4 @@ -// Generated by IcedCoffeeScript 1.2.0i +// Generated by IcedCoffeeScript 1.2.0j (function() { var Pipeliner, iced, iced_internals, __iced_k, _timeout, __slice = [].slice; diff --git a/lib/coffee-script/index.js b/lib/coffee-script/index.js index 0465b941da..07ce6cc428 100644 --- a/lib/coffee-script/index.js +++ b/lib/coffee-script/index.js @@ -1,4 +1,4 @@ -// Generated by IcedCoffeeScript 1.2.0i +// Generated by IcedCoffeeScript 1.2.0j (function() { var key, val, _ref; diff --git a/lib/coffee-script/lexer.js b/lib/coffee-script/lexer.js index ed8a4d41f9..57c49cfb19 100644 --- a/lib/coffee-script/lexer.js +++ b/lib/coffee-script/lexer.js @@ -1,4 +1,4 @@ -// Generated by IcedCoffeeScript 1.2.0i +// Generated by IcedCoffeeScript 1.2.0j (function() { var BOOL, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_ALIAS_MAP, COFFEE_KEYWORDS, COMMENT, COMPARE, COMPOUND_ASSIGN, HEREDOC, HEREDOC_ILLEGAL, HEREDOC_INDENT, HEREGEX, HEREGEX_OMIT, IDENTIFIER, INDEXABLE, INVERSES, JSTOKEN, JS_FORBIDDEN, JS_KEYWORDS, LINE_BREAK, LINE_CONTINUER, LOGIC, Lexer, MATH, MULTILINER, MULTI_DENT, NOT_REGEX, NOT_SPACED_REGEX, NUMBER, OPERATOR, REGEX, RELATION, RESERVED, Rewriter, SHIFT, SIMPLESTR, STRICT_PROSCRIBED, TRAILING_SPACES, UNARY, WHITESPACE, compact, count, key, last, starts, _ref, _ref2, __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; diff --git a/lib/coffee-script/nodes.js b/lib/coffee-script/nodes.js index c7e894edfb..d087713b84 100644 --- a/lib/coffee-script/nodes.js +++ b/lib/coffee-script/nodes.js @@ -1,4 +1,4 @@ -// Generated by IcedCoffeeScript 1.2.0i +// Generated by IcedCoffeeScript 1.2.0j (function() { var Access, Arr, Assign, Await, Base, Block, Call, Class, Closure, Code, Comment, CpsCascade, Defer, Existence, Extends, For, IDENTIFIER, IDENTIFIER_STR, IS_STRING, IcedReturnValue, IcedRuntime, IcedTailCall, If, In, Index, InlineRuntime, LEVEL_ACCESS, LEVEL_COND, LEVEL_LIST, LEVEL_OP, LEVEL_PAREN, LEVEL_TOP, Literal, METHOD_DEF, NEGATE, NO, NULL, Obj, Op, Param, Parens, RESERVED, Range, Return, SIMPLENUM, STRICT_PROSCRIBED, Scope, Slice, Slot, Splat, Switch, TAB, THIS, Throw, Try, UTILITIES, Value, While, YES, compact, del, ends, extend, flatten, iced, last, merge, multident, starts, unfoldSoak, utility, _ref, _ref2, __hasProp = {}.hasOwnProperty, @@ -48,6 +48,7 @@ this.icedGotCpsSplitFlag = false; this.icedCpsPivotFlag = false; this.icedHasAutocbFlag = false; + this.icedFoundArguments = false; this.icedParentAwait = null; this.icedCallContinuationFlag = false; } @@ -164,6 +165,7 @@ if (this.icedCpsPivotFlag) extras += "P"; if (this.icedHasAutocbFlag) extras += "C"; if (this.icedParentAwait) extras += "D"; + if (this.icedFoundArguments) extras += "G"; if (extras.length) extras = " (" + extras + ")"; tree = '\n' + idt + name; if (this.soak) tree += '?'; @@ -679,8 +681,9 @@ Literal.name = 'Literal'; - function Literal(value) { + function Literal(value, tag) { this.value = value; + this.tag = tag; Literal.__super__.constructor.call(this); } @@ -711,6 +714,14 @@ return name === this.value; }; + Literal.prototype.icedWalkAst = function(parent, o) { + if (this.value === 'arguments' && o.foundAwaitFunc) { + o.foundArguments = true; + this.value = "_arguments"; + } + return false; + }; + Literal.prototype.compileIced = function(o) { var call, d, func, l; d = { @@ -2067,6 +2078,9 @@ } uniqs.push(name); } + if (this.icedFoundArguments && this.icedNodeFlag) { + o.scope.assign('_arguments', 'arguments'); + } if (this.icedHasAutocbFlag) wasEmpty = false; if (!(wasEmpty || this.noReturn)) this.body.makeReturn(); if (this.bound) { @@ -2126,11 +2140,15 @@ }; Code.prototype.icedWalkAst = function(parent, o) { - var cf_prev, fa_prev, param, _i, _len, _ref3; + var cf_prev, fa_prev, faf_prev, fg_prev, param, _i, _len, _ref3; this.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 = this; _ref3 = this.params; for (_i = 0, _len = _ref3.length; _i < _len; _i++) { @@ -2142,6 +2160,9 @@ } this.icedHasAutocbFlag = o.foundAutocb; Code.__super__.icedWalkAst.call(this, parent, o); + this.icedFoundArguments = o.foundArguments; + o.foundAwaitFunc = faf_prev; + o.foundArguments = fg_prev; o.foundAutocb = fa_prev; o.currFunc = cf_prev; return false; @@ -2970,7 +2991,7 @@ p = p || this; this.icedParentAwait = p; Await.__super__.icedWalkAst.call(this, p, o); - return this.icedNodeFlag = o.foundAwait = true; + return this.icedNodeFlag = o.foundAwaitFunc = o.foundAwait = true; }; return Await; diff --git a/lib/coffee-script/optparse.js b/lib/coffee-script/optparse.js index 5b325cdd33..af41d8f8dd 100644 --- a/lib/coffee-script/optparse.js +++ b/lib/coffee-script/optparse.js @@ -1,4 +1,4 @@ -// Generated by IcedCoffeeScript 1.2.0i +// Generated by IcedCoffeeScript 1.2.0j (function() { var LONG_FLAG, MULTI_FLAG, OPTIONAL, OptionParser, SHORT_FLAG, buildRule, buildRules, normalizeArguments; diff --git a/lib/coffee-script/repl.js b/lib/coffee-script/repl.js index 69ab33b586..d3c1314f93 100644 --- a/lib/coffee-script/repl.js +++ b/lib/coffee-script/repl.js @@ -1,4 +1,4 @@ -// Generated by IcedCoffeeScript 1.2.0i +// Generated by IcedCoffeeScript 1.2.0j (function() { var ACCESSOR, CoffeeScript, Module, REPL_PROMPT, REPL_PROMPT_CONTINUATION, REPL_PROMPT_MULTILINE, SIMPLEVAR, Script, autocomplete, backlog, completeAttribute, completeVariable, enableColours, error, getCompletions, inspect, multilineMode, pipedInput, readline, repl, run, stdin, stdout; diff --git a/lib/coffee-script/rewriter.js b/lib/coffee-script/rewriter.js index c79328a0b0..0f7add3700 100644 --- a/lib/coffee-script/rewriter.js +++ b/lib/coffee-script/rewriter.js @@ -1,4 +1,4 @@ -// Generated by IcedCoffeeScript 1.2.0i +// Generated by IcedCoffeeScript 1.2.0j (function() { var BALANCED_PAIRS, EXPRESSION_CLOSE, EXPRESSION_END, EXPRESSION_START, IMPLICIT_BLOCK, IMPLICIT_CALL, IMPLICIT_END, IMPLICIT_FUNC, IMPLICIT_UNSPACED_CALL, INVERSES, LINEBREAKS, SINGLE_CLOSERS, SINGLE_LINERS, left, rite, _i, _len, _ref, __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }, diff --git a/lib/coffee-script/scope.js b/lib/coffee-script/scope.js index 5e973a8b36..15165440bf 100644 --- a/lib/coffee-script/scope.js +++ b/lib/coffee-script/scope.js @@ -1,4 +1,4 @@ -// Generated by IcedCoffeeScript 1.2.0i +// Generated by IcedCoffeeScript 1.2.0j (function() { var Scope, extend, last, _ref; diff --git a/src/nodes.coffee b/src/nodes.coffee index a4a71152ce..b0f4492250 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -45,6 +45,7 @@ exports.Base = class Base @icedGotCpsSplitFlag = false @icedCpsPivotFlag = false @icedHasAutocbFlag = false + @icedFoundArguments = false @icedParentAwait = null @icedCallContinuationFlag = false @@ -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 @@ -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 @@ -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: -> @@ -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 @@ -1675,6 +1685,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 @@ -1736,7 +1749,11 @@ 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 @@ -1744,6 +1761,9 @@ exports.Code = class Code extends Base 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 @@ -2418,7 +2438,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 # diff --git a/test/iced.coffee b/test/iced.coffee index 116f87b7f6..893c3ad26d 100644 --- a/test/iced.coffee +++ b/test/iced.coffee @@ -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, {})