1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Optimize.Environment
8 , getTailCall, setTailCall
15import qualified Control.Monad.State as State
16import Data.Monoid ((<>))
17import qualified Data.Set as Set
18import qualified Data.Text as Text
19import Data.Text (Text)
21import qualified AST.Effects as Effects
22import qualified AST.Expression.Optimized as Opt
23import qualified AST.Module.Name as ModuleName
24import qualified AST.Variable as Var
25import qualified Optimize.DecisionTree as DT
34 { _read_only_variants :: !DT.VariantDict
35 , _read_only_home :: !ModuleName.Canonical
37 , _deps :: Set.Set Var.Global
38 , _effects :: Maybe Effects.ManagerType
39 , _has_tail_call :: !Bool
53 -> ModuleName.Canonical
54 -> Optimizer (Text, Opt.Def)
56run variantDict home optimizer =
58 ((name, def), Env _ _ _ deps fx _) =
59 State.runState optimizer $
60 Env variantDict home 0 Set.empty Nothing False
62 ( name, Opt.Decl deps fx def )
69getVariantDict :: Optimizer DT.VariantDict
71 State.gets _read_only_variants
74getHome :: Optimizer ModuleName.Canonical
76 State.gets _read_only_home
83getTailCall :: Optimizer Bool
85 State.gets _has_tail_call
88setTailCall :: Bool -> Optimizer ()
91 State.put (env { _has_tail_call = bool })
98freshName :: Optimizer Text
100 do (Env vs home uid deps fx htc) <- State.get
101 State.put (Env vs home (uid + 1) deps fx htc)
102 return ("_p" <> Text.pack (show uid))
106-- REGISTER DEPENDENCIES
109register :: Var.Global -> Optimizer ()
111 State.modify (registerHelp global)
114registerHelp :: Var.Global -> Env -> Env
115registerHelp dep (Env vs home uid deps fx htc) =
116 Env vs home uid (Set.insert dep deps) fx htc
123registerEffects :: ModuleName.Canonical -> Effects.ManagerType -> Optimizer Effects.ManagerType
124registerEffects home manager =
125 do (Env vs hm uid deps _ htc) <- State.get
126 let newDeps = Set.union deps (getEffectDeps home manager)
127 State.put (Env vs hm uid newDeps (Just manager) htc)
131getEffectDeps :: ModuleName.Canonical -> Effects.ManagerType -> Set.Set Var.Global
132getEffectDeps home manager =
133 Set.fromList $ map (Var.Global home) $
136 [ "init", "onEffects", "onSelfMsg", "cmdMap" ]
139 [ "init", "onEffects", "onSelfMsg", "subMap" ]
142 [ "init", "onEffects", "onSelfMsg", "cmdMap", "subMap" ]
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