2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
4 \section[HsLit]{Abstract syntax: source-language literals}
7 #include "HsVersions.h"
13 IMPORT_1_3(Ratio(Rational))
19 %************************************************************************
21 \subsection[HsLit]{Literals}
23 %************************************************************************
28 = HsChar Char -- characters
29 | HsCharPrim Char -- unboxed char literals
30 | HsString FAST_STRING -- strings
31 | HsStringPrim FAST_STRING -- packed string
33 | HsInt Integer -- integer-looking literals
34 | HsFrac Rational -- frac-looking literals
35 -- Up through dict-simplification, HsInt and HsFrac simply
36 -- mean the literal was integral- or fractional-looking; i.e.,
37 -- whether it had an explicit decimal-point in it. *After*
38 -- dict-simplification, they mean (boxed) "Integer" and
39 -- "Rational" [Ratio Integer], respectively.
41 -- Dict-simplification tries to replace such lits w/ more
42 -- specific ones, using the unboxed variants that follow...
43 | HsIntPrim Integer -- unboxed Int literals
44 | HsFloatPrim Rational -- unboxed Float literals
45 | HsDoublePrim Rational -- unboxed Double literals
47 | HsLitLit FAST_STRING -- to pass ``literal literals'' through to C
48 -- also: "overloaded" type; but
49 -- must resolve to boxed-primitive!
54 negLiteral (HsInt i) = HsInt (-i)
55 negLiteral (HsFrac f) = HsFrac (-f)
59 instance Outputable HsLit where
60 ppr sty (HsChar c) = text (show c)
61 ppr sty (HsCharPrim c) = (<>) (text (show c)) (char '#')
62 ppr sty (HsString s) = text (show s)
63 ppr sty (HsStringPrim s) = (<>) (text (show s)) (char '#')
64 ppr sty (HsInt i) = integer i
65 ppr sty (HsFrac f) = rational f
66 ppr sty (HsFloatPrim f) = (<>) (rational f) (char '#')
67 ppr sty (HsDoublePrim d) = (<>) (rational d) (text "##")
68 ppr sty (HsIntPrim i) = (<>) (integer i) (char '#')
69 ppr sty (HsLitLit s) = hcat [text "``", ptext s, text "''"]