
    xKg5                      ^   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j8                        d        Z eej8                        d        Z ej>                  ej@                        d        Z!y)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                 \    |j                  |       }i }t        ||       t        ||         S )zG
    Generate simple function that get/set a field of the instance
    )formatexecr   )fieldtemplatefnamesourceglblss        f/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/numba/experimental/jitclass/boxing.py_generate_propertyr   !   s0     __U#FEe    accessor)r   r   mutatorc                     t         j                  |       }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    t&v&&r   )_method_code_templater   r   r   r   )namefuncr   r   r"   r   s        @r   _generate_methodr&   1   sR    
 #)))6FE%/"F
4[' ' Nr   c                    | t         v r	t         |    S d| | j                  j                  d}| j                  D ]'  }t	        |      }t        |      }t        ||      ||<   ) | j                  j                         D ]m  \  }}d}d}d|v rt	        |      }d|v rt        |      }|j                  d      xs |j                  d      xs d}t        |dd      }t        |||      ||<   o h d}| j                  j                         D ]O  \  }	}
|	d	k(  r|	j                  d
      r$|	j                  d
      r|	|vrt        d|	 d      t        |	|
      ||	<   Q | j                   j                         D ]  \  }	}
t        |	|
      ||	<    t#        | j$                  t&        j(                  f|      }|t         | <   |j                         D ]  \  }}t+        |t              st        ||      }|j,                  0|j,                  }|j/                  | f      }|j1                          t3        ||t        ||j4                  |j6                  |j8                                |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   sF    $$%c**nn..C
 !%(!%(ff-E
 
 ,,.vF?%e,FF?%e,Fjj<6::e#4<c9d+ff#6E
 /<z kk'')
d:OOD!d#--htf,?@AA$T40D	 * ((..0
d$T40D	 1 #--$((c2F"(3
 		1a"61%Dyy$yy LL#0	$$& DIItyy%)\\34  Mr   c                    t        j                  j                  |      \  }}t        |       }j                  j                  j                  t        |      d      }j                  j                  |j                  j                        }j                  j                  |d      t        j                  d      j                         j                  j                  |      }j                  j                  |      }	fd}
 |
t        j                  |        |
t        j                   |	       S )Nbox_class_instance)infor      c                 (   j                   j                  t        j                  |       }t	        j
                  j                  |      }j                  j                  |j                               }j                  j                  ||       y 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   sf    '']C!!!))S&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    ++AIIs;GW %S)NYY//			
>! 0 N
 ii>G
''
'
'
4C 

1((*I99$$Wi8L		!!'95I' t))<8t&&	2Jr   c                 n   fd}t        j                  |       } |j                  j                        } |t        j
                        } |t        j                        }j                  j                  ||j                  j                        |_        j                  j                  ||j                  j                        |_
        |j                         }j                  j                  j                  j                  | |       t        |j                  j!                               S )Nc                 j   j                   j                  t        j                  |       }t	        j
                  d      j                         }t        j                  j                  |      }j                  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JJqM,,.	!!!))S&9""3	(<(<(>?yy~~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1Jaii+D   : :;K 7 78K 99$$[$,,2C2CDDL		!!+tyy~~>DI
..
CIIMMC-sQWW%8%8%:;;r   c                 ,    t        t        |       d      S )Nr)   )rt   rz   )r   r   s     r   _typeof_jitclass_boxr     s    49n--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 0 , 
 
  -8M!+- -8M!*, "  ~H U @ u<  <H dhh.  .r   