diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2018-04-15 10:22:54 +0200 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2018-04-15 10:23:13 +0200 |
commit | 2a00a57fe78acd0b435c897016850aa92aba91a0 (patch) | |
tree | 2af62d935988bed936ba8b61f36b467bad382b4a | |
parent | 32147b215e5066545e4f971384f6f9c2865354fd (diff) |
-rw-r--r-- | Interpreter.hs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/Interpreter.hs b/Interpreter.hs index 4f3f3aa..690b23d 100644 --- a/Interpreter.hs +++ b/Interpreter.hs @@ -17,28 +17,28 @@ interInss :: Int -> Tape -> Int -> [Instruction] -> [Byte] -> IO [Byte] interInss _ _ _ [] _ = return [] -- interInss count _ _ _ _ | count > 2000000000 = return [] interInss !count !tape !memp allinss@(ins:rest) inp = case ins of - (IAdd value offset) -> do + IAdd value offset -> do MV.modify tape (+ value) (memp + offset) interInss (count + 1) tape memp rest inp - (ISet value offset) -> do + ISet value offset -> do MV.write tape (memp + offset) value interInss (count + 1) tape memp rest inp - (ICopy from to mult) -> do + ICopy from to mult -> do value <- MV.read tape (memp + from) MV.modify tape ((+) (mult * value)) (memp + to) interInss (count + 1) tape memp rest inp - (ISlide offset) -> do + ISlide offset -> do interInss (count + 1) tape (memp + offset) rest inp - (ILoop iins offset) -> do + ILoop iins offset -> do value <- MV.read tape (memp + offset) if value /= 0 then interInss (count + 1) tape memp (iins ++ allinss) inp else interInss (count + 1) tape memp rest inp - (IInput offset) -> do + IInput offset -> do let (c:cs) = inp MV.write tape (memp + offset) c interInss (count + 1) tape memp rest cs - (IOutput offset) -> do + IOutput offset -> do value <- MV.read tape (memp + offset) (value :) <$> interInss (count + 1) tape memp rest inp IStart -> do |