ó
\K]c           @   sh   d  d l  m Z m Z d d l m Z m Z d e f d     YZ e d  d e f d     Y Z d	 S(
   iÿÿÿÿ(   t   irt   errorsi   (   t   register_rewritet   Rewritet   Macroc           B   s,   e  Z d  Z d Z e d d  Z d   Z RS(	   sr  
    A macro object is expanded to a function call

    Args
    ----
    name: str
        Name of this Macro
    func: function
        Function that evaluates the macro expansion.
    callable: bool
        True if the macro is callable from Python code
        (``func`` is then a Python callable returning the desired IR node).
        False if the macro is not callable
        (``func`` is then the name of a backend-specific function name
         specifying the function to call at runtime).
    argnames: list
        If ``callable`` is True, this holds a list of the names of arguments
        to the function.
    t   namet   funct   callablet   argnamesc         C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   R   R   R   R   (   t   selfR   R   R   R   (    (    s4   lib/python2.7/site-packages/numba/rewrites/macros.pyt   __init__   s    			c         C   s   d |  j  |  j f S(   Ns   <macro %s -> %s>(   R   R   (   R	   (    (    s4   lib/python2.7/site-packages/numba/rewrites/macros.pyt   __repr__"   s    (   R   R   R   R   N(   t   __name__t
   __module__t   __doc__t	   __slots__t   Falset   NoneR
   R   (    (    (    s4   lib/python2.7/site-packages/numba/rewrites/macros.pyR      s   s   before-inferencet   ExpandMacrosc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s4   
    Expand lookups and calls of Macro objects.
    c   
      C   s  | |  _  i  |  _ } xm| j D]b} t | t j  r  | j } t | t j  rð | j d k rð t | j	 t j
  rð y | j | j	  } Wn t j k
 rŠ q  n Xt | t  r| j sÅ t  |  j | | | | j  }	 |	 | | <qqt | t j  r| j d k ry | j | j  } Wn t j k
 r@q  n Xt | t  r| j r|  j | | j  }	 |	 | | <qqq  q  Wt |  d k S(   sR   
        Look for potential macros for expand and store their expansions.
        t   callt   getattri    (   t   blockt   rewritest   bodyt
   isinstanceR    t   Assignt   valuet   Exprt   opR   t   Vart   infer_constantR   t   ConstantInferenceErrorR   R   t   AssertionErrort   _expand_callable_macrot   loct   targett   _expand_non_callable_macrot   len(
   R	   t   func_irR   t   typemapt	   calltypesR   t   instt   rhst   constt   new_expr(    (    s4   lib/python2.7/site-packages/numba/rewrites/macros.pyt   match,   s2    		!!c      	   C   sI   t  j | j | j d d } t  j j d | d d d d d |  } | S(   sO   
        Return the IR expression of expanding the non-callable macro.
        t   argsR   t   kwsR"   (    (    (    (   R    t	   IntrinsicR   R   R   R   (   R	   t   macroR"   t   intrR,   (    (    s4   lib/python2.7/site-packages/numba/rewrites/macros.pyR$   O   s    c      	   C   si  | j  s t  g  | j D] } | j | j  ^ q } i  } xi | j D]^ \ } }	 y | j |	  | | <WqG t j k
 r€ d j d | d |  }
 t	 |
   qG XqG Wy | j
 | |   } WnX t k
 r} t |  }
 d } | j d |  } d j | |
  } t j |   n X| d
 k	 s,t  | j | _ t j j d | d | j d	 | j d |  } | S(   sG   
        Return the IR expression of expanding the macro call.
        s-   Argument {name!r} must be a constant at {loc}R   R"   s    Macro expansion failed at {line}t   lines   {0}:
{1}R   R.   R/   N(   R   R    R.   R   R   R/   R   R   t   formatt
   ValueErrorR   t	   Exceptiont   strt
   MacroErrorR   R"   R    R   R   (   R	   R&   R   R1   R"   t   argR.   R/   t   kt   vt   msgt   resultt   et   headfmtt   headt   newmsgR,   (    (    s4   lib/python2.7/site-packages/numba/rewrites/macros.pyR!   X   s0    (		c         C   s^   |  j  } |  j } xE | j D]: } t | t j  r | j | k r | | j | _ q q W| S(   s<   
        Apply the expansions computed in .match().
        (   R   R   R   R   R    R   R   (   R	   R   R   R)   (    (    s4   lib/python2.7/site-packages/numba/rewrites/macros.pyt   applyz   s    		!(   R   R   R   R-   R$   R!   RB   (    (    (    s4   lib/python2.7/site-packages/numba/rewrites/macros.pyR   &   s
   	#			"N(	   t   numbaR    R   t    R   R   t   objectR   R   (    (    (    s4   lib/python2.7/site-packages/numba/rewrites/macros.pyt   <module>   s   !