Separate env-tree construction and usage

This commit is contained in:
Kirill Andreev 2020-07-03 20:35:58 +04:00
parent 24cc24b0d7
commit 65fc5bec75
No known key found for this signature in database
GPG Key ID: CF7DA79DE4785A47

View File

@ -5,12 +5,12 @@
-}
module AST.Scope
( HasLocalScope (..)
, addLocalScopes
, lookupEnv
, Kind (..)
, ScopedDecl (..)
)
-- ( HasLocalScope (..)
-- , addLocalScopes
-- , lookupEnv
-- , Kind (..)
-- , ScopedDecl (..)
-- )
where
import Control.Arrow (second)
@ -59,11 +59,15 @@ addLocalScopes
-> Pascal (Product ([ScopedDecl] : xs))
addLocalScopes tree =
fmap (\xs -> Cons (envAt envWithREfs $ getRange xs) xs) tree
where
envWithREfs = getEnvTree tree
getEnvTree tree = envWithREfs
where
envWithREfs = flip execState env do
flip traverseOnly tree \r (Name t) -> do
modify $ addRef (getRange r) t
return (Name t)
modify $ getRange r `addRef` t
return $ Name t
env
= execCollectM