~jojo/Carth

8b0eba3dd9909f0a48a7d792ba0ba65105f59cae — JoJo 1 year, 10 months ago fdf229a
Move some Pretty instances from module Codegen to Misc
2 files changed, 11 insertions(+), 18 deletions(-)

M src/Codegen.hs
M src/Misc.hs
M src/Codegen.hs => src/Codegen.hs +0 -18
@@ 41,9 41,7 @@ import LLVM.Internal.Coding (encodeM)
import LLVM.Internal.EncodeAST (EncodeAST, defineType)
import LLVM.Internal.Type (createNamedType, setNamedType)
import qualified Foreign.Ptr
import qualified Data.Text.Prettyprint.Doc as Prettyprint
import qualified Codec.Binary.UTF8.String as UTF8.String
import LLVM.Pretty ()
import Data.String
import System.FilePath
import Control.Monad.Writer


@@ 129,13 127,6 @@ instance Semigroup Out where
instance Monoid Out where
    mempty = Out [] [] []

instance Pretty Type where
    pretty' _ = show . Prettyprint.pretty
instance Pretty Name where
    pretty' _ = show . Prettyprint.pretty
instance Pretty Module where
    pretty' _ = show . Prettyprint.pretty

instance Typed Val where
    typeOf = \case
        VVar x -> getPointee (typeOf x)


@@ 355,15 346,6 @@ genExpr expr = do
        Fun p b -> assign lambdaParentFunc parent *> genLambda p b
        Let ds b -> genLet ds b
        Match e cs tbody -> genMatch e cs =<< toLlvmType tbody
        -- TODO: Currently, the desugar converts a constructor to a construction
        --       wrapped in a bunch of lambdas. This generates a lot of wasteful
        --       code. We could be smarter -- keep it as a constructor item until
        --       now, and then look at how many applications surround it and apply
        --       them without lambdas, only generating lambdas for the remaining.
        --
        --       Another alt. / complement could be to generate named functions for
        --       constructors and pass them through monomorphization and stuff,
        --       right?
        Ction c -> genCtion c
        Box e -> genBox =<< genExpr e
        Deref e -> genDeref e

M src/Misc.hs => src/Misc.hs +11 -0
@@ 24,6 24,10 @@ import Data.Map (Map)
import Data.Composition
import Control.Monad.Reader
import Control.Lens (Lens', locally)
import LLVM.AST.Type (Type)
import LLVM.AST (Name, Module)
import LLVM.Pretty ()
import qualified Data.Text.Prettyprint.Doc as Prettyprint

ice :: String -> a
ice = error . ("Internal Compiler Error: " ++)


@@ 52,6 56,13 @@ class Pretty a where
instance Pretty String where
    pretty' _ = id

instance Pretty Type where
    pretty' _ = show . Prettyprint.pretty
instance Pretty Name where
    pretty' _ = show . Prettyprint.pretty
instance Pretty Module where
    pretty' _ = show . Prettyprint.pretty

prettyBracketPair :: (Pretty a, Pretty b) => Int -> (a, b) -> String
prettyBracketPair d (a, b) = concat
    ["[", pretty' (d + 1) a, "\n", indent (d + 1), pretty' (d + 1) b, "]"]