never executed always true always false
    1 module HelVM.HelMA.Automaton.Instruction.Groups.CFInstruction where
    2 
    3 import           HelVM.HelMA.Automaton.Instruction.Extras.TextExtra
    4 
    5 import           HelVM.HelIO.Collections.SList
    6 
    7 -- | Others
    8 
    9 isNotJump :: Integral e => BranchTest -> e -> Bool
   10 isNotJump t = not . isJump t
   11 
   12 isJump :: Integral e => BranchTest -> e -> Bool
   13 isJump NE  e = e /= 0
   14 isJump EZ  e = e == 0
   15 isJump LTZ e = e <  0
   16 isJump GTZ e = e >  0
   17 
   18 -- | Types
   19 data CFInstruction =
   20     Mark     !Mark
   21   | Branch  !BranchOperand !BranchTest
   22   | Labeled !LabelOperand !LabelOperation
   23   | Return
   24   deriving stock (Eq , Read , Show)
   25 
   26 data Mark  = MNatural Natural | MArtificial Label
   27   deriving stock (Eq , Read , Show)
   28 
   29 data LabelOperand = LTop | LImmediate !Natural | LArtificial Label
   30   deriving stock (Eq , Read , Show)
   31 
   32 data BranchOperand = BSwapped | BTop | BImmediate !Natural | BArtificial Label
   33   deriving stock (Eq , Read , Show)
   34 
   35 --FIXME
   36 --data Artificial = Integer | Label
   37 --
   38 
   39 type Label = SString --FIXME Artificial
   40 
   41 data LabelOperation = Call | Jump
   42   deriving stock (Eq , Read , Show)
   43 
   44 data BranchTest = EZ | LTZ | GTZ | NE
   45   deriving stock (Eq , Read , Show)
   46 
   47 -- | Internal
   48 
   49 printCF :: CFInstruction -> Text
   50 printCF (Mark     i  ) = "\nmark" <> printMark i
   51 printCF (Branch i t)   = printBranchTest t <> printBranchOperand i
   52 printCF (Labeled  i o) = toLowerShow o <> printLabelOperand i
   53 printCF           i    = toLowerShow i
   54 
   55 printMark :: Mark -> Text
   56 printMark (MNatural    i) = "M " <> show i
   57 printMark (MArtificial i) = "A " <> show i
   58 
   59 printBranchTest :: BranchTest -> Text
   60 printBranchTest t = "b" <> show t
   61 
   62 printBranchOperand :: BranchOperand -> Text
   63 printBranchOperand  BTop           = ""
   64 printBranchOperand  BSwapped       = "S"
   65 printBranchOperand (BImmediate  i) = "I " <> show i
   66 printBranchOperand (BArtificial i) = "A " <> show i
   67 
   68 printLabelOperand :: LabelOperand -> Text
   69 printLabelOperand  LTop           = ""
   70 printLabelOperand (LImmediate  i) = "I " <> show i
   71 printLabelOperand (LArtificial i) = "A " <> show i