Implement division
This commit is contained in:
@ -12,7 +12,7 @@ import Language.Elna.Location (Identifier(..))
|
||||
newtype Store r = Store r
|
||||
|
||||
newtype MachineConfiguration r = MachineConfiguration
|
||||
{ temporaryRegister :: r
|
||||
{ temporaryRegisters :: [r]
|
||||
}
|
||||
|
||||
allocate
|
||||
@ -30,14 +30,29 @@ allocate MachineConfiguration{..} = fmap function
|
||||
quadruple (ParameterQuadruple operand1) =
|
||||
ParameterQuadruple (operand operand1)
|
||||
quadruple (CallQuadruple name count) = CallQuadruple name count
|
||||
quadruple (AddQuadruple operand1 operand2 _) =
|
||||
AddQuadruple (operand operand1) (operand operand2) (Store temporaryRegister)
|
||||
quadruple (SubtractionQuadruple operand1 operand2 _) =
|
||||
SubtractionQuadruple (operand operand1) (operand operand2) (Store temporaryRegister)
|
||||
quadruple (NegationQuadruple operand1 _) =
|
||||
NegationQuadruple (operand operand1) (Store temporaryRegister)
|
||||
quadruple (ProductQuadruple operand1 operand2 _) =
|
||||
ProductQuadruple (operand operand1) (operand operand2) (Store temporaryRegister)
|
||||
quadruple (AddQuadruple operand1 operand2 (TempVariable index))
|
||||
= AddQuadruple (operand operand1) (operand operand2)
|
||||
$ Store
|
||||
$ temporaryRegisters !! fromIntegral index
|
||||
quadruple (SubtractionQuadruple operand1 operand2 (TempVariable index))
|
||||
= SubtractionQuadruple (operand operand1) (operand operand2)
|
||||
$ Store
|
||||
$ temporaryRegisters !! fromIntegral index
|
||||
quadruple (NegationQuadruple operand1 (TempVariable index))
|
||||
= NegationQuadruple (operand operand1)
|
||||
$ Store
|
||||
$ temporaryRegisters !! fromIntegral index
|
||||
quadruple (ProductQuadruple operand1 operand2 (TempVariable index))
|
||||
= ProductQuadruple (operand operand1) (operand operand2)
|
||||
$ Store
|
||||
$ temporaryRegisters !! fromIntegral index
|
||||
quadruple (DivisionQuadruple operand1 operand2 (TempVariable index))
|
||||
= DivisionQuadruple (operand operand1) (operand operand2)
|
||||
$ Store
|
||||
$ temporaryRegisters !! fromIntegral index
|
||||
operand :: Operand Variable -> Operand (Store r)
|
||||
operand (IntOperand x) = IntOperand x
|
||||
operand (VariableOperand _) = VariableOperand (Store temporaryRegister)
|
||||
operand (VariableOperand (TempVariable index))
|
||||
= VariableOperand
|
||||
$ Store
|
||||
$ temporaryRegisters !! fromIntegral index
|
||||
|
@ -31,11 +31,11 @@ data Quadruple 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 Variable
|
||||
| ArrayQuadruple Variable Operand Variable
|
||||
| ArrayAssignQuadruple Operand Operand Variable
|
||||
| DivisionQuadruple Operand Operand Variable
|
||||
| EqualQuadruple Operand Operand Label
|
||||
| NonEqualQuadruple Operand Operand Label
|
||||
| LessQuadruple Operand Operand Label
|
||||
|
Reference in New Issue
Block a user