Implement division

This commit is contained in:
2024-10-06 18:07:57 +02:00
parent 35742aa525
commit 699cc8684b
13 changed files with 101 additions and 27 deletions

View File

@@ -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