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


Python model.lltype_to_annotation函数代码示例

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


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

示例1: builtin_func_for_spec

def builtin_func_for_spec(rtyper, oopspec_name, ll_args, ll_res):
    key = (oopspec_name, tuple(ll_args), ll_res)
    try:
        return rtyper._builtin_func_for_spec_cache[key]
    except (KeyError, AttributeError):
        pass
    args_s = [annmodel.lltype_to_annotation(v) for v in ll_args]
    if "." not in oopspec_name:  # 'newxxx' operations
        LIST_OR_DICT = ll_res
    else:
        LIST_OR_DICT = ll_args[0]
    s_result = annmodel.lltype_to_annotation(ll_res)
    impl = setup_extra_builtin(rtyper, oopspec_name, len(args_s))
    if getattr(impl, "need_result_type", False):
        bk = rtyper.annotator.bookkeeper
        args_s.insert(0, annmodel.SomePBC([bk.getdesc(deref(ll_res))]))
    #
    mixlevelann = MixLevelHelperAnnotator(rtyper)
    c_func = mixlevelann.constfunc(impl, args_s, s_result)
    mixlevelann.finish()
    #
    if not hasattr(rtyper, "_builtin_func_for_spec_cache"):
        rtyper._builtin_func_for_spec_cache = {}
    rtyper._builtin_func_for_spec_cache[key] = (c_func, LIST_OR_DICT)
    #
    return c_func, LIST_OR_DICT
开发者ID:alkorzt,项目名称:pypy,代码行数:26,代码来源:support.py

示例2: get_external_function_sandbox_graph

def get_external_function_sandbox_graph(fnobj, db, force_stub=False):
    """Build the graph of a helper trampoline function to be used
    in place of real calls to the external function 'fnobj'.  The
    trampoline marshals its input arguments, dumps them to STDOUT,
    and waits for an answer on STDIN.
    """
    fnname = fnobj._name
    if hasattr(fnobj, 'graph'):
        # get the annotation of the input arguments and the result
        graph = fnobj.graph
        annotator = db.translator.annotator
        args_s = [annotator.binding(v) for v in graph.getargs()]
        s_result = annotator.binding(graph.getreturnvar())
    else:
        # pure external function - fall back to the annotations
        # corresponding to the ll types
        FUNCTYPE = lltype.typeOf(fnobj)
        args_s = [annmodel.lltype_to_annotation(ARG) for ARG in FUNCTYPE.ARGS]
        s_result = annmodel.lltype_to_annotation(FUNCTYPE.RESULT)

    try:
        if force_stub:   # old case - don't try to support suggested_primitive
            raise NotImplementedError("sandboxing for external function '%s'"
                                      % (fnname,))

        dump_arguments = rmarshal.get_marshaller(tuple(args_s))
        load_result = rmarshal.get_loader(s_result)

    except (NotImplementedError,
            rmarshal.CannotMarshal,
            rmarshal.CannotUnmarshall), e:
        msg = 'Not Implemented: %s' % (e,)
        log.WARNING(msg)
        def execute(*args):
            not_implemented_stub(msg)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:35,代码来源:rsandbox.py

示例3: postprocess_timeshifting

 def postprocess_timeshifting(self):
     annhelper = self.hrtyper.annhelper
     convert_result = getattr(self.main, 'convert_result', str)
     annotator = self.rtyper.annotator
     args_s = [annmodel.lltype_to_annotation(v.concretetype)
               for v in self.maingraph.getargs()]
     retvar = self.maingraph.getreturnvar()
     s_result = annmodel.lltype_to_annotation(retvar.concretetype)
     main_fnptr = self.rtyper.type_system.getcallable(self.maingraph)
     main = PseudoHighLevelCallable(main_fnptr, args_s, s_result)
     
     if hasattr(self.main, 'convert_arguments'):
         decoders = self.main.convert_arguments
         assert len(decoders) == len(args_s)
     else:
         decoders = [int] * len(args_s)
     decoders = unrolling_iterable(decoders)
     def ll_main(argv):
         args = ()
         i = 1
         for decoder in decoders:
             args += (decoder(argv[i]),)
             i = i + 1
         try:
             res = main(*args)
         except Exception, e:
             os.write(1, 'EXCEPTION: %s\n' % (e,))
             return 0
         os.write(1, convert_result(res) + '\n')
         return 0
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:30,代码来源:test_genc_portal.py

示例4: helper_func

 def helper_func(self, FUNCPTR, func):
     if not self.cpu.translate_support_code:
         return llhelper(FUNCPTR, func)
     FUNC = get_functype(FUNCPTR)
     args_s = [annmodel.lltype_to_annotation(ARG) for ARG in FUNC.ARGS]
     s_result = annmodel.lltype_to_annotation(FUNC.RESULT)
     graph = self.annhelper.getgraph(func, args_s, s_result)
     return self.annhelper.graph2delayed(graph, FUNC)
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:warmspot.py

示例5: compute_result_annotation

 def compute_result_annotation(self, s_F, s_callable):
     assert s_F.is_constant()
     assert s_callable.is_constant()
     F = s_F.const
     args_s = [annmodel.lltype_to_annotation(T) for T in F.TO.ARGS]
     key = (llhelper, s_callable.const)
     s_res = self.bookkeeper.emulate_pbc_call(key, s_callable, args_s)
     assert annmodel.lltype_to_annotation(F.TO.RESULT).contains(s_res)
     return annmodel.SomePtr(F)
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:9,代码来源:annlowlevel.py

示例6: compute_result_annotation

 def compute_result_annotation(self, s_F, s_callable):
     assert s_F.is_constant()
     assert s_callable.is_constant()
     F = s_F.const
     if isinstance(F, ootype.OOType):
         FUNC = F
         resultcls = annmodel.SomeOOStaticMeth
     else:
         FUNC = F.TO
         resultcls = annmodel.SomePtr
     
     args_s = [annmodel.lltype_to_annotation(T) for T in FUNC.ARGS]
     key = (llhelper, s_callable.const)
     s_res = self.bookkeeper.emulate_pbc_call(key, s_callable, args_s)
     assert annmodel.lltype_to_annotation(FUNC.RESULT).contains(s_res)
     return resultcls(F)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:16,代码来源:annlowlevel.py

示例7: _compute_annotation

def _compute_annotation(t, bookkeeper=None):
    from pypy.rpython.lltypesystem import lltype
    from pypy.annotation.bookkeeper import getbookkeeper
    from pypy.rpython import extregistry
    if isinstance(t, SomeObject):
        return t
    elif isinstance(t, lltype.LowLevelType):
        return lltype_to_annotation(t)
    elif isinstance(t, list):
        assert len(t) == 1, "We do not support type joining in list"
        listdef = ListDef(bookkeeper, annotation(t[0]), mutated=True, resized=True)
        return SomeList(listdef)
    elif isinstance(t, tuple):
        return SomeTuple(tuple([annotation(i) for i in t]))
    elif isinstance(t, dict):
        assert len(t) == 1, "We do not support type joining in dict"
        result = SomeDict(DictDef(bookkeeper, annotation(t.keys()[0]),
                                annotation(t.values()[0])))
        return result
    elif type(t) is types.NoneType:
        return s_None
    elif extregistry.is_registered(t):
        entry = extregistry.lookup(t)
        entry.bookkeeper = bookkeeper
        return entry.compute_result_annotation()
    else:
        return annotationoftype(t, bookkeeper)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:27,代码来源:signature.py

示例8: gendirectcall

    def gendirectcall(self, ll_function, *args_v):
        rtyper = self.rtyper
        args_s = []
        newargs_v = []
        for v in args_v:
            if v.concretetype is Void:
                s_value = rtyper.binding(v, default=annmodel.s_None)
                if not s_value.is_constant():
                    raise TyperError("non-constant variable of type Void")
                if not isinstance(s_value, annmodel.SomePBC):
                    raise TyperError("non-PBC Void argument: %r", (s_value,))
                args_s.append(s_value)
            else:
                args_s.append(annmodel.lltype_to_annotation(v.concretetype))
            newargs_v.append(v)
        
        self.rtyper.call_all_setups()  # compute ForwardReferences now

        # hack for bound methods
        if hasattr(ll_function, 'im_func'):
            bk = rtyper.annotator.bookkeeper
            args_s.insert(0, bk.immutablevalue(ll_function.im_self))
            newargs_v.insert(0, inputconst(Void, ll_function.im_self))
            ll_function = ll_function.im_func

        graph = annotate_lowlevel_helper(rtyper.annotator, ll_function, args_s,
                                         rtyper.lowlevel_ann_policy)
        self.record_extra_call(graph)

        # build the 'direct_call' operation
        f = self.rtyper.getcallable(graph)
        c = inputconst(typeOf(f), f)
        fobj = self.rtyper.type_system_deref(f)
        return self.genop('direct_call', [c]+newargs_v,
                          resulttype = typeOf(fobj).RESULT)
开发者ID:ieure,项目名称:pypy,代码行数:35,代码来源:rtyper.py

示例9: annotation

 def annotation(x):
     T = typeOf(x)
     if T == Ptr(PyObject) and someobjects:
         return object
     elif T == Ptr(rstr.STR):
         return str
     else:
         return lltype_to_annotation(T)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:8,代码来源:test_llinterpsim.py

示例10: test_ll_calling_ll

    def test_ll_calling_ll(self):
        A = GcArray(Float)
        B = GcArray(Signed)
        def ll_make(T, n):
            x = malloc(T, n)
            return x
        def ll_get(T, x, i):
            return x[i]
        def llf():
            a = ll_make(A, 3)
            b = ll_make(B, 2)
            a[0] = 1.0
            b[1] = 3
            y0 = ll_get(A, a, 1)
            y1 = ll_get(B, b, 1)
            #
            a2 = ll_make(A, 4)
            a2[0] = 2.0
            return ll_get(A, a2, 1)
        s = self.annotate(llf, [])
        a = self.a
        assert s == annmodel.SomeFloat()

        seen = {}
        ngraphs = len(a.translator.graphs)

        vTs = []
        for call in annotated_calls(a):
            if derived(call, "ll_"):

                func, T = [x.value for x in call.args[0:2]]
                if (func, T) in seen:
                    continue
                seen[func, T] = True
                
                desc = a.bookkeeper.getdesc(func)
                g = desc.specialize([a.binding(x) for x in call.args[1:]])

                args = g.getargs()
                rv = g.getreturnvar()
                if func is ll_get:                    
                    vT, vp, vi = args
                    assert a.binding(vT) == a.bookkeeper.immutablevalue(T)
                    assert a.binding(vi).knowntype == int
                    assert a.binding(vp).ll_ptrtype.TO == T
                    assert a.binding(rv) == annmodel.lltype_to_annotation(T.OF)
                elif func is ll_make:
                    vT, vn = args
                    assert a.binding(vT) == a.bookkeeper.immutablevalue(T)
                    assert a.binding(vn).knowntype == int
                    assert a.binding(rv).ll_ptrtype.TO == T
                else:
                    assert False, func
                vTs.append(vT)

        assert len(seen) == 4

        return a, vTs # reused by a test in test_rtyper
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:58,代码来源:test_llann.py

示例11: lltype_to_annotation

 def lltype_to_annotation(cls, TYPE):
     if isinstance(TYPE, NativeInstance):
         return SomeOOInstance(TYPE)
     elif TYPE is ootype.Char:
         return SomeChar()
     elif TYPE is ootype.String:
         return SomeString()
     else:
         return lltype_to_annotation(TYPE)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:9,代码来源:dotnet.py

示例12: getprimitiverepr

 def getprimitiverepr(self, lltype):
     try:
         return self.primitive_to_repr[lltype]
     except KeyError:
         pass
     if isinstance(lltype, Primitive):
         repr = self.primitive_to_repr[lltype] = self.getrepr(annmodel.lltype_to_annotation(lltype))
         return repr
     raise TyperError('There is no primitive repr for %r'%(lltype,))
开发者ID:ieure,项目名称:pypy,代码行数:9,代码来源:rtyper.py

示例13: _compile

 def _compile(self, fn, args, ann=None, backendopt=True):
     if ann is None:
         ann = [lltype_to_annotation(typeOf(x)) for x in args]
     if self._func is fn and self._ann == ann:
         return self._cli_func
     else:
         self._cli_func = compile_function(fn, ann, backendopt=backendopt)
         self._func = fn
         self._ann = ann
         return self._cli_func
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:10,代码来源:runtest.py

示例14: _compile

 def _compile(self, fn, args, ann=None):
     if ann is None:
         ann = [lltype_to_annotation(typeOf(x)) for x in args]
     if self._func is fn and self._ann == ann:
         return self._llvm_func
     else:
         self._llvm_func = compile_function(fn, ann)
         self._func = fn
         self._ann = ann
         return self._llvm_func
开发者ID:antoine1fr,项目名称:pygirl,代码行数:10,代码来源:runtest.py

示例15: compute_result_annotation

 def compute_result_annotation(self, s_RESTYPE, s_pythonfunction, *args_s):
     from pypy.annotation import model as annmodel
     from pypy.rpython.lltypesystem import lltype
     assert s_RESTYPE.is_constant()
     assert s_pythonfunction.is_constant()
     s_result = s_RESTYPE.const
     if isinstance(s_result, lltype.LowLevelType):
         s_result = annmodel.lltype_to_annotation(s_result)
     assert isinstance(s_result, annmodel.SomeObject)
     return s_result
开发者ID:alkorzt,项目名称:pypy,代码行数:10,代码来源:debug.py


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