
ёRMc           @   s  d  Z  d d k Z d d k Z d d k Z d d k l Z e   Z d d k l	 Z	 d d k
 l Z d d k l Z d d k l Z l Z l Z d d k l Z d d	 k l Z l Z l Z d d
 k l Z l Z l Z d d k l Z l Z d d k l Z l Z d d k l Z l  Z  l! Z! l" Z" d d k# l$ Z$ d d k% l& Z& d d k' Z' d e f d     YZ( d e f d     YZ) d e) f d     YZ* d e) f d     YZ+ d e* f d     YZ, d e f d     YZ- d e. f d     YZ/ d e* f d     YZ0 d    Z1 d!   Z2 d" e i3 f d#     YZ4 d$ e4 f d%     YZ5 d& e4 f d'     YZ6 d( e4 f d)     YZ7 d* e4 f d+     YZ8 d, e4 f d-     YZ9 d. e4 f d/     YZ: d0 e4 f d1     YZ; d2 e f d3     YZ< d4 e f d5     YZ= d6 e< f d7     YZ> d8 dH d9     YZ? d: e f d;     YZ@ d<   ZA d= dI d>     YZB g  d?  ZC d@   ZD dA   ZE e? d dB  ZG e? ZH eG ZI dC e? f dD     YZJ dE e? f dF     YZK eJ d dG  ZL d S(J   s   

Gateway between app-level and interpreter-level:
* BuiltinCode (call interp-level code from app-level)
* app2interp  (embed an app-level function into an interp-level callable)
* interp2app  (publish an interp-level object to be visible from app-level)

iN(   t   md5(   t   func_with_new_name(   t   OperationError(   t   eval(   t   Functiont   Methodt   ClassMethod(   t   FunctionWithFixedCode(   t   W_Roott   ObjSpacet	   Wrappable(   R
   t
   SpaceCachet   DescrMismatch(   t	   Argumentst	   Signature(   t   NiceCompilet   compile2(   t
   r_longlongt   r_intt   r_ulonglongt   r_uint(   t	   rstackovf(   t   we_are_translatedt   SignatureBuilderc           B   s8   e  Z d  Z d d d d d d  Z d   Z d   Z RS(   t   NOT_RPYTHONc         C   se   | |  _  | d  j	 o | i |  _ n
 | |  _ | d  j o
 g  } n | |  _ | |  _ | |  _ d  S(   N(   t   funct   Nonet   __name__t   namet   argnamest
   varargnamet	   kwargname(   t   selfR   R   R   R   R   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   __init__!   s    		
		c         C   s   |  i  i |  d  S(   N(   R   t   append(   R    t   argname(    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR"   .   s    c         C   s   t  |  i |  i |  i  S(   N(   R   R   R   R   (   R    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt	   signature1   s    N(   R   t
   __module__t   __doc__R   R!   R"   R$   (    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR      s
   		t   UnwrapSpecRecipec           B   s5   e  Z d  Z e e e e e g Z d   Z	 d   Z
 RS(   R   c         G   s   t  | t  o! t |  d | f  | |  n t  | t  o= | d d j o |  i | d |  q |  i | |  nl xh |  i D]A } t | |  o+ t |  d | i f  } | | |  Pq q Wt	 d |  i
 i | f   d  S(   Ns   visit_%si    R    i   s	   visit__%ss'   %s: no match for unwrap_spec element %s(   t
   isinstancet   strt   getattrt   tuplet
   visit_selft   visit_functiont   bases_ordert
   issubclassR   t	   Exceptiont	   __class__(   R    t   elt   argst   typt   visit(    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   dispatch;   s    !
 	c         G   s+   |  i  } x | D] } | | |  q Wd  S(   N(   R6   (   R    t   unwrap_spect   extraR6   R2   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt
   apply_overM   s    	 (   R   R%   R&   R
   R   R	   R   t   objectR.   R6   R9   (    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR'   6   s   	t   UnwrapSpecEmitc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   d |  _  h  |  _ d  S(   Ni    (   t   nt   miniglobals(   R    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR!   T   s    	c         C   s   |  i  } |  i  d 7_  | S(   Ni   (   R<   (   R    R<   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   succX   s    	c         C   s   | i  } | |  i | <| S(   N(   R   R=   (   R    t   objR   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   use]   s    	(   R   R%   R!   R>   R@   (    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR;   R   s   		t   UnwrapSpec_Checkc           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 RS(   c         C   s%   | i  |  _  t | i  i |  _ d  S(   N(   R   t   iterR   t   nextt   orig_arg(   R    t   original_sig(    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR!   i   s    c         C   s    | \ } } |  i  | |  d  S(   N(   R6   (   R    t   .1t   app_sigR   t   cls(    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR-   m   s    	c         C   s   |  i  | |  d  S(   N(   t   visit__Wrappable(   R    RH   RG   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR,   p   s    c         C   sH   |  i    } | i d  p t d | | |  i f  | i |  d  S(   Nt   w_sK   unwrapped %s argument %s of built-in function %r should not start with 'w_'(   RD   t
   startswitht   AssertionErrorR   R"   (   R    t   typnameRG   R#   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   checked_space_methods   s
    c         C   s   |  i  | |  d  S(   N(   RN   (   R    t   indexRG   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   visit_indexz   s    c         C   s   |  i  | |  d  S(   N(   RN   (   R    R2   RG   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   visit_bufferstr}   s    c         C   s   |  i  | |  d  S(   N(   RN   (   R    R2   RG   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   visit_str_or_None   s    c         C   s   |  i  | |  d  S(   N(   RN   (   R    R2   RG   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   visit_nonnegint   s    c         C   s   |  i  | |  d  S(   N(   RN   (   R    R2   RG   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   visit_c_int   s    c         C   s   |  i  | |  d  S(   N(   RN   (   R    R2   RG   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   visit_c_uint   s    c         C   s   |  i  | |  d  S(   N(   RN   (   R    R2   RG   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   visit_c_nonnegint   s    c         C   sQ   | i  } |  i   } | i d  p t d | | |  i f  | i |  d  S(   NRJ   sK   unwrapped %s argument %s of built-in function %r should not start with 'w_'(   R   RD   RK   RL   R   R"   (   R    R2   RG   R   R#   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRI      s    	c         C   s   |  i    d  S(   N(   RD   (   R    R2   RG   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   visit__ObjSpace   s    c         C   sf   | t  j p t d | f  |  i   } | i d  p t d | |  i f  | i | d  d  S(   NsD   %s is not W_Root (forgotten to put .im_func in interp2app argument?)RJ   s:   argument %s of built-in function %r should start with 'w_'i   (   R   RL   RD   RK   R   R"   (   R    R2   RG   R#   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   visit__W_Root   s    c         C   sC   |  i    } | i d  j p t d |  i  d | _ d | _ d  S(   Ns4   built-in function %r has conflicting rest args specsR3   t   keywords(   RD   R   R   RL   R   R   (   R    R2   RG   R#   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   visit__Arguments   s
    	c         C   se   |  i    } | i d  p t d | |  i f  | i d  j p t d |  i  | d  | _ d  S(   Nt   _ws@   rest arguments arg %s of built-in function %r should end in '_w's4   built-in function %r has conflicting rest args specsi(   RD   t   endswithRL   R   R   R   (   R    R2   RG   R#   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   visit_args_w   s    c         C   se   |  i    } | i d  p t d | |  i f  | i d  j p t d |  i  | d | _ d  S(   NRJ   s?   rest arguments arg %s of built-in function %r should start 'w_'s4   built-in function %r has conflicting rest args specsi   (   RD   RK   RL   R   R   R   (   R    R2   RG   R#   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   visit_w_args   s    c         C   s    t  |  } |  i | |  d  S(   N(   t   int_unwrapping_space_methodRN   (   R    R4   RG   R   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   visit__object   s    (   R   R%   R!   R-   R,   RN   RP   RQ   RR   RS   RT   RU   RV   RI   RW   RX   RZ   R]   R^   R`   (    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRA   d   s$   																			t   UnwrapSpec_EmitRunc           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 h  d  Z d   Z e e  Z RS(   c         C   s   t  i |   g  |  _ d  S(   N(   R;   R!   t   run_args(   R    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR!      s    c         C   s   d |  i    S(   Ns   scope_w[%d](   R>   (   R    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt	   scopenext   s    c         C   s9   | \ } } |  i  i d |  i |  |  i   f  d  S(   Ns   %s(%s)(   Rb   R"   R@   Rc   (   R    RF   R   RH   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR-      s    	c         C   s-   |  i  i d |  i |  |  i   f  d  S(   Ns!   space.descr_self_interp_w(%s, %s)(   Rb   R"   R@   Rc   (   R    R4   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR,      s    c         C   s-   |  i  i d |  i |  |  i   f  d  S(   Ns   space.interp_w(%s, %s)(   Rb   R"   R@   Rc   (   R    R4   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRI      s    c         C   s   |  i  i d  d  S(   Nt   space(   Rb   R"   (   R    R2   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRW      s    c         C   s   |  i  i |  i    d  S(   N(   Rb   R"   Rc   (   R    R2   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRX      s    c         C   s7   t  |  i d <|  i i d |  i   |  i   f  d  S(   NR   s#   Arguments.frompacked(space, %s, %s)(   R   R=   Rb   R"   Rc   (   R    R2   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRZ      s    c         C   s   |  i  i d |  i    d  S(   Ns   space.fixedview(%s)(   Rb   R"   Rc   (   R    R2   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR]      s    c         C   s   |  i  i |  i    d  S(   N(   Rb   R"   Rc   (   R    R2   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR^      s    c         C   s0   t  |  } |  i i d | |  i   f  d  S(   Ns   space.%s(%s)(   R_   Rb   R"   Rc   (   R    R4   R   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR`      s    c         C   s!   |  i  i d |  i   f  d  S(   Ns+   space.getindex_w(%s, space.w_OverflowError)(   Rb   R"   Rc   (   R    R4   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRP      s    c         C   s!   |  i  i d |  i   f  d  S(   Ns   space.bufferstr_w(%s)(   Rb   R"   Rc   (   R    R4   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRQ      s    c         C   s!   |  i  i d |  i   f  d  S(   Ns   space.str_or_None_w(%s)(   Rb   R"   Rc   (   R    R4   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRR      s    c         C   s!   |  i  i d |  i   f  d  S(   Ns   space.gateway_nonnegint_w(%s)(   Rb   R"   Rc   (   R    R4   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRS      s    c         C   s!   |  i  i d |  i   f  d  S(   Ns   space.c_int_w(%s)(   Rb   R"   Rc   (   R    R4   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRT      s    c         C   s!   |  i  i d |  i   f  d  S(   Ns   space.c_uint_w(%s)(   Rb   R"   Rc   (   R    R4   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRU      s    c         C   s!   |  i  i d |  i   f  d  S(   Ns   space.c_nonnegint_w(%s)(   Rb   R"   Rc   (   R    R4   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRV     s    c      
   B   sS  y> e  |  } | | \ } } | |  i j p
 t d  | SWne j
 og  } xx | D]p } e | e   oA | i d i g  } | D] }	 | e |	 d |	  q ~   q\ | i e | d |   q\ Wd i |  }
 h  } d d i |  i  f } e |  |  i	 | Ue
 d |
 e f |  } e | _ | |  i f | | <| Sn Xd  S(   Ns)   unexpected: same spec, different run_argst    R   t   _su   if 1: 
                def _run(self, space, scope_w):
                    return self.behavior(%s)
                
s   , s   BuiltinActivation_UwS_%s(   R+   Rb   RL   t   KeyErrorR(   R"   t   joinR*   R   R=   t   typet   BuiltinActivationt   Truet   _immutable_(   R    R7   t   cachet   keyt   activation_factory_clsRb   t   partsR2   t   _[1]t   subelt   labelt   dt   sourcet   activation_cls(    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   _make_unwrap_activation_class  s.     .
	c         C   s/   t    } | i |   | i |   } | |  S(   N(   Ra   R9   Rw   (   R7   R   t   emitt   activation_uw_cls(    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   make_activation$  s    	(   R   R%   R!   Rc   R-   R,   RI   RW   RX   RZ   R]   R^   R`   RP   RQ   RR   RS   RT   RU   RV   Rw   Rz   t   staticmethod(    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRa      s*   																		 	Rj   c           B   s    e  Z e Z d    Z d   Z RS(   c         C   s   | |  _  d S(   R   N(   t   behavior(   R    R|   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR!   /  s    c         C   s   t  d  d S(   sB   Subclasses with behavior specific for an unwrap spec are generatedt   abstractN(   t	   TypeError(   R    Rd   t   scope_w(    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   _run3  s    (   R   R%   Rk   Rl   R!   R   (    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRj   ,  s   	t   FastFuncNotSupportedc           B   s   e  Z RS(    (   R   R%   (    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR   9  s   t   UnwrapSpec_FastFunc_Unwrapc           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 d   Z e e  Z RS(   c         C   s,   t  i |   g  |  _ g  |  _ d |  _ d  S(   Ni    (   R;   R!   R3   t   unwrapt   finger(   R    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR!   >  s    		c         G   s@   t  i |  | |  |  i d 7_ |  i d j o
 t  n d  S(   Ni   i   (   R;   R6   R   R<   R   (   R    R2   R3   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR6   D  s    c         C   s$   d |  i    } |  i i |  | S(   Ns   w%d(   R>   R3   R"   (   R    t   arg(    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   nextargJ  s    c         C   s   | \ } } t   d  S(   N(   R   (   R    RF   R   RH   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR-   O  s    	c         C   s-   |  i  i d |  i |  |  i   f  d  S(   Ns!   space.descr_self_interp_w(%s, %s)(   R   R"   R@   R   (   R    R4   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR,   R  s    c         C   s-   |  i  i d |  i |  |  i   f  d  S(   Ns   space.interp_w(%s, %s)(   R   R"   R@   R   (   R    R4   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRI   V  s    c         C   s.   |  i  d j o
 t  n |  i i d  d  S(   Ni    Rd   (   R   R   R   R"   (   R    R2   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRW   Z  s    
c         C   s   |  i  i |  i    d  S(   N(   R   R"   R   (   R    R2   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRX   _  s    c         C   s
   t   d  S(   N(   R   (   R    R2   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRZ   b  s    c         C   s
   t   d  S(   N(   R   (   R    R2   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR]   e  s    c         C   s
   t   d  S(   N(   R   (   R    R2   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR^   h  s    c         C   s0   t  |  } |  i i d | |  i   f  d  S(   Ns   space.%s(%s)(   R_   R   R"   R   (   R    R4   R   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR`   k  s    c         C   s   |  i  i d |  i    d  S(   Ns+   space.getindex_w(%s, space.w_OverflowError)(   R   R"   R   (   R    R4   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRP   p  s    c         C   s!   |  i  i d |  i   f  d  S(   Ns   space.bufferstr_w(%s)(   R   R"   R   (   R    R4   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRQ   t  s    c         C   s!   |  i  i d |  i   f  d  S(   Ns   space.str_or_None_w(%s)(   R   R"   R   (   R    R4   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRR   w  s    c         C   s!   |  i  i d |  i   f  d  S(   Ns   space.gateway_nonnegint_w(%s)(   R   R"   R   (   R    R4   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRS   z  s    c         C   s!   |  i  i d |  i   f  d  S(   Ns   space.c_int_w(%s)(   R   R"   R   (   R    R4   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRT   }  s    c         C   s!   |  i  i d |  i   f  d  S(   Ns   space.c_uint_w(%s)(   R   R"   R   (   R    R4   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRU     s    c         C   s!   |  i  i d |  i   f  d  S(   Ns   space.c_nonnegint_w(%s)(   R   R"   R   (   R    R4   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRV     s    c         B   s5  e    } | i |   | i } d g | i } | | i j o
 | } n | i d j o
 e  n | i i d  oI | i i d  o5 | i i d  o! | i i d  p
 e  q n h  } | | i	 d <d | i | d	 i
 |  d	 i
 | i  f } e |  | i	 | U| d
 | i | f } | | f S(   NRd   s    pypy.interpreter.astcompiler.asts   pypy.module.__builtin__s   pypy.module.syss   pypy.module.matht   descrR   sd   if 1: 
                def fastfunc_%s_%d(%s):
                    return func(%s)
                
s   , s   fastfunc_%s_%d(   R   R9   R<   R3   R   R%   R   RK   R   R=   Rh   R   (   R7   R   t   unwrap_infot   nargR3   t   fastfuncRt   Ru   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   make_fastfunc  s*    		

(   R   R%   R!   R6   R   R-   R,   RI   RW   RX   RZ   R]   R^   R`   RP   RQ   RR   RS   RT   RU   RV   R   R{   (    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR   <  s*   																				c      	   C   s   |  t  t t t t t t t f j p t  |  t	 j o
 t j n o d Sn5 |  t t t f j o |  i
 d Sn d |  i
 d Sd  S(   Nt   gateway_r_longlong_wR[   t   gateway_(   t   intR)   t   floatt   unicodeR   R   R   t   boolRL   R   R   (   R4   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR_     s    ,c             s     f d   } | S(   s5   A decorator which attaches the unwrap_spec attribute.c            s     |  _  |  S(   N(   R7   (   R   (   t   spec(    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt	   decorator  s    	(    (   R   R   (    (   R   s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR7     s    t   BuiltinCodec           B   s   e  Z d  Z e Z e Z d Z d Z d d g Z	 d d d d  Z
 d   Z d   Z e e  Z d   Z d   Z d   Z d	   Z d
   Z RS(   sA   The code object implementing a built-in (interpreter-level) hook.t   _bltint   _unwrap_specc      	   C   s  t  i i |  | i  | i |  _ d | i | i t | d d  f |  _ d d k	 l
 } | i | i  \ } } } | d j o t | d d  } n | d j o> t g t g t |  d } | o d g | d } q n | o | d	 d j p
 t d
  t |  } | d j	 o= t | t  p t  d | f | d	 <| |  _ | |  _ q| | d	 <n | d j p
 t d  t | | | |  }	 t |  }
 t |	  i | |
  |
 i   |  _ \ } } } t |  |  _ | o t i |  _ n |  i |  _ t  i! | |  |  _" | |  _# | |  _$ d	 t |  j o
 d j n o y t% i& | |  \ } } Wnh t' j
 o\ | t t( g j o t) |  _* | |  _+ q| t t t( g j o t, |  _* | |  _+ qqXt-   d | |  _* t. |  d | |  n d S(   R   s   %s-%s-%sR   t   *i(   t   pycodeR7   i   R    i    s%   self_type without 'self' spec elements+   descrmismatch without a self-type specifiedi   s   BuiltinCode%ds   fastfunc_%dN(/   R   t   CodeR!   R   R&   t	   docstringR%   R*   t
   identifiert   pypy.interpreterR   t   cpython_code_signaturet	   func_codeR   R	   R   t   lenRL   t   listR/   R
   t   descrmismatch_opt   descr_reqclsR   RA   R9   R$   t   sigt   minargst   syst   maxintt   maxargsRa   Rz   t
   activationR   R   R   R   R   R   t    BuiltinCodePassThroughArguments0R1   t   func__args__t    BuiltinCodePassThroughArguments1t   globalst   setattr(   R    R   R7   t	   self_typet   descrmismatchR   R   R   R   t   orig_sigRG   t   arityR   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR!     s`    			$		c         C   sk   d d k  l } | i d  } | i | |  } | i d  } | i | | i | i |  i  g  g  S(   Ni(   t   MixedModulet   _pickle_supportt   builtin_code(   t   pypy.interpreter.mixedmoduleR   t   getbuiltinmodulet   interp_wt   gett   newtuplet   wrapR   (   R    Rd   R   t   w_modt   modR   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   descr__reduce__  s    	c         C   s   d d k  l } | i |  i S(   Ni(   R   (   t   pypy.interpreter.functionR   t   _allt   code(   t   indentifierR   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   find  s    c         C   s   |  i  S(   N(   R   (   R    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR$   #  s    c         C   s   | i  |  i  S(   N(   R   R   (   R    Rd   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   getdocstring&  s    c         C   s   t  i |  | d  |  S(   N(   R   t   funcrun_objR   (   R    R   R3   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   funcrun)  s    c   	      C   s   | i  } |  i } | i | | i |  i | i |  i  } y | i | |  } Wny t j
 oG | d  j	 o | i
 |  } n | d i | |  i |  i |  Sn( t j
 o } |  i | |   n X| d  j o | i } n | S(   Ni    (   Rd   R   t	   parse_objR   R   t   defs_wR   R   R   R   t   prependt   descr_call_mismatchR   R   R0   t   handle_exceptiont   w_None(	   R    R   t   w_objR3   Rd   R   R   t   w_resultt   e(    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR   ,  s$    		c         C   s   y t    p   n |  Wn t j
 o t | i | i   nz t j
 o t | i | i   nS t i j
 o } t i	   | i
  n) t j
 o t | i | i   n Xd  S(   N(   R   t   KeyboardInterruptR   t   w_KeyboardInterruptR   t   MemoryErrort   w_MemoryErrorR   t   StackOverflowt   check_stack_overflowt   prebuilt_recursion_errort   RuntimeErrort   w_RuntimeError(   R    Rd   R   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR   @  s    

	
N(   R   R%   R&   Rk   Rl   t   hidden_applevelR   R   R   t   NOT_RPYTHON_ATTRIBUTESR!   R   R   R{   R$   R   R   R   R   (    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR     s    T						R   c           B   s   e  Z e Z d    Z RS(   c         C   s   | i  } y |  i | |  } Wn[ t j
 o) | i   i | |  i |  i |  Sn( t j
 o } |  i | |   n X| d  j o | i
 } n | S(   N(   Rd   R   R   t   firstargR   R   R   R0   R   R   R   (   R    R   R3   Rd   R   R   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR   U  s    	(   R   R%   Rk   Rl   R   (    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR   R  s   R   c           B   s#   e  Z e Z e i i Z d    Z RS(   c         C   s   | i  } y |  i | | |  } Wnd t j
 o2 | i   i | |  i |  i | i |   Sn( t j
 o } |  i	 | |   n X| d  j o | i } n | S(   N(   Rd   R   R   R   R   R   R   R   R0   R   R   R   (   R    R   R   R3   Rd   R   R   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR   h  s    	(	   R   R%   Rk   Rl   R   R   t   PASSTHROUGHARGS1t   fast_natural_arityR   (    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR   d  s   t   BuiltinCode0c           B   s   e  Z e Z d  Z d   Z RS(   i    c         C   s   y |  i  |  } WnT t j
 o" t | i | i d    n( t j
 o } |  i | |   n X| d  j o | i } n | S(   Ns   unexpected DescrMismatch error(	   t
   fastfunc_0R   R   t   w_SystemErrorR   R0   R   R   R   (   R    Rd   t   w_funcR   R   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt
   fastcall_0{  s    	(   R   R%   Rk   Rl   R   R   (    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR   w  s   t   BuiltinCode1c           B   s   e  Z e Z d  Z d   Z RS(   i   c         C   s   y |  i  | |  } Wna t j
 o/ | i | |  i |  i t | | g   Sn( t j
 o } |  i | |   n X| d  j o | i	 } n | S(   N(
   t
   fastfunc_1R   R   R   R   R   R0   R   R   R   (   R    Rd   R   t   w1R   R   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt
   fastcall_1  s    	(   R   R%   Rk   Rl   R   R   (    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR     s   t   BuiltinCode2c           B   s   e  Z e Z d  Z d   Z RS(   i   c         C   s   y |  i  | | |  } Wnd t j
 o2 | i | |  i |  i t | | | g   Sn( t j
 o } |  i | |   n X| d  j o | i	 } n | S(   N(
   t
   fastfunc_2R   R   R   R   R   R0   R   R   R   (   R    Rd   R   R   t   w2R   R   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt
   fastcall_2  s    	(   R   R%   Rk   Rl   R   R   (    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR     s   t   BuiltinCode3c           B   s   e  Z e Z d  Z d   Z RS(   i   c      	   C   s   y |  i  | | | |  } Wng t j
 o5 | i | |  i |  i t | | | | g   Sn( t j
 o } |  i | |   n X| d  j o | i	 } n | S(   N(
   t
   fastfunc_3R   R   R   R   R   R0   R   R   R   (   R    Rd   R   R   R   t   w3R   R   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt
   fastcall_3  s    	(   R   R%   Rk   Rl   R   R   (    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR     s   t   BuiltinCode4c           B   s   e  Z e Z d  Z d   Z RS(   i   c   	   
   C   s   y |  i  | | | | |  } Wnj t j
 o8 | i | |  i |  i t | | | | | g   Sn( t j
 o } |  i | |   n X| d  j o | i	 } n | S(   N(
   t
   fastfunc_4R   R   R   R   R   R0   R   R   R   (	   R    Rd   R   R   R   R   t   w4R   R   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt
   fastcall_4  s    	(   R   R%   Rk   Rl   R   R   (    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR     s   t
   interp2appc           B   sV   e  Z d  Z d g Z h  Z d d d e d  Z d   Z d   Z	 d   Z
 d   Z RS(   s/   Build a gateway that calls 'f' at interp-level.t   _staticdefsc         C   s}  d } t | d  o | i } | i } n t | t i  p t d |  n | d j o4 | i i	 d  o t
 d | i  n | i } n | d j	 o t |  } n d } | | | | | f } | |  i j o, |  i | }	 |	 i |  j p t  |	 Sn t i |   }
 |
 |  i | <t | d | d | d | |
 _ | i |
 _ | |
 _ | |
 _ t | i p d	  |
 _ |
 S(
   R   t   im_funcs!   function expected, got %r insteadt   app_s0   function name %r suspiciously starts with 'app_'R7   R   R   N(    (   R   t   hasattrt   im_classR   R(   t   typest   FunctionTypeR~   t	   func_nameRK   t
   ValueErrorR+   t   instancecacheR1   RL   R
   t   __new__R   t   _codeR   R   t   as_classmethodR   t   func_defaultsR   (   RH   t   ft   app_nameR7   R   R   R   t   unwrap_spec_keyRn   t   resultR    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR     s:    			c         C   sR   g  } xE |  i  D]: } | t j o | i d  q | i | i |   q W| S(   R   N(   R   t   NoneNotWrappedR"   R   R   (   R    Rd   R   t   val(    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   _getdefaults  s    
 c         C   s   |  i  |  S(   N(   t   get_function(   R    Rd   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   __spacebind__  s    c         C   s   |  i  |  i |   S(   N(   t   getcachet
   getorbuild(   R    Rd   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR    s    c         C   s   | i  t  S(   N(   t	   fromcachet   GatewayCache(   R    Rd   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR
    s    N(   R   R%   R&   R   R   R   t   FalseR   R  R	  R  R
  (    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR     s   	$			R  c           B   s   e  Z d    Z RS(   c         C   s   |  i  } | i |  } | i } t | | d | d | i } | i i p | i   n | i	 o t
 | i |   } n | S(   R   t	   forcenameN(   Rd   R  R   R   R   R   t   configt   translatingt   add_to_tableR   R   R   (   Rm   t   gatewayRd   t   defsR   t   fn(    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   build  s    		
(   R   R%   R  (    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR    s   t   interp2app_tempc           B   s   e  Z d  Z d   Z RS(   R   c         C   s   |  i  i | t |   S(   N(   t   __dict__t
   setdefaultR  (   R    Rd   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR
  2  s    (   R   R%   R&   R
  (    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR  0  s   t   ApplevelClassc           B   s\   e  Z d  Z e Z d
 d d  Z d   Z d   Z d d  Z	 d   Z
 d   Z d	   Z RS(   s   NOT_RPYTHON
    A container for app-level source code that should be executed
    as a module in the object space;  interphook() builds a static
    interp-level function that invokes the callable with the given
    name at app-level.t   __builtin__c   	      C   s   | d  j o, t i d  } d | i i | i f } n | |  _ t t i	 i
 |  i    |  _ | |  _ d i | i d d  d   } d | j o t |  _ n
 t |  _ g  } | i d  D] } | | d q ~ } d d  | | f t i i i | <d  S(   Ni   s   <%s:%d>s   
i   R   (   R   R   t	   _getframet   f_codet   co_filenamet   f_linenot   filenameR)   t   pyR   t   Sourcet   deindentRu   t   modnameRh   t   splitR  t   can_use_geninterpRk   t   stdt	   linecacheRm   (	   R    Ru   R   R$  R  t   firstRq   t   xt   lines(    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR!   B  s    	!		.c         C   s   d |  i  |  i f S(   Ns0   <ApplevelClass filename=%r can_use_geninterp=%r>(   R   R&  (   R    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   __repr__T  s    c         C   s   | i  t  i |   S(   N(   R  t   ApplevelCacheR  (   R    Rd   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   getwdictW  s    t   applevelc         C   s2   d d k  l } | | | i |  |  i |   S(   Ni(   t   Module(   t   pypy.interpreter.moduleR0  R   R.  (   R    Rd   R   R0  (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   buildmoduleZ  s    c         C   s(   |  i  |  } | i | | i |   S(   N(   R.  t   getitemR   (   R    Rd   R   t	   w_globals(    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   wget^  s    c            s@      f d   }    f d   } t  |   } | | _ | S(   R   c            s]  t  |  t  p t d   n t |  d  oL |  i } t | j o2 | t |     |  } | d  j	 o | Sqx q| n  i |     } | p |  i |  Sn | d } | d  j	 p t	  t  | t
  p |  i | |  Snf t |  d j o |  i | | d |  Sn8 t |  d j o$ | i t | d   | i  } n |  i | |  S(   Ns(   first argument must be a space instance.t   specialcasesii   i    (   R(   R	   R~   R   R6  R  R   R5  t   call_functionRL   R   R   t   call_obj_argst   replace_argumentsR   t   arguments_wt	   call_args(   Rd   t   args_wt   sct   ret_wR   R3   (   R   R    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt	   appcallerd  s*    	
c            s     i  |    } |  i |  S(   N(   R5  R   (   Rd   R   (   R    R   (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR    s    (   R   R  (   R    R   R?  R  (    (   R    R   s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt
   interphookb  s
    	c         C   s   t  S(   N(   Rk   (   R    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   _freeze_  s    N(   R   R%   R&   Rk   R   R   R!   R,  R.  R2  R5  R@  RA  (    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR  9  s   				&R-  c           B   s   e  Z d  Z d   Z RS(   sS   NOT_RPYTHON
    The cache mapping each applevel instance to its lazily built w_dictc         C   sH   |  i  i i i o! | i o t i | |  i   Sn t | |  i   Sd S(   s7   NOT_RPYTHON.  Called indirectly by Applevel.getwdict().N(   Rd   R  t   objspacet	   geninterpR&  t   PyPyCacheDirt   build_applevelinterp_dictt   build_applevel_dict(   R    t   app(    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR    s    (   R   R%   R&   R  (    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR-    s   c         C   sf   | i  d t  } | i | | i d  | i |  i   | i |  i | | d |  i d |  i | S(   R   t   moduleR   R   R   (	   t   newdictRk   t   setitemR   R$  t   exec_Ru   R   R   (   R    Rd   t   w_glob(    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRF    s    (	
RD  c           B   s>   e  Z d  Z d   Z e e  Z e Z d   Z e e  Z RS(   R   c      
   C   s  |  i  p |  i   n d d k l } d d k } t |  i  } | i | i | i	   | i
   } |  i i |  } | p | } | i o) t i i t i i | i   d }	 n d }	 d |	 | f } y t d |  Wn t j
 o	 }
 qX|  i | } n | p | | i	 | i | i  \ } } |  i i | d  i } t t |  d	  } | d
 | IJ| J| | IJ| d IJ| d | | i f IJ| i   t |  n | |  } | S(   R   i(   t   translate_as_moduleNi    t   zznonames   %s_%ss   pypy._cache.s   .pyt   ws5  # self-destruct on double-click:
if __name__ == "__main__":
    from pypy import _cache
    import os
    namestart = os.path.join(os.path.split(_cache.__file__)[0], '%s')
    for ending in ('.py', '.pyc', '.pyo'):
        try:
            os.unlink(namestart+ending)
        except os.error:
            passs"   from pypy._cache import known_codes   known_code[%r] = %s(   t   _setup_donet   _setupt   pypy.translator.geninterplevelRM  t   marshalR    t   seedt   updatet   dumpsRu   t	   hexdigestt
   known_codeR   R   t   ost   patht   splitextt   basenamet
   __import__t   ImportErrorR$  t
   cache_pathRh   t   strpatht   filet   get_tmp_file_nameR   t   closet    rename_tmp_to_eventual_file_name(   RH   R    Rd   RM  RS  t   scrambleRn   t   initfuncR   t   prenameR*  t   newsrct   fnameR  RL  (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRE    sD    

)




c         C   s  t  i i } d d k } d d k } | | i  i d d  i d d  } | |  _ | i	 d  } y1 | i
   p
 t  n d d k l } l } Wn t j
 o d	 } n Xd d
 k l } t t |   i   |  _ | | j p | d j o xC | i   D]5 }	 |	 i
 d d  o y |	 i   Wq7q7XqqWt t t |   d  }
 |
 i d |  |
 i   t t |   n d d k } | i i |  _ t |  _ d S(   R   iNR\  t   _cachet   diri   s   __init__.py(   RX  t   GI_VERSION_RENDEREDi    (   t
   GI_VERSIONRa  RO  s  # This folder acts as a cache for code snippets which have been
# compiled by compile_as_module().
# It will get a new entry for every piece of code that has
# not been seen, yet.
#
# Caution! Only the code snippet is checked. If something
# is imported, changes are not detected. Also, changes
# to geninterplevel or gateway are also not checked.
# Exception: There is a checked version number in geninterplevel.py
#
# If in doubt, remove this file from time to time.

GI_VERSION_RENDERED = %r

known_code = {}

# self-destruct on double-click:
def harakiri():
    import pypy._cache as _c
    import py
    lp = py.path.local
    for pth in lp(_c.__file__).dirpath().listdir():
        try:
            pth.remove()
        except: pass

if __name__ == "__main__":
    harakiri()

del harakiri
(    R!  RZ  t   localt   pypyRY  t   __file__t   newt   ensureR_  Rh   t   checkR^  t   pypy._cacheRX  Rl  RR  Rm  R    R)   t   digestRT  R   t   listdirt   removeRa  Rb  t   writeRc  Rd  Rj  Rk   RP  (   RH   t   lpRo  RY  t   pt   iniRX  Rl  Rm  t   pthR  (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRQ    s:    '	
  
(   R   R%   R&   RE  t   classmethodR  RP  RQ  (    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRD    s   	5	<c         C   sL   |  p= y d d  k  } | i   } Wn d } n X|  i |  n |  d S(   NiRe   i    (   t   sockett   gethostnameR"   (   Rj  R~  t   hostname(    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR  "  s    
c         C   s   d |  t    t i   f S(   Ns   %s~%s~%d(   R  RY  t   getpid(   Ri  (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRb  ,  s    c         C   s]   t  |   } y t i | |   Wn6 t t f j
 o$ t i |   t i | |   n Xd  S(   N(   Rb  RY  t   renamet   OSErrort   IOErrort   unlink(   Ri  t   tmpname(    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyRd  /  s    c         C   s  t  |  t  p t i i i |   i   }  xF |  i d  o5 d |  j p t  |  |  i	 d  d i   }  q. W|  i d  p
 t d  |  d }  n |  i	 d  } | d j p t  |  |  i
   } |  | }  |  i
   p t  d	 | |  f } | | d
 | } | i |  S(   s    NOT_RPYTHON: build an app-level helper function, like for example:
    myfunc = appdef('''myfunc(x, y):
                           return x+y
                    ''')
    s   @py.test.mark.s   
i   s   def s   can only transform functionsi   t   (i    s	   def %s%s
R   (   R(   R)   R!  R'  t   inspectt	   getsourcet   lstripRK   RL   R   t   stripR@  (   Ru   R/  R   Rz  t   funcnamet
   funcsourcet   a(    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   appdef<  s      "
t   applevel_tempc           B   s   e  Z e Z d    Z RS(   c         C   s   t  |  |  S(   N(   RF  (   R    Rd   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR.  [  s    (   R   R%   R  R   R.  (    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR  Y  s   t   applevelinterp_tempc           B   s   e  Z e Z d    Z RS(   c         C   s   t  i |  |  S(   N(   RD  RE  (   R    Rd   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR.  a  s    (   R   R%   R  R   R.  (    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyR  _  s   c         C   s   t  |  | d | S(   s    NOT_RPYTHON R   (   R  (   R   R  R   (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pyt   app2interp_tempe  s    (    (    (M   R&   R   R   RY  t   pypy.tool.compatR    R:   R  t   pypy.tool.sourcetoolsR   t   pypy.interpreter.errorR   R   R   R   R   R   R   R   t   pypy.interpreter.baseobjspaceR   R	   R
   R   R   t   pypy.interpreter.argumentR   R   R   R   t   pypy.rlib.rarithmeticR   R   R   R   t	   pypy.rlibR   t   pypy.rlib.objectmodelR   R!  R   R'   R;   RA   Ra   Rj   R0   R   R   R_   R7   R   R   R   R   R   R   R   R   R   R   R  R  R  R-  RF  RD  R  Rb  Rd  R   R  R/  t
   app2interpR  R  R  (    (    (    s,   /64/home/arigo/u/pypy/interpreter/gateway.pys   <module>   sd   $	"\lg	
	M	S	}
		
