Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

I think I see what's slow about parsing -- the tame AST passes. I thi…

…nk this fixes it, or at least works around it. Remove all tame from the core libraries
  • Loading branch information...
commit 618305ce1fa05bdbcf0a2448096593e60a93dd1c 1 parent ce2bdca
@maxtaco authored
View
22 Cakefile
@@ -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.
@@ -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) ->
@@ -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()
-
View
99 lib/coffee-script/cake.js
@@ -1,40 +1,5 @@
(function() {
- var CoffeeScript, atasks, cakefileDirectory, fatalError, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tame, tasks, __tame_k,
- __slice = Array.prototype.slice;
-
-
- tame = {
- Deferrals: (function() {
-
- function _Class(_arg) {
- this.continuation = _arg;
- this.count = 1;
- }
-
- _Class.prototype._fulfill = function() {
- if (!--this.count) return this.continuation();
- };
-
- _Class.prototype.defer = function(defer_params) {
- var _this = this;
- ++this.count;
- return function() {
- var inner_params, _ref;
- inner_params = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
- if (defer_params != null) {
- if ((_ref = defer_params.assign_fn) != null) {
- _ref.apply(null, inner_params);
- }
- }
- return _this._fulfill();
- };
- };
-
- return _Class;
-
- })()
- }
- __tame_k = function() {};
+ var CoffeeScript, cakefileDirectory, fatalError, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks;
fs = require('fs');
@@ -48,8 +13,6 @@
tasks = {};
- atasks = {};
-
options = {};
switches = [];
@@ -57,7 +20,7 @@
oparse = null;
helpers.extend(global, {
- task: function(name, description, action, async) {
+ task: function(name, description, action) {
var _ref;
if (!action) {
_ref = [description, action], action = _ref[0], description = _ref[1];
@@ -65,42 +28,21 @@
return tasks[name] = {
name: name,
description: description,
- action: action,
- async: async
+ action: action
};
},
- atask: function(name, description, action) {
- return task(name, description, action, true);
- },
option: function(letter, flag, description) {
return switches.push([letter, flag, description]);
},
invoke: function(name, cb) {
- var t, __tame_deferrals,
- _this = this;
+ var t;
if (!(t = tasks[name])) missingTask(name);
- (function(__tame_k) {
- if (t.async) {
- (function(__tame_k) {
- __tame_deferrals = new tame.Deferrals(__tame_k);
- t.action(options, __tame_deferrals.defer({}));
- __tame_deferrals._fulfill();
- })(function() {
- return __tame_k();
- });
- } else {
- t.action(options);
- return __tame_k();
- }
- })(function() {
- return cb();
- });
+ return t.action(options);
}
});
exports.run = function(cb) {
- var arg, args, __tame_deferrals, _i, _len, _ref, _results, _while,
- _this = this;
+ var arg, args, _i, _len, _ref, _results;
global.__originalDirname = fs.realpathSync('.');
process.chdir(cakefileDirectory(__originalDirname));
args = process.argv.slice(2);
@@ -115,29 +57,12 @@
return fatalError("" + e);
}
_ref = options.arguments;
- _len = _ref.length;
- _i = 0;
- _while = function(__tame_k) {
- var _break, _continue;
- _break = __tame_k;
- _continue = function() {
- ++_i;
- return _while(__tame_k);
- };
- if (_i < _len) {
- arg = _ref[_i];
- (function(__tame_k) {
- __tame_deferrals = new tame.Deferrals(__tame_k);
- invoke(arg, __tame_deferrals.defer({}));
- __tame_deferrals._fulfill();
- })(function() {
- return _continue();
- });
- } else {
- return _break();
- }
- };
- _while(__tame_k);
+ _results = [];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ arg = _ref[_i];
+ _results.push(invoke(arg));
+ }
+ return _results;
};
printTasks = function() {
View
19 lib/coffee-script/nodes.js
@@ -105,10 +105,10 @@
}
};
- Base.prototype.contains = function(pred) {
+ Base.prototype.contains = function(pred, traverseFuncBoundary) {
var contains;
contains = false;
- this.traverseChildren(false, function(node) {
+ this.traverseChildren(traverseFuncBoundary, function(node) {
if (pred(node)) {
contains = true;
return false;
@@ -117,8 +117,8 @@
return contains;
};
- Base.prototype.containsType = function(type) {
- return this instanceof type || this.contains(function(node) {
+ Base.prototype.containsType = function(type, traverseFuncBoundary) {
+ return this instanceof type || this.contains(function(node, traverseFuncBoundary) {
return node instanceof type;
});
};
@@ -300,6 +300,16 @@
return this.tameCpsPivotFlag;
};
+ Base.prototype.tameGo = function() {
+ var child, _i, _len, _ref2;
+ _ref2 = this.flattenChildren();
+ for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
+ child = _ref2[_i];
+ if ((child instanceof Await) || child.tameGo()) return true;
+ }
+ return false;
+ };
+
Base.prototype.children = [];
Base.prototype.tameContinuationBlock = null;
@@ -635,6 +645,7 @@
};
Block.prototype.tameTransform = function() {
+ if (!this.tameGo()) return this;
this.tameExtractExpressions(true);
this.tameAssignDefersToAwait();
this.tameWalkAst();
View
16 src/cake.coffee
@@ -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
@@ -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
@@ -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.
@@ -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 = ->
View
14 src/nodes.coffee
@@ -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) ->
@@ -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: []
@@ -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()
Please sign in to comment.
Something went wrong with that request. Please try again.