o
    i5                      @   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   q/var/www/html/eduruby.in/lip-sync/lip-sync-env/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rtd|	 dt|	|
||	< qg| j D ]\}	}
t|	|
||	< qt| jtjf|}|t | < | D ]/\}}t|trt
||}|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>;   __imatmul____and____mul____isub____ror____imul____ixor____ne__	__float____radd____eq____getitem____setitem____len____contains____rxor____iand____hash____ior____neg____ipow____complex____le____sub____rmatmul__
__rshift____or____xor____imod____gt____irshift__
__lshift____bool____ge__
__matmul____mod____pow____itruediv____rfloordiv____rpow____int____rrshift____pos__	__index____ilshift____iadd____rsub____truediv____rlshift____add____rmul____rtruediv____rmod____abs____rand____floordiv____lt____str____ifloordiv____init____zMethod 'z' is not supported.)_cache_specialized_boxZ
class_typeZ	class_docstruct_generate_getter_generate_setterpropertyZ	jit_propsitemsr&   getattrmethods
startswithendswith	TypeErrorr"   Zstatic_methodstype	classnamer   Box
isinstancefgetcompileZdisable_compilesetattrfsetfdelr%   )typdctr   gettersetterZimpdctimpr(   Zsupported_dundersr    r!   subclskvpropru   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   Zunpack_tupler   r   r   Zadd_dynamic_addridr   pyapiZpyobjZcall_function_objargsr   IntTyper   r   box_meminfoptr_offsetbox_dataptr_offset)rz   valr   meminfoZ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)Zis_error)r   Zcreate_struct_proxyr   r   r   r   r   r   r   rq   dataZ	_getvalueZnrtZincrefr
   r   Zc_api_error)	rz   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$   )rl   rq   )r   r   r   r   r   _typeof_jitclass_box  r   r   N)"r%   	functoolsr   r   Zllvmliter   Z
numba.corer   r   Znumba.core.decoratorsr   Znumba.core.pythonapir   r	   r
   Znumba.core.typing.typeofr   Znumba.experimental.jitclassr   Z_getter_code_templateZ_setter_code_templater   r   rh   ri   r"   rf   r   ZClassInstanceTyper   r   registerrs   r   r   r   r   r   <module>   s8    
 
 

$