[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / compiler / deforest / DefSyn.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1994
3 %
4 \section[DefSyn]{A temporary datatype for the deforestation pass}
5
6 > module DefSyn where
7
8 > import CoreSyn
9 > import Outputable
10 > import Util
11
12 This is exactly the same as core, except that the argument to
13 application can be an arbitrary expression.
14
15 > type DefProgram               = [CoreBinding  Id DefBindee]
16 > type DefBinding               = CoreBinding   Id DefBindee
17 > type DefExpr                  = CoreExpr      Id DefBindee
18 > type DefAtom                  = CoreAtom      DefBindee
19 > type DefCaseAlternatives      = CoreCaseAlternatives Id DefBindee
20 > type DefCaseDefault           = CoreCaseDefault Id DefBindee
21
22 > type DefCoreArg = CoreArg DefBindee
23
24 > data DefBindee 
25 >       = DefArgExpr DefExpr            -- arbitrary expressions as argumemts
26 >       | DefArgVar  Id                 -- or just ids
27 >       | Label DefExpr DefExpr         -- labels for detecting cycles
28
29
30 Ok, I've cheated horribly here.  Instead of defining a new data type
31 including the new Label construct, I've just defined a new
32 parameterisation of Core in which a variable can be one of {variable,
33 expression, label}.  This gives us both arbitrary expressions on the
34 right hand side of application, in addition to the new Label
35 construct.
36
37 The penalty for this is that expressions will have extra indirections
38 as compared with a new datatype.  The saving is basically not having
39 to define a new datatype almost identical to Core.
40
41 Because our parameterised datatype is a little too general (i.e. it
42 distinguishes expressions that we wish to equate), there are some
43 invariants that will be adhered to during the transformation.  The
44 following are alternative representations for certain expressions.
45 The forms on the left are disallowed:
46
47 CoVar (DefArgExpr e)    ==  e
48 CoVarAtom (Label l e)   ==  CoVarAtom (DefArgExpr (CoVar (Label l e)))
49
50 For completeness, we should also have:
51
52 CoVarAtom (DefArgVar v) == CoVarAtom (DefArgExpr (CoVar (DefArgVar v)))
53 CoLitAtom l             == CoVarAtom (DefArgExpr (CoLit l))
54
55 In other words, atoms must all be of the form (CoVarAtom (DefArgExpr
56 _)) and the argument to a CoVar can only be Label or DefArgVar.
57
58 > mkLabel :: DefExpr -> DefExpr -> DefExpr
59 > mkLabel l e = CoVar (Label l e)