Parse local variables
This commit is contained in:
@ -30,26 +30,21 @@ allocate MachineConfiguration{..} = fmap function
|
||||
quadruple (ParameterQuadruple operand1) =
|
||||
ParameterQuadruple (operand operand1)
|
||||
quadruple (CallQuadruple name count) = CallQuadruple name count
|
||||
quadruple (AddQuadruple operand1 operand2 (TempVariable index))
|
||||
quadruple (AddQuadruple operand1 operand2 variable)
|
||||
= AddQuadruple (operand operand1) (operand operand2)
|
||||
$ Store
|
||||
$ temporaryRegisters !! fromIntegral index
|
||||
quadruple (SubtractionQuadruple operand1 operand2 (TempVariable index))
|
||||
$ storeVariable variable
|
||||
quadruple (SubtractionQuadruple operand1 operand2 variable)
|
||||
= SubtractionQuadruple (operand operand1) (operand operand2)
|
||||
$ Store
|
||||
$ temporaryRegisters !! fromIntegral index
|
||||
quadruple (NegationQuadruple operand1 (TempVariable index))
|
||||
$ storeVariable variable
|
||||
quadruple (NegationQuadruple operand1 variable)
|
||||
= NegationQuadruple (operand operand1)
|
||||
$ Store
|
||||
$ temporaryRegisters !! fromIntegral index
|
||||
quadruple (ProductQuadruple operand1 operand2 (TempVariable index))
|
||||
$ storeVariable variable
|
||||
quadruple (ProductQuadruple operand1 operand2 variable)
|
||||
= ProductQuadruple (operand operand1) (operand operand2)
|
||||
$ Store
|
||||
$ temporaryRegisters !! fromIntegral index
|
||||
quadruple (DivisionQuadruple operand1 operand2 (TempVariable index))
|
||||
$ storeVariable variable
|
||||
quadruple (DivisionQuadruple operand1 operand2 variable)
|
||||
= DivisionQuadruple (operand operand1) (operand operand2)
|
||||
$ Store
|
||||
$ temporaryRegisters !! fromIntegral index
|
||||
$ storeVariable variable
|
||||
quadruple (LabelQuadruple label) = LabelQuadruple label
|
||||
quadruple (GoToQuadruple label) = GoToQuadruple label
|
||||
quadruple (EqualQuadruple operand1 operand2 goToLabel) =
|
||||
@ -64,9 +59,20 @@ allocate MachineConfiguration{..} = fmap function
|
||||
LessOrEqualQuadruple (operand operand1) (operand operand2) goToLabel
|
||||
quadruple (GreaterOrEqualQuadruple operand1 operand2 goToLabel) =
|
||||
GreaterOrEqualQuadruple (operand operand1) (operand operand2) goToLabel
|
||||
quadruple (AssignQuadruple operand1 variable)
|
||||
= AssignQuadruple (operand operand1)
|
||||
$ storeVariable variable
|
||||
operand :: Operand Variable -> Operand (Store r)
|
||||
operand (IntOperand x) = IntOperand x
|
||||
operand (VariableOperand (TempVariable index))
|
||||
= VariableOperand
|
||||
$ Store
|
||||
$ temporaryRegisters !! fromIntegral index
|
||||
operand (VariableOperand (LocalVariable index))
|
||||
= VariableOperand
|
||||
$ Store
|
||||
$ temporaryRegisters !! fromIntegral index
|
||||
storeVariable (TempVariable index) =
|
||||
Store $ temporaryRegisters !! fromIntegral index
|
||||
storeVariable (LocalVariable index) =
|
||||
Store $ temporaryRegisters !! fromIntegral index
|
||||
|
@ -17,12 +17,12 @@ instance Show Label
|
||||
where
|
||||
show (Label label) = '.' : Text.unpack label
|
||||
|
||||
newtype Variable = TempVariable Word32 -- | Variable Text
|
||||
data Variable = TempVariable Word32 | LocalVariable Word32
|
||||
deriving Eq
|
||||
|
||||
instance Show Variable
|
||||
where
|
||||
-- show (Variable variable) = '$' : Text.unpack variable
|
||||
show (LocalVariable variable) = '@' : show variable
|
||||
show (TempVariable variable) = '$' : show variable
|
||||
|
||||
data Operand v
|
||||
@ -41,8 +41,8 @@ data Quadruple v
|
||||
| ProductQuadruple (Operand v) (Operand v) v
|
||||
| DivisionQuadruple (Operand v) (Operand v) v
|
||||
| GoToQuadruple Label
|
||||
{-| AssignQuadruple Operand Variable
|
||||
| ArrayQuadruple Variable Operand Variable
|
||||
| AssignQuadruple (Operand v) v
|
||||
{-| ArrayQuadruple Variable Operand Variable
|
||||
| ArrayAssignQuadruple Operand Operand Variable -}
|
||||
| LessOrEqualQuadruple (Operand v) (Operand v) Label
|
||||
| GreaterOrEqualQuadruple (Operand v) (Operand v) Label
|
||||
|
Reference in New Issue
Block a user