diff options
Diffstat (limited to 'lib/Language/Elna/Glue.hs')
| -rw-r--r-- | lib/Language/Elna/Glue.hs | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/Language/Elna/Glue.hs b/lib/Language/Elna/Glue.hs index 02a9b9f..79ae461 100644 --- a/lib/Language/Elna/Glue.hs +++ b/lib/Language/Elna/Glue.hs @@ -71,14 +71,16 @@ declaration :: SymbolTable -> AST.Declaration -> Glue (Maybe (AST.Identifier, Vector (Quadruple Variable))) -declaration globalTable (AST.ProcedureDeclaration procedureName _ variableDeclarations statements) - = traverse_ registerVariable variableDeclarations +declaration globalTable (AST.ProcedureDeclaration procedureName parameters variableDeclarations statements) + = traverseWithIndex registerVariable variableDeclarations + >> traverseWithIndex registerParameter parameters >> nameQuadruplesTuple <$> traverse (statement globalTable) statements where - registerVariable (AST.VariableDeclaration identifier _) = do - currentCounter <- fmap (fromIntegral . HashMap.size) - $ Glue $ gets $ getField @"localMap" - Glue $ modify' $ modifier identifier $ LocalVariable currentCounter + traverseWithIndex f = traverse_ (uncurry f) . zip [0..] + registerParameter index (AST.Parameter identifier _ _) = + Glue $ modify' $ modifier identifier $ ParameterVariable index + registerVariable index (AST.VariableDeclaration identifier _) = + Glue $ modify' $ modifier identifier $ LocalVariable index modifier identifier currentCounter generator = generator { localMap = HashMap.insert identifier currentCounter $ getField @"localMap" generator @@ -131,7 +133,7 @@ statement localTable (AST.AssignmentStatement variableAccess' assignee) = do . AssignQuadruple rhsOperand <$> lookupLocal identifier pure $ rhsStatements <> lhsStatements -{- statement localTable (AST.WhileStatement whileCondition whileStatement) = do +statement localTable (AST.WhileStatement whileCondition whileStatement) = do (conditionStatements, jumpConstructor) <- condition localTable whileCondition startLabel <- createLabel endLabel <- createLabel @@ -141,7 +143,7 @@ statement localTable (AST.AssignmentStatement variableAccess' assignee) = do <> conditionStatements <> Vector.fromList [jumpConstructor startLabel, GoToQuadruple endLabel, LabelQuadruple startLabel] <> whileStatements - <> Vector.fromList [GoToQuadruple conditionLabel, LabelQuadruple endLabel] -} + <> Vector.fromList [GoToQuadruple conditionLabel, LabelQuadruple endLabel] createTemporary :: Glue Variable createTemporary = do |
