aboutsummaryrefslogtreecommitdiff
path: root/src/Micro/Compiler.hs
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2022-09-09 16:54:06 +0100
committerJuan J. Martinez <jjm@usebox.net>2022-09-09 16:54:06 +0100
commitbcc469bc7f1d73e66828637b5b518b7cab8e2781 (patch)
tree84d7a1d4a9b9c07797583c03b3fda274ee740148 /src/Micro/Compiler.hs
parentcdf88f13008cd3f6511d466c1078ae7b2f983faf (diff)
downloadmicro-lang-hs-bcc469bc7f1d73e66828637b5b518b7cab8e2781.tar.gz
micro-lang-hs-bcc469bc7f1d73e66828637b5b518b7cab8e2781.zip
SDCC generation WIP
Diffstat (limited to 'src/Micro/Compiler.hs')
-rw-r--r--src/Micro/Compiler.hs28
1 files changed, 12 insertions, 16 deletions
diff --git a/src/Micro/Compiler.hs b/src/Micro/Compiler.hs
index f7ae71f..b765c16 100644
--- a/src/Micro/Compiler.hs
+++ b/src/Micro/Compiler.hs
@@ -148,15 +148,15 @@ compile x = do
(ev, errs) <- return $ (ev, (verifyFuncType ident params ret pos) ++ errs)
-- updated with the function
(ev, errs) <-
- return $ case addSymUniq ev (ident, ftype, priv, pos) of
+ return $ case addSymUniq ev (newSym ident ftype priv False 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 fev, errs) params
+ (nev, errs) <- return $ foldlEither addSymUniq (addEnv fev, errs) $ map (toSym True) params
-- helper for return
- nev <- return $ addSym nev ("$fn$", ftype, True, pos)
+ nev <- return $ addSym nev $ newSym "$fn$" ftype True True pos
put (nev, errs)
_ <- compileAll body
(_, errs) <- get
@@ -176,7 +176,7 @@ compile x = do
_ -> addError $ Error NonCallable "non callable value in function call" pos
(A.Var ident typ val priv pos) -> do
(ev, errs) <- get
- (ev, errs) <- return $ foldlEither addSymUniq (ev, errs) [(ident, typ, priv, pos)]
+ (ev, errs) <- return $ foldlEither addSymUniq (ev, errs) [newSym ident typ priv True pos]
errs <-
return $
if not (definedType typ)
@@ -190,7 +190,7 @@ compile x = do
(A.Return value pos) -> do
(ev, _) <- get
case getSyml ev "$fn$" of
- Just (_, A.FuncType _ rtyp, _, _) -> do
+ Just Sym {symType = A.FuncType _ rtyp} -> do
r <- typecheckReturn value rtyp
case r of
Just err -> addError $ Error TypeError err pos
@@ -199,17 +199,13 @@ compile x = do
(A.Variable ident pos) -> do
(ev, _) <- get
case getSym ev ident of
- Just (_, t, _, _) -> return $ typeResult $ Just t
+ Just Sym {symType = t} -> return $ typeResult $ Just t
Nothing -> addError $ Error Undefined ("undefined \"" ++ ident ++ "\"") pos
compileAll :: [A.Expr] -> State CompState CompResult
-compileAll ast =
- case ast of
- (x : xs) -> do
- _ <- compile x
- compileAll xs
- [] -> do
- ((Env sym _), errs) <- get
- case errs of
- [] -> pure $ successResult $ generate sym ast
- _ -> return $ errorResult errs
+compileAll ast = do
+ _ <- traverse compile ast
+ ((Env sym _), errs) <- get
+ case errs of
+ [] -> pure $ successResult $ generate sym ast
+ _ -> return $ errorResult errs