2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1994
4 \section[HsLit]{Abstract syntax: source-language literals}
7 #include "HsVersions.h"
11 import AbsPrel ( PrimKind )
19 = CharLit Char -- characters
20 | CharPrimLit Char -- unboxed char literals
21 | StringLit FAST_STRING -- strings
22 | StringPrimLit FAST_STRING -- packed string
24 | IntLit Integer -- integer-looking literals
25 | FracLit Rational -- frac-looking literals
26 -- Up through dict-simplification, IntLit and FracLit 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 | LitLitLitIn FAST_STRING -- to pass ``literal literals'' through to C
35 -- also: "overloaded" type; but
36 -- must resolve to boxed-primitive!
38 | LitLitLit FAST_STRING
39 UniType -- and now we know the type
40 -- Must be a boxed-primitive type
42 | IntPrimLit Integer -- unboxed Int literals
43 #if __GLASGOW_HASKELL__ <= 22
44 | FloatPrimLit Double -- unboxed Float literals
45 | DoublePrimLit Double -- unboxed Double literals
47 | FloatPrimLit Rational -- unboxed Float literals
48 | DoublePrimLit Rational -- unboxed Double literals
53 negLiteral (IntLit i) = IntLit (-i)
54 negLiteral (FracLit f) = FracLit (-f)
58 instance Outputable Literal where
59 ppr sty (CharLit c) = ppStr (show c)
60 ppr sty (CharPrimLit c) = ppBeside (ppStr (show c)) (ppChar '#')
61 ppr sty (StringLit s) = ppStr (show s)
62 ppr sty (StringPrimLit s) = ppBeside (ppStr (show s)) (ppChar '#')
63 ppr sty (IntLit i) = ppInteger i
64 #if __GLASGOW_HASKELL__ <= 22
65 ppr sty (FracLit f) = ppDouble (fromRational f) -- ToDo: better??
66 ppr sty (FloatPrimLit f) = ppBeside (ppDouble f) (ppChar '#')
67 ppr sty (DoublePrimLit d) = ppBeside (ppDouble d) (ppStr "##")
69 ppr sty (FracLit f) = ppRational f
70 ppr sty (FloatPrimLit f) = ppBeside (ppRational f) (ppChar '#')
71 ppr sty (DoublePrimLit d) = ppBeside (ppRational d) (ppStr "##")
73 ppr sty (IntPrimLit i) = ppBeside (ppInteger i) (ppChar '#')
74 ppr sty (LitLitLitIn s) = ppBesides [ppStr "``", ppPStr s, ppStr "''"]
75 ppr sty (LitLitLit s k) = ppBesides [ppStr "``", ppPStr s, ppStr "''"]