diff options
| author | Eugen Wissner <belka@caraus.de> | 2024-08-09 20:16:41 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2024-08-09 20:16:41 +0200 |
| commit | 5e7683af32ecb769e986554e12465cbe9acb4a05 (patch) | |
| tree | 08f0adc36f364aa4e9ba9be0bed2c25124e5147a | |
| parent | 18a299098ccc2dff6a92ed9ff45b6f45a45f94c7 (diff) | |
| download | elna-5e7683af32ecb769e986554e12465cbe9acb4a05.tar.gz | |
Check types
| -rw-r--r-- | TODO | 5 | ||||
| -rw-r--r-- | lib/Language/Elna/TypeAnalysis.hs | 18 |
2 files changed, 17 insertions, 6 deletions
@@ -1,4 +1 @@ -# Type analysis - -- Iterate the tree and apply the expression function on procedure expressions. -- Check statement types. +# Register allocation diff --git a/lib/Language/Elna/TypeAnalysis.hs b/lib/Language/Elna/TypeAnalysis.hs index 2544947..040a022 100644 --- a/lib/Language/Elna/TypeAnalysis.hs +++ b/lib/Language/Elna/TypeAnalysis.hs @@ -5,7 +5,7 @@ module Language.Elna.TypeAnalysis import Control.Applicative (Alternative(..)) import Control.Monad.Trans.Except (Except, runExcept, throwE) -import Control.Monad.Trans.Reader (ReaderT, asks, runReaderT) +import Control.Monad.Trans.Reader (ReaderT, asks, runReaderT, withReaderT, ask) import qualified Data.Vector as Vector import qualified Language.Elna.AST as AST import Language.Elna.Location (Identifier(..)) @@ -56,7 +56,21 @@ typeAnalysis globalTable = either Just (const Nothing) . program program :: AST.Program -> TypeAnalysis () -program (AST.Program _declarations) = pure () +program (AST.Program declarations) = traverse_ declaration declarations + +declaration :: AST.Declaration -> TypeAnalysis () +declaration (AST.ProcedureDefinition procedureName _ _ body) = do + globalTable <- TypeAnalysis ask + case SymbolTable.lookup procedureName globalTable of + Just (ProcedureInfo localTable _) -> TypeAnalysis + $ withReaderT (const localTable) + $ runTypeAnalysis + $ traverse_ (statement globalTable) body + Just anotherInfo -> TypeAnalysis $ lift $ throwE + $ UnexpectedProcedureInfoError anotherInfo + Nothing -> TypeAnalysis $ lift $ throwE + $ UndefinedSymbolError procedureName +declaration _ = pure () statement :: SymbolTable -> AST.Statement -> TypeAnalysis () statement globalTable = \case |
