Ë
    üÇ:j+/  ã                   ó6  — d Z ddlZddlmZ ddlmZ ddlmZmZm	Z	 ddl
mZmZ ddlmZmZmZmZmZmZmZmZmZ ddlmZ  G d	„ d
«      Zd„ Zd„ Zd„ Zd„ Zd„ Zed„ «       Z G d„ d«      Z  eejB                  ejD                  ejD                  «      d„ «       Z#y)z€Utilities for defining a mutable struct.

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

é    N)Úcreate_struct_proxy)Únjit)ÚtypesÚimputilsÚcgutils)Údefault_managerÚmodels)	Úinfer_getattrÚlower_getattr_genericÚlower_setattr_genericÚlower_builtinÚboxÚunboxÚNativeValueÚ	intrinsicÚoverload)ÚAttributeTemplatec                   ó.   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zy)Ú_Utilsz;Internal builder-code utils for structref definitions.
    c                 ó.   — || _         || _        || _        y)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       úq/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/numba/experimental/structref.pyÚ__init__z_Utils.__init__   s   € ð ˆŒØˆŒØ&ˆÕó    c                 ó”   — | j                   }| j                  }| j                  } t        j                  |«      ||«      }||_        |S )zKEncapsulate the MemInfo from a `StructRefPayload` in a `StructRef`
        )r   r   r   r   r   Úmeminfo)r   Úmir   r   r   Ústs         r   Únew_struct_refz_Utils.new_struct_ref+   sF   € ð —,‘,ˆØ—,‘,ˆØ×&Ñ&ˆà5ŒW×(Ñ(¨Ó5°g¸wÓGˆØˆŒ
Øˆ	r   c                 ó†   — | j                   }| j                  }| j                  } t        j                  |«      |||¬«      S )z6Return a helper for accessing a StructRefType
        ©Úvalue)r   r   r   r   r   )r   Úvalr   r   r   s        r   Úget_struct_refz_Utils.get_struct_ref6   sB   € ð —,‘,ˆØ—,‘,ˆØ×&Ñ&ˆà7Œw×*Ñ*¨;Ó7Ø�W Cô
ð 	
r   c                 ó^  — | j                   }| j                  }| j                  }| j                  |«      }|j                  }|j
                  j                  ||«      }|j                  «       }|j                  |   }	|	j                  «       }
|j                  ||
j                  «       «      }|S )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_pointerz_Utils.get_data_pointerA   sœ   € ð —,‘,ˆØ—,‘,ˆØ×&Ñ&ˆà×'Ñ'¨Ó,ˆ	Ø×#Ñ#ˆØ—;‘;×+Ñ+¨G°WÓ=ˆà×+Ñ+Ó-ˆØ×*Ñ*¨7Ñ3ˆØ×)Ñ)Ó+ˆ
Ø—?‘? 8¨Z×-BÑ-BÓ-DÓEˆØˆr   c                 óÌ   — | j                   }| j                  }| j                  }| j                  |«      }|j	                  «       } t        j                  |«      |||¬«      }|S )zFGet a getter/setter helper for accessing a `StructRefPayload`
        )Úref)r   r   r   r5   r+   r   r   )r   r&   r   r   r   r1   r2   Údatavals           r   Úget_data_structz_Utils.get_data_structR   sd   € ð —,‘,ˆØ—,‘,ˆØ×&Ñ&ˆà×(Ñ(¨Ó-ˆØ×+Ñ+Ó-ˆØ6”'×-Ñ-¨gÓ6Ø�W (ô
ˆð ˆr   N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r"   r'   r5   r9   © r   r   r   r      s    „ ñò'ò	ò	
òó"r   r   c                 ó~   ‡ — t          G ˆ fd„dt        «      «       }t        ‰ «      d„ «       }t        ‰ «      d„ «       }y)zŽDefine attributes on `struct_typeclass`.

    Defines both setters and getters in jit-code.

    This is called directly in `register()`.
    c                   ó   •— e Zd ZW ° Zd„ Zy)ú*define_attributes.<locals>.StructAttributec                 óB   — ||j                   v r|j                   |   }|S y ©N)Ú
field_dict)r   ÚtypÚattrÚattrtys       r   Úgeneric_resolvez:define_attributes.<locals>.StructAttribute.generic_resolvel   s&   € Ø�s—~‘~Ñ%ØŸ™¨Ñ-�Ø�ð &r   N)r:   r;   r<   ÚkeyrH   )Ústruct_typeclasss   €r   ÚStructAttributerA   h   s   ø„ áˆó	r   rK   c                 ó¤   — t        | ||«      }|j                  |«      }t        ||«      }|j                  |   }t	        j
                  | |||«      S rC   )r   r9   ÚgetattrrD   r   Úimpl_ret_borrowed)	r   r   rE   r&   rF   Úutilsr8   ÚretÚ	fieldtypes	            r   Ústruct_getattr_implz.define_attributes.<locals>.struct_getattr_implq   sQ   € ä�w ¨Ó-ˆØ×'Ñ'¨Ó,ˆÜ�g˜tÓ$ˆØ—N‘N 4Ñ(ˆ	Ü×)Ñ)¨'°7¸IÀsÓKÐKr   c                 óT  — |j                   \  }}|\  }}t        | ||«      }	|	j                  |«      }
|j                  |   }| j	                  ||||«      }t        |
|«      }| j                  j                  |||«       | j                  j                  |||«       t        |
||«       y rC   )
Úargsr   r9   rD   ÚcastrM   r)   ÚincrefÚdecrefÚsetattr)r   r   ÚsigrT   rF   Ú	inst_typeÚval_typeÚinstancer&   rO   r8   Ú
field_typeÚcastedÚ	old_values                 r   Ústruct_setattr_implz.define_attributes.<locals>.struct_setattr_imply   sŸ   € à #§¡Ñˆ�HØ‰ˆ�3Ü�w ¨Ó3ˆØ×'Ñ'¨Ó1ˆà×)Ñ)¨$Ñ/ˆ
Ø—‘˜g s¨H°jÓAˆä˜G TÓ*ˆ	à�‰×Ñ˜7 H¨fÔ5à�‰×Ñ˜7 H¨iÔ8ä�˜˜vÕ&r   N)r
   r   r   r   )rJ   rK   rR   r`   s   `   r   Údefine_attributesra   a   sU   ø€ ô öÔ+ó ó ðô Ð+Ó,ñLó -ðLô Ð+Ó,ñ'ó -ñ'r   c                 óÂ   ‡— | t         j                  u rt        dt         j                  › �«      ‚|j                  Št	        | «      ˆfd„«       }t        | «      d„ «       }y)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                 óœ  •— t        |j                  |j                  | «      }|j                  |«      }|j                  }t        j                  t
        j                  «      }|j                  ||«      }|j                  j                  |j                  j                  ‰«      «      }|j                  j                  |j                  j                  | «      «      }	|j                  j                  ||	|g«      }
|j                  j                  |«       |j                  j                  |	«       |j                  j                  |«       |
S )z8
        Convert a raw pointer to a Python int.
        )r   r   r   r'   r   r   ÚMemInfoPointerÚvoidptrr   ÚpyapiÚunserializeÚserialize_objectÚcall_function_objargsrW   )rE   r&   ÚcrO   Ú
struct_refr   Úmip_typeÚboxed_meminfoÚctor_pyfuncÚty_pyobjÚresÚobj_ctors              €r   Úbox_struct_refz%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                 óˆ  — |j                   j                  |d«      }t        j                  t        j                  «      }|j                  ||«      j                  }t        |j                  |j                  | «      }|j                  |«      }|j                  «       }|j                   j                  |«       t        |«      S )NÚ_meminfo)rg   Úobject_getattr_stringr   re   rf   r   r%   r   r   r   r"   Ú	_getvaluerW   r   )	rE   Úobjrk   Úmi_objrm   r    rO   rl   Úouts	            r   Úunbox_struct_refz'define_boxing.<locals>.unbox_struct_refµ   s‘   € à—‘×.Ñ.¨s°JÓ?ˆä×'Ñ'¬¯©Ó6ˆà�W‰W�X˜vÓ&×,Ñ,ˆä�q—y‘y !§)¡)¨SÓ1ˆØ×)Ñ)¨"Ó-ˆ
Ø×"Ñ"Ó$ˆà	�‰�‰�vÔÜ˜3ÓÐr   N)r   Ú	StructRefÚ
ValueErrorÚ_numba_box_r   r   )r   Ú	obj_classrs   r{   rr   s       @r   Údefine_boxingr€   Œ   sd   ø€ ð ”e—o‘oÑ%ÜÐ+¬E¯O©OÐ+<Ð=Ó>Ð>à×$Ñ$€HäˆÓóó ðô, ˆ;Óñ ó ñ r   c                 ó.  — dj                  |«      }d}g }|D ]  }|j                  d|› d|› �«       Œ d|› �j                  |«      }d|› dt        |«      › d|› d	|› d
|› d�}t        |t        ¬«      }	t        ||	«       |	d   }
 t        | «      |
«       y)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
)rJ   ÚnewÚctorN)ÚjoinÚappendÚlistÚdictrƒ   Úexecr   )Úpy_classrJ   ÚfieldsÚparamsÚindentÚinit_fields_bufÚkÚinit_fieldsÚsourceÚglbsr„   s              r   Údefine_constructorr“   Å   sË   € ð �Y‰Y�vÓ€FØ€FØ€OØò 0ˆØ×Ñ  Q C s¨1¨#˜Õ/ð0à�v�h�-×$Ñ$ _Ó5€Kð
Ø
ˆð -Ü-1°&«\¨N¸#¸f¸Xð FØˆXð 	à	ˆð ð€Fô Ð!1´sÔ;€DÜˆ�ÔØ�‰<€Dà„HˆXÓ�tÕr   c                 ó6   — t        | ||«       t        || «       y)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Š   rJ   r‹   s      r   Údefine_proxyr•   å   s   € ô& �xÐ!1°6Ô:ÜÐ" HÕ-r   c                 óÀ   — | t         j                  u rt        dt         j                  › �«      ‚t        j                  | t
        j                  «       t        | «       | S )a˜  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)

    rc   )r   r|   r}   r   Úregisterr	   ÚStructRefModelra   )r   s    r   r—   r—   ü   sL   € ð8 ”e—o‘oÑ%ÜÐ+¬E¯O©OÐ+<Ð=Ó>Ð>Ü×Ñ˜[¬&×*?Ñ*?Ô@Ü�kÔ"ØÐr   c                 óN   ‡‡— ddl mŠ |j                  Šˆˆfd„} ‰|«      }||fS )a  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           	      ó.  •— | j                   ‰j                  «          }|j                  «       }| j                  |«      }| j                  j                  || j                  t        j                  |«       ‰
| |j                  ‰«      «      }| j                  j                  ||«      }|j                  ||j                  «       «      }|j                  t        j                  |«      |«       | j!                  |‰«      }	||	_        |	j%                  «       S rC   )r,   r+   r-   Úget_abi_sizeofr)   Úmeminfo_alloc_dtorÚget_constantr   ÚuintpÚmoduler*   r.   r/   Ústorer   Úget_null_valueÚmake_helperr   rw   )r   r   Ú	signaturerT   r3   r4   Ú
alloc_sizer   Údata_pointerÚinst_structrš   rZ   s             €€r   Úcodegenznew.<locals>.codegen0  sê   ø€ à×*Ñ*¨9×+BÑ+BÓ+DÑEˆØ×)Ñ)Ó+ˆ
Ø×+Ñ+¨JÓ7ˆ
à—+‘+×0Ñ0ØØ× Ñ ¤§¡¨jÓ9Ù�W˜gŸn™n¨iÓ8ó
ˆð
 —{‘{×/Ñ/°¸ÓAˆØ—‘ |°Z×5JÑ5JÓ5LÓMˆð 	�‰”g×,Ñ,¨ZÓ8¸,ÔGà×)Ñ)¨'°9Ó=ˆØ%ˆÔà×$Ñ$Ó&Ð&r   )Ú numba.experimental.jitclass.baserš   Úinstance_type)Ú	typingctxr   r¨   rY   rš   rZ   s       @@r   rƒ   rƒ     s.   ù€ õ :à×)Ñ)€Iõ'ñ, �KÓ
 €CØ�ˆ<Ðr   c                   óF   ‡ — e Zd ZdZdZeˆ fd„«       Zd„ Zed„ «       Z	ˆ xZ
S )ÚStructRefProxyz¸A PyObject proxy to the Numba allocated structref data structure.

    Notes
    -----

    * Subclasses should not define ``__init__``.
    * Subclasses can override ``__new__``.
    )Ú_typeru   c                 óB   •— t         ‰| �  | «      }||_        ||_        |S )aO  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®   ru   )ÚclsÚtyr    r\   Ú	__class__s       €r   r~   zStructRefProxy._numba_box_U  s'   ø€ ô" ‘7‘? 3Ó'ˆØˆŒØˆÔØˆr   c                 óp   ‡ — 	 ‰ j                   } ||Ž S # t        $ r t        ˆ fd„«       }|‰ _         Y Œ%w xY w)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                  ó   •—  ‰| Ž S rC   r>   )rT   r²   s    €r   r„   z$StructRefProxy.__new__.<locals>.ctorv  s   ø€ á˜D�zÐ!r   )Ú_StructRefProxy__numba_ctorÚAttributeErrorr   )r²   rT   r„   s   `  r   r±   zStructRefProxy.__new__k  sL   ø€ ð		$à×#Ñ#ˆDñ �Tˆ{Ðøô ò 	$äó"ó ð"ð  $ˆCÖð	$ús   ƒ ”5´5c                 ó   — | j                   S )znReturns the Numba type instance for this structref instance.

        Subclasses should NOT override.
        )r®   )r   s    r   Ú_numba_type_zStructRefProxy._numba_type_}  s   € ð �z‰zÐr   )r:   r;   r<   r=   Ú	__slots__Úclassmethodr~   r±   Úpropertyrº   Ú__classcell__)r´   s   @r   r­   r­   J  s:   ø„ ñð &€Iàóó ðò*ð$ ñó ôr   r­   c                 óÈ   — |\  }}|j                   \  }} t        |«      | ||¬«      j                  } t        |«      | ||¬«      j                  }	|j                  d||	«      S )zŠ
    Define the 'is' operator for structrefs by comparing the memory addresses.
    This is the identity check for structref objects.
    r$   z==)rT   r   r   Úicmp_unsigned)
r   r   rY   rT   ÚaÚbÚatyÚbtyÚa_ptrÚb_ptrs
             r   Ústructref_isrÇ   †  sg   € ð �D€A€qØ�x‰x�H€CˆØ$Ô Ó$ W¨g¸QÔ?×GÑG€EØ$Ô Ó$ W¨g¸QÔ?×GÑG€EØ× Ñ   u¨eÓ4Ð4r   )$r=   ÚoperatorÚnumba.core.cgutilsr   Únumbar   Ú
numba.corer   r   r   Únumba.core.datamodelr   r	   Únumba.core.extendingr
   r   r   r   r   r   r   r   r   Únumba.core.typing.templatesr   r   ra   r€   r“   r•   r—   rƒ   r­   Úis_r|   rÇ   r>   r   r   ú<module>rÐ      s¥   ðñó Ý 2Ý ß /Ñ /ß 8÷
÷ 
õ 
õ :÷Dñ DòN('òV6 òrò@.ò. ðF ñ'ó ð'÷T9ñ 9ñx ˆx�|‰|˜UŸ_™_¨e¯o©oÓ>ñ	5ó ?ñ	5r   