Slide 34
Slide 34 text
τϥϯϙϦϯԽ
let eval env cont e = match e with
| Exp.Int n -> Res.ApplyCont(env, cont, Val.Int n)
| Exp.Var s -> Res.ApplyCont(env, cont, Env.find env s)
| Exp.Call(e1, e2) -> Res.Eval(env, Cont.Call1(e2)::cont, e1)
let apply_cont env cont v = match cont with
| [] -> Res.Done v
| Cont.Call1(e)::cont' -> Res.Eval(env, Cont.Call2(v)::cont', e)
| Cont.Call2(v')::cont' -> Res.ApplyCont(env, cont', call v' v)
let rec trampoline r = match r with
| Res.Done v -> v
| Res.Eval(env, cont, e) -> trampoline (eval env cont e)
| Res.ApplyCont(env, cont, v) -> trampoline (apply_cont env cont v)
module Res = struct
type t =
| Done of Val.t
| Eval of Env.t * Cont.t * Exp.t
| ApplyCont of Env.t * Cont.t * Val.t
end