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 + + +