diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2022-12-11 18:45:46 +0200 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2022-12-11 18:48:28 +0200 |
| commit | e0e1c1d7573fc5251fe537314b6a6cfefae09e39 (patch) | |
| tree | b68787e42aff081fa23ad733ae73772a94fbc668 /src/Utils.hs | |
| parent | 3f7d328d356c75c0ae57c67eb64fb5337361cce7 (diff) | |
Ensure that imports do not overwrite symbols
Diffstat (limited to 'src/Utils.hs')
| -rw-r--r-- | src/Utils.hs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/Utils.hs b/src/Utils.hs index 1eabd72..d1a1642 100644 --- a/src/Utils.hs +++ b/src/Utils.hs @@ -10,7 +10,8 @@ import qualified Data.Char as C import qualified Data.Text as T import qualified FarmHash as FH import qualified Data.ByteString.UTF8 as BSU -import Data.Word as W +import qualified Data.Maybe as MB +import qualified Data.Word as W -- TYPES @@ -39,7 +40,8 @@ data Binding a | Memoized (M.Map [a] a) a deriving Show -type Env = M.Map String (Binding AST) +type SourceModule = String +type Env = M.Map String (SourceModule, Binding AST) type Scope = [(String, AST)] type AtomMap = M.Map LAtomRef AST @@ -68,6 +70,12 @@ getConfig = do s <- get return $ stateConfig s +getCurrentModule :: LContext SourceModule +getCurrentModule = do + config <- getConfig + let curMod = configScriptFileName config $> MB.fromMaybe "<repl>" + return curMod + putEnv :: Env -> LContext () putEnv env = do modify (\s -> s { stateEnv = env }) @@ -75,7 +83,8 @@ putEnv env = do insertEnv :: String -> Binding AST -> LContext () insertEnv k v = do env <- getEnv - putEnv $ M.insert k v env + currentModule <- getCurrentModule + putEnv $ M.insert k (currentModule, v) env incrementDepth :: LContext () incrementDepth = |
