Transformations.hs 2.16 KB
Newer Older
Björn Peemöller 's avatar
Björn Peemöller committed
1
2
3
4
5
6
7
8
9
10
11
12
{- |
    Module      :  $Header$
    Description :  Code transformations
    Copyright   :  (c) 2011, Björn Peemöller (bjp@informatik.uni-kiel.de)
    License     :  OtherLicense

    Maintainer  :  bjp@informatik.uni-kiel.de
    Stability   :  experimental
    Portability :  portable

    This module subsumes the different transformations of the source code.
-}
Björn Peemöller 's avatar
Björn Peemöller committed
13
14
15
16
17
18
module Transformations where

import Curry.Syntax

import Base.Types

Björn Peemöller 's avatar
Björn Peemöller committed
19
import Transformations.CaseCompletion as CC (completeCase)
20
import Transformations.CurryToIL      as IL (ilTrans, transType)
Björn Peemöller 's avatar
Björn Peemöller committed
21
22
23
24
import Transformations.Desugar        as DS (desugar)
import Transformations.Lift           as L  (lift)
import Transformations.Qual           as Q  (qual)
import Transformations.Simplify       as S  (simplify)
Björn Peemöller 's avatar
Björn Peemöller committed
25
26

import CompilerEnv
27
import Imports (qualifyEnv)
Björn Peemöller 's avatar
Björn Peemöller committed
28
29
import qualified IL

30
-- |Fully qualify used constructors and functions.
31
32
qual :: CompEnv Module -> CompEnv Module
qual (env, mdl) = (qualifyEnv env, mdl')
33
  where mdl' = Q.qual (moduleIdent env) (tyConsEnv env) (valueEnv env) mdl
Björn Peemöller 's avatar
Björn Peemöller committed
34

Björn Peemöller 's avatar
Björn Peemöller committed
35
-- |Remove any syntactic sugar, changes the value environment.
36
37
38
39
desugar :: CompEnv Module -> CompEnv Module
desugar (env, mdl) = (env { valueEnv = tyEnv' }, mdl')
  where (mdl', tyEnv') = DS.desugar (extensions env) (valueEnv env)
                                    (tyConsEnv env) mdl
40

Björn Peemöller 's avatar
Björn Peemöller committed
41
-- |Simplify the source code, changes the value environment.
42
43
simplify :: CompEnv Module -> CompEnv Module
simplify (env, mdl) = (env { valueEnv = tyEnv' }, mdl')
44
  where (mdl', tyEnv') = S.simplify (valueEnv env) mdl
Björn Peemöller 's avatar
Björn Peemöller committed
45

Björn Peemöller 's avatar
Björn Peemöller committed
46
-- |Lift local declarations, changes the value environment.
47
48
lift :: CompEnv Module -> CompEnv Module
lift (env, mdl) = (env { valueEnv = tyEnv' }, mdl')
49
  where (mdl', tyEnv') = L.lift (valueEnv env) mdl
Björn Peemöller 's avatar
Björn Peemöller committed
50

51
52
53
-- |Translate into the intermediate language
ilTrans :: CompEnv Module -> CompEnv IL.Module
ilTrans (env, mdl) = (env, il)
54
  where il = IL.ilTrans (valueEnv env) mdl
Björn Peemöller 's avatar
Björn Peemöller committed
55

56
-- |Translate a type into its representation in the intermediate language
57
transType :: Type -> IL.Type
58
59
60
61
62
transType = IL.transType

-- |Add missing case branches
completeCase :: CompEnv IL.Module -> CompEnv IL.Module
completeCase (env, mdl) = (env, CC.completeCase (interfaceEnv env) mdl)