U
    ,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   >/tmp/pip-unpacked-wheel-eu7e0c37/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   

