diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Eval.dyn_hi b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Eval.dyn_hi index 7ceb1dc..50ed9d3 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Eval.dyn_hi and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Eval.dyn_hi differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Eval.dyn_o b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Eval.dyn_o index a077e28..bd0c05c 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Eval.dyn_o and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Eval.dyn_o differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Eval.hi b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Eval.hi index 7ceb1dc..50ed9d3 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Eval.hi and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Eval.hi differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Eval.o b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Eval.o index a077e28..bd0c05c 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Eval.o and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Eval.o differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpIO.dyn_hi b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpIO.dyn_hi index 65d7da9..a560af1 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpIO.dyn_hi and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpIO.dyn_hi differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpIO.dyn_o b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpIO.dyn_o index 0cc3cbb..510e00c 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpIO.dyn_o and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpIO.dyn_o differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpIO.hi b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpIO.hi index 65d7da9..a560af1 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpIO.hi and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpIO.hi differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpIO.o b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpIO.o index 0cc3cbb..510e00c 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpIO.o and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpIO.o differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpPure.dyn_hi b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpPure.dyn_hi index 42f65bb..4f9749e 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpPure.dyn_hi and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpPure.dyn_hi differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpPure.dyn_o b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpPure.dyn_o index 1636485..d3239f5 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpPure.dyn_o and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpPure.dyn_o differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpPure.hi b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpPure.hi index 42f65bb..4f9749e 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpPure.hi and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpPure.hi differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpPure.o b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpPure.o index 1636485..d3239f5 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpPure.o and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/InterpPure.o differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Interp_Tests.dyn_hi b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Interp_Tests.dyn_hi index 2949765..b2c5ead 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Interp_Tests.dyn_hi and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Interp_Tests.dyn_hi differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Interp_Tests.dyn_o b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Interp_Tests.dyn_o index 044a861..3c1def9 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Interp_Tests.dyn_o and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Interp_Tests.dyn_o differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Interp_Tests.hi b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Interp_Tests.hi index 2949765..b2c5ead 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Interp_Tests.hi and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Interp_Tests.hi differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Interp_Tests.o b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Interp_Tests.o index 044a861..3c1def9 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Interp_Tests.o and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Interp_Tests.o differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Monad.dyn_hi b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Monad.dyn_hi index db421b6..8c81577 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Monad.dyn_hi and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Monad.dyn_hi differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Monad.dyn_o b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Monad.dyn_o index 77dea30..352d084 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Monad.dyn_o and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Monad.dyn_o differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Monad.hi b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Monad.hi index db421b6..8c81577 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Monad.hi and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Monad.hi differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Monad.o b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Monad.o index 00edbb4..eadf3e4 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Monad.o and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Monad.o differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Util.dyn_hi b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Util.dyn_hi index 538375a..f09b8f3 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Util.dyn_hi and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Util.dyn_hi differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Util.dyn_o b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Util.dyn_o index e415bb1..c60ba27 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Util.dyn_o and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Util.dyn_o differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Util.hi b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Util.hi index 538375a..f09b8f3 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Util.hi and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Util.hi differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Util.o b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Util.o index e7cef6d..e389140 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Util.o and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/APL/Util.o differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/libHSa4-1.0.0.0-inplace-ghc9.2.8.so b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/libHSa4-1.0.0.0-inplace-ghc9.2.8.so index aac81d9..423e45c 100755 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/libHSa4-1.0.0.0-inplace-ghc9.2.8.so and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/libHSa4-1.0.0.0-inplace-ghc9.2.8.so differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/libHSa4-1.0.0.0-inplace.a b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/libHSa4-1.0.0.0-inplace.a index aab51b9..70b92fb 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/libHSa4-1.0.0.0-inplace.a and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/build/libHSa4-1.0.0.0-inplace.a differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/cache/build b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/cache/build index 3c07cbf..272d881 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/cache/build and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/cache/build differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/t/a4-test/build/a4-test/a4-test-tmp/Main.dyn_hi b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/t/a4-test/build/a4-test/a4-test-tmp/Main.dyn_hi index 4b10687..8f09f78 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/t/a4-test/build/a4-test/a4-test-tmp/Main.dyn_hi and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/t/a4-test/build/a4-test/a4-test-tmp/Main.dyn_hi differ diff --git a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/t/a4-test/cache/build b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/t/a4-test/cache/build index 4c2fe68..2799101 100644 Binary files a/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/t/a4-test/cache/build and b/a4/dist-newstyle/build/x86_64-linux/ghc-9.2.8/a4-1.0.0.0/t/a4-test/cache/build differ diff --git a/a4/src/APL/InterpPure.hs b/a4/src/APL/InterpPure.hs index 5a39474..46745c1 100644 --- a/a4/src/APL/InterpPure.hs +++ b/a4/src/APL/InterpPure.hs @@ -15,6 +15,12 @@ runEval = runEval' envEmpty stateInitial in (p : ps, res) runEval' r s (Free (TryCatchOp m l)) = case (runEval' r s m) of - (_, Left e) -> runEval' r s l + (_, Left _) -> runEval' r s l a -> a + runEval' r s (Free (KvGetOp key k)) = + case (lookup key s) of + Just val -> runEval' r s $ k val + Nothing -> ([], Left "Cannot find key :)") + runEval' r s (Free (KvPutOp key val m)) = + runEval' r ((key,val):s) m runEval' _ _ (Free (ErrorOp e)) = ([], Left e) diff --git a/a4/src/APL/Interp_Tests.hs b/a4/src/APL/Interp_Tests.hs index 7cb5525..eacb4dd 100644 --- a/a4/src/APL/Interp_Tests.hs +++ b/a4/src/APL/Interp_Tests.hs @@ -81,7 +81,23 @@ pureTests = -- testCase "TryCatch catch1" $ eval' (TryCatch (Div (CstInt 1) (CstInt 0)) (Div (CstInt 1) (CstInt 0))) - @?= ([], Left "Division by zero") + @?= ([], Left "Division by zero"), + -- + testCase "KvPutOp" $ + eval' (KvPut (CstInt 1) (CstInt 2)) + @?= ([], Right (ValInt 2)), + -- + testCase "KvGetOp" $ + eval' (Let "_" (KvPut (CstInt 1) (CstInt 2)) (KvGet (CstInt 1))) + @?= ([], Right (ValInt 2)), + -- + testCase "KvGetOp shadowing" $ + eval' (Let "_" (KvPut (CstInt 1) (CstInt 2)) (Let "_" (KvPut (CstInt 1) (CstInt 3)) (KvGet (CstInt 1)))) + @?= ([], Right (ValInt 3)), + -- + testCase "KvGetOp fail" $ + eval' (KvGet (CstInt 1)) + @?= ([], Left "Cannot find key :)") ] ioTests :: TestTree @@ -96,16 +112,13 @@ ioTests = runEvalIO $ do evalPrint s1 evalPrint s2 - (out, res) @?= ([s1, s2], Right ()) - -- NOTE: This test will give a runtime error unless you replace the - -- version of `eval` in `APL.Eval` with a complete version that supports - -- `Print`-expressions. Uncomment at your own risk. - -- testCase "print 2" $ do - -- (out, res) <- - -- captureIO [] $ - -- evalIO' $ - -- Print "This is also 1" $ - -- Print "This is 1" $ - -- CstInt 1 - -- (out, res) @?= (["This is 1: 1", "This is also 1: 1"], Right $ ValInt 1) + (out, res) @?= ([s1, s2], Right ()), + testCase "print 2" $ do + (out, res) <- + captureIO [] $ + evalIO' $ + Print "This is also 1" $ + Print "This is 1" $ + CstInt 1 + (out, res) @?= (["This is 1: 1", "This is also 1: 1"], Right $ ValInt 1) ] diff --git a/a4/src/APL/Monad.hs b/a4/src/APL/Monad.hs index 3bdf3f7..83b7d48 100644 --- a/a4/src/APL/Monad.hs +++ b/a4/src/APL/Monad.hs @@ -77,6 +77,8 @@ data EvalOp a | PrintOp String a | ErrorOp Error | TryCatchOp a a + | KvGetOp Val (Val -> a) + | KvPutOp Val Val a instance Functor EvalOp where fmap f (ReadOp k) = ReadOp $ f . k @@ -85,6 +87,8 @@ instance Functor EvalOp where fmap f (PrintOp p m) = PrintOp p $ f m fmap _ (ErrorOp e) = ErrorOp e fmap f (TryCatchOp m1 m2) = TryCatchOp (f m1) (f m2) + fmap f (KvGetOp v k) = KvGetOp v (f . k) + fmap f (KvPutOp v1 v2 m) = KvPutOp v1 v2 (f m) type EvalM a = Free EvalOp a @@ -122,10 +126,10 @@ catch :: EvalM a -> EvalM a -> EvalM a catch m1 m2 = Free $ TryCatchOp m1 m2 evalKvGet :: Val -> EvalM Val -evalKvGet = error "TODO" +evalKvGet v = Free $ KvGetOp v $ \w -> pure w evalKvPut :: Val -> Val -> EvalM () -evalKvPut = error "TODO" +evalKvPut v1 v2 = Free $ KvPutOp v1 v2 $ pure () transaction :: EvalM () -> EvalM () transaction = error "TODO"