aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2022-08-13 08:55:13 +0100
committerJuan J. Martinez <jjm@usebox.net>2022-08-13 08:55:13 +0100
commite21bdbfc423717a4f2118f4ec5cda5543b0180fb (patch)
tree56294f898ee445bde41c2fc65041d2b43bb99223
parent1f2485fc44cad6155953de43567f9e7cf51c8ed9 (diff)
downloadmicro-lang-hs-e21bdbfc423717a4f2118f4ec5cda5543b0180fb.tar.gz
micro-lang-hs-e21bdbfc423717a4f2118f4ec5cda5543b0180fb.zip
We need to keep the function definition in the enviroment
-rw-r--r--src/Compiler.hs15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/Compiler.hs b/src/Compiler.hs
index 978e32b..f106bb2 100644
--- a/src/Compiler.hs
+++ b/src/Compiler.hs
@@ -36,14 +36,17 @@ compile (x : xs) = do
(A.Func ident params ret body priv pos) -> do
-- current env
(ev, errs) <- get
- -- with function and parameters
- (nev, nerrs) <-
+ -- updated with the function
+ (ev, errs) <-
return $ case addSymUniq ev (ident, A.toFuncType params ret, pos) of
- Left e -> (ev, e : errs)
- Right fev -> foldlEither addSymUniq (addEnv fev, errs) params
- put (nev, nerrs)
+ Left err -> (ev, err : errs)
+ Right ev -> (ev, errs)
+ -- with parameters
+ (nev, errs) <- return $ foldlEither addSymUniq (addEnv ev, errs) params
+ put (nev, errs)
r <- compile body
(_, errs) <- get
+ -- store updated errors and the env with the function
put (ev, errs)
return r
(A.Call ident args pos) -> do
@@ -57,7 +60,7 @@ compile (x : xs) = do
if existsSym ev ident
then return $ Right ()
else do
- put (ev, Error ("undefined variable \"" ++ ident ++ "\"") pos : errs)
+ put (ev, Error ("undefined \"" ++ ident ++ "\"") pos : errs)
return $ Right ()
_ -> compile []
compile xs