Reverse procedure parameters on the stack

This commit is contained in:
Eugen Wissner 2024-11-28 16:28:19 +01:00
parent f7b36cb81d
commit 147967c04b
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
3 changed files with 11 additions and 4 deletions

View File

@ -72,8 +72,9 @@ declaration
-> AST.Declaration
-> Glue (Maybe (AST.Identifier, Vector (Quadruple Variable)))
declaration globalTable (AST.ProcedureDeclaration procedureName parameters variableDeclarations statements)
= traverseWithIndex registerVariable variableDeclarations
>> traverseWithIndex registerParameter parameters
= Glue (modify' resetTemporaryCounter)
>> traverseWithIndex registerVariable variableDeclarations
>> traverseWithIndex registerParameter (reverse parameters)
>> nameQuadruplesTuple <$> traverse (statement globalTable) statements
where
traverseWithIndex f = traverse_ (uncurry f) . zip [0..]
@ -91,6 +92,10 @@ declaration globalTable (AST.ProcedureDeclaration procedureName parameters varia
$ flip Vector.snoc StopQuadruple
$ fold quadrupleList
)
resetTemporaryCounter paste = paste
{ temporaryCounter = 0
, localMap = mempty
}
declaration _ (AST.TypeDefinition _ _) = pure Nothing
statement :: SymbolTable -> AST.Statement -> Glue (Vector (Quadruple Variable))

View File

@ -1 +1,2 @@
14
8

View File

@ -1,7 +1,8 @@
proc print2(a: int) {
proc print2(a: int, b: int) {
printi(a);
printi(b);
}
proc main() {
print2(14);
print2(14, 8);
}