Skip to content

Commit

Permalink
wrk: misc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
doyougnu committed Jan 8, 2025
1 parent 5b6de9f commit 4de0c16
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
1 change: 0 additions & 1 deletion klister.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ common deps
megaparsec >= 7.0.5 && < 9.7,
mtl >= 2.2.2 && < 2.4,
prettyprinter >= 1.2 && < 1.8,
prettyprinter >= 1.2 && < 1.8,
text >= 1.2,
transformers ^>= 0.6

Expand Down
22 changes: 16 additions & 6 deletions src/Evaluator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ module Evaluator
, try
, projectError
, projectKont
, constructErrorType
) where

import Control.Lens hiding (List, elements)
Expand All @@ -101,8 +102,6 @@ import Syntax.SrcLoc
import Type
import Value

import Debug.Trace

-- -----------------------------------------------------------------------------
-- Interpreter Data Types

Expand All @@ -119,7 +118,6 @@ data TypeError = TypeError
, _typeErrorActual :: Type
}
deriving (Eq, Show)
makeLenses ''TypeError

data EvalError
= EvalErrorUnbound Var
Expand Down Expand Up @@ -578,9 +576,21 @@ extends exts env = foldl' (\acc (n,x,v) -> Env.insert x n v acc) env exts
evalErrorType :: Text -> Value -> EvalError
evalErrorType expected got =
EvalErrorType $ TypeError
{ _typeErrorExpected = expected
, _typeErrorActual = describeVal got
}
{ _typeErrorExpected = expected
, _typeErrorActual = describeVal got
}

-- this is a copy of 'evalErrorType' but with no memory of how we got to this
-- error state. This should just be a stopgap and we should remove it. Its sole
-- use case is in the expander where we have redundant error checks due to
-- functions such as @doTypeCase@
constructErrorType :: Text -> Value -> EState
constructErrorType expected got = Er err mempty Halt
where
err = EvalErrorType $ TypeError
{ _typeErrorExpected = expected
, _typeErrorActual = describeVal got
}

doTypeCase :: VEnv -> SrcLoc -> Ty -> [(TypePattern, Core)] -> Either EState Value
-- We pass @Right $ ValueType v0@ here so that the Core type-case still matches
Expand Down
19 changes: 6 additions & 13 deletions src/Expander.hs
Original file line number Diff line number Diff line change
Expand Up @@ -912,8 +912,7 @@ runTask (tid, localData, task) = withLocal localData $ do
forkInterpretMacroAction dest nextStep kont
otherVal -> do
p <- currentPhase
-- debug $ MacroEvaluationError p $ evalErrorType "macro action" otherVal
error "MacroEvaluationError p $ evalErrorType \"macro action\" otherVal"
debug $ MacroEvaluationError p $ constructErrorType "macro action" otherVal
Left err -> do
-- an error occurred in the evaluator, so just report it
p <- currentPhase
Expand Down Expand Up @@ -982,8 +981,7 @@ runTask (tid, localData, task) = withLocal localData $ do
forkExpandSyntax dest syntax
other -> do
p <- currentPhase
-- debug $ MacroEvaluationError p $ evalErrorType "syntax" other
error "MacroEvaluationError p $ evalErrorType \"syntax\" other"
debug $ MacroEvaluationError p $ constructErrorType "syntax" other
ContinueMacroAction dest value (closure:kont) -> do
case apply closure value of
Left err -> do
Expand All @@ -995,8 +993,7 @@ runTask (tid, localData, task) = withLocal localData $ do
forkInterpretMacroAction dest macroAction kont
other -> do
p <- currentPhase
-- debug $ MacroEvaluationError p $ evalErrorType "macro action" other
error "MacroEvaluationError p $ evalErrorType \"macro action\" other"
debug $ MacroEvaluationError p $ constructErrorType "macro action" other
EvalDefnAction x n p expr ->
linkedCore expr >>=
\case
Expand Down Expand Up @@ -1325,15 +1322,11 @@ expandOneForm prob stx
ValueSyntax expansionResult ->
forkExpandSyntax prob (flipScope p stepScope expansionResult)
other -> debug $ ValueNotSyntax other
other -> error "ValueNotMacro other"
-- debug $ ValueNotMacro other
Nothing -> error $ show $ InternalError $
other -> debug $ ValueNotMacro $ constructErrorType "error in user macro" other
Nothing -> debug $ InternalError $
"No transformer yet created for " ++ shortShow ident ++
" (" ++ show transformerName ++ ") at phase " ++ shortShow p
-- debug $ InternalError $
-- "No transformer yet created for " ++ shortShow ident ++
-- " (" ++ show transformerName ++ ") at phase " ++ shortShow p
Just other -> error "debug $ ValueNotMacro other"
Just other -> debug $ ValueNotMacro $ constructErrorType "expected macro but got value" other
| otherwise =
case prob of
ModuleDest {} ->
Expand Down

0 comments on commit 4de0c16

Please sign in to comment.