summaryrefslogtreecommitdiff
path: root/lib/Language/Elna/SymbolTable.hs
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2024-10-02 22:56:15 +0200
committerEugen Wissner <belka@caraus.de>2024-10-02 22:56:15 +0200
commitfdf56ce9d0de459dc5bd65537847ded7b02ad5c2 (patch)
tree01c13db713bfcbe3252c83d1b557ebf9fdb2b11e /lib/Language/Elna/SymbolTable.hs
parentcafae5c8307489e3c8a5bf3a5f9c0f0797b0ca6c (diff)
downloadelna-fdf56ce9d0de459dc5bd65537847ded7b02ad5c2.tar.gz
Negate integral expressions
Diffstat (limited to 'lib/Language/Elna/SymbolTable.hs')
-rw-r--r--lib/Language/Elna/SymbolTable.hs88
1 files changed, 0 insertions, 88 deletions
diff --git a/lib/Language/Elna/SymbolTable.hs b/lib/Language/Elna/SymbolTable.hs
deleted file mode 100644
index 97d9621..0000000
--- a/lib/Language/Elna/SymbolTable.hs
+++ /dev/null
@@ -1,88 +0,0 @@
-module Language.Elna.SymbolTable
- ( SymbolTable
- , Info(..)
- , ParameterInfo(..)
- , builtInSymbolTable
- , empty
- , enter
- , fromList
- , lookup
- , member
- , scope
- , toMap
- , update
- ) where
-
-import Data.HashMap.Strict (HashMap)
-import qualified Data.HashMap.Strict as HashMap
-import Data.List (sort)
-import Data.List.NonEmpty (NonEmpty)
-import qualified Data.List.NonEmpty as NonEmpty
-import Data.Maybe (isJust)
-import Data.Vector (Vector)
-import qualified Data.Vector as Vector
-import Language.Elna.Location (Identifier(..))
-import Language.Elna.Types (Type(..), intType)
-import Prelude hiding (lookup)
-
-data SymbolTable = SymbolTable (Maybe SymbolTable) (HashMap Identifier Info)
- deriving (Eq, Show)
-
-empty :: SymbolTable
-empty = SymbolTable Nothing HashMap.empty
-
-update :: (Info -> Maybe Info) -> Identifier -> SymbolTable -> SymbolTable
-update updater key (SymbolTable parent mappings) = SymbolTable parent
- $ HashMap.update updater key mappings
-
-scope :: SymbolTable -> SymbolTable -> SymbolTable
-scope parent (SymbolTable _ mappings) = SymbolTable (Just parent) mappings
-
-builtInSymbolTable :: SymbolTable
-builtInSymbolTable = SymbolTable Nothing $ HashMap.fromList
- [ ("printi", ProcedureInfo empty Vector.empty)
- , ("int", TypeInfo intType)
- ]
-
-toMap :: SymbolTable -> HashMap Identifier Info
-toMap (SymbolTable _ map') = map'
-
-enter :: Identifier -> Info -> SymbolTable -> Maybe SymbolTable
-enter identifier info table@(SymbolTable parent hashTable)
- | member identifier table = Nothing
- | otherwise = Just
- $ SymbolTable parent (HashMap.insert identifier info hashTable)
-
-lookup :: Identifier -> SymbolTable -> Maybe Info
-lookup identifier (SymbolTable parent table)
- | Just found <- HashMap.lookup identifier table = Just found
- | Just parent' <- parent = lookup identifier parent'
- | otherwise = Nothing
-
-member :: Identifier -> SymbolTable -> Bool
-member identifier table =
- isJust $ lookup identifier table
-
-fromList :: [(Identifier, Info)] -> Either (NonEmpty Identifier) SymbolTable
-fromList elements
- | Just identifierDuplicates' <- identifierDuplicates =
- Left identifierDuplicates'
- | otherwise = Right $ SymbolTable Nothing $ HashMap.fromList elements
- where
- identifierDuplicates = NonEmpty.nonEmpty
- $ fmap NonEmpty.head
- $ filter ((> 1) . NonEmpty.length)
- $ NonEmpty.group . sort
- $ fst <$> elements
-
-data ParameterInfo = ParameterInfo
- { name :: Identifier
- , type' :: Type
- , isReferenceParameter :: Bool
- } deriving (Eq, Show)
-
-data Info
- = TypeInfo Type
- | VariableInfo Bool Type
- | ProcedureInfo SymbolTable (Vector ParameterInfo)
- deriving (Eq, Show)