1 /****************************************************************
2 * Grammar for interface files
3 ****************************************************************/
5 This document purports to describe the syntax (and semantics?) of
6 interface files generated by GHC for use by Hugs.
9 /****************************************************************
11 ****************************************************************/
13 o GHC currently generates "Functor( :Functor :Functor map )" in export lists.
14 This is no longer legal and is very confusing besides - but what
15 will GHC generate instead?
18 /****************************************************************
19 * Closures generated by GHC
20 ****************************************************************/
22 GHC generates a closure for the following objects (if exported):
26 o methods selectors and superclass selectors
27 o selector functions (from record syntax)
30 If an object foo (respectively Foo) is declared in a module Bar, then
31 the closure is called Bar_foo_closure (respectively Bar_Foo_closure).
33 Whether the object is static or not is not reflected in the name. The
34 type or arity of the object is not reflected in the name. The name is
37 Modifications to the above:
39 1) Depending on the architecture, it might be necessary to add a
40 leading underscore to the name.
42 2) We also have to apply the infamous Z-encoding:
44 Code from somewhere inside GHC (circa 1994)
46 "std"++xs -> "Zstd"++xs
63 char_to_c c = "Z" ++ show (ord c)
65 (There's a commented out piece of code in rts/Printer.c which
69 /****************************************************************
71 ****************************************************************/
73 The lexical syntax is exactly the same as for Haskell with the
79 We add: __export __interface __requires
85 GHC will use pragmas of the form: {-## ##-}.
87 These are always ignored by Hugs and may be ignored by GHC.
89 GHC will be able to use lazy parsing for these - just as it
90 currently does for unfoldings and the like.
93 Compiler generated names
94 ~~~~~~~~~~~~~~~~~~~~~~~~
96 Are of the form _letter(letter|digit|symbol)*.
98 It's important that they can always be generated by putting "_l"
99 in front of a valid Haskell varid, varop, conid or conop.
101 It's also important that valid Haskell patterns such as _:_
102 should not be valid compiler generated names.
104 The letter indicates something about the kind of object it is
105 but all that Hugs needs to do is separate conid/ops from varid/ops
106 - which it does depending on whether the letter is uppercase.
109 /****************************************************************
111 ****************************************************************/
113 iface : '__interface' ifaceName NUMLIT version 'where' Body
115 Body : '__requires' STRINGLIT ';'
117 { instanceImportDecl ';' }
127 /****************************************************************
128 * Import-export stuff
130 * I believe the meaning of 'import' is "qualified import" - but
131 * I'm not sure. - ADR
132 ****************************************************************/
134 importDecl : 'import' CONID NUMLIT
135 instanceImportDecl : 'instance' 'import' CONID NUMLIT
136 exportDecl : '__export' CONID { Entity }
139 | EntityOcc StuffInside
140 | EntityOcc '|' StuffInside
147 StuffInside : '{' ValOcc { ValOcc } '}'
152 /****************************************************************
154 ****************************************************************/
156 fixityDecl : 'infixl' optdigit op
157 | 'infixr' optdigit op
158 | 'infix' optdigit op
160 /****************************************************************
163 * o data decls use "Data" on lhs and rhs to allow this decl:
167 * o data declarations don't have the usual Haskell syntax:
168 * o they don't have strictness annotations
169 * o they are given an explicit signature instead of a list of
171 * o field selectors are given an explicit signature
173 * [Simon PJ asked me to look again at how much work it would take to
174 * handle the standard syntax. The answer is:
175 * o It takes an awful lot of code to process the standard syntax.
176 * o I can hardly reuse any of the existing code because it is too
177 * tightly interwoven with other parts of static analysis.
178 * o The rules for processing data decls are very intricate
179 * (and are worse since existentials and local polymorphism were
180 * added). Implementing a complicated thing twice (once in
181 * GHC and once in Hugs) is bad; implementing it a third time
182 * is Just Plain Wrong.
185 * Data decls look like this:
187 * data List a = Nil :: forall [a] => List a
188 * | Cons{hd,tl} :: forall [a] => a -> List a -> List a
190 * hd :: forall [a] => List a -> a
191 * tl :: forall [a] => List a -> List a
193 * o The tyvars on the lhs serve only to help infer the kind of List
194 * o The type of each data constructor and selector is written
196 * o A small amount of work is required to figure out which
197 * variables are existentially quantified.
198 * o GHC will require an inlining pragma to recover strictness
200 ****************************************************************/
202 typeDecl : NUMLIT 'type' TCName {TVBndr} '=' Type
203 | NUMLIT 'data' Data {TVBndr} ['=' Constrs ['where' Sels]]
204 | NUMLIT 'newtype' TCName {TVBndr} [ '=' Data AType ]
206 Constrs : Constr {'|' Constr}
207 Constr : Data [Fields] '::' Type
208 Fields : '{' VarName {',' VarName} '}'
211 Sel : VarName '::' ['!'] Type
213 /****************************************************************
214 * Classes and instances
216 * Question: should the method signature include the class
217 * constraint? That is, should we write the Eq decl like this:
219 * class Eq a where { (==) :: a -> a -> Bool } -- like Haskell
223 * class Eq a where { (==) :: Eq a => a -> a -> Bool }
225 * There's not much to choose between them but the second version
226 * is more consistent with what we're doing with data constructors.
227 ****************************************************************/
229 classDecl : NUMLIT 'class' [ Context '=>' ] TCName {TVBndr} 'where' CSigs
230 instanceDecl : 'instance' [Quant] Class '=' Var
232 CSigs : '{' CSig { ';' CSigs } '}'
233 CSig : VarName ['='] '::' Type
235 /****************************************************************
237 ****************************************************************/
243 Context : '(' Class { ',' Class } ')'
245 Class : QTCName { AType }
247 BType : AType { AType }
252 | '(' Type ')' // parens
253 | '(' Type ',' Type { ',' Type } ')' // tuple
254 | '[' Type ']' // list
255 | '{' QTCName { AType } '}' // dictionary
258 Quant : 'forall' {TVBndr} [Context] '=>'
260 TVBndr : TVName [ '::' AKind ]
262 Kind : { AKind -> } AKind
263 AKind : VAROP // really '*'
266 /****************************************************************
268 ****************************************************************/
270 valueDecl : NUMLIT Var '::' Type
272 /****************************************************************
274 ****************************************************************/
301 /****************************************************************
303 ****************************************************************/