From f66874f1f5066e57ef5761cd7c87b5d498fd89b6 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Fri, 2 Sep 2022 12:57:29 +0100 Subject: Private variables --- src/Compiler.hs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/Compiler.hs') 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 -- cgit v1.2.3