
    J/Ph                         d Z ddlZddlmZ ddlmZmZ ddlmZm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZ  G d
 de          Z G d de          ZdS )z2
Implementation of compiled C callbacks (@cfunc).
    N)cached_property)compilerregistry)	NullCacheFunctionCache)_FunctionCompiler)	signature	to_ctypes)global_compiler_lockc                       e Zd Zd ZdS )_CFuncCompilerc                 j    d|_         d|_        d|_        d|_        |j        rt          d          |S )NTFz&object mode not allowed in C callbacks)no_cpython_wrapperno_cfunc_wrapper
no_compileenable_pyobjectforce_pyobjectNotImplementedError)selfflagss     T/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/core/ccallback.py_customize_flagsz_CFuncCompiler._customize_flags   sF    #' !&   !& 	P%&NOOO    N)__name__
__module____qualname__r    r   r   r   r      s#            r   r   c                       e Zd ZdZej        Zej        fdZ	d Z
ed             Zd Zed             Zed             Zed             Zed	             Zd
 Zed             Zd Zd ZdS )CFunczD
    A compiled C callback, as created by the @cfunc decorator.
    c                 L   |\  }}|t          d          |j        | _        t          |d| j                  | _        || _        || _        t          |g|R  | _        t          || j	        |||          | _
        d | _        d | _        t                      | _        d| _        d S )Nz(C callback needs an explicit return typer   )pipeline_classr   )	TypeErrorr   getattrr   __wrapped___pyfuncr	   _sigr   _targetdescr	_compiler_wrapper_name_wrapper_addressr   _cache_cache_hits)r   pyfuncsiglocalsoptionsr"   argsreturn_types           r   __init__zCFunc.__init__'   s    kFGGG#FNDMJJ!k1D111	'0A(/7EG G G " $kkr   c                 8    t          | j                  | _        d S N)r   r&   r,   r   s    r   enable_cachingzCFunc.enable_caching;   s    #DL11r   c                 j   | j                             | j        | j        j                  }|5|                                 }| j                             | j        |           n| xj        dz  c_        |j        | _	        |j
        j        | _        | j	                            | j                  | _        d S )N   )r,   load_overloadr'   r(   target_context_compile_uncachedsave_overloadr-   library_libraryfndescllvm_cfunc_wrapper_namer*   get_pointer_to_functionr+   )r   cress     r   compilezCFunc.compile>   s     {(()-):)IK K<))++DK%%di6666!![@ $ E E!  ! r   c                 Z    | j         }| j                            |j        |j                  S r6   )r'   r)   rE   r2   r3   )r   r/   s     r   r=   zCFunc._compile_uncachedN   s'    i ~%%ch@@@r   c                     | j         S )zG
        The process-wide symbol the C callback is exposed as.
        )r*   r7   s    r   native_namezCFunc.native_nameT   s     !!r   c                     | j         S )z0
        The address of the C callback.
        )r+   r7   s    r   addresszCFunc.address]   s    
 $$r   c                 h    ddl }|                                }|                    d| j                  S )zF
        A cffi function pointer representing the C callback.
        r   Nzvoid *)cffiFFIcastrJ   )r   rL   ffis      r   rL   z
CFunc.cffid   s2    
 	hhjj xx$,///r   c                     d | j         j        D             }t          | j         j                  }t	          j        |g|R  } || j                  S )zG
        A ctypes function object representing the C callback.
        c                 ,    g | ]}t          |          S r   r
   ).0tys     r   
<listcomp>z CFunc.ctypes.<locals>.<listcomp>t   s    >>>y}}>>>r   )r'   r2   r   r3   ctypes	CFUNCTYPErJ   )r   ctypes_argsctypes_restypefunctypes       r   rU   zCFunc.ctypeso   sW    
 ?>ty~>>>"49#899#NA[AAAx%%%r   c                 4    | j                                         S )zB
        Return the LLVM IR of the C callback definition.
        )r@   get_llvm_strr7   s    r   inspect_llvmzCFunc.inspect_llvmy   s     }))+++r   c                     | j         S r6   )r-   r7   s    r   
cache_hitszCFunc.cache_hits   s    r   c                     d| j         dS )Nz<Numba C callback >)r   r7   s    r   __repr__zCFunc.__repr__   s     *.*;*;*;==r   c                      | j         |i |S r6   )r&   )r   r2   kwargss      r   __call__zCFunc.__call__   s    t|T,V,,,r   N)r   r   r   __doc__r   
cpu_targetr(   r   Compilerr4   r8   r   rE   r=   propertyrH   rJ   r   rL   rU   r\   r^   ra   rd   r   r   r   r    r    !   s5         &L !) 1   (2 2 2      A A A " " X" % % X% 0 0 _0 & & _&, , ,     X > > >- - - - -r   r    )re   rU   	functoolsr   
numba.corer   r   numba.core.cachingr   r   numba.core.dispatcherr   numba.core.typingr	   numba.core.typing.ctypes_utilsr   numba.core.compiler_lockr   r   objectr    r   r   r   <module>rq      s   
  % % % % % % ) ) ) ) ) ) ) ) 7 7 7 7 7 7 7 7 3 3 3 3 3 3 ' ' ' ' ' ' 4 4 4 4 4 4 9 9 9 9 9 9    &    f- f- f- f- f-F f- f- f- f- f-r   