ó
n‘]c           @  sî   d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z e d i  ƒ Z	 d a
 d a d „  Z d „  Z d e f d	 „  ƒ  YZ d
 e j j f d „  ƒ  YZ d e f d „  ƒ  YZ d e j j f d „  ƒ  YZ d „  Z d S(   iÿÿÿÿ(   t   print_functionN(   t   sixt   asti    c          C  s~   t  d 7a  t  d k r d  Sd a  t j ƒ  }  |  t k rQ |  d a t d ƒ ‚ n  t j j rz t |  d k rz |  d a n  d  S(   Ni   iè  i    i<   s   Possible infinite loop.(   t   il_statementst   timet   il_timet	   Exceptiont   renpyt   configt	   developer(   t   now(    (    s   renpy/execution.pyt   check_infinite_loop+   s    

c         C  s-   t  j j s |  d 9}  n  t j ƒ  |  a d S(   sW   
    :doc: other

    Resets the infinite loop detection timer to `delay` seconds.
    i   N(   R   R   R	   R   R   (   t   delay(    (    s   renpy/execution.pyt   not_infinite_loopC   s    	t   Deletec           B  s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s   renpy/execution.pyR   S   s   t   PredictInfoc           B  s   e  Z d  Z RS(   sC   
    Not used anymore, but needed for backwards compatibility.
    (   R   R   t   __doc__(    (    (    s   renpy/execution.pyR   W   s   t   LineLogEntryc           B  s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C  sI   | |  _  | |  _ | |  _ | |  _ x t j j D] } | |  ƒ q1 Wd  S(   N(   t   filenamet   linet   nodet   abnormalR   R   t   line_log_callbacks(   t   selfR   R   R   R   t   i(    (    s   renpy/execution.pyt   __init___   s    				c         C  sG   t  | t ƒ s t S|  j | j k oF |  j | j k oF |  j | j k S(   N(   t
   isinstanceR   t   FalseR   R   R   (   R   t   other(    (    s   renpy/execution.pyt   __eq__h   s    c         C  s   |  | k S(   N(    (   R   R   (    (    s   renpy/execution.pyt   __ne__n   s    (   R   R   R   R   R    (    (    (    s   renpy/execution.pyR   ]   s   			t   Contextc           B  s7  e  Z d  Z d Z d g Z d Z e Z d Z	 d Z
 d Z d „  Z d „  Z d e d „ Z d „  Z e d „ Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z d d „ Z d „  Z e d „ Z d „  Z d „  Z  d „  Z! d „  Z" d „  Z# d „  Z$ d „  Z% d „  Z& RS(   sÃ  
    This is the context object which stores the current context
    of the game interpreter.

    @ivar current: The name of the node that is currently being
    executed.

    @ivar return_stack: A list of names of nodes that should be
    returned to when the return statement executes. (When a return
    occurs, the name is looked up, and name.text is then executed.)

    @ivar scene_lists: The scene lists associated with the current
    context.

    @ivar rollback: True if this context participates in rollbacks.

    @ivar runtime: The time spent in this context, in milliseconds.

    @ivar info: An object that is made available to user code. This object
    does participates in rollback.
    i   t	   next_nodec         C  sD   |  j  s d St j j j |  j  ƒ } d j | j | j | j ƒ  ƒ S(   Ns	   <Context>s   <Context: {}:{} {!r}>(	   t   currentR   t   gamet   scriptt   lookupt   formatR   t
   linenumbert	   diff_info(   R   R   (    (    s   renpy/execution.pyt   __repr__–   s    	c         C  s¾  | d k  r! |  j  j |  j _ n  | d k  rB t |  _ t |  _ n  | d k  rZ i  |  _ n  | d k  rr t |  _ n  | d k  r¢ t	 j
 j d g ƒ |  _ t |  _ n  | d k  rÀ |  j  j |  _ n  | d k  rá t |  _ d  |  _ n  | d	 k  rù d  |  _ n  | d
 k  rd  |  _ d  |  _ n  | d k  r2d  |  _ n  | d k  rJd  |  _ n  | d k  rbg  |  _ n  | d k  rzi  |  _ n  | d k  r¢t g t |  j ƒ |  _ n  | d k  rºd  |  _ n  d  S(   Ni   i   i   i   i   t   starti   i   i   i	   i
   i   i   i   i   i   (   t   predict_infot   imagest   scene_listst   image_predict_infoR   R   t   last_abnormalt   musict   interactingR   t   pythont   RevertableListt   modest   Truet	   use_modest
   init_phaset   NoneR"   t   defer_rollbackt   translate_languaget   translate_identifiert   exception_handlert   say_attributest   line_logt   moviet   lent   return_stackt   abnormal_stackt   alternate_translate_identifier(   R   t   version(    (    s   renpy/execution.pyt   after_upgrade£   sD    			c         C  si  t  t |  ƒ j ƒ  d
 |  _ g  |  _ g  |  _ g  |  _ i  g |  _ | |  _	 d |  _
 t j j ƒ  |  _ t |  _ t |  _ t |  _ t j j ƒ  |  _ t |  _ t |  _ d
 |  _ d
 |  _ d
 |  _ d
 |  _ g  |  _ t |  _ i  |  _ | r‚| j } | j
 |  _
 t  |  j ƒ j! t  | j ƒ ƒ x0 | j j" ƒ  D] \ } } | j# ƒ  |  j | <q/Wt$ | j ƒ |  _ t j% j& j' | j( ƒ |  _( n d
 } t j% j& j' d
 ƒ |  _( t j% j) j* | |  j( ƒ |  _ |  j+ d d d d d d g ƒ |  j j, i  ƒ | r x* t j- j. D] } |  j j/ d | ƒ q Wn  t j j0 d	 g ƒ |  _1 t |  _2 t j3 j4 j5 |  _6 d
 |  _7 d
 |  _8 d
 S(   s[   
        `clear`
            True if we should clear out the context_clear_layers.
        i    t   _returnt   _argst   _kwargst   mouse_visiblet   suppress_overlayt   _side_image_attributest   layerR+   N(9   t   superR!   R   R9   R#   t   call_location_stackRB   RC   t   dynamic_stackt   rollbackt   runtimeR   R3   t   RevertableObjectt   infoR   t   seenR6   R   R0   t   RevertableDictR1   R2   R8   R:   R=   R>   t   temporary_attributesR?   t   force_checkpointR@   R.   t   varst   updatet   itemst   copyt   dictt   displayt   imaget   ShownImageInfoR-   t   coret
   SceneListst   make_dynamict   appendR   t   context_clear_layerst   clearR4   R5   R7   R$   t   preferencest   languageR;   R<   RD   (   R   RQ   t   contextRf   t   oldslt   kt   vR   (    (    s   renpy/execution.pyR   Õ   sV    																					c           sM   ‡  ‡ f d †  } | |  j  ƒ |  _  g  |  j D] } | | ƒ ^ q. |  _ d  S(   Nc           s,   t  j j j |  ƒ } | ˆ k r( ˆ  j S|  S(   N(   R   R$   R%   R&   t   name(   Rm   t   n(   t   newt   old(    s   renpy/execution.pyt   replace_oneD  s    (   R#   RB   (   R   Rp   Ro   Rq   R   (    (   Ro   Rp   s   renpy/execution.pyt   replace_nodeB  s    c         C  s‡   t  j j } | r d } n d } x_ | D]W } | |  j | k rG q( n  | | k rk | | |  j | | <q( t ƒ  |  j | | <q( Wd S(   s›   
        Makes the variable names listed in names dynamic, by backing up
        their current value (if not already dynamic in the current call).
        i    iÿÿÿÿN(   R   t   storet   __dict__RP   R   (   R   t   namesRi   Rs   t   indexR   (    (    s   renpy/execution.pyRc   N  s    	c         C  sl   |  j  s d St j j } |  j  j ƒ  } x= | j ƒ  D]/ \ } } t | t ƒ rZ | | =q5 | | | <q5 Wd S(   sg   
        Pops one level of the dynamic stack. Called when the return
        statement is run.
        N(   RP   R   Rs   Rt   t   popt	   iteritemsR   R   (   R   Rs   t   dynamicRk   Rl   (    (    s   renpy/execution.pyt   pop_dynamice  s    	
c         C  s   x |  j  r |  j ƒ  q Wd S(   se   
        Pops all levels of the dynamic stack. Called when we jump
        out of a context.
        N(   RP   Rz   (   R   (    (    s   renpy/execution.pyt   pop_all_dynamicx  s    c         C  st   xm t  |  j ƒ D]\ } xS | j ƒ  D]E \ } } d | } t | t ƒ r^ | | k r^ | | =q# | | | <q# Wq Wd  S(   Ns   store.(   t   reversedRP   Rx   R   R   (   R   t   rootsRy   Rk   Rl   Rm   (    (    s   renpy/execution.pyt   pop_dynamic_roots  s    

c         C  s   | |  _  d S(   se   
        Sets the name of the node that will be run when this context
        next executes.
        N(   R#   (   R   t	   node_name(    (    s   renpy/execution.pyt
   goto_label  s    c         C  sÅ   t  |  j ƒ t  |  j ƒ d k rÁ t d j t  |  j ƒ t  |  j ƒ ƒ ƒ } x6 t  |  j ƒ t  |  j ƒ d k  r„ |  j j i  ƒ qO Wx0 t  |  j ƒ t  |  j ƒ d k r· |  j ƒ  qˆ W| ‚ n  d S(   s1   
        Check and fix stack corruption.
        i   s7   Potential return stack corruption: dynamic={} return={}N(   RA   RP   RB   R   R'   Rd   Rz   (   R   t   e(    (    s   renpy/execution.pyt   check_stacks•  s    "*%%c         C  sñ   | r
 d  Sg  } xt |  j  D]i } yY t j j j | ƒ } | j j d d ƒ j d ƒ sx | j | j | j	 d d  f ƒ n  Wq q Xq Wy\ t j j j |  j ƒ } | j j d d ƒ j d ƒ sâ | j | j | j	 d d  f ƒ n  Wn n X| S(   Ns   \t   /s   common/s   script callR%   (   RO   R   R$   R%   R&   R   t   replacet
   startswithRd   R(   R9   R#   (   R   Rm   t   lastt   rvR   R   (    (    s   renpy/execution.pyt   report_traceback¦  s"    &&c         B  s`   e  j d | j d d ƒ } e  j d | j d d d | g ƒ } e | | j d ƒ } | d Ud S(   s¶   
        Execs a python pass statement on the line of code corresponding to
        `node`. This indicates to python coverage tools that this line has
        been executed.
        t   linenot
   col_offseti    t   bodyt   execN(   t   pyastt   PassR(   t   Modulet   compileR   (   R   R   t   pst   modulet   code(    (    s   renpy/execution.pyt   report_coverage¾  s    $c         C  s   | |  _  | |  _ d S(   sO   
        When control reaches name, call label. Only for internal use.
        N(   t   come_from_namet   come_from_label(   R   Rm   t   label(    (    s   renpy/execution.pyt	   come_fromÊ  s    	c         C  sÀ  d |  _ t |  _ | d k r9 t j j j |  j ƒ } n  t j	 j
 } t j ƒ  d k	 } t } x4| r“| j |  j k r¾ d |  _ |  j |  j d | j ƒ} |  j d d g ƒ t t j _ n  | } t | ƒ j } t j d d | | j | j ƒ | j |  _ |  j |  _ t |  _ d |  _ t j	 j rkt | j | j | |  j ƒ } | |  j k rk|  j j | ƒ qkn  t j j s†t } t }	 nd | s¤|  j s¤| j  d k r³t } t }	 n7 t j	 j! rÞ| j  d k rÞt } t }	 n t } t }	 t j j" j# r(t j j" j# d d | j k r(t } t }	 n  t } | r’|  j  rbt j j" rbt j j" j$ d |	 ƒ n  |  j  r’|  j r’t t j j" _ t |  _ q’n  t |  _% t j& j' j( |  j ƒ y´yš t) ƒ  | rÔ|  j* | ƒ n  d	 t j _+ d |  _, t j d
 d | | j | j ƒ | j- ƒ  t j d
 d | | j | j ƒ | rM|  j, rM|  j. ƒ  n  Wn
t j j/ k
 ru}
 d |  _0 ‚  næ t1 k
 rZ}
 d |  _0 t j2 ƒ  } t j3 j4 |
 d t ƒ\ } } } yJ |  j d k	 râ|  j | | | ƒ n! t j5 j3 j4 | | | ƒ r‚  n  Wq[t j j/ k
 r%} | ‚ q[t1 k
 rV} t6 j7 | d | d | d
 ƒ q[Xn X|  j, } WnÔ t j j8 k
 r¥}
 t j j j |
 j9 d ƒ } t |  _ n— t j j: k
 r;}
 |
 j; rÏ| j } n* |  j, d k rít1 d ƒ ‚ n  |  j, j } |  j |
 j< d | ƒ} t |  _ |
 j9 t j _= |
 j> t j _? n X|  j% rqt t j j@ jA |  j <t t j jB |  j <n  t j d
 d | | j | j ƒ q` W|  j  r¼t j j" r¼t j j" jC ƒ  n  d S(   sé   
        Executes as many nodes as possible in the current context. If the
        node argument is given, starts executing from that node. Otherwise,
        looks up the node given in self.current, and executes from there.
        t   return_siteRG   t   _begin_rollbacki   s   --- start {} ({}:{})t   forcet   neveri    s   While running game code:i   s       before execute {} ({}:{})s       after execute {} ({}:{})t   editors9   renpy.call can't be used when the next node is undefined.s       end {} ({}:{})N(D   R9   R=   R6   R   R   R$   R%   R&   R#   R   R	   t   syst   gettraceRm   R•   t   callR–   Rc   R   Rs   Rš   t   typeR   t   plogR   R(   R0   R:   R?   R   Rd   RX   RQ   t   all_nodes_rollbackt   logt   forwardt   beginRU   t   testt   testexecutiont	   take_nameR   R”   t   exception_infoR"   t   executeR‚   t   CONTROL_EXCEPTIONSt   translate_interactionR   t   exc_infot   errort   report_exceptionR^   R   t   reraiset   JumpExceptiont   argst   CallExceptiont   from_currentR—   RH   t   kwargsRI   t
   persistentt
   _seen_evert   seen_sessiont   complete(   R   R   R	   t   tracingt   firstt	   this_nodet   type_node_namet   ll_entryt   update_rollbackt   force_rollbackR   R®   t   shortt   fullt   traceback_fnt   ceR™   (    (    s   renpy/execution.pyt   runÒ  s¾    									/			
		!
	'			#c         C  s   t  |  _ d S(   sT   
        Marks the current statement as one that has been seen by the user.
        N(   R6   RU   (   R   (    (    s   renpy/execution.pyt	   mark_seeng  s    c         C  s½   |  j  s t d ƒ ‚ n  | d k r0 |  j  } n  |  j j |  j  ƒ |  j j | ƒ |  j j i  ƒ |  j j |  j ƒ | |  _  |  j	 d d g ƒ d t
 j _ d t
 j _ t
 j j j | ƒ S(   s(   
        Calls the named label.
        s-   Context not capable of executing Ren'Py code.RH   RI   N(   R#   R   R9   RO   Rd   RB   RP   RC   R0   Rc   R   Rs   RH   RI   R$   R%   R&   (   R   R—   R™   (    (    s   renpy/execution.pyR    n  s    		c         C  s]   |  j  s( t j j r$ t d ƒ ‚ n  d S|  j  j ƒ  |  j j ƒ  |  j ƒ  |  j j ƒ  d S(   sB   
        Blindly pops the top call record from the stack.
        s   No call on call stack.N(	   RB   R   R   R	   R   Rw   RO   Rz   RC   (   R   (    (    s   renpy/execution.pyt   pop_call†  s    	
c         C  s<  x5|  j  r7d } t j j j |  j  d ƒ rM t j j j |  j  d ƒ } n> t j j j |  j d ƒ r‹ t j j j |  j d ƒ j } n  | d k rþ t j	 j
 rÂ t d j |  j  d ƒ ƒ ‚ n  |  j  j ƒ  |  j j ƒ  |  j ƒ  |  j j ƒ  |  _ q n  | r3|  j  j ƒ  |  j j ƒ  |  j j ƒ  |  _ n  | SWd S(   sZ   
        Returns the node to return to, or None if there is no
        such node.
        iÿÿÿÿs!   Could not find return label {!r}.N(   RB   R9   R   R$   R%   t	   has_labelR&   RO   t   nextR   R	   R   R'   Rw   Rz   RC   R   (   R   Rw   R   (    (    s   renpy/execution.pyt   lookup_return–  s(    "
c         C  s»   t  |  j |  ƒ } |  j | _ |  j | _ g  |  j D] } | j ƒ  ^ q6 | _ |  j | _ |  j | _ |  j | _ |  j	 | _	 |  j
 | _
 |  j | _ |  j | _ t |  j ƒ | _ | S(   sL   
        Makes a copy of this object, suitable for rolling back to.
        (   R!   RQ   RO   RB   RP   R\   R#   RR   RT   R;   R<   R   R0   t   listRC   (   R   R‡   R   (    (    s   renpy/execution.pyt   rollback_copyº  s    %c         C  s5   t  |  j ƒ |  _ |  j j | ƒ t j j j | ƒ S(   s  
        This is called by the prediction code to indicate that a call to
        `label` will occur.

        `return_site`
            The name of the return site to push on the predicted return
            stack.

        Returns the node corresponding to `label`
        (   RÌ   t   predict_return_stackRd   R   R$   R%   R&   (   R   R—   R™   (    (    s   renpy/execution.pyt   predict_callÑ  s    c         C  sA   |  j  s d St |  j  ƒ |  _  |  j  j ƒ  } t j j j | ƒ S(   sv   
        This predicts that a return will occur.

        It returns the node we predict will be returned to.
        N(   RÎ   R9   RÌ   Rw   R   R$   R%   R&   (   R   R—   (    (    s   renpy/execution.pyt   predict_returnâ  s
    	c         c  só  |  j  s d St j j d k r# d S|  j } g  } t ƒ  } x† t j j |  j  ƒ D]o } t j j j	 | ƒ sp d St j j j
 | ƒ } | | k r— qQ n  | j | |  j |  j f ƒ | j | ƒ qQ Wx#t d t j j ƒ D]} | t | ƒ k rö Pn  | | \ } } } t j j j | ƒ |  _ | |  _ ye x^ | j ƒ  D]P }	 |	 d k rRq:n  |	 | k r:| j |	 |  j |  j f ƒ | j |	 ƒ q:q:WWn= t j j rÏd d l }
 t ƒ  |
 j ƒ  t d ƒ qÏn X| |  _ d |  _ t VqÚ Wt Vd S(   s¿   
        Performs image prediction, calling the given callback with each
        images that we predict to be loaded, in the rough order that
        they will be potentially loaded.
        Ni    iÿÿÿÿs   While predicting images.(   R#   R   R   t   predict_statements_callbackR9   R-   t   setR$   R%   RÉ   R&   Rd   RB   t   addt   ranget   predict_statementsRA   R^   R_   R`   RÎ   t   predictt   debug_image_cachet	   tracebackt   printt	   print_excR6   R   (   R   t
   old_imagest   nodesRU   R—   R   R   R-   RB   Rn   RØ   (    (    s   renpy/execution.pyRÖ   ñ  sL    				
			c         C  s>   |  j  s t S| r% t j j j } n t j j } |  j  | k S(   s2  
        Returns a true value if we have finshed the current statement
        at least once before.

        @param ever: If True, we're checking to see if we've ever
        finished this statement. If False, we're checking to see if
        we've finished this statement in the current session.
        (   R#   R   R   R$   R·   R¸   R¹   (   R   t   everRU   (    (    s   renpy/execution.pyt   seen_current9  s    
	c         C  s<   |  j  s d S|  j  \ } } d |  _  t j j | | ƒ d S(   s=   
        Called to cause deferred rollback to occur.
        N(   R:   R9   R   t   exportsRQ   (   R   R›   t   checkpoints(    (    s   renpy/execution.pyt   do_deferred_rollbackM  s
    		c         C  s   t  |  j ƒ S(   N(   RÌ   RB   (   R   (    (    s   renpy/execution.pyt   get_return_stack[  s    c         C  sº   t  | ƒ |  _ x_ t |  j ƒ t |  j ƒ k rp |  j j ƒ  |  j j ƒ  } | j |  j d ƒ | |  j d <q WxB t |  j ƒ t |  j ƒ k  rµ |  j j d ƒ |  j j i  ƒ qt Wd  S(   Niÿÿÿÿs   unknown location(   RÌ   RB   RA   RO   Rw   RP   RZ   Rd   (   R   RB   t   d(    (    s   renpy/execution.pyt   set_return_stack^  s    !!N('   R   R   R   t   __version__t   nosaveR9   R"   R   RX   R•   R–   RW   R*   RF   R   Rr   Rc   Rz   R{   R~   R€   R‚   Rˆ   R”   R˜   RÆ   RÇ   R    RÈ   R6   RË   RÍ   RÏ   RÐ   RÖ   RÞ   Rá   Râ   Rä   (    (    (    s   renpy/execution.pyR!   r   sD   			2m										•		$				H			c         C  sã   t  j j d k	 r" t  j j ƒ  n  xº t rÞ y7 t  j j ƒ  } | j ƒ  t  j j	 } | j
 ƒ  | SWq% t  j j k
 r } t  j j t ƒ q% q% t  j j k
 rÇ } |  rÁ t  j j t ƒ q% qÛ ‚  q% | j
 ƒ  ‚  q% Xq% Wd S(   s‰   
    Runs the current context until it can't be run anymore, while handling
    the RestartContext and RestartTopContext exceptions.
    N(   R   R   t   context_callbackR9   R6   R$   Ri   RÆ   Rs   RG   R{   t   RestartContextRß   t   execute_default_statementR   t   RestartTopContext(   t   topRi   R‡   R   (    (    s   renpy/execution.pyt   run_contextm  s(    	


(   t
   __future__R    Rž   R   t   renpy.displayR   t
   renpy.testR   t
   __import__R   R   R   R   R   t   objectR   t   ObjectR   R   R!   Rì   (    (    (    s   renpy/execution.pyt   <module>   s"   		ÿ ÿ ý