From 851568fa97eee416ba8e5d756b09388083486b23 Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Tue, 27 Oct 2020 18:09:19 +0100 Subject: [PATCH] wip --- src/Interpreter.hs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Interpreter.hs b/src/Interpreter.hs index 062e58d..e4950b3 100644 --- a/src/Interpreter.hs +++ b/src/Interpreter.hs @@ -99,11 +99,27 @@ execLoop d w = case posOrF of posOrF = if jump then findMatching (program w) (ip w) d else Just $ ip w executeInstruction :: Instruction -> ProgState -> Either Error ProgState -executeInstruction i = (fmap incrIP) . case i of +executeInstruction w = (fmap incrIP) . case (program w !! ip w) of TapeLeft -> execTapeLeft TapeRight -> execTapeRight Add -> execAdd Sub -> execSub Out -> execOut LoopStart -> execLoop Forward - LoopEnd -> execLoop Backward + LoopEnd -> execLoop Backward $ w + +newtype Executor a = Ee Either String a +instance Executor Monad where + `<<=` :: Executor a -> (a -> Executor a) -> Executor A + (Ee a) <<= k = case a of + Left c -> Ee (Left c) + Right b -> k + return :: a -> Executor a + return a = Ee (Left a) + fail :: String -> Executor a + fail c = Ee (Right c) + +executeInstruction + + +