wip
This commit is contained in:
parent
d12b9590b7
commit
851568fa97
1 changed files with 18 additions and 2 deletions
|
@ -99,11 +99,27 @@ execLoop d w = case posOrF of
|
||||||
posOrF = if jump then findMatching (program w) (ip w) d else Just $ ip w
|
posOrF = if jump then findMatching (program w) (ip w) d else Just $ ip w
|
||||||
|
|
||||||
executeInstruction :: Instruction -> ProgState -> Either Error ProgState
|
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
|
TapeLeft -> execTapeLeft
|
||||||
TapeRight -> execTapeRight
|
TapeRight -> execTapeRight
|
||||||
Add -> execAdd
|
Add -> execAdd
|
||||||
Sub -> execSub
|
Sub -> execSub
|
||||||
Out -> execOut
|
Out -> execOut
|
||||||
LoopStart -> execLoop Forward
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue