ó
\K]c           @` s'  d  Z  d d l m Z m Z m Z d d l m Z m Z d d l j j	 Z
 d d l Z d d l m Z m Z m Z m Z m Z d d l m Z d d l m Z d d	 l m Z m Z m Z e e g ƒ Z i d
 e f e j 6d e f e j 6d e f e j 6d e f e j  6d e f e j! 6d e f e j" 6d e f e j# 6d e f e j$ 6d e f e j% 6d e f e j& 6d e f e j' 6d e f e j( 6d
 e) f e j* 6d e) f e j+ 6d e) f e j, 6d e) f e j- 6d e) f e j. 6d e) f e j/ 6d e) f e j0 6d e) f e j1 6d e) f e j2 6d e) f e j3 6d e) f e j4 6d e) f e j5 6Z6 e s~d e f e6 e j7 <d e) f e6 e j8 <n  e r­d e f e6 e j9 <d e) f e6 e j: <n  i	 d e j; 6d e j< 6d e j= 6d e j> 6d e j? 6d e j@ 6d e jA 6d e jB 6d  e jC 6ZD d! e f d" „  ƒ  YZE d S(#   s*   
Lowering implementation for object mode.
i    (   t   print_functiont   divisiont   absolute_import(   t   Typet   ConstantNi   (   t   cgutilst
   generatorst   irt   typest   utils(   t   ForbiddenConstruct(   t	   BaseLower(   t   builtinst   HAS_MATMUL_OPERATORt   IS_PY3t
   number_addt   number_subtractt   number_multiplyt   number_truedividet   number_floordividet   number_remaindert   number_powert   number_lshiftt   number_rshiftt
   number_andt	   number_ort
   number_xort   number_dividet   number_matrix_multiplys   ==s   !=t   <s   <=t   >s   >=t   iss   is nott   int   PyLowerc           B` s%  e  Z e j Z d  „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z e d „ Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z d d „ Z d „  Z d „  Z e d „ Z d „  Z d d „ Z  d „  Z! d „  Z" d „  Z# RS(   c         C` s   t  ƒ  |  _ t  ƒ  |  _ d  S(   N(   t   sett   _frozen_stringst
   _live_vars(   t   self(    (    s/   lib/python2.7/site-packages/numba/pylowering.pyt   initJ   s    c         C` sR   t  t |  ƒ j ƒ  |  j ƒ  d d l m } |  j j |  j j | ƒ ƒ |  _	 d  S(   Ni   (   t
   OmittedArg(
   t   superR!   t	   pre_lowert
   init_pyapit
   dispatcherR'   t   pyapit   unserializet   serialize_objectt   omitted_typobj(   R%   R'   (    (    s/   lib/python2.7/site-packages/numba/pylowering.pyR)   P   s
    
	c         C` s   d  S(   N(    (   R%   (    (    s/   lib/python2.7/site-packages/numba/pylowering.pyt
   post_lowerX   s    c         C` s   |  j  | ƒ d  S(   N(   t	   init_vars(   R%   t   block(    (    s/   lib/python2.7/site-packages/numba/pylowering.pyt	   pre_block[   s    c         C` sa  t  | t j ƒ r: |  j | ƒ } |  j | | j j ƒ n#t  | t j ƒ r³ |  j | j j ƒ } |  j | j	 j ƒ } |  j | j
 j ƒ } |  j j | | | ƒ } |  j | ƒ nªt  | t j ƒ r|  j | j j ƒ } |  j | j	 j ƒ } |  j j | | ƒ } |  j | ƒ nIt  | t j ƒ r„|  j | j j ƒ } |  j | j
 j ƒ } |  j j | |  j | j ƒ | ƒ } |  j | ƒ nÙt  | t j ƒ rÜ|  j | j j ƒ } |  j j | |  j | j ƒ ƒ } |  j | ƒ nt  | t j ƒ rU|  j | j j ƒ } |  j | j j ƒ } |  j | j
 j ƒ } |  j j | | | ƒ } |  j | ƒ nt  | t j ƒ rÂ|  j | j
 j ƒ } |  j r©|  j j | ƒ |  j j |  ƒ d  S|  j j  |  j! | ƒ n›t  | t j" ƒ r…|  j | j# j ƒ }	 |	 j$ t% j& d ƒ k r
|	 }
 n |  j j' |	 ƒ }
 t( j) j* |
 j$ ƒ } |  j! j+ t( j, |
 | ƒ } |  j- | j. } |  j- | j/ } |  j! j0 | | | ƒ nØ t  | t j1 ƒ rº|  j- | j } |  j! j2 | ƒ n£ t  | t j3 ƒ rß|  j4 | j
 ƒ n~ t  | t j5 ƒ rH| j6 d  k	 r%|  j | j6 j ƒ } |  j8 | ƒ n d  } |  j j9 | ƒ |  j: ƒ  n t; t$ | ƒ | ƒ ‚ d  S(   Ni   (<   t
   isinstanceR   t   Assignt   lower_assignt   storevart   targett   namet   SetItemt   loadvart   indext   valueR,   t   object_setitemt   check_int_statust   DelItemt   object_delitemt   SetAttrt   object_setattrt   _freeze_stringt   attrt   DelAttrt   object_delattrt   StoreMapt   dctt   keyt   dict_setitemt   Returnt   generator_infot   decreft   genlowert   return_from_generatort	   call_convt   return_valuet   buildert   Brancht   condt   typeR   t   intt   object_istruet   lcR   t   nullt   icmpt   ICMP_NEt   blkmapt   truebrt   falsebrt   cbrancht   Jumpt   brancht   Delt   delvart   Raiset	   exceptiont   Nonet   increft   raise_objectt   return_exception_raisedt   NotImplementedError(   R%   t   instR=   R8   R<   t   okRI   RJ   t   retvalRU   t   istruet   zerot   predt   trt   flt   exc(    (    s/   lib/python2.7/site-packages/numba/pylowering.pyt
   lower_inst^   s|    			c   
      C` så  | j  } t | t j t j f ƒ r4 |  j | j  ƒ St | t j ƒ ri |  j | j ƒ } |  j	 | ƒ | St | t j
 ƒ rˆ |  j | ƒ St | t j ƒ r° |  j | j | j  ƒ St | t j ƒ rÏ |  j | ƒ St | t j ƒ rÌ|  j | j } |  j j | ƒ } t j |  j | ƒ } |  j j d | |  j ƒ } |  j j | d t ƒo \ } }	 |	 % |  j	 | ƒ |  j j | | ƒ Wd QX| - |  j j | d ƒ } |  j j | | ƒ Wd QXWd QX|  j j | ƒ St t  | ƒ | ƒ ‚ d S(   s?   
        The returned object must have a new reference
        s   ==t   likelyNR=   (!   R=   R4   R   t   Constt   FreeVart   lower_constt   VarR;   R9   Rh   t   Exprt
   lower_exprt   Globalt   lower_globalt   Yieldt   lower_yieldt   Argt   fnargsR<   R,   t   get_typeR   t   alloca_once_valueRS   t   icmp_unsignedR/   t   if_elset   Falset   storet   object_getattr_stringt   loadRk   RV   (
   R%   Rl   R=   t   valt   objt   typobjt   slott
   is_omittedt   omittedt   present(    (    s/   lib/python2.7/site-packages/numba/pylowering.pyR6   ²   s8    	!c         C` s³   |  j  j | j } | j | k s( t ‚ |  j j |  ƒ t j |  | | j	 | j
 Bƒ } | j ƒ  |  j | j j ƒ } |  j j | ƒ |  j j |  j | ƒ | j ƒ  |  j j ƒ  S(   N(   RM   t   yield_pointsR<   Rl   t   AssertionErrorRO   t   init_generator_stateR   t
   LowerYieldt	   live_varst   weak_live_varst   lower_yield_suspendR;   R=   R9   R,   Rh   RQ   RR   RS   t   lower_yield_resumet	   make_none(   R%   Rl   t   ypt   yR‹   (    (    s/   lib/python2.7/site-packages/numba/pylowering.pyR€   Ø   s    

c   	      C` sã   |  j  | j j ƒ } |  j  | j j ƒ } t | t ƒ s@ t ‚ | t k r† t | \ } } t |  j	 | ƒ } | | | d | ƒ} nL t
 j | j | j ƒ } | d k rº | | } } n  |  j	 j | | | ƒ } |  j | ƒ | S(   Nt   inplaceR    (   R;   t   lhsR9   t   rhsR4   t   strR“   t   PYTHON_BINOPMAPt   getattrR,   t   PYTHON_COMPAREOPMAPt   gett   fnt   object_richcomparet   check_error(	   R%   t   exprt   opR   Rž   RŸ   t   fnameR¥   t   res(    (    s/   lib/python2.7/site-packages/numba/pylowering.pyt   lower_binopì   s    c   (      C` s^	  | j  d k r( |  j | | j d t ƒS| j  d k rP |  j | | j d t ƒS| j  d k rg|  j | j j ƒ } | j t j	 k r› |  j
 j | ƒ } n» | j t j k rÂ |  j
 j | ƒ } n” | j t j k r#|  j
 j | ƒ } |  j | ƒ |  j j | |  j
 j ƒ } |  j
 j | ƒ } n3 | j t j k rJ|  j
 j | ƒ } n t | ƒ ‚ |  j | ƒ | S| j  d k rµg  | j D] } |  j | j ƒ ^ q€} |  j | j j ƒ } |  j
 j | ƒ } | j r|  j
 j | |  j | j j ƒ ƒ }	 |  j | ƒ |	 } n  | j s,|  j
 j  | | d  ƒ }
 nk g  | j D]$ \ } } | |  j | j ƒ f ^ q6} |  j
 j" | ƒ } |  j
 j  | | | ƒ }
 |  j | ƒ |  j | ƒ |  j |
 ƒ |
 S| j  d k r|  j | j j ƒ } |  j
 j# | |  j$ | j% ƒ ƒ } |  j | ƒ | S| j  d k reg  | j& D] } |  j | j ƒ ^ q$} |  j
 j | ƒ } |  j | ƒ | S| j  d k r¿g  | j& D] } |  j | j ƒ ^ q~} |  j
 j' | ƒ } |  j | ƒ | S| j  d	 k rW|  j
 j( | j) ƒ } |  j | ƒ x` | j& D]U \ } } |  j | j ƒ } |  j | j ƒ } |  j
 j* | | | ƒ } |  j | ƒ qúW| S| j  d
 k rág  | j& D] } |  j | j ƒ ^ qp} |  j
 j+ ƒ  } |  j | ƒ x0 | D]( } |  j
 j, | | ƒ } |  j | ƒ q±W| S| j  d k r(|  j | j j ƒ } |  j
 j- | ƒ } |  j | ƒ | S| j  d k r%|  j | j j ƒ } |  j
 j. | ƒ } t/ j0 |  j | ƒ } |  j
 j1 d ƒ } |  j j2 | ƒ f \ } } |  |  j
 j3 | d | ƒ Wd  QX| . |  j4 ƒ  |  j
 j3 | d |  j
 j5 ƒ  ƒ Wd  QXWd  QX|  j
 j3 | d |  j
 j6 | ƒ ƒ | S| j  d k ro|  j | j j ƒ } |  j
 j7 | d ƒ } |  j8 | ƒ | S| j  d k r¹|  j | j j ƒ } |  j
 j7 | d ƒ } |  j8 | ƒ | S| j  d k rq|  j | j j ƒ } |  j
 j9 | ƒ } |  j | ƒ |  j
 j: | ƒ } |  j; j< t= j> | j? ƒ } |  j j@ tA jB | | ƒ } t/ jC |  j | ƒ  |  jD tE ƒ Wd  QX| S| j  d k rÐ|  j | j j ƒ } |  j | jF j ƒ }  |  j
 jG | |  ƒ } |  j | ƒ | S| j  d k ra|  j | j j ƒ } |  j; j< t= j> | jF ƒ }  |  j
 jH |  ƒ }! |  j |! ƒ |  j
 jG | |! ƒ } |  j |! ƒ |  j | ƒ | S| j  d k r	|  j | jI j ƒ }" |  j | jJ j ƒ }# |  j | jK j ƒ }$ |  jL d ƒ }% |  j
 jM |% |# |$ f ƒ }& |  j |% ƒ |  j |& ƒ |  j
 jG |" |& ƒ } |  j | ƒ | S| j  d k rN	|  j | j j ƒ }' |  j8 |' ƒ |' St | ƒ ‚ d  S(   Nt   binopR   t   inplace_binopt   unaryt   callR¢   t   build_tuplet
   build_listt	   build_mapt	   build_sett   getitert   iternexti   i    i   t
   pair_firstt   pair_secondt   exhaust_itert   getitemt   static_getitemt   getslicet   slicet   cast(N   R©   R¬   R¥   R‡   t   TrueR;   R=   R9   t   operatort   negR,   t   number_negativet   post   number_positivet   not_t
   object_notR?   RS   t   zextt   longt   bool_from_longt   invertt   number_invertRk   R§   t   argst   funct
   tuple_packt   varargR   RN   t   kwsR°   Rg   t	   dict_packt   object_getattrRD   RE   t   itemst	   list_packt   dict_newt   sizeRK   t   set_newt   set_addt   object_getitert	   iter_nextR   t   is_not_nullt	   tuple_newR†   t   tuple_setitemt   check_occurredRš   t   bool_from_boolt   tuple_getitemRh   t   sequence_tuplet
   tuple_sizet   contextt   get_constantR   t   intpt   countR[   RY   R\   t   if_unlikelyt   return_exceptiont
   ValueErrorR<   t   object_getitemt   long_from_ssize_tR8   t   startt   stopt   get_builtin_objt   call_function_objargs((   R%   R¨   R=   R«   t   longvalt   at   argvalsR¥   RÌ   t   new_argst   rett   kt   vt	   keyvaluesRÐ   RŒ   t   itRÓ   RJ   Rm   t   iterobjt   itemt   is_validt   pairt   thent	   otherwiset   firstt   secondt   tupt   tup_sizet   expected_sizet   has_wrong_sizeR<   t   indexobjR8   Rì   Rí   t   slicefnt   sliceobjR‹   (    (    s/   lib/python2.7/site-packages/numba/pylowering.pyR|   ý   s   (			4!(((
+"c         C` sB   |  j  j | ƒ } |  j  j | ƒ } |  j | ƒ |  j | ƒ | S(   N(   t   env_managert	   add_constt
   read_constR§   Rh   (   R%   t   constR<   Rô   (    (    s/   lib/python2.7/site-packages/numba/pylowering.pyRy   š  s
    c         C` sz  |  j  ƒ  } |  j j | |  j | ƒ ƒ } |  j | ƒ y, | t k rb t d | d |  j ƒ‚ n  Wn t k
 rv n Xt	 t
 | ƒ r1|  j | ƒ } |  j j } |  j j | ƒ A |  j j | |  j d ƒ ƒ } |  j | | ƒ } |  j j }	 Wd QX|  j j |  j j ƒ }
 |
 j | | ƒ |
 j | |	 ƒ nE | }
 t j |  j |  j |
 ƒ ƒ  |  j j | ƒ |  j ƒ  Wd QX|
 S(   sÄ   
        1) Check global scope dictionary.
        2) Check __builtins__.
            2a) is it a dictionary (for non __main__ module)
            2b) is it a module (for __main__ module)
        s   builtins %s() is not supportedt   loct   __builtins__N(   t   get_module_dictR,   t   dict_getitemRD   Rh   t   _unsupported_builtinsR
   R  t	   TypeErrort   hasattrR   t   is_nullRS   t   basic_blockt   if_thent   builtin_lookupt   phit   pyobjt   add_incomingR   Rç   t   raise_missing_global_errorRj   (   R%   R9   R=   t   moddictRŒ   t   obj_is_nullt   bbelset   modt   builtint   bbifRn   (    (    s/   lib/python2.7/site-packages/numba/pylowering.pyR~   ¢  s2    c         C` s
   |  j  j S(   N(   t   env_bodyt   globals(   R%   (    (    s/   lib/python2.7/site-packages/numba/pylowering.pyR  Í  s    c         C` s:   |  j  ƒ  } |  j j | |  j d ƒ ƒ } |  j | | ƒ S(   NR  (   R  R,   R  RD   R  (   R%   R9   R  R  (    (    s/   lib/python2.7/site-packages/numba/pylowering.pyRî   Ð  s    c      
   C` s  |  j  j | |  j | ƒ ƒ } |  j | ƒ |  j j } t j |  j |  j | ƒ ƒ n |  j  j	 | |  j | ƒ ƒ } t j |  j |  j | ƒ ƒ  |  j  j
 | ƒ |  j ƒ  Wd QX|  j j } Wd QX|  j j |  j  j ƒ } | j | | ƒ | j | | ƒ | S(   sÆ   
        Args
        ----
        mod:
            The __builtins__ dictionary or module, as looked up in
            a module's globals.
        name: str
            The object to lookup
        N(   R,   R  RD   Rh   RS   R  R   Rç   R  RÒ   R  Rj   R  R  R  (   R%   R  R9   t   fromdictt   bbifdictt   frommodt   bbifmodR  (    (    s/   lib/python2.7/site-packages/numba/pylowering.pyR  ×  s    
c         C` sH   t  j |  j |  j j ƒ  ƒ } t  j |  j | ƒ  |  j ƒ  Wd QXd S(   s2   
        Return if an exception occurred.
        N(   R   RÛ   RS   R,   t   err_occurredRç   Rj   (   R%   R'  (    (    s/   lib/python2.7/site-packages/numba/pylowering.pyRÞ   õ  s    c         C` s3   t  j |  j |  j | ƒ ƒ  |  j ƒ  Wd QX| S(   s*   
        Return if *obj* is NULL.
        N(   R   Rç   RS   R  Rj   (   R%   RŒ   (    (    s/   lib/python2.7/site-packages/numba/pylowering.pyR§   ÿ  s    i    c         C` s]   t  j j | j | ƒ } |  j j t  j | | ƒ } t j |  j | ƒ  |  j	 ƒ  Wd QXd S(   sI   
        Raise an exception if *num* is smaller than *ok_value*.
        N(
   RY   R   RW   RV   RS   R[   t   ICMP_SLTR   Rç   Rj   (   R%   t   numt   ok_valueRm   Rq   (    (    s/   lib/python2.7/site-packages/numba/pylowering.pyR?     s    c         C` s   t  j |  j | ƒ S(   N(   R   R  RS   (   R%   RŒ   (    (    s/   lib/python2.7/site-packages/numba/pylowering.pyR    s    c         C` s!   |  j  ƒ  |  j j |  j ƒ d S(   s=   
        Return with the currently raised exception.
        N(   t   cleanup_varsRQ   t
   return_excRS   (   R%   (    (    s/   lib/python2.7/site-packages/numba/pylowering.pyRj     s    
c         C` s   t  |  j j | ƒ ƒ |  _ d S(   s8   
        Initialize live variables for *block*.
        N(   R"   t   func_irt   get_block_entry_varsR$   (   R%   R2   (    (    s/   lib/python2.7/site-packages/numba/pylowering.pyR1     s    c         C` s9   | |  j  k r. |  j | d | ƒ|  j  | <n  |  j  | S(   Nt   ltype(   t   varmapt   alloca(   R%   R9   R/  (    (    s/   lib/python2.7/site-packages/numba/pylowering.pyt   _getvar!  s    c         C` s}   | |  j  k s t | ƒ ‚ |  j | } |  j j | ƒ } t j |  j |  j | ƒ ƒ  |  j j	 | ƒ |  j
 ƒ  Wd QX| S(   sC   
        Load the llvm value of the variable named *name*.
        N(   R$   R“   R0  RS   RŠ   R   Rç   R  R,   t   raise_missing_name_errorRj   (   R%   R9   t   ptrR‹   (    (    s/   lib/python2.7/site-packages/numba/pylowering.pyR;   &  s    c         C` s^   |  j  j | ƒ |  j | ƒ } |  j |  j j | ƒ ƒ |  j j t j | j	 j
 ƒ | ƒ d S(   sy   
        Delete the variable slot with the given name. This will decref
        the corresponding Python object.
        N(   R$   t   removeR2  RN   RS   RŠ   Rˆ   R   t   get_null_valueRV   t   pointee(   R%   R9   R4  (    (    s/   lib/python2.7/site-packages/numba/pylowering.pyRd   3  s    c         C` sÂ   | |  j  k o | } |  j | d | j ƒ} | rI |  j j | ƒ } n |  j  j | ƒ | j | j j k s• t t | j ƒ t | j j ƒ f ƒ ‚ |  j j	 | | ƒ | r¾ |  j
 | ƒ n  d S(   s|   
        Stores a llvm value and allocate stack slot if necessary.
        The llvm value can be of arbitrary type.
        R/  N(   R$   R2  RV   RS   RŠ   t   addR7  R“   R    Rˆ   RN   (   R%   R=   R9   t   clobbert   is_redefineR4  t   old(    (    s/   lib/python2.7/site-packages/numba/pylowering.pyR7   A  s    $c         C` s@   x9 |  j  D]. } |  j | ƒ } |  j |  j j | ƒ ƒ q
 Wd S(   s)   
        Cleanup live variables.
        N(   R$   R2  RN   RS   RŠ   (   R%   R9   R4  (    (    s/   lib/python2.7/site-packages/numba/pylowering.pyR+  S  s    c         C` sx   | d k r$ |  j j t j ƒ } n  |  j j |  j ƒ 9 |  j j | d | ƒ} |  j j	 t
 j | ƒ | ƒ Wd QX| S(   sœ   
        Allocate a stack slot and initialize it to NULL.
        The default is to allocate a pyobject pointer.
        Use ``ltype`` to override.
        R9   N(   Rg   Rã   t   get_value_typeR   t   pyobjectRS   t
   goto_blockt   entry_blockR1  Rˆ   R   R6  (   R%   R9   R/  R4  (    (    s/   lib/python2.7/site-packages/numba/pylowering.pyR1  [  s    "c         C` s   |  j  j | ƒ d  S(   N(   R,   Rh   (   R%   R=   (    (    s/   lib/python2.7/site-packages/numba/pylowering.pyRh   h  s    c         C` s;   |  j  j t j ƒ } | j | k r7 |  j j | ƒ n  d S(   sp   
        This is allow to be called on non pyobject pointer, in which case
        no code is inserted.
        N(   Rã   R<  R   R=  RV   R,   RN   (   R%   R=   t   lpyobj(    (    s/   lib/python2.7/site-packages/numba/pylowering.pyRN   k  s    c         C` s   |  j  | ƒ S(   s>   
        Freeze a Python string object into the code.
        (   Ry   (   R%   t   string(    (    s/   lib/python2.7/site-packages/numba/pylowering.pyRD   t  s    N($   t   __name__t
   __module__R   t   PyGeneratorLowert   GeneratorLowerR&   R)   R0   R3   Ru   R6   R€   R‡   R¬   R|   Ry   R~   R  Rî   R  RÞ   R§   R?   R  Rj   R1   Rg   R2  R;   Rd   R7   R+  R1  Rh   RN   RD   (    (    (    s/   lib/python2.7/site-packages/numba/pylowering.pyR!   F   s<   						T	&				+				
												(F   t   __doc__t
   __future__R    R   R   t   llvmlite.llvmpy.coreR   R   t   llvmpyt   coreRY   RÀ   t    R   R   R   R   R	   t   errorsR
   t   loweringR   R   R   R   R"   t   localsR  R‡   R8  t   subt   mult   truedivt   floordivR  t   powt   lshiftt   rshiftt   and_t   or_t   xorR¿   t   iaddt   isubt   imult   itruedivt	   ifloordivt   imodt   ipowt   ilshiftt   irshiftt   iandt   iort   ixorR¡   t   divt   idivt   matmult   imatmult   eqt   net   ltt   let   gtt   get   is_t   is_nott   containsR£   R!   (    (    (    s/   lib/python2.7/site-packages/numba/pylowering.pyt   <module>   sf   (







