U
    hâËdC  ã                   @   sX   d Z ddlmZmZmZ ddlmZ ddlmZ edd„ ƒZ	edd„ ƒZ
ed	d
„ ƒZdS )z™
This file provides internal compiler utilities that support certain special
operations with tuple and workarounds for limitations enforced in userland.
é    )ÚtypesÚtypingÚerrors)Úalloca_once)Ú	intrinsicc                 C   s   dd„ }||||j ƒ}||fS )a  Return a copy of the tuple with item at *idx* replaced with *val*.

    Operation: ``out = tup[:idx] + (val,) + tup[idx + 1:]

    **Warning**

    - No boundchecking.
    - The dtype of the tuple cannot be changed.
      *val* is always cast to the existing dtype of the tuple.
    c           	      S   sR   |\}}}t ||jƒ}| ||¡ |j|| d¡|gdd�}| ||¡ | |¡S )Nr   T)Zinbounds)r   ÚtypeÚstoreZgepÚload)	ÚcontextÚbuilderÚ	signatureÚargsÚtupÚidxÚvalÚstackZoffptr© r   úS/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/numba/cpython/unsafe/tuple.pyÚcodegen   s    
ztuple_setitem.<locals>.codegen)Údtype)Z	typingctxr   r   r   r   Úsigr   r   r   Útuple_setitem   s    	r   c                    sN   t |tjƒst |¡‚t|jƒ‰ tjtjˆ d�‰ˆ|ƒ}‡ ‡fdd„}||fS )z"Creates a sz-tuple of full slices.)r   Úcountc                    sX   dd„ }t jˆg}tjˆf|žŽ }|  t j¡}|  ˆ¡}|ˆ ƒ|g}	|  ||||	¡}
|
S )Nc                 S   s(   |}t | ƒD ]}t||td d ƒƒ}q|S )N)Úranger   Úslice)ÚlengthÚempty_tupleÚoutÚir   r   r   Úimpl/   s    z5build_full_slice_tuple.<locals>.codegen.<locals>.impl)r   Zintpr   r   Zget_value_typeZget_constant_undefZcompile_internal)r
   r   r   r   r   Zinner_argtypesZ	inner_sigZll_idx_typer   Z
inner_argsÚres©ÚsizeZ
tuple_typer   r   r   .   s    

z'build_full_slice_tuple.<locals>.codegen)	Ú
isinstancer   ZIntegerLiteralr   ZRequireLiteralValueÚintZliteral_valueZUniTupleZslice2_type)ÚtyctxÚszr   r   r   r!   r   Úbuild_full_slice_tuple$   s    

r'   c                 C   s8   t |tjƒs d|› �}t |¡‚||ƒ}dd„ }||fS )aR  This exists to handle the situation y = (*x,), the interpreter injects a
    call to it in the case of a single value unpack. It's not possible at
    interpreting time to differentiate between an unpack on a variable sized
    container e.g. list and a fixed one, e.g. tuple. This function handles the
    situation should it arise.
    zBOnly tuples are supported when unpacking a single item, got type: c                 S   s   |d S )Nr   r   )r
   r   r   r   r   r   r   r   R   s    z$unpack_single_tuple.<locals>.codegen)r#   r   Z	BaseTupler   ZUnsupportedError)r%   r   Úmsgr   r   r   r   r   Úunpack_single_tupleB   s    	

r)   N)Ú__doc__Z
numba.corer   r   r   Znumba.core.cgutilsr   Znumba.core.extendingr   r   r'   r)   r   r   r   r   Ú<module>   s   

