never executed always true always false
    1 module HelVM.HelMA.Automaton.Optimizer.MarkRemovingOptimizer (
    2   makrRemoving,
    3 ) where
    4 
    5 import           HelVM.HelMA.Automaton.Instruction
    6 
    7 import           HelVM.HelMA.Automaton.Instruction.Extras.Constructors
    8 import           HelVM.HelMA.Automaton.Instruction.Extras.Patterns
    9 
   10 import qualified Data.Set                                              as Set
   11 
   12 makrRemoving :: InstructionList -> InstructionList
   13 makrRemoving il = catMaybes $ makrRemovingWithSet set <$> il where set = consValueSet il
   14 
   15 makrRemovingWithSet :: Set Integer -> Instruction -> Maybe Instruction
   16 makrRemovingWithSet set (MNaturalP i) = mark set i
   17 makrRemovingWithSet _              i  = Just i
   18 
   19 mark :: Set.Set Integer -> Natural -> Maybe Instruction
   20 mark set i = build $ Set.member (fromIntegral i) set where
   21   build True  = Just $ markNI i
   22   build False = Nothing
   23 
   24 consValueSet :: InstructionList -> Set.Set Integer
   25 consValueSet il = fromList $ catMaybes $ consValueOpt <$> il
   26 
   27 consValueOpt :: Instruction -> Maybe Integer
   28 consValueOpt (ConsP i) = Just i
   29 consValueOpt        _  = Nothing