Added docstrings (contributed by Martin von Loewis).
This commit is contained in:
parent
e4a93bc4b3
commit
421c224044
14
Lib/dis.py
14
Lib/dis.py
|
@ -1,10 +1,15 @@
|
||||||
# Disassembler
|
"""Disassembler of Python byte code into mnemonics."""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import string
|
import string
|
||||||
import types
|
import types
|
||||||
|
|
||||||
def dis(x=None):
|
def dis(x=None):
|
||||||
|
"""Disassemble classes, methods, functions, or code.
|
||||||
|
|
||||||
|
With no argument, disassemble the last traceback.
|
||||||
|
|
||||||
|
"""
|
||||||
if not x:
|
if not x:
|
||||||
distb()
|
distb()
|
||||||
return
|
return
|
||||||
|
@ -36,6 +41,7 @@ def dis(x=None):
|
||||||
type(x).__name__
|
type(x).__name__
|
||||||
|
|
||||||
def distb(tb=None):
|
def distb(tb=None):
|
||||||
|
"""Disassemble a traceback (default: last traceback)."""
|
||||||
if not tb:
|
if not tb:
|
||||||
try:
|
try:
|
||||||
tb = sys.last_traceback
|
tb = sys.last_traceback
|
||||||
|
@ -45,6 +51,7 @@ def distb(tb=None):
|
||||||
disassemble(tb.tb_frame.f_code, tb.tb_lasti)
|
disassemble(tb.tb_frame.f_code, tb.tb_lasti)
|
||||||
|
|
||||||
def disassemble(co, lasti=-1):
|
def disassemble(co, lasti=-1):
|
||||||
|
"""Disassemble a code object."""
|
||||||
code = co.co_code
|
code = co.co_code
|
||||||
labels = findlabels(code)
|
labels = findlabels(code)
|
||||||
n = len(code)
|
n = len(code)
|
||||||
|
@ -79,6 +86,11 @@ def disassemble(co, lasti=-1):
|
||||||
disco = disassemble
|
disco = disassemble
|
||||||
|
|
||||||
def findlabels(code):
|
def findlabels(code):
|
||||||
|
"""Detect all offsets in a byte code which are jump targets.
|
||||||
|
|
||||||
|
Return the list of offsets.
|
||||||
|
|
||||||
|
"""
|
||||||
labels = []
|
labels = []
|
||||||
n = len(code)
|
n = len(code)
|
||||||
i = 0
|
i = 0
|
||||||
|
|
Loading…
Reference in New Issue