%
\begin{code}
-module PprExternalCore where
+module PprExternalCore () where
import Pretty
import ExternalCore
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)
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
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}