mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-17 16:38:14 +03:00
fix: replace qualified bindings (#1125)
Previously, we couldn't replace qualified bindings in Envs. This change updates envReplaceBindings to accept qualified paths and to replace the binding denoted by the path, updating the module environments the binder belongs to accordingly. If the qualified path does not denote an existing module, it simply returns the environment as is (just like the unqualified case).
This commit is contained in:
parent
afa9b1223d
commit
02e04f33b2
@ -1,6 +1,7 @@
|
||||
module Env where
|
||||
|
||||
import Data.List (foldl')
|
||||
import Data.Maybe (fromMaybe)
|
||||
import qualified Map
|
||||
import Obj
|
||||
import Types
|
||||
@ -70,7 +71,12 @@ envReplaceBinding s@(SymPath [] name) binder env =
|
||||
case envParent env of
|
||||
Just parent -> env {envParent = Just (envReplaceBinding s binder parent)}
|
||||
Nothing -> env
|
||||
envReplaceBinding (SymPath _ _) _ _ = error "TODO: cannot replace qualified bindings"
|
||||
envReplaceBinding s@(SymPath (p : ps) name) binder env =
|
||||
case Map.lookup p (envBindings env) of
|
||||
Just b@(Binder _ (XObj (Mod innerEnv) i t)) ->
|
||||
envReplaceBinding (SymPath [] p) b {binderXObj = (XObj (Mod (envReplaceBinding (SymPath ps name) binder innerEnv)) i t)} env
|
||||
_ ->
|
||||
fromMaybe env (envParent env >>= \parent -> Just (env {envParent = Just (envReplaceBinding s binder parent)}))
|
||||
|
||||
envBindingNames :: Env -> [String]
|
||||
envBindingNames = concatMap select . envBindings
|
||||
|
Loading…
Reference in New Issue
Block a user