ó
\K]c           @` s\   d  d l  m Z m Z m 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_importt   division(   t   ir(   t   cgutilst   typest
   NRTContextc           B` s°   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sF   
    An object providing access to NRT APIs in the lowering pass.
    c         C` s   | |  _  | |  _ d  S(   N(   t   _contextt   _enabled(   t   selft   contextt   enabled(    (    s4   lib/python2.7/site-packages/numba/runtime/context.pyt   __init__   s    	c         C` s   |  j  s t d ƒ ‚ n  d  S(   Ns   NRT required but not enabled(   R   t   RuntimeError(   R	   (    (    s4   lib/python2.7/site-packages/numba/runtime/context.pyt   _require_nrt   s    	c         C` sf   |  j  ƒ  | j } t j t j t j g ƒ } | j | d d ƒ} | j j	 d ƒ | j
 | | g ƒ S(   sG   
        Low-level allocate a new memory area of `size` bytes.
        t   namet   NRT_Allocatet   noalias(   R   t   moduleR   t   FunctionTypeR   t	   voidptr_tt   intp_tt   get_or_insert_functiont   return_valuet   add_attributet   call(   R	   t   buildert   sizet   modt   fntyt   fn(    (    s4   lib/python2.7/site-packages/numba/runtime/context.pyt   allocate   s    
	c         C` sY   |  j  ƒ  | j } t j t j ƒ  t j g ƒ } | j | d d ƒ} | j | | g ƒ S(   sI   
        Low-level free a memory area allocated with allocate().
        R   t   NRT_Free(	   R   R   R   R   t   VoidTypeR   R   R   R   (   R	   R   t   ptrR   R   R   (    (    s4   lib/python2.7/site-packages/numba/runtime/context.pyt   free!   s
    
	c         C` sf   |  j  ƒ  | j } t j t j t j g ƒ } | j | d d ƒ} | j j	 d ƒ | j
 | | g ƒ S(   s|   
        Allocate a new MemInfo with a data payload of `size` bytes.

        A pointer to the MemInfo is returned.
        R   t   NRT_MemInfo_alloc_safeR   (   R   R   R   R   R   R   R   R   R   R   R   (   R	   R   R   R   R   R   (    (    s4   lib/python2.7/site-packages/numba/runtime/context.pyt   meminfo_alloc,   s    
	c         C` s~   |  j  ƒ  | j } t j t j t j t j g ƒ } | j | d d ƒ} | j j	 d ƒ | j
 | | | j | t j ƒ g ƒ S(   NR   t   NRT_MemInfo_alloc_dtor_safeR   (   R   R   R   R   R   R   R   R   R   R   R   t   bitcast(   R	   R   R   t   dtorR   R   R   (    (    s4   lib/python2.7/site-packages/numba/runtime/context.pyt   meminfo_alloc_dtor:   s    
		c         C` sÀ   |  j  ƒ  | j } t j d ƒ } t j t j t j | g ƒ } | j | d d ƒ} | j	 j
 d ƒ t | t ƒ r |  j j t j | ƒ } n | j | k sª t d ƒ ‚ | j | | | g ƒ S(   sÿ   
        Allocate a new MemInfo with an aligned data payload of `size` bytes.
        The data pointer is aligned to `align` bytes.  `align` can be either
        a Python int or a LLVM uint32 value.

        A pointer to the MemInfo is returned.
        i    R   t   NRT_MemInfo_alloc_safe_alignedR   s   align must be a uint32(   R   R   R   t   IntTypeR   R   R   R   R   R   R   t
   isinstancet   intR   t   get_constantR   t   uint32t   typet   AssertionErrorR   (   R	   R   R   t   alignR   t   u32R   R   (    (    s4   lib/python2.7/site-packages/numba/runtime/context.pyt   meminfo_alloc_alignedF   s    
		c         C` sf   |  j  ƒ  | j } t j t j t j g ƒ } | j | d d ƒ} | j j	 d ƒ | j
 | | g ƒ S(   s  
        Allocate a MemInfo pointing to a variable-sized data area.  The area
        is separately allocated (i.e. two allocations are made) so that
        re-allocating it doesn't change the MemInfo's address.

        A pointer to the MemInfo is returned.
        R   t   NRT_MemInfo_new_varsizeR   (   R   R   R   R   R   R   R   R   R   R   R   (   R	   R   R   R   R   R   (    (    s4   lib/python2.7/site-packages/numba/runtime/context.pyt   meminfo_new_varsize\   s    
	c         C` s_   |  j  ƒ  | j } t j t j t j t j g ƒ } | j | d d ƒ} | j | | | g ƒ S(   s   
        Like meminfo_new_varsize() but also set the destructor for
        cleaning up references to objects inside the allocation.
        R   t   NRT_MemInfo_new_varsize_dtor(	   R   R   R   R   R   R   R   R   R   (   R	   R   R   R(   R   R   R   (    (    s4   lib/python2.7/site-packages/numba/runtime/context.pyt   meminfo_new_varsize_dtorl   s    
	c         C` s   |  j  | | | d ƒ S(   s¾  
        Allocate a new data area for a MemInfo created by meminfo_new_varsize().
        The new data pointer is returned, for convenience.

        Contrary to realloc(), this always allocates a new area and doesn't
        copy the old data.  This is useful if resizing a container needs
        more than simply copying the data area (e.g. for hash tables).

        The old pointer will have to be freed with meminfo_varsize_free().
        t   NRT_MemInfo_varsize_alloc(   t   _call_varsize_alloc(   R	   R   t   meminfoR   (    (    s4   lib/python2.7/site-packages/numba/runtime/context.pyt   meminfo_varsize_allocz   s    c         C` s   |  j  | | | d ƒ S(   s‡   
        Reallocate a data area allocated by meminfo_new_varsize().
        The new data pointer is returned, for convenience.
        t   NRT_MemInfo_varsize_realloc(   R:   (   R	   R   R;   R   (    (    s4   lib/python2.7/site-packages/numba/runtime/context.pyt   meminfo_varsize_reallocˆ   s    c         C` sb   |  j  ƒ  | j } t j t j ƒ  t j t j g ƒ } | j | d d ƒ} | j | | | f ƒ S(   s   
        Free a memory area allocated for a NRT varsize object.
        Note this does *not* free the NRT object itself!
        R   t   NRT_MemInfo_varsize_free(	   R   R   R   R   R!   R   R   R   R   (   R	   R   R;   R"   R   R   R   (    (    s4   lib/python2.7/site-packages/numba/runtime/context.pyt   meminfo_varsize_free   s    
	c         C` so   |  j  ƒ  | j } t j t j t j t j g ƒ } | j | d | ƒ} | j j	 d ƒ | j
 | | | g ƒ S(   NR   R   (   R   R   R   R   R   R   R   R   R   R   R   (   R	   R   R;   R   t   funcnameR   R   R   (    (    s4   lib/python2.7/site-packages/numba/runtime/context.pyR:      s    
	c         C` sK   |  j  ƒ  d d l m } | j } | j | d d ƒ} | j | | g ƒ S(   s¯   
        Given a MemInfo pointer, return a pointer to the allocated data
        managed by it.  This works for MemInfos allocated with all the
        above methods.
        i    (   t   meminfo_data_tyR   t   NRT_MemInfo_data_fast(   R   t   numba.runtime.nrtdynmodRB   R   R   R   (   R	   R   R;   RB   R   R   (    (    s4   lib/python2.7/site-packages/numba/runtime/context.pyt   meminfo_data§   s    
		c         C` s¢   |  j  j | } | j | ƒ } g  } | j ƒ  rY | j | | ƒ } | j | | f ƒ n  xB | D]: \ } }	 |	 | ƒ }
 |  j | | |
 ƒ } | j | ƒ q` W| S(   sC   Return a list of *(type, meminfo)* inside the given value.
        (   R   t   data_model_managert   traverset   has_nrt_meminfot   get_nrt_meminfot   appendt   get_meminfost   extend(   R	   R   t   tyt   valt	   datamodelt   memberst   meminfost   mit   mtypt   gettert   fieldt   inner_meminfos(    (    s4   lib/python2.7/site-packages/numba/runtime/context.pyRK   ¶   s    c         C` s£   |  j  ƒ  d d l m } |  j | | | ƒ } xm | D]e \ } } | j }	 |	 j | d | ƒ}
 |
 j d j d ƒ |
 j d j d ƒ | j |
 | g ƒ q6 Wd S(   sG   Call function of *funcname* on every meminfo found in *value*.
        i    (   t   incref_decref_tyR   R   t	   nocaptureN(	   R   RD   RW   RK   R   R   t   argsR   R   (   R	   R   t   typt   valueRA   RW   RQ   t   _RR   R   R   (    (    s4   lib/python2.7/site-packages/numba/runtime/context.pyt   _call_incref_decrefÇ   s    
	c         C` s   |  j  | | | d ƒ d S(   sG   
        Recursively incref the given *value* and its members.
        t
   NRT_increfN(   R]   (   R	   R   RZ   R[   (    (    s4   lib/python2.7/site-packages/numba/runtime/context.pyt   increfØ   s    c         C` s   |  j  | | | d ƒ d S(   sG   
        Recursively decref the given *value* and its members.
        t
   NRT_decrefN(   R]   (   R	   R   RZ   R[   (    (    s4   lib/python2.7/site-packages/numba/runtime/context.pyt   decrefÞ   s    (   t   __name__t
   __module__t   __doc__R   R   R   R#   R%   R)   R4   R6   R8   R<   R>   R@   R:   RE   RK   R]   R_   Ra   (    (    (    s4   lib/python2.7/site-packages/numba/runtime/context.pyR      s&   													
				N(   t
   __future__R    R   R   t   llvmliteR   t   numbaR   R   t   objectR   (    (    (    s4   lib/python2.7/site-packages/numba/runtime/context.pyt   <module>   s   