diff --git a/src/Gyehoek/CPS/Eval.hs b/src/Gyehoek/CPS/Eval.hs index 1d780d8..f30a3c1 100644 --- a/src/Gyehoek/CPS/Eval.hs +++ b/src/Gyehoek/CPS/Eval.hs @@ -211,8 +211,26 @@ eval g dps (ExpLetRec bs e) = do traverse_ (uncurry assign) $ zip ls (bs' ^.. each . _2) eval g' dps e +eval g dps (ExpPrim p k) = do + p' <- evalPrim g =<< traverse (evalVal g) p + evalKexp g k >>= \case + EProcedure fp -> fp p' dps + _ -> wrong [i|prim(#{p})의 계속을 나쁘다|] + eval g dps e = error [i|unimplemented #{e}|] +evalPrim :: Env -> Prim E -> M Answer (List E) +evalPrim g = \case + PrimAdd x y -> arith2 (+) x y + PrimMul x y -> arith2 (*) x y + PrimSub x y -> arith2 (-) x y + PrimDiv x y -> arith2 div x y + PrimValues xs -> pure xs + p -> wrong [i|prim(#{p})은 벌써 나지 않다|] + where + arith2 f (EInt x) (EInt y) = pure [EInt $ f x y] + arith2 f x y = wrong [i|나쁜 인자: #{x}, #{y}|] + evalExp :: Jalmot :> es => Exp -> Eff es _