CompilerEnv.hs 2.23 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
13
{- |
    Module      :  $Header$
    Description :  Environment containing the module's information
    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 defines an environment for a module containing the information
    needed throughout the compilation of the module.
-}
Björn Peemöller 's avatar
Björn Peemöller committed
14
15
module CompilerEnv where

16
17
import qualified Data.Map as Map (keys)

Björn Peemöller 's avatar
Björn Peemöller committed
18
19
import Curry.Base.Ident (ModuleIdent)

Björn Peemöller 's avatar
Björn Peemöller committed
20
import Base.TopEnv (allLocalBindings)
21

Björn Peemöller 's avatar
Björn Peemöller committed
22
import Env.Eval
Björn Peemöller 's avatar
Björn Peemöller committed
23
24
import Env.Interface
import Env.ModuleAlias
Björn Peemöller 's avatar
Björn Peemöller committed
25
import Env.OpPrec
26
import Env.TypeConstructor
Björn Peemöller 's avatar
Björn Peemöller committed
27
28
import Env.Value

Björn Peemöller 's avatar
Björn Peemöller committed
29
30
31
-- |A compiler environment contains information about the module currently
--  compiled. The information is updated during the different stages of
--  compilation.
Björn Peemöller 's avatar
Björn Peemöller committed
32
data CompilerEnv = CompilerEnv
Björn Peemöller 's avatar
Björn Peemöller committed
33
34
  { moduleIdent  :: ModuleIdent  -- ^ identifier of the module
  , interfaceEnv :: InterfaceEnv -- ^ declarations of imported interfaces
Björn Peemöller 's avatar
Björn Peemöller committed
35
  , aliasEnv     :: AliasEnv     -- ^ aliases for imported modules
Björn Peemöller 's avatar
Björn Peemöller committed
36
  , tyConsEnv    :: TCEnv        -- ^ type constructors
Björn Peemöller 's avatar
Björn Peemöller committed
37
  , valueEnv     :: ValueEnv     -- ^ functions and data constructors
Björn Peemöller 's avatar
Björn Peemöller committed
38
39
  , opPrecEnv    :: PEnv         -- ^ operator precedences
  , evalAnnotEnv :: EvalEnv      -- ^ evaluation annotations
40
  }
Björn Peemöller 's avatar
Björn Peemöller committed
41
42
43
44

initCompilerEnv :: ModuleIdent -> CompilerEnv
initCompilerEnv mid = CompilerEnv
  { moduleIdent  = mid
Björn Peemöller 's avatar
Björn Peemöller committed
45
  , interfaceEnv = initInterfaceEnv
Björn Peemöller 's avatar
Björn Peemöller committed
46
  , aliasEnv     = initAliasEnv
Björn Peemöller 's avatar
Björn Peemöller committed
47
48
  , tyConsEnv    = initTCEnv
  , valueEnv     = initDCEnv
Björn Peemöller 's avatar
Björn Peemöller committed
49
50
  , opPrecEnv    = initPEnv
  , evalAnnotEnv = initEEnv
Björn Peemöller 's avatar
Björn Peemöller committed
51
  }
52
53
54
55
56
57

showCompilerEnv :: CompilerEnv -> String
showCompilerEnv env = unlines $ concat
  [ header "ModuleIdent"      $ show $ moduleIdent  env
  , header "Interfaces"       $ show $ Map.keys      $ interfaceEnv env
  , header "ModuleAliases"    $ show $ aliasEnv     env
Björn Peemöller 's avatar
Björn Peemöller committed
58
59
60
  , header "TypeConstructors" $ show $ allLocalBindings $ tyConsEnv    env
  , header "Values"           $ show $ allLocalBindings $ valueEnv     env
  , header "Precedences"      $ show $ allLocalBindings $ opPrecEnv    env
61
62
63
  , header "Eval Annotations" $ show $ evalAnnotEnv env
  ]
  where header hdr content = [hdr, replicate (length hdr) '=', content]