32 lines
684 B
Haskell
32 lines
684 B
Haskell
module Gyehoek.CPS.Convert
|
|
( convert
|
|
) where
|
|
|
|
import Gyehoek.CPS.Syntax
|
|
import Gyehoek.Scheme.Syntax qualified as Scm
|
|
import Gyehoek.GenSym
|
|
import Effectful
|
|
import Control.Monad.Cont qualified as Cont
|
|
|
|
|
|
-- 뻘짓이어라
|
|
telescope
|
|
:: Traversable t
|
|
=> (a -> (b -> r) -> r)
|
|
-> t a -> (t b -> r) -> r
|
|
telescope f = Cont.runCont . traverse (Cont.cont . f)
|
|
|
|
convert
|
|
:: forall es. (GenSym :> es)
|
|
=> Scm.Exp -> (Val -> Eff es Exp) -> Eff es Exp
|
|
|
|
convert (Scm.ExpVar x) k = k $ ValVar x
|
|
convert (Scm.ExpLit l) k = k $ ValLit l
|
|
|
|
convert (Scm.ExpPrim p) k =
|
|
telescope (convert @es) p \p' -> do
|
|
r <- gensym' "r"
|
|
ExpPrim p' [r] . pure <$> k (ValVar r)
|
|
|
|
convert _ _ = _
|