³ò
Ð‘RMc           @   sæ   d  Z  d d k l Z l Z d d k l Z d d k l Z d e f d „  ƒ  YZ	 d e f d „  ƒ  YZ
 d	 e
 f d
 „  ƒ  YZ d d „ Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   s   
Arguments objects.
iÿÿÿÿ(   t   OperationErrort   operationerrfmt(   t   make_sure_not_resized(   t   jitt	   Signaturec           B   s˜   e  Z e Z d  g Z d Z d d d „ Z e i	 d „  ƒ Z
 d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s   argnames[*]t   argnamest
   varargnamet	   kwargnamec         C   s   | |  _  | |  _ | |  _ d  S(   N(   R   R   R   (   t   selfR   R   R   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt   __init__   s    		c         C   s2   y |  i  i | ƒ SWn t j
 o d Sn Xd  S(   Niÿÿÿÿ(   R   t   indext
   ValueError(   R   t   name(    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt   find_argname   s    c         C   s   t  |  i ƒ S(   N(   t   lenR   (   R   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt   num_argnames   s    c         C   s   |  i  d  j	 S(   N(   R   t   None(   R   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt
   has_vararg   s    c         C   s   |  i  d  j	 S(   N(   R   R   (   R   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt	   has_kwarg!   s    c         C   s3   t  |  i ƒ } | |  i ƒ  7} | |  i ƒ  7} | S(   N(   R   R   R   R   (   R   t   scopelen(    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt   scope_length$   s    c         C   sU   |  i  } |  i d  j	 o | |  i g } n |  i d  j	 o | |  i g } n | S(   N(   R   R   R   R   (   R   R   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt   getallvarnames*   s    	c         C   s   d |  i  |  i |  i f S(   Ns   Signature(%r, %r, %r)(   R   R   R   (   R   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt   __repr__2   s    c         C   sN   t  | t ƒ p t Sn |  i | i j o# |  i | i j o |  i | i j S(   N(   t
   isinstanceR   t   NotImplementedR   R   R   (   R   t   other(    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt   __eq__6   s
    c         C   s#   t  | t ƒ p t Sn |  | j S(   N(   R   R   R   (   R   R   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt   __ne__=   s    c         C   s   d S(   Ni   (    (   R   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt   __len__E   s    c         C   sR   | d j o |  i  Sn | d j o |  i Sn | d j o |  i Sn t ‚ d  S(   Ni    i   i   (   R   R   R   t
   IndexError(   R   t   i(    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt   __getitem__H   s    (   s   argnamess
   varargnames	   kwargnameN(   t   __name__t
   __module__t   Truet   _immutable_t   _immutable_fields_t	   __slots__R   R	   R   t   purefunctionR   R   R   R   R   R   R   R   R   R   R   (    (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyR   
   s   										t	   Argumentsc           B   sû   e  Z d  Z d d d d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z g  d d „ Z e i d „  ƒ Z e i g  d d „ ƒ Z g  d „ Z d d „ Z g  d d „ Z e d d d „ ƒ Z d „  Z RS(   sg   
    Collects the arguments of a function call.
    
    Instances should be considered immutable.
    c         C   sè   | |  _  t | t ƒ p t ‚ | |  _ | |  _ | |  _ | d  j	 oR | d  j	 p t ‚ t | ƒ t | ƒ j p t ‚ t	 |  i ƒ t	 |  i ƒ n t	 |  i ƒ | d  j	 o |  i
 | ƒ n | d  j	 o |  i | ƒ |  _ d  S(   N(   t   spaceR   t   listt   AssertionErrort   arguments_wt   keywordst
   keywords_wR   R   R   t   _combine_starargs_wrappedt   _combine_starstarargs_wrappedt	   _dont_jit(   R   R(   t   args_wR,   R-   t	   w_starargt   w_starstararg(    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyR	   \   s    				 c         C   sL   |  i  i } |  i p d | |  i f Sn d | |  i |  i |  i f Sd S(   s    NOT_RPYTHON s   %s(%s)s   %s(%s, %s, %s)N(   t	   __class__R    R,   R+   R-   (   R   R   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyR   q   s
    
c         C   sY   h  } |  i  o< x9 t t |  i  ƒ ƒ D] } |  i | | |  i  | <q& Wn |  i | f S(   s)   Return a ([w1,w2...], {'kw':w3...}) pair.(   R,   t   rangeR   R-   R+   (   R   t   kwds_wR   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt   unpack}   s    
  c         C   s   t  |  i | |  i |  i ƒ S(   s=   Return a new Arguments with a args_w as positional arguments.(   R'   R(   R,   R-   (   R   R1   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt   replace_arguments…   s    c         C   s   |  i  | g |  i ƒ S(   s:   Return a new Arguments with a new argument inserted first.(   R8   R+   (   R   t
   w_firstarg(    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt   prepend‰   s    c         C   s@   | d j	 o |  i | ƒ n | d j	 o |  i | ƒ n d S(   s9   unpack the *arg and **kwd into arguments_w and keywords_wN(   R   R.   R/   (   R   R2   R3   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt   _combine_wrapped   s    c         C   s¥   |  i  } y | i | ƒ } Wnr t j
 of } | i | | i ƒ oD | i | ƒ } | i | ƒ } t | i | i d | f ƒ ƒ ‚ n ‚  n X|  i | |  _ d  S(   Ns+   argument after * must be a sequence, not %s(	   R(   t	   fixedviewR    t   matcht   w_TypeErrort   typet   getnamet   wrapR+   (   R   R2   R(   R1   t   et   w_typet   typename(    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyR.   ”   s    		c         C   s  |  i  } | i | | i ƒ o+ | i | ƒ p t Sn | i | ƒ } n› y | i | d ƒ } Wnr t j
 of } | i | | i	 ƒ oD | i
 | ƒ } | i | ƒ } t | i | i d | f ƒ ƒ ‚ n ‚  n X| i | ƒ } | o |  i | | ƒ t Sn t Sd  S(   Nt   keyss+   argument after ** must be a mapping, not %s(   R(   t   isinstance_wt   w_dictt   is_truet   Falset   unpackiterablet   call_methodR    R=   t   w_AttributeErrorR?   R@   R>   RA   t    _do_combine_starstarargs_wrappedR"   (   R   R3   R(   t   keys_wt   w_keysRB   RC   RD   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyR/   ¤   s*    		c   
      C   sˆ  |  i  } d  g t | ƒ } d  g t | ƒ } d } x| D]þ } y | i | ƒ } Wn‚ t j
 ov }	 |	 i | | i ƒ o t | i | i d ƒ ƒ ‚ n |	 i | | i ƒ o t | i | i d ƒ ƒ ‚ n ‚  n X|  i	 o, | |  i	 j o t
 |  i  i d | ƒ ‚ n | | | <| i | | ƒ | | <| d 7} q< W|  i	 d  j o | |  _	 | |  _ n! |  i	 | |  _	 |  i | |  _ d  S(   Ni    s   keywords must be stringss"   keyword cannot be encoded to asciis-   got multiple values for keyword argument '%s'i   (   R(   R   R   t   str_wR    R=   R>   RA   t   w_UnicodeEncodeErrorR,   R   t   getitemR-   (
   R   RN   R3   R(   R-   R,   R   t   w_keyt   keyRB   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyRM   ¾   s<    	 
	c         C   sl   |  i  o t d ‚ n t |  i ƒ | j o t d | ‚ n( t |  i ƒ | j  o t d | ‚ n |  i S(   sw   The simplest argument parsing: get the 'argcount' arguments,
        or raise a real ValueError if the length is wrong.s   no keyword arguments expecteds    too many arguments (%d expected)s"   not enough arguments (%d expected)(   R,   R   R   R+   (   R   t   argcount(    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt   fixedunpackß   s    
c         C   s   |  i  o |  i  d Sn d S(   s)   Return the first argument for inspection.i    N(   R+   R   (   R   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt   firstargê   s    
i    c         C   sM   t  i ƒ  o' |  i o |  i | | | | | ƒ Sn |  i | | | | | ƒ S(   s¬   Parse args and kwargs according to the signature of a code object,
        or raise an ArgErr in case of failure.
        Return the number of arguments filled in.
        (   R   t   we_are_jittedR0   t   _match_signature_jit_opaquet   _really_match_signature(   R   R9   t   scope_wt	   signaturet
   defaults_wt	   blindargs(    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt   _match_signatureò   s    c         C   s   |  i  | | | | | ƒ S(   N(   RZ   (   R   R9   R[   R\   R]   R^   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyRY   ÿ   s    c         C   sN  | i  ƒ  } | i ƒ  } | i ƒ  } d  }	 d }
 | d  j	 o4 d } | d j o | | d <d }
 qw | g }	 n d } |  i } t | ƒ } |  i } |  i } d } | d  j	 o t | ƒ } n | | } |
 | j  oX | | j o | |
 } n | } x& t | ƒ D] } | | | | |
 <qW|
 | 7}
 n | o… | | } | d j  o3 |	 d  j	 p t	 ‚ |	 } | o | | } q¢n" | | j o | | } n g  } |  i
 i | ƒ | | <n0 | | j o" t | | | | | | d ƒ ‚ n | } d  } | o½ t g | } x­ t | ƒ D]› } | | } | i | ƒ } | d j  o qq| |
 j  o! | | j o t | ƒ ‚ q³q| | d  j p t	 ‚ | | | | <t | | <| d 8} qWn d } |
 | j  op | t | ƒ } x] t |
 | ƒ D]H } | | d  j	 o qî| | j o | | | | | <qî| d 7} qîWn | oˆ |  i
 i ƒ  } | o` x] t t | ƒ ƒ D]E } | | p4 | | } |  i
 i | |  i
 i | ƒ | | ƒ qnqnWn | | | | <nM | oE | d j o" t | | | | | | | ƒ ‚ n t | | | ƒ ‚ n | o" t | | | | | | | ƒ ‚ n | | | S(   Ni    i   (   R   R   R   R   R+   R   R,   R-   R5   R*   R(   t   newtuplet   ArgErrCountRI   R   t   ArgErrMultipleValuesR"   t   newdictt   setitemRA   t   ArgErrUnknownKwds(   R   R9   R[   R\   R]   R^   t   co_argcountR   R   t   extravarargst   input_argcountt   upfrontR1   t   num_argsR,   R-   t   num_kwdst   availt   takeR   t	   args_leftt
   starargs_wt   num_remainingkwdst   used_keywordsR   t   jt   missingt	   def_firstt   w_kwdsRT   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyRZ     s´    

			
 
		 

  
2				c      	   C   sc   y |  i  | | | | d ƒ SWn? t j
 o3 } t |  i i |  i i | i | ƒ ƒ ƒ ‚ n Xd S(   sÈ   Parse args and kwargs to initialize a frame
        according to the signature of code object.
        Store the argumentvalues into scope_w.
        scope_w must be big enough for signature.
        i    N(   R_   t   ArgErrR    R(   R>   RA   t   getmsg(   R   R9   R[   t   fnnameR\   R]   RB   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt   parse_into_scope  s    	c         C   s6   | i  ƒ  } d g | } |  i | | | | | ƒ | S(   sz   Parse args and kwargs according to the signature of a code object,
        or raise an ArgErr in case of failure.
        N(   R   R   R_   (   R   R9   R\   R]   R^   R   R[   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt   _parse›  s
    c         C   s`   y |  i  | | | | ƒ SWn? t j
 o3 } t |  i i |  i i | i | ƒ ƒ ƒ ‚ n Xd S(   sg   Parse args and kwargs to initialize a frame
        according to the signature of code object.
        N(   Rz   Rv   R    R(   R>   RA   Rw   (   R   R9   Rx   R\   R]   R^   RB   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt	   parse_obj¦  s
    c         C   s   t  |  g  d | d | ƒS(   sl   Convenience static method to build an Arguments
           from a wrapped sequence and a wrapped dictionary.R2   R3   (   R'   (   R(   t   w_argsRu   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt
   frompacked±  s    c         C   s   |  i  } | i |  i ƒ } | i ƒ  } |  i d j	 oN xK t t |  i ƒ ƒ D]0 } | i | | i	 |  i | ƒ |  i
 | ƒ qM Wn | | f S(   s@   Express the Argument object as a pair of wrapped w_args, w_kwds.N(   R(   R`   R+   Rc   R,   R   R5   R   Rd   RA   R-   (   R   R(   R|   Ru   R   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt   topacked·  s    	 N(   R    R!   t   __doc__R   R	   R   R7   R8   R:   R;   R.   R/   RM   RV   RW   R_   R   t   dont_look_insideRY   t   unroll_safeRZ   Ry   Rz   R{   t   staticmethodR}   R~   (    (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyR'   S   s2   								!		‡
t   ArgumentsForTranslationc           B   s›   e  Z d d d d d  „ Z d „  Z d „  Z d „  Z g  d d „ Z d „  Z d „  Z	 d „  Z
 e d d d	 „ ƒ Z e d
 „  ƒ Z d „  Z d d „ Z RS(   c         C   s8   | |  _  | |  _ t |  _ t i |  | | | | ƒ d  S(   N(   R2   R3   RI   t   combine_has_happenedR'   R	   (   R   R(   R1   R,   R-   R2   R3   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyR	   Ã  s    			c         C   s5   |  i  o d  Sn |  i |  i |  i ƒ t |  _  d  S(   N(   R„   R;   R2   R3   R"   (   R   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt   combine_if_necessaryÊ  s    
c         C   s2   t  |  i | g |  i |  i |  i |  i |  i ƒ S(   s:   Return a new Arguments with a new argument inserted first.(   Rƒ   R(   R+   R,   R-   R2   R3   (   R   R9   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyR:   Ð  s    c         C   s+   t  |  i |  i |  i |  i |  i |  i ƒ S(   N(   Rƒ   R(   R+   R,   R-   R2   R3   (   R   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt   copyÖ  s    i    c         C   s&   |  i  ƒ  t i |  | | | | | ƒ S(   N(   R…   R'   R_   (   R   R9   R[   R\   R]   R^   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyR_   Ý  s    
c         C   s   |  i  ƒ  t i |  ƒ S(   N(   R…   R'   R7   (   R   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyR7   å  s    
c         C   s   |  i  d | | ƒ S(   sz   Parse args and kwargs according to the signature of a code object,
        or raise an ArgErr in case of failure.
        N(   Rz   R   (   R   R\   R]   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt   match_signatureé  s    c         C   sr  |  i  ƒ  \ } } t | ƒ } | i ƒ  } |  i } | \ } }	 }
 t | ƒ } | |  } |	 o | | } | d 7} n | i g  ƒ } h  } |
 o] | | } xB | i | ƒ D]1 } | i | ƒ } | i | | ƒ } | | | <q­ W| d 7} n t | ƒ | j p t ‚ t | ƒ } | | j oX | |  } x/ t	 | | | | ƒ D] \ } } | | | <qEW| i
 | ƒ p t ‚ n§ | i | ƒ } t | ƒ } d g | t | ƒ } x% t d | ƒ D] } | | | | <q½Wx/ t d t | ƒ ƒ D] } | | | | | <qëWt | ƒ | j p t ‚ g  } g  } x, | D]$ } | i | ƒ | i | | ƒ q4Wt |  i | | | ƒ S(   s"   kind of inverse of match_signaturei   i    N(   R7   R   RE   R(   R`   RJ   RP   RR   R*   t   zipRH   R   R5   t   appendRƒ   (   R   R\   t   data_wR1   R6   t   need_cntt	   need_kwdsR(   R   R   R   t   cntt   data_args_wt   data_w_starargt   unfiltered_kwds_wt   data_w_starargargRS   RT   t   w_valuet   ndata_args_wt   argnamet   w_argt	   stararg_wt   datalenR   R,   R-   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt   unmatch_signatureï  sZ    	


 
    c         C   s   t  d ƒ ‚ d  S(   Ns   go away(   t   NotImplementedError(   R(   R|   Ru   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyR}      s    c      	   C   s    | \ } } } } | |  } | t  | ƒ } }	 | o | | }
 | d 7} n d  }
 | o | | } | d 7} n d  } t |  | t | ƒ | | |	 !|
 | ƒ S(   Ni   (   R   R   Rƒ   R)   (   R(   t   .1RŠ   t	   shape_cntt
   shape_keyst
   shape_start
   shape_ststR1   t   pt   end_keyst   w_start
   w_starstar(    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt	   fromshape$  s   


c         C   sŸ   |  i  ƒ  \ } } } } |  i g  } | D]  } | |  i |  i i | ƒ q) ~ } | o | i |  i ƒ n | o | i |  i ƒ n | | | | f | f S(   sB    Argument <-> list of w_objects together with "shape" information (   t	   _rawshapeR+   R-   R,   R
   R‰   R2   R3   (   R   R›   Rœ   R   Rž   t   _[1]RT   RŠ   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt   flatten6  s    .c         C   s   |  i  p t ‚ t |  i ƒ | } |  i o |  i } | i ƒ  n g  } |  i d  j	 } |  i d  j	 } | t	 | ƒ | | f S(   N(
   R„   R*   R   R+   R,   t   sortR2   R   R3   t   tuple(   R   t   nextraR›   Rœ   R   Rž   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyR¤   A  s    

N(   R    R!   R   R	   R…   R:   R†   R_   R7   R‡   R˜   R‚   R}   R£   R¦   R¤   (    (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyRƒ   Â  s   						1	i    c         C   s   |  i  | ƒ S(   N(   R¤   (   t   argsR©   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyt   rawshapeM  s    Rv   c           B   s   e  Z d  „  Z RS(   c         C   s
   t  ‚ d  S(   N(   R™   (   R   Rx   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyRw   X  s    (   R    R!   Rw   (    (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyRv   V  s   Ra   c           B   s   e  Z d  „  Z d „  Z RS(   c         C   sI   | |  _  | |  _ | |  _ t | ƒ |  _ | |  _ | |  _ | |  _ d  S(   N(   t   expected_nargsR   R   R   t   num_defaultst   missing_argsRj   Rk   (   R   t	   got_nargst   nkwdsR¬   R   R   R]   R®   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyR	   ]  s    					c   	      C   sÉ   d  } |  i |  i } |  i } | d j o d | | f } n† |  i } | d j o |  i o
 d } n% |  i p
 d } n d } | | 8} | d j o
 d } n d } d	 | | | | | f } | S(
   Ni    s!   %s() takes no argument (%d given)t   exactlys   at mosts   at leasti   t    t   ss&   %s() takes %s %d argument%s (%d given)(   R   Rj   Rk   R¬   R­   R   R®   (	   R   Rx   Rª   t   nargst   nt   msgt   defcountt   msg1t   plural(    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyRw   h  s0    		





(   R    R!   R	   Rw   (    (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyRa   [  s   	Rb   c           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   | |  _  d  S(   N(   R”   (   R   R”   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyR	   ˆ  s    c         C   s   d | |  i  f } | S(   Ns2   %s() got multiple values for keyword argument '%s'(   R”   (   R   Rx   R¶   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyRw   ‹  s    (   R    R!   R	   Rw   (    (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyRb   †  s   	Re   c           B   s   e  Z d  „  Z d „  Z RS(   c         C   sa   d |  _  | |  _ | d j o> x; t t | ƒ ƒ D]# } | | p | | |  _  Pq2 q2 Wn d  S(   NR²   i   (   t   kwd_nameRk   R5   R   (   R   Rp   R,   Rq   R   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyR	   “  s    		 c         C   s>   |  i  d j o d | |  i f } n d | |  i  f } | S(   Ni   s,   %s() got an unexpected keyword argument '%s's(   %s() got %d unexpected keyword arguments(   Rk   Rº   (   R   Rx   R¶   (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyRw   œ  s    (   R    R!   R	   Rw   (    (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pyRe   ‘  s   		N(   R   t   pypy.interpreter.errorR    R   t   pypy.rlib.debugR   t	   pypy.rlibR   t   objectR   R'   Rƒ   R«   t	   ExceptionRv   Ra   Rb   Re   (    (    (    s-   /64/home/arigo/u/pypy/interpreter/argument.pys   <module>   s   Iÿ p‹	+
