aboutsummaryrefslogtreecommitdiff
path: root/src/Compiler.hs
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2022-08-14 19:19:26 +0100
committerJuan J. Martinez <jjm@usebox.net>2022-08-14 19:19:26 +0100
commit641de5e4f68385da3b53bfc532c2d6585a6d958d (patch)
tree33098b477d2e98331db8174cbc51cbb3b5630182 /src/Compiler.hs
parent2b78e2b5689d05e484254c9878eeb08542dcfbc5 (diff)
downloadmicro-lang-hs-641de5e4f68385da3b53bfc532c2d6585a6d958d.tar.gz
micro-lang-hs-641de5e4f68385da3b53bfc532c2d6585a6d958d.zip
Limit lambdas to only use local variables
Dynamic allocation (and hence closures) is not supported.
Diffstat (limited to 'src/Compiler.hs')
-rw-r--r--src/Compiler.hs6
1 files changed, 4 insertions, 2 deletions
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)