aboutsummaryrefslogtreecommitdiff
path: root/src/Compiler.hs
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2022-09-02 12:57:29 +0100
committerJuan J. Martinez <jjm@usebox.net>2022-09-02 12:57:29 +0100
commitf66874f1f5066e57ef5761cd7c87b5d498fd89b6 (patch)
tree0edef26cda608a79c92f9c64c847f214ba877f9c /src/Compiler.hs
parenta5633563e9bb579ed10cb7d6d43676485c13b1fb (diff)
downloadmicro-lang-hs-f66874f1f5066e57ef5761cd7c87b5d498fd89b6.tar.gz
micro-lang-hs-f66874f1f5066e57ef5761cd7c87b5d498fd89b6.zip
Private variables
Diffstat (limited to 'src/Compiler.hs')
-rw-r--r--src/Compiler.hs14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/Compiler.hs b/src/Compiler.hs
index a708f96..f36083c 100644
--- a/src/Compiler.hs
+++ b/src/Compiler.hs
@@ -90,7 +90,7 @@ verifyFuncType :: String -> [A.FuncParam] -> Maybe A.Type -> SourcePos -> [Error
verifyFuncType ident params ret pos = do
( catMaybes $
map
- ( \(id, t, pos) ->
+ ( \(id, t, _, pos) ->
if not (definedType t)
then Just $ Error UndefinedType ("undefined type in function declaration \"" ++ id ++ "\"") pos
else Nothing
@@ -118,7 +118,7 @@ compile x = do
(ev, errs) <- return $ (ev, (verifyFuncType ident params ret pos) ++ errs)
-- updated with the function
(ev, errs) <-
- return $ case addSymUniq ev (ident, ftype, pos) of
+ return $ case addSymUniq ev (ident, ftype, priv, pos) of
Left err -> (ev, err : errs)
Right ev -> (ev, errs)
-- lambdas can only access local variables (closures aren't supported)
@@ -126,7 +126,7 @@ compile x = do
-- with parameters
(nev, errs) <- return $ foldlEither addSymUniq (addEnv fev, errs) params
-- helper for return
- nev <- return $ addSym nev ("$fn$", ftype, pos)
+ nev <- return $ addSym nev ("$fn$", ftype, True, pos)
put (nev, errs)
r <- compileAll body
(_, errs) <- get
@@ -145,9 +145,9 @@ compile x = do
Nothing -> return $ Right rtyp
Right _ -> addError $ Error NonCallable "non callable value in function call" pos
_ -> return $ Right Nothing
- (A.Var ident typ val pos) -> do
+ (A.Var ident typ val priv pos) -> do
(ev, errs) <- get
- (ev, errs) <- return $ foldlEither addSymUniq (ev, errs) [(ident, typ, pos)]
+ (ev, errs) <- return $ foldlEither addSymUniq (ev, errs) [(ident, typ, priv, pos)]
errs <-
return $
if not (definedType typ)
@@ -160,7 +160,7 @@ compile x = do
(ev, errs) <- get
case getSyml ev "$fn$" of
Nothing -> addError $ Error UnexpectedReturn "return without function call" pos
- Just (_, A.FuncType _ rtyp, _) -> do
+ Just (_, A.FuncType _ rtyp, _, _) -> do
r <- typecheckReturn value rtyp
case r of
Just err -> addError $ Error TypeError err pos
@@ -168,7 +168,7 @@ compile x = do
(A.Variable ident pos) -> do
(ev, errs) <- get
case getSym ev ident of
- Just (_, t, _) -> return $ Right $ Just t
+ Just (_, t, _, _) -> return $ Right $ Just t
Nothing -> addError $ Error Undefined ("undefined variable \"" ++ ident ++ "\"") pos
compileAll :: [A.Expr] -> State CompState CompResult