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

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


�`^c@s�dZddlZddlZddlTddlmZddddd	d
geZ[ejejejej	e
fZdd�Z
dd�Zdd
�Zddddd�ZeZd�Zd�Zd�Zedkr��ndS(s0Disassembler of Python byte code into mnemonics.i�N(t*(t__all__tdistdisassembletdistbtdiscotfindlinestartst
findlabelscCsH|dkrt�dSt|tj�r5|j}nt|d�rP|j}nt|d�rk|j}nt|d�r�j	j
�}|j�x�|D]U\}}t|t�r�d|GHyt
|�Wntk
r�}dG|GHnXHq�q�WnNt|d�rt|�n2t|t�r.t|�ntdt|�j�dS(	snDisassemble classes, methods, functions, or code.

    With no argument, disassemble the last traceback.

    Ntim_funct	func_codet__dict__sDisassembly of %s:sSorry:tco_codes(don't know how to disassemble %s objects(tNoneRt
isinstancettypestInstanceTypet	__class__thasattrRR	R
titemstsortt
_have_codeRt	TypeErrorRtstrtdisassemble_stringttypet__name__(txRtnametx1tmsg((s/sys/lib/python2.7/dis.pyRs6
	


cCsl|dkrRy
tj}Wntk
r5td�nXx|jrN|j}q9Wnt|jj|j	�dS(s2Disassemble a traceback (default: last traceback).s no last traceback to disassembleN(
Rtsystlast_tracebacktAttributeErrortRuntimeErrorttb_nextRttb_frametf_codettb_lasti(ttb((s/sys/lib/python2.7/dis.pyR3s


cCsa|j}t|�}tt|��}t|�}d}d}d}x||kr\||}	t|	�}
||kr�|dkr�Hnd||GndG||kr�dGndG||kr�dGndGt|�jd�Gt	|
j
d�G|d	}|
tkrXt||�t||d	�d
|}d}|d}|
tkrT|d}nt|�jd
�G|
t
kr�dt|j|�dGqX|
tkr�d|j|dGqX|
tkr�dt||�dGqX|
tkr�|j|dGqX|
tkrdt|dGqX|
tkrX|dkrB|j|j}nd||dGqXnHqHWdS(sDisassemble a code object.is%3ds   s-->s>>s  iiiiilit(t)s(to N(RRtdictRtlenRtordtreprtrjusttopnametljustt
HAVE_ARGUMENTtEXTENDED_ARGthasconstt	co_conststhasnametco_namesthasjrelthaslocaltco_varnamest
hascomparetcmp_opthasfreetco_cellvarstco_freevars(tcotlastitcodetlabelst
linestartstntitextended_argtfreetctoptoparg((s/sys/lib/python2.7/dis.pyR=s\	

*

cCs�t|�}t|�}d}x�||kr�||}t|�}	||krVdGndG||krmdGndGt|�jd�Gt|	jd�G|d}|	tkr�t||�t||d�d	}
|d
}t|
�jd�G|	tkr$|rdt||
�d
Gq�d|
Gq�|	t	krZ|dk	rOd||
d
Gq�d|
Gq�|	tkrdt||
�d
Gq�|	tkr�|r�d||
d
Gq�d|
Gq�|	t
kr�dt|
d
Gq�nHq!WdS(Nis-->s   s>>s  iiiiiiR'R(s(%d)s(to (RR*R+R,R-R.R/R0R2R4RR6R7R9R:(R@R?tvarnamestnamest	constantsRARCRDRGRHRI((s/sys/lib/python2.7/dis.pyRnsH

&
cCs�g}t|�}d}x�||kr�|}t|�}|d}|tkrt||�t||d�d}|d}d}|tkr�||}n|tkr�|}n|dkr�|kr�j|�q��qW|S(s`Detect all offsets in a byte code which are jump targets.

    Return the list of offsets.

    iiiii�(R*R+R0R6thasjabstappend(R@RARCRDRGRHRItlabel((s/sys/lib/python2.7/dis.pyR�s&

&

	c	cs�g|jddd�D]}t|�^q}g|jddd�D]}t|�^qF}d}|j}d}xZt||�D]I\}}|r�||kr�||fV|}n||7}n||7}q�W||kr�|fVndS(s�Find the offsets in a byte code which are start of lines in the source.

    Generate pairs (offset, lineno) as described in Python/compile.c.

    iNii(t	co_lnotabR+Rtco_firstlinenotzip(	R@RGtbyte_incrementstline_incrementst
lastlinenotlinenotaddrt	byte_incrt	line_incr((s/sys/lib/python2.7/dis.pyR�s//		
cCs�tjdrftjdr:tjjd�tjd�ntjd}|sZ|dkrld}qlnd}|dkr�tj}nt|�}|j�}|dk	r�|j	�nd}t
||d�}t|�dS(s*Simple test program to disassemble a file.iisusage: python dis.py [-|file]
t-s<stdin>texecN(RtargvtstderrtwritetexitRtstdintopentreadtclosetcompileR(tfntftsourceR@((s/sys/lib/python2.7/dis.pyt_test�s"



t__main__(t__doc__RRtopcodeRt_opcodes_allt
MethodTypetFunctionTypetCodeTypet	ClassTypeRRRRRRRRRRRhR(((s/sys/lib/python2.7/dis.pyt<module>s(
#
1	'			

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.