mirror of
https://github.com/github/semantic.git
synced 2024-12-25 16:02:43 +03:00
Add Numeric2Error and remove TypeError
This commit is contained in:
parent
1d05cb1cfc
commit
0997ee81e2
@ -1,3 +1,7 @@
|
|||||||
|
def require_dependency(path)
|
||||||
|
require_relative(path)
|
||||||
|
end
|
||||||
|
|
||||||
class Object
|
class Object
|
||||||
def new
|
def new
|
||||||
self
|
self
|
||||||
|
@ -34,6 +34,8 @@ instance ( Effectful m
|
|||||||
yield (Env.push env)
|
yield (Env.push env)
|
||||||
(CallError val) -> yield val
|
(CallError val) -> yield val
|
||||||
(StringError val) -> yield (pack $ show val)
|
(StringError val) -> yield (pack $ show val)
|
||||||
(BoolError val) -> yield True)
|
BoolError{} -> yield True
|
||||||
|
Numeric2Error{} -> unit >>= yield
|
||||||
|
)
|
||||||
|
|
||||||
analyzeModule = liftAnalyze analyzeModule
|
analyzeModule = liftAnalyze analyzeModule
|
||||||
|
@ -27,7 +27,8 @@ instance ( Effectful m
|
|||||||
type Effects location term value (BadVariables m effects) = State [Name] ': Effects location term value (m effects)
|
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) (
|
analyzeTerm eval term = resumeException @(EvalError value) (liftAnalyze analyzeTerm eval term) (
|
||||||
\yield (FreeVariableError name) ->
|
\yield err -> case err of
|
||||||
raise (modify' (name :)) >> unit >>= yield)
|
(FreeVariableError name) -> raise (modify' (name :)) >> unit >>= yield
|
||||||
|
(FreeVariablesError names) -> raise (modify' (names <>)) >> yield (last names) )
|
||||||
|
|
||||||
analyzeModule = liftAnalyze analyzeModule
|
analyzeModule = liftAnalyze analyzeModule
|
||||||
|
@ -189,20 +189,20 @@ class ValueRoots location value where
|
|||||||
|
|
||||||
-- The type of exceptions that can be thrown when constructing values in `MonadValue`.
|
-- The type of exceptions that can be thrown when constructing values in `MonadValue`.
|
||||||
data ValueError location value resume where
|
data ValueError location value resume where
|
||||||
TypeError :: Prelude.String -> ValueError location value value
|
|
||||||
StringError :: value -> ValueError location value ByteString
|
StringError :: value -> ValueError location value ByteString
|
||||||
NamespaceError :: Prelude.String -> ValueError location value (Environment location value)
|
NamespaceError :: Prelude.String -> ValueError location value (Environment location value)
|
||||||
ScopedEnvironmentError :: Prelude.String -> ValueError location value (Environment location value)
|
ScopedEnvironmentError :: Prelude.String -> ValueError location value (Environment location value)
|
||||||
CallError :: value -> ValueError location value value
|
CallError :: value -> ValueError location value value
|
||||||
BoolError :: value -> ValueError location value Bool
|
BoolError :: value -> ValueError location value Bool
|
||||||
|
Numeric2Error :: value -> value -> ValueError location value value
|
||||||
|
|
||||||
instance Eq value => Eq1 (ValueError location value) where
|
instance Eq value => Eq1 (ValueError location value) where
|
||||||
liftEq _ (TypeError a) (TypeError b) = a == b
|
|
||||||
liftEq _ (StringError a) (StringError b) = a == b
|
liftEq _ (StringError a) (StringError b) = a == b
|
||||||
liftEq _ (NamespaceError a) (NamespaceError b) = a == b
|
liftEq _ (NamespaceError a) (NamespaceError b) = a == b
|
||||||
liftEq _ (ScopedEnvironmentError a) (ScopedEnvironmentError b) = a == b
|
liftEq _ (ScopedEnvironmentError a) (ScopedEnvironmentError b) = a == b
|
||||||
liftEq _ (CallError a) (CallError 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
|
liftEq _ _ _ = False
|
||||||
|
|
||||||
deriving instance (Show value) => Show (ValueError location value resume)
|
deriving instance (Show value) => Show (ValueError location value resume)
|
||||||
|
@ -15,6 +15,7 @@ module Data.Abstract.Evaluatable
|
|||||||
, evaluatePackageBody
|
, evaluatePackageBody
|
||||||
, throwLoadError
|
, throwLoadError
|
||||||
, throwEvalError
|
, throwEvalError
|
||||||
|
, throwValueError
|
||||||
, resolve
|
, resolve
|
||||||
, listModulesInDir
|
, listModulesInDir
|
||||||
, require
|
, require
|
||||||
@ -95,6 +96,10 @@ instance Eq1 (EvalError term) where
|
|||||||
liftEq _ (FreeVariablesError a) (FreeVariablesError b) = a == b
|
liftEq _ (FreeVariablesError a) (FreeVariablesError b) = a == b
|
||||||
liftEq _ _ _ = False
|
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 :: MonadEvaluatable location term value m => LoadError term value resume -> m resume
|
||||||
throwLoadError = throwException
|
throwLoadError = throwException
|
||||||
|
|
||||||
|
@ -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, Integer j) <- prjPair pair = f i j & specialize
|
||||||
| Just (Float i, Rational 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
|
| 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
|
where
|
||||||
-- Dispatch whatever's contained inside a 'Number.SomeNumber' to its appropriate 'MonadValue' ctor
|
-- Dispatch whatever's contained inside a 'Number.SomeNumber' to its appropriate 'MonadValue' ctor
|
||||||
specialize :: MonadValue location value m => Number.SomeNumber -> m value
|
specialize :: MonadValue location value m => Number.SomeNumber -> m value
|
||||||
|
Loading…
Reference in New Issue
Block a user