From 3d2b80cf454e682ba1fcd094465b7ee1a94297dd Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Thu, 1 Sep 2022 22:34:28 +0100 Subject: Variable declaration --- src/Compiler.hs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/Compiler.hs') diff --git a/src/Compiler.hs b/src/Compiler.hs index a8cca5d..a708f96 100644 --- a/src/Compiler.hs +++ b/src/Compiler.hs @@ -92,7 +92,7 @@ verifyFuncType ident params ret pos = do map ( \(id, t, pos) -> if not (definedType t) - then Just $ Error UndefinedType ("undefined type in \"" ++ id ++ "\"") pos + then Just $ Error UndefinedType ("undefined type in function declaration \"" ++ id ++ "\"") pos else Nothing ) params @@ -145,6 +145,17 @@ 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 + (ev, errs) <- get + (ev, errs) <- return $ foldlEither addSymUniq (ev, errs) [(ident, typ, pos)] + errs <- + return $ + if not (definedType typ) + then Error UndefinedType ("undefined type in variable declaration \"" ++ ident ++ "\"") pos : errs + else errs + -- TODO: typecheck value + put (ev, errs) + return $ Right $ Just typ (A.Return value pos) -> do (ev, errs) <- get case getSyml ev "$fn$" of @@ -154,7 +165,7 @@ compile x = do case r of Just err -> addError $ Error TypeError err pos Nothing -> return $ Right rtyp - (A.Var ident pos) -> do + (A.Variable ident pos) -> do (ev, errs) <- get case getSym ev ident of Just (_, t, _) -> return $ Right $ Just t -- cgit v1.2.3