diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-01-25 20:08:47 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-01-25 20:08:47 (GMT) |
commit | a39414b15ca4b1a8e1b3cd7db463403ab0af933e (patch) | |
tree | 4b28c40247e00884d00d8c3d3610a86744de2876 /Lib | |
parent | 903f654ac9116bc5c598c19b9e9c45f5ba9e1a7b (diff) | |
download | cpython-a39414b15ca4b1a8e1b3cd7db463403ab0af933e.zip cpython-a39414b15ca4b1a8e1b3cd7db463403ab0af933e.tar.gz cpython-a39414b15ca4b1a8e1b3cd7db463403ab0af933e.tar.bz2 |
PEP 227 implementation
Track changes to new opcodes. Add hasfree list that applies to all
ops that use the closure.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/dis.py | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -6,7 +6,7 @@ import types __all__ = ["dis","disassemble","distb","disco","opname","cmp_op", "hasconst","hasname","hasjrel","hasjabs","haslocal", - "hascompare"] + "hascompare", "hasfree"] def dis(x=None): """Disassemble classes, methods, functions, or code. @@ -60,6 +60,7 @@ def disassemble(co, lasti=-1): n = len(code) i = 0 extended_arg = 0 + free = None while i < n: c = code[i] op = ord(c) @@ -88,6 +89,10 @@ def disassemble(co, lasti=-1): print '(' + co.co_varnames[oparg] + ')', elif op in hascompare: print '(' + cmp_op[oparg] + ')', + elif op in hasfree: + if free is None: + free = co.co_cellvars + co.co_freevars + print '(' + free[oparg] + ')', print disco = disassemble # XXX For backwards compatibility @@ -127,6 +132,7 @@ hasjrel = [] hasjabs = [] haslocal = [] hascompare = [] +hasfree = [] opname = [''] * 256 for op in range(256): opname[op] = '<' + `op` + '>' @@ -272,6 +278,14 @@ def_op('CALL_FUNCTION', 131) # #args + (#kwargs << 8) def_op('MAKE_FUNCTION', 132) # Number of args with default values def_op('BUILD_SLICE', 133) # Number of items +def_op('MAKE_CLOSURE', 134) +def_op('LOAD_CLOSURE', 135) +hasfree.append(135) +def_op('LOAD_DEREF', 136) +hasfree.append(136) +def_op('STORE_DEREF', 137) +hasfree.append(137) + def_op('CALL_FUNCTION_VAR', 140) # #args + (#kwargs << 8) def_op('CALL_FUNCTION_KW', 141) # #args + (#kwargs << 8) def_op('CALL_FUNCTION_VAR_KW', 142) # #args + (#kwargs << 8) |