From 641de5e4f68385da3b53bfc532c2d6585a6d958d Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sun, 14 Aug 2022 19:19:26 +0100 Subject: Limit lambdas to only use local variables Dynamic allocation (and hence closures) is not supported. --- src/Compiler.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/Compiler.hs') diff --git a/src/Compiler.hs b/src/Compiler.hs index f9c0eed..0d90143 100644 --- a/src/Compiler.hs +++ b/src/Compiler.hs @@ -86,7 +86,7 @@ compile x = do l <- compile a r <- compile b return $ l -- TODO: placeholder - (A.Func ident params ret body priv pos) -> do + (A.Func ident params ret body priv anon pos) -> do -- current env (ev, errs) <- get -- updated with the function @@ -94,8 +94,10 @@ compile x = do return $ case addSymUniq ev (ident, ftype, pos) of Left err -> (ev, err : errs) Right ev -> (ev, errs) + -- lambdas can only access local variables (closures aren't supported) + fev <- return $ if anon then emptyEnv else ev -- with parameters - (nev, errs) <- return $ foldlEither addSymUniq (addEnv ev, errs) params + (nev, errs) <- return $ foldlEither addSymUniq (addEnv fev, errs) params -- helper for return nev <- return $ addSym nev ("$fn$", ftype, pos) put (nev, errs) -- cgit v1.2.3