1
1
mirror of https://github.com/github/semantic.git synced 2024-12-24 23:42:31 +03:00

Add Numeric2Error and remove TypeError

This commit is contained in:
joshvera 2018-04-05 18:14:33 -04:00
parent 1d05cb1cfc
commit 0997ee81e2
6 changed files with 19 additions and 7 deletions

View File

@ -1,3 +1,7 @@
def require_dependency(path)
require_relative(path)
end
class Object
def new
self

View File

@ -34,6 +34,8 @@ instance ( Effectful m
yield (Env.push env)
(CallError val) -> yield val
(StringError val) -> yield (pack $ show val)
(BoolError val) -> yield True)
BoolError{} -> yield True
Numeric2Error{} -> unit >>= yield
)
analyzeModule = liftAnalyze analyzeModule

View File

@ -27,7 +27,8 @@ instance ( Effectful m
type Effects location term value (BadVariables m effects) = State [Name] ': Effects location term value (m effects)
analyzeTerm eval term = resumeException @(EvalError value) (liftAnalyze analyzeTerm eval term) (
\yield (FreeVariableError name) ->
raise (modify' (name :)) >> unit >>= yield)
\yield err -> case err of
(FreeVariableError name) -> raise (modify' (name :)) >> unit >>= yield
(FreeVariablesError names) -> raise (modify' (names <>)) >> yield (last names) )
analyzeModule = liftAnalyze analyzeModule

View File

@ -189,20 +189,20 @@ class ValueRoots location value where
-- The type of exceptions that can be thrown when constructing values in `MonadValue`.
data ValueError location value resume where
TypeError :: Prelude.String -> ValueError location value value
StringError :: value -> ValueError location value ByteString
NamespaceError :: Prelude.String -> ValueError location value (Environment location value)
ScopedEnvironmentError :: Prelude.String -> ValueError location value (Environment location value)
CallError :: value -> ValueError location value value
BoolError :: value -> ValueError location value Bool
Numeric2Error :: value -> value -> ValueError location value value
instance Eq value => Eq1 (ValueError location value) where
liftEq _ (TypeError a) (TypeError b) = a == b
liftEq _ (StringError a) (StringError b) = a == b
liftEq _ (NamespaceError a) (NamespaceError b) = a == b
liftEq _ (ScopedEnvironmentError a) (ScopedEnvironmentError b) = a == b
liftEq _ (CallError a) (CallError b) = a == b
liftEq _ (BoolError a) (BoolError c) = (a == c)
liftEq _ (BoolError a) (BoolError c) = a == c
liftEq _ (Numeric2Error a b) (Numeric2Error c d) = (a == c) && (b == d)
liftEq _ _ _ = False
deriving instance (Show value) => Show (ValueError location value resume)

View File

@ -15,6 +15,7 @@ module Data.Abstract.Evaluatable
, evaluatePackageBody
, throwLoadError
, throwEvalError
, throwValueError
, resolve
, listModulesInDir
, require
@ -95,6 +96,10 @@ instance Eq1 (EvalError term) where
liftEq _ (FreeVariablesError a) (FreeVariablesError b) = a == b
liftEq _ _ _ = False
throwValueError :: MonadEvaluatable location term value m => ValueError location value resume -> m resume
throwValueError = throwException
throwLoadError :: MonadEvaluatable location term value m => LoadError term value resume -> m resume
throwLoadError = throwException

View File

@ -259,7 +259,7 @@ instance forall location term m. (Monad m, MonadEvaluatable location term (Value
| Just (Float i, Integer j) <- prjPair pair = f i j & specialize
| Just (Float i, Rational j) <- prjPair pair = f i j & specialize
| Just (Float i, Float j) <- prjPair pair = f i j & specialize
| otherwise = fail ("Invalid operands to liftNumeric2: " <> show pair)
| otherwise = throwValueError (Numeric2Error left right)
where
-- Dispatch whatever's contained inside a 'Number.SomeNumber' to its appropriate 'MonadValue' ctor
specialize :: MonadValue location value m => Number.SomeNumber -> m value