diff options
| author | Eugen Wissner <belka@caraus.de> | 2024-12-02 13:57:03 +0100 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2024-12-02 13:57:03 +0100 |
| commit | 0c40bca60b343bb289f0a567ec9ec9e9382bad2a (patch) | |
| tree | bd0906d21a34afcd571e1b1489f3982c2c98151e /lib/Language/Elna/Glue.hs | |
| parent | 147967c04b0efeec4246b8ba0ff9b6961c9fe6cd (diff) | |
| download | elna-0c40bca60b343bb289f0a567ec9ec9e9382bad2a.tar.gz | |
Add array assignment to the IR
Diffstat (limited to 'lib/Language/Elna/Glue.hs')
| -rw-r--r-- | lib/Language/Elna/Glue.hs | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/lib/Language/Elna/Glue.hs b/lib/Language/Elna/Glue.hs index f5bd005..3cd46e3 100644 --- a/lib/Language/Elna/Glue.hs +++ b/lib/Language/Elna/Glue.hs @@ -230,27 +230,30 @@ variableAccess -> Glue (AST.Identifier, Maybe (Operand Variable), Vector (Quadruple Variable)) variableAccess _ (AST.VariableAccess identifier) accumulatedIndex _ accumulatedStatements = pure (identifier, accumulatedIndex, accumulatedStatements) -{- variableAccess localTable (AST.ArrayAccess access1 index1) Nothing (ArrayType _ baseType) _ = do - (indexPlace, statements) <- expression localTable index1 - variableAccess localTable access1 (Just indexPlace) baseType statements -variableAccess localTable (AST.ArrayAccess arrayAccess' arrayIndex) (Just baseIndex) (ArrayType arraySize baseType) statements = do - (indexPlace, statements') <- expression localTable arrayIndex - resultVariable <- createTemporary - let resultOperand = VariableOperand resultVariable - indexCalculation = Vector.fromList - [ ProductQuadruple (IntOperand $ fromIntegral arraySize) baseIndex resultVariable - , AddQuadruple indexPlace resultOperand resultVariable - ] - in variableAccess localTable arrayAccess' (Just resultOperand) baseType - $ statements <> indexCalculation <> statements' +variableAccess localTable accessKind accumulatedIndex arrayType statements + | (AST.ArrayAccess access1 index1) <- accessKind + , (ArrayType arraySize baseType) <- arrayType = do + (indexPlace, statements') <- expression localTable index1 + case accumulatedIndex of + Just baseIndex -> do + resultVariable <- createTemporary + let resultOperand = VariableOperand resultVariable + indexCalculation = Vector.fromList + [ ProductQuadruple (IntOperand $ fromIntegral arraySize) baseIndex resultVariable + , AddQuadruple indexPlace resultOperand resultVariable + ] + in variableAccess localTable access1 (Just resultOperand) baseType + $ statements <> indexCalculation <> statements' + Nothing -> + variableAccess localTable access1 (Just indexPlace) baseType statements' variableAccess _ _ _ _ _ = error "Array access operator doesn't match the type." --} + variableType :: AST.VariableAccess -> SymbolTable -> Type variableType (AST.VariableAccess identifier) symbolTable | Just (TypeInfo type') <- SymbolTable.lookup identifier symbolTable = type' | otherwise = error "Undefined type." -{-variableType (AST.ArrayAccess arrayAccess' _) symbolTable = - variableType arrayAccess' symbolTable -} +variableType (AST.ArrayAccess arrayAccess' _) symbolTable = + variableType arrayAccess' symbolTable expression :: SymbolTable -> AST.Expression -> Glue (Operand Variable, Vector (Quadruple Variable)) expression localTable = \case |
