From e21bdbfc423717a4f2118f4ec5cda5543b0180fb Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sat, 13 Aug 2022 08:55:13 +0100 Subject: We need to keep the function definition in the enviroment --- src/Compiler.hs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/Compiler.hs') 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 -- cgit v1.2.3