o
    TdC                     @   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)inbounds)r   typestoregepload)	contextbuilder	signatureargstupidxvalstackoffptr r   m/home/ncw/WWW/www-new/content/articles/pi-bbp/venv/lib/python3.10/site-packages/numba/cpython/unsafe/tuple.pycodegen   s   

ztuple_setitem.<locals>.codegen)dtype)	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                    sZ   dd }t jg}tjg|R  }| 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   intpr   r   get_value_typeget_constant_undefcompile_internal)r   r   r   r   r#   inner_argtypes	inner_sigll_idx_typer    
inner_argsressize
tuple_typer   r   r   .   s   

z'build_full_slice_tuple.<locals>.codegen)	
isinstancer   IntegerLiteralr   RequireLiteralValueintliteral_valueUniTupleslice2_type)tyctxszr   r   r   r-   r   build_full_slice_tuple$   s   

r9   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)r0   r   	BaseTupler   UnsupportedError)r7   r   msgr   r   r   r   r   unpack_single_tupleB   s   	
r=   N)__doc__
numba.corer   r   r   numba.core.cgutilsr   numba.core.extendingr   r   r9   r=   r   r   r   r   <module>   s    

