2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
4 \section[HsLit]{Abstract syntax: source-language literals}
7 #include "HsVersions.h"
18 = HsChar Char -- characters
19 | HsCharPrim Char -- unboxed char literals
20 | HsString FAST_STRING -- strings
21 | HsStringPrim FAST_STRING -- packed string
23 | HsInt Integer -- integer-looking literals
24 | HsFrac Rational -- frac-looking literals
25 -- Up through dict-simplification, HsInt and HsFrac simply
26 -- mean the literal was integral- or fractional-looking; i.e.,
27 -- whether it had an explicit decimal-point in it. *After*
28 -- dict-simplification, they mean (boxed) "Integer" and
29 -- "Rational" [Ratio Integer], respectively.
31 -- Dict-simplification tries to replace such lits w/ more
32 -- specific ones, using the unboxed variants that follow...
33 | HsIntPrim Integer -- unboxed Int literals
34 | HsFloatPrim Rational -- unboxed Float literals
35 | HsDoublePrim Rational -- unboxed Double literals
37 | HsLitLit FAST_STRING -- to pass ``literal literals'' through to C
38 -- also: "overloaded" type; but
39 -- must resolve to boxed-primitive!
44 negLiteral (HsInt i) = HsInt (-i)
45 negLiteral (HsFrac f) = HsFrac (-f)
49 instance Outputable HsLit where
50 ppr sty (HsChar c) = ppStr (show c)
51 ppr sty (HsCharPrim c) = ppBeside (ppStr (show c)) (ppChar '#')
52 ppr sty (HsString s) = ppStr (show s)
53 ppr sty (HsStringPrim s) = ppBeside (ppStr (show s)) (ppChar '#')
54 ppr sty (HsInt i) = ppInteger i
55 ppr sty (HsFrac f) = ppRational f
56 ppr sty (HsFloatPrim f) = ppBeside (ppRational f) (ppChar '#')
57 ppr sty (HsDoublePrim d) = ppBeside (ppRational d) (ppStr "##")
58 ppr sty (HsIntPrim i) = ppBeside (ppInteger i) (ppChar '#')
59 ppr sty (HsLitLit s) = ppBesides [ppStr "``", ppPStr s, ppStr "''"]