2024-10-02 22:56:15 +02:00
|
|
|
module Language.Elna.Backend.Intermediate
|
2024-11-14 19:55:30 +01:00
|
|
|
( ProcedureQuadruples(..)
|
|
|
|
, Operand(..)
|
2024-10-02 22:56:15 +02:00
|
|
|
, Quadruple(..)
|
2024-10-11 16:14:01 +02:00
|
|
|
, Label(..)
|
2024-10-02 22:56:15 +02:00
|
|
|
, Variable(..)
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Data.Int (Int32)
|
2024-11-14 19:55:30 +01:00
|
|
|
import Data.Vector (Vector)
|
2024-10-02 22:56:15 +02:00
|
|
|
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
|
|
|
|
2024-11-24 13:05:11 +01:00
|
|
|
data Variable = TempVariable Word32 | LocalVariable Word32 | ParameterVariable Word32
|
2024-10-02 22:56:15 +02:00
|
|
|
deriving Eq
|
|
|
|
|
|
|
|
instance Show Variable
|
|
|
|
where
|
2024-11-06 22:23:49 +01:00
|
|
|
show (LocalVariable variable) = '@' : show variable
|
2024-10-02 22:56:15 +02:00
|
|
|
show (TempVariable variable) = '$' : show variable
|
2024-11-24 13:05:11 +01:00
|
|
|
show (ParameterVariable variable) = '%' : show variable
|
2024-10-02 22:56:15 +02:00
|
|
|
|
|
|
|
data Operand v
|
|
|
|
= IntOperand Int32
|
|
|
|
| VariableOperand v
|
|
|
|
deriving (Eq, Show)
|
|
|
|
|
2024-11-14 19:55:30 +01:00
|
|
|
data ProcedureQuadruples v = ProcedureQuadruples
|
|
|
|
{ quadruples :: Vector (Quadruple v)
|
|
|
|
, stackSize :: Word32
|
|
|
|
} deriving (Eq, Show)
|
|
|
|
|
2024-10-02 22:56:15 +02:00
|
|
|
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
|
2024-11-06 22:23:49 +01:00
|
|
|
| AssignQuadruple (Operand v) v
|
2024-12-02 13:57:03 +01:00
|
|
|
{-| ArrayQuadruple Variable Operand Variable -}
|
|
|
|
| ArrayAssignQuadruple (Operand v) (Operand v) v
|
2024-10-13 12:59:47 +02:00
|
|
|
| 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)
|