Plan 9 from Bell Labs’s /usr/web/sources/contrib/stallion/root/sys/lib/python2.7/compiler/pyassem.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�`^c@sdZddlZddlZddlZddlmZddlmZmZm	Z	m
Z
dfd��YZd�Zdfd	��YZ
d
ZdZdZd
Zdefd��YZd�Zdfd��YZd�Zd�Zdfd��YZdfd��YZe�jZdS(s/A flow graph representation for Python bytecodei�N(tmisc(tCO_OPTIMIZEDtCO_NEWLOCALSt
CO_VARARGStCO_VARKEYWORDSt	FlowGraphcBs}eZd�Zd�Zd
d�Zd�Zd�ZdZd�Z	d�Z
d�Zd	�Zd
�Z
d�Zd�ZRS(cCs[t�|_|_td�|_tj�|_|jj|j�|jj|j�dS(Ntexit(tBlocktcurrenttentryRRtSettblockstadd(tself((s&/sys/lib/python2.7/compiler/pyassem.pyt__init__s
cCsr|jre|jrWdGt|j�GHdG|jjGHdG|jjGHdG|jj�GHnt|�GHn||_dS(Ntends    nexts    prevs   (t_debugRtreprtnexttprevtget_children(R
tblock((s&/sys/lib/python2.7/compiler/pyassem.pyt
startBlocks		cCs<|dkr|j�}n|jj|�|j|�dS(N(tNonetnewBlockRtaddNextR(R
R((s&/sys/lib/python2.7/compiler/pyassem.pyt	nextBlockscCst�}|jj|�|S(N(RRR(R
tb((s&/sys/lib/python2.7/compiler/pyassem.pyR5s	cCs|j|j�dS(N(RR(R
((s&/sys/lib/python2.7/compiler/pyassem.pytstartExitBlock:sicCs
d|_dS(Ni(R(R
((s&/sys/lib/python2.7/compiler/pyassem.pyt
_enable_debug?scCs
d|_dS(Ni(R(R
((s&/sys/lib/python2.7/compiler/pyassem.pyt_disable_debugBscGse|jrdG|GHnt|�dkrQt|dt�rQ|jj|d�n|jj|�dS(Ns	ii(Rtlent
isinstanceRRt
addOutEdgetemit(R
tinst((s&/sys/lib/python2.7/compiler/pyassem.pyR"Es
	%cCst|j|j�}|S(slReturn the blocks in reverse postorder

        i.e. each node appears before all of its successors
        (torder_blocksR	R(R
torder((s&/sys/lib/python2.7/compiler/pyassem.pytgetBlocksInOrderLscCs
|jj�S(N(Rtelements(R
((s&/sys/lib/python2.7/compiler/pyassem.pyt	getBlocksTscCs|jS(s/Return nodes appropriate for use with dominator(R	(R
((s&/sys/lib/python2.7/compiler/pyassem.pytgetRootWscCs4g}x'|j�D]}|j|j��qW|S(N(R(textendtgetContainedGraphs(R
tlR((s&/sys/lib/python2.7/compiler/pyassem.pyR+[sN(t__name__t
__module__RRRRRRRRRR"R&R(R)R+(((s&/sys/lib/python2.7/compiler/pyassem.pyRs		
								cs�g}t��|g}xh|r�|j�}|�kr?qn�j|�x0|j�D]"}|�krY|j|�qYqYWqWi�x��D]�}tr�|jr�||jdjdks�t||jf��n�j	|t��xc|j
�D]U}xL�j	|t��j|�|jrH|jd|k	rH|jd}qPqq��W��fd�}|}xu|j|��j|�|jr�|jd}qon)||k	r�|j�r�|j|�n�s�Pn|�}qo|S(s8Order blocks so that they are emitted in the right ordericsPx7�D]/}x&�|D]}|�krPqqW|SqWdsLtd��dS(Nis+circular dependency, cannot find next block(tAssertionError(Rtc(t
dominatorst	remaining(s&/sys/lib/python2.7/compiler/pyassem.pyt	find_next�s
(
tsettpopRRtappendt	__debug__RRR/t
setdefaultt
get_followerstdiscardthas_unconditional_transfer(tstart_blockt
exit_blockR%ttodoRR0R3((R1R2s&/sys/lib/python2.7/compiler/pyassem.pyR$bsH			

2


	
RcBszeZdZdd�Zd�Zd�Zd�Zd�Zd�Zd�Z	dZ
d�Zd�Zd�Z
d�ZRS(itcCsPg|_t�|_||_tj|_g|_g|_tjdt_dS(Ni(	tinstsR4toutEdgestlabelRt_counttbidRR(R
RB((s&/sys/lib/python2.7/compiler/pyassem.pyR�s				cCs,|jrd|j|jfSd|jSdS(Ns<block %s id=%d>s
<block id=%d>(RBRD(R
((s&/sys/lib/python2.7/compiler/pyassem.pyt__repr__�s	cCs2tt|j�}d|j|jdj|�fS(Ns<block %s %d:
%s>s
(tmaptstrR@RBRDtjoin(R
R@((s&/sys/lib/python2.7/compiler/pyassem.pyt__str__�scCs|d}|jj|�dS(Ni(R@R6(R
R#top((s&/sys/lib/python2.7/compiler/pyassem.pyR"�s
cCs|jS(N(R@(R
((s&/sys/lib/python2.7/compiler/pyassem.pytgetInstructions�scCs|jj|�dS(N(RAR(R
R((s&/sys/lib/python2.7/compiler/pyassem.pyR!�scCs~|jj|�t|j�dks=ttt|j���|jj|�t|j�dkszttt|j���dS(Ni(RR6RR/RFRGR(R
R((s&/sys/lib/python2.7/compiler/pyassem.pyR�s-tRETURN_VALUEt
RAISE_VARARGSt
JUMP_ABSOLUTEtJUMP_FORWARDt
CONTINUE_LOOPcCs?y|jd\}}Wnttfk
r1dSX||jkS(s�Returns True if there is an unconditional transfer to an other block
        at the end of this block. This means there is no risk for the bytecode
        executer to go past this block's bytecode.i�N(R@t
IndexErrort
ValueErrort_uncond_transfer(R
RJtarg((s&/sys/lib/python2.7/compiler/pyassem.pyR;�s
cCst|j�|jS(N(tlistRAR(R
((s&/sys/lib/python2.7/compiler/pyassem.pyR�scCsNt|j�}x8|jD]-}|dtjkr|j|d�qqW|S(s:Get the whole list of followers, including the next block.ii(R4RR@tPyFlowGraphthasjrelR(R
t	followersR#((s&/sys/lib/python2.7/compiler/pyassem.pyR9�s
cCsbg}xU|jD]J}t|�dkr.qn|d}t|d�r|j|j�qqW|S(s�Return all graphs contained within this block.

        For example, a MAKE_FUNCTION block will contain a reference to
        the graph for the function body.
        itgraph(R@RthasattrR6RY(R
t	containedR#RJ((s&/sys/lib/python2.7/compiler/pyassem.pyR+�s
(RLRMRNRORP(R-R.RCRRERIR"RKR!RRSR;RR9R+(((s&/sys/lib/python2.7/compiler/pyassem.pyR�s								
		
tRAWtFLATtCONVtDONERVcBsAeZejZdddd�Zd�Zd�Zd�Zd�Z	d�Z
d�Zdd�Zd	�Z
d
�Ze�Zx%ejD]Zejeje�q�We�Zx%ejD]Zejeje�q�Wd�Zd�Zd
�ZiZd�Zd�ZeZeZd�Zd�ZeZ eZ!eZ"eZ#eZ$eZ%eZ&eZ'eZ(eZ)d�Z*e*Z+e*Z,d�Z-e.ej/�Z0d�Z1xDe2�j3�D]3\Z4Z5e4d dkr�e4dZe5ee<q�q�W[4[5[d�Z6iZ7x.e8e9ej��D]Z:e:e7eje:<qW[:d�Z;d�Z<RS(icCs|j�||_||_d|_||_t|�|_||_|r\t	t
B|_n	d|_g|_g|_
g|_g|_g|_t|�p�g|_xOtt|j��D]8}|j|}t|t�r�|j�|j|<q�q�Wt|_dS(Ni(t
super_inittnametfilenameRt	docstringtargstgetArgCounttargcounttklassRRtflagstconststnamestfreevarstcellvarstclosureRUtvarnamestrangeRR tTupleArgtgetNameR\tstage(R
RaRbRdt	optimizedRgtitvar((s&/sys/lib/python2.7/compiler/pyassem.pyRs*
											
cCs
||_dS(N(Rc(R
tdoc((s&/sys/lib/python2.7/compiler/pyassem.pytsetDocstringscCs3|j|B|_|tkr/|jd|_ndS(Ni(RhRRf(R
tflag((s&/sys/lib/python2.7/compiler/pyassem.pytsetFlag"scCs|j|@rdSdS(Ni(Rh(R
Rx((s&/sys/lib/python2.7/compiler/pyassem.pyt	checkFlag's
cCst|�|_dS(N(RURk(R
Rj((s&/sys/lib/python2.7/compiler/pyassem.pytsetFreeVars+scCs
||_dS(N(Rl(R
Rj((s&/sys/lib/python2.7/compiler/pyassem.pytsetCellVars.scCs�|jtkst�|j�|j�|jtks>t�|j�|jtks]t�|j�|jt	ks|t�|j
�S(sGet a Python code object(RrR\R/tcomputeStackDepthtflattenGraphR]tconvertArgsR^tmakeByteCodeR_t
newCodeObject(R
((s&/sys/lib/python2.7/compiler/pyassem.pytgetCode1s



cCs�|rtj}|t_nd}x~|jD]s}|d}|dkrKHnt|�dkr{dGd|G|GH|d}q+dGd|G|G|dGH|d}q+W|r�|t_ndS(Nit
SET_LINENOis	s%3di(tsyststdoutR@R(R
tiotsavetpctttopname((s&/sys/lib/python2.7/compiler/pyassem.pytdump=s	

cspi�d}x*�j�D]}t|j���|<qWi�����fd����jd��_dS(s�Compute the max stack depth.

        Approach is to compute the stack effect of each basic block.
        Then find the path through the code with the largest total
        effect.
        cs�|�kr|Sd�|<|�|}|j�}|r`tg|D]}�||�^qD�S|jdks��j|�S|SdS(NiR(RtmaxRBR(RtdtchildrenR0(tdeptht	max_depthtseenR
(s&/sys/lib/python2.7/compiler/pyassem.pyR�]s
&iN(RR(t	findDepthRKR	t	stacksize(R
RR((R�R�R�R
s&/sys/lib/python2.7/compiler/pyassem.pyR}OscCs�|jtkst�g|_}d}i}i}x�|j�D]z}|||<x]|j�D]O}|j|�t|�dkr�|d}q^|ddkr^|d}q^q^W|||<qAWd}x�tt|��D]�}||}t|�dkr|d}n|ddkr$|d}n|d}||j	krh|d}	||	|}
||
f||<q�||j
kr�|||df||<q�q�Wt|_dS(s-Arrange the blocks in order and resolve jumpsiiR�iN(RrR\R/R@R&RKR6RRoRWthasjabsR](R
R@R�tbeginRRR#RtR�topargtoffset((s&/sys/lib/python2.7/compiler/pyassem.pyR~ms:








cCs�|jtkst�|jjd|j�|j�x�tt|j	��D]n}|j	|}t|�dkrK|\}}|j
j|d�}|r�||||�f|j	|<q�qKqKWt
|_dS(s0Convert arguments from symbolic to concrete formiiN(RrR]R/RitinsertRct
sort_cellvarsRoRR@t_converterstgetRR^(R
RtR�R�R�tconv((s&/sys/lib/python2.7/compiler/pyassem.pyR�s

&cCs�i}x|jD]}d||<qWg|jD]}||kr.|^q.|_x|jD]
}||=qYW|j|j�|_|j|j|_dS(sHSort cellvars in the order of varnames and prune from freevars.
        iN(RlRntkeysRkRm(R
tcellsRa((s&/sys/lib/python2.7/compiler/pyassem.pyR��scCspt|�}xDtt|��D]0}|t||�kr|||kr|SqWt|�}|j|�|S(s�Return index of name in list, appending if necessary

        This routine uses a list instead of a dictionary, because a
        dictionary can't store two different keys if the keys have the
        same value but different types, e.g. 2 and 2L.  The compiler
        must treat these two separately, so it does an explicit type
        comparison before comparing the values.
        (ttypeRoRR6(R
RaRUR�RtR((s&/sys/lib/python2.7/compiler/pyassem.pyt_lookupName�s	&
cCs1t|d�r|j�}n|j||j�S(NR�(RZR�R�Ri(R
RT((s&/sys/lib/python2.7/compiler/pyassem.pyt_convert_LOAD_CONST�scCs&|j||j�|j||j�S(N(R�RjRn(R
RT((s&/sys/lib/python2.7/compiler/pyassem.pyt_convert_LOAD_FAST�scCs8|jdkr%|j||j�n|j||j�S(N(RgRR�RnRj(R
RT((s&/sys/lib/python2.7/compiler/pyassem.pyt_convert_LOAD_NAME�scCs8|jdkr%|j||j�n|j||j�S(N(RgRR�RnRj(R
RT((s&/sys/lib/python2.7/compiler/pyassem.pyt
_convert_NAME�scCs9|j||j�|j||j�|j||j�S(N(R�RjRnRm(R
RT((s&/sys/lib/python2.7/compiler/pyassem.pyt_convert_DEREF�scCs&|j||j�|j||j�S(N(R�RnRm(R
RT((s&/sys/lib/python2.7/compiler/pyassem.pyt_convert_LOAD_CLOSURE�scCs|jj|�S(N(t_cmptindex(R
RT((s&/sys/lib/python2.7/compiler/pyassem.pyt_convert_COMPARE_OP�si	t	_convert_cCs|jtkst�t�|_}x�|jD]�}|d}t|�dkrh|j|j|�q/|d}|dkr�|j	|�q/nt
|�\}}y|j|j|||�Wq/tk
r�|G|GH|j|G|G|GH�q/Xq/Wt|_dS(NiiR�(
RrR^R/t
LineAddrTabletlnotabR@RtaddCodetopnumtnextLinettwobyteRRR_(R
R�R�R�R�thitlo((s&/sys/lib/python2.7/compiler/pyassem.pyR��s$



	cCs�|jtkst�|jt@dkr1d}nt|j�}|j}|jt@rc|d}nt	j
|||j|j|jj
�|j�t|j�t|j�|j|j|jj|jj�t|j�t|j��S(Nii(RrR_R/RhRRRnRfRttypestCodeTypeR�R�R�t	getConststtupleRjRbRat	firstlinetgetTableRkRl(R
tnlocalsRf((s&/sys/lib/python2.7/compiler/pyassem.pyR�s		

cCsOg}x<|jD]1}t|t�r4|j�}n|j|�qWt|�S(s�Return a tuple for the const slot of the code object

        Must convert references to code (MAKE_FUNCTION) to code
        objects recursively.
        (RiR RVR�R6R�(R
R,telt((s&/sys/lib/python2.7/compiler/pyassem.pyR�"s(N(=R-R.RRR`RRwRyRzR{R|R�R�R}R~R4RWtdisRtRR�R�RR�R�R�R�R�t_convert_STORE_FASTt_convert_DELETE_FASTR�R�t_convert_STORE_NAMEt_convert_DELETE_NAMEt_convert_IMPORT_NAMEt_convert_IMPORT_FROMt_convert_STORE_ATTRt_convert_LOAD_ATTRt_convert_DELETE_ATTRt_convert_LOAD_GLOBALt_convert_STORE_GLOBALt_convert_DELETE_GLOBALR�t_convert_LOAD_DEREFt_convert_STORE_DEREFR�RUtcmp_opR�R�tlocalstitemsRatobjR�R�RoRtnumR�R�(((s&/sys/lib/python2.7/compiler/pyassem.pyRV�sn									!				
								
			cCs|d dkrdSdS(NitJUMPi((R�((s&/sys/lib/python2.7/compiler/pyassem.pytisJump/sRpcBs)eZdZd�Zd�Zd�ZRS(s:Helper for marking func defs with nested tuples in arglistcCs||_||_dS(N(tcountRj(R
R�Rj((s&/sys/lib/python2.7/compiler/pyassem.pyR5s	cCsd|j|jfS(NsTupleArg(%s, %s)(R�Rj(R
((s&/sys/lib/python2.7/compiler/pyassem.pyRE8scCsd|jS(Ns.%d(R�(R
((s&/sys/lib/python2.7/compiler/pyassem.pyRq:s(R-R.t__doc__RRERq(((s&/sys/lib/python2.7/compiler/pyassem.pyRp3s		cCs^t|�}|rZxE|D]:}t|t�rttj|j��}||}qqWn|S(N(RR RpRtflattenRj(RdRfRTtnumNames((s&/sys/lib/python2.7/compiler/pyassem.pyRe=s
cCs"t|t�st�t|d�S(s/Convert an int argument into high and low bytesi(R tintR/tdivmod(tval((s&/sys/lib/python2.7/compiler/pyassem.pyR�FsR�cBs;eZdZd�Zd�Zd�Zd�Zd�ZRS(s(lnotab

    This class builds the lnotab, which is documented in compile.c.
    Here's a brief recap:

    For each SET_LINENO instruction after the first one, two bytes are
    added to lnotab.  (In some cases, multiple two-byte entries are
    added.)  The first byte is the distance in bytes between the
    instruction for the last SET_LINENO and the current SET_LINENO.
    The second byte is offset in line numbers.  If either offset is
    greater than 255, multiple two-byte entries are added -- see
    compile.c for the delicate details.
    cCs:g|_d|_d|_d|_d|_g|_dS(Ni(tcodet
codeOffsetR�tlastlinetlastoffR�(R
((s&/sys/lib/python2.7/compiler/pyassem.pyRZs					cGsAx$|D]}|jjt|��qW|jt|�|_dS(N(R�R6tchrR�R(R
RdRT((s&/sys/lib/python2.7/compiler/pyassem.pyR�bs
cCs|jdkr$||_||_n�j|j}||j}|dkr|jj}x.|dkr�|d�|d�|d8}q\Wx4|dkr�||�|d�|d8}d}q�W|dks�|dkr�|�||�n||_|j|_ndS(Nii�(R�R�R�R�R�R6(R
tlinenotaddrtlinetpush((s&/sys/lib/python2.7/compiler/pyassem.pyR�gs*	








	cCsdj|j�S(NR?(RHR�(R
((s&/sys/lib/python2.7/compiler/pyassem.pyR��scCsdjtt|j��S(NR?(RHRFR�R�(R
((s&/sys/lib/python2.7/compiler/pyassem.pyR��s(R-R.R�RR�R�R�R�(((s&/sys/lib/python2.7/compiler/pyassem.pyR�Ks
			 	tStackDepthTrackercBs�eZdd�Zi&dd6dd6dd6dd6dd	6dd
6dd6dd6dd
6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd 6dd!6dd"6dd#6dd$6dd%6dd&6dd'6d(d)6d(d*6dd+6dd,6Zd;d<gZd/�Zd0�Zd1�Zd2�Zd3�Z	d4�Z
d5�Zd6�Zd7�Z
d8�Zd9�Zd:�ZRS(=icCsd}d}x|D]�|d}|r0|Gn|jj|d�}|dk	r^||}n�xA|jD]6\}}	|t|� |krh|	}||}PqhqhW|dkr�||d�}
|
dk	r�|
|d�}q�||kr�}n|r|G|GHqqW|S(Nii(teffectR�RtpatternsRtgetattr(R
R@tdebugR�tmaxDepthRtR�tdeltatpatt	pat_deltatmeth((s&/sys/lib/python2.7/compiler/pyassem.pyR��s.



	i�tPOP_TOPitDUP_TOPtLIST_APPENDtSET_ADDi�tMAP_ADDsSLICE+1sSLICE+2sSLICE+3s
STORE_SLICE+0s
STORE_SLICE+1s
STORE_SLICE+2i�s
STORE_SLICE+3sDELETE_SLICE+0sDELETE_SLICE+1sDELETE_SLICE+2sDELETE_SLICE+3tSTORE_SUBSCRt
DELETE_SUBSCRt
PRINT_ITEMRLtYIELD_VALUEt	EXEC_STMTtBUILD_CLASSt
STORE_NAMEt
STORE_ATTRtDELETE_ATTRtSTORE_GLOBALt	BUILD_MAPt
COMPARE_OPt
STORE_FASTtIMPORT_STARtIMPORT_NAMEtIMPORT_FROMt	LOAD_ATTRitSETUP_EXCEPTt
SETUP_FINALLYtFOR_ITERtWITH_CLEANUPtBINARY_tLOAD_cCs|dS(Ni((R
R�((s&/sys/lib/python2.7/compiler/pyassem.pytUNPACK_SEQUENCE�scCs	|dS(Ni((R
R�((s&/sys/lib/python2.7/compiler/pyassem.pytBUILD_TUPLE�scCs	|dS(Ni((R
R�((s&/sys/lib/python2.7/compiler/pyassem.pyt
BUILD_LIST�scCs	|dS(Ni((R
R�((s&/sys/lib/python2.7/compiler/pyassem.pyt	BUILD_SET�scCs"t|d�\}}||dS(Nii(R�(R
targcR�R�((s&/sys/lib/python2.7/compiler/pyassem.pyt
CALL_FUNCTION�scCs|j|�dS(Ni(R(R
R((s&/sys/lib/python2.7/compiler/pyassem.pytCALL_FUNCTION_VAR�scCs|j|�dS(Ni(R(R
R((s&/sys/lib/python2.7/compiler/pyassem.pytCALL_FUNCTION_KW�scCs|j|�dS(Ni(R(R
R((s&/sys/lib/python2.7/compiler/pyassem.pytCALL_FUNCTION_VAR_KW�scCs|S(N((R
R((s&/sys/lib/python2.7/compiler/pyassem.pyt
MAKE_FUNCTION�scCs|S(N((R
R((s&/sys/lib/python2.7/compiler/pyassem.pytMAKE_CLOSURE�scCs$|dkrdS|dkr dSdS(Nii�ii�((R
R((s&/sys/lib/python2.7/compiler/pyassem.pytBUILD_SLICE�scCs|S(N((R
R((s&/sys/lib/python2.7/compiler/pyassem.pytDUP_TOPX�s(Ri�(Ri(R-R.R�R�R�RRR	R
RR
RRRRRR(((s&/sys/lib/python2.7/compiler/pyassem.pyR��sl
												(R�R�R�R�tcompilerRtcompiler.constsRRRRRR$RR\R]R^R_RVR�RpReR�R�R�R�(((s&/sys/lib/python2.7/compiler/pyassem.pyt<module>s*"W	CT�
			Bn

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].