Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

better idea for dealing with the tame runtime

  • Loading branch information...
commit 668db1e2e8000ba56a43fd3cc62110bd547a8106 1 parent cd491d0
@maxtaco authored
View
2  Cakefile
@@ -30,7 +30,7 @@ header = """
sources = [
'coffee-script', 'grammar', 'helpers'
'lexer', 'nodes', 'rewriter', 'scope',
- 'tame', 'tamerun'
+ 'tame'
].map (filename) -> "src/#{filename}.coffee"
# Run a CoffeeScript through our node/coffee interpreter.
View
2  lib/coffee-script/coffee-script.js
@@ -149,4 +149,6 @@
parser.yy = require('./nodes');
+ exports.tame = tame.runtime;
+
}).call(this);
View
8 lib/coffee-script/nodes.js
@@ -541,12 +541,14 @@
};
Block.prototype.addRuntime = function() {
- var assign, call, lib, ns, req;
+ var assign, call, lib, ns, req, rhs;
ns = new Value(new Literal(tame["const"].ns));
req = new Value(new Literal('require'));
- lib = '"' + tame["const"].runtime + '"';
+ lib = '"coffee-script"';
call = new Call(req, [new Value(new Literal(lib))]);
- assign = new Assign(ns, call);
+ rhs = new Value(call);
+ rhs.add(new Access(ns));
+ assign = new Assign(ns, rhs);
return this.expressions.unshift(assign);
};
View
1  lib/coffee-script/parser.js
@@ -1,6 +1,5 @@
/* Jison generated parser */
var parser = (function(){
-undefined
var parser = {trace: function trace() { },
yy: {},
symbols_: {"error":2,"Root":3,"Body":4,"Block":5,"TERMINATOR":6,"Line":7,"Expression":8,"Statement":9,"Return":10,"Throw":11,"Comment":12,"STATEMENT":13,"Await":14,"AWAIT":15,"Value":16,"Invocation":17,"Code":18,"Operation":19,"Assign":20,"If":21,"Try":22,"While":23,"For":24,"Switch":25,"Class":26,"Defer":27,"INDENT":28,"OUTDENT":29,"Identifier":30,"IDENTIFIER":31,"AlphaNumeric":32,"NUMBER":33,"STRING":34,"Literal":35,"JS":36,"REGEX":37,"BOOL":38,"Assignable":39,"=":40,"AssignObj":41,"ObjAssignable":42,":":43,"ThisProperty":44,"RETURN":45,"HERECOMMENT":46,"PARAM_START":47,"ParamList":48,"PARAM_END":49,"FuncGlyph":50,"->":51,"=>":52,"OptComma":53,",":54,"Param":55,"ParamVar":56,"...":57,"Array":58,"Object":59,"Splat":60,"SimpleAssignable":61,"Accessor":62,"Parenthetical":63,"Range":64,"This":65,".":66,"?.":67,"::":68,"Index":69,"INDEX_START":70,"IndexValue":71,"INDEX_END":72,"INDEX_SOAK":73,"Slice":74,"{":75,"AssignList":76,"}":77,"CLASS":78,"EXTENDS":79,"OptFuncExist":80,"Arguments":81,"SUPER":82,"DEFER":83,"FUNC_EXIST":84,"CALL_START":85,"CALL_END":86,"ArgList":87,"THIS":88,"@":89,"[":90,"]":91,"RangeDots":92,"..":93,"Arg":94,"SimpleArgs":95,"TRY":96,"Catch":97,"FINALLY":98,"CATCH":99,"THROW":100,"(":101,")":102,"WhileSource":103,"WHILE":104,"WHEN":105,"UNTIL":106,"Loop":107,"LOOP":108,"ForBody":109,"FOR":110,"ForStart":111,"ForSource":112,"ForVariables":113,"OWN":114,"ForValue":115,"FORIN":116,"FOROF":117,"BY":118,"SWITCH":119,"Whens":120,"ELSE":121,"When":122,"LEADING_WHEN":123,"IfBlock":124,"IF":125,"POST_IF":126,"UNARY":127,"-":128,"+":129,"--":130,"++":131,"?":132,"MATH":133,"SHIFT":134,"COMPARE":135,"LOGIC":136,"RELATION":137,"COMPOUND_ASSIGN":138,"$accept":0,"$end":1},
View
49 lib/coffee-script/tame.js
@@ -1,5 +1,5 @@
(function() {
- var AstTamer;
+ var AstTamer, Deferrals, makeDeferReturn;
var __slice = Array.prototype.slice;
exports.AstTamer = AstTamer = (function() {
@@ -33,4 +33,51 @@
runtime: "tamerun"
};
+ makeDeferReturn = function(obj, defer_args, id) {
+ var k, ret, _i, _len, _ref;
+ ret = function() {
+ var inner_args, _ref;
+ inner_args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
+ if (defer_args != null) {
+ if ((_ref = defer_args.assign_fn) != null) _ref.apply(null, inner_args);
+ }
+ return obj._fulfill(id);
+ };
+ if (defer_args) {
+ ret.__tame_trace = {};
+ _ref = ["parent_cb", "file", "line", "func_name"];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ k = _ref[_i];
+ ret.__tame_trace[k] = defer_args[k];
+ }
+ }
+ return ret;
+ };
+
+ Deferrals = (function() {
+
+ function Deferrals(k) {
+ this.continuation = k;
+ this.count = 1;
+ }
+
+ Deferrals.prototype._fulfill = function() {
+ if (--this.count === 0) return this.continuation();
+ };
+
+ Deferrals.prototype.defer = function(args) {
+ var self;
+ this.count++;
+ self = this;
+ return makeDeferReturn(self, args, null);
+ };
+
+ return Deferrals;
+
+ })();
+
+ exports.runtime = {
+ Deferrals: Deferrals
+ };
+
}).call(this);
View
3  src/coffee-script.coffee
@@ -131,3 +131,6 @@ parser.lexer =
""
parser.yy = require './nodes'
+
+# Export the tame runtime as 'tame'
+exports.tame = tame.runtime
View
10 src/nodes.coffee
@@ -462,9 +462,11 @@ exports.Block = class Block extends Base
addRuntime : ->
ns = new Value new Literal tame.const.ns
req = new Value new Literal 'require'
- lib = '"' + tame.const.runtime + '"'
+ lib = '"coffee-script"'
call = new Call req, [ new Value new Literal lib ]
- assign = new Assign ns, call
+ rhs = new Value call
+ rhs.add new Access ns
+ assign = new Assign ns, rhs
@expressions.unshift assign
# Perform all steps of the Tame transform
@@ -2092,7 +2094,7 @@ exports.For = class For extends While
ref_val_copy.add new Index ival
a4 = new Assign @name, ref_val_copy
body.unshift a4
-
+
b = @tameWrap { condition, body, init, step }
b.compile o
@@ -2123,7 +2125,7 @@ exports.For = class For extends While
idt1 = @tab + TAB
return code if code = @compileTame o, { ivar, stepvar, body }
-
+
if @range
forPart = source.compile merge(o, {index: ivar, name, @step})
else
View
38 src/tame.coffee
@@ -1,7 +1,7 @@
#=======================================================================
# Compile Time!
-#
+#
exports.AstTamer = class AstTamer
constructor: (rest...) ->
@@ -24,4 +24,40 @@ exports.const =
assign_fn : "assign_fn"
runtime : "tamerun"
+#=======================================================================
+# runtime
+
+makeDeferReturn = (obj, defer_args, id) ->
+ ret = (inner_args...) ->
+ defer_args?.assign_fn?.apply(null, inner_args)
+ obj._fulfill id
+
+ if defer_args
+ ret.__tame_trace = {}
+ for k in [ "parent_cb", "file", "line", "func_name" ]
+ ret.__tame_trace[k] = defer_args[k]
+
+ ret
+
+#-----------------------------------------------------------------------
+# Deferrals
+#
+# A collection of Deferrals that can
+#
+class Deferrals
+
+ constructor: (k) ->
+ @continuation = k
+ @count = 1
+
+ _fulfill : ->
+ @continuation() if --@count == 0
+
+ defer : (args) ->
+ @count++
+ self = this
+ return makeDeferReturn self, args, null
+
+#=======================================================================
+exports.runtime = { Deferrals }
Please sign in to comment.
Something went wrong with that request. Please try again.