From ef8ace3a6f6cf8396fa92ae62352e8a29ddfca1d Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Thu, 24 Aug 2000 00:32:09 +0000 Subject: Charles G. Waldman : Add the EXTENDED_ARG opcode to the virtual machine, allowing 32-bit arguments to opcodes instead of being forced to stick to the 16-bit limit. This is especially useful for machine-generated code, which can be too long for the SET_LINENO parameter to fit into 16 bits. This closes the implementation portion of SourceForge patch #100893. --- Lib/dis.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'Lib/dis.py') diff --git a/Lib/dis.py b/Lib/dis.py index 3a80e741f7..9fc9d30059 100644 --- a/Lib/dis.py +++ b/Lib/dis.py @@ -56,6 +56,7 @@ def disassemble(co, lasti=-1): labels = findlabels(code) n = len(code) i = 0 + extended_arg = 0 while i < n: c = code[i] op = ord(c) @@ -68,8 +69,11 @@ def disassemble(co, lasti=-1): print string.ljust(opname[op], 20), i = i+1 if op >= HAVE_ARGUMENT: - oparg = ord(code[i]) + ord(code[i+1])*256 + oparg = ord(code[i]) + ord(code[i+1])*256 + extended_arg + extended_arg = 0 i = i+2 + if op == EXTENDED_ARG: + extended_arg = oparg*65536L print string.rjust(`oparg`, 5), if op in hasconst: print '(' + `co.co_consts[oparg]` + ')', @@ -258,6 +262,8 @@ 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) +def_op('EXTENDED_ARG', 143) +EXTENDED_ARG = 143 def _test(): """Simple test program to disassemble a file.""" -- cgit v1.2.1