git.haldean.org del / 4b23a1f
update references to scoped globals Haldean Brown 4 years ago
3 changed file(s) with 17 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
33
44 (define root:color (v:f3)
55 (if (< (s.sphere 1.0 v) 0.001)
6 (rgb 1.0 1.0 1.0)
7 (rgb 0.0 0.0 0.0)
6 (s.rgb 1.0 1.0 1.0)
7 (s.rgb 0.0 0.0 0.0)
88 ))
2828 | Apply Expr [Expr]
2929 | NativeCall T.Text [Expr]
3030 | Id Name
31 | ScopedId Name Name
31 | ScopedId Name Name -- first is package, second is name
3232 | Number DelNum
3333 | Boolean Bool
3434 | Let Name Expr Expr
0 module Language.Del.Imports where
0 module Language.Del.Imports (collectImports, defaultImportEnv) where
11
22 import Control.Monad
33 import Data.List.Split
44 import qualified Data.Map.Strict as Map
5 import Data.Set
56 import qualified Data.Text as T
67 import Language.Del.AST
8 import Language.Del.AstUtils
79 import Language.Del.CompileDefs
810 import Language.Del.Load
911 import qualified Language.Del.Reader as R
2224 Just incvar -> splitOn ":" incvar)
2325 return $ ImportEnv dirs
2426
27 substName :: T.Text -> Set T.Text -> Expr -> Expr
28 substName alias globals e = case e of
29 Id name -> if member name globals then (ScopedId alias name) else e
30 _ -> e
31
32 updateDef :: T.Text -> Set T.Text -> Def -> Def
33 updateDef alias globals (Def n t a b) =
34 Def (T.concat [alias, ".", n]) t a (mapexpr (substName alias globals) b)
35
2536 mergeBinds :: T.Text -> Map.Map T.Text Def -> Map.Map T.Text Def -> Artifact (Map.Map T.Text Def)
2637 mergeBinds alias orig new =
2738 let aliaser = \n -> T.concat [alias, ".", n]
39 valfunc = updateDef alias (Map.keysSet new)
2840 aliasKeys = Map.mapKeys aliaser new
29 aliased = Map.map (\(Def n t a b) -> (Def (aliaser n) t a b)) aliasKeys
41 aliased = Map.map valfunc aliasKeys
3042 overlap = Map.intersection orig aliased
3143 in if Map.size overlap > 0
3244 then Failure $ ImportNameClash alias (Map.keys overlap)