Permalink
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...
maxtaco authored and maxtaco committed Dec 6, 2011
1 parent 71f34d7 commit d3f5a7c50293554f1c1ece270662664ce66857dd
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

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -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
@@ -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.