我在这里有一个以下 Koka 片段,我希望有人解释调用处理程序时堆栈帧会发生什么。我试图通过打印值和全局计数器来使处理程序堆栈帧也可见,并且在表达时我已经脱糖。
effect foo<a> { control foo() : a }
fun main() {
var c:int := 0
val r = (handler {
return(x:int) { println("in RET ctrl: " ++ x.show); x*2 }
control foo() {
c := c + 1
val this_c:int = c
println("in FOO ctrl_1. c is: " ++ c.show)
val r1 = resume(3)
println("in FOO ctrl_2, r1: " ++ r1.show ++ " this_c is: " ++ this_c.show)
r1*3
}
})(fn(){
println("throw first foo")
val first:int = foo()
println("throw second foo, first: " ++ first.show)
val snd:int = foo()
println("got second: " ++ snd.show ++ " RET SUM: " ++ (first + snd).show)
(first + snd)
})
println(r)
}
结果如下:
throw first foo
in FOO ctrl_1. c is: 1
throw second foo, first: 3
in FOO ctrl_1. c is: 2
got second: 3 RET SUM: 6
in RET ctrl: 6
in FOO ctrl_2, r1: 12 this_c is: 2
in FOO ctrl_2, r1: 36 this_c is: 1
108
两个“FOO_CTRL”处理程序框架现在如何位于原始 FN() 调用以及 RET 处理程序下方?