本文整理汇总了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]