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))
15 #if __GLASGOW_HASKELL__ >= 202
20 %************************************************************************
22 \subsection[Version]{Module and identifier version numbers}
24 %************************************************************************
30 %************************************************************************
32 \subsection[HsLit]{Literals}
34 %************************************************************************
39 = HsChar Char -- characters
40 | HsCharPrim Char -- unboxed char literals
41 | HsString FAST_STRING -- strings
42 | HsStringPrim FAST_STRING -- packed string
44 | HsInt Integer -- integer-looking literals
45 | HsFrac Rational -- frac-looking literals
46 -- Up through dict-simplification, HsInt and HsFrac simply
47 -- mean the literal was integral- or fractional-looking; i.e.,
48 -- whether it had an explicit decimal-point in it. *After*
49 -- dict-simplification, they mean (boxed) "Integer" and
50 -- "Rational" [Ratio Integer], respectively.
52 -- Dict-simplification tries to replace such lits w/ more
53 -- specific ones, using the unboxed variants that follow...
54 | HsIntPrim Integer -- unboxed Int literals
55 | HsFloatPrim Rational -- unboxed Float literals
56 | HsDoublePrim Rational -- unboxed Double literals
58 | HsLitLit FAST_STRING -- to pass ``literal literals'' through to C
59 -- also: "overloaded" type; but
60 -- must resolve to boxed-primitive!
65 negLiteral (HsInt i) = HsInt (-i)
66 negLiteral (HsFrac f) = HsFrac (-f)
70 instance Outputable HsLit where
71 ppr sty (HsChar c) = text (show c)
72 ppr sty (HsCharPrim c) = (<>) (text (show c)) (char '#')
73 ppr sty (HsString s) = text (show s)
74 ppr sty (HsStringPrim s) = (<>) (text (show s)) (char '#')
75 ppr sty (HsInt i) = integer i
76 ppr sty (HsFrac f) = rational f
77 ppr sty (HsFloatPrim f) = (<>) (rational f) (char '#')
78 ppr sty (HsDoublePrim d) = (<>) (rational d) (text "##")
79 ppr sty (HsIntPrim i) = (<>) (integer i) (char '#')
80 ppr sty (HsLitLit s) = hcat [text "``", ptext s, text "''"]
83 %************************************************************************
85 \subsection[Fixity]{Fixity info}
87 %************************************************************************
90 data Fixity = Fixity Int FixityDirection
91 data FixityDirection = InfixL | InfixR | InfixN
94 instance Outputable Fixity where
95 ppr sty (Fixity prec dir) = hcat [ppr sty dir, space, int prec]
97 instance Outputable FixityDirection where
98 ppr sty InfixL = ptext SLIT("infixl")
99 ppr sty InfixR = ptext SLIT("infixr")
100 ppr sty InfixN = ptext SLIT("infix")
102 instance Eq Fixity where -- Used to determine if two fixities conflict
103 (Fixity p1 dir1) == (Fixity p2 dir2) = p1==p2 && dir1 == dir2