U
    ú¾|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)Úno_cpython_wrapperÚno_cfunc_wrapperÚ
no_compileÚenable_pyobjectÚforce_pyobjectÚNotImplementedError)ÚselfÚflags© r   úQ/var/www/website-v5/atlas_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   Ú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&   Úload_overloadr!   r"   Útarget_contextÚ_compile_uncachedÚsave_overloadr'   ÚlibraryÚ_libraryÚfndescÚllvm_cfunc_wrapper_namer$   Úget_pointer_to_functionr%   )r   Ú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   r5   N   s    zCFunc._compile_uncachedc                 C   s   | j S )zG
        The process-wide symbol the C callback is exposed as.
        )r$   r0   r   r   r   Únative_nameT   s    zCFunc.native_namec                 C   s   | j S )z0
        The address of the C callback.
        )r%   r0   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 *)ÚcffiÚFFIÚcastr?   )r   r@   Úffir   r   r   r@   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-   ÚctypesÚ	CFUNCTYPEr?   )r   Zctypes_argsZctypes_restypeZfunctyper   r   r   rG   o   s    zCFunc.ctypesc                 C   s
   | j  ¡ S )zB
        Return the LLVM IR of the C callback definition.
        )r8   Úget_llvm_strr0   r   r   r   Úinspect_llvmy   s    zCFunc.inspect_llvmc                 C   s   | j S r/   )r'   r0   r   r   r   Ú
cache_hits   s    zCFunc.cache_hitsc                 C   s   d| j f S )Nz<Numba C callback %r>)r   r0   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   Ú
cpu_targetr"   r   ÚCompilerr.   r1   r   r=   r5   Úpropertyr>   r?   r   r@   rG   rJ   rK   rL   rN   r   r   r   r   r   !   s*   ÿ






	
r   )rO   rG   Ú	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   r   Ú<module>   s   