Skip to content

Commit

Permalink
Add option to hide prelude from certain step
Browse files Browse the repository at this point in the history
  • Loading branch information
edsko committed Dec 20, 2023
1 parent 966c0fb commit 95b2fd6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/circular_hos.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
--
-- > cabal run visualize-cbn -- \
-- > --show-trace \
-- > --hide-prelude \
-- > --hide-prelude=1 \
-- > --gc \
-- > --selector-thunk-opt \
-- > --inline-heap \
Expand Down
2 changes: 1 addition & 1 deletion examples/repmin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
--
-- > cabal run visualize-cbn -- \
-- > --show-trace \
-- > --hide-prelude \
-- > --hide-prelude=1 \
-- > --gc \
-- > --selector-thunk-opt \
-- > --inline-heap \
Expand Down
5 changes: 3 additions & 2 deletions src/CBN/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ parseSummarizeOptions = SummarizeOptions
, value 1000
, metavar "N"
])
<*> (switch $ mconcat [
<*> (optional $ option auto $ mconcat [
long "hide-prelude"
, help "Hide the prelude from the help"
, metavar "STEP"
, help "Hide the prelude from the help from the given step"
])
<*> (many $ option str $ mconcat [
long "hide-term"
Expand Down
12 changes: 7 additions & 5 deletions src/CBN/Trace.hs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ traceTerm shouldGC shouldInline enableSelThunkOpt = go
data SummarizeOptions = SummarizeOptions {
summarizeCollapseBeta :: Bool
, summarizeMaxNumSteps :: Int
, summarizeHidePrelude :: Bool
, summarizeHidePrelude :: Maybe Int
, summarizeHideTerms :: [String]
, summarizeHideGC :: Bool
, summarizeHideSelThunk :: Bool
Expand Down Expand Up @@ -167,7 +167,7 @@ summarize SummarizeOptions{..} = go 0

where
showSrc :: TraceCont -> Trace
showSrc = Trace (goHeap hp, e)
showSrc = Trace (goHeap n hp, e)

-- | We already saw one beta reduction; skip any subsequent ones
goBeta :: Int -> Trace -> TraceCont
Expand All @@ -186,13 +186,15 @@ summarize SummarizeOptions{..} = go 0
_otherwise -> False

-- | Cleanup the heap
goHeap :: Heap Term -> Heap Term
goHeap (Heap next heap) =
goHeap :: Int -> Heap Term -> Heap Term
goHeap n (Heap next heap) =
Heap next $ Map.filterWithKey shouldShow heap
where
shouldShow :: Ptr -> Term -> Bool
shouldShow (Ptr Nothing (Just name)) _ = and [
not summarizeHidePrelude
case summarizeHidePrelude of
Nothing -> True
Just n' -> n < n'
, not (name `elem` summarizeHideTerms)
]
shouldShow (Ptr _ _) _ = True
Expand Down

0 comments on commit 95b2fd6

Please sign in to comment.