Unique names of new binds with different types
This commit is contained in:
parent
f10919ac20
commit
224a165715
1 changed files with 13 additions and 12 deletions
|
|
@ -144,8 +144,8 @@ getExpType (T.ELet _ _) = error "Lets not allowed🛑👮"
|
||||||
-- | 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).
|
||||||
morphBind :: M.Type -> T.Bind -> EnvM ()
|
morphBind :: M.Type -> T.Bind -> EnvM ()
|
||||||
morphBind expectedType b@(T.Bind (ident, _) args exp) = do
|
morphBind expectedType b@(T.Bind (Ident name, _) args exp) = do
|
||||||
outputted <- isOutputted ident
|
outputted <- isOutputted (Ident name)
|
||||||
if outputted then
|
if outputted then
|
||||||
-- Don't add anything!
|
-- Don't add anything!
|
||||||
return ()
|
return ()
|
||||||
|
|
@ -154,7 +154,7 @@ morphBind expectedType b@(T.Bind (ident, _) args exp) = do
|
||||||
addLocals $ map fst args -- Add all the local variables
|
addLocals $ map fst args -- Add all the local variables
|
||||||
addPolyMap expectedType b
|
addPolyMap expectedType b
|
||||||
exp' <- morphExp expectedType exp
|
exp' <- morphExp expectedType exp
|
||||||
addMonomorphic $ M.Bind (ident, expectedType) [] exp'
|
addMonomorphic $ M.Bind (newName expectedType b, expectedType) [] exp'
|
||||||
|
|
||||||
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
|
||||||
|
|
@ -189,7 +189,7 @@ morphExp expectedType exp = case exp of
|
||||||
Just bind' -> do
|
Just bind' -> do
|
||||||
maybeCurrentFunc <- isCurrentFunc ident
|
maybeCurrentFunc <- isCurrentFunc ident
|
||||||
t' <- getMono t
|
t' <- getMono t
|
||||||
if maybeCurrentFunc then
|
if maybeCurrentFunc then -- Recursive call?
|
||||||
return ()
|
return ()
|
||||||
else
|
else
|
||||||
morphBind t' bind'
|
morphBind t' bind'
|
||||||
|
|
@ -197,6 +197,14 @@ morphExp expectedType exp = case exp of
|
||||||
|
|
||||||
T.ELet (T.Bind {}) _ -> error "Lets not possible yet."
|
T.ELet (T.Bind {}) _ -> error "Lets not possible yet."
|
||||||
|
|
||||||
|
-- Creates a new identifier for a function with an assigned type
|
||||||
|
newName :: M.Type -> T.Bind -> Ident
|
||||||
|
newName t (T.Bind (Ident bindName, _) _ _) = Ident (bindName ++ "_" ++ newName' t)
|
||||||
|
where
|
||||||
|
newName' :: M.Type -> String
|
||||||
|
newName' (M.TMono (Ident str)) = str
|
||||||
|
newName' (M.TArr t1 t2) = newName' t1 ++ "_" ++ newName' t2
|
||||||
|
|
||||||
-- TODO: make sure that monomorphic binds are not processed again
|
-- TODO: make sure that monomorphic binds are not processed again
|
||||||
-- | Does the monomorphization.
|
-- | Does the monomorphization.
|
||||||
monomorphize :: T.Program -> M.Program
|
monomorphize :: T.Program -> M.Program
|
||||||
|
|
@ -210,10 +218,3 @@ monomorphize (T.Program binds) = M.Program $ (map snd . Map.toList) outputMap
|
||||||
main <- getMain
|
main <- getMain
|
||||||
morphBind (M.TMono $ M.Ident "Int") main
|
morphBind (M.TMono $ M.Ident "Int") main
|
||||||
|
|
||||||
-- Simple tests
|
|
||||||
--argX = T.Ident "x"
|
|
||||||
--funcF = (T.Ident "f", T.TArr )
|
|
||||||
--typeInt = T.TMono (T.Ident "Int")
|
|
||||||
--test1Exp = T.ELit typeInt (T.LInt 8)
|
|
||||||
--test1 = T.Program [T.Bind funcF [argX] test1Exp]
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue