elna/lib/Language/Elna/Backend/Intermediate.hs

67 lines
2.0 KiB
Haskell
Raw Permalink Normal View History

2024-12-11 21:44:32 +01:00
{- This Source Code Form is subject to the terms of the Mozilla Public License,
v. 2.0. If a copy of the MPL was not distributed with this file, You can
obtain one at https://mozilla.org/MPL/2.0/. -}
2024-10-02 22:56:15 +02:00
module Language.Elna.Backend.Intermediate
( 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)
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)
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-04 16:11:06 +01:00
| ArrayQuadruple v (Operand v) v
2024-12-02 13:57:03 +01:00
| 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)