module CPython.Types.Function
( Function
, functionType
, new
, getCode
, getGlobals
, getModule
, getDefaults
, setDefaults
, getClosure
, setClosure
, getAnnotations
, setAnnotations
) where
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 x) = SomeObject x
fromForeignPtr = Function
instance Concrete Function where
concreteType _ = functionType
functionType :: Type
functionType =
unsafePerformIO $
let {res = functionType'_} in
peekStaticObject res >>= \res' ->
return (res')
new :: Code -> Dictionary -> IO (Function)
new a1 a2 =
withObject a1 $ \a1' ->
withObject a2 $ \a2' ->
new'_ a1' a2' >>= \res ->
stealObject res >>= \res' ->
return (res')
getCode :: Function -> IO (Code)
getCode a1 =
withObject a1 $ \a1' ->
getCode'_ a1' >>= \res ->
peekObject res >>= \res' ->
return (res')
getGlobals :: Function -> IO (Dictionary)
getGlobals a1 =
withObject a1 $ \a1' ->
getGlobals'_ a1' >>= \res ->
peekObject res >>= \res' ->
return (res')
getModule :: Function -> IO (SomeObject)
getModule a1 =
withObject a1 $ \a1' ->
getModule'_ a1' >>= \res ->
peekObject res >>= \res' ->
return (res')
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 = maybePeek peekObject
getDefaults :: Function -> IO (Maybe Tuple)
getDefaults a1 =
withObject a1 $ \a1' ->
getDefaults'_ a1' >>= \res ->
peekNullableObject res >>= \res' ->
return (res')
setDefaults :: Function -> Maybe Tuple -> IO (())
setDefaults a1 a2 =
withObject a1 $ \a1' ->
withNullableObject a2 $ \a2' ->
setDefaults'_ a1' a2' >>= \res ->
checkStatusCode res >>= \res' ->
return (res')
getClosure :: Function -> IO (Maybe Tuple)
getClosure a1 =
withObject a1 $ \a1' ->
getClosure'_ a1' >>= \res ->
peekNullableObject res >>= \res' ->
return (res')
setClosure :: Function -> Maybe Tuple -> IO (())
setClosure a1 a2 =
withObject a1 $ \a1' ->
withNullableObject a2 $ \a2' ->
setClosure'_ a1' a2' >>= \res ->
checkStatusCode res >>= \res' ->
return (res')
getAnnotations :: Function -> IO (Maybe Dictionary)
getAnnotations a1 =
withObject a1 $ \a1' ->
getAnnotations'_ a1' >>= \res ->
peekNullableObject res >>= \res' ->
return (res')
setAnnotations :: Function -> Maybe Dictionary -> IO (())
setAnnotations a1 a2 =
withObject a1 $ \a1' ->
withNullableObject a2 $ \a2' ->
setAnnotations'_ a1' a2' >>= \res ->
checkStatusCode res >>= \res' ->
return (res')
foreign import ccall unsafe "CPython/Types/Function.chs.h hscpython_PyFunction_Type"
functionType'_ :: (Ptr ())
foreign import ccall safe "CPython/Types/Function.chs.h PyFunction_New"
new'_ :: ((Ptr ()) -> ((Ptr ()) -> (IO (Ptr ()))))
foreign import ccall safe "CPython/Types/Function.chs.h PyFunction_GetCode"
getCode'_ :: ((Ptr ()) -> (IO (Ptr ())))
foreign import ccall safe "CPython/Types/Function.chs.h PyFunction_GetGlobals"
getGlobals'_ :: ((Ptr ()) -> (IO (Ptr ())))
foreign import ccall safe "CPython/Types/Function.chs.h PyFunction_GetModule"
getModule'_ :: ((Ptr ()) -> (IO (Ptr ())))
foreign import ccall safe "CPython/Types/Function.chs.h PyFunction_GetDefaults"
getDefaults'_ :: ((Ptr ()) -> (IO (Ptr ())))
foreign import ccall safe "CPython/Types/Function.chs.h PyFunction_SetDefaults"
setDefaults'_ :: ((Ptr ()) -> ((Ptr ()) -> (IO CInt)))
foreign import ccall safe "CPython/Types/Function.chs.h PyFunction_GetClosure"
getClosure'_ :: ((Ptr ()) -> (IO (Ptr ())))
foreign import ccall safe "CPython/Types/Function.chs.h PyFunction_SetClosure"
setClosure'_ :: ((Ptr ()) -> ((Ptr ()) -> (IO CInt)))
foreign import ccall safe "CPython/Types/Function.chs.h PyFunction_GetAnnotations"
getAnnotations'_ :: ((Ptr ()) -> (IO (Ptr ())))
foreign import ccall safe "CPython/Types/Function.chs.h PyFunction_SetAnnotations"
setAnnotations'_ :: ((Ptr ()) -> ((Ptr ()) -> (IO CInt)))