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) =
|
||||
(id, FunctionInfo{numArgs = length args, arguments = args})
|
||||
: go xs
|
||||
go (MIR.DData (MIR.Data n cons) : xs) = undefined
|
||||
go (MIR.DData (MIR.Constructor n cons) : xs) = undefined
|
||||
{-do map
|
||||
( \(Constructor id xs) ->
|
||||
( (id, MIR.TLit n)
|
||||
|
|
@ -96,8 +96,8 @@ createArgs xs = fst $ foldl (\(acc, l) t -> (acc ++ [(GA.Ident ("arg_" <> show l
|
|||
getConstructors :: [MIR.Def] -> Map Ident ConstructorInfo
|
||||
getConstructors bs = Map.fromList $ go bs
|
||||
where
|
||||
go [] = []
|
||||
go (MIR.DData (MIR.Data n cons) : xs) = undefined
|
||||
go [] = []
|
||||
go (MIR.DData (MIR.Constructor n cons) : xs) = undefined
|
||||
{-do
|
||||
fst
|
||||
( foldl
|
||||
|
|
@ -117,7 +117,7 @@ getConstructors bs = Map.fromList $ go bs
|
|||
cons
|
||||
)
|
||||
<> go xs-}
|
||||
go (_ : xs) = go xs
|
||||
go (_ : xs) = go xs
|
||||
|
||||
initCodeGenerator :: [MIR.Def] -> CodeGenerator
|
||||
initCodeGenerator scs =
|
||||
|
|
@ -260,7 +260,7 @@ compileScs (MIR.DBind (MIR.Bind (name, _t) args exp) : xs) = do
|
|||
emit DefineEnd
|
||||
modify $ \s -> s{variableCount = 0}
|
||||
compileScs xs
|
||||
compileScs (MIR.DData (MIR.Data outer_id ts) : xs) = do
|
||||
compileScs (MIR.DData (MIR.Constructor outer_id ts) : xs) = do
|
||||
undefined
|
||||
-- let biggestVariant = maximum ((\(Constructor _ t) -> sum $ typeByteSize . type2LlvmType <$> t) <$> ts)
|
||||
-- emit $ LIR.Type outer_id [I8, Array biggestVariant I8]
|
||||
|
|
|
|||
|
|
@ -2,53 +2,59 @@
|
|||
|
||||
module Monomorphizer.Monomorphizer (monomorphize) where
|
||||
|
||||
import Grammar.Abs (Ident (..))
|
||||
import Monomorphizer.MonomorphizerIr
|
||||
import Data.Coerce (coerce)
|
||||
import Grammar.Abs (Constructor (..), Ident (..),
|
||||
Indexed (..))
|
||||
import qualified Monomorphizer.MonomorphizerIr as M
|
||||
import qualified TypeChecker.TypeCheckerIr as T
|
||||
|
||||
monomorphize :: T.Program -> Program
|
||||
monomorphize (T.Program ds) = Program $ monoDefs ds
|
||||
monomorphize :: T.Program -> M.Program
|
||||
monomorphize (T.Program ds) = M.Program $ monoDefs ds
|
||||
|
||||
monoDefs :: [T.Def] -> [Def]
|
||||
monoDefs :: [T.Def] -> [M.Def]
|
||||
monoDefs = map monoDef
|
||||
|
||||
monoDef :: T.Def -> Def
|
||||
monoDef (T.DBind bind) = DBind $ monoBind bind
|
||||
monoDef (T.DData d) = DData d
|
||||
monoDef :: T.Def -> M.Def
|
||||
monoDef (T.DBind bind) = M.DBind $ monoBind bind
|
||||
monoDef (T.DData d) = M.DData $ monoData d
|
||||
|
||||
monoBind :: T.Bind -> Bind
|
||||
monoBind (T.Bind name args (e, t)) = Bind (monoId name) (map monoId args) (monoExpr e, monoType t)
|
||||
monoBind :: T.Bind -> M.Bind
|
||||
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 = \case
|
||||
T.EId (Ident i) -> EId (Ident i)
|
||||
T.ELit lit -> ELit $ monoLit lit
|
||||
T.ELet bind expt -> ELet (monoBind bind) (monoexpt expt)
|
||||
T.EApp expt1 expt2 -> EApp (monoexpt expt1) (monoexpt expt2)
|
||||
T.EAdd expt1 expt2 -> EAdd (monoexpt expt1) (monoexpt expt2)
|
||||
T.EId (Ident i) -> M.EId (Ident i)
|
||||
T.ELit lit -> M.ELit $ monoLit lit
|
||||
T.ELet bind expt -> M.ELet (monoBind bind) (monoexpt expt)
|
||||
T.EApp expt1 expt2 -> M.EApp (monoexpt expt1) (monoexpt expt2)
|
||||
T.EAdd expt1 expt2 -> M.EAdd (monoexpt expt1) (monoexpt expt2)
|
||||
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.TVar (T.MkTVar i)) = error "NOT POLYMORPHIC TYPES"
|
||||
monoType (T.TLit i) = TLit i
|
||||
monoType (T.TFun t1 t2) = TFun (monoType t1) (monoType t2)
|
||||
monoType (T.TLit i) = M.TLit i
|
||||
monoType (T.TFun t1 t2) = M.TFun (monoType t1) (monoType t2)
|
||||
|
||||
monoexpt :: T.ExpT -> M.ExpT
|
||||
monoexpt (e, t) = (monoExpr e, monoType t)
|
||||
|
||||
monoId :: T.Id -> Id
|
||||
monoId :: T.Id -> M.Id
|
||||
monoId (n,t) = (n, monoType t)
|
||||
|
||||
monoLit :: T.Lit -> Lit
|
||||
monoLit (T.LInt i) = LInt i
|
||||
monoLit (T.LChar c) = LChar c
|
||||
monoLit :: T.Lit -> M.Lit
|
||||
monoLit (T.LInt i) = M.LInt i
|
||||
monoLit (T.LChar c) = M.LChar c
|
||||
|
||||
monoInjs :: [T.Inj] -> [M.Injection]
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
module Monomorphizer.MonomorphizerIr (module Monomorphizer.MonomorphizerIr, module RE, module GA) where
|
||||
|
||||
import Grammar.Abs (Data (..), Ident (..), Init (..))
|
||||
import qualified Grammar.Abs as GA (Data (..), Ident (..),
|
||||
Init (..))
|
||||
import Grammar.Abs (Ident (..), Init (..), UIdent)
|
||||
import qualified Grammar.Abs as GA (Ident (..), Init (..))
|
||||
import qualified TypeChecker.TypeCheckerIr as RE (Indexed)
|
||||
import TypeChecker.TypeCheckerIr (Indexed)
|
||||
|
||||
|
|
@ -11,7 +10,7 @@ type Id = (Ident, Type)
|
|||
newtype Program = Program [Def]
|
||||
deriving (Show, Ord, Eq)
|
||||
|
||||
data Def = DBind Bind | DData Data
|
||||
data Def = DBind Bind | DData Constructor
|
||||
deriving (Show, Ord, Eq)
|
||||
|
||||
data Bind = Bind Id [Id] ExpT
|
||||
|
|
@ -31,7 +30,7 @@ data Injection = Injection (Init, Type) ExpT
|
|||
|
||||
type ExpT = (Exp, Type)
|
||||
|
||||
data Constructor = Constructor Ident [Type]
|
||||
data Constructor = Constructor UIdent [(UIdent, Type)]
|
||||
deriving (Show, Ord, Eq)
|
||||
|
||||
data Lit
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue