2 % (c) The GRASP/AQUA Project, Glasgow University, 1993-1998
4 %************************************************************************
6 \section[HsCore]{Core-syntax unfoldings in Haskell interface files}
8 %************************************************************************
10 We could either use this, or parameterise @GenCoreExpr@ on @Types@ and
11 @TyVars@ as well. Currently trying the former... MEGA SIGH.
15 UfExpr(..), UfAlt, UfBinder(..), UfNote(..),
16 UfBinding(..), UfCon(..)
19 #include "HsVersions.h"
22 import HsTypes ( HsType, pprParendHsType )
25 import Const ( Literal )
31 %************************************************************************
33 \subsection[HsCore-types]{Types for read/written Core unfoldings}
35 %************************************************************************
40 | UfType (HsType name)
41 | UfCon (UfCon name) [UfExpr name]
42 | UfTuple name [UfExpr name] -- Type arguments omitted
43 | UfLam (UfBinder name) (UfExpr name)
44 | UfApp (UfExpr name) (UfExpr name)
45 | UfCase (UfExpr name) name [UfAlt name]
46 | UfLet (UfBinding name) (UfExpr name)
47 | UfNote (UfNote name) (UfExpr name)
49 data UfNote name = UfSCC CostCentre
50 | UfCoerce (HsType name)
53 type UfAlt name = (UfCon name, [name], UfExpr name)
55 data UfCon name = UfDefault
58 | UfLitLitCon FAST_STRING (HsType name)
60 | UfCCallOp FAST_STRING -- callee
61 Bool -- True => dynamic (first arg is fun. pointer)
62 Bool -- True <=> casm, rather than ccall
63 Bool -- True <=> might cause GC
66 = UfNonRec (UfBinder name)
68 | UfRec [(UfBinder name, UfExpr name)]
71 = UfValBinder name (HsType name)
72 | UfTyBinder name Kind
76 %************************************************************************
78 \subsection[HsCore-print]{Printing Core unfoldings}
80 %************************************************************************
83 instance Outputable name => Outputable (UfExpr name) where
85 ppr (UfType ty) = char '@' <+> pprParendHsType ty
88 = hsep [text "UfCon", ppr c, ppr as]
90 ppr (UfTuple c as) = parens (hsep (punctuate comma (map ppr as)))
93 = hsep [char '\\', ppr b, ptext SLIT("->"), ppr body]
95 ppr (UfApp fun arg) = ppr fun <+> ppr arg
97 ppr (UfCase scrut bndr alts)
98 = hsep [ptext SLIT("case"), ppr scrut, ptext SLIT("of"), ppr bndr,
99 braces (hsep (punctuate semi (map pp_alt alts)))]
101 pp_alt (c,bs,rhs) = hsep [ppr c, ppr bs, ppr_arrow, ppr rhs]
103 ppr_arrow = ptext SLIT("->")
105 ppr (UfLet (UfNonRec b rhs) body)
106 = hsep [ptext SLIT("let"), ppr b, equals, ppr rhs, ptext SLIT("in"), ppr body]
107 ppr (UfLet (UfRec pairs) body)
108 = hsep [ptext SLIT("letrec"), braces (hsep (punctuate semi (map pp_pair pairs))), ptext SLIT("in"), ppr body]
110 pp_pair (b,rhs) = hsep [ppr b, equals, ppr rhs]
112 ppr (UfNote note body)
113 = hsep [ptext SLIT("_NOTE_ [ToDo]>"), ppr body]
115 instance Outputable name => Outputable (UfCon name) where
116 ppr UfDefault = text "DEFAULT"
117 ppr (UfDataCon d) = ppr d
118 ppr (UfPrimOp p) = ppr p
119 ppr (UfCCallOp str is_dyn is_casm can_gc)
120 = hcat [before, ptext str, after]
122 before = (if is_dyn then ptext SLIT("_dyn_") else empty) <>
123 ptext (if is_casm then SLIT("_casm_ ``") else SLIT("_ccall_ "))
124 after = if is_casm then text "'' " else space
126 instance Outputable name => Outputable (UfBinder name) where
127 ppr (UfValBinder name ty) = hsep [ppr name, dcolon, ppr ty]
128 ppr (UfTyBinder name kind) = hsep [ppr name, dcolon, ppr kind]