
    J/Ph5                      h   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 Z eeed          Z eeed          Zd Zi Zd Z eej                  d             Z eej                  d             Z ej        ej                   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                 z    |                     |           }i }t          ||           t          ||                   S )zG
    Generate simple function that get/set a field of the instance
    )formatexecr   )fieldtemplatefnamesourceglblss        b/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/experimental/jitclass/boxing.py_generate_propertyr   !   s<     __U##FEe    accessor)r   r   mutatorc                     t                               |           }i }t          ||           t          |d                   t	          |          fd            }|S )zo
    Generate a wrapper for calling a method.  Note the wrapper will only
    accept positional arguments.
    )methodr   c                       | i |S N )argskwargsr   s     r   wrapperz!_generate_method.<locals>.wrapper;   s    vt&v&&&r   )_method_code_templater   r   r   r   )namefuncr   r   r"   r   s        @r   _generate_methodr&   1   sq    
 #)))66FE%/""F
4[[' ' ' ' [' Nr   c                    | t           v rt           |          S d| | j        j        d}| j        D ]3}t	          |          }t          |          }t          ||          ||<   4| j                                        D ]\  }}d}d}d|v rt	          |          }d|v rt          |          }|	                    d          p|	                    d          pd}t          |dd          }t          |||          ||<   h d}| j                                        D ]`\  }	}
|	d	k    r|	                    d
          r,|	                    d
          r|	|vrt          d|	 d          t          |	|
          ||	<   a| j                                        D ]\  }	}
t          |	|
          ||	<   t#          | j        t&          j        f|          }|t           | <   |                                D ]\  }}t+          |t                    ryt          ||          }|j        b|j        }|                    | f          }|                                 t3          ||t          ||j        |j        |j                             |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>;   __eq____ge____gt____le____lt____ne____or____abs____add____and____int____ior____len____mod____mul____neg____pos____pow____ror____str____sub____xor____bool____hash____iadd____iand____imod____imul____ipow____isub____ixor____radd____rand____rmod____rmul____rpow____rsub____rxor__	__float__	__index__
__lshift__
__matmul__
__rshift____complex____getitem____ilshift____imatmul____irshift____rlshift____rmatmul____rrshift____setitem____truediv____contains____floordiv____itruediv____rtruediv____ifloordiv____rfloordiv____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setterimpdctimpr-   supported_dundersr$   r%   subclskvpropr~   	fast_fgets                    r   _specialize_boxr   E   s    $$$%c**n. C
  . .!%((!%((ff--E

,,.. 
7 
7vF??%e,,FF??%e,,Fjj<6::e#4#4<c9d++ff#666E

< < <z k'')) 	1 	1
d:OOD!!	Bd##	B ---@t@@@AAA$T400D		 (..00 1 1
d$T400D		 #-$(c22F"(3
 		 	4 	41a"" 	461%%Dy$y LL#00	$$&&& DIty%)\3 3 34 4 4 Mr   c                 `   t          j        j        |          \  }}t          |           }j                            j        t          |          d          }j                            |j        j	                  }j        
                    |d          t          j        d                                          j                            |          }j                            |          }	fd}
 |
t          j        |            |
t          j        |	           S )Nbox_class_instance)infor      c                    j                             t          j        |           }t	          j        j        |          }j                            |                                          }j        	                    ||           d S r   )
contextget_constantr   uintpr   pointer_addbuilderbitcast
as_pointerstore)member_offsetvalueoffsetptrcastedr	   c	llvoidptrs        r   
set_memberz'_box_class_instance.<locals>.set_member   sq    '']CC!!)S&99""3	(<(<(>(>??		v&&&&&r   )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dataptrbox_subclassedvoidptr_boxclsbox_clsaddr_meminfo	addr_datar   r	   r   s     `        @@r   _box_class_instancer      s-   +AIs;;GW %S))NY//		
>! 0  N
 i>>G
'
'
'
4
4C 
1((**I9$$Wi88L	!!'955I' ' ' ' ' ' ' Jt)<888Jt&	222Jr   c                 &   fd}t          j        |           } |j        j                  } |t          j                  } |t          j                  }j                            ||j        j	                  |_        j                            ||j
        j	                  |_
        |                                }j        j                            j        | |           t          |j                                                  S )Nc                 ^   j                             t          j        |           }t	          j        d                                          }t          j        j	        |          }j	        
                    ||                                          }j	                            |          S )Nr   )r   r   r   r   r   r   r   r   r   r   r   load)r   r   r   r   r   r   r   s        r   access_memberz,_unbox_class_instance.<locals>.access_member   s    '']CCJqMM,,..	!!)S&99""3	(<(<(>(>??y~~f%%%r   )is_error)r   create_struct_proxyr   r   r   r   r   r   r   rz   data	_getvaluenrtincrefr   r   c_api_error)	r   r   r   r   
struct_clsinstptr_meminfoptr_dataptrrets	    ``      r   _unbox_class_instancer      s    & & & & & & ,S11J:ai++D  - :;;K- 788K 9$$[$,2CDDDL	!!+ty~>>DI
..

CIMC---sQW%8%8%:%:;;;;r   c                 <    t          t          |           d          S )Nr)   )rt   rz   )r   r   s     r   _typeof_jitclass_boxr     s    499n---r   N)"r*   	functoolsr   r   llvmliter   
numba.corer   r   numba.core.decoratorsr   numba.core.pythonapir	   r
   r   numba.core.typing.typeofr   numba.experimental.jitclassr   _getter_code_template_setter_code_templater#   r   ro   rp   r&   rk   r   ClassInstanceTyper   r   registerr|   r   r   r   r   <module>r      s   
 % $ $ $ $ $ $ $       % % % % % % % % & & & & & & 8 8 8 8 8 8 8 8 8 8 0 0 0 0 0 0 , , , , , , 
 
    7-8M!+- - - 7-8M!*, , ,   "  ~ ~ ~H U  @ u< <  <H dh. .  . . .r   