o
    ­ôjh   ã                   @   sè   d Z ddlmZmZ ddlmZ ddlmZmZ ddl	m
Z
 ddlmZmZmZ ddlmZ ddlmZ d	Zd
ZdZdd„ Zeeedd�Zeeedd�Zdd„ Zi Zdd„ Zeejƒdd„ ƒZeejƒdd„ ƒZe ej ¡dd„ ƒZ!dS )z‚
Implement logic relating to wrapping (box) and unwrapping (unbox) instances
of jitclasses for use inside the python interpreter.
é    )ÚwrapsÚpartial)Úir)ÚtypesÚcgutils)Únjit)ÚboxÚunboxÚNativeValue)Útypeof_impl)Ú_boxz;
def accessor(__numba_self_):
    return __numba_self_.{0}
zN
def mutator(__numba_self_, __numba_val):
    __numba_self_.{0} = __numba_val
zL
def method(__numba_self_, *args):
    return __numba_self_.{method}(*args)
c                 C   s$   |  | ¡}i }t||ƒ t|| ƒS )zG
    Generate simple function that get/set a field of the instance
    )ÚformatÚexecr   )ÚfieldÚtemplateÚfnameÚsourceÚglbls© r   ús/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/numba/experimental/jitclass/boxing.pyÚ_generate_property!   s   

r   Úaccessor)r   r   Zmutatorc                    s>   t j| d�}i }t||ƒ t|d ƒ‰ t|ƒ‡ fdd„ƒ}|S )zo
    Generate a wrapper for calling a method.  Note the wrapper will only
    accept positional arguments.
    ©Úmethodr   c                     s   ˆ | i |¤ŽS ©Nr   )ÚargsÚkwargsr   r   r   Úwrapper;   ó   z!_generate_method.<locals>.wrapper)Ú_method_code_templater   r   r   r   )ÚnameÚfuncr   r   r   r   r   r   Ú_generate_method1   s   
r"   c              
   C   sÄ  | t v rt |  S d| | jjdœ}| jD ]}t|ƒ}t|ƒ}t||ƒ||< q| j ¡ D ]3\}}d}d}d|v r:t|ƒ}d|v rBt|ƒ}| 	d¡pM| 	d¡pMd}t
|ddƒ}t|||d�||< q*h d£}| j ¡ D ]&\}	}
|	d	krpqg|	 d
¡r†|	 d
¡r†|	|vr†td|	› d�ƒ‚t|	|
ƒ||	< qg| j ¡ D ]\}	}
t|	|
ƒ||	< q“t| jtjf|ƒ}|t | < | ¡ D ]/\}}t|tƒrßt
||ƒ}|jdurß|j}| | f¡}| ¡  t||t||j|j|jd�ƒ q°|S )z�
    Create a subclass of Box that is specialized to the jitclass.

    This function caches the result to avoid code bloat.
    r   )Ú	__slots__Ú_numba_type_Ú__doc__NÚgetÚsetr%   )Údoc>=   Ú__le__Ú__pow__Ú__ror__Ú__hash__Ú__rtruediv__Ú__eq__Ú__ge__Ú
__matmul__Ú__truediv__Ú__rlshift__Ú__rrshift__Ú__pos__Ú__add__Ú__rmod__Ú	__index__Ú__gt__Ú__ifloordiv__Ú__getitem__Ú__ipow__Ú__setitem__Ú__rsub__Ú
__invert__Z__annotate_func__Ú__str__Ú__ne__Ú__contains__Ú__rand__Ú__ilshift__Ú__irshift__Ú__rmatmul__Ú__iadd__Ú__itruediv__Ú__abs__Ú__imatmul__Ú__rfloordiv__Ú__neg__Ú__complex__Ú__rmul__Ú__mul__Ú__or__Ú__rpow__Ú__xor__Ú__floordiv__Ú__ior__Ú__sub__Ú__bool__Ú__rxor__Ú__iand__Ú__and__Ú__imul__Ú__radd__Ú__ixor__Ú__lt__Ú__int__Ú__len__Ú
__rshift__Ú
__lshift__Ú	__float__Ú__imod__Ú__mod__Ú__isub__Ú__init__Ú__zMethod 'z' is not supported.)Ú_cache_specialized_boxÚ
class_typeÚ	class_docÚstructÚ_generate_getterÚ_generate_setterÚpropertyÚ	jit_propsÚitemsr&   ÚgetattrÚmethodsÚ
startswithÚendswithÚ	TypeErrorr"   Ústatic_methodsÚtypeÚ	classnamer   ÚBoxÚ
isinstanceÚfgetÚcompileÚdisable_compileÚsetattrÚfsetÚfdelr%   )ÚtypÚdctr   ÚgetterÚsetterZimpdctÚimpr(   Zsupported_dundersr    r!   ÚsubclsÚkÚvÚproprz   Z	fast_fgetr   r   r   Ú_specialize_boxE   sb   þ
?ÿþ


ÿÿ€r‰   c                    s¨   t  ˆj|¡\}}t| ƒ}ˆjjˆjt|ƒdd�}ˆj |ˆjj	¡}ˆj 
|d¡‰ t d¡ ¡ ‰ˆj |ˆ¡}ˆj |ˆ¡}	‡ ‡‡fdd„}
|
tj|ƒ |
tj|	ƒ ˆ S )NZbox_class_instance)Úinfor   é   c                    sD   ˆj  tj| ¡}t ˆjˆ |¡}ˆj |ˆ ¡ ¡}ˆj 	||¡ d S r   )
ÚcontextÚget_constantr   Úuintpr   Úpointer_addÚbuilderÚbitcastÚ
as_pointerÚstore)Úmember_offsetÚvalueÚoffsetÚptrÚcasted©r   ÚcÚ	llvoidptrr   r   Ú
set_memberà   s   z'_box_class_instance.<locals>.set_member)r   Úunpack_tupler�   r‰   rŒ   Úadd_dynamic_addrÚidr‘   ÚpyapiÚpyobjÚcall_function_objargsr   ÚIntTyper’   r   Úbox_meminfoptr_offsetÚbox_dataptr_offset)r€   Úvalrš   ÚmeminfoÚdataptrZbox_subclassedZvoidptr_boxclsZbox_clsZaddr_meminfoZ	addr_datarœ   r   r™   r   Ú_box_class_instanceË   s    ýr©   c           	         s�   ‡ ‡fdd„}t  | ¡}|ˆ jˆ jƒ}|tjƒ}|tjƒ}ˆ j ||jj	¡|_ˆ j ||j
j	¡|_
| ¡ }ˆ jj ˆ j| |¡ t|ˆ j ¡ d�S )Nc                    sL   ˆ j  tj| ¡}t d¡ ¡ }t ˆ j	ˆ|¡}ˆ j	 
|| ¡ ¡}ˆ j	 |¡S )Nr‹   )rŒ   r�   r   rŽ   r   r£   r’   r   r�   r�   r‘   Úload)r”   r–   r›   r—   r˜   ©rš   r¦   r   r   Úaccess_memberî   s
   z,_unbox_class_instance.<locals>.access_member)Úis_error)r   Úcreate_struct_proxyrŒ   r�   r   r¤   r¥   r‘   r§   rv   ÚdataÚ	_getvalueÚnrtÚincrefr
   r    Úc_api_error)	r€   r¦   rš   r¬   Z
struct_clsÚinstZptr_meminfoZptr_dataptrÚretr   r«   r   Ú_unbox_class_instanceì   s   


r¶   c                 C   s   t t| ƒdƒS )Nr$   )rp   rv   )r¦   rš   r   r   r   Ú_typeof_jitclass_box  r   r·   N)"r%   Ú	functoolsr   r   Úllvmliter   Ú
numba.corer   r   Únumba.core.decoratorsr   Únumba.core.pythonapir   r	   r
   Znumba.core.typing.typeofr   Únumba.experimental.jitclassr   Z_getter_code_templateZ_setter_code_templater   r   rk   rl   r"   rg   r‰   ÚClassInstanceTyper©   r¶   Úregisterrx   r·   r   r   r   r   Ú<module>   s8    
ÿÿ 
 

$