本文整理匯總了Python中pykit.ir.Builder.exc_setup方法的典型用法代碼示例。如果您正苦於以下問題:Python Builder.exc_setup方法的具體用法?Python Builder.exc_setup怎麽用?Python Builder.exc_setup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pykit.ir.Builder
的用法示例。
在下文中一共展示了Builder.exc_setup方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: preserve_exceptions
# 需要導入模塊: from pykit.ir import Builder [as 別名]
# 或者: from pykit.ir.Builder import exc_setup [as 別名]
def preserve_exceptions(oldblock, newblock):
"""
Preserve exc_setup instructions for block splits.
"""
from pykit.ir import Builder
func = oldblock.parent
b = Builder(func)
b.position_at_beginning(newblock)
for op in oldblock.leaders:
if op.opcode == 'exc_setup':
b.exc_setup(op.args[0], **op.metadata)
示例2: test_exc_rewrite
# 需要導入模塊: from pykit.ir import Builder [as 別名]
# 或者: from pykit.ir.Builder import exc_setup [as 別名]
def test_exc_rewrite(self):
func = Function("foo", [], types.Function(types.Void, ()))
entry = func.new_block("entry")
catch_block = func.new_block("catch")
b = Builder(func)
with b.at_front(entry):
b.exc_setup([catch_block])
b.exc_throw(Const(StopIteration, types.Exception))
with b.at_front(catch_block):
b.exc_catch([Const(Exception, types.Exception)])
local_exceptions.run(func, {})
print(func)
示例3: Translate
# 需要導入模塊: from pykit.ir import Builder [as 別名]
# 或者: from pykit.ir.Builder import exc_setup [as 別名]
#.........這裏部分代碼省略.........
# Add unpacked iterable to args list
f, args = call.args
call.set_args([f, args + [it]])
# Annotate call as a 'varargs' application
self.call_annotations[call]['varargs'] = True
def op_GET_ITER(self, inst):
self.call(iter, [self.pop()])
def op_FOR_ITER(self, inst):
"""
Translate a for loop to:
it = getiter(iterable)
try:
while 1:
i = next(t)
...
except StopIteration:
pass
"""
iterobj = self.peek()
delta = inst.arg
loopexit = self.blocks[inst.next + delta]
loop_block = self.loop_stack[-1]
loop_block.catch_block = loopexit
# -------------------------------------------------
# Try
self.insert('exc_setup', [loopexit])
self.call(next, [iterobj])
# We assume a 1-to-1 block mapping, resolve a block split in a
# later pass
self.insert('exc_end')
# -------------------------------------------------
# Catch
with self.builder.at_front(loopexit):
self.insert('exc_catch', [Const(StopIteration, type=types.Exception)])
# -------------------------------------------------
# Exit
# Add the loop exit at a successor to the header
self.predecessors[loopexit].add(self.curblock)
# Remove ourselves as a predecessor from the actual exit block, set by
# SETUP_LOOP
self.predecessors[loop_block.end].remove(self.prevblock)
def op_BREAK_LOOP(self, inst):
loopblock = self.loop_stack[-1]
self.jump(target=loopblock.catch_block or loopblock.end)
def op_BUILD_TUPLE(self, inst):
count = inst.arg
items = [self.pop() for _ in range(count)]
ordered = list(reversed(items))
if all(isinstance(item, Const) for item in ordered):
# create constant tuple