本文整理汇总了Python中opcode.hasname方法的典型用法代码示例。如果您正苦于以下问题:Python opcode.hasname方法的具体用法?Python opcode.hasname怎么用?Python opcode.hasname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opcode
的用法示例。
在下文中一共展示了opcode.hasname方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_op_oparg
# 需要导入模块: import opcode [as 别名]
# 或者: from opcode import hasname [as 别名]
def get_op_oparg(self, op, arg, bc_index=0):
"""
Retrieve the opcode (`op`) and its argument (`oparg`) from the supplied
opcode and argument.
:param op: The current opcode.
:param arg: The current dereferenced argument.
:param bc_index: The current bytecode index.
"""
# Conversion of LOAD_NAME opcode based on injected references (global, vars)
if op == LOAD_NAME:
if arg in self.name_to_fast:
op = LOAD_FAST
elif arg in self.name_to_global:
op = LOAD_GLOBAL
oparg = None
if op >= opcode.HAVE_ARGUMENT:
if op in opcode.hasconst:
oparg = self.add_get_constant(arg)
elif op in opcode.hasname:
oparg = self.add_get_names(arg)
elif op in opcode.haslocal:
oparg = self.add_get_varnames(arg)
elif op in opcode.hascompare:
oparg = opcode.cmp_op.index(arg)
elif op in opcode.hasfree:
oparg = self.add_get_cellvars_freevars(arg)
elif op in opcode.hasjrel or op in opcode.hasjabs:
oparg = arg
else:
oparg = arg
return op, oparg
示例2: decode_codeobj
# 需要导入模块: import opcode [as 别名]
# 或者: from opcode import hasname [as 别名]
def decode_codeobj(codeobj):
# adapted from dis.dis
extended_arg = 0
if is_py3k:
codestr = codeobj.co_code
else:
codestr = [ord(ch) for ch in codeobj.co_code]
free = None
i = 0
while i < len(codestr):
op = codestr[i]
opname = opcode.opname[op]
i += 1
argval = None
if op >= opcode.HAVE_ARGUMENT:
oparg = codestr[i] + codestr[i + 1] * 256 + extended_arg
i += 2
extended_arg = 0
if op == opcode.EXTENDED_ARG:
extended_arg = oparg * 65536
continue
if op in opcode.hasconst:
argval = codeobj.co_consts[oparg]
elif op in opcode.hasname:
argval = codeobj.co_names[oparg]
elif op in opcode.hasjrel:
argval = i + oparg
elif op in opcode.haslocal:
argval = codeobj.co_varnames[oparg]
elif op in opcode.hascompare:
argval = opcode.cmp_op[oparg]
elif op in opcode.hasfree:
if free is None:
free = codeobj.co_cellvars + codeobj.co_freevars
argval = free[oparg]
yield (opname, argval)
示例3: disassemble
# 需要导入模块: import opcode [as 别名]
# 或者: from opcode import hasname [as 别名]
def disassemble(co):
code = co.co_code
labels = dis.findlabels(code)
linestarts = dict(dis.findlinestarts(co))
n = len(code)
i = 0
extended_arg = 0
free = None
lineno = None
while i < n:
c = code[i]
op = ord(c)
lineno = linestarts.get(i, lineno)
is_label = i in labels
ist = i
i += 1
if op >= opcode.HAVE_ARGUMENT:
oparg = ord(code[i]) + ord(code[i + 1]) * 256 + extended_arg
extended_arg = 0
i += 2
if op == opcode.EXTENDED_ARG:
extended_arg = oparg * 65536L
if op in opcode.hasconst:
arg = co.co_consts[oparg]
elif op in opcode.hasname:
arg = co.co_names[oparg]
elif op in opcode.hasjrel:
arg = i + oparg
elif op in opcode.haslocal:
arg = co.co_varnames[oparg]
elif op in opcode.hascompare:
arg = opcode.cmp_op[oparg]
elif op in opcode.hasfree:
if free is None:
free = co.co_cellvars + co.co_freevars
arg = free[oparg]
else:
arg = NOVAL
else:
arg = NOVAL
yield ist, lineno, is_label, opcode.opname[op], arg