Skip to content

Commit

Permalink
First successful test of a little test script. Need to massage the lo…
Browse files Browse the repository at this point in the history
…cal runtime a little bit better.
  • Loading branch information
maxtaco committed Dec 5, 2012
1 parent dc821d9 commit 0b737ab
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -7,3 +7,4 @@ test/*.js
examples/beautiful_code/parse.coffee examples/beautiful_code/parse.coffee
*.gem *.gem
/node_modules /node_modules
*~
3 changes: 2 additions & 1 deletion Cakefile
Expand Up @@ -29,7 +29,8 @@ header = """


sources = [ sources = [
'coffee-script', 'grammar', 'helpers' 'coffee-script', 'grammar', 'helpers'
'lexer', 'nodes', 'rewriter', 'scope' 'lexer', 'nodes', 'rewriter', 'scope',
'tame', 'tamerun'
].map (filename) -> "src/#{filename}.coffee" ].map (filename) -> "src/#{filename}.coffee"


# Run a CoffeeScript through our node/coffee interpreter. # Run a CoffeeScript through our node/coffee interpreter.
Expand Down
34 changes: 30 additions & 4 deletions lib/coffee-script/nodes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/coffee-script/tame.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions lib/coffee-script/tamerun.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 20 additions & 3 deletions src/nodes.coffee
Expand Up @@ -180,6 +180,11 @@ exports.Base = class Base
@tameNodeFlag = true if child.walkAstTame() @tameNodeFlag = true if child.walkAstTame()
@tameNodeFlag @tameNodeFlag


needsRuntime : ->
for child in @flattenChildren()
return true if child.needsRuntime()
return false

# Walk all loops that are marked as "tamed" and mark their children # Walk all loops that are marked as "tamed" and mark their children
# as being children in a tamed loop. They'll need more translations # as being children in a tamed loop. They'll need more translations
# than other nodes. Eventually, "switch" statements might also be "loops # than other nodes. Eventually, "switch" statements might also be "loops
Expand Down Expand Up @@ -453,12 +458,22 @@ exports.Block = class Block extends Base
return nodes[0] if nodes.length is 1 and nodes[0] instanceof Block return nodes[0] if nodes.length is 1 and nodes[0] instanceof Block
new Block nodes new Block nodes


addRuntime : ->
ns = new Value new Literal tame.const.ns
req = new Value new Literal 'require'
lib = '"' + tame.const.runtime + '"'
call = new Call req, [ new Value new Literal lib ]
assign = new Assign ns, call
@expressions.unshift assign

# Perform all steps of the Tame transform # Perform all steps of the Tame transform
tameTransform : -> tameTransform : ->
@walkAstTame() @walkAstTame()
@addRuntime() if @needsRuntime()
@walkAstTamedLoop(false) @walkAstTamedLoop(false)
@walkCpsPivots() @walkCpsPivots()
@cpsRotate() @cpsRotate()
this


#### Literal #### Literal


Expand Down Expand Up @@ -1438,9 +1453,9 @@ exports.Code = class Code extends Base
@tameLoopFlag = true if super(false) @tameLoopFlag = true if super(false)
false false


walkAstPivots: () -> walkCpsPivots: ->
@cpsPivotFlag = true if super() super()
false @cpsPivotFlag = false


#### Param #### Param


Expand Down Expand Up @@ -1900,6 +1915,8 @@ exports.Defer = class Defer extends Base
scope.add name, 'var' scope.add name, 'var'
@call.compile o @call.compile o


needsRuntime : -> true

#### Await #### Await


exports.Await = class Await extends Base exports.Await = class Await extends Base
Expand Down
6 changes: 6 additions & 0 deletions src/tame.coffee
@@ -1,4 +1,7 @@


#=======================================================================
# Compile Time!
#
exports.AstTamer = class AstTamer exports.AstTamer = class AstTamer


constructor: (rest...) -> constructor: (rest...) ->
Expand All @@ -19,3 +22,6 @@ exports.const =
defer_method : "defer" defer_method : "defer"
slot : "__slot" slot : "__slot"
assign_fn : "assign_fn" assign_fn : "assign_fn"
runtime : "tamerun"


35 changes: 35 additions & 0 deletions src/tamerun.coffee
@@ -0,0 +1,35 @@

#=======================================================================

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
#
exports.Deferrals = class Deferrals

constructor: (k) ->
@continuation = k
@count = 1

_fulfill : ->
@continuation() if --@count == 0

defer : (args) ->
@count++
self = this
return makeDeferReturn self, args, null

#=======================================================================

0 comments on commit 0b737ab

Please sign in to comment.