summaryrefslogtreecommitdiff
path: root/lib/Language/Elna/Backend/Intermediate.hs
blob: 624bba81a32bdb1ee9812694d4b3c05786a07d75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
    deriving Eq

instance Show Variable
  where
    show (LocalVariable variable) = '@' : show variable
    show (TempVariable 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 Variable Operand Variable
    | 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
    | EqualQuadruple (Operand v) (Operand v) Label
    | LabelQuadruple Label
    deriving (Eq, Show)