Skip to content
Browse files

more code from tamejs, this one from rendezvous. also, fix a broken r…

…egtest due to defer being a reserved coffee word.
  • Loading branch information...
1 parent 71f34d7 commit d3f5a7c50293554f1c1ece270662664ce66857dd maxtaco committed with Dec 5, 2011
Showing with 128 additions and 4 deletions.
  1. +69 −2 lib/coffee-script/tame.js
  2. +58 −2 src/tame.coffee
  3. +1 −0 test/assignment.coffee
View
71 lib/coffee-script/tame.js
@@ -1,5 +1,5 @@
(function() {
- var AstTamer, Deferrals, makeDeferReturn;
+ var AstTamer, Deferrals, Rendezvous, makeDeferReturn;
var __slice = Array.prototype.slice;
exports.AstTamer = AstTamer = (function() {
@@ -75,8 +75,75 @@
})();
+ Rendezvous = (function() {
+ var RvId;
+
+ function Rendezvous() {
+ this.completed = [];
+ this.waiters = [];
+ this.defer_id = 0;
+ this.__tame_defers = this;
+ }
+
+ RvId = (function() {
+
+ function RvId(rv, id) {
+ this.rv = rv;
+ this.id = id;
+ }
+
+ RvId.prototype.defer = function(defer_args) {
+ return this.rv._deferWithId(this.id, defer_args);
+ };
+
+ return RvId;
+
+ })();
+
+ Rendezvous.prototype.wait = function(cb) {
+ var x;
+ if (this.completed.length) {
+ x = this.completed.shift();
+ return cb(x);
+ } else {
+ return this.waiters.push(cb);
+ }
+ };
+
+ Rendezvous.prototype.defer = function(defer_args) {
+ var id;
+ id = this.defer_id++;
+ return this.deferWithId(id, defer_args);
+ };
+
+ Rendezvous.prototype.id = function(i) {
+ return {
+ __tame_defers: new this.RvId(this, i)
+ };
+ };
+
+ Rendezvous.prototype._fulfill = function(id) {
+ var cb;
+ if (this.waiters.length) {
+ cb = this.waiters.shift();
+ return cb(id);
+ } else {
+ return this.completed.push(id);
+ }
+ };
+
+ Rendezvous.prototype._deferWithId = function(id, defer_args) {
+ this.count++;
+ return makeDeferReturn(this, defer_args, id);
+ };
+
+ return Rendezvous;
+
+ })();
+
exports.runtime = {
- Deferrals: Deferrals
+ Deferrals: Deferrals,
+ Rendezvous: Rendezvous
};
}).call(this);
View
60 src/tame.coffee
@@ -1,5 +1,5 @@
-#=======================================================================
+# =======================================================================
# Compile Time!
#
exports.AstTamer = class AstTamer
@@ -60,4 +60,60 @@ class Deferrals
#=======================================================================
-exports.runtime = { Deferrals }
+class Rendezvous
+ constructor: ->
+ @completed = []
+ @waiters = []
+ @defer_id = 0
+ # This is a hack to work with the semantic desugaring of
+ # 'defers' output by the tamejs compiler.
+ @__tame_defers = this
+
+ #-----------------------------------------
+
+ class RvId
+ constructor: (@rv,@id)->
+ defer: (defer_args) ->
+ @rv._deferWithId @id, defer_args
+
+ #-----------------------------------------
+ #
+ # The public interface has 3 methods --- wait, defer and id
+ wait: (cb) ->
+ if @completed.length
+ x = @completed.shift()
+ cb(x)
+ else
+ @waiters.push cb
+
+ #-----------------------------------------
+
+ defer: (defer_args) ->
+ id = @defer_id++
+ @deferWithId id, defer_args
+
+ #-----------------------------------------
+
+ id: (i) ->
+ { __tame_defers : new @RvId(this, i) }
+
+ #-----------------------------------------
+
+ _fulfill: (id) ->
+ if @waiters.length
+ cb = @waiters.shift()
+ cb(id)
+ else
+ @completed.push id
+
+ #-----------------------------------------
+
+ _deferWithId: (id, defer_args) ->
+ @count++
+ makeDeferReturn this, defer_args, id
+
+#=======================================================================
+
+exports.runtime = { Deferrals, Rendezvous }
+
+#=======================================================================
View
1 test/assignment.coffee
@@ -262,6 +262,7 @@ test "#1005: invalid identifiers allowed on LHS of destructuring assignment", ->
throws (-> CoffeeScript.compile tSplat), null, tSplat = "[#{v}...] = x"
doesNotThrow ->
for v in disallowed
+ continue if v is 'defer'
CoffeeScript.compile "[a.#{v}] = x"
CoffeeScript.compile "[a.#{v}...] = x"
CoffeeScript.compile "[@#{v}] = x"

0 comments on commit d3f5a7c

Please sign in to comment.
Something went wrong with that request. Please try again.