σ
\K]c           @` sΪ   d  Z  d d l m Z m Z m Z d d l Z d d l m Z d d l m	 Z	 m
 Z
 d d l m Z m Z d d l m Z d d	 l m Z d d
 l m Z d d l m Z d e f d     YZ d e f d     YZ d S(   s2   
Implementation of compiled C callbacks (@cfunc).
i    (   t   print_functiont   divisiont   absolute_importN(   t   iri   (   t   utilst   compiler(   t	   NullCachet   FunctionCache(   t   _FunctionCompiler(   t   registry(   t	   signature(   t	   to_ctypest   _CFuncCompilerc           B` s   e  Z d    Z RS(   c         C` sL   | j  d t  | j  d t  | j  d t  | j rH t d   n  | S(   Nt   no_cpython_wrappert
   no_compilet   enable_pyobjects&   object mode not allowed in C callbacks(   t   sett   Truet   Falset   force_pyobjectt   NotImplementedError(   t   selft   flags(    (    s.   lib/python2.7/site-packages/numba/ccallback.pyt   _customize_flags   s    	(   t   __name__t
   __module__R   (    (    (    s.   lib/python2.7/site-packages/numba/ccallback.pyR      s   t   CFuncc           B` sΆ   e  Z d  Z e j Z e j d  Z d   Z	 e j
 d    Z d   Z d   Z e d    Z e d    Z e j d    Z e j d	    Z d
   Z e d    Z d   Z RS(   sD   
    A compiled C callback, as created by the @cfunc decorator.
    c         C` s»   | \ } } | d  k r' t d   n  | j |  _ t | d |  j  |  _ | |  _ | |  _ t | |  |  _ t	 | |  j
 | | d | |  _ d  |  _ d  |  _ t   |  _ d |  _ d  S(   Ns(   C callback needs an explicit return typet   __qualname__t   pipeline_classi    (   t   Nonet	   TypeErrorR   t   getattrR   t   __wrapped__t   _pyfuncR
   t   _sigR   t   _targetdescrt	   _compilert   _wrapper_namet   _wrapper_addressR   t   _cachet   _cache_hits(   R   t   pyfunct   sigt   localst   optionsR   t   argst   return_type(    (    s.   lib/python2.7/site-packages/numba/ccallback.pyt   __init__(   s    					c         C` s   t  |  j  |  _ d  S(   N(   R   R!   R'   (   R   (    (    s.   lib/python2.7/site-packages/numba/ccallback.pyt   enable_caching<   s    c         C` s   |  j  j |  j |  j j  } | d  k rO |  j   } |  j  j |  j |  n |  j d 7_ | j	 |  _
 | j j |  _ |  j
 j |  j  |  _ d  S(   Ni   (   R'   t   load_overloadR"   R#   t   target_contextR   t   _compile_uncachedt   save_overloadR(   t   libraryt   _libraryt   fndesct   llvm_cfunc_wrapper_nameR%   t   get_pointer_to_functionR&   (   R   t   cres(    (    s.   lib/python2.7/site-packages/numba/ccallback.pyt   compile?   s    c         C` s  |  j  } |  j j | j | j  } | j s4 t  | j } | j } | j	 | j
  } | j } g  | j D] } | j |  ^ qk } | j | j  }	 t j |	 |  }
 | j |
 | j  } t j | j d   } |  j | | | | j  | j |  | j   | S(   Nt   entry(   R"   R$   R;   R-   R.   t
   objectmodet   AssertionErrorR7   R5   t   create_ir_modulet   unique_nameR2   t   get_value_typeR   t   FunctionTypet   add_functionR8   t	   IRBuildert   append_basic_blockt   _build_c_wrappert   add_ir_modulet   finalize(   R   R*   R:   R7   R5   t   modulet   contextt   tyt   ll_argtypest   ll_return_typet   wraptyt   wrapfnt   builder(    (    s.   lib/python2.7/site-packages/numba/ccallback.pyR3   M   s     				%
c         C` s  |  j  } | j |  } | j j | j | j  } | j j | | j j	  } | j j
 | | | j | j |  \ }	 }
 | j |	 j d t x | j   } | j j | | |	  | j | j t |    } | j |  } | j |  | j |  | j |  Wd  QX| j |
  d  S(   Nt   likely(   R"   t   get_python_apit	   call_convt   get_function_typeR.   R-   RI   RC   R7   t   llvm_func_namet   call_functiont   if_thent   is_errorR   t
   gil_ensuret   raise_errort   insert_const_stringt   reprt   string_from_stringt   err_write_unraisablet   decreft   gil_releaset   ret(   R   RJ   RP   R:   t   c_argsR*   t   pyapit   fntyt   fnt   statust   outt	   gil_statet   cstrt   strobj(    (    s.   lib/python2.7/site-packages/numba/ccallback.pyRF   i   s    		!c         C` s   |  j  S(   sG   
        The process-wide symbol the C callback is exposed as.
        (   R%   (   R   (    (    s.   lib/python2.7/site-packages/numba/ccallback.pyt   native_name   s    c         C` s   |  j  S(   s0   
        The address of the C callback.
        (   R&   (   R   (    (    s.   lib/python2.7/site-packages/numba/ccallback.pyt   address   s    c         C` s+   d d l  } | j   } | j d |  j  S(   sF   
        A cffi function pointer representing the C callback.
        i    Ns   void *(   t   cffit   FFIt   castRl   (   R   Rm   t   ffi(    (    s.   lib/python2.7/site-packages/numba/ccallback.pyRm      s    c         C` sV   g  |  j  j D] } t |  ^ q } t |  j  j  } t j | |  } | |  j  S(   sG   
        A ctypes function object representing the C callback.
        (   R"   R-   R   R.   t   ctypest	   CFUNCTYPERl   (   R   RK   t   ctypes_argst   ctypes_restypet   functype(    (    s.   lib/python2.7/site-packages/numba/ccallback.pyRq      s    %c         C` s   |  j  j   S(   sB   
        Return the LLVM IR of the C callback definition.
        (   R6   t   get_llvm_str(   R   (    (    s.   lib/python2.7/site-packages/numba/ccallback.pyt   inspect_llvm¦   s    c         C` s   |  j  S(   N(   R(   (   R   (    (    s.   lib/python2.7/site-packages/numba/ccallback.pyt
   cache_hits¬   s    c         C` s   d |  j  f S(   Ns   <Numba C callback %r>(   R   (   R   (    (    s.   lib/python2.7/site-packages/numba/ccallback.pyt   __repr__°   s    (   R   R   t   __doc__R	   t
   cpu_targetR#   R   t   PipelineR/   R0   t   global_compiler_lockR;   R3   RF   t   propertyRk   Rl   R   t   cached_propertyRm   Rq   Rw   Rx   Ry   (    (    (    s.   lib/python2.7/site-packages/numba/ccallback.pyR   "   s   					
	(   Rz   t
   __future__R    R   R   Rq   t   llvmliteR   t    R   R   t   cachingR   R   t
   dispatcherR   t   targetsR	   t   typingR
   t   typing.ctypes_utilsR   R   t   objectR   (    (    (    s.   lib/python2.7/site-packages/numba/ccallback.pyt   <module>   s   