
ّRMc           @   s  d  d k  Z  d  d k Z d  d k l Z d  d k l Z d  d k l Z d  d k l Z d  d k	 l
 Z
 d   Z d   Z d	   Z d
   Z d   Z d d  Z d   Z d e f d     YZ d   Z e d d d Z d e f d     YZ d   Z d e _ e i d e i d e i d e i d d  Z d e _ d   Z d e _ d e _ d e f d     YZ d    Z d! e _ d"   Z d# e _ d$   Z d% e f d&     YZ  d' e  f d(     YZ! d e f d)     YZ d e f d*     YZ e d  Z# d+ e f d,     YZ$ d Z% d Z& d- Z' h  d. d/ <d0 d1 <d2 d3 <e( d4 <e' d5 <d. d6 <Z) e e) i*    Z+ d7 dA d8     YZ, d9 e f d:     YZ- d; e f d<     YZ. d= e f d>     YZ/ d? e f d@     YZ0 d S(B   iN(   t   ExtRegistryEntry(   t   CDefinedIntSymbolic(   t   keepalive_until_here(   t   unrolling_iterable(   t   NonConstantc         C   s   t  |  _ |  S(   s   Decorate a function as pure. Pure means precisely that:

    (1) the result of the call should not change if the arguments are
        the same (same numbers or same pointers)
    (2) it's fine to remove the call completely if we can guess the result
    according to rule 1

    Most importantly it doesn't mean that pure function has no observable
    side effect, but those side effects can be ommited (ie caching).
    For now, such a function should never raise an exception.
    (   t   Truet   _pure_function_(   t   func(    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyt   purefunction	   s    	c         K   s   |  S(   s;    Hint for the JIT

    possible arguments are:
    XXX
    (    (   t   xt   kwds(    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyt   hint   s    c         C   s   t  |  _ |  S(   s`    Make sure the JIT does not trace inside decorated function
    (it becomes a call instead)
    (   t   Falset   _jit_look_inside_(   R   (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyt   dont_look_inside    s    	c         C   s   t  |  _ |  S(   s_    JIT can safely unroll loops in this function and this will
    not lead to code explosion
    (   R   t   _jit_unroll_safe_(   R   (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyt   unroll_safe'   s    	c         C   s   t  |   t |  _ |  S(   s    Describes a function with no argument that returns an object that
    is always the same in a loop.

    Use it only if you know what you're doing.
    (   R   R   t   _jit_loop_invariant_(   R   (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyt   loop_invariant.   s    
	t   allc            s     f d   } | S(   sV    A decorator that promotes all arguments and then calls the supplied
    function
    c            s  d d  k  } e |   | i |   \ } } } } g  } e e |   D] } | d | f qH ~ } | d  j o | d  j p t  | p t  d i |  } d | f g }	   d j o8 g  }
   i d  D] } |
 d e	 |  q ~
 } n x% | D] } |	 i
 d | | f  q W|	 i
 d	 | f  h  |  d
 <e d <} e i i d i |	   i   | U| d } |  i d | _ | S(   Nis   v%ss   , s   def f(%s):
R   t   ,s   v%ds        %s = hint(%s, promote=True)
s       return func(%s)
R   R   s   
t   ft   _promote(   t   inspectR   t
   getargspect   ranget   lent   Nonet   AssertionErrort   joint   splitt   intt   appendR   t   pyt   codet   Sourcet   compilet	   func_name(   R   R   t   argst   varargst   varkwt   defaultst   _[1]t   it	   argstringR"   t   _[2]t   argt   dt   result(   t   promote_args(    s!   /64/home/arigo/u/pypy/rlib/jit.pyt	   decorator<   s&    
4!8 #
(    (   R1   R2   (    (   R1   s!   /64/home/arigo/u/pypy/rlib/jit.pyt   purefunction_promote8   s    c            s     f d   } | S(   Nc            s     |  _  |  S(   N(   t   oopspec(   R   (   t   spec(    s!   /64/home/arigo/u/pypy/rlib/jit.pyR2   R   s    	(    (   R5   R2   (    (   R5   s!   /64/home/arigo/u/pypy/rlib/jit.pyR4   Q   s    t   Entryc           B   s    e  Z e Z d    Z d   Z RS(   c   
      K   s  d d k  l } | i |  } d | j } d | j } | p | o | p
 t d  t | | i  o d d k l } | i i	 } | i
 d | d    i } | d  j	 oM | i i   }	 t |	 d <| o t |	 d	 <n | i | i | i |	  } q qn | S(
   Ni(   t   modelt   s_access_directlyt   s_fresh_virtualizables   lone fresh_virtualizable hint(   t   Constantt   _virtualizable2_t   access_directlyt   fresh_virtualizable(   t   pypy.annotationR7   t	   not_constR   t
   isinstancet   SomeInstancet   pypy.objspace.flow.modelR:   t   classdeft	   classdesct   read_attributeR   t   valuet   flagst   copyR   t   can_be_None(
   t   selft   s_xt   kwds_st   annmodelR<   R=   R:   RD   t   virtualizableRG   (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyt   compute_result_annotationZ   s(    	
c         K   s   d d k  l } h  } x | i   D]u \ } } | i | } | i   p' d d k l } | d | f   n | i d  p t  | i	 | | d <q# W| i
 | i d d d }	 | i | i |  }
 | i   | i d	 |	 |
 g d
 |	 i S(   Ni(   t   lltype(   t
   TyperErrors   hint %r is not constantt   i_i   i    R.   R   t
   resulttype(   t   pypy.rpython.lltypesystemRP   t   itemst   args_st   is_constantt   pypy.rpython.errorRQ   t
   startswithR   t   constt   inputargt   args_rt
   inputconstt   Voidt   exception_cannot_occurt   genopt   concretetype(   RJ   t   hopt   kwds_iRP   t   hintst   keyt   indext   s_valueRQ   t   vt   c_hint(    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyt   specialize_callp   s     
(   t   __name__t
   __module__R   t   _about_RO   Rj   (    (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyR6   W   s   	c           C   s   t  S(   sj    Considered as true during tracing and blackholing,
    so its consquences are reflected into jitted code (   R   (    (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyt   we_are_jitted   s    s   0 /* we are not jitted here */t   defaulti    c           B   s    e  Z e Z d    Z d   Z RS(   c         C   s    d d k  l } | i d t  S(   Ni(   R7   t   nonneg(   R>   R7   t   SomeIntegerR   (   RJ   RM   (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyRO      s    c         C   s-   d d k  l } | i   | i | i t  S(   Ni(   RP   (   RT   RP   R_   R]   t   Signedt   _we_are_jitted(   RJ   Rb   RP   (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyRj      s    
(   Rk   Rl   Rn   Rm   RO   Rj   (    (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyR6      s   	c           C   s   t  t  o d Sn d S(   se   During JIT tracing, returns the current trace length (as a constant).
    If not tracing, returns -1.iI   i(   R   R   (    (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyt   current_trace_length   s    s   jit.current_trace_length()i   c         C   s   t  |   d S(   sq   When JITted, cause an extra operation JIT_DEBUG to appear in
    the graphs.  Should not be left after debugging.N(   R   (   t   stringt   arg1t   arg2t   arg3t   arg4(    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyt	   jit_debug   s    s)   jit.debug(string, arg1, arg2, arg3, arg4)c         C   s   t  |   d S(   sU   Very strong assert: checks that 'value' is a green
    (a JIT compile-time constant).N(   R   (   RF   (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyt   assert_green   s    s   specialize:argtype(0)s   jit.assert_green(value)t   AssertGreenFailedc           B   s   e  Z RS(    (   Rk   Rl   (    (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyR|      s   c         C   s
   t  |   S(   s  Creates a 'vref' object that contains a reference to 'x'.  Calls
    to virtual_ref/virtual_ref_finish must be properly nested.  The idea
    is that the object 'x' is supposed to be JITted as a virtual between
    the calls to virtual_ref and virtual_ref_finish, but the 'vref'
    object can escape at any point in time.  If at runtime it is
    dereferenced (by the call syntax 'vref()'), it returns 'x', which is
    then forced.(   t   DirectJitVRef(   R	   (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyt   virtual_ref   s    	s   virtual_ref(x)c         C   s   t  |   d S(   ss   See docstring in virtual_ref(x).  Note that virtual_ref_finish
    takes as argument the real object, not the vref.N(   R   (   R	   (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyt   virtual_ref_finish   s    s   virtual_ref_finish(x)c         C   s
   t  |   S(   sz   Creates a 'vref' that just returns x when called; nothing more special.
    Used for None or for frames outside JIT scope.(   t
   DirectVRef(   R	   (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyt   non_virtual_ref   s    R   c           B   s   e  Z d    Z d   Z RS(   c         C   s   | |  _  d  S(   N(   t   _x(   RJ   R	   (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyt   __init__   s    c         C   s   |  i  S(   N(   R   (   RJ   (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyt   __call__   s    (   Rk   Rl   R   R   (    (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyR      s   	R}   c           B   s   e  Z d    Z RS(   c         C   s+   | d  j	 p
 t d  t i |  |  d  S(   Ns    virtual_ref(None) is not allowed(   R   R   R   R   (   RJ   R	   (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyR      s    (   Rk   Rl   R   (    (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyR}      s   c           B   s&   e  Z e e f Z d    Z d   Z RS(   c         C   s   d d k  l } | i |  S(   Ni(   t	   _jit_vref(   t	   pypy.rlibR   t   SomeVRef(   RJ   t   s_objR   (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyRO      s    c         C   s   | i  i |  S(   N(   t   r_resultRj   (   RJ   Rb   (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyRj      s    (   Rk   Rl   R   R}   Rm   RO   Rj   (    (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyR6      s   	c           B   s   e  Z e Z d    Z RS(   c         C   sO   d d k  l } t |  i t  p t  |  i i |  i    } | i |  S(   Ni(   R   (	   R   R   R@   t   instanceR   R   t
   bookkeepert   immutablevalueR   (   RJ   R   R   (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyt   compute_annotation   s    (   Rk   Rl   R   t   _type_R   (    (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyR6      s   t   JitHintErrorc           B   s   e  Z d  Z RS(   s   Inconsistency in the JIT hints.(   Rk   Rl   t   __doc__(    (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyR      s   i   i  t	   thresholdi   t   trace_eagernessi'  t   trace_limitt   inliningt	   optimizert   loop_longevityt	   JitDriverc        	   B   s   e  Z d  Z e Z g  Z d d d d d d d d d  Z d   Z d   Z	 d   Z
 d   Z d   Z d   Z d e _ d	   Z d e _ d
   Z RS(   s  Base class to declare fine-grained user control on the JIT.  So
    far, there must be a singleton instance of JitDriver.  This style
    will allow us (later) to support a single RPython program with
    several independent JITting interpreters in it.
    c	         C   s.  | d  j	 o | |  _ n | d  j	 o | |  _ n t |  d  p t |  d  o t d   n | d  j	 o | |  _ n x( |  i D] }	 |	 |  i j p t  q Wt i g  }
 |  i |  i D] } d | j o |
 | q q ~
  |  _	 |  i
   | |  _ | |  _ | |  _ | |  _ | |  _ d  S(   Nt   greenst   redss   no 'greens' or 'reds' suppliedt   .(   R   R   R   t   hasattrt   AttributeErrort   virtualizablesR   t   dictt   fromkeyst   _alllivevarst   _make_extregistryentriest   get_jitcell_att   set_jitcell_att   get_printable_locationt   confirm_enter_jitt   can_never_inline(   RJ   R   R   R   R   R   R   R   R   Rh   R*   t   name(    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyR     s&    "
 B
				c         C   s   t  S(   N(   R   (   RJ   (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyt   _freeze_3  s    c         K   s$   t  i |  |  i j p t  d  S(   N(   R   R   R   R   (   t   _selft   livevars(    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyt   jit_merge_point6  s    c         K   s$   t  i |  |  i j p t  d  S(   N(   R   R   R   R   (   R   R   (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyt   can_enter_jit:  s    c         C   s   d  S(   N(    (   RJ   (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyt   loop_header>  s    c         C   s   | t  j p t  d  S(   N(   t
   PARAMETERSR   (   RJ   R   RF   (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyt
   _set_paramB  s    c         C   sF   x3 t  D]+ } | | j o |  i | |  d Sq q Wt d   d S(   s%   Set one of the tunable JIT parameter.Ns   no such parameter(   t   unroll_parametersR   t
   ValueError(   RJ   R   RF   t   name1(    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyt	   set_paramG  s     s   specialize:arg(0)c         C   s   x | i  d  D] } | i d  } | i  d  } t |  d j o
 t  n y t | d  } Wn t j
 o
   n X| d } |  i | |  q Wd S(   s   Set the tunable JIT parameters from a user-supplied string
        following the format 'param=value,param=value'.  For programmatic
        setting of parameters, use directly JitDriver.set_param().
        R   t    t   =i   i   i    N(   R   t   stripR   R   R   R   (   RJ   t   textt   st   partsRF   R   (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyt   set_user_paramP  s     

c            s     i    _    i   _   i   _   i   _ d t f   f d     Y} d t f   f d     Y} d t f   f d     Y} d  S(   NR6   c              s   e  Z   i   i f Z RS(    (   Rk   Rl   R   R   Rm   (    (   RJ   (    s!   /64/home/arigo/u/pypy/rlib/jit.pyR6   l  s   c              s   e  Z   i Z RS(    (   Rk   Rl   R   Rm   (    (   RJ   (    s!   /64/home/arigo/u/pypy/rlib/jit.pyR6   o  s   c              s   e  Z   i Z RS(    (   Rk   Rl   R   Rm   (    (   RJ   (    s!   /64/home/arigo/u/pypy/rlib/jit.pyR6   r  s   (   R   R   R   R   t   ExtEnterLeaveMarkert   ExtLoopHeadert   ExtSetParam(   RJ   R6   (    (   RJ   s!   /64/home/arigo/u/pypy/rlib/jit.pyR   b  s    N(   Rk   Rl   R   R   t   activeR   R   R   R   R   R   R   R   R   t   _annspecialcase_R   R   (    (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyR     s"   										t   BaseJitCellc           B   s   e  Z d  Z RS(   (    (   Rk   Rl   t	   __slots__(    (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyR   y  s   R   c           B   s/   e  Z d    Z d   Z g  d  Z d   Z RS(   c         K   s  d d k  l } |  i i d j o |  i |   n |  i i } | i   } | i   g  } | i | i	 D]" } d | j o | d | qk qk ~ } | i   | | j o t
 d |  i | f   n y |  i i | } WnV t j
 o" h  } h  | | <|  i _ n* t j
 o h  } | |  i i | <n Xxs | i   D]e \ }	 }
 | i |	 | i  } | i | |
  }
 | i |
  o t
 d |	 d   n |
 | |	 <qDW| i S(	   Ni(   R7   R   R   t   s_s.   %s expects the following keyword arguments: %ssI   mixing incompatible types in argument %s of jit_merge_point/can_enter_jiti   (   R>   R7   R   Rk   t   annotate_hookst   im_selft   keyst   sortR   R   R   R   t   _jit_annotation_cacheR   t   KeyErrorRU   t   gett   s_ImpossibleValuet   unionoft   isdegeneratedt   s_None(   RJ   RL   RM   t   driverR   R*   R   t   expectedt   cacheRe   Rg   t
   s_previous(    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyRO     s<    
%
 c         K   ss   |  i  i } |  i i t  } |  i } | | i | i |  | | i | i | g |  | | i	 | i |  d  S(   N(
   R   R   R   t   valueoftypeR   t   annotate_hookR   R   R   R   (   RJ   RL   R   t	   s_jitcellt   h(    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyR     s    	c         K   s  | d  j o d  Sn |  i } | i |  } d | i } | } x | D] } d | j o | d | }	 no | i d  \ }
 } | d |
 } | i i |  } |  i i } t | i	 | <| i
   }	 |	 d  j	 p t  | i |	  qH W| i | | |  d  S(   Ns   jitdriver.%sR   R   (   R   R   R   R%   R   RC   t   find_attributet   position_keyR   t   read_locationst   getvalueR   R    t   emulate_pbc_call(   RJ   R   t	   variablesRV   RL   t   bkt   s_funct	   uniquekeyR   t   s_argt   objnamet	   fieldnamet
   s_instancet   attrdeft   position(    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyR     s&    	 c         K   s&  d d k  l } d d k l } |  i i } g  } g  } x-| i D]"} d | j o4 | d | }	 | i |	 }
 | i |
 d |	 } n| i	 i
 i d j o t i i d  n | i d  \ } } | | i j p t  | d | }	 | i |	 } | i |	 } xo t og y | i |  \ } } PWn t j
 o n X| i d  j	 p t d	 | | i i f  | i } q
W| i i } | i |  p t d
 |  t | d  p h  | _ n | | f | i | <| i | d |	 } | i | i |  } | i d | | g d | } | i  i! |  } | d  j	 p t  | i	 i" i# | |  | i$ |  qB WxN | i D]C } | d | }	 | i |	 } | i | d |	 } | i$ |  qrW| i%   | i | i |  i i&  | i | i |  g } | i' |  | i' |  | i d | d | i S(   Ni(   RQ   (   RP   R   RR   R.   t   ootypesystems   lltype onlys   field %r not found in %rs&   field %r must be declared as immutablet   ll_greenfieldst   getfieldRS   t
   jit_marker((   RX   RQ   RT   RP   R   R   R   R\   R[   t   rtypert   type_systemR   R!   t   testt   skipR   R   R   RV   R   t
   _get_fieldR   t   rbaseR   t   lowleveltypet   TOt   _immutable_fieldR   R   R]   R^   R`   RC   t   about_attributet	   annotatort
   setbindingR    R_   Rk   t   extend(   RJ   Rb   Rc   RQ   RP   R   t   greens_vt   reds_vR   R+   t   r_greent   v_greenR   R   t   s_redt   r_redt   mangled_namet   r_fieldt   GTYPEt   v_redt   c_llnamet   s_greent   vlist(    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyRj     sp    
  	
 
(   Rk   Rl   RO   R   R   Rj   (    (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyR   }  s   	$	R   c           B   s   e  Z d    Z d   Z RS(   c         K   s   d d k  l } | i S(   Ni(   R7   (   R>   R7   R   (   RJ   RL   RM   (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyRO     s    c         C   si   d d k  l } |  i i } | i   | i | i d  | i | i |  g } | i d | d | i S(   Ni(   RP   R   R   RS   (   RT   RP   R   R   R_   R]   R^   R`   (   RJ   Rb   RP   R   R  (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyRj     s    
(   Rk   Rl   RO   Rj   (    (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyR     s   	R   c           B   s   e  Z d    Z d   Z RS(   c         C   sH   d d k  l } | i   p t  | i   i |  p t  | i S(   Ni(   R7   (   R>   R7   RW   R   Rq   t   containsR   (   RJ   t   s_nameRg   RM   (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyRO     s    c         C   s   d d k  l } | i   |  i i } | i d i } | i | i d d } | i	 | i
 d  | i	 | i
 |  | i	 | i
 |  | g } | i d | d | i
 S(	   Ni(   RP   i    R.   i   R   R   RS   (   RT   RP   R_   R   R   RV   RZ   R[   Rr   R]   R^   R`   (   RJ   Rb   RP   R   R   t   v_valueR  (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyRj     s    
	(   Rk   Rl   RO   Rj   (    (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pyR     s   	(    (1   R!   t   syst   pypy.rpython.extregistryR    t   pypy.rlib.objectmodelR   R   t   pypy.rlib.unrollR   t   pypy.rlib.nonconstR   R   R   R   R   R   R3   R4   R6   Rn   Rs   Rt   t   maxintRz   R{   R   t	   ExceptionR|   R~   R   R   t   objectR   R}   R   t	   vref_NoneR   t   OPTIMIZER_SIMPLEt   OPTIMIZER_NO_UNROLLt   OPTIMIZER_FULLR   R   R   R   R   R   R   R   R   (    (    (    s!   /64/home/arigo/u/pypy/rlib/jit.pys   <module>   sj   					
	)										
				
					g
