Reverse procedure parameters on the stack
This commit is contained in:
parent
f7b36cb81d
commit
147967c04b
@ -72,8 +72,9 @@ declaration
|
|||||||
-> AST.Declaration
|
-> AST.Declaration
|
||||||
-> Glue (Maybe (AST.Identifier, Vector (Quadruple Variable)))
|
-> Glue (Maybe (AST.Identifier, Vector (Quadruple Variable)))
|
||||||
declaration globalTable (AST.ProcedureDeclaration procedureName parameters variableDeclarations statements)
|
declaration globalTable (AST.ProcedureDeclaration procedureName parameters variableDeclarations statements)
|
||||||
= traverseWithIndex registerVariable variableDeclarations
|
= Glue (modify' resetTemporaryCounter)
|
||||||
>> traverseWithIndex registerParameter parameters
|
>> traverseWithIndex registerVariable variableDeclarations
|
||||||
|
>> traverseWithIndex registerParameter (reverse parameters)
|
||||||
>> nameQuadruplesTuple <$> traverse (statement globalTable) statements
|
>> nameQuadruplesTuple <$> traverse (statement globalTable) statements
|
||||||
where
|
where
|
||||||
traverseWithIndex f = traverse_ (uncurry f) . zip [0..]
|
traverseWithIndex f = traverse_ (uncurry f) . zip [0..]
|
||||||
@ -91,6 +92,10 @@ declaration globalTable (AST.ProcedureDeclaration procedureName parameters varia
|
|||||||
$ flip Vector.snoc StopQuadruple
|
$ flip Vector.snoc StopQuadruple
|
||||||
$ fold quadrupleList
|
$ fold quadrupleList
|
||||||
)
|
)
|
||||||
|
resetTemporaryCounter paste = paste
|
||||||
|
{ temporaryCounter = 0
|
||||||
|
, localMap = mempty
|
||||||
|
}
|
||||||
declaration _ (AST.TypeDefinition _ _) = pure Nothing
|
declaration _ (AST.TypeDefinition _ _) = pure Nothing
|
||||||
|
|
||||||
statement :: SymbolTable -> AST.Statement -> Glue (Vector (Quadruple Variable))
|
statement :: SymbolTable -> AST.Statement -> Glue (Vector (Quadruple Variable))
|
||||||
|
@ -1 +1,2 @@
|
|||||||
14
|
14
|
||||||
|
8
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
proc print2(a: int) {
|
proc print2(a: int, b: int) {
|
||||||
printi(a);
|
printi(a);
|
||||||
|
printi(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
proc main() {
|
proc main() {
|
||||||
print2(14);
|
print2(14, 8);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user