module Language.Elna.Backend.Intermediate ( ProcedureQuadruples(..) , Operand(..) , Quadruple(..) , Label(..) , Variable(..) ) where import Data.Int (Int32) import Data.Vector (Vector) import Data.Word (Word32) import Data.Text (Text) import qualified Data.Text as Text newtype Label = Label { unLabel :: Text } deriving Eq instance Show Label where show (Label label) = '.' : Text.unpack label data Variable = TempVariable Word32 | LocalVariable Word32 | ParameterVariable Word32 deriving Eq instance Show Variable where show (LocalVariable variable) = '@' : show variable show (TempVariable variable) = '$' : show variable show (ParameterVariable variable) = '%' : show variable data Operand v = IntOperand Int32 | VariableOperand v deriving (Eq, Show) data ProcedureQuadruples v = ProcedureQuadruples { quadruples :: Vector (Quadruple v) , stackSize :: Word32 } deriving (Eq, Show) data Quadruple v = StartQuadruple | StopQuadruple | ParameterQuadruple (Operand v) | CallQuadruple Text Word32 | AddQuadruple (Operand v) (Operand v) v | SubtractionQuadruple (Operand v) (Operand v) v | NegationQuadruple (Operand v) v | ProductQuadruple (Operand v) (Operand v) v | DivisionQuadruple (Operand v) (Operand v) v | GoToQuadruple Label | AssignQuadruple (Operand v) v | ArrayQuadruple v (Operand v) v | ArrayAssignQuadruple (Operand v) (Operand v) v | LessOrEqualQuadruple (Operand v) (Operand v) Label | GreaterOrEqualQuadruple (Operand v) (Operand v) Label | GreaterQuadruple (Operand v) (Operand v) Label | LessQuadruple (Operand v) (Operand v) Label | NonEqualQuadruple (Operand v) (Operand v) Label | EqualQuadruple (Operand v) (Operand v) Label | LabelQuadruple Label deriving (Eq, Show)