a
    VŸ$cÄ0 ã                   @   s‚  d dl mZmZmZmZmZ d dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZ d dlmZmZ d dlmZmZ d dlZd dlZd dlZd dlZd dlZd dlZd dlm Z m!Z! d dl"m#Z# d dl$m%Z& d d	l'm(Z( d d
l)m*Z*m+Z+m,Z,m-Z-m.Z. d dl/Z/d dl0Z0e1e0 0¡ d ƒa2ej3 4d¡Z5dZ6ej7jdddddZ8dd„ Z9G dd„ dej:j;ƒZ<G dd„ de3ƒZ=ej3 4d¡Z>G dd„ de=ƒZ?e@eAfZBG dd„ de3ƒZCejDjE F¡ ZGG dd„ de?ƒZHG dd „ d e=ƒZIG d!d"„ d"e=ƒZJG d#d$„ d$e?ƒZKG d%d&„ d&e=ƒZLG d'd(„ d(e=ƒZMG d)d*„ d*e=ƒZNG d+d,„ d,e=ƒZOG d-d.„ d.e=ƒZPG d/d0„ d0e=ƒZQG d1d2„ d2e?ƒZRG d3d4„ d4e3ƒZSeSƒ ZTd5ZUd6d7„ ZVd8d9„ ZWdS ):é    )ÚdivisionÚabsolute_importÚwith_statementÚprint_functionÚunicode_literals)ÚPY2Ú
basestringÚbchrÚbordÚchrÚopenÚpystrÚrangeÚroundÚstrÚtobytesÚunicode)ÚOptionalÚAny)ÚloadsÚdumpsN)Ú	TransformÚATLTransform)ÚFixed)Údisplayable)Úpy_eval_bytecode)ÚAnalysisÚ	NOT_CONSTÚLOCAL_CONSTÚGLOBAL_CONSTÚccachei@B Úuse_expressionz<screen language>Úprofile_screenTF)Ú	developerÚappendÚflushc                 C   sL   | d }|t jjv rt jj}nt jj}tj|d}t |¡ t||d|dƒS )z:
    Wraps the node in a python AST, and compiles it.
    r   )ÚbodyÚevalé   )	ÚrenpyÚpythonÚ	py3_filesÚpy3_compile_flagsÚnew_compile_flagsÚastÚ
ExpressionÚfix_missing_locationsÚcompile)ÚlocÚnodeÚfilenameÚflagsÚexpr© r7   úrenpy/sl2\slast.pyÚcompile_exprG   s    

r9   c                   @   s*   e Zd ZdZd	dd„Zdd„ Zdd„ ZdS )
Ú	SLContextzs
    A context object that can be passed to the execute methods, and can also
    be placed in renpy.ui.stack.
    Nc                 C   s²   |d ur| j  |j ¡ d S i | _| j| _i | _g | _i | _d | _i | _i | _	i | _
t t¡| _d | _d | _d| _d| _d| _tƒ | _d | _d| _d | _d | _d| _i | _i | _d S ©NF)Ú__dict__ÚupdateÚscopeÚ
root_scopeÚglobalsÚchildrenÚkeywordsÚstyle_prefixÚ	new_cacheÚ	old_cacheÚ
miss_cacheÚcollectionsÚdefaultdictÚintÚ	use_indexÚ
uses_scopeÚwidgetsÚdebugÚ
predictingÚupdatingÚsetÚ	predictedÚshowifÚfailÚparentÚ
transcludeÚunlikelyÚnew_use_cacheÚold_use_cache)ÚselfrT   r7   r7   r8   Ú__init__]   s4    zSLContext.__init__c                 C   s   | j  |¡ d S ©N)rA   r$   )rY   ÚdÚkeyr7   r7   r8   Úadd²   s    zSLContext.addc                 C   s   t dƒ‚d S )NzSpurious ui.close().)Ú	Exception)rY   r\   r7   r7   r8   Úcloseµ   s    zSLContext.close)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rZ   r^   r`   r7   r7   r7   r8   r:   W   s   
Ur:   c                   @   s”   e Zd ZdZeZdZdZdd„ Zdd„ Z	dd„ Z
d	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!S )"ÚSLNodez3
    The base class for screen language nodes.
    Fc                 C   s   t d7 a t | _ || _d S )Nr(   )ÚserialÚlocation©rY   r2   r7   r7   r8   rZ   È   s    zSLNode.__init__c                 C   s&   t | ƒ}| |¡}| j|_| j|_|S )z‡
        Instantiates a new instance of this class, copying the global
        attributes of this class onto the new instance.
        )ÚtypeÚ__new__rf   rg   )rY   rU   ÚclsÚrvr7   r7   r8   ÚinstantiateÒ   s
    
zSLNode.instantiatec                 C   s   t dt| ƒj ƒ‚dS )zv
        Makes a copy of this node.

        `transclude`
            The constness of transclude statements.
        zcopy not implemented by N©r_   ri   ra   ©rY   rU   r7   r7   r8   Úcopyà   s    zSLNode.copyc                 C   s    |rd S | j \}}|||d fgS r[   )rg   )rY   ÚnameÚlastr4   Úliner7   r7   r8   Úreport_tracebackê   s    
zSLNode.report_tracebackc                 C   s   dS )zQ
        Performs static analysis on Python code used in this statement.
        Nr7   ©rY   Úanalysisr7   r7   r8   Úanalyzeò   s    zSLNode.analyzec                 C   s   dS )a$  
        This should be called before the execute code is called, and again
        after init-level code (like the code in a .rpym module or an init
        python block) is called.

        `analysis`
            A pyanalysis.Analysis object containing the analysis of this screen.
        Nr7   ru   r7   r7   r8   Úprepareù   s    zSLNode.preparec                 C   s   t dt| ƒj ƒ‚dS )zE
        Execute this node, updating context as appropriate.
        zexecute not implemented by Nrn   ©rY   Úcontextr7   r7   r8   Úexecute  s    zSLNode.executec                 C   s   dS )zN
        Execute this node, updating context.keywords as appropriate.
        Nr7   ry   r7   r7   r8   rB     s    zSLNode.keywordsc                 C   s   dS )zr
        Flags the displayables that are created by this node and its children
        as copy-on-change.
        Nr7   ©rY   Úcacher7   r7   r8   Úcopy_on_change  s    zSLNode.copy_on_changec                 C   sN   | j \}}tj |¡}t ||¡p$d}t d||| ¡ ¡ | j	rJt d¡ dS )zN
        Writes information about the line we're on to the debug log.
        Ú z
  %s:%d %sz    potentially constantN)
rg   r)   ÚexportsÚunelide_filenameÚ	linecacheÚgetlineÚprofile_logÚwriteÚrstripÚconstant)rY   r4   ÚlinenoÚfull_filenamers   r7   r7   r8   Ú
debug_line  s    
zSLNode.debug_linec                 C   s   dS )ze
        Calls callback with the name of each screen this node and its
        children use.
        Nr7   ©rY   Úcallbackr7   r7   r8   Úused_screens+  s    zSLNode.used_screensc                 C   s   dS )z[
        Returns true if this node is a transclude or has a transclude as a child.
        Fr7   ©rY   r7   r7   r8   Úhas_transclude3  s    zSLNode.has_transcludec                 C   s   dS )zV
        Returns true if this node is Python or has a python node as a child.
        Fr7   rŽ   r7   r7   r8   Ú
has_python:  s    zSLNode.has_pythonc                 C   s   t dt| ƒj ƒ‚dS )z
        Dumps a tree-representation of this node, to help determine what
        Ren'Py is treating as const and not.
        zdump_const not implemented by Nrn   ©rY   Úprefixr7   r7   r8   Ú
dump_constA  s    zSLNode.dump_constc                 G   sX   | j tkrd}n| j tkr d}nd}|j|Ž }t dd |||| jd | jd ¡¡ dS )	zI
        Adds a line of const dump information to the debug log.
        zglobal zlocal  znot    z%sz    {}{}{} ({}:{})r   r(   N)r‡   r   r   Úformatr„   r…   rg   )rY   r’   ÚtextÚargsÚ
const_typeÚ	formattedr7   r7   r8   ÚdcI  s    


z	SLNode.dcN)ra   rb   rc   rd   r   r‡   Úhas_keywordÚlast_keywordrZ   rm   rp   rt   rw   rx   r{   rB   r~   rŠ   r   r   r   r“   r™   r7   r7   r7   r8   re   ¹   s&   

re   ÚNotGivenc                   @   s„   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚSLBlockzk
    Represents a screen language block that can contain keyword arguments
    and child displayables.
    Nc                 C   s   t  | |¡ g | _g | _d S r[   )re   rZ   ÚkeywordrA   rh   r7   r7   r8   rZ   g  s    zSLBlock.__init__c                    s6   t  | ˆ ¡}| j|_‡ fdd„| jD ƒ|_| j|_|S )Nc                    s   g | ]}|  ˆ ¡‘qS r7   ©rp   ©Ú.0Úi©rU   r7   r8   Ú
<listcomp>s  ó    z'SLBlock.instantiate.<locals>.<listcomp>)re   rm   rž   rA   Úatl_transform©rY   rU   rl   r7   r£   r8   rm   p  s
    zSLBlock.instantiatec                 C   s
   |   |¡S r[   ©rm   ro   r7   r7   r8   rp   x  s    zSLBlock.copyc                 C   s   | j D ]}| |¡ qd S r[   )rA   rw   )rY   rv   r¢   r7   r7   r8   rw   {  s    
zSLBlock.analyzec                 C   s¦  | j D ]}| |¡ t| j|jƒ| _qi }g }g }| jD ]d\}}t |¡}| |¡}	|	tkrrt	t
| j|ƒƒ||< n| tj|d¡ | |¡ t| j|	ƒ| _q8|rª|| _nd | _|râtj||d}t ||d ¡ t
| j|ƒ| _nd | _t| jƒ| _g | _| jd urFd| _| j |¡ | jjtkr0| j ¡  | jj}	t| j|	ƒ| _d}
| j D ]P}|jr||
rjtdƒ‚| j |¡ d| _|jrPd| _d}
tjjsP q¢qPd S )N)Ús)ÚkeysÚvaluesr   TFz Properties are not allowed here.)rA   rx   Úminr‡   rž   r    Úast_evalÚis_constantr   r   r9   rg   r$   r.   ÚStrÚkeyword_valuesÚDictÚcopy_locationÚkeyword_exprsÚboolrš   Úkeyword_childrenr¦   Úmark_constantÚcompile_blockr_   r›   r)   Úconfigr#   )rY   rv   r¢   r°   Úkeyword_keysr³   Úkr6   r3   ÚconstÚwas_last_keywordr7   r7   r8   rx   €  sV    







zSLBlock.preparec              	   C   s:   | j D ].}z| |¡ W q ty2   |js.‚ Y q0 qd S r[   )rA   r{   r_   rN   )rY   rz   r¢   r7   r7   r8   r{   Ë  s    
zSLBlock.executec                 C   s°   | j }|d ur|j |¡ | j}|d ur@|j t||j|jƒ¡ | jD ]}| |¡ qF| jd urzt	| j|jd}||jd< |j 
dt¡}|tu rž|j 
dt¡}|tur¬||_d S )N©rz   ÚatrC   Ústyle_group)r°   rB   r=   r³   r'   r@   r>   rµ   r¦   r   Úpoprœ   rC   )rY   rz   r°   r³   r¢   Ú	transformrC   r7   r7   r8   rB   Ø  s     


zSLBlock.keywordsc                 C   s   | j D ]}| |¡ qd S r[   )rA   r~   )rY   r}   r¢   r7   r7   r8   r~   ó  s    
zSLBlock.copy_on_changec                 C   s   | j D ]}| |¡ qd S r[   )rA   r   )rY   rŒ   r¢   r7   r7   r8   r   ÷  s    
zSLBlock.used_screensc                 C   s   | j D ]}| ¡ r dS qdS ©NTF)rA   r   )rY   r¢   r7   r7   r8   r   û  s    
zSLBlock.has_transcludec                 C   s   t dd„ | jD ƒƒS )Nc                 s   s   | ]}|  ¡ V  qd S r[   ©r   r    r7   r7   r8   Ú	<genexpr>  r¥   z%SLBlock.has_python.<locals>.<genexpr>)ÚanyrA   rŽ   r7   r7   r8   r     s    zSLBlock.has_pythonc                 C   sb   t | jƒ}|r^| d¡}t|ƒtu r2| |j¡ q
t|tƒrX|jD ]\}}| 	|¡ qBq
dS q
dS )zs
        Returns true if this block has a child that is not an SLIf statement,
        or false otherwise.
        r   TF)
ÚlistrA   rÀ   ri   r   ÚextendÚ
isinstanceÚSLIfÚentriesr$   )rY   ÚworklistÚnÚ_Úblockr7   r7   r8   Úhas_noncondition_child  s    


zSLBlock.has_noncondition_childc                 C   s<   |t | jƒv rdS | jD ]}t|tƒr| |¡r dS qdS )zz
        Returns true if this block or it's SLIf children have parsed `name` keyword,
        or false otherwise.
        TF)Údictrž   rA   rÈ   rÉ   Úkeyword_exist)rY   rq   rÌ   r7   r7   r8   rÑ     s    


zSLBlock.keyword_existc                 C   s*   |   |d¡ | jD ]}| |d ¡ qd S )NrÎ   ú  )r™   rA   r“   ©rY   r’   r¢   r7   r7   r8   r“   ,  s    
zSLBlock.dump_const)ra   rb   rc   rd   r¦   rZ   rm   rp   rw   rx   r{   rB   r~   r   r   r   rÏ   rÑ   r“   r7   r7   r7   r8   r   ^  s    	Kr   c                   @   s   e Zd ZdZdd„ ZdS )ÚSLCachez=
    The type of cache associated with an SLDisplayable.
    c                 C   s^   d | _ d | _d | _d | _d | _d | _d | _d | _d | _g | _	i | _
d| _d | _d | _d | _d S r;   )r   Ú
positionalrB   rA   Úouter_transformÚinner_transformÚraw_transformÚimagemapr‡   Úconstant_uses_scopeÚconstant_widgetsr~   Ú
old_showifrU   rC   rŽ   r7   r7   r8   rZ   ;  s    zSLCache.__init__N)ra   rb   rc   rd   rZ   r7   r7   r7   r8   rÔ   6  s   rÔ   c                   @   sŽ   e Zd ZdZdZdZdZdZg Zdddddddi ddddfdd„Z	dd	„ Z
d
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚSLDisplayablezc
    A screen language AST node that corresponds to a displayable being
    added to the tree.
    FNr   Tc                 C   s^   t  | |¡ || _|| _|| _|| _|| _|| _|| _|	| _	|
| _
|| _|| _g | _|| _dS )aì  
        `displayable`
            A function that, when called with the positional and keyword
            arguments, causes the displayable to be displayed.

        `scope`
            If true, the scope is supplied as an argument to the displayable.

        `child_or_fixed`
            If true and the number of children of this displayable is not one,
            the children are added to a Fixed, and the Fixed is added to the
            displayable.

        `style`
            The base name of the main style.

        `pass_context`
            If given, the context is passed in as the first positional argument
            of the displayable.

        `imagemap`
            True if this is an imagemap, and should be handled as one.

        `hotspot`
            True if this is a hotspot that depends on the imagemap it was
            first displayed with.

        `replaces`
            True if the object this displayable replaces should be
            passed to it.

        `default_keywords`
            The default keyword arguments to supply to the displayable.

        `variable`
            A variable that the main displayable is assigned to.

        `name`
            The name of the displayable, used for debugging.
        N)r   rZ   r   r>   Úchild_or_fixedÚstyleÚpass_contextrÙ   ÚhotspotÚreplacesÚdefault_keywordsÚvariableÚuniquerÕ   rq   )rY   r2   r   r>   rÞ   rß   Ú
text_stylerà   rÙ   râ   rã   rá   rä   rq   rå   r7   r7   r8   rZ   ‚  s    *zSLDisplayable.__init__c                 C   sv   |   |¡}| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j	|_	| j
|_
| j|_| j|_| j|_|S r[   )rm   r   r>   rÞ   rß   rà   rÙ   rá   râ   rã   rä   rÕ   rq   rå   r§   r7   r7   r8   rp   À  s    
zSLDisplayable.copyc                 C   s  | j r:t}| jD ]\}}t|| |¡ƒ}q|j|tkd | jrRt|  ¡ | jƒ| _t 	| |¡ | j rl| 
¡  | jr~t|jƒ| _| jd ur
| j}| jD ]}t| j| |¡ƒ}q–| jD ]\}}t| j| |¡ƒ}q´|  d¡rÞt}|tkrô| | j¡ n|tkr
| | j¡ d S )N)rÙ   Úid)rÙ   r   rž   r¬   Úis_constant_exprÚpush_controlrá   r‡   r   rw   Úpop_controlr>   rÆ   Úlocal_constanträ   rÕ   rÑ   r   r   r¶   Úmark_not_constant)rY   rv   r»   Ú_kr6   r¢   rº   Úvr7   r7   r8   rw   Ó  s0    


zSLDisplayable.analyzec           
      C   s  t  | |¡ g }g }d}d}| jD ]t}t |¡}| |¡}|tkrp| tt	| j
|ƒƒ¡ | tjdd¡ d}n| t¡ | |¡ d}t| j|ƒ| _q"|r¤|| _nd | _|ràtj|t ¡ d}	t |	|d ¡ t	| j
|	ƒ| _nd | _d| _|  d¡rüt| _| jd urt| _d S )NFr   )rÌ   T)ÚeltsÚctxrç   )r   rx   rÕ   r    r­   r®   r   r$   r   r9   rg   r.   ÚNumr!   r¬   r‡   Úpositional_valuesÚTupleÚLoadr²   Úpositional_exprsrš   rÑ   r   rä   )
rY   rv   Úexprsr«   Ú	has_exprsÚ
has_valuesÚar3   r»   Útr7   r7   r8   rx   ü  s:    





zSLDisplayable.preparec                 C   s   d S r[   r7   ry   r7   r7   r8   rB   2  s    zSLDisplayable.keywordsc           %   	   C   sÎ	  |j }tjj}|j | jd ¡p,|j | jd ¡}t|t	ƒs>t	ƒ }||j
| j< |j}|r\|  ¡  |jr<|j|jkr<|jD ]^\}}}|d u r|j}|r¨t|ƒ}	|	 |¡ n|}	|rÊ| |	d¡rÖd |_ q<qx| |	d¡ qx|j}
|
tur|jd ur|  |
||¡}
|j |
¡ |jd ur(|j |j¡ |r8t d¡ d S t|ƒ}d}d }d}d}zr| j}| j}|r–|r–t ||j!|j"ƒ}dd„ t#||ƒD ƒ}n(|r¢|}n|rºt ||j!|j"ƒ}ng }| j$ %¡  }|_&| jrÜg |_t' &| |¡ | (dd ¡}|r||7 }| (dd ¡}|r| |¡ | (dd ¡}| (d	d ¡}| (d
d ¡pH| j)}d|vr‚|r‚|jd u rp||d< n|jd | |d< |r¤||j*v r¤| |j*| ¡ |j+}|r¾|j,pº|}nd }|rØ|  -||||¡ |d uo||j.ko||j&ko|j|jk}| j/d ur|rd}| j0rFtjj1d }|j2|ur@d}||_2|r´d}|}
|}|rz|j3sz||j4|< |
|j5|< | j"r´|j6r´|r¦| |j"d¡r´d}n| |j"d¡ |rà| j2ràd}|j2 7¡  tjj1 |j2¡ |s||_.| %¡ |_&| j"r|j"|d< | j8r |j9r ||d< | j:r0||d< | j+|i |¤Ž}
|
 ;¡  |
j,pR|
}| j<|_=|r~|j3s~||j4|< |
|j5|< | j2}d|_d |_|rÆ|r¨t d¡ n| jr¼t d¡ n
t d¡ W n" t>yê   |j?sâ‚ d}Y n0 | j/d ur||j"| j/< g |_d |_tjj@}| |¡ zr| jD ]8}z| A|¡ W n" t>y^   |j?sV‚ d}Y n0 q*W d |_&| (¡  |rÆtjj1 (¡ |_2|j2jB C¡  n0d |_&| (¡  |rÄtjj1 (¡ |_2|j2jB C¡  0 |rôtD|ƒ |jD ]}tD|ƒ qÚd|_Ed S |j|jkrü|r”|r”|}| j"r$|j"|d< | j8r<|j9r<||d< | j:rL||d< | j+|i |¤Ž}
|
j,pf|
}| j<|_=|rŠ||j4|< |
|j5|< d|_d}|r¢| F¡  | jGrätH|jƒdkrätIƒ }|jD ]}| J|¡ qÆ| J|¡ n|jD ]}| J|¡ qê|
}
|}|j?s\|d ur\tjKjLjM} |
| tN|ƒ< |
|ur\t#|jO|
jOƒD ]\}!}"|"| tN|!ƒ< qD|
|_+|j|_|j|_|}|d urÖ|
turÖ|rÖ||jPkrÖt|jQtjKjRjSƒrÎ|jQjT|
urÎ|jQjU|
dd |jV}
nþ|jV}#||_Pd |_Qd |_Vt|tSƒr||
d}
|
 ;¡  |
|_Q|
|_VnŽt|tWƒr†|D ]X}$t|$tSƒr^|$|
d}
|
|_V|jQd u rx|
|_Qn|$|
ƒ}
d |_Pd |_Vd |_Q|
 ;¡  q*n"||
ƒ}
|
 ;¡  d |_Pd |_Vd |_Qt|
tSƒrè|j9sÀd }#|
 X|#¡ |
 Y|#¡ nd |_Qd |_Vd |_P|jErød|_En¢| j	rš|
|_| j"	rx|j6	rxi }| jZD ] }||j"v 	r |j"| ||< 	q |j"|ju 	rd|j ||d f¡ n|j |||j"f¡ |j|_|jd u	rš|j |j¡ |
tu	rÊ|jd u	r¾|  |
||¡}
|j |
¡ d S )NFTz    reused constant displayablec                 S   s    g | ]\}}|t u r|n|‘qS r7   )r!   )r¡   rù   Úbr7   r7   r8   r¤   …  r¥   z)SLDisplayable.execute.<locals>.<listcomp>Ú	argumentsÚ
propertiesrç   r¾   Ústyle_suffixrß   rÍ   éÿÿÿÿr>   râ   rz   z    reused displayablez     created constant displayablez    created displayabler(   )Ú	duplicate)Úchild)[rM   r)   ÚuiÚscreenrE   Úgetrf   rF   rÈ   rÔ   rD   r~   rŠ   r‡   rC   rÚ   r?   rÐ   r=   Ú_scopeÚNO_DISPLAYABLErR   Úwrap_in_showifrA   r$   rK   rÇ   r„   r…   r:   rò   rõ   r'   r@   r>   Úziprã   rp   rB   r   rÀ   rß   Úwidget_propertiesr   Ú_mainÚreport_argumentsrÕ   rä   rá   Úimagemap_stackrÙ   rV   rL   Úbase_widgetsÚ_uses_scopeÚreuserâ   rO   rà   Ú_uniquerg   Ú	_locationr_   rN   Ústackr{   r}   ÚfinishÚpredict_displayablerS   Ú_clearrÞ   Úlenr   r^   ÚdisplayÚfocusÚreplaced_byrç   Ú_composite_partsrØ   r×   rÁ   r   r  Ú	set_childrÖ   Úlist_or_tupleÚ
take_stateÚtake_execution_staterë   )%rY   rz   rM   r  r}   r~   r¢   Úlocal_scopeÚcontext_scoper>   r\   rð   rS   ÚmainrÙ   Úreusedrò   rõ   r«   rÕ   rB   rü   rý   Ú	widget_idrÁ   rþ   Úold_dÚold_mainÚ	can_reuseÚimcr  Úfr  Úold_partÚnew_partÚold_outer_transformrú   r7   r7   r8   r{   6  sú    




.









ú












zSLDisplayable.executec                 C   s.   t jj |j|j¡}| |¡ |js*||_|S )z4
        Wraps `d` in a ShowIf displayable.
        )r)   Úsl2ÚsldisplayablesÚShowIfrR   rÜ   r^   rN   )rY   r\   rz   r}   rl   r7   r7   r8   r  Ì  s
    
zSLDisplayable.wrap_in_showifc           	      C   sÄ  |r–g }| j ptgt|ƒ }tt|ƒƒD ]Z}|| turD| d¡ q(|jd u rZ| d¡ q(|j| || krx| d¡ q(| d¡ q(t dd |¡¡ | j	pži }|rfi }|j
d u rÚ|D ]}||v rÎd||< q¸d||< q¸n€|D ]Z}t|ƒ}||v rüd||< qÞ||j
vrd||< qÞ|| |j
| kr0d||< qÞd||< qÞ|j
D ]}||vr@d||< q@t d	|¡ |d urÀd
|v r†t d¡ n:|jd u ržt d¡ n"|j|kr¶t d¡ n
t d¡ d S )Nr»   ÚnewÚequalz	not-equalz    args: %sú znew-onlyzold-onlyz    kwargs: %rr¾   z    at: constz    at: newz    at: equalz    at: not-equal)rò   r!   r  r   r$   rÕ   r„   r…   Újoinr°   rB   r   rØ   )	rY   r}   rÕ   rB   rÁ   Úreportr«   r¢   rº   r7   r7   r8   r  Ù  sX    








zSLDisplayable.report_argumentsc                 C   s8   |  | jd ¡}t|tƒrd|_| jD ]}| |¡ q$d S ©NT)r  rf   rÈ   rÔ   r~   rA   )rY   r}   Úcr¢   r7   r7   r8   r~     s
    

zSLDisplayable.copy_on_changec                 C   s,   |   || j¡ | jD ]}| |d ¡ qd S )NrÒ   )r™   rq   rA   r“   rÓ   r7   r7   r8   r“   $  s    
zSLDisplayable.dump_const)ra   rb   rc   rd   rá   rä   rq   rå   rë   rZ   rp   rw   rx   rB   r{   r  r  r~   r“   r7   r7   r7   r8   rÝ   s  s&   ">)6   B	rÝ   c                   @   sx   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )rÉ   zS
    A screen language AST node that corresponds to an If/Elif/Else statement.
    c                 C   s   t  | |¡ g | _dS ©z>
        An AST node that represents an if statement.
        N©re   rZ   rÊ   rh   r7   r7   r8   rZ   0  s    zSLIf.__init__c                    s$   |   ˆ ¡}‡ fdd„| jD ƒ|_|S )Nc                    s   g | ]\}}||  ˆ ¡f‘qS r7   rŸ   ©r¡   r6   rÎ   r£   r7   r8   r¤   =  r¥   zSLIf.copy.<locals>.<listcomp>©rm   rÊ   r§   r7   r£   r8   rp   :  s    
z	SLIf.copyc                 C   s\   t }| jD ] \}}|d ur
t|| |¡ƒ}q
| |¡ | jD ]\}}| |¡ q<| ¡  d S r[   )r   rÊ   r¬   rè   ré   rw   rê   )rY   rv   r»   ÚcondÚ_blockÚ_condrÎ   r7   r7   r8   rw   A  s    
zSLIf.analyzec                 C   s–   g | _ | jD ]„\}}|d urFt |¡}t| j| |¡ƒ| _t| j|ƒ}| 	|¡ t| j|jƒ| _| j  
||f¡ |  j|jO  _|  j|jO  _qd S r[   )Úprepared_entriesrÊ   r    r­   r¬   r‡   r®   r9   rg   rx   r$   rš   r›   ©rY   rv   r:  rÎ   r3   r7   r7   r8   rx   P  s    

zSLIf.preparec                 C   s\   |j r|  |¡ d S | jD ]<\}}|d u s:t||j|jƒr|jD ]}| |¡ q@ d S qd S r[   )rN   Úexecute_predictingr=  r'   r@   r>   rA   r{   )rY   rz   r:  rÎ   r¢   r7   r7   r8   r{   e  s    

zSLIf.executec           	   
   C   s  d}g }| j D ]‚\}}z|d u p.t||j|jƒ}W n tyH   d}Y n0 |r†|r†d}|jD ]&}z| |¡ W q\ ty€   Y q\0 q\q| |¡ q| j|j	v r¢d S |j	 
| j¡ |D ]\}t|ƒ}g |_d|_|jD ]&}z| |¡ W qÒ työ   Y qÒ0 qÒ|jD ]}t|ƒ q q´d S rÂ   )r=  r'   r@   r>   r_   rA   r{   r$   rf   rQ   r^   r:   rV   r  )	rY   rz   ÚfirstÚfalse_blocksr:  rÎ   Ú
cond_valuer¢   rð   r7   r7   r8   r?  q  s:    




zSLIf.execute_predictingc                 C   s<   | j D ]0\}}|d u s&t||j|jƒr| |¡  d S qd S r[   )r=  r'   r@   r>   rB   )rY   rz   r:  rÎ   r7   r7   r8   rB   ¤  s    
zSLIf.keywordsc                 C   s   | j D ]\}}| |¡ qd S r[   ©rÊ   r~   ©rY   r}   r<  rÎ   r7   r7   r8   r~   «  s    zSLIf.copy_on_changec                 C   s   | j D ]\}}| |¡ qd S r[   ©rÊ   r   ©rY   rŒ   r<  rÎ   r7   r7   r8   r   ¯  s    zSLIf.used_screensc                 C   s"   | j D ]\}}| ¡ r dS qdS rÂ   ©rÊ   r   ©rY   r<  rÎ   r7   r7   r8   r   ³  s    zSLIf.has_transcludec                 C   s   t dd„ | jD ƒƒS )Nc                 s   s   | ]}|d    ¡ V  qdS ©r(   NrÃ   r    r7   r7   r8   rÄ   »  r¥   z"SLIf.has_python.<locals>.<genexpr>©rÅ   rÊ   rŽ   r7   r7   r8   r   º  s    zSLIf.has_pythonc                    s   t ‡ fdd„| jD ƒƒS )Nc                 3   s   | ]}|d    ˆ ¡V  qdS rI  )rÑ   r    ©rq   r7   r8   rÄ   ¾  r¥   z%SLIf.keyword_exist.<locals>.<genexpr>rJ  )rY   rq   r7   rK  r8   rÑ   ½  s    zSLIf.keyword_existc                 C   sX   d}| j D ]H\}}|r&|  |d|¡ n|  |d|¡ d}|jD ]}| |d ¡ q>q
d S )NTzif {}zelif {}FrÒ   ©rÊ   r™   rA   r“   ©rY   r’   r@  r:  rÎ   r¢   r7   r7   r8   r“   À  s    
zSLIf.dump_constN)ra   rb   rc   rd   rZ   rp   rw   rx   r{   r?  rB   r~   r   r   r   rÑ   r“   r7   r7   r7   r8   rÉ   +  s   
3rÉ   c                   @   s`   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZdS )ÚSLShowIfz@
    The AST node that corresponds to the showif statement.
    c                 C   s   t  | |¡ g | _dS r6  r7  rh   r7   r7   r8   rZ   Õ  s    zSLShowIf.__init__c                    s$   |   ˆ ¡}‡ fdd„| jD ƒ|_|S )Nc                    s   g | ]\}}||  ˆ ¡f‘qS r7   rŸ   r8  r£   r7   r8   r¤   â  r¥   z!SLShowIf.copy.<locals>.<listcomp>r9  r§   r7   r£   r8   rp   ß  s    
zSLShowIf.copyc                 C   s   | j D ]\}}| |¡ qd S r[   )rÊ   rw   )rY   rv   r<  rÎ   r7   r7   r8   rw   æ  s    zSLShowIf.analyzec                 C   s|   g | _ | jD ]d\}}|d urFt |¡}t| j| |¡ƒ| _t| j|ƒ}| 	|¡ t| j|jƒ| _| j  
||f¡ qd| _d S r4  )r=  rÊ   r    r­   r¬   r‡   r®   r9   rg   rx   r$   r›   r>  r7   r7   r8   rx   ë  s    

zSLShowIf.preparec                 C   s~   |j du}| jD ]h\}}t|ƒ}|s,d|_ n*|d u sDt||j|jƒrPd|_ d}nd|_ |jD ]}| |¡ q\|jrd|_qd S )NFT)	rR   r=  r:   r'   r@   r>   rA   r{   rS   )rY   rz   Ú
first_truer:  rÎ   rð   r¢   r7   r7   r8   r{   ÿ  s    

zSLShowIf.executec                 C   s   | j D ]\}}| |¡ qd S r[   rC  rD  r7   r7   r8   r~     s    zSLShowIf.copy_on_changec                 C   s   | j D ]\}}| |¡ qd S r[   rE  rF  r7   r7   r8   r     s    zSLShowIf.used_screensc                 C   s"   | j D ]\}}| ¡ r dS qdS rÂ   rG  rH  r7   r7   r8   r   !  s    zSLShowIf.has_transcludec                 C   s   t dd„ | jD ƒƒS )Nc                 s   s   | ]}|d    ¡ V  qdS rI  rÃ   r    r7   r7   r8   rÄ   )  r¥   z&SLShowIf.has_python.<locals>.<genexpr>rJ  rŽ   r7   r7   r8   r   (  s    zSLShowIf.has_pythonc                 C   sX   d}| j D ]H\}}|r&|  |d|¡ n|  |d|¡ d}|jD ]}| |d ¡ q>q
d S )NTz	showif {}zelse {}FrÒ   rL  rM  r7   r7   r8   r“   +  s    
zSLShowIf.dump_constN)ra   rb   rc   rd   rZ   rp   rw   rx   r{   r~   r   r   r   r“   r7   r7   r7   r8   rN  Ð  s   
rN  c                   @   sT   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ Zdd„ ZdS )ÚSLForz‚
    The AST node that corresponds to a for statement. This only supports
    simple for loops that assign a single variable.
    Nc                 C   s"   t  | |¡ || _|| _|| _d S r[   )r   rZ   rä   Ú
expressionÚindex_expression)rY   r2   rä   rQ  rR  r7   r7   r8   rZ   C  s    zSLFor.__init__c                 C   s&   |   |¡}| j|_| j|_| j|_|S r[   )rm   rä   rQ  rR  r§   r7   r7   r8   rp   J  s
    
z
SLFor.copyc                 C   sV   |  | j¡tkr(| d¡ | | j¡ n| d¡ | | j¡ t | |¡ | 	¡  d S rÂ   )
rè   rQ  r   ré   r¶   rä   rì   r   rw   rê   ru   r7   r7   r8   rw   S  s    

zSLFor.analyzec                 C   sp   t  | j¡}| |¡}|tkr8tt| j|ƒƒ| _d | _	nd | _t| j|ƒ| _	t
| j|ƒ| _t | |¡ d| _d S r4  )r    r­   rQ  r®   r   r   r9   rg   Úexpression_valueÚexpression_exprr¬   r‡   r   rx   r›   )rY   rv   r3   r»   r7   r7   r8   rx   `  s    
zSLFor.preparec              
   C   sê  | j }| j}z$|d ur(t||j|jƒ}n| j}W n  tyP   |jsF‚ dg}Y n0 i }|j 	| j
|¡phi }t|tƒsxi }|j 	| j
|¡pŠi }t|tƒsši }t|ƒ}t|ƒD ]\}	}
|
|j|< t| jƒ}|dkrt|ƒ}z| |¡ W n ty   |js‚ Y n0 | jd ur&t| j|j|jƒ}	| 	|	d ¡p6i |_t|jtƒsNi |_| 	|	d ¡p^i |_t|jtƒsvi |_i  ||	< |_|D ]4}z| |¡ W n ty¸   |js´‚ Y n0 qˆ|jrª qÌqª||j| j
< |jræd|_d S )Nr   Ú_sl2_iT)rä   rT  r'   r@   r>   rS  r_   rN   rE   r  rf   rÈ   rÐ   rF   r:   Ú	enumerateÚiterrA   Únextr{   rR  rD   rV   rS   )rY   rz   rä   r6   ÚvalueÚ	newcachesÚ	oldcachesÚ
misscachesrð   Úindexrî   Ú
children_iÚ	sl_pythonr¢   r7   r7   r8   r{   r  s`    





zSLFor.executec                 C   s   d S r[   r7   ry   r7   r7   r8   rB   Â  s    zSLFor.keywordsc                 C   sD   |  | jd ¡}t|tƒsd S | ¡ D ]}| jD ]}| |¡ q.q$d S r[   )r  rf   rÈ   rÐ   r«   rA   r~   )rY   r}   r5  Úchild_cacher¢   r7   r7   r8   r~   Å  s    

zSLFor.copy_on_changec                 C   s2   |   |d| j| j¡ | jD ]}| |d ¡ qd S )Nzfor {} in {}rÒ   )r™   rä   rQ  rA   r“   rÓ   r7   r7   r8   r“   Ï  s    
zSLFor.dump_const)ra   rb   rc   rd   rR  rZ   rp   rw   rx   r{   rB   r~   r“   r7   r7   r7   r8   rP  ;  s   	P
rP  c                   @   sD   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dS )ÚSLPythonc                 C   s   t  | |¡ || _d S r[   )re   rZ   Úcode)rY   r2   rb  r7   r7   r8   rZ   Ø  s    zSLPython.__init__c                 C   s   |   |¡}| j|_|S r[   )rm   rb  r§   r7   r7   r8   rp   Þ  s    
zSLPython.copyc                 C   s   |  | jj¡ d S r[   )r*   rb  Úsourceru   r7   r7   r8   rw   å  s    zSLPython.analyzec                 C   s   t | jj|j|jƒ d S r[   )Úexecrb  Úbytecoder@   r>   ry   r7   r7   r8   r{   è  s    zSLPython.executec                 C   s   t | _d| _d S r4  )r   r‡   r›   ru   r7   r7   r8   rx   ë  s    zSLPython.preparec                 C   s   dS r4  r7   rŽ   r7   r7   r8   r   ï  s    zSLPython.has_pythonc                 C   s   |   |d¡ d S )Nr*   ©r™   r‘   r7   r7   r8   r“   ò  s    zSLPython.dump_constN)
ra   rb   rc   rZ   rp   rw   r{   rx   r   r“   r7   r7   r7   r8   ra  Ö  s   ra  c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚSLPassc                 C   s   d S r[   r7   ry   r7   r7   r8   r{   ø  s    zSLPass.executec                 C   s   |   |¡}|S r[   r¨   r§   r7   r7   r8   rp   û  s    
zSLPass.copyc                 C   s   |   |d¡ d S )NÚpassrf  r‘   r7   r7   r8   r“      s    zSLPass.dump_constN)ra   rb   rc   r{   rp   r“   r7   r7   r7   r8   rg  ö  s   rg  c                   @   sD   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dS )Ú	SLDefaultc                 C   s   t  | |¡ || _|| _d S r[   )re   rZ   rä   rQ  )rY   r2   rä   rQ  r7   r7   r8   rZ     s    zSLDefault.__init__c                 C   s   |   |¡}| j|_| j|_|S r[   )rm   rä   rQ  r§   r7   r7   r8   rp     s    
zSLDefault.copyc                 C   s   |  | j¡ d S r[   )rì   rä   ru   r7   r7   r8   rw     s    zSLDefault.analyzec                 C   s&   t | jt | j¡ƒ| _t| _d| _d S r4  )	r9   rg   r    r­   rQ  r6   r   r‡   r›   ru   r7   r7   r8   rx     s    zSLDefault.preparec                 C   s0   |j }| j}||v rd S t| j|j|ƒ||< d S r[   )r>   rä   r'   r6   r@   )rY   rz   r>   rä   r7   r7   r8   r{     s
    zSLDefault.executec                 C   s   dS r4  r7   rŽ   r7   r7   r8   r   %  s    zSLDefault.has_pythonc                 C   s   |   |d| j| j¡ d S )Nzdefault {} = {})r™   rä   rQ  r‘   r7   r7   r8   r“   (  s    zSLDefault.dump_constN)
ra   rb   rc   rZ   rp   rw   rx   r{   r   r“   r7   r7   r7   r8   ri    s   	ri  c                   @   sd   e Zd ZdZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ ZdS )ÚSLUseNc                 C   s.   t  | |¡ || _d | _|| _|| _|| _d S r[   )re   rZ   Útargetr.   r–   rç   rÎ   )rY   r2   rk  r–   Úid_exprrÎ   r7   r7   r8   rZ   0  s    zSLUse.__init__c                 C   sL   |   |¡}| j|_| j|_| j|_| jd ur<| j |¡|_nd |_d |_|S r[   )rm   rk  r–   rç   rÎ   rp   r.   r§   r7   r7   r8   rp   E  s    

z
SLUse.copyc                 C   s(   d| _ | jrt| _| jr$| j |¡ d S r4  )r›   rç   r   r‡   rÎ   rw   ru   r7   r7   r8   rw   V  s
    zSLUse.analyzec                 C   sÖ   d | _ | jr0| j |¡ | jjtkr*d}q4d}nd}t| jtj jƒrVt	| _d}d | _ n|tj
j | j¡}|d u r’t	| _tjjrŽtd | j¡ƒ‚nd S |j d u r¦t	| _d S |r¶|j j| _ n
|j j| _ t| j| j jƒ| _d S )NTFú!A screen named {} does not exist.)r.   rÎ   rx   r‡   r   rÈ   rk  r)   ÚPyExprr   r  r  Úget_screen_variantr¸   r#   r_   r”   Ú	const_astÚnot_const_astr¬   )rY   rv   r»   rk  r7   r7   r8   rx   `  s0    

zSLUse.preparec                 C   s~   |j | j }|d |j | j< |j dd¡| j|f}| jrL| j |j¡\}}ng }i }tjjj	| j
g|¢R ||jdœ|¤Ž d S )Nr(   Ú_namer7   )rr  r  )rJ   rf   r>   r  r–   Úevaluater)   r  r  Ú
use_screenrk  )rY   rz   rf   rq   r–   Úkwargsr7   r7   r8   Úexecute_use_screenŒ  s    ýzSLUse.execute_use_screenc                 C   s¤  t | jtjjƒrTt| j|j|jƒ}tjj	 
|¡}|d u rFtd |¡ƒ‚|jj}d}n| j}| j}|d u rv|  |¡ d S t|ƒ}d|i |_|j| j< |j | jd ¡p¦i |_| jr
|t| j|j|jƒf}|j |d ¡pè|j | jd ¡pèi |_||jv rüd|_|j|j|< n|j | jd ¡pi |_t |jtƒs6i |_t |jtƒsJi |_z(| jrh| j |j¡\}}	ng }i }	W n& ty˜   |jsŒ‚ g }i }	Y n0 |jd urê|jj||	|jd}
|j dd ¡pÜ|j dd ¡pÜi }| |
¡ n^|rtd | jt |ƒ¡ƒ‚|j dd ¡p(|j dd ¡p(i }| !¡  | |j¡ | |	¡ ||d< ||jd< ||_t" #|¡|_$| j%|_&z| '|¡ W |d= n|d= 0 |j(r d|_(d S )	Nrm  Ú_use_expressionr.   T©Úignore_errorsr>   ú8Screen {} does not take positional arguments. ({} given)r  ))rÈ   rk  r)   r.   rn  r'   r@   r>   r  r  ro  r_   r”   rq  rv  r:   rD   rf   rF   r  rç   rX   rE   rO   rW   rÐ   r–   rs  rN   Ú
parametersÚapplyr=   r  ÚclearÚweakrefÚrefrT   rÎ   rU   r{   rS   )rY   rz   Útarget_namerk  r.   Ú	id_prefixrð   Úuse_idr–   ru  Ú	new_scoper>   r7   r7   r8   r{   Ÿ  sp    
$

$$

zSLUse.executec                 C   s<   |  | jd ¡}|d u rd S |  dd ¡}|d ur8| |¡ d S )Nr.   )r  rf   r~   )rY   r}   r5  r.   r7   r7   r8   r~     s    zSLUse.copy_on_changec                 C   s4   t | jtjjƒs|| jƒ | jd ur0| j |¡ d S r[   )rÈ   rk  r)   r.   rn  rÎ   r   r‹   r7   r7   r8   r     s    

zSLUse.used_screensc                 C   s   | j r| j  ¡ S dS d S r;   ©rÎ   r   rŽ   r7   r7   r8   r     s    
zSLUse.has_transcludec                 C   st   |   |d| j¡ | jjD ](}| jr2| |d ¡ q| |d ¡ q| jrp|   |d¡ | jjD ]}| |d ¡ q\d S )NÚuseõ   â”‚ rÒ   õ   â”” (transclude block)©r™   rk  r.   rA   rÎ   r“   rÓ   r7   r7   r8   r“     s    zSLUse.dump_const)ra   rb   rc   rç   rÎ   rZ   rp   rw   rx   rv  r{   r~   r   r   r“   r7   r7   r7   r8   rj  +  s   
,crj  c                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚSLTranscludec                 C   s   t  | |¡ d S r[   )re   rZ   rh   r7   r7   r8   rZ   +  s    zSLTransclude.__init__c                 C   s   |   |¡}||_|S r[   )rm   r‡   r§   r7   r7   r8   rp   .  s    
zSLTransclude.copyc                 C   s  |j s
d S |j}|d ur|ƒ }t|ƒ}i  |_|j| j< |j | jd ¡pJi |_|j | jd ¡p`i |_|j|_t	|jt
ƒs~i |_t	|jt
ƒsi |_|j |jd< |j|_|j|_z6tjj |¡ |j  |¡ |j  |¡ W tjj ¡  ntjj ¡  0 |jrþd|_d S )NrU   T)rU   rT   r:   rD   rf   rE   r  rF   rK   rÈ   rÐ   rA   rR   r)   r  r  r$   rB   r{   rÀ   rS   )rY   rz   rT   rð   r7   r7   r8   r{   3  s0    zSLTransclude.executec                 C   s6   |  | jd ¡}|d u sd|vr"d S t |d |¡ d S ©NrU   )r  rf   r   r~   ©rY   r}   r5  r7   r7   r8   r~   V  s    zSLTransclude.copy_on_changec                 C   s   dS r4  r7   rŽ   r7   r7   r8   r   _  s    zSLTransclude.has_transcludec                 C   s   |   |d¡ d S rŠ  rf  r‘   r7   r7   r8   r“   b  s    zSLTransclude.dump_constN)	ra   rb   rc   rZ   rp   r{   r~   r   r“   r7   r7   r7   r8   r‰  )  s   #	r‰  c                   @   sX   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ ZdS )ÚSLCustomUsez]This represents special use screen statement defined
    by renpy.register_sl_statement.
    c                 C   s(   t  | |¡ || _d | _|| _|| _d S r[   )re   rZ   rk  r.   rÕ   rÎ   )rY   r2   rk  rÕ   rÎ   r7   r7   r8   rZ   j  s
    zSLCustomUse.__init__c                 C   s2   |   |¡}| j|_d |_| j|_| j |¡|_|S r[   )rm   rk  r.   rÕ   rÎ   rp   r§   r7   r7   r8   rp   z  s    
zSLCustomUse.copyc                 C   s   d| _ | j |¡ d S r4  )r›   rÎ   rw   ru   r7   r7   r8   rw   †  s    zSLCustomUse.analyzec                 C   sÄ   | j }| |¡ tjj | j¡}|d u rLt| _tj	j
rHtd | j¡ƒ‚nd S |jd u rrt| _tj	j
rntdƒ‚nd S | d¡rŽt| _|jj| _n |jtkr¤|jj| _n
|jj| _t| j| jjƒ| _d S )Nrm  z4A screen used in CD SLS should be a SL-based screen.rç   )rÎ   rx   r)   r  r  ro  rk  r   r‡   r¸   r#   r_   r”   r.   rÑ   rq  r   rp  r¬   )rY   rv   rÎ   rk  r7   r7   r8   rx   Œ  s(    





zSLCustomUse.preparec                    s´  t ˆ ƒ}i  |_ˆ j| j< ˆ j | jd ¡p,i |_zž‡ fdd„| jD ƒ}i  }|_| j |¡ | dd ¡}|rt||7 }| dd ¡}|rŽ| 	|¡ | dd ¡}d|vrÌ|rÌ|j
d u rº||d< n|j
d | |d< W n" tyð   ˆ jsä‚ g }i }Y n0 | dd ¡}|d urZ| j|f}	ˆ j |	d ¡p6ˆ j | jd ¡p6i |_|	|jv rLd	|_|j|j|	< nˆ j | jd ¡pni |_t|jtƒs†i |_t|jtƒsši |_| j}
|
jd urð|
jj||ˆ jd
}|j dd ¡pâ|j dd ¡pâi }| 	|¡ n^|rtd | jt|ƒ¡ƒ‚|j dd ¡p.|j dd ¡p.i }| ¡  | 	ˆ j¡ | 	|¡ ||d< ||jd< ||_t ˆ ¡|_| jjr„| j|_z|
  |¡ W |d= n|d= 0 |j!r°d	ˆ _!d S )Nc                    s   g | ]}t |ˆ jˆ jƒ‘qS r7   )r'   r@   r>   r    r½   r7   r8   r¤   »  r¥   z'SLCustomUse.execute.<locals>.<listcomp>rü   rý   rþ   rß   rÍ   rç   Trx  r>   rz  r  )"r:   rD   rf   rF   r  rÕ   rB   rÎ   rÀ   r=   rC   r_   rN   rk  rX   rE   rO   rW   rÈ   rÐ   r.   r{  r|  r”   r  r}  r>   r~  r  rT   rA   rU   r{   rS   )rY   rz   rð   r–   ru  rü   rý   rþ   rç   r‚  r.   rƒ  r>   r7   r½   r8   r{   ²  sr    






($$


zSLCustomUse.executec                 C   s*   |  | jd ¡}|d u rd S | j |¡ d S r[   )r  rf   r.   r~   r‹  r7   r7   r8   r~   	  s    zSLCustomUse.copy_on_changec                 C   s$   || j ƒ | jd ur | j |¡ d S r[   )rk  rÎ   r   r‹   r7   r7   r8   r   	  s    

zSLCustomUse.used_screensc                 C   s
   | j  ¡ S r[   r„  rŽ   r7   r7   r8   r   #	  s    zSLCustomUse.has_transcludec                 C   st   |   |d| j¡ | jjD ](}| jr2| |d ¡ q| |d ¡ q| jrp|   dd¡ | jjD ]}| |d ¡ q\d S )Nz
custom-user†  rÒ   r’   r‡  rˆ  rÓ   r7   r7   r8   r“   '	  s    zSLCustomUse.dump_constN)ra   rb   rc   rd   rZ   rp   rw   rx   r{   r~   r   r   r“   r7   r7   r7   r8   rŒ  e  s   &brŒ  c                   @   s„   e Zd ZdZdZdZdZdZdZdZ	dZ
dd„ Zd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚSLScreenzD
    This represents a screen defined in the screen language 2.
    r   Nz	'screens'ÚTrueÚNonec                 C   sL   t  | |¡ d | _d| _d| _d | _d| _d| _d| _d | _	d | _
d| _d S )NÚFalseÚ0r  rŽ  F)r   rZ   rq   ÚmodalÚzorderÚtagÚvariantÚpredictÚ	sensitiver{  rv   Úpreparedrh   r7   r7   r8   rZ   M	  s    zSLScreen.__init__c                 C   sZ   |   |¡}| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j|_d|_	d |_
|S r;   )rm   rq   r’  r“  r”  r•  r–  r{  r—  r˜  rv   r§   r7   r7   r8   rp   p	  s    
zSLScreen.copyc                 C   s`   t jjj| j| | j| j| jt j 	| j
¡t j 	| j¡| j| jt j 	| j¡| jt j 	| j¡d dS )z#
        Defines a screen.
        )
r’  r“  r”  r•  r–  r{  rg   Úlayerr—  Úroll_forwardN)r)   r  r  Údefine_screenrq   r’  r“  r”  r*   Úpy_evalr•  r–  r{  rg   r™  r—  rš  )rY   rg   r7   r7   r8   Údefine	  s    ôzSLScreen.definec                 C   s   t  | |¡ d S r[   )r   rw   ru   r7   r7   r8   rw   •	  s    zSLScreen.analyzec                 C   sì   | j r
d S | j| j| jf}|tjv r@tj| | _ tj| | _d S | | _ |  ¡ rr|  	t
¡| _| j| j_ | j | jg}n| j | _| j g}|D ]B}td ƒ }|_|jrª| |j¡ | |¡ | ¡ s†| |¡ q´q†| j tj|< | jtj|< dt_d S r4  )rp  rq   r•  rg   ÚscacheÚconst_analyzedÚnot_const_analyzedrq  r   rp   r   r   rv   r{  rw   Úat_fixed_pointÚupdated)rY   r]   Útargetsr.   rv   r7   r7   r8   Úanalyze_screen™	  s0    


zSLScreen.analyze_screenc                 C   s
   d| _ d S r;   )r˜  rŽ   r7   r7   r8   Úunprepare_screen¿	  s    zSLScreen.unprepare_screenc                 C   s  | j r
d S |  ¡  |  jd7  _| j | jj¡ | j| jurL| j | jj¡ d| _ tjj	 
| j¡jrt d| j¡ dd„ | jjjD ƒ}| ¡  t dd |¡¡ t| jjjƒ}| ¡  t dd |¡¡ t| jjjƒ}| ¡  t d	d |¡¡ t d
¡ | j d
¡ t d
¡ d S )Nr(   TzCONST ANALYSIS %sc                 S   s   g | ]}|t jjvr|‘qS r7   )r)   Ú
pyanalysisÚ	constantsr    r7   r7   r8   r¤   ×	  r¥   z+SLScreen.prepare_screen.<locals>.<listcomp>z    global_const: %sr1  z    local_const: %sz    not_const: %sr   )r˜  r¤  Úversionrp  rx   rv   rq  r)   r  r  Úget_profilerq   r»   r„   r…   Úglobal_constantÚsortr2  rÆ   rë   Únot_constantr“   )rY   Únew_constantsÚlocal_constantsÚnot_constantsr7   r7   r8   Úprepare_screenÂ	  s,    
zSLScreen.prepare_screenc                 C   s   | j  |¡ t | j |¡ d S r[   )rp  rB   r   r{   ry   r7   r7   r8   r{   é	  s    zSLScreen.executec                 C   s"   |rd S |dkrg S t  | ||¡S )NÚ__call__)r   rt   )rY   rq   rr   r7   r7   r8   rt   í	  s
    zSLScreen.report_tracebackc                 C   s   t  | j|¡ d S r[   )r   r~   rp  r|   r7   r7   r8   r~   ö	  s    zSLScreen.copy_on_changec           
         sP  |d }|  dd¡}ˆjrX|  dd¡}|  di ¡}tjjˆj||tjjjd}| |¡ ˆj	sfˆ 
¡  tjj ¡ }|jd tjjv rˆd	}tƒ }||_||_tjjd
 |_||_tjjj|_|jtjjjk|_|d ‰ ‡ ‡fdd„}||jƒ|_||jƒ|_dˆji|_|j|_ i |_!ˆ "|¡ |j#D ]}	tj$ %|	¡ q$|j|jˆ < |j!|_d S )Nr  Ú_debugFÚ_argsr7   Ú_kwargsrx  r   TÚstorerr  c                    s>   |   ˆ d ¡}t|tƒr(|  dd ¡ˆjkr:dˆji}|| ˆ < |S )Nr¨  )r  rÈ   rÐ   r¨  )r\   rl   ©rq   rY   r7   r8   Ú	get_cache
  s
    
z$SLScreen.__call__.<locals>.get_cacher¨  )&r  r{  r)   r.   Úapply_argumentsr  r–  rN   r=   r˜  r°  r  Úcurrent_screenÚscreen_namer¸   Úprofile_screensr:   r>   r?   r*   Ústore_dictsr@   rM   ÚphaseÚUPDATErO   r}   rE   rF   r¨  rD   Ú	use_cacherX   rW   r{   rA   r  Úimplicit_add)
rY   r–   ru  r>   rM   r«   r¹  rz   r·  r¢   r7   r¶  r8   r±  ù	  s>    
	

zSLScreen.__call__)ra   rb   rc   rd   r¨  rp  rq  rv   r™  r—  rš  rZ   rp   r  rw   r¤  r¥  r°  r{   rt   r~   r±  r7   r7   r7   r8   r  6	  s&   #&'	r  c                   @   s   e Zd Zdd„ ZdS )ÚScreenCachec                 C   s   d| _ i | _i | _d| _d S )Nr(   F)r¨  rŸ  r   r¢  rŽ   r7   r7   r8   rZ   4
  s    zScreenCache.__init__N)ra   rb   rc   rZ   r7   r7   r7   r8   rÁ  2
  s   rÁ  zcache/screens.rpybc                  C   sÐ   t jjjrd S zªt j t¡V} |  t 	¡ j
¡}|t jjj ¡ krRW d   ƒ W d S tt |  ¡ ¡ƒ}W d   ƒ n1 sx0    Y  |jtjkr¶t jj ¡  tj |j¡ tj |j¡ W n tyÊ   Y n0 d S r[   )r)   Úgamer–   r1   ÚloaderÚloadÚCACHE_FILENAMEÚreadÚhashlibÚmd5Údigest_sizeÚscriptÚdigestr   ÚzlibÚ
decompressr¨  rž  Úupdate_bytecoderŸ  r=   r   r_   )r(  rË  r©   r7   r7   r8   Ú
load_cacheB
  s    
0rÏ  c                  C   s   t js
d S tjrd S zdt tt ƒd¡} ttj 	t
¡dƒ.}| tjjj ¡ ¡ | | ¡ W d   ƒ n1 sl0    Y  W n tyŠ   Y n0 d S )Né   Úwb)rž  r¢  r)   ÚmacapprÌ  Úcompressr   r   rÃ  Úget_pathrÅ  r…   rÂ  rÊ  rË  r_   )Údatar(  r7   r7   r8   Ú
save_cacheW
  s    ,rÖ  )XÚ
__future__r   r   r   r   r   Úrenpy.compatr   r   r	   r
   r   r   r   r   r   r   r   r   Útypingr   r   Úrenpy.compat.pickler   r   r.   rG   r‚   rÌ  r~  r)   Úrenpy.display.transformr   r   Úrenpy.display.layoutr   Úrenpy.display.predictr   r  Úrenpy.pythonr   Úrenpy.pyanalysisr   r   r   r   r    rÇ  ÚtimerI   rf   ÚobjectÚSentinelr!   r4   Úlogr„   r9   r  ÚAddabler:   re   rœ   r   rÆ   Útupler  rÔ   r  ÚlayoutÚNullr  rÝ   rÉ   rN  rP  ra  rg  ri  rj  r‰  rŒ  r  rÁ  rž  rÅ  rÏ  rÖ  r7   r7   r7   r8   Ú<module>   sr   8b # V:     = &k  '   < R }