X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2FcoreSyn%2FPprExternalCore.lhs;h=26c89cce486982a791e87272cfc1fa634ee8fd7f;hb=28a464a75e14cece5db40f2765a29348273ff2d2;hp=8ed16c55dd90011df7ae8f50dab67a8d575c472b;hpb=c66f666e3ac615be4b58eb44667b9a0830d29253;p=ghc-hetmet.git diff --git a/ghc/compiler/coreSyn/PprExternalCore.lhs b/ghc/compiler/coreSyn/PprExternalCore.lhs index 8ed16c5..26c89cc 100644 --- a/ghc/compiler/coreSyn/PprExternalCore.lhs +++ b/ghc/compiler/coreSyn/PprExternalCore.lhs @@ -3,7 +3,7 @@ % \begin{code} -module PprExternalCore where +module PprExternalCore () where import Pretty import ExternalCore @@ -39,32 +39,30 @@ instance Show Lit where indent = nest 2 -pmodule (Module mname {- (texports,dexports,vexports) -} tdefs vdefs) = +pmodule (Module mname tdefs vdefgs) = (text "%module" <+> text mname) -{- $$ indent (parens (((fsep (map pname texports) <> char ',') - $$ (fsep (map pname dexports) <> char ',') - $$ (fsep (map pname vexports)))) --} $$ indent ((vcat (map ((<> char ';') . ptdef) tdefs)) - $$ (vcat (map ((<> char ';') . pgvdef) vdefs))) - -pgvdef (False,vdef) = text "%local" <+> pvdefg vdef -pgvdef (True,vdef) = pvdefg vdef + $$ (vcat (map ((<> char ';') . pvdefg) vdefgs))) ptdef (Data tcon tbinds cdefs) = - (text "%data" <+> pname tcon <+> (hsep (map ptbind tbinds)) <+> char '=') + (text "%data" <+> pqname tcon <+> (hsep (map ptbind tbinds)) <+> char '=') $$ indent (braces ((vcat (punctuate (char ';') (map pcdef cdefs))))) -ptdef (Newtype tcon tbinds ty ) = - text "%newtype" <+> pname tcon <+> (hsep (map ptbind tbinds)) <+> char '=' <+> pty ty +ptdef (Newtype tcon tbinds rep ) = + text "%newtype" <+> pqname tcon <+> (hsep (map ptbind tbinds)) <+> repclause + where repclause = case rep of + Just ty -> char '=' <+> pty ty + Nothing -> empty pcdef (Constr dcon tbinds tys) = (pname dcon) <+> (sep [hsep (map pattbind tbinds),sep (map paty tys)]) +pcdef (GadtConstr dcon ty) = + (pname dcon) <+> text "::" <+> pty ty pname id = text id pqname ("",id) = pname id -pqname (m,id) = pname m <> char '.' <> pname id +pqname (m,id) = pname m <> char '.' <> pname id ptbind (t,Klifted) = pname t ptbind (t,k) = parens (pname t <> text "::" <> pkind k) @@ -127,12 +125,12 @@ 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 ty alts) = sep [text "%case" <+> parens (paty ty) <+> 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 (Note s e) = (text "%note" <+> pstring s) $$ pexp e -pexp (Ccall n t) = (text "%ccall" <+> pstring n) $$ paty t +pexp (External n t) = (text "%external" <+> pstring n) $$ paty t pexp e = pfexp e @@ -159,15 +157,17 @@ pstring s = doubleQuotes(text (escape s)) escape s = foldr f [] (map ord s) where - f cv rest | (cv < 0x20 || cv > 0x7e || cv == 0x22 || cv == 0x27 || cv == 0x5c) = - '\\':'u':h3:h2:h1:h0:rest - where (q3,r3) = quotRem cv (16*16*16) - h3 = toUpper(intToDigit q3) - (q2,r2) = quotRem r3 (16*16) - h2 = toUpper(intToDigit q2) - (q1,r1) = quotRem r2 16 - h1 = toUpper(intToDigit q1) - h0 = toUpper(intToDigit r1) + f cv rest + | cv > 0xFF = '\\':'x':hs ++ rest + | (cv < 0x20 || cv > 0x7e || cv == 0x22 || cv == 0x27 || cv == 0x5c) = + '\\':'x':h1:h0:rest + where (q1,r1) = quotRem cv 16 + h1 = intToDigit q1 + h0 = intToDigit r1 + hs = dropWhile (=='0') $ reverse $ mkHex cv + mkHex 0 = "" + mkHex cv = intToDigit r : mkHex q + where (q,r) = quotRem cv 16 f cv rest = (chr cv):rest \end{code}