
ёRMc           @   s  d  Z  d d k Z d d k Z d d k Z d d k Z 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 l Z d d k l Z l Z l Z l Z l Z l Z l Z l 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# l$ Z$ d   Z% e i& d e i'    \ Z( d Z) d   Z* d e i+ f d     YZ, d S(   s   
Python-style code objects.
PyCode instances have the same co_xxx arguments as CPython code objects.
The bytecode interpreter itself is implemented by the PyFrame class.
iN(   t   eval(   t	   Signature(   t   OperationError(   t   NoneNotWrapped(   t   ObjSpacet   W_Root(   t   CO_OPTIMIZEDR   t   CO_NEWLOCALSt
   CO_VARARGSt   CO_VARKEYWORDSt	   CO_NESTEDt   CO_GENERATORt   CO_CONTAINSGLOBALS(   t   intmask(   t   make_sure_not_resized(   t   jit(   t   compute_hash(   t
   opcodedesct   HAVE_ARGUMENTc         C   s1   g  } |  i  |  D] } | |  i |  q ~ S(   N(   t   unpackiterablet   str_w(   t   spacet   w_str_tuplet   _[1]t   w_el(    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyt   unpack_str_tuple   s    s   <ii
i   i  
c         C   s   |  i  } | d j p t  t |  i |   } |  i t @o |  i | } | d 7} n d } |  i t @o |  i | } | d 7} n d } t | | |  S(   s?   ([list-of-arg-names], vararg-name-or-None, kwarg-name-or-None).i    i   N(	   t   co_argcountt   AssertionErrort   listt   co_varnamest   co_flagsR   t   NoneR	   R   (   t   codet   argcountt   argnamest
   varargnamet	   kwargname(    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyt   cpython_code_signature$   s    	t   PyCodec           B   s  e  Z d  Z e Z d d d d d g Z e e d  Z d   Z	 d   Z
 d	   Z e d
    Z d   Z e e d! 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" e# e# e# e# e$ e" e" e" e$ e$ e# e$ e" e" e# g Z% e& e& e d  Z' e% e' _% d   Z( d   Z) d   Z* d  e! g e* _% RS("   s   CPython-style code objects.s   co_consts_w[*]s   co_names_w[*]s   co_varnames[*]s   co_freevars[*]s   co_cellvars[*]c         C   s   | |  _  t i i |  |  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _	 g  } | D] } | | i
 |  q] ~ |  _ |	 |  _ | |  _ | |  _ |
 |  _ | |  _ | |  _ | |  _ | |  _ | |  _ t |   |  _ |  i   d S(   sO   Initialize a new code object from parameters given by
        the pypy compilerN(   R   R    t   Codet   __init__R   t
   co_nlocalst   co_stacksizeR   t   co_codet   co_consts_wt   new_interned_strt
   co_names_wR   t   co_freevarst   co_cellvarst   co_filenamet   co_namet   co_firstlinenot	   co_lnotabt   hidden_applevelt   magicR%   t
   _signaturet   _initialize(   t   selfR   R!   t   nlocalst	   stacksizet   flagsR    t   constst   namest   varnamest   filenamet   namet   firstlinenot   lnotabt   freevarst   cellvarsR5   R6   R   t   aname(    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyR(   ;   s(    							-									c         C   sX  |  i    g  |  _ |  i o |  i } | d j p t  |  i t @o | d 7} n |  i t @o | d 7} n |  i } |  i } x t	 t
 |   D]w } | | } xd t	 |  D]V } | | | j o? x+ t
 |  i  | j o |  i i d  q W| |  i | <q q Wq Wn |  i   |  i i i i i o d d k l } | |   n d  S(   Ni    i   i(   t   init_mapdict_cache(   t   _init_flagst   _args_as_cellvarsR0   R   R   R   R   R	   R   t   ranget   lent   appendt   _compute_flatcallR   t   configt   objspacet   stdt   withmapdictt   pypy.objspace.std.mapdictRG   (   R9   R!   t   argvarsRE   t   it   cellnamet   jRG   (    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyR8   V   s2    
	
	
		 
  
c         C   s4   |  i  t j o  d t i j o t d   n t S(   Nt   __pypy__s)   CPython host codes should not be rendered(   R6   t   cpython_magict   syst   builtin_module_namest	   Exceptiont   False(   R9   (    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyt   _freeze_|   s    c         C   s   |  i  } d } x | t |  j  o t | |  } | d 7} | t j o | d 7} n x2 | t i i j o t | |  } | d 7} q] W| t i i j o |  i t	 O_ q | t i
 i j o |  i t	 O_ q q Wd  S(   Ni    i   i   i   (   R+   RK   t   ordR   R   t   EXTENDED_ARGt   indext   LOAD_GLOBALR   R   t	   LOAD_NAME(   R9   R+   t
   next_instrt   opcode(    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyRH      s     	 
 c         C   s.   g  } |  i  D] } | |  i i |  q ~ S(    (   R.   R   t   unwrap(   R9   R   t   w_name(    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyt   <lambda>   s    c         C   s   |  i  S(   N(   R7   (   R9   (    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyt	   signature   s    c         C   s'  t  | t i  p t  d g t | i  } d } | d j o |  i } n xZ | i D]O } t  | t i  o | | | | |  } n | i |  | | <| d 7} qZ W|  | | i	 | i
 | i | i | i | t | i  t | i  | i | i | i | i t | i  t | i  | t  S(   s    Initialize the code object from a real (CPython) one.
            This is just a hack, until we have our own compile.
            At the moment, we just fake this.
            This method is called by our compile builtin function.
        i    i   N(   t
   isinstancet   typest   CodeTypeR   R   RK   t	   co_constst
   _from_codet   wrapR   R)   R*   R   R+   R   t   co_namesR   R1   R2   R3   R4   R/   R0   RX   (   t   clsR   R    R5   t	   code_hookt   newconsts_wt   numt   const(    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyRm      s4    
 c         C   sy   t  i i |  _ |  i t t B@o d  Sn t |  i  d j o d  Sn |  i	 d j o d  Sn t  i i
 |  i	 B|  _ d  S(   Ni    i   (   R    R'   t   HOPELESSt   fast_natural_arityR   R   R	   RK   RI   R   t
   FLATPYCALL(   R9   (    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyRM      s    c         C   sz   |  i  i |  | i | i  } |  i } t i | d t d t } | i d  | i
 | i | | i  } | i   | i   S(   Nt   access_directlyt   fresh_virtualizable(   R   t   createframet   w_func_globalst   closureR7   R   t   hintt   Truet   parse_into_scopeR   t   fastlocals_wRA   t   defs_wt
   init_cellst   run(   R9   t   funct   argst   framet   sigt   fresh_framet   args_matched(    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyt   funcrun   s    		
c         C   sz   |  i  i |  | i | i  } |  i } t i | d t d t } | i | | i	 | i
 | | i  } | i   | i   S(   NRx   Ry   (   R   Rz   R{   R|   R7   R   R}   R~   R   R   RA   R   R   R   (   R9   R   t   w_objR   R   R   R   R   (    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyt   funcrun_obj   s    		
c         C   s   |  i  S(   N(   R   (   R9   (    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyt   getvarnames   s    c         C   sI   |  i  o8 |  i  d } | i | i | | i   o | SqB n | i S(   Ni    (   R,   t   is_trueRi   t   w_basestringt   w_None(   R9   R   t   w_first(    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyt   getdocstring   s
    
c         C   s   d g t |  i  } d } xU |  i D]J } t | t  o | i   | | <n |  i i |  | | <| d 7} q& Wt i	 |  i
 |  i |  i |  i |  i t |  t |  i  t |  i  |  i |  i |  i |  i t |  i  t |  i   S(   s   For debugging only.i    i   N(   R   RK   R,   Ri   R&   t   _to_codeR   Re   t   newR    R   R)   R*   R   R+   t   tupleRo   R   R1   R2   R3   R4   R/   R0   (   R9   R=   Rs   t   w(    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyR      s,    
 	c         C   s?   d d k  l } | |  i |  | d   } | i |  | i   S(   Ni(   t   CPythonFrame(   t   pypy.interpreter.pyframeR   R   R   t   setdictscopeR   (   R9   t   w_dictt	   w_globalst   w_localsR   R   (    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyt   exec_host_bytecode  s    c         C   s   |  i    } t i |  d S(   s$   A dis.dis() dump of the code object.N(   R   t   dis(   R9   t   co(    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyt   dump
  s    c         C   s   |  i  | i  S(   N(   t   newtupleR,   (   R   R9   (    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyt   fget_co_consts  s    c         C   s   |  i  | i  S(   N(   R   R.   (   R   R9   (    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyt   fget_co_names  s    c         C   s4   |  i  g  } | i D] } | |  i |  q ~  S(   N(   R   R   Rn   (   R   R9   R   RA   (    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyt   fget_co_varnames  s    c         C   s4   |  i  g  } | i D] } | |  i |  q ~  S(   N(   R   R0   Rn   (   R   R9   R   RA   (    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyt   fget_co_cellvars  s    c         C   s4   |  i  g  } | i D] } | |  i |  q ~  S(   N(   R   R/   Rn   (   R   R9   R   RA   (    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyt   fget_co_freevars  s    c         C   s  |  i  } | i |  } t | t  p | i Sn |  i | i j o |  i | i j o |  i | i j o |  i | i j o |  i	 | i	 j o |  i
 | i
 j ot t |  i  t | i  j oU t |  i  t | i  j o6 |  i | i j o# |  i | i j o |  i | i j } | p | i Sn xI t t |  i   D]2 } | i |  i | | i |  p | i SqCqCWxI t t |  i   D]2 } | i |  i | | i |  p | i SqqW| i S(   N(   R   t   interpclass_wRi   R&   t   w_FalseR2   R   R)   R   R3   R+   RK   R,   R.   R   R/   R0   RJ   t   eq_wt   w_True(   R9   t   w_otherR   t   othert   areEqualRT   (    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyt   descr_code__eq__  s4    	 ! !c         C   sB  |  i  } t |  i  } | |  i N} | |  i N} | |  i N} | |  i N} | t |  i  N} x! |  i D] } | t |  N} qi Wx! |  i	 D] } | t |  N} q Wx! |  i
 D] } | t |  N} q W| i t |   } x, |  i D]! } | i | | i |   } q Wx, |  i D]! } | i | | i |   } qW| S(   N(   R   R   R2   R   R)   R   R3   R+   R   R/   R0   Rn   R   R.   t   xort   hashR,   (   R9   R   t   resultRA   t   w_resultRf   t   w_const(    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyt   descr_code__hash__;  s0    	
  
  
  
 
 c         C   so  | d j  o t  |  i |  i d    n | d j  o t  |  i |  i d    n |  i |  i | |  i   p t  |  i |  i d    n |  i |  } t |  |  } t |  |	  } | d  j	 o t |  |  } n g  } | d  j	 o t |  |  } n g  } |  i
 t |  } t i | |  | | | | | | | | |
 | | | | | d | |  i |  S(   Ni    s#   code: argcount must not be negatives"   code: nlocals must not be negatives   Expected tuple for constantsR6   (   R   t   w_ValueErrorRn   R   Ri   t   w_tuplet   w_TypeErrort	   fixedviewR   R   t   allocate_instanceR&   R(   (   R   t	   w_subtypeR!   R:   R;   R<   t
   codestringt   w_constantst   w_namest
   w_varnamesR@   RA   RB   RC   t
   w_freevarst
   w_cellvarsR6   t   consts_wR>   R?   RD   RE   R    (    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyt   descr_code__new__U  s,    			"c         C   s  d d k  l } | i d  } | i | |  } | i d  } | i } | |  i  | |  i  | |  i  | |  i	  | |  i
  | i |  i  | i |  i  | i g  } |  i D] } | | |  q ~  | |  i  | |  i  | |  i  | |  i  | i g  }	 |  i D] } |	 | |  q~	  | i g  }
 |  i D] } |
 | |  qG~
  | |  i  g } | i | | i |  g  S(   Ni(   t   MixedModulet   _pickle_supportt   code_new(   t   pypy.interpreter.mixedmoduleR   t   getbuiltinmodulet   interp_wt   getRn   R   R)   R*   R   R+   R   R,   R.   R   R1   R2   R3   R4   R/   R0   R6   (   R9   R   R   t   w_modt   modt   new_instR   R   t   vt   _[2]t   _[3]t   tup(    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyt   descr__reduce__v  s*    	000c         C   s   d |  i  |  i |  i f S(   Ns$   <code object %s, file '%s', line %d>(   R2   R1   R3   (   R9   (    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyt   get_repr  s    c         C   s   | i  |  i    S(   N(   Rn   R   (   R9   R   (    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyt   repr  s    R9   N(+   t   __name__t
   __module__t   __doc__R~   t   _immutable_t   _immutable_fields_R\   t   default_magicR(   R8   R]   RH   t   propertyRo   Rh   t   classmethodR   Rm   RM   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t   intt   strt   unwrap_specR   R   R   R   R   (    (    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pyR&   5   sR   		&			#																				i
i
(-   R   R   t   impt   structRj   R   RY   t   pypy.interpreterR    t   pypy.interpreter.argumentR   t   pypy.interpreter.errorR   t   pypy.interpreter.gatewayR   t   pypy.interpreter.baseobjspaceR   R   t#   pypy.interpreter.astcompiler.constsR   R   R   R	   R
   R   R   t   pypy.rlib.rarithmeticR   t   pypy.rlib.debugR   t	   pypy.rlibR   t   pypy.rlib.objectmodelR   t   pypy.tool.stdlib_opcodeR   R   R   t   unpackt	   get_magicRX   R   R%   R'   R&   (    (    (    s+   /64/home/arigo/u/pypy/interpreter/pycode.pys   <module>   s"   H:		
