U
    9%e                     @   s   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 deZG d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                   @   s   e Zd Zdd ZdS )_CFuncCompilerc                 C   s*   d|_ d|_d|_d|_|jr&td|S )NTFz&object mode not allowed in C callbacks)Zno_cpython_wrapperZno_cfunc_wrapperZ
no_compileZenable_pyobjectZforce_pyobjectNotImplementedError)selfflags r   S/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/numba/core/ccallback.py_customize_flags   s    z_CFuncCompiler._customize_flagsN)__name__
__module____qualname__r   r   r   r   r   r      s   r   c                   @   s   e Zd ZdZejZejfddZ	dd Z
edd Zdd	 Zed
d Zedd Zedd Zedd Zdd Zedd Zdd Zdd ZdS )CFunczD
    A compiled C callback, as created by the @cfunc decorator.
    c                 C   s   |\}}|d krt d|j| _t|d| j| _|| _|| _t|f| | _t|| j	|||d| _
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   Zpyfuncsiglocalsoptionsr   argsreturn_typer   r   r   __init__'   s"     zCFunc.__init__c                 C   s   t | j| _d S N)r   r   r!   r   r   r   r   enable_caching;   s    zCFunc.enable_cachingc                 C   sj   | j | j| jj}|d kr6|  }| j | j| n|  jd7  _|j| _	|j
j| _| j	| j| _d S )N   )r!   Zload_overloadr   r   Ztarget_context_compile_uncachedZsave_overloadr"   Zlibrary_libraryZfndescZllvm_cfunc_wrapper_namer   Zget_pointer_to_functionr    )r   Zcresr   r   r   compile>   s    

zCFunc.compilec                 C   s   | j }| j|j|jS r)   )r   r   r/   r&   r'   )r   r#   r   r   r   r-   N   s    zCFunc._compile_uncachedc                 C   s   | j S )zG
        The process-wide symbol the C callback is exposed as.
        )r   r*   r   r   r   native_nameT   s    zCFunc.native_namec                 C   s   | j S )z0
        The address of the C callback.
        )r    r*   r   r   r   address]   s    zCFunc.addressc                 C   s   ddl }| }|d| jS )zF
        A cffi function pointer representing the C callback.
        r   Nzvoid *)cffiZFFIcastr1   )r   r2   ffir   r   r   r2   d   s    z
CFunc.cffic                 C   s8   dd | j jD }t| j j}tj|f| }|| jS )zG
        A ctypes function object representing the C callback.
        c                 S   s   g | ]}t |qS r   r	   ).0tyr   r   r   
<listcomp>t   s     z CFunc.ctypes.<locals>.<listcomp>)r   r&   r
   r'   ctypesZ	CFUNCTYPEr1   )r   Zctypes_argsZctypes_restypeZfunctyper   r   r   r8   o   s    zCFunc.ctypesc                 C   s
   | j  S )zB
        Return the LLVM IR of the C callback definition.
        )r.   Zget_llvm_strr*   r   r   r   inspect_llvmy   s    zCFunc.inspect_llvmc                 C   s   | j S r)   )r"   r*   r   r   r   
cache_hits   s    zCFunc.cache_hitsc                 C   s   d| j f S )Nz<Numba C callback %r>)r   r*   r   r   r   __repr__   s    zCFunc.__repr__c                 O   s   | j ||S r)   )r   )r   r&   kwargsr   r   r   __call__   s    zCFunc.__call__N)r   r   r   __doc__r   Z
cpu_targetr   r   ZCompilerr(   r+   r   r/   r-   propertyr0   r1   r   r2   r8   r9   r:   r;   r=   r   r   r   r   r   !   s*   






	
r   )r>   r8   	functoolsr   Z
numba.corer   r   Znumba.core.cachingr   r   Znumba.core.dispatcherr   Znumba.core.typingr   Znumba.core.typing.ctypes_utilsr
   Znumba.core.compiler_lockr   r   objectr   r   r   r   r   <module>   s   