never executed always true always false
1 module HelVM.HelMA.Automata.ETA.Addressing (
2 genericFindAddress,
3 findAddress,
4 genericNextLabel,
5 nextLabel
6 ) where
7
8 import HelVM.HelMA.Automata.ETA.Symbol
9 import HelVM.HelMA.Automata.ETA.Token
10
11 import HelVM.HelIO.Containers.LLIndexSafe
12
13 import HelVM.HelIO.Control.Safe
14
15 import Data.ListLike hiding (show)
16
17 import Prelude hiding (length, splitAt)
18
19 import qualified Data.Vector as Vector
20
21 ----
22
23 genericFindAddress :: (MonadSafe m , Integral cell) => Vector.Vector Token -> cell -> m InstructionAddress
24 genericFindAddress il = findAddress il . fromIntegral
25
26 findAddress :: MonadSafe m => Vector.Vector Token -> Int -> m InstructionAddress
27 findAddress _ 1 = pure 0
28 findAddress il address = appendErrorTupleList [("il" , show il) , ("address" , show address)] ((+1) <$> indexSafe (Vector.elemIndices R il) (address-2))
29
30 ----
31
32 genericNextLabel :: Integral cell => Vector.Vector Token -> InstructionAddress -> cell
33 genericNextLabel il = fromIntegral . nextLabel il
34
35 nextLabel :: Vector.Vector Token -> InstructionAddress -> Int
36 nextLabel il ic = length (Vector.elemIndices R il') + 2 where (il' , _) = splitAt ic il