X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=utils%2Fext-core%2FPrinter.hs;h=404fda9bc8ed5ff4320eae9490b491e0277299fb;hb=318c22aad1837e471cbf59c6fddd6987a36c2c9b;hp=ded48aadc201cd7cf4c5e5b2ff4b24aa20875bfb;hpb=0065d5ab628975892cea1ec7303f968c3338cbe1;p=ghc-hetmet.git diff --git a/utils/ext-core/Printer.hs b/utils/ext-core/Printer.hs index ded48aa..404fda9 100644 --- a/utils/ext-core/Printer.hs +++ b/utils/ext-core/Printer.hs @@ -1,9 +1,11 @@ module Printer where -import Pretty -import Core -import Char +import Text.PrettyPrint.HughesPJ import Numeric (fromRat) +import Char + +import Core +import Encoding instance Show Module where showsPrec d m = shows (pmodule m) @@ -38,8 +40,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 +62,30 @@ 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 <> pname id + +-- be sure to print the '.' here so we don't print out +-- ".foo" for unqualified foo... +pmname Nothing = empty +pmname (Just m) = panmname m <> char '.' + +panmname p@(pkgName, parents, name) = + let parentStrs = map pname parents in + pname pkgName <> char ':' <> + -- This is to be sure to not print out: + -- main:.Main for when there's a single module name + -- with no parents. + (case parentStrs of + [] -> empty + _ -> hcat (punctuate hierModuleSeparator + (map pname parents)) + <> hierModuleSeparator) + <> pname name + +-- note that this is not a '.' but a Z-encoded '.': +-- GHCziIOBase.IO, not GHC.IOBase.IO. +-- What a pain. +hierModuleSeparator = text (zEncodeString ".") ptbind (t,Klifted) = pname t ptbind (t,k) = parens (pname t <> text "::" <> pkind k) @@ -122,10 +148,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