bool now lit

This commit is contained in:
sebastianselander 2023-04-27 12:43:02 +02:00
parent 8782556603
commit e9852079ab
2 changed files with 36 additions and 27 deletions

9
benchmark.txt Normal file
View file

@ -0,0 +1,9 @@
# Full optimization Churf
File: output/hello_world, 100 runs gave average: 0.025261127948760988s
# O2 Haskell
File: ./Bench, 100 runs gave average: 0.05629507303237915s
# 03 Haskell
File: ./Bench, 100 runs gave average: 0.05490849256515503s
File: ./Bench, 100 runs gave average: 0.05323728561401367s

View file

@ -2,16 +2,15 @@
module TypeChecker.ReportTEVar where module TypeChecker.ReportTEVar where
import Auxiliary (onM) import Auxiliary (onM)
import Control.Applicative (Applicative (liftA2), liftA3) import Control.Applicative (Applicative (liftA2), liftA3)
import Control.Monad.Except (MonadError (throwError)) import Control.Monad.Except (MonadError (throwError))
import Data.Coerce (coerce) import Data.Coerce (coerce)
import Data.Tuple.Extra (secondM) import Data.Tuple.Extra (secondM)
import qualified Grammar.Abs as G import Grammar.Abs qualified as G
import Grammar.ErrM (Err) import Grammar.ErrM (Err)
import Grammar.Print (printTree) import Grammar.Print (printTree)
import TypeChecker.TypeCheckerIr hiding (Type (..)) import TypeChecker.TypeCheckerIr hiding (Type (..))
data Type data Type
= TLit Ident = TLit Ident
@ -30,20 +29,20 @@ instance ReportTEVar (Program' G.Type) (Program' Type) where
instance ReportTEVar (Def' G.Type) (Def' Type) where instance ReportTEVar (Def' G.Type) (Def' Type) where
reportTEVar = \case reportTEVar = \case
DBind bind -> DBind <$> reportTEVar bind DBind bind -> DBind <$> reportTEVar bind
DData dat -> DData <$> reportTEVar dat DData dat -> DData <$> reportTEVar dat
instance ReportTEVar (Bind' G.Type) (Bind' Type) where instance ReportTEVar (Bind' G.Type) (Bind' Type) where
reportTEVar (Bind id vars rhs) = liftA3 Bind (reportTEVar id) (reportTEVar vars) (reportTEVar rhs) reportTEVar (Bind id vars rhs) = liftA3 Bind (reportTEVar id) (reportTEVar vars) (reportTEVar rhs)
instance ReportTEVar (Exp' G.Type) (Exp' Type) where instance ReportTEVar (Exp' G.Type) (Exp' Type) where
reportTEVar exp = case exp of reportTEVar exp = case exp of
EVar name -> pure $ EVar name EVar name -> pure $ EVar name
EInj name -> pure $ EInj name EInj name -> pure $ EInj name
ELit lit -> pure $ ELit lit ELit lit -> pure $ ELit lit
ELet bind e -> liftA2 ELet (reportTEVar bind) (reportTEVar e) ELet bind e -> liftA2 ELet (reportTEVar bind) (reportTEVar e)
EApp e1 e2 -> onM EApp reportTEVar e1 e2 EApp e1 e2 -> onM EApp reportTEVar e1 e2
EAdd e1 e2 -> onM EAdd reportTEVar e1 e2 EAdd e1 e2 -> onM EAdd reportTEVar e1 e2
EAbs name e -> EAbs name <$> reportTEVar e EAbs name e -> EAbs name <$> reportTEVar e
ECase e branches -> liftA2 ECase (reportTEVar e) (reportTEVar branches) ECase e branches -> liftA2 ECase (reportTEVar e) (reportTEVar branches)
instance ReportTEVar (Branch' G.Type) (Branch' Type) where instance ReportTEVar (Branch' G.Type) (Branch' Type) where
@ -54,10 +53,10 @@ instance ReportTEVar (Pattern' G.Type, G.Type) (Pattern' Type, Type) where
instance ReportTEVar (Pattern' G.Type) (Pattern' Type) where instance ReportTEVar (Pattern' G.Type) (Pattern' Type) where
reportTEVar = \case reportTEVar = \case
PVar name -> pure $ PVar name PVar name -> pure $ PVar name
PLit lit -> pure $ PLit lit PLit lit -> pure $ PLit lit
PCatch -> pure PCatch PCatch -> pure PCatch
PEnum name -> pure $ PEnum name PEnum name -> pure $ PEnum name
PInj name ps -> PInj name <$> reportTEVar ps PInj name ps -> PInj name <$> reportTEVar ps
instance ReportTEVar (Data' G.Type) (Data' Type) where instance ReportTEVar (Data' G.Type) (Data' Type) where
@ -77,9 +76,10 @@ instance ReportTEVar a b => ReportTEVar [a] [b] where
instance ReportTEVar G.Type Type where instance ReportTEVar G.Type Type where
reportTEVar = \case reportTEVar = \case
G.TLit lit -> pure $ TLit (coerce lit) G.TLit lit -> pure $ TLit (coerce lit)
G.TVar (G.MkTVar i) -> pure $ TVar (MkTVar $ coerce i) G.TVar (G.MkTVar i) -> pure $ TVar (MkTVar $ coerce i)
G.TData name typs -> TData (coerce name) <$> reportTEVar typs G.TData (G.UIdent "Bool") _ -> pure $ TLit (coerce "Bool")
G.TFun t1 t2 -> liftA2 TFun (reportTEVar t1) (reportTEVar t2) G.TData name typs -> TData (coerce name) <$> reportTEVar typs
G.TFun t1 t2 -> liftA2 TFun (reportTEVar t1) (reportTEVar t2)
G.TAll (G.MkTVar i) t -> TAll (MkTVar $ coerce i) <$> reportTEVar t G.TAll (G.MkTVar i) t -> TAll (MkTVar $ coerce i) <$> reportTEVar t
G.TEVar tevar -> throwError ("Found TEVar: " ++ printTree tevar) G.TEVar tevar -> throwError ("Found TEVar: " ++ printTree tevar)