当前位置: 首页>>代码示例>>Python>>正文


Python Builder.exc_setup方法代码示例

本文整理汇总了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)
开发者ID:DarshanKumar89,项目名称:Delivery-Optimization,代码行数:15,代码来源:builder.py

示例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)
开发者ID:aterrel,项目名称:pykit,代码行数:16,代码来源:test_opt_local_exception.py

示例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
开发者ID:flypy,项目名称:flypy,代码行数:70,代码来源:translation.py


注:本文中的pykit.ir.Builder.exc_setup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。