Add --scopes option to print out scoping information

This commit is contained in:
John Wiegley 2018-08-04 14:40:04 -04:00
parent 36864cdbb4
commit 705d7c474d
No known key found for this signature in database
GPG key ID: C144D8F4F19FE630
3 changed files with 9 additions and 2 deletions

View file

@ -8,6 +8,7 @@ data Options = Options
, tracing :: Bool
, thunks :: Bool
, values :: Bool
, scopes :: Bool
, reduce :: Maybe FilePath
, reduceSets :: Bool
, reduceLists :: Bool
@ -41,6 +42,7 @@ defaultOptions current = Options
, tracing = False
, thunks = False
, values = False
, scopes = False
, reduce = Nothing
, reduceSets = False
, reduceLists = False

View file

@ -45,6 +45,9 @@ nixOptions current = Options
<*> switch
( long "values"
<> help "Enable reporting of value provenance in error messages")
<*> switch
( long "scopes"
<> help "Enable reporting of scopes in evaluation traces")
<*> optional (strOption
( long "reduce"
<> help "When done evaluating, output the evaluated part of the expression to FILE"))

View file

@ -92,8 +92,10 @@ renderEvalFrame :: (MonadReader e m, Has e Options, MonadFile m)
renderEvalFrame level f = do
opts :: Options <- asks (view hasLens)
case f of
EvaluatingExpr _scope e@(Fix (Compose (Ann ann _))) ->
fmap (:[]) $ renderLocation ann
EvaluatingExpr scope e@(Fix (Compose (Ann ann _))) -> do
let scopeInfo | scopes opts = [string (show scope)]
| otherwise = []
fmap (\x -> scopeInfo ++ [x]) $ renderLocation ann
=<< renderExpr level "While evaluating" "Expression" e
ForcingExpr _scope e@(Fix (Compose (Ann ann _)))