never executed always true always false
    1 module HelVM.HelMA.Automata.BrainFuck.Impl.Flat.TableOfInstructions where
    2 
    3 import           HelVM.HelMA.Automata.BrainFuck.Impl.Flat.Instruction
    4 
    5 type HalfTable = FlatTreeInstructionList
    6 type Table = (HalfTable , HalfTable)
    7 type TableD = Table -> Table
    8 
    9 currentInstruction :: ([a], [a]) -> Maybe a
   10 currentInstruction (_ , i : _) = Just i
   11 currentInstruction (_ ,    []) = Nothing
   12 
   13 prevInst :: TableD
   14 prevInst (inst : prev , next) = (prev , inst : next)
   15 prevInst ([] , _)             = error "End of the table"
   16 
   17 nextInst :: TableD
   18 nextInst (prev , inst : next) = (inst : prev , next)
   19 nextInst (_ , [])             = error "End of the table"
   20 
   21 matchPrevJmp :: TableD
   22 matchPrevJmp table@(JmpPast : _ , _) =                                      table
   23 matchPrevJmp table@(JmpBack : _ , _) = (matchPrevJmp . prevInst . jumpBack) table
   24 matchPrevJmp table                   =                            jumpBack  table
   25 
   26 matchNextJmp :: TableD
   27 matchNextJmp table@(_ , JmpBack : _) =                 nextInst  table
   28 matchNextJmp table@(_ , JmpPast : _) = (matchNextJmp . jumpPast) table
   29 matchNextJmp table                   =                 jumpPast  table
   30 
   31 jumpPast :: TableD
   32 jumpPast = matchNextJmp . nextInst
   33 
   34 jumpBack :: TableD
   35 jumpBack = matchPrevJmp . prevInst