Permalink
Browse files

support for switch statements

  • Loading branch information...
1 parent 242fad0 commit 514750117d7198ac293e3ee7fdee7cd489062ae7 @maxtaco committed with Dec 4, 2011
Showing with 29 additions and 11 deletions.
  1. +12 −1 lib/coffee-script/nodes.js
  2. +17 −10 src/nodes.coffee
Oops, something went wrong.
View
@@ -2195,6 +2195,12 @@ exports.Switch = class Switch extends Base
@otherwise?.makeReturn res
this
+ callContinuation : ->
+ code = CALL_CONTINUATION()
+ for [condition,block] in @cases
+ block.push code
+ @otherwise?.push code
+
compileNode: (o) ->
idt1 = o.indent + TAB
idt2 = o.indent = idt1 + TAB
@@ -2255,7 +2261,8 @@ exports.If = class If extends Base
# to be a statement. Otherwise a conditional operator is safe.
isStatement: (o) ->
o?.level is LEVEL_TOP or
- @bodyNode().isStatement(o) or @elseBodyNode()?.isStatement(o)
+ @bodyNode().isStatement(o) or @elseBodyNode()?.isStatement(o) or
+ @hasContinuation()
jumps: (o) -> @body.jumps(o) or @elseBody?.jumps(o)
@@ -2362,7 +2369,7 @@ CpsCascade =
InlineDeferral =
# Generate this code, inline. Is there a better way?
- #
+ #
# tame =
# Deferrals : class
# constructor: (@continuation) ->
@@ -2374,18 +2381,18 @@ InlineDeferral =
# (inner_params...) =>
# defer_params?.assign_fn?.apply(null, inner_params)
# @_fulfill()
- #
+ #
generate : ->
k = new Literal "continuation"
cnt = new Literal "count"
cn = new Value new Literal tame.const.Deferrals
ns = new Value new Literal tame.const.ns
# make the constructor:
- #
+ #
# constructor: (@continuation) ->
# @count = 1
- #
+ #
k_member = new Value new Literal "this"
k_member.add new Access k
p1 = new Param k_member
@@ -2399,10 +2406,10 @@ InlineDeferral =
constructor_assign = new Assign constructor_name, constructor_code
# make the _fulfill member:
- #
+ #
# _fulfill : ->
# @continuation if ! --@count
- #
+ #
if_expr = new Call k_member, []
if_body = new Block [ if_expr ]
decr = new Op '--', cnt_member
@@ -2419,7 +2426,7 @@ InlineDeferral =
# (inner_params...) =>
# defer_params?.assign_fn?.apply(null, inner_params)
# @_fulfill()
- #
+ #
inc = new Op "++", cnt_member
ip = new Literal "inner_params"
dp = new Literal "defer_params"
@@ -2447,10 +2454,10 @@ InlineDeferral =
obj = new Obj assignments, true
body = new Block [ new Value obj ]
klass = new Class null, null, body
-
+
# tame =
# Deferrals : <class>
- #
+ #
klass_assign = new Assign cn, klass, "object"
ns_obj = new Obj [ klass_assign ], true
ns_val = new Value ns_obj

0 comments on commit 5147501

Please sign in to comment.