2024-10-02 22:56:15 +02:00
|
|
|
module Language.Elna.Backend.Intermediate
|
|
|
|
( Operand(..)
|
|
|
|
, Quadruple(..)
|
2024-10-11 16:14:01 +02:00
|
|
|
, Label(..)
|
2024-10-02 22:56:15 +02:00
|
|
|
, Variable(..)
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Data.Int (Int32)
|
|
|
|
import Data.Word (Word32)
|
|
|
|
import Data.Text (Text)
|
2024-10-11 16:14:01 +02:00
|
|
|
import qualified Data.Text as Text
|
|
|
|
|
|
|
|
newtype Label = Label { unLabel :: Text }
|
|
|
|
deriving Eq
|
|
|
|
|
|
|
|
instance Show Label
|
|
|
|
where
|
|
|
|
show (Label label) = '.' : Text.unpack label
|
2024-10-02 22:56:15 +02:00
|
|
|
|
|
|
|
newtype Variable = TempVariable Word32 -- | Variable Text
|
|
|
|
deriving Eq
|
|
|
|
|
|
|
|
instance Show Variable
|
|
|
|
where
|
|
|
|
-- show (Variable variable) = '$' : Text.unpack variable
|
|
|
|
show (TempVariable variable) = '$' : show variable
|
|
|
|
|
|
|
|
data Operand v
|
|
|
|
= IntOperand Int32
|
|
|
|
| VariableOperand v
|
|
|
|
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
|
2024-10-04 18:26:10 +02:00
|
|
|
| ProductQuadruple (Operand v) (Operand v) v
|
2024-10-06 18:07:57 +02:00
|
|
|
| DivisionQuadruple (Operand v) (Operand v) v
|
2024-10-11 16:14:01 +02:00
|
|
|
| GoToQuadruple Label
|
|
|
|
{-| AssignQuadruple Operand Variable
|
2024-10-02 22:56:15 +02:00
|
|
|
| ArrayQuadruple Variable Operand Variable
|
2024-10-13 12:59:47 +02:00
|
|
|
| ArrayAssignQuadruple Operand Operand Variable -}
|
|
|
|
| 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
|
2024-10-11 16:14:01 +02:00
|
|
|
| EqualQuadruple (Operand v) (Operand v) Label
|
|
|
|
| LabelQuadruple Label
|
2024-10-02 22:56:15 +02:00
|
|
|
deriving (Eq, Show)
|