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))
17 %************************************************************************
19 \subsection[Version]{Module and identifier version numbers}
21 %************************************************************************
27 %************************************************************************
29 \subsection[HsLit]{Literals}
31 %************************************************************************
36 = HsChar Char -- characters
37 | HsCharPrim Char -- unboxed char literals
38 | HsString FAST_STRING -- strings
39 | HsStringPrim FAST_STRING -- packed string
41 | HsInt Integer -- integer-looking literals
42 | HsFrac Rational -- frac-looking literals
43 -- Up through dict-simplification, HsInt and HsFrac simply
44 -- mean the literal was integral- or fractional-looking; i.e.,
45 -- whether it had an explicit decimal-point in it. *After*
46 -- dict-simplification, they mean (boxed) "Integer" and
47 -- "Rational" [Ratio Integer], respectively.
49 -- Dict-simplification tries to replace such lits w/ more
50 -- specific ones, using the unboxed variants that follow...
51 | HsIntPrim Integer -- unboxed Int literals
52 | HsFloatPrim Rational -- unboxed Float literals
53 | HsDoublePrim Rational -- unboxed Double literals
55 | HsLitLit FAST_STRING -- to pass ``literal literals'' through to C
56 -- also: "overloaded" type; but
57 -- must resolve to boxed-primitive!
62 negLiteral (HsInt i) = HsInt (-i)
63 negLiteral (HsFrac f) = HsFrac (-f)
67 instance Outputable HsLit where
68 ppr sty (HsChar c) = ppStr (show c)
69 ppr sty (HsCharPrim c) = ppBeside (ppStr (show c)) (ppChar '#')
70 ppr sty (HsString s) = ppStr (show s)
71 ppr sty (HsStringPrim s) = ppBeside (ppStr (show s)) (ppChar '#')
72 ppr sty (HsInt i) = ppInteger i
73 ppr sty (HsFrac f) = ppRational f
74 ppr sty (HsFloatPrim f) = ppBeside (ppRational f) (ppChar '#')
75 ppr sty (HsDoublePrim d) = ppBeside (ppRational d) (ppStr "##")
76 ppr sty (HsIntPrim i) = ppBeside (ppInteger i) (ppChar '#')
77 ppr sty (HsLitLit s) = ppBesides [ppStr "``", ppPStr s, ppStr "''"]
80 %************************************************************************
82 \subsection[Fixity]{Fixity info}
84 %************************************************************************
87 data Fixity = Fixity Int FixityDirection
88 data FixityDirection = InfixL | InfixR | InfixN
91 instance Outputable Fixity where
92 ppr sty (Fixity prec dir) = ppBesides [ppr sty dir, ppSP, ppInt prec]
94 instance Outputable FixityDirection where
95 ppr sty InfixL = ppStr "infixl"
96 ppr sty InfixR = ppStr "infixr"
97 ppr sty InfixN = ppStr "infix"
99 instance Eq Fixity where -- Used to determine if two fixities conflict
100 (Fixity p1 dir1) == (Fixity p2 dir2) = p1==p2 && dir1 == dir2