1
1
mirror of https://github.com/github/semantic.git synced 2024-12-26 00:12:29 +03:00

remove value parameter from ValueRef

This commit is contained in:
Charlie Somerville 2018-06-12 08:55:08 +10:00
parent 9e936a4a1a
commit a9a49ec56c
6 changed files with 19 additions and 19 deletions

View File

@ -36,8 +36,8 @@ lookupCache configuration = cacheLookup configuration <$> get
cachingConfiguration :: (Cacheable term address (Cell address) value, Member (State (Cache term address (Cell address) value)) effects, Member (State (Heap address (Cell address) value)) effects) cachingConfiguration :: (Cacheable term address (Cell address) value, Member (State (Cache term address (Cell address) value)) effects, Member (State (Heap address (Cell address) value)) effects)
=> Configuration term address (Cell address) value => Configuration term address (Cell address) value
-> Set (Cached address (Cell address) value) -> Set (Cached address (Cell address) value)
-> TermEvaluator term address value effects (ValueRef address value) -> TermEvaluator term address value effects (ValueRef address)
-> TermEvaluator term address value effects (ValueRef address value) -> TermEvaluator term address value effects (ValueRef address)
cachingConfiguration configuration values action = do cachingConfiguration configuration values action = do
modify' (cacheSet configuration values) modify' (cacheSet configuration values)
result <- Cached <$> action <*> TermEvaluator getHeap result <- Cached <$> action <*> TermEvaluator getHeap
@ -65,8 +65,8 @@ cachingTerms :: ( Cacheable term address (Cell address) value
, Member (Env address) effects , Member (Env address) effects
, Member (State (Heap address (Cell address) value)) effects , Member (State (Heap address (Cell address) value)) effects
) )
=> SubtermAlgebra (Base term) term (TermEvaluator term address value effects (ValueRef address value)) => SubtermAlgebra (Base term) term (TermEvaluator term address value effects (ValueRef address))
-> SubtermAlgebra (Base term) term (TermEvaluator term address value effects (ValueRef address value)) -> SubtermAlgebra (Base term) term (TermEvaluator term address value effects (ValueRef address))
cachingTerms recur term = do cachingTerms recur term = do
c <- getConfiguration (embedSubterm term) c <- getConfiguration (embedSubterm term)
cached <- lookupCache c cached <- lookupCache c
@ -122,7 +122,7 @@ converge seed f = loop seed
loop x' loop x'
-- | Nondeterministically write each of a collection of stores & return their associated results. -- | Nondeterministically write each of a collection of stores & return their associated results.
scatter :: (Foldable t, Member NonDet effects, Member (State (Heap address (Cell address) value)) effects) => t (Cached address (Cell address) value) -> TermEvaluator term address value effects (ValueRef address value) scatter :: (Foldable t, Member NonDet effects, Member (State (Heap address (Cell address) value)) effects) => t (Cached address (Cell address) value) -> TermEvaluator term address value effects (ValueRef address)
scatter = foldMapA (\ (Cached value heap') -> TermEvaluator (putHeap heap') $> value) scatter = foldMapA (\ (Cached value heap') -> TermEvaluator (putHeap heap') $> value)

View File

@ -219,7 +219,7 @@ value :: ( AbstractValue address value effects
, Member (Env address) effects , Member (Env address) effects
, Member (Resumable (EnvironmentError address)) effects , Member (Resumable (EnvironmentError address)) effects
) )
=> ValueRef address value => ValueRef address
-> Evaluator address value effects value -> Evaluator address value effects value
value = deref <=< address value = deref <=< address
@ -229,7 +229,7 @@ subtermValue :: ( AbstractValue address value effects
, Member (Env address) effects , Member (Env address) effects
, Member (Resumable (EnvironmentError address)) effects , Member (Resumable (EnvironmentError address)) effects
) )
=> Subterm term (Evaluator address value effects (ValueRef address value)) => Subterm term (Evaluator address value effects (ValueRef address))
-> Evaluator address value effects value -> Evaluator address value effects value
subtermValue = value <=< subtermRef subtermValue = value <=< subtermRef
@ -239,7 +239,7 @@ address :: ( AbstractValue address value effects
, Member (Env address) effects , Member (Env address) effects
, Member (Resumable (EnvironmentError address)) effects , Member (Resumable (EnvironmentError address)) effects
) )
=> ValueRef address value => ValueRef address
-> Evaluator address value effects address -> Evaluator address value effects address
address (LvalLocal var) = variable var address (LvalLocal var) = variable var
address (LvalMember obj prop) = evaluateInScopedEnv (deref obj) (variable prop) address (LvalMember obj prop) = evaluateInScopedEnv (deref obj) (variable prop)
@ -251,12 +251,12 @@ subtermAddress :: ( AbstractValue address value effects
, Member (Env address) effects , Member (Env address) effects
, Member (Resumable (EnvironmentError address)) effects , Member (Resumable (EnvironmentError address)) effects
) )
=> Subterm term (Evaluator address value effects (ValueRef address value)) => Subterm term (Evaluator address value effects (ValueRef address))
-> Evaluator address value effects address -> Evaluator address value effects address
subtermAddress = address <=< subtermRef subtermAddress = address <=< subtermRef
-- | Convenience function for boxing a raw value and wrapping it in an Rval -- | Convenience function for boxing a raw value and wrapping it in an Rval
rvalBox :: Member (Allocator address value) effects rvalBox :: Member (Allocator address value) effects
=> value => value
-> Evaluator address value effects (ValueRef address value) -> Evaluator address value effects (ValueRef address)
rvalBox val = Rval <$> box val rvalBox val = Rval <$> box val

View File

@ -13,7 +13,7 @@ newtype Cache term address cell value = Cache { unCache :: Monoidal.Map (Configu
deriving (Eq, Lower, Monoid, Ord, Reducer (Configuration term address cell value, Cached address cell value), Semigroup) deriving (Eq, Lower, Monoid, Ord, Reducer (Configuration term address cell value, Cached address cell value), Semigroup)
data Cached address cell value = Cached data Cached address cell value = Cached
{ cachedValue :: ValueRef address value { cachedValue :: ValueRef address
, cachedHeap :: Heap address cell value , cachedHeap :: Heap address cell value
} }
deriving (Eq, Ord, Show) deriving (Eq, Ord, Show)

View File

@ -58,7 +58,7 @@ class Show1 constr => Evaluatable constr where
, Member (Return address value) effects , Member (Return address value) effects
, Member Trace effects , Member Trace effects
) )
=> SubtermAlgebra constr term (Evaluator address value effects (ValueRef address value)) => SubtermAlgebra constr term (Evaluator address value effects (ValueRef address))
eval expr = rvalBox =<< throwResumable (Unspecialized ("Eval unspecialized for " ++ liftShowsPrec (const (const id)) (const id) 0 expr "")) eval expr = rvalBox =<< throwResumable (Unspecialized ("Eval unspecialized for " ++ liftShowsPrec (const (const id)) (const id) 0 expr ""))
@ -89,7 +89,7 @@ evaluatePackageWith :: forall address term value inner inner' inner'' outer
, inner'' ~ (Modules address value ': Reader Span ': Reader PackageInfo ': outer) , inner'' ~ (Modules address value ': Reader Span ': Reader PackageInfo ': outer)
) )
=> (SubtermAlgebra Module term (TermEvaluator term address value inner address) -> SubtermAlgebra Module term (TermEvaluator term address value inner address)) => (SubtermAlgebra Module term (TermEvaluator term address value inner address) -> SubtermAlgebra Module term (TermEvaluator term address value inner address))
-> (SubtermAlgebra (Base term) term (TermEvaluator term address value inner (ValueRef address value)) -> SubtermAlgebra (Base term) term (TermEvaluator term address value inner (ValueRef address value))) -> (SubtermAlgebra (Base term) term (TermEvaluator term address value inner (ValueRef address)) -> SubtermAlgebra (Base term) term (TermEvaluator term address value inner (ValueRef address)))
-> Package term -> Package term
-> TermEvaluator term address value outer [(address, Environment address)] -> TermEvaluator term address value outer [(address, Environment address)]
evaluatePackageWith analyzeModule analyzeTerm package evaluatePackageWith analyzeModule analyzeTerm package

View File

@ -4,13 +4,13 @@ module Data.Abstract.Ref where
import Data.Abstract.Name import Data.Abstract.Name
-- | 'ValueRef' is the type subterms evaluate to and can represent either values directly ('Rval'), or references to values (lvals - such as local variables or object members) -- | 'ValueRef' is the type subterms evaluate to and can represent either values directly ('Rval'), or references to values (lvals - such as local variables or object members)
data ValueRef address value where data ValueRef address where
-- | A value. -- | A value.
Rval :: address -> ValueRef address value Rval :: address -> ValueRef address
-- | A local variable. No environment is attached—its assumed that 'LvalLocal' will be evaluated in the same scope it was constructed in. -- | A local variable. No environment is attached—its assumed that 'LvalLocal' will be evaluated in the same scope it was constructed in.
LvalLocal :: Name -> ValueRef address value LvalLocal :: Name -> ValueRef address
-- | An object member. -- | An object member.
LvalMember :: address -> Name -> ValueRef address value LvalMember :: address -> Name -> ValueRef address
deriving (Eq, Ord, Show) deriving (Eq, Ord, Show)

View File

@ -54,9 +54,9 @@ include :: ( AbstractValue address value effects
, Member (Resumable (EnvironmentError address)) effects , Member (Resumable (EnvironmentError address)) effects
, Member Trace effects , Member Trace effects
) )
=> Subterm term (Evaluator address value effects (ValueRef address value)) => Subterm term (Evaluator address value effects (ValueRef address))
-> (ModulePath -> Evaluator address value effects (Maybe (address, Environment address))) -> (ModulePath -> Evaluator address value effects (Maybe (address, Environment address)))
-> Evaluator address value effects (ValueRef address value) -> Evaluator address value effects (ValueRef address)
include pathTerm f = do include pathTerm f = do
name <- subtermValue pathTerm >>= asString name <- subtermValue pathTerm >>= asString
path <- resolvePHPName name path <- resolvePHPName name