module Data.Ruby.Marshal.Types where
import Control.Applicative
import Prelude
import Control.Monad.State (lift, MonadState, StateT)
import Data.Map (Map)
import Data.Serialize.Get (Get)
import Data.Vector (Vector)
import qualified Data.ByteString as BS
data Cache = Cache {
_objects :: Vector RubyObject
, _symbols :: Vector RubyObject
} deriving Show
data Error
= Unsupported
deriving (Eq, Ord, Show)
newtype Marshal a = Marshal {
runMarshal :: StateT Cache Get a
} deriving (Functor, Applicative, Monad, MonadState Cache)
liftMarshal :: Get a -> Marshal a
liftMarshal = Marshal . lift
data RubyObject
= RNil
| RBool !Bool
| RFixnum !Int
| RArray !(Vector RubyObject)
| RHash !(Map RubyObject RubyObject)
| RIVar !(RubyObject, BS.ByteString)
| RString !BS.ByteString
| RFloat !Double
| RSymbol !BS.ByteString
| RError !Error
deriving (Eq, Ord, Show)
pattern NilC = 48
pattern FalseC = 70
pattern TrueC = 84
pattern ArrayC = 91
pattern FixnumC = 105
pattern FloatC = 102
pattern HashC = 123
pattern IVarC = 73
pattern ObjectLinkC = 64
pattern StringC = 34
pattern SymbolC = 58
pattern SymlinkC = 59