³ò
Ñ‘RMc           @   s–   d  d k  Z  d  d k l Z l Z d  d k l Z d „  Z d d „ Z d „  Z d d d „ Z
 d d d	 „ Z d d
 „ Z d d „ Z e d „ Z d S(   iÿÿÿÿN(   t   evalt   module(   t   OperationErrorc         C   s“   |  i  d ƒ } |  i i d ƒ } y |  i | | ƒ SWn2 t j
 o& } | i |  |  i ƒ p ‚  qj n Xt i |  | ƒ } |  i	 | | | ƒ | S(   Nt   __main__t   modules(
   t   wrapt   syst   gett   getitemR   t   matcht
   w_KeyErrorR   t   Modulet   setitem(   t   spacet   w_maint	   w_modulest   et
   mainmodule(    (    s)   /64/home/arigo/u/pypy/interpreter/main.pyt   ensure__main__   s    t   execc         C   sa   |  i  } |  i i d | | ƒ | | ƒ | | ƒ | d ƒ | d ƒ ƒ } |  i t i | ƒ } | S(   Nt   compilei    (   R   t   builtint   callt   interp_wR    t   Code(   R   t   sourcet   filenamet   cmdt   wt   w_codet   pycode(    (    s)   /64/home/arigo/u/pypy/interpreter/main.pyt   compilecode   s
    	3c      	   C   s  | o
 d } n d } yÜ | d  j o d d k l } | ƒ  } n | i } t | |  | p d | ƒ } t | ƒ } | i }	 | i |	 | d ƒ | i ƒ | d  j	 o# | i |	 | d ƒ | | ƒ ƒ n | i	 | |	 |	 ƒ }
 | o |
 Sn d  SWn" t
 j
 o } | i ƒ  ‚  n Xd  S(   NR    R   iÿÿÿÿ(   t   StdObjSpaces   <string>t   __builtins__t   __file__(   t   Nonet   pypy.objspace.stdR    R   R   R   t   w_dictR   R   t	   exec_codeR   t   record_interpreter_traceback(   R   R   R   R    R   R    R   R   R   t	   w_globalst   retvalt   operationerr(    (    s)   /64/home/arigo/u/pypy/interpreter/main.pyt   _run_eval_string   s*    
		#
c         C   s   t  |  | | t ƒ d  S(   N(   R+   t   False(   R   R   R   (    (    s)   /64/home/arigo/u/pypy/interpreter/main.pyt
   run_string:   s    c         C   s   t  |  | | t ƒ S(   N(   R+   t   True(   R   R   R   (    (    s)   /64/home/arigo/u/pypy/interpreter/main.pyt   eval_string=   s    c         C   sF   t  d j o d |  | f GHn t |  ƒ i ƒ  } t | |  | ƒ d  S(   NR   s   Running %r with %r(   t   __name__t   opent   readR-   (   R   R   t   istring(    (    s)   /64/home/arigo/u/pypy/interpreter/main.pyt   run_file@   s    c   	      C   sï   | d j o d d k l } | ƒ  } n | i } |  g } | d j	 o | i | ƒ n | i | i i | d ƒ | | ƒ ƒ | i i	 d ƒ } | i
 | | d ƒ ƒ } | i | i | d ƒ ƒ } | i
 | | |  ƒ | i | d ƒ | i ƒ S(	   s  Implements PEP 338 'Executing modules as scripts', overwriting
    sys.argv[1:] using `args` and executing the module `module_name`.
    sys.argv[0] always is `module_name`.

    Delegates the real work to the runpy module provided as the reference
    implementation.
    iÿÿÿÿ(   R    t   argvt
   __import__t   runpyt
   run_moduleR   N(   R#   R$   R    R   t   extendR   R   R%   R   R   t   call_functionR   t   w_Nonet   w_True(	   t   module_namet   argsR   R    R   R5   t   w_importR7   t   w_run_module(    (    s)   /64/home/arigo/u/pypy/interpreter/main.pyR8   F   s    		%c         C   s$  y¡ | ƒ  y1 |  i  i d ƒ } |  i | |  i d ƒ ƒ } Wn2 t j
 o& } | i |  |  i ƒ p ‚  q  n2 X|  i | ƒ o  |  i | d |  i d ƒ ƒ n Wn|t j
 op} | i	 |  ƒ | i
 } | i |  ƒ } |  i | i ƒ }	 | i ƒ  t  i ƒ  \ t  _ t  _ t  _ y™| i |  |  i ƒ oŸ |  i | |  i d ƒ ƒ }
 |  i |
 |  i ƒ o
 d } nU y |  i |
 ƒ } Wn> t j
 o2 |  i |  i |
 ƒ ƒ } t  i | IJd } n Xt | ƒ ‚ n |  i |  i  i |  i d ƒ | ƒ |  i |  i  i |  i d	 ƒ | ƒ |  i |  i  i |  i d
 ƒ |	 ƒ |  i  i |  d ƒ } | d j	 oX |  i  i |  d ƒ } | d j p |  i | | ƒ o |  i | | | |	 ƒ t Sq«n WnC t j
 o7 } t  i d IJ| i  |  ƒ t  i Jt  i d IJn X| o | i! |  ƒ n | i  |  ƒ t Sn Xt" S(   s  Calls f() and handle all OperationErrors.
    Intended use is to run the main program or one interactive statement.
    run_protected() handles details like forwarding exceptions to
    sys.excepthook(), catching SystemExit, printing a newline after
    sys.stdout if needed, etc.
    t   stdoutt	   softspacet   writes   
t   codei    i   t	   last_typet
   last_valuet   last_tracebackt
   excepthookt   __excepthook__s   Error calling sys.excepthook:s   Original exception was:N(#   R   R   t   getattrR   R   R	   t   w_AttributeErrort   is_truet   call_methodt   normalize_exceptiont   w_typet   get_w_valuet   application_tracebackR'   t   exc_infoRE   RF   RG   t   w_SystemExitt   is_wR;   t   int_wt   str_wt   strt   stderrt
   SystemExitR   R%   t   getdictvalueR#   R:   R,   t   print_application_tracebackt   print_detailed_tracebackR.   (   R   t   ft   verboset   w_stdoutt   w_softspaceR   R*   RO   t   w_valuet   w_tracebackt
   w_exitcodet   exitcodet   msgt   w_hookt
   w_originalt   err2(    (    s)   /64/home/arigo/u/pypy/interpreter/main.pyt   run_toplevel^   sd    $	
	
""!	(   R   t   pypy.interpreterR    R   t   pypy.interpreter.errorR   R   R   R+   R#   R-   R/   R4   R8   R,   Ri   (    (    (    s)   /64/home/arigo/u/pypy/interpreter/main.pys   <module>   s   		 
