aboutsummaryrefslogtreecommitdiff
path: root/src/Micro/Env.hs
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2022-09-09 16:54:06 +0100
committerJuan J. Martinez <jjm@usebox.net>2022-09-09 16:54:06 +0100
commitbcc469bc7f1d73e66828637b5b518b7cab8e2781 (patch)
tree84d7a1d4a9b9c07797583c03b3fda274ee740148 /src/Micro/Env.hs
parentcdf88f13008cd3f6511d466c1078ae7b2f983faf (diff)
downloadmicro-lang-hs-bcc469bc7f1d73e66828637b5b518b7cab8e2781.tar.gz
micro-lang-hs-bcc469bc7f1d73e66828637b5b518b7cab8e2781.zip
SDCC generation WIP
Diffstat (limited to 'src/Micro/Env.hs')
-rw-r--r--src/Micro/Env.hs28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/Micro/Env.hs b/src/Micro/Env.hs
index 7259deb..9de7248 100644
--- a/src/Micro/Env.hs
+++ b/src/Micro/Env.hs
@@ -6,7 +6,21 @@ import qualified Micro.Ast as A
import Micro.Error
import Text.Parsec (SourcePos)
-type Sym = (A.Ident, A.Type, Bool, SourcePos)
+data Sym = Sym
+ { symId :: A.Ident,
+ symType :: A.Type,
+ symPriv :: Bool,
+ symRef :: Bool,
+ symPos :: SourcePos
+ }
+ deriving (Show)
+
+newSym :: A.Ident -> A.Type -> Bool -> Bool -> SourcePos -> Sym
+newSym a b c d e = Sym {symId = a, symType = b, symPriv = c, symRef = d, symPos = e}
+
+-- XXX: this name is not good
+toSym :: Bool -> A.FuncParam -> Sym
+toSym ref (a, b, c, d) = newSym a b c ref d
type SymMap = Map.Map A.Ident Sym
@@ -45,9 +59,9 @@ existsSyml env sym = isJust $ getSyml env sym
-- environment. It will create a new enviroment if the symbol already exists
-- (shadowing).
addSym :: Env -> Sym -> Env
-addSym env@(Env m parent) sym@(id, _, _, _) = case getSym env id of
- Nothing -> Env (Map.insert id sym m) parent
- Just _ -> Env (Map.singleton id sym) $ Just env
+addSym env@(Env m parent) sym = case getSym env (symId sym) of
+ Nothing -> Env (Map.insert (symId sym) sym m) parent
+ Just _ -> Env (Map.singleton (symId sym) sym) $ Just env
-- | @addEnv e@ adds a new local environment using @e@ as parent.
addEnv :: Env -> Env
@@ -56,8 +70,6 @@ addEnv env = Env Map.empty $ Just env
-- | @addSymUniq e s@ adds a local symbol @s@ to the enviroment @e@ if it
-- doesn't exist.
addSymUniq :: Env -> Sym -> Either Error Env
-addSymUniq ev (id, typ, priv, pos) = case getSyml ev id of
+addSymUniq ev sym = case getSyml ev (symId sym) of
Nothing -> Right $ addSym ev sym
- Just (_, _, _, p) -> Left $ Error AlreadyDefined ("\"" ++ id ++ "\" already defined in " ++ show p) pos
- where
- sym = (id, typ, priv, pos)
+ Just other -> Left $ Error AlreadyDefined ("\"" ++ symId sym ++ "\" already defined in " ++ show (symPos other)) $ symPos sym