Converter.hs 978 Bytes
Newer Older
1
2
module Converter where

3
import Program
4
5
import GeneralTerms

marton bognar's avatar
marton bognar committed
6
7
-- | Data type for storing the functions that depend on the
-- variable representation
marton bognar's avatar
marton bognar committed
8
9
10
data ConvertFunctions = VF {
  variableType :: Language -> (Type, [Constructor]),
  userTypes :: Language -> [(Type, [Constructor])],
11
  variableInstances :: (Type, [Constructor]) -> [(Type, Type, [Function])],
marton bognar's avatar
marton bognar committed
12
  variableFunctions :: Language -> (Type, [Constructor]) -> [Function],
13
14
  envFunctions :: Language -> [Function],
  nativeCode :: Language -> (Type, [Constructor])-> [String]
15
16
}

marton bognar's avatar
marton bognar committed
17
-- | Convert a language into a program using the specified variable functions
marton bognar's avatar
marton bognar committed
18
convert :: Language -> ConvertFunctions -> Program
19
convert lan@(nsd, sd, imp, cd) vf =
marton bognar's avatar
marton bognar committed
20
  let var = (variableType vf) lan
21
22
  in P {
    imports = imp,
23
    types = var : (userTypes vf) lan,
24
25
    instances = (variableInstances vf) var,
    functions = (variableFunctions vf) lan var ++
marton bognar's avatar
marton bognar committed
26
                (envFunctions vf) lan,
27
    code = (nativeCode vf) lan var ++ cd
28
  }