From c495fc064a8e27f8d3f8885a9138c3f4ce288e1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madeleine=20Sydney=20=C5=9Alaga?= Date: Sat, 5 Sep 2026 19:56:10 -0600 Subject: [PATCH] arith prims --- src/Gyehoek/CPS/Eval.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 _