Skip to content

Commit

Permalink
rename vars in resume, added some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuoguo committed Nov 16, 2024
1 parent a250924 commit f810983
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/main/scala/wasm/MiniWasmFX.scala
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ case class EvaluatorFX(module: ModuleInstance) {
// resumable try-catch exception handling:
case TryCatch(es1, es2) =>
val join: MCont[Ans] = (newStack) => eval(rest, stack, frame, kont, mkont, trail, h)
// the `restK` for catch block (es2) is the join point
// the restK simply applies the meta-continuation, this is the same the [nil] case
// where we fall back to join point
val idK: Cont[Ans] = (s, m) => m(s)
val newHandler: Handler[Ans] = (newStack) => eval(es2, newStack, frame, idK, join, trail, h)
eval(es1, List(), frame, idK, join, trail, newHandler)
Expand All @@ -228,9 +231,12 @@ case class EvaluatorFX(module: ModuleInstance) {
resume.k(List(), k, mkont)
case Throw() =>
val err :: newStack = stack
def kr(s: Stack, k: Cont[Ans], m: MCont[Ans]): Ans = {
val k1: Cont[Ans] = (s1, m1) => kont(s1, s2 => k(s2, m1))
eval(rest, newStack/*!*/, frame, k1, m/*vs mkont?*/, trail, h)
// kont composed with k
// note that kr doesn't use the stack at all
// it only takes the err value
def kr(s: Stack, k1: Cont[Ans], m: MCont[Ans]): Ans = {
val kontK: Cont[Ans] = (s1, m1) => kont(s1, s2 => k1(s2, m1))
eval(rest, newStack/*!*/, frame, kontK, m/*vs mkont?*/, trail, h)
}
h(List(err, TCContV(kr)))
case _ =>
Expand Down

0 comments on commit f810983

Please sign in to comment.