on master help sign in
No longer need Objects.Internal => delete it
commitfeb5ece22c8bfae1c851f2b0f935a3040fb0f7df authorEvan Czaplicki <evancz@users.noreply.github.com> dateFri 8 Dec 2017, 14:31 (9 years ago) parent810172e
2 files changed+42−120
src/Elm/Compiler/Objects.hs+42−16 src/Elm/Compiler/Objects/Internal.hs−104
src/Elm/Compiler/Objects.hs+42−16
@@ -1,32 +1,58 @@
11{-# OPTIONS_GHC -Wall #-}
22module Elm.Compiler.Objects
3− ( Graph
4− , union
5− , unions
6− , graphForPackage
7− , Roots
3+ ( Gen.Roots
84 , mains
95 , value
6+ , Opt.Graph
7+ , empty
8+ , union
9+ , unions
10+ ,
1011 )
1112 where
1213
1314
15+import qualified Data.List as List
1416import qualified Data.Map as Map
17+import qualified Data.Text as Text
1518
16−import qualified AST.Kernel as Kernel
19+import qualified AST.Optimized as Opt
1720import qualified AST.Module.Name as ModuleName
18−import qualified Elm.Compiler as Compiler
19−import Elm.Compiler.Objects.Internal as Obj
21+import qualified Generate.JavaScript as Gen
22+
23+
24+
25+-- ROOTS
26+
27+
28+mains :: [ModuleName.Canonical] -> Gen.Roots
29+mains =
30+ Gen.Mains
31+
32+
33+value :: ModuleName.Canonical -> String -> Gen.Roots
34+value home name =
35+ Gen.Value home (Text.pack name)
36+
37+
38+
39+-- COMBINE GRAPHS
40+
2041
42+{-# NOINLINE empty #-}
43+empty :: Opt.Graph
44+empty =
45+ Opt.Graph Map.empty Map.empty Map.empty
2146
2247
23−-- HELPER
48+union :: Opt.Graph -> Opt.Graph -> Opt.Graph
49+union (Opt.Graph mains1 graph1 fields1) (Opt.Graph mains2 graph2 fields2) =
50+ Opt.Graph
51+ (Map.union mains1 mains2)
52+ (Map.union graph1 graph2)
53+ (Map.union fields1 fields2)
2454
2555
26−graphForPackage :: Map.Map ModuleName.Raw Kernel.Data -> [Compiler.Result] -> Obj.Graph
27−graphForPackage kernels results =
28− let
29− kernelGraph =
30− Obj.Graph Map.empty kernels
31− in
32− Obj.unions (kernelGraph : map Compiler._objs results)
56+unions :: [Opt.Graph] -> Opt.Graph
57+unions graphs =
58+ List.foldl' union empty graphs
src/Elm/Compiler/Objects/Internal.hsdeleted−104
@@ -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