diff options
author | Juan J. Martinez <jjm@usebox.net> | 2022-09-01 22:34:28 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2022-09-01 22:34:38 +0100 |
commit | 3d2b80cf454e682ba1fcd094465b7ee1a94297dd (patch) | |
tree | 68b6731494756df20fc4cc0cea3b556f92f0ed12 /src/Compiler.hs | |
parent | 476b0d2d6c27b9ec326b465480795582a3b22f4c (diff) | |
download | micro-lang-hs-3d2b80cf454e682ba1fcd094465b7ee1a94297dd.tar.gz micro-lang-hs-3d2b80cf454e682ba1fcd094465b7ee1a94297dd.zip |
Variable declaration
Diffstat (limited to 'src/Compiler.hs')
-rw-r--r-- | src/Compiler.hs | 15 |
1 files changed, 13 insertions, 2 deletions
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 |