本文整理汇总了Python中opcode.cmp_op方法的典型用法代码示例。如果您正苦于以下问题:Python opcode.cmp_op方法的具体用法?Python opcode.cmp_op怎么用?Python opcode.cmp_op使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opcode
的用法示例。
在下文中一共展示了opcode.cmp_op方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: COMPARE_OP
# 需要导入模块: import opcode [as 别名]
# 或者: from opcode import cmp_op [as 别名]
def COMPARE_OP(self, addr, opname):
left, right = self.stack.pop(2)
if opname != 10: # 10 is exception match
self.stack.push(PyCompare([left, cmp_op[opname], right]))
else:
# It's an exception match
# left is a TryStatement
# right is the exception type to be matched
# It goes:
# COMPARE_OP 10
# POP_JUMP_IF_FALSE <next except>
# POP_TOP
# POP_TOP or STORE_FAST (if the match is named)
# POP_TOP
# SETUP_FINALLY if the match was named
assert addr[1].opcode == POP_JUMP_IF_FALSE
left.next_start_except = addr[1].jump()
assert addr[2].opcode == POP_TOP
assert addr[4].opcode == POP_TOP
if addr[5].opcode == SETUP_FINALLY:
except_start = addr[6]
except_end = addr[5].jump()
else:
except_start = addr[5]
except_end = left.next_start_except[-1]
d_body = SuiteDecompiler(except_start, except_end)
d_body.run()
left.add_except_clause(right, d_body.suite)
if addr[3].opcode != POP_TOP:
# The exception is named
d_exc_name = SuiteDecompiler(addr[3], addr[4])
d_exc_name.stack.push(left)
# This will store the name in left:
d_exc_name.run()
# We're done with this except clause
return self.END_NOW
#
# Stack manipulation
#
示例2: decode_codeobj
# 需要导入模块: import opcode [as 别名]
# 或者: from opcode import cmp_op [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 cmp_op [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