{-# 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 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')
{-# 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 a1 =
withObject a1 $ \a1' ->
getModule'_ a1' >>= \res ->
peekObject res >>= \res' ->
return (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 = maybePeek peekObject
getDefaults :: (Function) -> IO ((Maybe Tuple))
getDefaults a1 =
withObject a1 $ \a1' ->
getDefaults'_ a1' >>= \res ->
peekNullableObject res >>= \res' ->
return (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 a1 =
withObject a1 $ \a1' ->
getAnnotations'_ a1' >>= \res ->
peekNullableObject res >>= \res' ->
return (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'_ :: (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)))