lookupPool c pool =
fromIntegral `fmap` findIndex (== c) (M.elems pool)
-addNT :: Binary (Signature a) => NameType a -> Generate Word16
+addNT :: HasSignature a => NameType a -> Generate Word16
addNT (NameType name sig) = do
let bsig = encode sig
x <- addItem (CNameType name bsig)
deriving (Eq, Show, Ord, Enum)
-- | Fields and methods have signatures.
-class HasSignature a where
+class (Binary (Signature a), Show (Signature a), Eq (Signature a))
+ => HasSignature a where
type Signature a
instance HasSignature Field where
ntName :: B.ByteString,
ntSignature :: Signature a }
-instance Show (Signature a) => Show (NameType a) where
+instance (HasSignature a) => Show (NameType a) where
show (NameType n t) = toString n ++ ": " ++ show t
-deriving instance Eq (Signature a) => Eq (NameType a)
+deriving instance HasSignature a => Eq (NameType a)
-instance (Binary (Signature a)) => Binary (NameType a) where
+instance HasSignature a => Binary (NameType a) where
put (NameType n t) = putLazyByteString n >> put t
get = NameType <$> get <*> get
n = fromIntegral $ M.size ps
- convertNameType :: (HasSignature a, Binary (Signature a)) => Word16 -> NameType a
+ convertNameType :: (HasSignature a) => Word16 -> NameType a
convertNameType i =
let (CNameType n s) = pool ! i
in NameType n (decode s)