Skip to content

Commit

Permalink
I think I see what's slow about parsing -- the tame AST passes. I thi…
Browse files Browse the repository at this point in the history
…nk this fixes it, or at least works around it. Remove all tame from the core libraries
  • Loading branch information
maxtaco committed Jan 24, 2012
1 parent ce2bdca commit 618305c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 121 deletions.
22 changes: 8 additions & 14 deletions Cakefile
Expand Up @@ -30,7 +30,7 @@ header = """
sources = [
'coffee-script', 'grammar', 'helpers'
'lexer', 'nodes', 'rewriter', 'scope',
'tame', 'tamelib'
'tame'
].map (filename) -> "src/#{filename}.coffee"

# Run a CoffeeScript through our node/coffee interpreter.
Expand Down Expand Up @@ -192,13 +192,13 @@ runTests = (CoffeeScript) ->
global.atest = (description, fn) ->
++attemptedTests
fn.test = { description, currentFile }
await fn.call(fn, defer(ok, e))
if ok
++passedTests
else
e.description = description if description?
e.source = fn.toString() if fn.toString?
failures.push filename : currentFile, error : e
fn.call fn, (ok, e) =>
if ok
++passedTests
else
e.description = description if description?
e.source = fn.toString() if fn.toString?
failures.push filename : currentFile, error : e

# See http://wiki.ecmascript.org/doku.php?id=harmony:egal
egal = (a, b) ->
Expand Down Expand Up @@ -262,9 +262,3 @@ task 'test:browser', 'run the test suite against the merged browser script', ->
(-> eval source).call result
runTests result.CoffeeScript

atask 'test:acake', 'run a test for Cakefile async', (opts,cb) ->
console.log "start sleep"
await setTimeout defer(), 1000
console.log "end sleep"
cb()

99 changes: 12 additions & 87 deletions lib/coffee-script/cake.js

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

19 changes: 15 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.

16 changes: 4 additions & 12 deletions src/cake.coffee
Expand Up @@ -17,7 +17,6 @@ CoffeeScript = require './coffee-script'

# Keep track of the list of defined tasks, the accepted options, and so on.
tasks = {}
atasks = {}
options = {}
switches = []
oparse = null
Expand All @@ -27,12 +26,9 @@ helpers.extend global,

# Define a Cake task with a short name, an optional sentence description,
# and the function to run as the action itself.
task: (name, description, action, async) ->
task: (name, description, action) ->
[action, description] = [description, action] unless action
tasks[name] = {name, description, action, async}

atask: (name, description, action) ->
task name, description, action, true
tasks[name] = {name, description, action}

# Define an option that the Cakefile accepts. The parsed options hash,
# containing all of the command-line options passed, will be made available
Expand All @@ -43,11 +39,7 @@ helpers.extend global,
# Invoke another task in the current Cakefile.
invoke: (name, cb) ->
missingTask name unless (t = tasks[name])
if t.async
await t.action(options, defer())
else
t.action options
cb()
t.action options

# Run `cake`. Executes all of the tasks you pass, in order. Note that Node's
# asynchrony may cause tasks to execute in a different order than you'd expect.
Expand All @@ -65,7 +57,7 @@ exports.run = (cb) ->
catch e
return fatalError "#{e}"
for arg in options.arguments
await invoke(arg,defer())
invoke arg

# Display the list of Cake tasks in a format similar to `rake -T`
printTasks = ->
Expand Down
14 changes: 10 additions & 4 deletions src/nodes.coffee
Expand Up @@ -101,17 +101,17 @@ exports.Base = class Base
# Recursively traverses down the *children* of the nodes, yielding to a block
# and returning true when the block finds a match. `contains` does not cross
# scope boundaries.
contains: (pred) ->
contains: (pred, traverseFuncBoundary) ->
contains = no
@traverseChildren no, (node) ->
@traverseChildren traverseFuncBoundary, (node) ->
if pred node
contains = yes
return no
contains

# Is this node of a certain type, or does it contain the type?
containsType: (type) ->
this instanceof type or @contains (node) -> node instanceof type
containsType: (type, traverseFuncBoundary) ->
this instanceof type or @contains (node, traverseFuncBoundary) -> node instanceof type

# Pull out the last non-comment node of a node list.
lastNonComment: (list) ->
Expand Down Expand Up @@ -248,6 +248,11 @@ exports.Base = class Base
@tameCpsPivotFlag = true if child.tameWalkCpsPivots()
@tameCpsPivotFlag

tameGo : ->
for child in @flattenChildren()
return true if (child instanceof Await) or child.tameGo()
return false

# Default implementations of the common node properties and methods. Nodes
# will override these with custom logic, if needed.
children: []
Expand Down Expand Up @@ -539,6 +544,7 @@ exports.Block = class Block extends Base

# Perform all steps of the Tame transform
tameTransform : ->
return this unless @tameGo()
@tameExtractExpressions(true)
@tameAssignDefersToAwait()
@tameWalkAst()
Expand Down

0 comments on commit 618305c

Please sign in to comment.