{-# LINE 1 "lib/CPython/Protocols/Object.chs" #-}
{-# LANGUAGE ForeignFunctionInterface #-}
module CPython.Protocols.Object
( Object
, Concrete
, SomeObject
, getType
, isInstance
, isSubclass
, toObject
, cast
, hasAttribute
, getAttribute
, setAttribute
, deleteAttribute
, print
, repr
, ascii
, string
, bytes
, callable
, call
, callArgs
, callMethod
, callMethodArgs
, Comparison (..)
, richCompare
, toBool
, hash
, dir
, getIterator
) where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import Prelude hiding (Ordering (..), print)
import qualified Data.Text as T
import System.IO (Handle, hPutStrLn)
import CPython.Internal hiding (toBool)
import CPython.Protocols.Object.Enums
import qualified CPython.Types.Bytes as B
import qualified CPython.Types.Dictionary as D
import qualified CPython.Types.Tuple as Tuple
import qualified CPython.Types.Unicode as U
getType :: Object self => (self) -> IO ((Type))
getType :: self -> IO Type
getType a1 :: self
a1 =
self -> (Ptr () -> IO Type) -> IO Type
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject self
a1 ((Ptr () -> IO Type) -> IO Type) -> (Ptr () -> IO Type) -> IO Type
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' ->
Ptr () -> IO (Ptr ())
getType'_ Ptr ()
a1' IO (Ptr ()) -> (Ptr () -> IO Type) -> IO Type
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: Ptr ()
res ->
Ptr () -> IO Type
forall obj a. Object obj => Ptr a -> IO obj
stealObject Ptr ()
res IO Type -> (Type -> IO Type) -> IO Type
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: Type
res' ->
Type -> IO Type
forall (m :: * -> *) a. Monad m => a -> m a
return (Type
res')
{-# LINE 78 "lib/CPython/Protocols/Object.chs" #-}
isInstance :: (Object self, Object cls) => (self) -> (cls) -> IO ((Bool))
isInstance :: self -> cls -> IO Bool
isInstance a1 :: self
a1 a2 :: cls
a2 =
self -> (Ptr () -> IO Bool) -> IO Bool
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject self
a1 ((Ptr () -> IO Bool) -> IO Bool) -> (Ptr () -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' ->
cls -> (Ptr () -> IO Bool) -> IO Bool
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject cls
a2 ((Ptr () -> IO Bool) -> IO Bool) -> (Ptr () -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \a2' :: Ptr ()
a2' ->
Ptr () -> Ptr () -> IO CInt
isInstance'_ Ptr ()
a1' Ptr ()
a2' IO CInt -> (CInt -> IO Bool) -> IO Bool
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: CInt
res ->
CInt -> IO Bool
checkBoolReturn CInt
res IO Bool -> (Bool -> IO Bool) -> IO Bool
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: Bool
res' ->
Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
res')
{-# LINE 105 "lib/CPython/Protocols/Object.chs" #-}
isSubclass :: (Object derived, Object cls) => (derived) -> (cls) -> IO ((Bool))
isSubclass :: derived -> cls -> IO Bool
isSubclass a1 :: derived
a1 a2 :: cls
a2 =
derived -> (Ptr () -> IO Bool) -> IO Bool
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject derived
a1 ((Ptr () -> IO Bool) -> IO Bool) -> (Ptr () -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' ->
cls -> (Ptr () -> IO Bool) -> IO Bool
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject cls
a2 ((Ptr () -> IO Bool) -> IO Bool) -> (Ptr () -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \a2' :: Ptr ()
a2' ->
Ptr () -> Ptr () -> IO CInt
isSubclass'_ Ptr ()
a1' Ptr ()
a2' IO CInt -> (CInt -> IO Bool) -> IO Bool
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: CInt
res ->
CInt -> IO Bool
checkBoolReturn CInt
res IO Bool -> (Bool -> IO Bool) -> IO Bool
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: Bool
res' ->
Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
res')
{-# LINE 118 "lib/CPython/Protocols/Object.chs" #-}
cast :: (Object a, Concrete b) => a -> IO (Maybe b)
cast :: a -> IO (Maybe b)
cast obj :: a
obj = let castObj :: b
castObj = case a -> SomeObject
forall a. Object a => a -> SomeObject
toObject a
obj of SomeObject ptr :: ForeignPtr a
ptr -> ForeignPtr b -> b
forall a. Object a => ForeignPtr a -> a
fromForeignPtr (ForeignPtr b -> b) -> ForeignPtr b -> b
forall a b. (a -> b) -> a -> b
$ ForeignPtr a -> ForeignPtr b
forall a b. ForeignPtr a -> ForeignPtr b
castForeignPtr ForeignPtr a
ptr
in do
Bool
validCast <- a -> Type -> IO Bool
forall self cls.
(Object self, Object cls) =>
self -> cls -> IO Bool
isInstance a
obj (Type -> IO Bool) -> Type -> IO Bool
forall a b. (a -> b) -> a -> b
$ b -> Type
forall a. Concrete a => a -> Type
concreteType b
castObj
Maybe b -> IO (Maybe b)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe b -> IO (Maybe b)) -> Maybe b -> IO (Maybe b)
forall a b. (a -> b) -> a -> b
$ if Bool
validCast
then b -> Maybe b
forall a. a -> Maybe a
Just b
castObj
else Maybe b
forall a. Maybe a
Nothing
hasAttribute :: Object self => (self) -> (U.Unicode) -> IO ((Bool))
hasAttribute :: self -> Unicode -> IO Bool
hasAttribute a1 :: self
a1 a2 :: Unicode
a2 =
self -> (Ptr () -> IO Bool) -> IO Bool
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject self
a1 ((Ptr () -> IO Bool) -> IO Bool) -> (Ptr () -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' ->
Unicode -> (Ptr () -> IO Bool) -> IO Bool
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Unicode
a2 ((Ptr () -> IO Bool) -> IO Bool) -> (Ptr () -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \a2' :: Ptr ()
a2' ->
Ptr () -> Ptr () -> IO CInt
hasAttribute'_ Ptr ()
a1' Ptr ()
a2' IO CInt -> (CInt -> IO Bool) -> IO Bool
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: CInt
res ->
CInt -> IO Bool
checkBoolReturn CInt
res IO Bool -> (Bool -> IO Bool) -> IO Bool
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: Bool
res' ->
Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
res')
{-# LINE 137 "lib/CPython/Protocols/Object.chs" #-}
getAttribute :: Object self => (self) -> (U.Unicode) -> IO ((SomeObject))
getAttribute :: self -> Unicode -> IO SomeObject
getAttribute a1 :: self
a1 a2 :: Unicode
a2 =
self -> (Ptr () -> IO SomeObject) -> IO SomeObject
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject self
a1 ((Ptr () -> IO SomeObject) -> IO SomeObject)
-> (Ptr () -> IO SomeObject) -> IO SomeObject
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' ->
Unicode -> (Ptr () -> IO SomeObject) -> IO SomeObject
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Unicode
a2 ((Ptr () -> IO SomeObject) -> IO SomeObject)
-> (Ptr () -> IO SomeObject) -> IO SomeObject
forall a b. (a -> b) -> a -> b
$ \a2' :: Ptr ()
a2' ->
Ptr () -> Ptr () -> IO (Ptr ())
getAttribute'_ Ptr ()
a1' Ptr ()
a2' IO (Ptr ()) -> (Ptr () -> IO SomeObject) -> IO SomeObject
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: Ptr ()
res ->
Ptr () -> IO SomeObject
forall obj a. Object obj => Ptr a -> IO obj
stealObject Ptr ()
res IO SomeObject -> (SomeObject -> IO SomeObject) -> IO SomeObject
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: SomeObject
res' ->
SomeObject -> IO SomeObject
forall (m :: * -> *) a. Monad m => a -> m a
return (SomeObject
res')
{-# LINE 146 "lib/CPython/Protocols/Object.chs" #-}
setAttribute :: (Object self, Object v) => (self) -> (U.Unicode) -> (v) -> IO ((()))
setAttribute :: self -> Unicode -> v -> IO ()
setAttribute a1 :: self
a1 a2 :: Unicode
a2 a3 :: v
a3 =
self -> (Ptr () -> IO ()) -> IO ()
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject self
a1 ((Ptr () -> IO ()) -> IO ()) -> (Ptr () -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' ->
Unicode -> (Ptr () -> IO ()) -> IO ()
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Unicode
a2 ((Ptr () -> IO ()) -> IO ()) -> (Ptr () -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \a2' :: Ptr ()
a2' ->
v -> (Ptr () -> IO ()) -> IO ()
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject v
a3 ((Ptr () -> IO ()) -> IO ()) -> (Ptr () -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \a3' :: Ptr ()
a3' ->
Ptr () -> Ptr () -> Ptr () -> IO CInt
setAttribute'_ Ptr ()
a1' Ptr ()
a2' Ptr ()
a3' IO CInt -> (CInt -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: CInt
res ->
CInt -> IO ()
checkStatusCode CInt
res IO () -> (() -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: ()
res' ->
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return (()
res')
{-# LINE 156 "lib/CPython/Protocols/Object.chs" #-}
deleteAttribute :: Object self => (self) -> (U.Unicode) -> IO ((()))
deleteAttribute :: self -> Unicode -> IO ()
deleteAttribute a1 :: self
a1 a2 :: Unicode
a2 =
self -> (Ptr () -> IO ()) -> IO ()
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject self
a1 ((Ptr () -> IO ()) -> IO ()) -> (Ptr () -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' ->
Unicode -> (Ptr () -> IO ()) -> IO ()
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Unicode
a2 ((Ptr () -> IO ()) -> IO ()) -> (Ptr () -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \a2' :: Ptr ()
a2' ->
Ptr () -> Ptr () -> IO CInt
deleteAttribute'_ Ptr ()
a1' Ptr ()
a2' IO CInt -> (CInt -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: CInt
res ->
CInt -> IO ()
checkStatusCode CInt
res IO () -> (() -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: ()
res' ->
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return (()
res')
{-# LINE 165 "lib/CPython/Protocols/Object.chs" #-}
print :: Object self => self -> Handle -> IO ()
print obj h = repr obj >>= U.fromUnicode >>= (hPutStrLn h . T.unpack)
repr :: Object self => (self) -> IO ((U.Unicode))
repr :: self -> IO Unicode
repr a1 :: self
a1 =
self -> (Ptr () -> IO Unicode) -> IO Unicode
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject self
a1 ((Ptr () -> IO Unicode) -> IO Unicode)
-> (Ptr () -> IO Unicode) -> IO Unicode
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' ->
Ptr () -> IO (Ptr ())
repr'_ Ptr ()
a1' IO (Ptr ()) -> (Ptr () -> IO Unicode) -> IO Unicode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: Ptr ()
res ->
Ptr () -> IO Unicode
forall obj a. Object obj => Ptr a -> IO obj
stealObject Ptr ()
res IO Unicode -> (Unicode -> IO Unicode) -> IO Unicode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: Unicode
res' ->
Unicode -> IO Unicode
forall (m :: * -> *) a. Monad m => a -> m a
return (Unicode
res')
{-# LINE 176 "lib/CPython/Protocols/Object.chs" #-}
ascii :: Object self => (self) -> IO ((U.Unicode))
ascii :: self -> IO Unicode
ascii a1 :: self
a1 =
self -> (Ptr () -> IO Unicode) -> IO Unicode
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject self
a1 ((Ptr () -> IO Unicode) -> IO Unicode)
-> (Ptr () -> IO Unicode) -> IO Unicode
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' ->
Ptr () -> IO (Ptr ())
ascii'_ Ptr ()
a1' IO (Ptr ()) -> (Ptr () -> IO Unicode) -> IO Unicode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: Ptr ()
res ->
Ptr () -> IO Unicode
forall obj a. Object obj => Ptr a -> IO obj
stealObject Ptr ()
res IO Unicode -> (Unicode -> IO Unicode) -> IO Unicode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: Unicode
res' ->
Unicode -> IO Unicode
forall (m :: * -> *) a. Monad m => a -> m a
return (Unicode
res')
{-# LINE 185 "lib/CPython/Protocols/Object.chs" #-}
string :: Object self => (self) -> IO ((U.Unicode))
string :: self -> IO Unicode
string a1 :: self
a1 =
self -> (Ptr () -> IO Unicode) -> IO Unicode
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject self
a1 ((Ptr () -> IO Unicode) -> IO Unicode)
-> (Ptr () -> IO Unicode) -> IO Unicode
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' ->
Ptr () -> IO (Ptr ())
string'_ Ptr ()
a1' IO (Ptr ()) -> (Ptr () -> IO Unicode) -> IO Unicode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: Ptr ()
res ->
Ptr () -> IO Unicode
forall obj a. Object obj => Ptr a -> IO obj
stealObject Ptr ()
res IO Unicode -> (Unicode -> IO Unicode) -> IO Unicode
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: Unicode
res' ->
Unicode -> IO Unicode
forall (m :: * -> *) a. Monad m => a -> m a
return (Unicode
res')
{-# LINE 192 "lib/CPython/Protocols/Object.chs" #-}
bytes :: Object self => (self) -> IO ((B.Bytes))
bytes :: self -> IO Bytes
bytes a1 :: self
a1 =
self -> (Ptr () -> IO Bytes) -> IO Bytes
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject self
a1 ((Ptr () -> IO Bytes) -> IO Bytes)
-> (Ptr () -> IO Bytes) -> IO Bytes
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' ->
Ptr () -> IO (Ptr ())
bytes'_ Ptr ()
a1' IO (Ptr ()) -> (Ptr () -> IO Bytes) -> IO Bytes
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: Ptr ()
res ->
Ptr () -> IO Bytes
forall obj a. Object obj => Ptr a -> IO obj
stealObject Ptr ()
res IO Bytes -> (Bytes -> IO Bytes) -> IO Bytes
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: Bytes
res' ->
Bytes -> IO Bytes
forall (m :: * -> *) a. Monad m => a -> m a
return (Bytes
res')
callable :: self -> IO Bool
{-# LINE 199 "lib/CPython/Protocols/Object.chs" #-}
callable :: Object self => (self) -> IO ((Bool))
callable a1 =
withObject a1 $ \a1' ->
callable'_ a1' >>= \res ->
checkBoolReturn res >>= \res' ->
return (res')
{-# LINE 205 "lib/CPython/Protocols/Object.chs" #-}
call :: Object self => self -> Tuple -> Dictionary -> IO SomeObject
call :: self -> Tuple -> Dictionary -> IO SomeObject
call self :: self
self args :: Tuple
args kwargs :: Dictionary
kwargs =
self -> (Ptr () -> IO SomeObject) -> IO SomeObject
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject self
self ((Ptr () -> IO SomeObject) -> IO SomeObject)
-> (Ptr () -> IO SomeObject) -> IO SomeObject
forall a b. (a -> b) -> a -> b
$ \selfPtr :: Ptr ()
selfPtr ->
Tuple -> (Ptr () -> IO SomeObject) -> IO SomeObject
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Tuple
args ((Ptr () -> IO SomeObject) -> IO SomeObject)
-> (Ptr () -> IO SomeObject) -> IO SomeObject
forall a b. (a -> b) -> a -> b
$ \argsPtr :: Ptr ()
argsPtr ->
Dictionary -> (Ptr () -> IO SomeObject) -> IO SomeObject
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Dictionary
kwargs ((Ptr () -> IO SomeObject) -> IO SomeObject)
-> (Ptr () -> IO SomeObject) -> IO SomeObject
forall a b. (a -> b) -> a -> b
$ \kwargsPtr :: Ptr ()
kwargsPtr ->
Ptr () -> Ptr () -> Ptr () -> IO (Ptr ())
pyObjectCall Ptr ()
selfPtr Ptr ()
argsPtr Ptr ()
kwargsPtr
IO (Ptr ()) -> (Ptr () -> IO SomeObject) -> IO SomeObject
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Ptr () -> IO SomeObject
forall obj a. Object obj => Ptr a -> IO obj
stealObject
callArgs :: Object self => self -> [SomeObject] -> IO SomeObject
callArgs :: self -> [SomeObject] -> IO SomeObject
callArgs self :: self
self args :: [SomeObject]
args = do
Tuple
args' <- [SomeObject] -> IO Tuple
Tuple.toTuple [SomeObject]
args
IO Dictionary
D.new IO Dictionary -> (Dictionary -> IO SomeObject) -> IO SomeObject
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= self -> Tuple -> Dictionary -> IO SomeObject
forall self.
Object self =>
self -> Tuple -> Dictionary -> IO SomeObject
call self
self Tuple
args'
callMethod :: Object self => self -> T.Text -> Tuple -> Dictionary -> IO SomeObject
callMethod :: self -> Text -> Tuple -> Dictionary -> IO SomeObject
callMethod self :: self
self name :: Text
name args :: Tuple
args kwargs :: Dictionary
kwargs = do
SomeObject
method <- self -> Unicode -> IO SomeObject
forall self. Object self => self -> Unicode -> IO SomeObject
getAttribute self
self (Unicode -> IO SomeObject) -> IO Unicode -> IO SomeObject
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> IO Unicode
U.toUnicode Text
name
SomeObject -> Tuple -> Dictionary -> IO SomeObject
forall self.
Object self =>
self -> Tuple -> Dictionary -> IO SomeObject
call SomeObject
method Tuple
args Dictionary
kwargs
callMethodArgs :: Object self => self -> T.Text -> [SomeObject] -> IO SomeObject
callMethodArgs :: self -> Text -> [SomeObject] -> IO SomeObject
callMethodArgs self :: self
self name :: Text
name args :: [SomeObject]
args = do
Tuple
args' <- [SomeObject] -> IO Tuple
Tuple.toTuple [SomeObject]
args
IO Dictionary
D.new IO Dictionary -> (Dictionary -> IO SomeObject) -> IO SomeObject
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= self -> Text -> Tuple -> Dictionary -> IO SomeObject
forall self.
Object self =>
self -> Text -> Tuple -> Dictionary -> IO SomeObject
callMethod self
self Text
name Tuple
args'
data Comparison = LT | LE | EQ | NE | GT | GE
deriving (Int -> Comparison -> ShowS
[Comparison] -> ShowS
Comparison -> String
(Int -> Comparison -> ShowS)
-> (Comparison -> String)
-> ([Comparison] -> ShowS)
-> Show Comparison
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Comparison] -> ShowS
$cshowList :: [Comparison] -> ShowS
show :: Comparison -> String
$cshow :: Comparison -> String
showsPrec :: Int -> Comparison -> ShowS
$cshowsPrec :: Int -> Comparison -> ShowS
Show)
comparisonToInt :: Comparison -> CInt
comparisonToInt :: Comparison -> CInt
comparisonToInt = Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> CInt) -> (Comparison -> Int) -> Comparison -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HSCPythonComparisonEnum -> Int
forall a. Enum a => a -> Int
fromEnum (HSCPythonComparisonEnum -> Int)
-> (Comparison -> HSCPythonComparisonEnum) -> Comparison -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Comparison -> HSCPythonComparisonEnum
enum where
enum :: Comparison -> HSCPythonComparisonEnum
enum LT = HSCPythonComparisonEnum
HSCPYTHON_LT
enum LE = HSCPythonComparisonEnum
HSCPYTHON_LE
enum EQ = HSCPythonComparisonEnum
HSCPYTHON_EQ
enum NE = HSCPythonComparisonEnum
HSCPYTHON_NE
enum GT = HSCPythonComparisonEnum
HSCPYTHON_GT
enum GE = HSCPythonComparisonEnum
HSCPYTHON_GE
richCompare :: (Object a, Object b) => (a) -> (b) -> (Comparison) -> IO ((Bool))
richCompare :: a -> b -> Comparison -> IO Bool
richCompare a1 :: a
a1 a2 :: b
a2 a3 :: Comparison
a3 =
a -> (Ptr () -> IO Bool) -> IO Bool
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject a
a1 ((Ptr () -> IO Bool) -> IO Bool) -> (Ptr () -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' ->
b -> (Ptr () -> IO Bool) -> IO Bool
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject b
a2 ((Ptr () -> IO Bool) -> IO Bool) -> (Ptr () -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \a2' :: Ptr ()
a2' ->
let {a3' :: CInt
a3' = Comparison -> CInt
comparisonToInt Comparison
a3} in
Ptr () -> Ptr () -> CInt -> IO CInt
richCompare'_ Ptr ()
a1' Ptr ()
a2' CInt
a3' IO CInt -> (CInt -> IO Bool) -> IO Bool
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: CInt
res ->
CInt -> IO Bool
checkBoolReturn CInt
res IO Bool -> (Bool -> IO Bool) -> IO Bool
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: Bool
res' ->
Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
res')
{-# LINE 262 "lib/CPython/Protocols/Object.chs" #-}
toBool :: Object self => (self) -> IO ((Bool))
toBool :: self -> IO Bool
toBool a1 :: self
a1 =
self -> (Ptr () -> IO Bool) -> IO Bool
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject self
a1 ((Ptr () -> IO Bool) -> IO Bool) -> (Ptr () -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' ->
Ptr () -> IO CInt
toBool'_ Ptr ()
a1' IO CInt -> (CInt -> IO Bool) -> IO Bool
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: CInt
res ->
CInt -> IO Bool
checkBoolReturn CInt
res IO Bool -> (Bool -> IO Bool) -> IO Bool
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: Bool
res' ->
Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
res')
{-# LINE 270 "lib/CPython/Protocols/Object.chs" #-}
hash :: Object self => (self) -> IO ((Integer))
hash :: self -> IO Integer
hash a1 :: self
a1 =
self -> (Ptr () -> IO Integer) -> IO Integer
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject self
a1 ((Ptr () -> IO Integer) -> IO Integer)
-> (Ptr () -> IO Integer) -> IO Integer
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' ->
Ptr () -> IO CLong
hash'_ Ptr ()
a1' IO CLong -> (CLong -> IO Integer) -> IO Integer
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: CLong
res ->
CLong -> IO Integer
forall a. Integral a => a -> IO Integer
checkIntReturn CLong
res IO Integer -> (Integer -> IO Integer) -> IO Integer
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: Integer
res' ->
Integer -> IO Integer
forall (m :: * -> *) a. Monad m => a -> m a
return (Integer
res')
{-# LINE 278 "lib/CPython/Protocols/Object.chs" #-}
dir :: Object self => (self) -> IO ((List))
dir :: self -> IO List
dir a1 :: self
a1 =
self -> (Ptr () -> IO List) -> IO List
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject self
a1 ((Ptr () -> IO List) -> IO List) -> (Ptr () -> IO List) -> IO List
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' ->
Ptr () -> IO (Ptr ())
dir'_ Ptr ()
a1' IO (Ptr ()) -> (Ptr () -> IO List) -> IO List
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: Ptr ()
res ->
Ptr () -> IO List
forall obj a. Object obj => Ptr a -> IO obj
stealObject Ptr ()
res IO List -> (List -> IO List) -> IO List
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: List
res' ->
List -> IO List
forall (m :: * -> *) a. Monad m => a -> m a
return (List
res')
{-# LINE 286 "lib/CPython/Protocols/Object.chs" #-}
getIterator :: Object self => (self) -> IO ((SomeObject))
getIterator :: self -> IO SomeObject
getIterator a1 :: self
a1 =
self -> (Ptr () -> IO SomeObject) -> IO SomeObject
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject self
a1 ((Ptr () -> IO SomeObject) -> IO SomeObject)
-> (Ptr () -> IO SomeObject) -> IO SomeObject
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' ->
Ptr () -> IO (Ptr ())
getIterator'_ Ptr ()
a1' IO (Ptr ()) -> (Ptr () -> IO SomeObject) -> IO SomeObject
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: Ptr ()
res ->
Ptr () -> IO SomeObject
forall obj a. Object obj => Ptr a -> IO obj
stealObject Ptr ()
res IO SomeObject -> (SomeObject -> IO SomeObject) -> IO SomeObject
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: SomeObject
res' ->
SomeObject -> IO SomeObject
forall (m :: * -> *) a. Monad m => a -> m a
return (SomeObject
res')
{-# LINE 295 "lib/CPython/Protocols/Object.chs" #-}
foreign import ccall safe "CPython/Protocols/Object.chs.h PyObject_Type"
getType'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))
foreign import ccall safe "CPython/Protocols/Object.chs.h PyObject_IsInstance"
isInstance'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt)))
foreign import ccall safe "CPython/Protocols/Object.chs.h PyObject_IsSubclass"
isSubclass'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt)))
foreign import ccall safe "CPython/Protocols/Object.chs.h PyObject_HasAttr"
hasAttribute'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt)))
foreign import ccall safe "CPython/Protocols/Object.chs.h PyObject_GetAttr"
getAttribute'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ()))))
foreign import ccall safe "CPython/Protocols/Object.chs.h PyObject_SetAttr"
setAttribute'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))))
foreign import ccall safe "CPython/Protocols/Object.chs.h hscpython_PyObject_DelAttr"
deleteAttribute'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt)))
foreign import ccall safe "CPython/Protocols/Object.chs.h PyObject_Repr"
repr'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))
foreign import ccall safe "CPython/Protocols/Object.chs.h PyObject_ASCII"
ascii'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))
foreign import ccall safe "CPython/Protocols/Object.chs.h PyObject_Str"
string'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))
foreign import ccall safe "CPython/Protocols/Object.chs.h PyObject_Bytes"
bytes'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))
foreign import ccall safe "CPython/Protocols/Object.chs.h PyCallable_Check"
callable'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))
foreign import ccall safe "CPython/Protocols/Object.chs.h PyObject_Call"
pyObjectCall :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))))
foreign import ccall safe "CPython/Protocols/Object.chs.h PyObject_RichCompareBool"
richCompare'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (C2HSImp.CInt -> (IO C2HSImp.CInt))))
foreign import ccall safe "CPython/Protocols/Object.chs.h PyObject_IsTrue"
toBool'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt))
foreign import ccall safe "CPython/Protocols/Object.chs.h PyObject_Hash"
hash'_ :: ((C2HSImp.Ptr ()) -> (IO C2HSImp.CLong))
foreign import ccall safe "CPython/Protocols/Object.chs.h PyObject_Dir"
dir'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))
foreign import ccall safe "CPython/Protocols/Object.chs.h PyObject_GetIter"
getIterator'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))