X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=utils%2Fext-core%2FPrinter.hs;fp=utils%2Fext-core%2FPrinter.hs;h=8ff4ba5ad2de3e05bbd33110c54e3a5e13c8ed7f;hp=ded48aadc201cd7cf4c5e5b2ff4b24aa20875bfb;hb=276585028d51a2516a31b91a91a1f4bba5c9f8ba;hpb=e415eeaf6c7771488af24758ca5b9c22c42be3a6 diff --git a/utils/ext-core/Printer.hs b/utils/ext-core/Printer.hs index ded48aa..8ff4ba5 100644 --- a/utils/ext-core/Printer.hs +++ b/utils/ext-core/Printer.hs @@ -1,9 +1,10 @@ module Printer where -import Pretty -import Core -import Char +import Text.PrettyPrint.HughesPJ import Numeric (fromRat) +import Char + +import Core instance Show Module where showsPrec d m = shows (pmodule m) @@ -38,8 +39,10 @@ instance Show Lit where indent = nest 2 +-- seems like this is asking for a type class... + pmodule (Module mname tdefs vdefgs) = - (text "%module" <+> text mname) + (text "%module" <+> panmname mname) $$ indent ((vcat (map ((<> char ';') . ptdef) tdefs)) $$ (vcat (map ((<> char ';') . pvdefg) vdefgs))) @@ -58,8 +61,14 @@ pcdef (Constr qdcon tbinds tys) = pname id = text id -pqname ("",id) = pname id -pqname (m,id) = pname m <> char '.' <> pname id +pqname (m,id) = pmname m <> char '.' <> pname id + +pmname Nothing = empty +pmname (Just m) = panmname m + +panmname (pkgName, parents, name) = pname pkgName <> char ':' + <> (sep (punctuate (char '.') (map pname parents))) + <> char '.' <> pname name ptbind (t,Klifted) = pname t ptbind (t,k) = parens (pname t <> text "::" <> pkind k) @@ -122,10 +131,10 @@ pappexp e as = fsep (paexp e : map pa as) pexp (Lam b e) = char '\\' <+> plamexp [b] e pexp (Let vd e) = (text "%let" <+> pvdefg vd) $$ (text "%in" <+> pexp e) -pexp (Case e vb alts) = sep [text "%case" <+> paexp e, +pexp (Case e vb t alts) = sep [text "%case" <+> pty t <+> paexp e, text "%of" <+> pvbind vb] $$ (indent (braces (vcat (punctuate (char ';') (map palt alts))))) -pexp (Coerce t e) = (text "%coerce" <+> paty t) $$ pexp e +pexp (Cast e t) = (text "%cast" <+> paty t) $$ pexp e pexp (Note s e) = (text "%note" <+> pstring s) $$ pexp e pexp (External n t) = (text "%extcall" <+> pstring n) $$ paty t pexp e = pfexp e