[project @ 1997-05-19 00:12:10 by sof]
[ghc-hetmet.git] / ghc / compiler / hsSyn / HsBasic.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
3 %
4 \section[HsLit]{Abstract syntax: source-language literals}
5
6 \begin{code}
7 #include "HsVersions.h"
8
9 module HsBasic where
10
11 IMP_Ubiq(){-uitous-}
12 IMPORT_1_3(Ratio(Rational))
13
14 import Pretty
15 #if __GLASGOW_HASKELL__ >= 202
16 import Outputable
17 #endif
18 \end{code}
19
20 %************************************************************************
21 %*                                                                      *
22 \subsection[Version]{Module and identifier version numbers}
23 %*                                                                      *
24 %************************************************************************
25
26 \begin{code}
27 type Version = Int
28 \end{code}
29
30 %************************************************************************
31 %*                                                                      *
32 \subsection[HsLit]{Literals}
33 %*                                                                      *
34 %************************************************************************
35
36
37 \begin{code}
38 data HsLit
39   = HsChar          Char        -- characters
40   | HsCharPrim      Char        -- unboxed char literals
41   | HsString        FAST_STRING -- strings
42   | HsStringPrim    FAST_STRING -- packed string
43
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.
51
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
57
58   | HsLitLit        FAST_STRING -- to pass ``literal literals'' through to C
59                                 -- also: "overloaded" type; but
60                                 -- must resolve to boxed-primitive!
61                                 -- (WDP 94/10)
62 \end{code}
63
64 \begin{code}
65 negLiteral (HsInt  i) = HsInt  (-i)
66 negLiteral (HsFrac f) = HsFrac (-f)
67 \end{code}
68
69 \begin{code}
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 "''"]
81 \end{code}
82
83 %************************************************************************
84 %*                                                                      *
85 \subsection[Fixity]{Fixity info}
86 %*                                                                      *
87 %************************************************************************
88
89 \begin{code}
90 data Fixity = Fixity Int FixityDirection
91 data FixityDirection = InfixL | InfixR | InfixN 
92                      deriving(Eq)
93
94 instance Outputable Fixity where
95     ppr sty (Fixity prec dir) = hcat [ppr sty dir, space, int prec]
96
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")
101
102 instance Eq Fixity where                -- Used to determine if two fixities conflict
103   (Fixity p1 dir1) == (Fixity p2 dir2) = p1==p2 && dir1 == dir2
104 \end{code}
105