ó
    ýZhã,  ã                   óÂ   • S r SSKJr  SSKJrJrJr  SSKJrJ	r	  SSK
JrJrJrJrJrJrJrJr  SSKJr   " S S5      rS	 rS
 rS rS rS r\S 5       r " S S5      rg)z€Utilities for defining a mutable struct.

A mutable struct is passed by reference;
hence, structref (a reference to a struct).

é    )Únjit)ÚtypesÚimputilsÚcgutils)Údefault_managerÚmodels)Úinfer_getattrÚlower_getattr_genericÚlower_setattr_genericÚboxÚunboxÚNativeValueÚ	intrinsicÚoverload)ÚAttributeTemplatec                   ó6   • \ rS rSrSrS rS rS rS rS r	Sr
g	)
Ú_Utilsé   z;Internal builder-code utils for structref definitions.
    c                 ó(   • Xl         X l        X0l        g)zˆ
Parameters
----------
context :
    a numba target context
builder :
    a llvmlite IRBuilder
struct_type : numba.core.types.StructRef
N)ÚcontextÚbuilderÚstruct_type)Úselfr   r   r   s       Úk/home/gothic/public_html/Fooocus/fooocus_env/lib64/python3.13/site-packages/numba/experimental/structref.pyÚ__init__Ú_Utils.__init__   s   € ð ŒØŒØ&Õó    c                 ó’   • U R                   nU R                  nU R                  n[        R                  " U5      " X#5      nXl        U$ )zKEncapsulate the MemInfo from a `StructRefPayload` in a `StructRef`
        )r   r   r   r   Úcreate_struct_proxyÚmeminfo)r   Úmir   r   r   Ústs         r   Únew_struct_refÚ_Utils.new_struct_ref(   s@   € ð —,‘,ˆØ—,‘,ˆØ×&Ñ&ˆä×(Ò(¨Ô5°gÓGˆØŒ
Øˆ	r   c                 ó€   • U R                   nU R                  nU R                  n[        R                  " U5      " X#US9$ )z6Return a helper for accessing a StructRefType
        )Úvalue)r   r   r   r   r   )r   Úvalr   r   r   s        r   Úget_struct_refÚ_Utils.get_struct_ref3   s>   € ð —,‘,ˆØ—,‘,ˆØ×&Ñ&ˆä×*Ò*¨;Ô7Ø Cñ
ð 	
r   c                 óZ  • U R                   nU R                  nU R                  nU R                  U5      nUR                  nUR
                  R                  X65      nUR                  5       nUR                  U   n	U	R                  5       n
UR                  XzR                  5       5      nU$ )zDGet the data pointer to the payload from a `StructRefType`.
        )r   r   r   r(   r    ÚnrtÚmeminfo_dataÚget_data_typeÚdata_model_managerÚget_value_typeÚbitcastÚ
as_pointer)r   r'   r   r   r   Ú	structvalr    Údata_ptrÚvaltypeÚmodelÚ
alloc_types              r   Úget_data_pointerÚ_Utils.get_data_pointer>   s˜   € ð —,‘,ˆØ—,‘,ˆØ×&Ñ&ˆà×'Ñ'¨Ó,ˆ	Ø×#Ñ#ˆØ—;‘;×+Ñ+¨GÓ=ˆà×+Ñ+Ó-ˆØ×*Ñ*¨7Ñ3ˆØ×)Ñ)Ó+ˆ
Ø—?‘? 8×-BÑ-BÓ-DÓEˆØˆr   c                 óÆ   • U R                   nU R                  nU R                  nU R                  U5      nUR	                  5       n[
        R                  " U5      " X#US9nU$ )zFGet a getter/setter helper for accessing a `StructRefPayload`
        )Úref)r   r   r   r7   r-   r   r   )r   r'   r   r   r   r3   r4   Údatavals           r   Úget_data_structÚ_Utils.get_data_structO   s`   € ð —,‘,ˆØ—,‘,ˆØ×&Ñ&ˆà×(Ñ(¨Ó-ˆØ×+Ñ+Ó-ˆÜ×-Ò-¨gÔ6Ø (ñ
ˆð ˆr   )r   r   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r#   r(   r7   r<   Ú__static_attributes__© r   r   r   r      s    † ñò'ò	ò	
òõ"r   r   c                 ó€   ^ • [          " U 4S jS[        5      5       n[        T 5      S 5       n[        T 5      S 5       ng)z‚Define attributes on `struct_typeclass`.

Defines both setters and getters in jit-code.

This is called directly in `register()`.
c                   ó"   >• \ rS rSr Y rS rSrg)Ú*define_attributes.<locals>.StructAttributeée   c                 óD   • X!R                   ;   a  UR                   U   nU$ g ©N)Ú
field_dict)r   ÚtypÚattrÚattrtys       r   Úgeneric_resolveÚ:define_attributes.<locals>.StructAttribute.generic_resolvei   s$   € Ø—~‘~Ó%ØŸ™¨Ñ-�Ø�ð &r   rD   N)r>   r?   r@   rA   ÚkeyrO   rC   )Ústruct_typeclasss   €r   ÚStructAttributerG   e   s   ø† áˆõ	r   rS   c                 óž   • [        XU5      nUR                  U5      n[        Xd5      nUR                  U   n[        R
                  " XX‡5      $ rJ   )r   r<   ÚgetattrrK   r   Úimpl_ret_borrowed)	r   r   rL   r'   rM   Úutilsr;   ÚretÚ	fieldtypes	            r   Ústruct_getattr_implÚ.define_attributes.<locals>.struct_getattr_impln   sI   € ä�w¨Ó-ˆØ×'Ñ'¨Ó,ˆÜ�gÓ$ˆØ—N‘N 4Ñ(ˆ	Ü×)Ò)¨'¸IÓKÐKr   c                 óB  • UR                   u  pVUu  px[        XU5      n	U	R                  U5      n
UR                  U   nU R	                  XXk5      n[        X¤5      nU R                  R                  XU5        U R                  R                  XU5        [        X¤U5        g rJ   )
Úargsr   r<   rK   ÚcastrU   r+   ÚincrefÚdecrefÚsetattr)r   r   Úsigr]   rM   Ú	inst_typeÚval_typeÚinstancer'   rW   r;   Ú
field_typeÚcastedÚ	old_values                 r   Ústruct_setattr_implÚ.define_attributes.<locals>.struct_setattr_implv   s�   € à #§¡ÑˆØ‰ˆÜ�w¨Ó3ˆØ×'Ñ'¨Ó1ˆà×)Ñ)¨$Ñ/ˆ
Ø—‘˜g¨HÓAˆä˜GÓ*ˆ	à�‰×Ñ˜7¨fÔ5à�‰×Ñ˜7¨iÔ8ä�˜vÕ&r   N)r	   r   r
   r   )rR   rS   rZ   ri   s   `   r   Údefine_attributesrk   ^   sU   ø€ ô ÷Ô+ó ó ðô Ð+Ó,ñLó -ðLô Ð+Ó,ñ'ó -ñ'r   c                 óÆ   ^• U [         R                  L a  [        S[         R                   35      eUR                  m[	        U 5      U4S j5       n[        U 5      S 5       ng)a|  Define the boxing & unboxing logic for `struct_type` to `obj_class`.

Defines both boxing and unboxing.

- boxing turns an instance of `struct_type` into a PyObject of `obj_class`
- unboxing turns an instance of `obj_class` into an instance of
  `struct_type` in jit-code.


Use this directly instead of `define_proxy()` when the user does not
want any constructor to be defined.
úcannot register c                 óš  >• [        UR                  UR                  U 5      nUR                  U5      nUR                  n[
        R                  " [
        R                  5      nUR                  Xe5      nUR                  R                  UR                  R                  T5      5      nUR                  R                  UR                  R                  U 5      5      n	UR                  R                  X‰U/5      n
UR                  R                  U5        UR                  R                  U	5        UR                  R                  U5        U
$ )z(
Convert a raw pointer to a Python int.
)r   r   r   r(   r    r   ÚMemInfoPointerÚvoidptrr   ÚpyapiÚunserializeÚserialize_objectÚcall_function_objargsr`   )rL   r'   ÚcrW   Ú
struct_refr    Úmip_typeÚboxed_meminfoÚctor_pyfuncÚty_pyobjÚresÚobj_ctors              €r   Úbox_struct_refÚ%define_boxing.<locals>.box_struct_ref›   sñ   ø€ ô
 �q—y‘y !§)¡)¨SÓ1ˆØ×)Ñ)¨#Ó.ˆ
Ø×$Ñ$ˆä×'Ò'¬¯©Ó6ˆØŸ™˜hÓ0ˆà—g‘g×)Ñ)¨!¯'©'×*BÑ*BÀ8Ó*LÓMˆØ—7‘7×&Ñ& q§w¡w×'?Ñ'?ÀÓ'DÓEˆà�g‰g×+Ñ+Ø MÐ2ó
ˆð 	
�‰�‰�{Ô#Ø	�‰�‰�xÔ Ø	�‰�‰�}Ô%Øˆ
r   c                 óˆ  • UR                   R                  US5      n[        R                  " [        R                  5      nUR                  XC5      R                  n[        UR                  UR                  U 5      nUR                  U5      nUR                  5       nUR                   R                  U5        [        U5      $ )NÚ_meminfo)rq   Úobject_getattr_stringr   ro   rp   r   r&   r   r   r   r#   Ú	_getvaluer`   r   )	rL   Úobjru   Úmi_objrw   r!   rW   rv   Úouts	            r   Úunbox_struct_refÚ'define_boxing.<locals>.unbox_struct_ref²   s�   € à—‘×.Ñ.¨s°JÓ?ˆä×'Ò'¬¯©Ó6ˆà�W‰W�XÓ&×,Ñ,ˆä�q—y‘y !§)¡)¨SÓ1ˆØ×)Ñ)¨"Ó-ˆ
Ø×"Ñ"Ó$ˆà	�‰�‰�vÔÜ˜3ÓÐr   N)r   Ú	StructRefÚ
ValueErrorÚ_numba_box_r   r   )r   Ú	obj_classr}   r†   r|   s       @r   Údefine_boxingrŒ   ‰   sd   ø€ ð ”e—o‘oÒ%ÜÐ+¬E¯O©OÐ+<Ð=Ó>Ð>à×$Ñ$€HäˆÓôó ðô, ˆ;Óñ ó ñ r   c                 ó*  • SR                  U5      nSn/ nU H  nUR                  SU SU 35        M     SU 3R                  U5      nSU S[        U5       SU S	U S
U S3n[        U[        S9n	[        X‰5        U	S   n
[        U 5      " U
5        g)zÉDefine the jit-code constructor for `struct_typeclass` using the
Python type `py_class` and the required `fields`.

Use this instead of `define_proxy()` if the user does not want boxing
logic defined.
z, z        zst.z = Ú
z

def ctor(z/):
    struct_type = struct_typeclass(list(zip(z, [z])))
    def impl(z)):
        st = new(struct_type)
        z#
        return st
    return impl
)rR   ÚnewÚctorN)ÚjoinÚappendÚlistÚdictr�   Úexecr   )Úpy_classrR   ÚfieldsÚparamsÚindentÚinit_fields_bufÚkÚinit_fieldsÚsourceÚglbsr�   s              r   Údefine_constructorrŸ   Â   sÂ   € ð �Y‰Y�vÓ€FØ€FØ€OÛˆØ×Ñ  Q C s¨1¨#˜Ö/ñ à�v�h�-×$Ñ$ _Ó5€Kð
Ø
ˆð -Ü-1°&«\¨N¸#¸f¸Xð FØˆXð 	à	ˆð ð€Fô Ð!1´sÑ;€DÜˆÔØ�‰<€DäˆXÔ�tÕr   c                 ó2   • [        XU5        [        X5        g)aÃ  Defines a PyObject proxy for a structref.

This makes `py_class` a valid constructor for creating a instance of
`struct_typeclass` that contains the members as defined by `fields`.

Parameters
----------
py_class : type
    The Python class for constructing an instance of `struct_typeclass`.
struct_typeclass : numba.core.types.Type
    The structref type class to bind to.
fields : Sequence[str]
    A sequence of field names.

Returns
-------
None
N)rŸ   rŒ   )r–   rR   r—   s      r   Údefine_proxyr¡   â   s   € ô& �x°6Ô:ÜÐ"Õ-r   c                 óÄ   • U [         R                  L a  [        S[         R                   35      e[        R                  " U [
        R                  5        [        U 5        U $ )aP  Register a `numba.core.types.StructRef` for use in jit-code.

This defines the data-model for lowering an instance of `struct_type`.
This defines attributes accessor and mutator for an instance of
`struct_type`.

Parameters
----------
struct_type : type
    A subclass of `numba.core.types.StructRef`.

Returns
-------
struct_type : type
    Returns the input argument so this can act like a decorator.

Examples
--------

.. code-block::

    class MyStruct(numba.core.types.StructRef):
        ...  # the simplest subclass can be empty

    numba.experimental.structref.register(MyStruct)

rm   )r   rˆ   r‰   r   Úregisterr   ÚStructRefModelrk   )r   s    r   r£   r£   ù   sL   € ð8 ”e—o‘oÒ%ÜÐ+¬E¯O©OÐ+<Ð=Ó>Ð>Ü×Ò˜[¬&×*?Ñ*?Ô@Ü�kÔ"ØÐr   c                 óN   ^^• SSK Jm  UR                  mUU4S jnT" U5      nX24$ )zùnew(struct_type)

A jit-code only intrinsic. Used to allocate an **empty** mutable struct.
The fields are zero-initialized and must be set manually after calling
the function.

Example:

    instance = new(MyStruct)
    instance.field = field_value
r   )Úimp_dtorc           	      ó(  >• U R                   TR                  5          nUR                  5       nU R                  U5      nU R                  R                  UU R                  [        R                  U5      T
" XR                  T5      5      nU R                  R                  X5      nUR                  X…R                  5       5      nUR                  [        R                  " U5      U5        U R!                  UT5      n	Xyl        U	R%                  5       $ rJ   )r.   r-   r/   Úget_abi_sizeofr+   Úmeminfo_alloc_dtorÚget_constantr   ÚuintpÚmoduler,   r0   r1   Ústorer   Úget_null_valueÚmake_helperr    r‚   )r   r   Ú	signaturer]   r5   r6   Ú
alloc_sizer    Údata_pointerÚinst_structr¦   rc   s             €€r   ÚcodegenÚnew.<locals>.codegen-  sâ   ø€ à×*Ñ*¨9×+BÑ+BÓ+DÑEˆØ×)Ñ)Ó+ˆ
Ø×+Ñ+¨JÓ7ˆ
à—+‘+×0Ñ0ØØ× Ñ ¤§¡¨jÓ9Ù�WŸn™n¨iÓ8ó
ˆð
 —{‘{×/Ñ/°ÓAˆØ—‘ |×5JÑ5JÓ5LÓMˆð 	�‰”g×,Ò,¨ZÓ8¸,ÔGà×)Ñ)¨'°9Ó=ˆØ%Ôà×$Ñ$Ó&Ð&r   )Ú numba.experimental.jitclass.baser¦   Úinstance_type)Ú	typingctxr   r´   rb   r¦   rc   s       @@r   r�   r�     s,   ù€ õ :à×)Ñ)€Iö'ñ, �KÓ
 €CØˆ<Ðr   c                   óP   ^ • \ rS rSrSrSr\U 4S j5       rS r\	S 5       r
SrU =r$ )ÚStructRefProxyiG  z¤A PyObject proxy to the Numba allocated structref data structure.

Notes
-----

* Subclasses should not define ``__init__``.
* Subclasses can override ``__new__``.
)Ú_typer€   c                 ó>   >• [         TU ]  U 5      nXl        X#l        U$ )zïCalled by boxing logic, the conversion of Numba internal
representation into a PyObject.

Parameters
----------
ty :
    a Numba type instance.
mi :
    a wrapped MemInfoPointer.

Returns
-------
instance :
     a StructRefProxy instance.
)ÚsuperÚ__new__r»   r€   )ÚclsÚtyr!   re   Ú	__class__s       €r   rŠ   ÚStructRefProxy._numba_box_R  s#   ø€ ô" ‘7‘? 3Ó'ˆØŒØÔØˆr   c                 ót   ^ •  T R                   nU" U6 $ ! [         a    [        U 4S j5       nUT l          N'f = f)z¬Construct a new instance of the structref.

This takes positional-arguments only due to limitation of the compiler.
The arguments are mapped to ``cls(*args)`` in jit-code.
c                  ó   >• T" U 6 $ rJ   rD   )r]   r¿   s    €r   r�   Ú$StructRefProxy.__new__.<locals>.ctors  s   ø€ á˜D�zÐ!r   )Ú_StructRefProxy__numba_ctorÚAttributeErrorr   )r¿   r]   r�   s   `  r   r¾   ÚStructRefProxy.__new__h  sL   ø€ ð		$à×#Ñ#ˆDñ �Tˆ{Ðøô ó 	$äô"ó ð"ð  $ˆCÖð	$ús   ƒ ” 7¶7c                 ó   • U R                   $ )z^Returns the Numba type instance for this structref instance.

Subclasses should NOT override.
)r»   )r   s    r   Ú_numba_type_ÚStructRefProxy._numba_type_z  s   € ð �z‰zÐr   rD   )r>   r?   r@   rA   rB   Ú	__slots__ÚclassmethodrŠ   r¾   ÚpropertyrÊ   rC   Ú__classcell__)rÁ   s   @r   rº   rº   G  s:   ø† ñð &€Iàôó ðò*ð$ ñó ör   rº   N)rB   Únumbar   Ú
numba.corer   r   r   Únumba.core.datamodelr   r   Únumba.core.extendingr	   r
   r   r   r   r   r   r   Únumba.core.typing.templatesr   r   rk   rŒ   rŸ   r¡   r£   r�   rº   rD   r   r   Ú<module>rÕ      su   ðñõ ß /Ñ /ß 8÷	÷ 	ó 	õ :÷Dñ DòN('òV6 òrò@.ò. ðF ñ'ó ð'÷T9ò 9r   