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 Reporting.Annotation as A
39 -> Map.Map Name.Name Int
40 -> (Int -> Set.Set Opt.Global -> Map.Map Name.Name Int -> a -> r)
45run :: Tracker a -> (Set.Set Opt.Global, Map.Map Name.Name Int, a)
47 k 0 Set.empty Map.empty
48 (\_uid deps fields value -> (deps, fields, value))
51generate :: Tracker Name.Name
53 Tracker $ \uid deps fields ok ->
54 ok (uid + 1) deps fields (Name.fromVarIndex uid)
57registerKernel :: Name.Name -> a -> Tracker a
58registerKernel home value =
59 Tracker $ \uid deps fields ok ->
60 ok uid (Set.insert (Opt.toKernelGlobal home) deps) fields value
63registerGlobal :: ModuleName.Canonical -> Name.Name -> Tracker Opt.Expr
64registerGlobal home name =
65 Tracker $ \uid deps fields ok ->
66 let global = Opt.Global home name in
67 ok uid (Set.insert global deps) fields (Opt.VarGlobal global)
70registerDebug :: Name.Name -> ModuleName.Canonical -> A.Region -> Tracker Opt.Expr
71registerDebug name home region =
72 Tracker $ \uid deps fields ok ->
73 let global = Opt.Global ModuleName.debug name in
74 ok uid (Set.insert global deps) fields (Opt.VarDebug name home region Nothing)
77registerCtor :: ModuleName.Canonical -> Name.Name -> Index.ZeroBased -> Can.CtorOpts -> Tracker Opt.Expr
78registerCtor home name index opts =
79 Tracker $ \uid deps fields ok ->
81 global = Opt.Global home name
82 newDeps = Set.insert global deps
86 ok uid newDeps fields (Opt.VarGlobal global)
89 ok uid newDeps fields $
91 "True" | home == ModuleName.basics -> Opt.Bool True
92 "False" | home == ModuleName.basics -> Opt.Bool False
93 _ -> Opt.VarEnum global index
96 ok uid (Set.insert identity newDeps) fields (Opt.VarBox global)
101 Opt.Global ModuleName.basics Name.identity
104registerField :: Name.Name -> a -> Tracker a
105registerField name value =
106 Tracker $ \uid d fields ok ->
107 ok uid d (Map.insertWith (+) name 1 fields) value
110registerFieldDict :: Map.Map Name.Name v -> a -> Tracker a
111registerFieldDict newFields value =
112 Tracker $ \uid d fields ok ->
113 ok uid d (Map.unionWith (+) fields (Map.map toOne newFields)) value
120registerFieldList :: [Name.Name] -> a -> Tracker a
121registerFieldList names value =
122 Tracker $ \uid deps fields ok ->
123 ok uid deps (foldr addOne fields names) value
126addOne :: Name.Name -> Map.Map Name.Name Int -> Map.Map Name.Name Int
128 Map.insertWith (+) name 1 fields
135instance Functor Tracker where
136 fmap func (Tracker kv) =
137 Tracker $ \n d f ok ->
140 ok n1 d1 f1 (func value)
145instance Applicative Tracker where
148 Tracker $ \n d f ok -> ok n d f value
150 (<*>) (Tracker kf) (Tracker kv) =
151 Tracker $ \n d f ok ->
156 ok n2 d2 f2 (func value)
163instance Monad Tracker where
166 (>>=) (Tracker k) callback =
167 Tracker $ \n d f ok ->
171 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