{-# LINE 1 "lib/CPython/Types/Function.chs" #-}
{-# LANGUAGE ForeignFunctionInterface #-}
module CPython.Types.Function
( Function
, functionType
, new
, getCode
, getGlobals
, getModule
, getDefaults
, setDefaults
, getClosure
, setClosure
, getAnnotations
, setAnnotations
) where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp
import qualified System.IO.Unsafe as C2HSImp
import qualified CPython.Constants as Const
import CPython.Internal hiding (new)
import CPython.Types.Code (Code)
newtype Function = Function (ForeignPtr Function)
instance Object Function where
toObject :: Function -> SomeObject
toObject (Function x :: ForeignPtr Function
x) = ForeignPtr Function -> SomeObject
forall a. Object a => ForeignPtr a -> SomeObject
SomeObject ForeignPtr Function
x
fromForeignPtr :: ForeignPtr Function -> Function
fromForeignPtr = ForeignPtr Function -> Function
Function
instance Concrete Function where
concreteType :: Function -> Type
concreteType _ = Type
functionType
functionType :: (Type)
functionType :: Type
functionType =
IO Type -> Type
forall a. IO a -> a
C2HSImp.unsafePerformIO (IO Type -> Type) -> IO Type -> Type
forall a b. (a -> b) -> a -> b
$
IO (Ptr ())
functionType'_ 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
peekStaticObject 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 49 "lib/CPython/Types/Function.chs" #-}
new :: (Code) -> (Dictionary) -> IO ((Function))
new a1 a2 =
withObject a1 $ \a1' ->
withObject a2 $ \a2' ->
new'_ a1' a2' >>= \res ->
stealObject res >>= \res' ->
return (res')
{-# LINE 59 "lib/CPython/Types/Function.chs" #-}
getCode :: (Function) -> IO ((Code))
getCode a1 =
withObject a1 $ \a1' ->
getCode'_ a1' >>= \res ->
peekObject res >>= \res' ->
return (res')
{-# LINE 64 "lib/CPython/Types/Function.chs" #-}
getGlobals :: (Function) -> IO ((Dictionary))
getGlobals a1 =
withObject a1 $ \a1' ->
getGlobals'_ a1' >>= \res ->
peekObject res >>= \res' ->
return (res')
{-# LINE 69 "lib/CPython/Types/Function.chs" #-}
getModule :: (Function) -> IO ((SomeObject))
getModule :: Function -> IO SomeObject
getModule a1 :: Function
a1 =
Function -> (Ptr () -> IO SomeObject) -> IO SomeObject
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Function
a1 ((Ptr () -> IO SomeObject) -> IO SomeObject)
-> (Ptr () -> IO SomeObject) -> IO SomeObject
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' ->
Ptr () -> IO (Ptr ())
getModule'_ 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
peekObject 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 76 "lib/CPython/Types/Function.chs" #-}
withNullableObject :: Object obj => Maybe obj -> (Ptr a -> IO b) -> IO b
withNullableObject Nothing io = do
none <- Const.none
withObject none io
withNullableObject (Just obj) io = withObject obj io
peekNullableObject :: Object obj => Ptr a -> IO (Maybe obj)
peekNullableObject :: Ptr a -> IO (Maybe obj)
peekNullableObject = (Ptr a -> IO obj) -> Ptr a -> IO (Maybe obj)
forall a b. (Ptr a -> IO b) -> Ptr a -> IO (Maybe b)
maybePeek Ptr a -> IO obj
forall obj a. Object obj => Ptr a -> IO obj
peekObject
getDefaults :: (Function) -> IO ((Maybe Tuple))
getDefaults :: Function -> IO (Maybe Tuple)
getDefaults a1 :: Function
a1 =
Function -> (Ptr () -> IO (Maybe Tuple)) -> IO (Maybe Tuple)
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Function
a1 ((Ptr () -> IO (Maybe Tuple)) -> IO (Maybe Tuple))
-> (Ptr () -> IO (Maybe Tuple)) -> IO (Maybe Tuple)
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' ->
Ptr () -> IO (Ptr ())
getDefaults'_ Ptr ()
a1' IO (Ptr ()) -> (Ptr () -> IO (Maybe Tuple)) -> IO (Maybe Tuple)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: Ptr ()
res ->
Ptr () -> IO (Maybe Tuple)
forall obj a. Object obj => Ptr a -> IO (Maybe obj)
peekNullableObject Ptr ()
res IO (Maybe Tuple)
-> (Maybe Tuple -> IO (Maybe Tuple)) -> IO (Maybe Tuple)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: Maybe Tuple
res' ->
Maybe Tuple -> IO (Maybe Tuple)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Tuple
res')
{-# LINE 91 "lib/CPython/Types/Function.chs" #-}
setDefaults :: (Function) -> (Maybe Tuple) -> IO ((()))
setDefaults a1 a2 =
withObject a1 $ \a1' ->
withNullableObject a2 $ \a2' ->
setDefaults'_ a1' a2' >>= \res ->
checkStatusCode res >>= \res' ->
return (res')
{-# LINE 97 "lib/CPython/Types/Function.chs" #-}
getClosure :: (Function) -> IO ((Maybe Tuple))
getClosure a1 =
withObject a1 $ \a1' ->
getClosure'_ a1' >>= \res ->
peekNullableObject res >>= \res' ->
return (res')
{-# LINE 103 "lib/CPython/Types/Function.chs" #-}
setClosure :: (Function) -> (Maybe Tuple) -> IO ((()))
setClosure a1 a2 =
withObject a1 $ \a1' ->
withNullableObject a2 $ \a2' ->
setClosure'_ a1' a2' >>= \res ->
checkStatusCode res >>= \res' ->
return (res')
{-# LINE 110 "lib/CPython/Types/Function.chs" #-}
getAnnotations :: (Function) -> IO ((Maybe Dictionary))
getAnnotations :: Function -> IO (Maybe Dictionary)
getAnnotations a1 :: Function
a1 =
Function
-> (Ptr () -> IO (Maybe Dictionary)) -> IO (Maybe Dictionary)
forall obj a b. Object obj => obj -> (Ptr a -> IO b) -> IO b
withObject Function
a1 ((Ptr () -> IO (Maybe Dictionary)) -> IO (Maybe Dictionary))
-> (Ptr () -> IO (Maybe Dictionary)) -> IO (Maybe Dictionary)
forall a b. (a -> b) -> a -> b
$ \a1' :: Ptr ()
a1' ->
Ptr () -> IO (Ptr ())
getAnnotations'_ Ptr ()
a1' IO (Ptr ())
-> (Ptr () -> IO (Maybe Dictionary)) -> IO (Maybe Dictionary)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res :: Ptr ()
res ->
Ptr () -> IO (Maybe Dictionary)
forall obj a. Object obj => Ptr a -> IO (Maybe obj)
peekNullableObject Ptr ()
res IO (Maybe Dictionary)
-> (Maybe Dictionary -> IO (Maybe Dictionary))
-> IO (Maybe Dictionary)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \res' :: Maybe Dictionary
res' ->
Maybe Dictionary -> IO (Maybe Dictionary)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Dictionary
res')
{-# LINE 116 "lib/CPython/Types/Function.chs" #-}
setAnnotations :: (Function) -> (Maybe Dictionary) -> IO ((()))
setAnnotations a1 a2 =
withObject a1 $ \a1' ->
withNullableObject a2 $ \a2' ->
setAnnotations'_ a1' a2' >>= \res ->
checkStatusCode res >>= \res' ->
return (res')
{-# LINE 122 "lib/CPython/Types/Function.chs" #-}
foreign import ccall unsafe "CPython/Types/Function.chs.h hscpython_PyFunction_Type"
functionType'_ :: (IO (C2HSImp.Ptr ()))
foreign import ccall safe "CPython/Types/Function.chs.h PyFunction_New"
new'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ()))))
foreign import ccall safe "CPython/Types/Function.chs.h PyFunction_GetCode"
getCode'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))
foreign import ccall safe "CPython/Types/Function.chs.h PyFunction_GetGlobals"
getGlobals'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))
foreign import ccall safe "CPython/Types/Function.chs.h PyFunction_GetModule"
getModule'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))
foreign import ccall safe "CPython/Types/Function.chs.h PyFunction_GetDefaults"
getDefaults'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))
foreign import ccall safe "CPython/Types/Function.chs.h PyFunction_SetDefaults"
setDefaults'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt)))
foreign import ccall safe "CPython/Types/Function.chs.h PyFunction_GetClosure"
getClosure'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))
foreign import ccall safe "CPython/Types/Function.chs.h PyFunction_SetClosure"
setClosure'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt)))
foreign import ccall safe "CPython/Types/Function.chs.h PyFunction_GetAnnotations"
getAnnotations'_ :: ((C2HSImp.Ptr ()) -> (IO (C2HSImp.Ptr ())))
foreign import ccall safe "CPython/Types/Function.chs.h PyFunction_SetAnnotations"
setAnnotations'_ :: ((C2HSImp.Ptr ()) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt)))