๓
\K]c           @` s  d  Z  d d l m Z m Z m Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 m Z d d l m Z m Z m Z m Z m Z d d l m Z d e f d	     YZ d
 e f d     YZ e   Z e j Z e j Z e j Z e j Z e j Z e j Z e j Z d   Z  d   Z! d   Z" d   Z# d   Z$ d   Z% d e f d     YZ& d e f d     YZ' d d  Z) d   Z* d   Z+ d   Z, e j- d d$  Z. e j/ d    Z0 d   Z1 d   Z2 d    Z3 e j/ d! d"   Z4 d#   Z5 d S(%   s<   
Utilities to simplify the boilerplate for native lowering.
i    (   t   print_functiont   absolute_importt   divisionN(   t   Enumi   (   t   typingt   cgutilst   typest   utilst   errors(   t   BaseRegistryLoadert   Registryc           B` s_   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z RS(
   s?   
    A registry of function and attribute implementations.
    c         C` s1   g  |  _  g  |  _ g  |  _ g  |  _ g  |  _ d  S(   N(   t	   functionst   getattrst   setattrst   castst	   constants(   t   self(    (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   __init__   s
    				c         ` s       f d   } | S(   s1  
        Decorate an implementation of *func* for the given argument types.
        *func* may be an actual global function object, or any
        pseudo-function supported by Numba, such as "getitem".

        The decorated implementation has the signature
        (context, builder, sig, args).
        c         ` s    j  j |     f  |  S(   N(   R   t   append(   t   impl(   t   argtyst   funcR   (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   decorate&   s    (    (   R   R   R   R   (    (   R   R   R   s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   lower   s    	c         C` s/   | | | |  } | j  | | | j f  | S(   N(   R   t	   signature(   R   R   t   tyt   attrt	   impl_listt	   decoratort	   real_impl(    (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   _decorate_attr+   s    c         ` s       f d   } | S(   sฯ   
        Decorate an implementation of __getattr__ for type *ty* and
        the attribute *attr*.

        The decorated implementation will have the signature
        (context, builder, typ, val).
        c         ` s    j  |      j t  S(   N(   R   R   t   _decorate_getattr(   R   (   R   R   R   (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyR   8   s    (    (   R   R   R   R   (    (   R   R   R   s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   lower_getattr0   s    c         C` s   |  j  | d  S(   s:  
        Decorate the fallback implementation of __getattr__ for type *ty*.

        The decorated implementation will have the signature
        (context, builder, typ, val, attr).  The implementation is
        called for attributes which haven't been explicitly registered
        with lower_getattr().
        N(   R    t   None(   R   R   (    (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   lower_getattr_generic=   s    	c         ` s       f d   } | S(   sะ   
        Decorate an implementation of __setattr__ for type *ty* and
        the attribute *attr*.

        The decorated implementation will have the signature
        (context, builder, sig, args).
        c         ` s    j  |      j t  S(   N(   R   R   t   _decorate_setattr(   R   (   R   R   R   (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyR   P   s    (    (   R   R   R   R   (    (   R   R   R   s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   lower_setattrH   s    c         C` s   |  j  | d  S(   s;  
        Decorate the fallback implementation of __setattr__ for type *ty*.

        The decorated implementation will have the signature
        (context, builder, sig, args, attr).  The implementation is
        called for attributes which haven't been explicitly registered
        with lower_setattr().
        N(   R$   R!   (   R   R   (    (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   lower_setattr_genericU   s    	c         ` s       f d   } | S(   sึ   
        Decorate the implementation of implicit conversion between
        *fromty* and *toty*.

        The decorated implementation will have the signature
        (context, builder, fromty, toty, val).
        c         ` s     j  j |     f f  |  S(   N(   R   R   (   R   (   t   fromtyR   t   toty(    s5   lib/python2.7/site-packages/numba/targets/imputils.pyR   h   s    (    (   R   R&   R'   R   (    (   R&   R   R'   s5   lib/python2.7/site-packages/numba/targets/imputils.pyt
   lower_cast`   s    c         ` s      f d   } | S(   sธ   
        Decorate the implementation for creating a constant of type *ty*.

        The decorated implementation will have the signature
        (context, builder, ty, pyval).
        c         ` s     j  j |   f f  |  S(   N(   R   R   (   R   (   R   R   (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyR   t   s    (    (   R   R   R   (    (   R   R   s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   lower_constantm   s    (   t   __name__t
   __module__t   __doc__R   R   R   R    R"   R$   R%   R(   R)   (    (    (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyR
      s   								t   RegistryLoaderc           B` s   e  Z d  Z d Z RS(   s6   
    An incremental loader for a target registry.
    R   R   R   R   R   (   R   R   R   R   R   (   R*   R+   R,   t   registry_items(    (    (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyR-   z   s   c         ` sL   |    | d  k	 r$   f d   } n   f d   } | f | _ | | _ | S(   Nc         ` s     |  | | |  S(   N(    (   t   contextt   buildert   typt   valueR   (   R   (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   res   s    c         ` s     |  | | | |  S(   N(    (   R/   R0   R1   R2   R   (   R   (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyR3      s    (   R!   R   R   (   R   R   R   R3   (    (   R   s5   lib/python2.7/site-packages/numba/targets/imputils.pyR      s    	c         ` sR   |    | d  k	 r$   f d   } n   f d   } | t j f | _ | | _ | S(   Nc         ` s     |  | | |  S(   N(    (   R/   R0   t   sigt   argsR   (   R   (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyR3       s    c         ` s     |  | | | |  S(   N(    (   R/   R0   R4   R5   R   (   R   (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyR3   ฃ   s    (   R!   R   t   AnyR   R   (   R   R   R   R3   (    (   R   s5   lib/python2.7/site-packages/numba/targets/imputils.pyR#      s    	c   	      C` sข   t  | j t j  r | j j } |  j | |  } t j | |  } | j | j	 | j
   * |  j | | |  } | j | |  Wd  QX| j |  } n  | S(   N(   t
   isinstancet   return_typeR   t   Optionalt   typet   make_optional_noneR   t   alloca_once_valuet   if_thent   not_t   is_nonet   make_optional_valuet   storet   load(	   R/   R0   R4   t   statust   retvalt
   value_typet   optional_nonet	   retvalptrt   optional_value(    (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   fix_returning_optionalซ   s    c         ` s.     f d   }   j  | _ t |  | _ | S(   sC   
    A wrapper inserting code calling Numba-compiled *fndesc*.
    c         ` s๖   |  j  | j    } |  j j | |   j   j |  \ } } t j | | j   |  j j	 | |  Wd  QX| j
   j k s t  t |  | | | |  } | j |  j | j
  k rเ d } t | j | j | j
    n  t |  |   j |  S(   Ns$   function returned {0} but expect {1}(   t   declare_functiont   modulet	   call_convt   call_functiont   restypet   argtypesR   t   if_unlikelyt   is_errort   return_status_propagateR8   t   AssertionErrorRI   R:   t   get_value_typet	   TypeErrort   formatt   impl_ret_new_ref(   R/   R0   R4   R5   R   RC   RD   t   msg(   t   fndesc(    s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   impพ   s    	!!(   RO   R   t   tuplet   libs(   RY   R\   RZ   (    (   RY   s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   user_functionน   s    c         ` s"     f d   } t  |  | _ | S(   sD   
    A wrapper inserting code calling Numba-compiled *gendesc*.
    c         ` sI   |  j  | j    } |  j j | |   j   j |  \ } } | | f S(   N(   RJ   RK   RL   RM   RN   RO   (   R/   R0   R4   R5   R   RC   RD   (   t   gendesc(    s5   lib/python2.7/site-packages/numba/targets/imputils.pyRZ   ู   s    	!(   R[   R\   (   R^   R\   RZ   (    (   R^   s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   user_generatorิ   s    c         ` s     f d   } | S(   sl   
    Decorator a given class as implementing *iterator_type*
    (by providing an `iternext()` method).
    c         ` sA     j   t t j     f d    } t d   |    S(   Nc         ` s.   | \ }   |  | |  }  | |  | |  S(   N(    (   R/   R0   R4   R5   t   resultR2   t   iterobj(   t   clst   iternext(    s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   iternext_wrapper๏   s    	Rc   (   Rc   t   iternext_implt   RefTypet   BORROWEDt   lower_builtin(   Rb   Rd   (   t   iterator_type(   Rb   Rc   s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   wrapper๋   s    	!(    (   t   iterable_typeRi   Rj   (    (   Ri   s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   iterator_implๅ   s    t   _IternextResultc           B` sM   e  Z d  Z d
 Z d   Z d   Z e d  Z d   Z d   Z	 d	   Z
 RS(   sb   
    A result wrapper for iteration, passed by iternext_impl() into the
    wrapped function.
    t   _contextt   _buildert   _pairobjc         C` s   | |  _  | |  _ | |  _ d  S(   N(   Rn   Ro   Rp   (   R   R/   R0   t   pairobj(    (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyR     s    		c         C` s"   |  j  j t j t  |  j _ d S(   s1   
        Mark the iterator as exhausted.
        N(   Rn   t   get_constantR   t   booleant   FalseRp   t   second(   R   (    (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   set_exhausted  s    c         C` s=   | t  t f k r- |  j j t j |  } n  | |  j _ d S(   s   
        Mark the iterator as valid according to *is_valid* (which must
        be either a Python boolean or a LLVM inst).
        N(   Rt   t   TrueRn   Rr   R   Rs   Rp   Ru   (   R   t   is_valid(    (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyt	   set_valid  s    c         C` s   | |  j  _ d S(   sP   
        Mark the iterator as yielding the given *value* (a LLVM inst).
        N(   Rp   t   first(   R   R2   (    (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   yield_  s    c         C` s"   |  j  j |  j t j |  j j  S(   s>   
        Return whether the iterator is marked valid.
        (   Rn   t   get_argument_valueRo   R   Rs   Rp   Ru   (   R   (    (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyRx     s    c         C` s
   |  j  j S(   s>   
        Return the iterator's yielded value, if any.
        (   Rp   Rz   (   R   (    (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   yielded_value$  s    (   Rn   Ro   Rp   (   R*   R+   R,   t	   __slots__R   Rv   Rw   Ry   R{   Rx   R}   (    (    (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyRm   ๛   s   					Rf   c           B` s    e  Z d  Z d Z d Z d Z RS(   s&   
    Enumerate the reference type
    i   i   i   (   R*   R+   R,   t   NEWRg   t	   UNTRACKED(    (    (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyRf   *  s   c         ` s     d k r t d   n    g  t D] } | ^ q% k ry d } d | } t j t j |  d d   f d   } | S  f d   } | Sd S(	   sต  
    Wrap the given iternext() implementation so that it gets passed
    an _IternextResult() object easing the returning of the iternext()
    result pair.

    ref_type: If the ref_type is a numba.targets.imputils.RefType value then the
    reference type used is that specified through the RefType enum.

    For backwards compatibility Numba will, for a short period of time, maintain
    the old interface which assumes the reference type is borrowed. This is,
    however, deprecated behaviour and users of this API are encouraged to update
    their code.

    The wrapped function will be called with the following signature:
        (context, builder, sig, args, iternext_result)
    s3   ref_type must be an enum member of imputils.RefTypes{   http://numba.pydata.org/numba-doc/latest/reference/deprecation.html#deprecation-of-iternext-impl-without-a-supplied-reftypes{   
The use of iternext_impl without specifying a numba.targets.imputils.RefType is deprecated.

For more information visit %st
   stackleveli   c      	   ` sV   | j  } |  j | |  }   |  | | | t |  | |   t |  | | | j    S(   N(   R8   t   make_helperRm   t   impl_ret_borrowedt	   _getvalue(   R/   R0   R4   R5   t	   pair_typeRq   (   t   ref_type(    s5   lib/python2.7/site-packages/numba/targets/imputils.pyRj   Y  s    		c         ` s      f d   } | S(   Nc      	   ` sช   | j  } |  j | |  }   |  | | | t |  | |    t j k rU t } n<  t j k rm t } n$  t j k r t	 } n t
 d   | |  | | | j    S(   Ns   Unknown ref_type encountered(   R8   R   Rm   Rf   R   RW   Rg   R   R   t   impl_ret_untrackedt
   ValueErrorR   (   R/   R0   R4   R5   R   Rq   t   impl_ret(   R   R   (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyRj   c  s    					(    (   R   Rj   (   R   (   R   s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   outerb  s    N(   R!   R   Rf   t   warningst   warnR   t   NumbaDeprecationWarning(   R   t   xt   urlRX   Rj   R   (    (   R   s5   lib/python2.7/site-packages/numba/targets/imputils.pyRe   ;  s    c         C` s7   t  j | j |  } |  j d |  } | | | f  S(   s   
    Call the `getiter()` implementation for the given *iterable_type*
    of value *val*, and return the corresponding LLVM inst.
    t   getiter(   R   R   Ri   t   get_function(   R/   R0   Rk   t   valt   getiter_sigt   getiter_impl(    (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   call_getiterv  s    c   	      C` sy   | j  } t j | t j  } t j | |  } |  j d |  } | | | f  } |  j | | |  } t |  | |  S(   sฎ   
    Call the `iternext()` implementation for the given *iterator_type*
    of value *val*, and return a convenience _IternextResult() object
    reflecting the results.
    Rc   (	   t
   yield_typeR   t   PairRs   R   R   R   R   Rm   (	   R/   R0   Ri   R   t   itemtyR   t   iternext_sigRe   Rq   (    (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   call_iternext  s    	c         C` sN   y% |  j  t t j t j |   } Wn t k
 r9 d SX| | | f  Sd S(   s^   
    Call len() on the given value.  Return None if len() isn't defined on
    this type.
    N(   R   t   lenR   R   R   t   intpt   NotImplementedErrorR!   (   R/   R0   R   R   t   len_impl(    (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   call_len  s
    %t   _ForIterLoopR2   t   do_breakc   	   
   #` s  | j  } t |   | |  }  j d  }  j d       f d   }  j |   j |  s t |   | |  }  j  j | j    d t	   j    Wd QXt
 | j   |  V j |  Wd QX j    |  j r|  j j  | |  n  d S(   sฦ   
    Simulate a for loop on the given iterable.  Yields a namedtuple with
    the given members:
    - `value` is the value being yielded
    - `do_break` is a callable to early out of the loop
    s   for_iter.bodys   for_iter.endc           ` s    j     d  S(   N(   t   branch(    (   t   bb_endR0   (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyRก   ฎ  s    t   likelyN(   Ri   R   t   append_basic_blockRข   t
   goto_blockR   R=   R>   Rx   Rt   R    R}   t   position_at_endt
   enable_nrtt   nrtt   decref(	   R/   R0   Rk   R   Ri   t   itervalt   bb_bodyRก   R3   (    (   Rฃ   R0   s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   for_iter   s    	%	c         C` s   | S(   s5   
    The implementation returns a new reference.
    (    (   t   ctxR0   t   rettyt   ret(    (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyRW   ฟ  s    c         C` s&   |  j  r" |  j j | | |  n  | S(   s   
    The implementation returns a borrowed reference.
    This function automatically incref so that the implementation is
    returning a new reference.
    (   Rจ   Rฉ   t   incref(   Rฎ   R0   Rฏ   Rฐ   (    (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyR   ฦ  s    	c         C` s   | S(   s.   
    The return type is not a NRT object.
    (    (   Rฎ   R0   Rฏ   Rฐ   (    (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyR   ั  s    t   numpyc         c` sH   d d l  m } |  j } | j | |   |  _ z	 d VWd | |  _ Xd S(   s7   
    Temporarily change the context's error model.
    i   (   t   callconvN(   t    Rณ   t   error_modelt   create_error_model(   R/   t
   model_nameRณ   t   old_error_model(    (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   force_error_modelุ  s    		c          O` s   t  d   d S(   sP   A stub for use internally by Numba when a call is emitted
    on a TypeRef.
    s%   This function should not be executed.N(   R   (   R5   t   kwargs(    (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   numba_typeref_ctor็  s    (   R2   Rก   (6   R,   t
   __future__R    R   R   t   collectionst
   contextlibt   inspectt	   functoolsR   t   enumR   Rด   R   R   R   R   R   t   typing.templatesR	   t   objectR
   R-   t   builtin_registryR   Rh   R    R"   R$   R%   R(   R)   R   R#   RI   R]   R_   Rl   Rm   Rf   R!   Re   R   R   R   t
   namedtupleR    t   contextmanagerRญ   RW   R   R   Rน   Rป   (    (    (    s5   lib/python2.7/site-packages/numba/targets/imputils.pyt   <module>   sP   (h															/;	
							