Monomorphization of function applications should work

This commit is contained in:
Rakarake 2023-03-21 17:15:15 +01:00
parent 71d07ebf0f
commit 8f151b7531

View file

@ -157,27 +157,31 @@ morphBind expectedType b@(T.Bind (Ident name, _) args exp) = do
exp' <- morphExp expectedType exp exp' <- morphExp expectedType exp
addOutputBind $ M.Bind (newName expectedType b, expectedType) [] exp' addOutputBind $ M.Bind (newName expectedType b, expectedType) [] exp'
-- Morphs function applications, such as EApp and EAdd
morphApp :: M.Type -> T.Exp -> T.Exp -> EnvM M.Exp
morphApp expectedType e1 e2 = do
t2 <- getMonoFromPoly $ getExpType e2 -- TODO: make better helper
e2' <- morphExp t2 e2
e1' <- morphExp (M.TArr t2 expectedType) e1
return $ M.EApp (M.TArr t2 expectedType) e1' e2'
--t2 <- getMonoFromPoly $ getExpType e2
--e2' <- morphExp t2 e2
--t1 <- getMonoFromPoly $ getExpType e1
--e1' <- morphExp t1 e1
--return $ M.EApp expectedType e1' e2'
morphExp :: M.Type -> T.Exp -> EnvM M.Exp morphExp :: M.Type -> T.Exp -> EnvM M.Exp
morphExp expectedType exp = case exp of morphExp expectedType exp = case exp of
T.ELit t lit -> do t' <- getMonoFromPoly t -- These steps are abundant T.ELit t lit -> do
return $ M.ELit t' lit t' <- getMonoFromPoly t -- These steps are abundant
T.EApp _ e1 e2 -> do t2 <- getMonoFromPoly $ getExpType e2 return $ M.ELit t' lit
e2' <- morphExp t2 e2 T.EApp _ e1 e2 -> do
t1 <- getMonoFromPoly $ getExpType e1 morphApp expectedType e1 e2
e1' <- morphExp t1 e1 T.EAdd _ e1 e2 -> do
return $ M.EApp expectedType e1' e2' morphApp expectedType e1 e2
T.EAdd _ e1 e2 -> do t2 <- getMonoFromPoly $ getExpType e2 T.EAbs _ (_, _) _ -> do
e2' <- morphExp t2 e2 error "EAbs found in Monomorpher, should not be possible"
t1 <- getMonoFromPoly $ getExpType e1 T.EId (ident@(Ident istr), t) -> do
e1' <- morphExp t1 e1
return $ M.EAdd expectedType e1' e2'
-- Add local vars to locals, this will never be called after the lambda lifter
T.EAbs _ (ident, _) e -> do let (M.TArr _ t) = expectedType
error "EAbs found in Monomorpher, should not be possible"
addLocal ident
morphExp t e
T.EId (ident@(Ident istr), t) -> do
maybeLocal <- localExists ident maybeLocal <- localExists ident
if maybeLocal then do if maybeLocal then do
t' <- getMonoFromPoly t t' <- getMonoFromPoly t