Skip to content

Commit

Permalink
style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Sep 13, 2024
1 parent 4d778dc commit d8accb3
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/Juvix/Compiler/Core/Info/FreeVarsInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ makeLenses ''FreeVarsInfo
computeFreeVarsInfo :: Node -> Node
computeFreeVarsInfo = computeFreeVarsInfo' 1

-- | `lambdaMultiplier` specifies how much to multiply the free variable count
-- for variables under lambdas
computeFreeVarsInfo' :: Int -> Node -> Node
computeFreeVarsInfo' lambdaMultiplier = umap go
where
Expand All @@ -36,25 +38,26 @@ computeFreeVarsInfo' lambdaMultiplier = umap go
fvi =
FreeVarsInfo
. fmap (* lambdaMultiplier)
. Map.mapKeysMonotonic (\idx -> idx - 1)
. Map.filterWithKey (\idx _ -> idx >= 1)
$ getFreeVarsInfo _lambdaBody ^. infoFreeVars
$ getFreeVars 1 _lambdaBody
_ ->
modifyInfo (Info.insert fvi) node
where
fvi =
FreeVarsInfo $
foldr
( \NodeChild {..} acc ->
Map.unionWith (+) acc
. Map.mapKeysMonotonic (\idx -> idx - _childBindersNum)
. Map.filterWithKey
(\idx _ -> idx >= _childBindersNum)
$ getFreeVarsInfo _childNode ^. infoFreeVars
Map.unionWith (+) acc $
getFreeVars _childBindersNum _childNode
)
mempty
(children node)

getFreeVars :: Int -> Node -> Map Index Int
getFreeVars bindersNum node =
Map.mapKeysMonotonic (\idx -> idx - bindersNum)
. Map.filterWithKey (\idx _ -> idx >= bindersNum)
$ getFreeVarsInfo node ^. infoFreeVars

getFreeVarsInfo :: Node -> FreeVarsInfo
getFreeVarsInfo = fromJust . Info.lookup kFreeVarsInfo . getInfo

Expand Down

0 comments on commit d8accb3

Please sign in to comment.