Fixed some more stuff.
This commit is contained in:
parent
75fa232e21
commit
0012efabb7
3 changed files with 40 additions and 35 deletions
|
|
@ -74,7 +74,7 @@ getFunctions bs = Map.fromList $ go bs
|
||||||
go (MIR.DBind (MIR.Bind id args _) : xs) =
|
go (MIR.DBind (MIR.Bind id args _) : xs) =
|
||||||
(id, FunctionInfo{numArgs = length args, arguments = args})
|
(id, FunctionInfo{numArgs = length args, arguments = args})
|
||||||
: go xs
|
: go xs
|
||||||
go (MIR.DData (MIR.Data n cons) : xs) = undefined
|
go (MIR.DData (MIR.Constructor n cons) : xs) = undefined
|
||||||
{-do map
|
{-do map
|
||||||
( \(Constructor id xs) ->
|
( \(Constructor id xs) ->
|
||||||
( (id, MIR.TLit n)
|
( (id, MIR.TLit n)
|
||||||
|
|
@ -97,7 +97,7 @@ getConstructors :: [MIR.Def] -> Map Ident ConstructorInfo
|
||||||
getConstructors bs = Map.fromList $ go bs
|
getConstructors bs = Map.fromList $ go bs
|
||||||
where
|
where
|
||||||
go [] = []
|
go [] = []
|
||||||
go (MIR.DData (MIR.Data n cons) : xs) = undefined
|
go (MIR.DData (MIR.Constructor n cons) : xs) = undefined
|
||||||
{-do
|
{-do
|
||||||
fst
|
fst
|
||||||
( foldl
|
( foldl
|
||||||
|
|
@ -260,7 +260,7 @@ compileScs (MIR.DBind (MIR.Bind (name, _t) args exp) : xs) = do
|
||||||
emit DefineEnd
|
emit DefineEnd
|
||||||
modify $ \s -> s{variableCount = 0}
|
modify $ \s -> s{variableCount = 0}
|
||||||
compileScs xs
|
compileScs xs
|
||||||
compileScs (MIR.DData (MIR.Data outer_id ts) : xs) = do
|
compileScs (MIR.DData (MIR.Constructor outer_id ts) : xs) = do
|
||||||
undefined
|
undefined
|
||||||
-- let biggestVariant = maximum ((\(Constructor _ t) -> sum $ typeByteSize . type2LlvmType <$> t) <$> ts)
|
-- let biggestVariant = maximum ((\(Constructor _ t) -> sum $ typeByteSize . type2LlvmType <$> t) <$> ts)
|
||||||
-- emit $ LIR.Type outer_id [I8, Array biggestVariant I8]
|
-- emit $ LIR.Type outer_id [I8, Array biggestVariant I8]
|
||||||
|
|
|
||||||
|
|
@ -2,53 +2,59 @@
|
||||||
|
|
||||||
module Monomorphizer.Monomorphizer (monomorphize) where
|
module Monomorphizer.Monomorphizer (monomorphize) where
|
||||||
|
|
||||||
import Grammar.Abs (Ident (..))
|
import Data.Coerce (coerce)
|
||||||
import Monomorphizer.MonomorphizerIr
|
import Grammar.Abs (Constructor (..), Ident (..),
|
||||||
|
Indexed (..))
|
||||||
import qualified Monomorphizer.MonomorphizerIr as M
|
import qualified Monomorphizer.MonomorphizerIr as M
|
||||||
import qualified TypeChecker.TypeCheckerIr as T
|
import qualified TypeChecker.TypeCheckerIr as T
|
||||||
|
|
||||||
monomorphize :: T.Program -> Program
|
monomorphize :: T.Program -> M.Program
|
||||||
monomorphize (T.Program ds) = Program $ monoDefs ds
|
monomorphize (T.Program ds) = M.Program $ monoDefs ds
|
||||||
|
|
||||||
monoDefs :: [T.Def] -> [Def]
|
monoDefs :: [T.Def] -> [M.Def]
|
||||||
monoDefs = map monoDef
|
monoDefs = map monoDef
|
||||||
|
|
||||||
monoDef :: T.Def -> Def
|
monoDef :: T.Def -> M.Def
|
||||||
monoDef (T.DBind bind) = DBind $ monoBind bind
|
monoDef (T.DBind bind) = M.DBind $ monoBind bind
|
||||||
monoDef (T.DData d) = DData d
|
monoDef (T.DData d) = M.DData $ monoData d
|
||||||
|
|
||||||
monoBind :: T.Bind -> Bind
|
monoBind :: T.Bind -> M.Bind
|
||||||
monoBind (T.Bind name args (e, t)) = Bind (monoId name) (map monoId args) (monoExpr e, monoType t)
|
monoBind (T.Bind name args (e, t)) = M.Bind (monoId name) (map monoId args) (monoExpr e, monoType t)
|
||||||
|
|
||||||
|
monoData :: T.Data -> M.Constructor
|
||||||
|
monoData (T.Data (Indexed n _) cons) = undefined-- M.Constructor n (map (\(Constructor n t) -> (n, monoType t)) cons)
|
||||||
|
|
||||||
monoExpr :: T.Exp -> M.Exp
|
monoExpr :: T.Exp -> M.Exp
|
||||||
monoExpr = \case
|
monoExpr = \case
|
||||||
T.EId (Ident i) -> EId (Ident i)
|
T.EId (Ident i) -> M.EId (Ident i)
|
||||||
T.ELit lit -> ELit $ monoLit lit
|
T.ELit lit -> M.ELit $ monoLit lit
|
||||||
T.ELet bind expt -> ELet (monoBind bind) (monoexpt expt)
|
T.ELet bind expt -> M.ELet (monoBind bind) (monoexpt expt)
|
||||||
T.EApp expt1 expt2 -> EApp (monoexpt expt1) (monoexpt expt2)
|
T.EApp expt1 expt2 -> M.EApp (monoexpt expt1) (monoexpt expt2)
|
||||||
T.EAdd expt1 expt2 -> EAdd (monoexpt expt1) (monoexpt expt2)
|
T.EAdd expt1 expt2 -> M.EAdd (monoexpt expt1) (monoexpt expt2)
|
||||||
T.EAbs i expt -> error "BUG"
|
T.EAbs i expt -> error "BUG"
|
||||||
T.ECase expt injs -> ECase (monoexpt expt) (monoInjs injs)
|
T.ECase expt injs -> M.ECase (monoexpt expt) (monoInjs injs)
|
||||||
|
|
||||||
monoType :: T.Type -> Type
|
monoType :: T.Type -> M.Type
|
||||||
monoType (T.TAll _ t) = monoType t
|
monoType (T.TAll _ t) = monoType t
|
||||||
monoType (T.TVar (T.MkTVar i)) = error "NOT POLYMORPHIC TYPES"
|
monoType (T.TVar (T.MkTVar i)) = error "NOT POLYMORPHIC TYPES"
|
||||||
monoType (T.TLit i) = TLit i
|
monoType (T.TLit i) = M.TLit i
|
||||||
monoType (T.TFun t1 t2) = TFun (monoType t1) (monoType t2)
|
monoType (T.TFun t1 t2) = M.TFun (monoType t1) (monoType t2)
|
||||||
|
|
||||||
monoexpt :: T.ExpT -> M.ExpT
|
monoexpt :: T.ExpT -> M.ExpT
|
||||||
monoexpt (e, t) = (monoExpr e, monoType t)
|
monoexpt (e, t) = (monoExpr e, monoType t)
|
||||||
|
|
||||||
monoId :: T.Id -> Id
|
monoId :: T.Id -> M.Id
|
||||||
monoId (n,t) = (n, monoType t)
|
monoId (n,t) = (n, monoType t)
|
||||||
|
|
||||||
monoLit :: T.Lit -> Lit
|
monoLit :: T.Lit -> M.Lit
|
||||||
monoLit (T.LInt i) = LInt i
|
monoLit (T.LInt i) = M.LInt i
|
||||||
monoLit (T.LChar c) = LChar c
|
monoLit (T.LChar c) = M.LChar c
|
||||||
|
|
||||||
|
monoInjs :: [T.Inj] -> [M.Injection]
|
||||||
monoInjs = map monoInj
|
monoInjs = map monoInj
|
||||||
|
|
||||||
monoInj (T.Inj (init, t) expt) = Injection (monoInit init, monoType t) (monoexpt expt)
|
monoInj :: T.Inj -> M.Injection
|
||||||
|
monoInj (T.Inj (init, t) expt) = M.Injection (monoInit init, monoType t) (monoexpt expt)
|
||||||
|
|
||||||
monoInit :: T.Init -> Init
|
monoInit :: T.Init -> M.Init
|
||||||
monoInit = id
|
monoInit = id
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
module Monomorphizer.MonomorphizerIr (module Monomorphizer.MonomorphizerIr, module RE, module GA) where
|
module Monomorphizer.MonomorphizerIr (module Monomorphizer.MonomorphizerIr, module RE, module GA) where
|
||||||
|
|
||||||
import Grammar.Abs (Data (..), Ident (..), Init (..))
|
import Grammar.Abs (Ident (..), Init (..), UIdent)
|
||||||
import qualified Grammar.Abs as GA (Data (..), Ident (..),
|
import qualified Grammar.Abs as GA (Ident (..), Init (..))
|
||||||
Init (..))
|
|
||||||
import qualified TypeChecker.TypeCheckerIr as RE (Indexed)
|
import qualified TypeChecker.TypeCheckerIr as RE (Indexed)
|
||||||
import TypeChecker.TypeCheckerIr (Indexed)
|
import TypeChecker.TypeCheckerIr (Indexed)
|
||||||
|
|
||||||
|
|
@ -11,7 +10,7 @@ type Id = (Ident, Type)
|
||||||
newtype Program = Program [Def]
|
newtype Program = Program [Def]
|
||||||
deriving (Show, Ord, Eq)
|
deriving (Show, Ord, Eq)
|
||||||
|
|
||||||
data Def = DBind Bind | DData Data
|
data Def = DBind Bind | DData Constructor
|
||||||
deriving (Show, Ord, Eq)
|
deriving (Show, Ord, Eq)
|
||||||
|
|
||||||
data Bind = Bind Id [Id] ExpT
|
data Bind = Bind Id [Id] ExpT
|
||||||
|
|
@ -31,7 +30,7 @@ data Injection = Injection (Init, Type) ExpT
|
||||||
|
|
||||||
type ExpT = (Exp, Type)
|
type ExpT = (Exp, Type)
|
||||||
|
|
||||||
data Constructor = Constructor Ident [Type]
|
data Constructor = Constructor UIdent [(UIdent, Type)]
|
||||||
deriving (Show, Ord, Eq)
|
deriving (Show, Ord, Eq)
|
||||||
|
|
||||||
data Lit
|
data Lit
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue