1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE Rank2Types #-}
19import qualified Data.Map as Map
20import qualified Data.Name as Name
21import qualified Data.Set as Set
23import qualified AST.Canonical as Can
24import qualified AST.Optimized as Opt
25import qualified Data.Index as Index
26import qualified Elm.ModuleName as ModuleName
27import qualified Elm.Package as Pkg
28import qualified Reporting.Annotation as A
40 -> Map.Map Name.Name Int
41 -> (Int -> Set.Set Opt.Global -> Map.Map Name.Name Int -> a -> r)
46run :: Tracker a -> (Set.Set Opt.Global, Map.Map Name.Name Int, a)
48 k 0 Set.empty Map.empty
49 (\_uid deps fields value -> (deps, fields, value))
52generate :: Tracker Name.Name
54 Tracker $ \uid deps fields ok ->
55 ok (uid + 1) deps fields (Name.fromVarIndex uid)
58registerKernel :: Name.Name -> a -> Tracker a
59registerKernel home value =
60 Tracker $ \uid deps fields ok ->
61 ok uid (Set.insert (toKernelGlobal home) deps) fields value
64toKernelGlobal :: Name.Name -> Opt.Global
66 Opt.Global (ModuleName.Canonical Pkg.kernel home) Name.dollar
69registerGlobal :: ModuleName.Canonical -> Name.Name -> Tracker Opt.Expr
70registerGlobal home name =
71 Tracker $ \uid deps fields ok ->
72 let global = Opt.Global home name in
73 ok uid (Set.insert global deps) fields (Opt.VarGlobal global)
76registerDebug :: Name.Name -> ModuleName.Canonical -> A.Region -> Tracker Opt.Expr
77registerDebug name home region =
78 Tracker $ \uid deps fields ok ->
79 let global = Opt.Global ModuleName.debug name in
80 ok uid (Set.insert global deps) fields (Opt.VarDebug name home region Nothing)
83registerCtor :: ModuleName.Canonical -> Name.Name -> Index.ZeroBased -> Can.CtorOpts -> Tracker Opt.Expr
84registerCtor home name index opts =
85 Tracker $ \uid deps fields ok ->
87 global = Opt.Global home name
88 newDeps = Set.insert global deps
92 ok uid newDeps fields (Opt.VarGlobal global)
95 ok uid newDeps fields $
97 "True" | home == ModuleName.basics -> Opt.Bool True
98 "False" | home == ModuleName.basics -> Opt.Bool False
99 _ -> Opt.VarEnum global index
102 ok uid (Set.insert identity newDeps) fields (Opt.VarBox global)
105identity :: Opt.Global
107 Opt.Global ModuleName.basics Name.identity
110registerField :: Name.Name -> a -> Tracker a
111registerField name value =
112 Tracker $ \uid d fields ok ->
113 ok uid d (Map.insertWith (+) name 1 fields) value
116registerFieldDict :: Map.Map Name.Name v -> a -> Tracker a
117registerFieldDict newFields value =
118 Tracker $ \uid d fields ok ->
119 ok uid d (Map.unionWith (+) fields (Map.map toOne newFields)) value
126registerFieldList :: [Name.Name] -> a -> Tracker a
127registerFieldList names value =
128 Tracker $ \uid deps fields ok ->
129 ok uid deps (foldr addOne fields names) value
132addOne :: Name.Name -> Map.Map Name.Name Int -> Map.Map Name.Name Int
134 Map.insertWith (+) name 1 fields
141instance Functor Tracker where
142 fmap func (Tracker kv) =
143 Tracker $ \n d f ok ->
146 ok n1 d1 f1 (func value)
151instance Applicative Tracker where
154 Tracker $ \n d f ok -> ok n d f value
156 (<*>) (Tracker kf) (Tracker kv) =
157 Tracker $ \n d f ok ->
162 ok n2 d2 f2 (func value)
169instance Monad Tracker where
172 (>>=) (Tracker k) callback =
173 Tracker $ \n d f ok ->
177 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