2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
4 \section[Demand]{@Demand@: the amount of demand on a value}
7 #include "HsVersions.h"
11 import PprStyle ( PprStyle )
13 import Pretty ( SYN_IE(Pretty), PrettyRep, ppStr )
18 %************************************************************************
20 \subsection{The @Demand@ data type}
22 %************************************************************************
26 = WwLazy -- Argument is lazy as far as we know
27 MaybeAbsent -- (does not imply worker's existence [etc]).
28 -- If MaybeAbsent == True, then it is
29 -- *definitely* lazy. (NB: Absence implies
32 | WwStrict -- Argument is strict but that's all we know
33 -- (does not imply worker's existence or any
34 -- calling-convention magic)
36 | WwUnpack -- Argument is strict & a single-constructor
37 [Demand] -- type; its constituent parts (whose StrictInfos
38 -- are in the list) should be passed
39 -- as arguments to the worker.
41 | WwPrim -- Argument is of primitive type, therefore
42 -- strict; doesn't imply existence of a worker;
43 -- argument should be passed as is to worker.
45 | WwEnum -- Argument is strict & an enumeration type;
46 -- an Int# representing the tag (start counting
47 -- at zero) should be passed to the worker.
49 -- we need Eq/Ord to cross-chk update infos in interfaces
51 type MaybeAbsent = Bool -- True <=> not even used
53 -- versions that don't worry about Absence:
56 wwUnpack xs = WwUnpack xs
62 %************************************************************************
64 \subsection{Functions over @Demand@}
66 %************************************************************************
69 isStrict :: Demand -> Bool
71 isStrict WwStrict = True
72 isStrict (WwUnpack _) = True
73 isStrict WwPrim = True
74 isStrict WwEnum = True
79 %************************************************************************
81 \subsection{Instances}
83 %************************************************************************
86 #ifdef REALLY_HASKELL_1_3
87 instance Read Demand where
89 instance Text Demand where
91 readList str = read_em [{-acc-}] str
93 read_em acc ('L' : xs) = read_em (WwLazy False : acc) xs
94 read_em acc ('A' : xs) = read_em (WwLazy True : acc) xs
95 read_em acc ('S' : xs) = read_em (WwStrict : acc) xs
96 read_em acc ('P' : xs) = read_em (WwPrim : acc) xs
97 read_em acc ('E' : xs) = read_em (WwEnum : acc) xs
99 read_em acc (')' : xs) = [(reverse acc, xs)]
100 read_em acc ( 'U' : '(' : xs)
101 = case (read_em [] xs) of
102 [(stuff, rest)] -> read_em (WwUnpack stuff : acc) rest
103 _ -> panic ("Text.Demand:"++str++"::"++xs)
105 read_em acc rest = [(reverse acc, rest)]
107 #ifdef REALLY_HASKELL_1_3
108 instance Show Demand where
110 showList wrap_args rest = foldr show1 rest wrap_args
112 show1 (WwLazy False) rest = 'L' : rest
113 show1 (WwLazy True) rest = 'A' : rest
114 show1 WwStrict rest = 'S' : rest
115 show1 WwPrim rest = 'P' : rest
116 show1 WwEnum rest = 'E' : rest
117 show1 (WwUnpack args) rest = "U(" ++ showList args (')' : rest)
119 instance Outputable Demand where
120 ppr sty si = ppStr (showList [si] "")