本文整理匯總了Python中opcode.opmap方法的典型用法代碼示例。如果您正苦於以下問題:Python opcode.opmap方法的具體用法?Python opcode.opmap怎麽用?Python opcode.opmap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類opcode
的用法示例。
在下文中一共展示了opcode.opmap方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: co_code_findloadednames
# 需要導入模塊: import opcode [as 別名]
# 或者: from opcode import opmap [as 別名]
def co_code_findloadednames(co):
"""Find in the code of a code object, all loaded names.
(by LOAD_NAME, LOAD_GLOBAL or LOAD_FAST) """
import dis
from opcode import HAVE_ARGUMENT, opmap
hasloadname = (opmap['LOAD_NAME'],
opmap['LOAD_GLOBAL'], opmap['LOAD_FAST'])
insns = dis.get_instructions(co)
len_co_names = len(co.co_names)
indexset = {}
for insn in insns:
if insn.opcode >= HAVE_ARGUMENT:
if insn.opcode in hasloadname:
indexset[insn.argval] = 1
if len(indexset) >= len_co_names:
break
for name in co.co_varnames:
try:
del indexset[name]
except KeyError:
pass
return indexset
示例2: add_jump_instruction
# 需要導入模塊: import opcode [as 別名]
# 或者: from opcode import opmap [as 別名]
def add_jump_instruction(jump_arg, code_to_insert):
"""
Note: although it's adding a POP_JUMP_IF_TRUE, it's actually no longer used now
(we could only return the return and possibly the load of the 'None' before the
return -- not done yet because it needs work to fix all related tests).
"""
extended_arg_list = []
if jump_arg > MAX_BYTE:
extended_arg_list += [EXTENDED_ARG, jump_arg >> 8]
jump_arg = jump_arg & MAX_BYTE
# remove 'RETURN_VALUE' instruction and add 'POP_JUMP_IF_TRUE' with (if needed) 'EXTENDED_ARG'
return list(code_to_insert.co_code[:-RETURN_VALUE_SIZE]) + extended_arg_list + [opmap['POP_JUMP_IF_TRUE'], jump_arg]