U
    ?h                     @   sH   d dl mZ d dlmZmZ d dlmZ edddgZG dd dZd	S )
    )
namedtuple)typesir)	signatureZ	BoundFuncfuncsigc                   @   s   e Zd ZdZdd Zedd Zedd Zedd	 Zed
d Z	i fddZ
d!ejdddZd"ejdddZd#ejdddZejdddZi fejdddZejdddZejdddZd S )$ParforLoweringBuilderz@Helper class for building Numba-IR and lowering for Parfor.
    c                 C   s   || _ || _|| _d S N)_lowerer_scope_loc)selfZlowererscopeloc r   U/var/www/html/venv/lib/python3.8/site-packages/numba/parfors/parfor_lowering_utils.py__init__   s    zParforLoweringBuilder.__init__c                 C   s   | j jS r	   )r
   contextr   r   r   r   _context   s    zParforLoweringBuilder._contextc                 C   s   | j jS r	   )r   Ztyping_contextr   r   r   r   
_typingctx   s    z ParforLoweringBuilder._typingctxc                 C   s
   | j jjS r	   )r
   fndesctypemapr   r   r   r   _typemap   s    zParforLoweringBuilder._typemapc                 C   s
   | j jjS r	   )r
   r   	calltypesr   r   r   r   
_calltypes   s    z ParforLoweringBuilder._calltypesc           
      C   sR   | j }|j d}|j }| j|||}| jtj|||d||d}	t|	|dS )a9  Binds a global function to a variable.

        Parameters
        ----------
        fobj : object
            The function to be bound.
        ftype : types.Type
        args : Sequence[types.Type]
        kws : Mapping[str, types.Type]

        Returns
        -------
        callable: _CallableNode
        Z_funcr   rhstypname)r   r   )r   __name__r   Zresolve_function_typeassignr   Global_CallableNode)
r   ZfobjZftypeargskwsr   varnameZgvnameZfunc_sigZfunc_varr   r   r   bind_global_function"   s      z*ParforLoweringBuilder.bind_global_functionpf_const)returnc                 C   s   | j tj|| jd||dS )a$  Makes a constant variable

        Parameters
        ----------
        cval : object
            The constant value
        typ : types.Type
            type of the value
        name : str
            variable name to store to

        Returns
        -------
        res : ir.Var
        r   r   )r"   r   ZConstr   )r   cvalr   r    r   r   r   make_const_variable;   s
      z)ParforLoweringBuilder.make_const_variablepf_tuplec                    s>    j } fdd|D }tj|} jtj||||dS )a  Makes a tuple variable

        Parameters
        ----------
        varlist : Sequence[ir.Var]
            Variables containing the values to be stored.
        name : str
            variable name to store to

        Returns
        -------
        res : ir.Var
        c                    s   g | ]} j |j qS r   )r   r    ).0xr   r   r   
<listcomp>^   s     z=ParforLoweringBuilder.make_tuple_variable.<locals>.<listcomp>r   )r   r   TupleZ
from_typesr"   r   ExprZbuild_tuple)r   Zvarlistr    r   ZvartysZtuptyr   r   r   make_tuple_variableO   s      z)ParforLoweringBuilder.make_tuple_variable	pf_assignc                 C   s>   | j }| j||}|| j|j< t|||}| j| |S )a!  Assign a value to a new variable

        Parameters
        ----------
        rhs : object
            The value
        typ : types.Type
            type of the value
        name : str
            variable name to store to

        Returns
        -------
        res : ir.Var
        )	r   r   Zredefiner   r    r   Assignr
   
lower_instr   r   r   r    r   varr"   r   r   r   r"   d   s    zParforLoweringBuilder.assignc                 C   sD   | j }t| j||}t|||}| j|j| | j	| |S )a@  Assign a value to a new variable or inplace if it already exist

        Parameters
        ----------
        rhs : object
            The value
        typ : types.Type
            type of the value
        name : str
            variable name to store to

        Returns
        -------
        res : ir.Var
        )
r   r   Varr   r5   r   
setdefaultr    r
   r6   r7   r   r   r   assign_inplace{   s    z$ParforLoweringBuilder.assign_inplacec                 C   s(   t jj|j||| jd}|j| j|< |S )a=  Call a bound callable

        Parameters
        ----------
        callable_node : _CallableNode
            The callee
        args : Sequence[ir.Var]
        kws : Mapping[str, ir.Var]

        Returns
        -------
        res : ir.Expr
            The expression node for the return value of the call
        r   )r   r2   callr   r   r   r   )r   Zcallable_noder%   r&   r<   r   r   r   r<      s    zParforLoweringBuilder.callc                 C   sZ   | j }| j}tj||||d}ttj||j ||j ||j | jj	j
|< | j| |S )a  Makes a setitem call

        Parameters
        ----------
        obj : ir.Var
            the object being indexed
        index : ir.Var
            the index
        val : ir.Var
            the value to be stored

        Returns
        -------
        res : ir.SetItem
        r   )r   r   r   SetItemr   r   noner    r
   r   r   r6   )r   objindexvalr   tmsetitemr   r   r   rC      s       zParforLoweringBuilder.setitemc                 C   s@   | j }tjj||| jd}t|||j ||j | jjj	|< |S )a*  Makes a getitem call

        Parameters
        ----------
        obj : ir.Var
            the object being indexed
        index : ir.Var
            the index
        val : ir.Var
            the ty

        Returns
        -------
        res : ir.Expr
            the retrieved value
        r   )
r   r   r2   getitemr   r   r    r
   r   r   )r   r?   r@   r   rB   rD   r   r   r   rD      s      zParforLoweringBuilder.getitemN)r)   )r-   )r4   )r!   
__module____qualname____doc__r   propertyr   r   r   r   r(   r   r9   r,   r3   r"   r;   r2   r<   r=   rC   rD   r   r   r   r   r   
   s$   



r   N)	collectionsr   Z
numba.corer   r   Znumba.core.typingr   r$   r   r   r   r   r   <module>   s   