@@ -1,104 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE OverloadedStrings #-}
3−module Elm.Compiler.Objects.Internal
4− ( Graph(..)
5− , fromModule
6− , union
7− , unions
8− , Roots
9− , mains
10− , value
11− , toGlobals
12− )
13− where
14−
15−
16−import Prelude hiding (lookup)
17−import Control.Arrow (first)
18−import Control.Monad (liftM2)
19−import Data.Binary
20−import qualified Data.Map as Map
21−import qualified Data.Text as Text
22−
23−import qualified AST.Expression.Optimized as Opt
24−import qualified AST.Kernel as Kernel
25−import qualified AST.Module.Name as ModuleName
26−import qualified AST.Module as Module
27−import qualified AST.Variable as Var
28−
29−
30−
31−-- OBJECT GRAPH
32−
33−
34−data Graph =
35− Graph
36− { _decls :: Map.Map Var.Global Opt.Decl
37− , _kernels :: Map.Map ModuleName.Raw Kernel.Data
38− }
39−
40−
41−
42−-- OBJECT GRAPH HELPERS
43−
44−
45−fromModule :: Module.Optimized -> Graph
46−fromModule (Module.Module home info) =
47− let
48− decls =
49− Map.fromList $ map (first (Var.Global home)) (Module.program info)
50− in
51− Graph decls Map.empty
52−
53−
54−union :: Graph -> Graph -> Graph
55−union (Graph decls1 kernels1) (Graph decls2 kernels2) =
56− Graph (Map.union decls1 decls2) (Map.union kernels1 kernels2)
57−
58−
59−unions :: [Graph] -> Graph
60−unions graphs =
61− Graph
62− (Map.unions (map _decls graphs))
63− (Map.unions (map _kernels graphs))
64−
65−
66−
67−-- ROOTS
68−
69−
70−data Roots
71− = Mains [ModuleName.Canonical]
72− | Value ModuleName.Canonical Text.Text
73−
74−
75−mains :: [ModuleName.Canonical] -> Roots
76−mains =
77− Mains
78−
79−
80−value :: ModuleName.Canonical -> String -> Roots
81−value home name =
82− Value home (Text.pack name)
83−
84−
85−toGlobals :: Roots -> [Var.Global]
86−toGlobals roots =
87− case roots of
88− Mains modules ->
89− map (\home -> Var.Global home "main") modules
90−
91− Value home name ->
92− [ Var.Global home name ]
93−
94−
95−
96−-- BINARY
97−
98−
99−instance Binary Graph where
100− put (Graph decls kernels) =
101− put decls >> put kernels
102−
103− get =
104− liftM2 Graph get get