• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python simplify.get_funcobj函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pypy.translator.simplify.get_funcobj函数的典型用法代码示例。如果您正苦于以下问题:Python get_funcobj函数的具体用法?Python get_funcobj怎么用?Python get_funcobj使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_funcobj函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_read_really

    def test_read_really(self):
        class A(object):
            def __init__(self, y):
                self.y = y
            def f(self):
                self.x = 1
                return self.y
        def h(flag):
            obj = A(flag)
            return obj.f()
        
        t, wa = self.translate(h, [int])
        hgraph = graphof(t, h)
        op_call_f = hgraph.startblock.operations[-1]

        # check that we fished the expected ops
        assert op_call_f.opname == "direct_call"
        assert get_funcobj(op_call_f.args[0].value)._name == 'A.f'

        result = wa.analyze(op_call_f)
        assert len(result) == 2
        result = list(result)
        result.sort()
        [(struct1, T1, name1), (struct2, T2, name2)] = result
        assert struct1 == "readstruct"
        assert name1.endswith("y")
        assert struct2 == "struct"
        assert name2.endswith("x")
        assert T1 == T2
开发者ID:alkorzt,项目名称:pypy,代码行数:29,代码来源:test_writeanalyze.py


示例2: getcalldescr

 def getcalldescr(self, op, oopspecindex=EffectInfo.OS_NONE,
                  extraeffect=None):
     """Return the calldescr that describes all calls done by 'op'.
     This returns a calldescr that we can put in the corresponding
     call operation in the calling jitcode.  It gets an effectinfo
     describing the effect of the call: which field types it may
     change, whether it can force virtualizables, whether it can
     raise, etc.
     """
     NON_VOID_ARGS = [x.concretetype for x in op.args[1:]
                                     if x.concretetype is not lltype.Void]
     RESULT = op.result.concretetype
     # check the number and type of arguments
     FUNC = get_functype(op.args[0].concretetype)
     ARGS = FUNC.ARGS
     assert NON_VOID_ARGS == [T for T in ARGS if T is not lltype.Void]
     assert RESULT == FUNC.RESULT
     # ok
     # get the 'pure' and 'loopinvariant' flags from the function object
     pure = False
     loopinvariant = False
     if op.opname == "direct_call":
         func = getattr(get_funcobj(op.args[0].value), '_callable', None)
         pure = getattr(func, "_pure_function_", False)
         loopinvariant = getattr(func, "_jit_loop_invariant_", False)
         if loopinvariant:
             assert not NON_VOID_ARGS, ("arguments not supported for "
                                        "loop-invariant function!")
     # build the extraeffect
     can_invalidate = self.quasiimmut_analyzer.analyze(op)
     if extraeffect is None:
         if self.virtualizable_analyzer.analyze(op):
             extraeffect = EffectInfo.EF_FORCES_VIRTUAL_OR_VIRTUALIZABLE
         elif loopinvariant:
             extraeffect = EffectInfo.EF_LOOPINVARIANT
         elif pure:
             # XXX check what to do about exceptions (also MemoryError?)
             extraeffect = EffectInfo.EF_PURE
         elif self._canraise(op):
             extraeffect = EffectInfo.EF_CAN_RAISE
         else:
             extraeffect = EffectInfo.EF_CANNOT_RAISE
     #
     effectinfo = effectinfo_from_writeanalyze(
         self.readwrite_analyzer.analyze(op), self.cpu, extraeffect,
         oopspecindex, can_invalidate)
     #
     if oopspecindex != EffectInfo.OS_NONE:
         assert effectinfo is not None
     if pure or loopinvariant:
         assert effectinfo is not None
         assert extraeffect != EffectInfo.EF_FORCES_VIRTUAL_OR_VIRTUALIZABLE
         # XXX this should also say assert not can_invalidate, but
         #     it can't because our analyzer is not good enough for now
         #     (and getexecutioncontext() can't really invalidate)
     #
     return self.cpu.calldescrof(FUNC, tuple(NON_VOID_ARGS), RESULT,
                                 effectinfo)
开发者ID:ieure,项目名称:pypy,代码行数:58,代码来源:call.py


示例3: analyze_external_call

 def analyze_external_call(self, op, seen=None):
     funcobj = get_funcobj(op.args[0].value)
     result = self.bottom_result()
     if hasattr(funcobj, '_callbacks'):
         bk = self.translator.annotator.bookkeeper
         for function in funcobj._callbacks.callbacks:
             desc = bk.getdesc(function)
             for graph in desc.getgraphs():
                 result = self.join_two_results(
                     result, self.analyze_direct_call(graph, seen))
     return result
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:11,代码来源:graphanalyze.py


示例4: decode_builtin_call

def decode_builtin_call(op):
    if op.opname == 'oosend':
        SELFTYPE, name, opargs = decompose_oosend(op)
        return get_send_oopspec(SELFTYPE, name), opargs
    elif op.opname == 'direct_call':
        fnobj = get_funcobj(op.args[0].value)
        opargs = op.args[1:]
        return get_call_oopspec_opargs(fnobj, opargs)
    elif op.opname in ('oostring', 'oounicode'):
        return get_oostring_oopspec(op)
    elif op.opname == 'gc_identityhash':
        return get_identityhash_oopspec(op)
    else:
        raise ValueError(op.opname)
开发者ID:enyst,项目名称:plexnet,代码行数:14,代码来源:support.py


示例5: iter_callsites

def iter_callsites(graph, calling_what):
    for block in graph.iterblocks():
        for i, op in enumerate(block.operations):
            if op.opname == "direct_call":
                funcobj = get_funcobj(op.args[0].value)
            elif op.opname == "oosend":
                funcobj = get_meth_from_oosend(op)
                if funcobj is None:
                    continue # cannot inline virtual methods
            else:
                continue

            graph = getattr(funcobj, 'graph', None)
            # accept a function or a graph as 'inline_func'
            if (graph is calling_what or
                getattr(funcobj, '_callable', None) is calling_what):
                yield graph, block, i
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:17,代码来源:inline.py


示例6: direct_call

    def direct_call(hs_f1, *args_hs):
        bookkeeper = getbookkeeper()
        fnobj = get_funcobj(hs_f1.const)
        if (bookkeeper.annotator.policy.oopspec and
            hasattr(fnobj._callable, 'oopspec')):
            # try to handle the call as a high-level operation
            try:
                return handle_highlevel_operation(bookkeeper, fnobj._callable,
                                                  *args_hs)
            except NotImplementedError:
                pass

        # normal call
        if not hasattr(fnobj, 'graph'):
            raise NotImplementedError("XXX call to externals or primitives")

        return hs_f1._call_single_graph(fnobj.graph, lltype.typeOf(fnobj).RESULT, *args_hs)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:17,代码来源:model.py


示例7: maybe_on_top_of_llinterp

def maybe_on_top_of_llinterp(rtyper, fnptr):
    # Run a generated graph on top of the llinterp for testing.
    # When translated, this just returns the fnptr.
    def process_args(args):
        real_args = []
        ARGS = lltype.typeOf(funcobj).ARGS
        i = 0
        for ARG in ARGS:
            if ARG is lltype.Void:
                real_args.append(None)
            else:
                if ARG is lltype.Float:
                    real_args.append(args[i])
                elif isinstance(ARG, lltype.Primitive):
                    real_args.append(lltype.cast_primitive(ARG, args[i]))
                elif isinstance(ARG, lltype.Ptr):
                    if ARG.TO._gckind == 'gc':
                        real_args.append(lltype.cast_opaque_ptr(ARG, args[i]))
                    else:
                        real_args.append(rffi.cast(ARG, args[i]))
                else:
                    raise Exception("Unexpected arg: %s" % ARG)
                i += 1
        return real_args

    funcobj = get_funcobj(fnptr)
    if hasattr(funcobj, 'graph'):
        # cache the llinterp; otherwise the remember_malloc/remember_free
        # done on the LLInterpreter don't match
        try:
            llinterp = rtyper._on_top_of_llinterp_llinterp
        except AttributeError:
            llinterp = LLInterpreter(rtyper)  #, exc_data_ptr=exc_data_ptr)
            rtyper._on_top_of_llinterp_llinterp = llinterp
        def on_top_of_llinterp(*args):
            real_args = process_args(args)
            return llinterp.eval_graph(funcobj.graph, real_args)
    else:
        assert hasattr(funcobj, '_callable')
        def on_top_of_llinterp(*args):
            args = process_args(args)
            return funcobj._callable(*args)
    return on_top_of_llinterp
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:43,代码来源:support.py


示例8: guess_call_kind

 def guess_call_kind(self, op, is_candidate=None):
     if op.opname == 'direct_call':
         funcptr = op.args[0].value
         if self.jitdriver_sd_from_portal_runner_ptr(funcptr) is not None:
             return 'recursive'
         funcobj = get_funcobj(funcptr)
         if getattr(funcobj, 'graph', None) is None:
             return 'residual'
         targetgraph = funcobj.graph
         if (hasattr(targetgraph, 'func') and
             hasattr(targetgraph.func, 'oopspec')):
             return 'builtin'
     elif op.opname == 'oosend':
         SELFTYPE, methname, opargs = support.decompose_oosend(op)
         if SELFTYPE.oopspec_name is not None:
             return 'builtin'
     if self.graphs_from(op, is_candidate) is None:
         return 'residual'
     return 'regular'
开发者ID:gorakhargosh,项目名称:pypy,代码行数:19,代码来源:call.py


示例9: search_for_calls

 def search_for_calls(self, block):
     d = {}
     for i, op in enumerate(block.operations):
         if op.opname == "direct_call":
             funcobj = get_funcobj(op.args[0].value)
         elif op.opname == "oosend":
             funcobj = get_meth_from_oosend(op)
             if funcobj is None:
                 continue
         else:
             continue
         graph = getattr(funcobj, 'graph', None)
         # accept a function or a graph as 'inline_func'
         if (graph is self.inline_func or
             getattr(funcobj, '_callable', None) is self.inline_func):
             d[i] = graph
     if d:
         self.block_to_index[block] = d
     else:
         try:
             del self.block_to_index[block]
         except KeyError:
             pass
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:23,代码来源:inline.py


示例10: graphs_from

 def graphs_from(self, op, is_candidate=None):
     if is_candidate is None:
         is_candidate = self.is_candidate
     if op.opname == 'direct_call':
         funcobj = get_funcobj(op.args[0].value)
         graph = funcobj.graph
         if is_candidate(graph):
             return [graph]     # common case: look inside this graph
     else:
         assert op.opname in ('indirect_call', 'oosend')
         if op.opname == 'indirect_call':
             graphs = op.args[-1].value
         else:
             v_obj = op.args[1].concretetype
             graphs = v_obj._lookup_graphs(op.args[0].value)
         #
         if graphs is None:
             # special case: handle the indirect call that goes to
             # the 'instantiate' methods.  This check is a bit imprecise
             # but it's not too bad if we mistake a random indirect call
             # for the one to 'instantiate'.
             from pypy.rpython.lltypesystem import rclass
             CALLTYPE = op.args[0].concretetype
             if (op.opname == 'indirect_call' and len(op.args) == 2 and
                 CALLTYPE == rclass.OBJECT_VTABLE.instantiate):
                 graphs = list(self._graphs_of_all_instantiate())
         #
         if graphs is not None:
             result = []
             for graph in graphs:
                 if is_candidate(graph):
                     result.append(graph)
             if result:
                 return result  # common case: look inside these graphs,
                                # and ignore the others if there are any
     # residual call case: we don't need to look into any graph
     return None
开发者ID:gorakhargosh,项目名称:pypy,代码行数:37,代码来源:call.py


示例11: analyze_external_call

 def analyze_external_call(self, op, seen=None):
     fnobj = get_funcobj(op.args[0].value)
     return getattr(fnobj, 'canraise', True)
开发者ID:alkorzt,项目名称:pypy,代码行数:3,代码来源:canraise.py


示例12: get_graph_from_op

 def get_graph_from_op(self, op):
     assert op.opname in ('direct_call', 'oosend')
     if op.opname == 'direct_call':
         return get_funcobj(self.op.args[0].value).graph
     else:
         return get_meth_from_oosend(op).graph
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:6,代码来源:inline.py


示例13: consider_op_ts_metacall

 def consider_op_ts_metacall(self, hs_f1, hs_metadesccls, *args_hs):
     bookkeeper = self.bookkeeper
     fnobj = get_funcobj(hs_f1.const)
     return hintmodel.cannot_follow_call(bookkeeper, fnobj.graph, args_hs,
                                         lltype.typeOf(fnobj).RESULT)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:5,代码来源:annotator.py


示例14: check_call

 def check_call(op, fname):
     assert op.opname == "direct_call"
     assert get_funcobj(op.args[0].value)._name == fname
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:3,代码来源:test_canraise.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python simplify.simplify_graph函数代码示例发布时间:2022-05-27
下一篇:
Python option.getoption函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap