[project @ 1996-03-19 08:58:34 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               = [GenCoreBinding       Id DefBindee]
16 > type DefBinding               = GenCoreBinding        Id DefBindee
17 > type DefExpr                  = GenCoreExpr           Id DefBindee
18 > type DefAtom                  = GenCoreAtom   DefBindee
19 > type DefCaseAlternatives      = GenCoreCaseAlts Id DefBindee
20 > type DefCaseDefault           = GenCoreCaseDefault Id DefBindee
21
22 > type DefCoreArg = GenCoreArg 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 Var (DefArgExpr e)      ==  e
48 VarArg (Label l e)      ==  VarArg (DefArgExpr (Var (Label l e)))
49
50 For completeness, we should also have:
51
52 VarArg (DefArgVar v) == VarArg (DefArgExpr (Var (DefArgVar v)))
53 LitArg l                == VarArg (DefArgExpr (Lit l))
54
55 In other words, atoms must all be of the form (VarArg (DefArgExpr
56 _)) and the argument to a Var can only be Label or DefArgVar.
57
58 > mkLabel :: DefExpr -> DefExpr -> DefExpr
59 > mkLabel l e = Var (Label l e)