1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE Rank2Types #-}
18import qualified Data.Map as Map
19import qualified Data.Set as Set
21import qualified AST.Canonical as Can
22import qualified AST.Optimized as Opt
23import qualified AST.Module.Name as ModuleName
24import qualified Data.Index as Index
25import qualified Elm.Name as N
26import qualified Elm.Package as Pkg
39 -> (Int -> Set.Set Opt.Global -> Map.Map N.Name Int -> a -> r)
44run :: Tracker a -> (Set.Set Opt.Global, Map.Map N.Name Int, a)
46 k 0 Set.empty Map.empty
47 (\_uid deps fields value -> (deps, fields, value))
50generate :: Tracker N.Name
52 Tracker $ \uid deps fields ok ->
53 ok (uid + 1) deps fields (N.addIndex "_n" uid)
56registerKernel :: N.Name -> a -> Tracker a
57registerKernel home value =
58 Tracker $ \uid deps fields ok ->
59 ok uid (Set.insert (toKernelGlobal home) deps) fields value
62toKernelGlobal :: N.Name -> Opt.Global
64 Opt.Global (ModuleName.Canonical Pkg.kernel home) N.dollar
67registerGlobal :: ModuleName.Canonical -> N.Name -> Tracker Opt.Expr
68registerGlobal home name =
69 Tracker $ \uid deps fields ok ->
70 let global = Opt.Global home name in
71 ok uid (Set.insert global deps) fields (Opt.VarGlobal global)
74registerCtor :: ModuleName.Canonical -> N.Name -> Index.ZeroBased -> Can.CtorOpts -> Tracker Opt.Expr
75registerCtor home name index opts =
76 Tracker $ \uid deps fields ok ->
78 global = Opt.Global home name
79 newDeps = Set.insert global deps
83 ok uid newDeps fields (Opt.VarGlobal global)
86 ok uid newDeps fields $
88 "True" | home == ModuleName.basics -> Opt.Bool True
89 "False" | home == ModuleName.basics -> Opt.Bool False
90 _ -> Opt.VarEnum global index
93 ok uid (Set.insert identity newDeps) fields (Opt.VarBox global)
98 Opt.Global ModuleName.basics N.identity
101registerField :: N.Name -> a -> Tracker a
102registerField name value =
103 Tracker $ \uid d fields ok ->
104 ok uid d (Map.insertWith (+) name 1 fields) value
107registerFieldDict :: Map.Map N.Name v -> a -> Tracker a
108registerFieldDict newFields value =
109 Tracker $ \uid d fields ok ->
110 ok uid d (Map.unionWith (+) fields (Map.map toOne newFields)) value
117registerFieldList :: [N.Name] -> a -> Tracker a
118registerFieldList names value =
119 Tracker $ \uid deps fields ok ->
120 ok uid deps (foldr addOne fields names) value
123addOne :: N.Name -> Map.Map N.Name Int -> Map.Map N.Name Int
125 Map.insertWith (+) name 1 fields
132instance Functor Tracker where
133 fmap func (Tracker kv) =
134 Tracker $ \n d f ok ->
137 ok n1 d1 f1 (func value)
142instance Applicative Tracker where
145 Tracker $ \n d f ok -> ok n d f value
147 (<*>) (Tracker kf) (Tracker kv) =
148 Tracker $ \n d f ok ->
153 ok n2 d2 f2 (func value)
160instance Monad Tracker where
163 (>>=) (Tracker k) callback =
164 Tracker $ \n d f ok ->
168 Tracker kb -> kb n1 d1 f1 ok
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list