Made it possible for main to have different monomorphic types
This commit is contained in:
parent
283f8ccf83
commit
2226a6ad33
1 changed files with 21 additions and 3 deletions
|
|
@ -142,6 +142,19 @@ getMonoFromPoly t = do
|
||||||
-- error $ "type not found! type: " ++ show ident ++ ", error in previous compilation steps"
|
-- error $ "type not found! type: " ++ show ident ++ ", error in previous compilation steps"
|
||||||
(L.TData ident args) -> M.TData ident (map (getMono polys) args)
|
(L.TData ident args) -> M.TData ident (map (getMono polys) args)
|
||||||
|
|
||||||
|
-- | Converts a monomorphic type to the output tree if that type is monomorphic
|
||||||
|
getMonoFromMono :: L.Type -> Maybe M.Type
|
||||||
|
getMonoFromMono t = case t of
|
||||||
|
L.TLit ident -> Just $ M.TLit ident
|
||||||
|
L.TFun t1 t2 -> do
|
||||||
|
t1' <- getMonoFromMono t1
|
||||||
|
t2' <- getMonoFromMono t2
|
||||||
|
return $ M.TFun t1' t2'
|
||||||
|
L.TVar _ -> Nothing
|
||||||
|
L.TData ident args -> do
|
||||||
|
args' <- mapM getMonoFromMono args
|
||||||
|
return $ M.TData ident args'
|
||||||
|
|
||||||
{- | If ident not already in env's output, morphed bind to output
|
{- | If ident not already in env's output, morphed bind to output
|
||||||
(and all referenced binds within this bind).
|
(and all referenced binds within this bind).
|
||||||
Returns the annotated bind name.
|
Returns the annotated bind name.
|
||||||
|
|
@ -376,9 +389,14 @@ monomorphize (L.Program defs) =
|
||||||
where
|
where
|
||||||
monomorphize' :: EnvM ()
|
monomorphize' :: EnvM ()
|
||||||
monomorphize' = do
|
monomorphize' = do
|
||||||
main <- getMain
|
mainBind <- getMain
|
||||||
morphBind (M.TLit $ Ident "Int") main
|
case mainBind of
|
||||||
return ()
|
(L.BindC _ _ _ _) -> error "main should not be a BindC node"
|
||||||
|
main@(L.Bind _ _ (_, mainType)) -> case getMonoFromMono mainType of
|
||||||
|
Nothing -> error "main should be monomorphic"
|
||||||
|
Just mainTypeMono -> do
|
||||||
|
morphBind mainTypeMono main
|
||||||
|
return ()
|
||||||
|
|
||||||
-- | Runs and gives the output binds.
|
-- | Runs and gives the output binds.
|
||||||
runEnvM :: Output -> Env -> EnvM () -> Output
|
runEnvM :: Output -> Env -> EnvM () -> Output
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue