ó
\K]c           @@ sr   d  d l  m Z m Z d  d l m Z d  d l Z d d l m Z d d l m	 Z	 m
 Z
 d e f d „  ƒ  YZ d S(	   i    (   t   print_functiont   absolute_import(   t
   ModuleTypeNi   (   t   ir(   t   ConstantInferenceErrort
   NumbaErrort   ConstantInferencec           B@ sP   e  Z d  Z d „  Z d d „ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   sì   
    A constant inference engine for a given interpreter.
    Inference inspects the IR to try and compute a compile-time constant for
    a variable.

    This shouldn't be used directly, instead call Interpreter.infer_constant().
    c         C@ s   t  j | ƒ |  _ i  |  _ d  S(   N(   t   weakreft   proxyt   _func_irt   _cache(   t   selft   func_ir(    (    s+   lib/python2.7/site-packages/numba/consts.pyt   __init__   s    c         C@ sÄ   | |  j  k rg y  t |  j | ƒ f |  j  | <Wqg t k
 rc } t | j | j f f |  j  | <qg Xn  |  j  | \ } } | r„ | S| \ } } t | t ƒ r´ | d | | Œ ‚ n | | Œ  ‚ d S(   s£   
        Infer a constant value for the given variable *name*.
        If no value can be inferred, numba.errors.ConstantInferenceError
        is raised.
        t   locN(	   R
   t   Truet	   _do_inferR   t   Falset	   __class__t   argst
   issubclassR   (   R   t   nameR   t   exct   successt   valR   (    (    s+   lib/python2.7/site-packages/numba/consts.pyt   infer_constant   s     &c         C@ s   t  d | f d d  ƒ‚ d  S(   Ns'   Constant inference not possible for: %sR   (   R   t   None(   R   R   (    (    s+   lib/python2.7/site-packages/numba/consts.pyt   _fail1   s    c         C@ s¶   t  | t ƒ s% t d | f ƒ ‚ n  y |  j j | ƒ } Wn$ t k
 ra t d | f ƒ ‚ n Xy | j ƒ  } Wn= t k
 r± t  | t j	 ƒ r¡ |  j
 | ƒ S|  j | ƒ n X| S(   Ns'   infer_constant() called with non-str %rs   no single definition for %r(   t
   isinstancet   strt	   TypeErrorR	   t   get_definitiont   KeyErrorR   R   R   t   Exprt   _infer_exprR   (   R   R   t   defnt   const(    (    s+   lib/python2.7/site-packages/numba/consts.pyR   :   s    c         @ sø   ˆ  j  d k r= ˆ j ˆ  j j d ˆ  j ƒ} ˆ j | ˆ  ƒ Sˆ  j  d k rz ˆ j ˆ  j j d ˆ  j ƒ} ˆ j | ˆ  ƒ Sˆ  j  d k r¸ g  ˆ  j D]! } ˆ j | j d ˆ  j ƒ^ q“ Sˆ  j  d k rç t	 ‡  ‡ f d †  ˆ  j Dƒ ƒ Sˆ j
 ˆ  ƒ d  S(   Nt   callR   t   getattrt
   build_listt   build_tuplec         3@ s*   |  ]  } ˆ j  | j d  ˆ  j ƒVq d S(   R   N(   R   R   R   (   t   .0t   i(   t   exprR   (    s+   lib/python2.7/site-packages/numba/consts.pys	   <genexpr>W   s    (   t   opR   t   funcR   R   t   _infer_callt   valuet   _infer_getattrt   itemst   tupleR   (   R   R+   R-   R/   R*   (    (   R+   R   s+   lib/python2.7/site-packages/numba/consts.pyR"   K   s    ,c         C@ sÒ   | j  s | j r" |  j | ƒ n  | t f k } t | t ƒ oL t | t ƒ } | s[ | rÁ g  | j D]! } |  j	 | j
 d | j ƒ^ qe } | rœ | | Œ  S| r¬ | | f Sd sÁ t d ƒ ‚ n  |  j | ƒ d  S(   NR   i    t   Unreachable(   t   kwst   varargR   t   sliceR   t   typeR   t   BaseExceptionR   R   R   R   t   AssertionError(   R   R-   R+   t   _slicet   _exct   aR   (    (    s+   lib/python2.7/site-packages/numba/consts.pyR.   [   s    .

c         C@ s6   t  | t t f ƒ r% t | | j ƒ S|  j | ƒ d  S(   N(   R   R   R7   R&   t   attrR   (   R   R/   R+   (    (    s+   lib/python2.7/site-packages/numba/consts.pyR0   q   s    N(   t   __name__t
   __module__t   __doc__R   R   R   R   R   R"   R.   R0   (    (    (    s+   lib/python2.7/site-packages/numba/consts.pyR      s   						(   t
   __future__R    R   t   typesR   R   t    R   t   errorsR   R   t   objectR   (    (    (    s+   lib/python2.7/site-packages/numba/consts.pyt   <module>   s
   