diff options
author | Juan J. Martinez <jjm@usebox.net> | 2022-08-13 08:55:13 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2022-08-13 08:55:13 +0100 |
commit | e21bdbfc423717a4f2118f4ec5cda5543b0180fb (patch) | |
tree | 56294f898ee445bde41c2fc65041d2b43bb99223 /src/Compiler.hs | |
parent | 1f2485fc44cad6155953de43567f9e7cf51c8ed9 (diff) | |
download | micro-lang-hs-e21bdbfc423717a4f2118f4ec5cda5543b0180fb.tar.gz micro-lang-hs-e21bdbfc423717a4f2118f4ec5cda5543b0180fb.zip |
We need to keep the function definition in the enviroment
Diffstat (limited to 'src/Compiler.hs')
-rw-r--r-- | src/Compiler.hs | 15 |
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 |