ó
Ū³Y]c           @   s£   d  d l  m Z d  d l j Z d  d l m Z d  d l j j	 Z
 d  d l m Z m Z d  d l m Z m Z d e j f d     YZ e d k r e j   n  d S(	   i’’’’(   t   divisionN(   t   contextmanager(   t   typest   typing(   t   callconvt   cput   TestCompileCachec           B   s8   e  Z d  Z e d    Z d   Z d   Z d   Z RS(   s   
    Tests that the caching in BaseContext.compile_internal() works correctly by
    checking the state of the cache when it is used by the CPUContext.
    c         c   sń   t  j   } t j |  } | j   j d  } | j |  ¬ t j d  } t  j	 t
 j t
 j  } | j j | j | j  } | j | d d } | j j |  } | j sø t  | j d  }	 t j |	  }
 | |
 | | f VWd  QXd  S(   Nt   testingt   test_modulet   namet   test_fnt   entry(   R   t   ContextR   t
   CPUContextt   codegent   create_libraryt   push_code_libraryt   lct   Modulet	   signatureR   t   int32t	   call_convt   get_function_typet   return_typet   argst   get_or_insert_functiont   get_argumentst   is_declarationt   AssertionErrort   append_basic_blockt   Builder(   t   selft   typing_contextt   contextt   libt   modulet   sigt	   llvm_fntyt   functionR   t   entry_blockt   builder(    (    s=   lib/python2.7/site-packages/numba/tests/test_compile_cache.pyt   _context_builder_sig_args   s    c      	   C   s  d   } d   } |  j    r\ } } } } |  j d t | j   | j | | | |  |  j d t | j   | j | | | |  |  j d t | j   | j | | | |  |  j d t | j   t j t j t j  } | j	 j
 | j | j  } | j j | d d }	 | j	 j |	  }
 |	 j s?t  |	 j d  } t j |  } | j | | | |
  |  j d	 t | j   Wd  QXd  S(
   Nc         S   s   d |  S(   Ni   (    (   t   i(    (    s=   lib/python2.7/site-packages/numba/tests/test_compile_cache.pyt   times2&   s    c         S   s   |  d S(   Ni   (    (   R*   (    (    s=   lib/python2.7/site-packages/numba/tests/test_compile_cache.pyt   times3)   s    i    i   i   R	   t	   test_fn_2R   i   (   R)   t   assertEqualt   lent   cached_internal_funct   compile_internalR   R   R   t   float64R   R   R   R   R#   R   R   R   R   R   R   R   (   R   R+   R,   R!   R(   R$   R   t   sig2t
   llvm_fnty2t	   function2t   args2t   entry_block2t   builder2(    (    s=   lib/python2.7/site-packages/numba/tests/test_compile_cache.pyt
   test_cache%   s,    			c      	   C   sī   d   } |  j    Ó \ } } } } | d d  } | d d  } | d d  } | j | | | |  }	 |  j d t | j   | j | | | |  }
 |  j d t | j   | j | | | |  } |  j d t | j   Wd QXd S(   sP   
        Caching must not mix up closures reusing the same code object.
        c            s     f d   } | S(   Nc            s     |  S(   N(    (   t   z(   t   y(    s=   lib/python2.7/site-packages/numba/tests/test_compile_cache.pyt   fT   s    (    (   t   xR;   R<   (    (   R;   s=   lib/python2.7/site-packages/numba/tests/test_compile_cache.pyt   make_closureS   s    i   i   N(   R)   R1   R.   R/   R0   (   R   R>   R!   R(   R$   R   t   clo11t   clo12t   clo22t   res1t   res2t   res3(    (    s=   lib/python2.7/site-packages/numba/tests/test_compile_cache.pyt   test_closuresO   s    	c   
         s7  d    t  j t j t j       f d   } |  j   ļ \ }   } } t j d |  } t j d |  } | j d |  } | j d |  } | j d |  }	 |  j d t	 | j
   | |  |  j d t	 | j
   | |  |  j d t	 | j
   | |	  |  j d t	 | j
   Wd	 QXd	 S(
   sA   
        Caching must not mix up different error models.
        c         S   s   d |  S(   Ng      š?(    (   R=   (    (    s=   lib/python2.7/site-packages/numba/tests/test_compile_cache.pyt   invk   s    c            s   |  j       S(   N(   t   compile_subroutine(   R!   (   R(   RF   t   inv_sig(    s=   lib/python2.7/site-packages/numba/tests/test_compile_cache.pyt   compile_invp   s    t   pythont   numpyt   error_modeli    i   i   N(   R   R   R   R2   R)   R   t   create_error_modelt	   subtargetR.   R/   R0   (
   R   RI   R!   R$   R   t   py_error_modelt   np_error_modelt   py_context1t   py_context2t
   np_context(    (   R(   RF   RH   s=   lib/python2.7/site-packages/numba/tests/test_compile_cache.pyt   test_error_modelg   s"    	


(   t   __name__t
   __module__t   __doc__R   R)   R9   RE   RT   (    (    (    s=   lib/python2.7/site-packages/numba/tests/test_compile_cache.pyR      s
   	*	t   __main__(   t
   __future__R    t   numba.unittest_supportt   unittest_supportt   unittestt
   contextlibR   t   llvmlite.llvmpy.coret   llvmpyt   coreR   t   numbaR   R   t   numba.targetsR   R   t   TestCaseR   RU   t   main(    (    (    s=   lib/python2.7/site-packages/numba/tests/test_compile_cache.pyt   <module>   s   }