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