never executed always true always false
    1 module HelVM.HelMA.Automata.BrainFuck.Common.Symbol (
    2   inc,
    3   compare0,
    4   def,
    5   next,
    6   prev,
    7   toInteger,
    8   fromChar,
    9   toChar,
   10   Symbol,
   11 ) where
   12 
   13 import           Data.Default (Default)
   14 
   15 import qualified Data.Default as Default
   16 import qualified Relude.Extra as Extra
   17 
   18 inc :: Symbol e => e -> e -> e
   19 inc = flip (+)
   20 
   21 compare0 :: Integer -> Ordering
   22 compare0 = compare 0
   23 
   24 --
   25 
   26 def :: Symbol e => e
   27 def = Default.def
   28 
   29 next :: Symbol e => e -> e
   30 next = Extra.next
   31 
   32 prev :: Symbol e => e -> e
   33 prev = Extra.prev
   34 
   35 class (Bounded e , Default e , Enum e , Eq e , Integral e , Show e) => Symbol e where
   36 --  toInteger  :: e -> Integer
   37   fromChar   :: Char -> e
   38   toChar     :: e -> Char
   39 
   40 --
   41 
   42 instance Symbol Int where
   43 --  toInteger  = fromIntegral
   44   fromChar   = ord
   45   toChar     = chr
   46 
   47 instance Symbol Word where
   48 --  toInteger  = fromIntegral
   49   fromChar   = fromIntegral . ord
   50   toChar     = chr . fromIntegral
   51 
   52 instance Symbol Int8 where
   53 --  toInteger  = fromIntegral
   54   fromChar   = fromIntegral . ord
   55   toChar     = chr . normalizeMod . fromIntegral
   56 
   57 instance Symbol Word8 where
   58 --  toInteger  = fromIntegral
   59   fromChar   = fromIntegral . ord
   60   toChar     = chr . fromIntegral
   61 
   62 instance Symbol Int16 where
   63 --  toInteger  = fromIntegral
   64   fromChar   = fromIntegral . ord
   65   toChar     = chr . normalizeMod . fromIntegral
   66 
   67 instance Symbol Word16 where
   68 --  toInteger  = fromIntegral
   69   fromChar   = fromIntegral . ord
   70   toChar     = chr . fromIntegral
   71 
   72 instance Symbol Int32 where
   73 --  toInteger  = fromIntegral
   74   fromChar   = fromIntegral . ord
   75   toChar     = chr . normalizeMod . fromIntegral
   76 
   77 instance Symbol Word32 where
   78 --  toInteger  = fromIntegral
   79   fromChar   = fromIntegral . ord
   80   toChar     = chr . fromIntegral
   81 
   82 instance Symbol Int64 where
   83 --  toInteger  = fromIntegral
   84   fromChar   = fromIntegral . ord
   85   toChar     = chr . normalizeMod . fromIntegral
   86 
   87 instance Symbol Word64 where
   88 --  toInteger  = fromIntegral
   89   fromChar   = fromIntegral . ord
   90   toChar     = chr . fromIntegral
   91 --
   92 
   93 countSymbols :: (Integral e) => e
   94 countSymbols = 256
   95 
   96 modifyMod :: (Integral e) => (e -> e) -> e -> e
   97 modifyMod f i = f (i + countSymbols) `mod` countSymbols
   98 
   99 normalizeMod :: (Integral e) => e -> e
  100 normalizeMod = modifyMod id