module Data.Registry.Internal.Stack where
import Data.Registry.Internal.Operations
import Data.Registry.Internal.Types
import Protolude
type Stack a = StateT (Values, Operations) (Either Text) a
runStack :: Stack a -> Values -> Either Text a
runStack sa vs = evalStateT sa (vs, [])
execStack :: Stack a -> Values -> Either Text Values
execStack sa vs = fst <$> execStateT sa (vs, [])
evalStack :: Stack a -> Values -> Either Text Operations
evalStack sa vs = snd <$> execStateT sa (vs, [])
getValues :: Stack Values
getValues = fst <$> get
getOperation :: Stack Operations
getOperation = snd <$> get
modifyValues :: (Values -> Values) -> Stack ()
modifyValues f = modify (\(vs, ops) -> (f vs, ops))
modifyOperations :: (Operations -> Operations) -> Stack ()
modifyOperations f = modify (\(vs, ops) -> (vs, f ops))
functionApplied :: Value -> [Value] -> Stack ()
functionApplied output inputs = modifyOperations (AppliedFunction output inputs:)