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
|
||||
-- (and all referenced binds within this bind).
|
||||
morphBind :: M.Type -> T.Bind -> EnvM ()
|
||||
morphBind expectedType b@(T.Bind (ident, _) args exp) = do
|
||||
outputted <- isOutputted ident
|
||||
morphBind expectedType b@(T.Bind (Ident name, _) args exp) = do
|
||||
outputted <- isOutputted (Ident name)
|
||||
if outputted then
|
||||
-- Don't add anything!
|
||||
return ()
|
||||
|
|
@ -154,7 +154,7 @@ morphBind expectedType b@(T.Bind (ident, _) args exp) = do
|
|||
addLocals $ map fst args -- Add all the local variables
|
||||
addPolyMap expectedType b
|
||||
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 expectedType exp = case exp of
|
||||
|
|
@ -189,7 +189,7 @@ morphExp expectedType exp = case exp of
|
|||
Just bind' -> do
|
||||
maybeCurrentFunc <- isCurrentFunc ident
|
||||
t' <- getMono t
|
||||
if maybeCurrentFunc then
|
||||
if maybeCurrentFunc then -- Recursive call?
|
||||
return ()
|
||||
else
|
||||
morphBind t' bind'
|
||||
|
|
@ -197,6 +197,14 @@ morphExp expectedType exp = case exp of
|
|||
|
||||
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
|
||||
-- | Does the monomorphization.
|
||||
monomorphize :: T.Program -> M.Program
|
||||
|
|
@ -210,10 +218,3 @@ monomorphize (T.Program binds) = M.Program $ (map snd . Map.toList) outputMap
|
|||
main <- getMain
|
||||
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