Skip to content

Commit

Permalink
Start translating handler
Browse files Browse the repository at this point in the history
  • Loading branch information
b-studios committed Nov 24, 2023
1 parent 21ff024 commit 497616f
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,14 @@ object TransformerDS {
case Return(e) =>
Return(toJS(e))

// const exc = { raise: ... }; try { }
case Try(core.BlockLit(_, _, _, bps, body), hs) =>
val suspension = freshName("suspension")
val handlerDefs = (bps zip hs) map {
case (param, handler) => js.Const(toJS(param), toJS(handler))
}
// TODO implement properly
bindingLocals(all(bps, bound)) { toJS(body) }
Bind { k => handlerDefs ++ List(js.Try(bindingLocals(all(bps, bound)) { toJS(body)(k) }, suspension, List())) }

case Try(_, _) =>
Context.panic("Body of the try is expected to be a block literal in core.")
Expand All @@ -226,7 +231,12 @@ object TransformerDS {
}

def toJS(handler: core.Implementation)(using DeclarationContext, Locals, Continuations, Context): js.Expr =
Context.panic("`run` not implemented, yet...")
js.Object(handler.operations.map {
case Operation(id, tps, cps, vps, bps, resume, body) =>
nameDef(id) -> js.Lambda((vps ++ bps ++ resume.toList) map toJS, bindingLocals(all(vps, bound) ++ all(bps, bound) ++ all(resume, bound)) {
js.Block(toJS(body)(x => js.Return(x))) // return here is dangerous...
})
})

def toJS(d: core.Definition)(using DC: DeclarationContext, L: Locals, K: Continuations, C: Context): List[js.Stmt] = d match {
case Definition.Def(id, BlockLit(tps, cps, vps, bps, body)) =>
Expand Down

0 comments on commit 497616f

Please sign in to comment.