Permalink
Browse files

better idea for dealing with the tame runtime

  • Loading branch information...
1 parent cd491d0 commit 668db1e2e8000ba56a43fd3cc62110bd547a8106 @maxtaco committed with Dec 2, 2011
View
@@ -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.

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

Oops, something went wrong.

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

Oops, something went wrong.

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

Oops, something went wrong.
View

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

Oops, something went wrong.
View
@@ -131,3 +131,6 @@ parser.lexer =
""
parser.yy = require './nodes'
+
+# Export the tame runtime as 'tame'
+exports.tame = tame.runtime
View
@@ -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
@@ -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 }

0 comments on commit 668db1e

Please sign in to comment.