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

Python ootype.new函数代码示例

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

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



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

示例1: f

 def f(n):
     obj1 = ootype.new(A)
     if n:
         obj2 = obj1
     else:
         obj2 = ootype.new(A)
     return obj1 is obj2
开发者ID:enyst,项目名称:plexnet,代码行数:7,代码来源:test_basic.py


示例2: ll_join_chars

 def ll_join_chars(length_dummy, lst):
     if typeOf(lst)._ITEMTYPE == Char:
         buf = ootype.new(ootype.StringBuilder)
     else:
         buf = ootype.new(ootype.UnicodeBuilder)
     length = lst.ll_length()
     buf.ll_allocate(length)
     i = 0
     while i < length:
         buf.ll_append_char(lst.ll_getitem_fast(i))
         i += 1
     return buf.ll_build()
开发者ID:antoine1fr,项目名称:pygirl,代码行数:12,代码来源:rstr.py


示例3: test_unwrap_object

 def test_unwrap_object(self):
     A = ootype.Instance("A", ootype.ROOT, {})
     a1 = ootype.new(A)
     a2 = ootype.new(A)
     obj1 = ootype.cast_to_object(a1)
     obj2 = ootype.cast_to_object(a2)
     def fn(flag):
         if flag:
             obj = obj1
         else:
             obj = obj2
         a3 = ootype.cast_from_object(A, obj)
         return a3 is a1
     res = self.interpret(fn, [True], backendopt=False)
     assert res is True
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:15,代码来源:constant.py


示例4: fn_instance

 def fn_instance():
     a = ootype.new(A)
     obj = ootype.cast_to_object(a)
     a2 = ootype.cast_from_object(A, obj)
     a3 = ootype.cast_from_object(ootype.ROOT, obj)
     assert a is a2
     assert a is a3
开发者ID:alkorzt,项目名称:pypy,代码行数:7,代码来源:test_rclass.py


示例5: ll_rangeiter

def ll_rangeiter(ITER, rng):
    iter = new(ITER)
    iter.next = rng.start
    iter.stop = rng.stop
    if ITER is RANGESTITER:
        iter.step = rng.step
    return iter
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:7,代码来源:rrange.py


示例6: fn_record

 def fn_record():
     b = ootype.new(B)
     b.x = 42
     obj = ootype.cast_to_object(b)
     b2 = ootype.cast_from_object(B, obj)
     assert b2.x == 42
     assert b is b2
开发者ID:alkorzt,项目名称:pypy,代码行数:7,代码来源:test_rclass.py


示例7: fn_is_true

 def fn_is_true(flag):
     if flag:
         a = ootype.new(A)
     else:
         a = ootype.null(A)
     obj = ootype.cast_to_object(a)
     return bool(obj)
开发者ID:alkorzt,项目名称:pypy,代码行数:7,代码来源:test_rclass.py


示例8: test_invalid_cache

def test_invalid_cache():
    DT = Dict(Signed, Signed)
    d = new(DT)
    py.test.raises(AssertionError, d.ll_get, 0)
    d.ll_set(42, 1)
    d.ll_contains(43)
    py.test.raises(AssertionError, d.ll_get, 42)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:test_oodict.py


示例9: fn_mix_null

 def fn_mix_null(flag):
     a = ootype.new(A)
     obj = ootype.cast_to_object(a)
     if flag:
         return obj
     else:
         return ootype.NULL
开发者ID:alkorzt,项目名称:pypy,代码行数:7,代码来源:test_rclass.py


示例10: make_pyexcclass2exc

    def make_pyexcclass2exc(self, rtyper):
        # ll_pyexcclass2exc(python_exception_class) -> exception_instance
        table = {}
        Exception_def = rtyper.annotator.bookkeeper.getuniqueclassdef(Exception)
        for clsdef in rtyper.class_reprs:
            if (clsdef and clsdef is not Exception_def
                and clsdef.issubclass(Exception_def)):
                if not hasattr(clsdef.classdesc, 'pyobj'):
                    continue
                cls = clsdef.classdesc.pyobj
                if cls in self.standardexceptions and cls not in FORCE_ATTRIBUTES_INTO_CLASSES:
                    is_standard = True
                    assert not clsdef.attrs, (
                        "%r should not have grown attributes" % (cls,))
                else:
                    is_standard = (cls.__module__ == 'exceptions'
                                   and not clsdef.attrs)
                if is_standard:
                    example = self.get_standard_ll_exc_instance(rtyper, clsdef)
                    table[cls] = example
        r_inst = rclass.getinstancerepr(rtyper, None)
        r_inst.setup()
        r_class = rclass.getclassrepr(rtyper, None)
        r_class.setup()
        default_excinst = ootype.new(self.lltype_of_exception_value)
        default_excinst.meta = r_class.get_meta_instance()

        # build the table in order base classes first, subclasses last
        sortedtable = []
        def add_class(cls):
            if cls in table:
                for base in cls.__bases__:
                    add_class(base)
                sortedtable.append((cls, table[cls]))
                del table[cls]
        for cls in table.keys():
            add_class(cls)
        assert table == {}

        initial_value_of_i = len(sortedtable) - 1
        def pyexcclass2exc(python_exception_class):
            python_exception_class = python_exception_class._obj.value
            i = initial_value_of_i
            while i >= 0:
                if issubclass(python_exception_class, sortedtable[i][0]):
                    return sortedtable[i][1]
                i -= 1
            return default_excinst

        # This function will only be used by the llinterpreter which usually
        # expects a low-level callable (_meth, _static_meth), so we just
        # fake it here.
        FakeCallableType = ootype.OOType()
        FakeCallableType.ARGS = ()
        class fake_callable(object):
            def __init__(self, fn):
                self._TYPE = FakeCallableType
                self._callable = fn
        return fake_callable(pyexcclass2exc)
开发者ID:antoine1fr,项目名称:pygirl,代码行数:59,代码来源:exceptiondata.py


示例11: h

 def h(x, y, z):
     s = ootype.new(S)
     s.x = x
     s.y = y
     fsm = llhelper(F, f)
     gsm = llhelper(G, g)
     assert typeOf(fsm) == F
     return fsm(s, z)+fsm(s, z*2)+gsm(s)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:8,代码来源:test_llann.py


示例12: ll_newrangest

def ll_newrangest(start, stop, step):
    if step == 0:
        raise ValueError
    l = new(RANGEST)
    l.start = start
    l.stop = stop
    l.step = step
    return l
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:8,代码来源:rrange.py


示例13: ll_known_maxlength2list

def ll_known_maxlength2list(RESLIST, l):
    res = ootype.new(RESLIST)
    length = l.length
    res._ll_resize_ge(length)
    for i in range(length):
        item = l.items.ll_getitem_fast(i)
        res.ll_setitem_fast(i, item)
    return res
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:rlist.py


示例14: ll_popitem

def ll_popitem(ELEM, d):
    it = d.ll_get_items_iterator()
    if it.ll_go_next():
        res = ootype.new(ELEM)
        key = res.item0 = it.ll_current_key()
        res.item1 = it.ll_current_value()
        d.ll_remove(key)
        return res
    raise KeyError
开发者ID:ieure,项目名称:pypy,代码行数:9,代码来源:rdict.py


示例15: get_meta_instance

 def get_meta_instance(self, cast_to_root_meta=True):
     if self.meta_instance is None:
         self.meta_instance = ootype.new(self.lowleveltype) 
         self.setup_meta_instance(self.meta_instance, self)
     
     meta_instance = self.meta_instance
     if cast_to_root_meta:
         meta_instance = ootype.ooupcast(CLASSTYPE, meta_instance)
     return meta_instance
开发者ID:antoine1fr,项目名称:pygirl,代码行数:9,代码来源:rclass.py


示例16: test_cast_record_pbc

 def test_cast_record_pbc(self):
     T = ootype.Record({'x': ootype.Signed})
     record = ootype.new(T)
     record.x = 42
     obj = cast_record_to_object(record)
     def fn():
         record2 = cast_object_to_record(T, obj)
         return record is record2
     res = self.interpret(fn, [])
     assert res
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:10,代码来源:test_dotnet.py


示例17: ll_str

 def ll_str(self, value):
     sb = ootype.new(ootype.StringBuilder)
     lgt = value.ll_strlen()
     sb.ll_allocate(lgt)
     for i in range(lgt):
         c = value.ll_stritem_nonneg(i)
         if ord(c) > 127:
             raise UnicodeEncodeError("%d > 127, not ascii" % ord(c))
         sb.ll_append_char(cast_primitive(Char, c))
     return sb.ll_build()
开发者ID:alkorzt,项目名称:pypy,代码行数:10,代码来源:rstr.py


示例18: fn

 def fn():
     a = ootype.new(A)
     ahash = ootype.identityhash(a)
     obj = ootype.cast_to_object(a)
     native = cast_to_native_object(obj)
     name = native.GetType().get_Name()
     obj2 = cast_from_native_object(native)
     a2 = ootype.cast_from_object(A, obj2)
     a2hash = ootype.identityhash(a2)
     return name, ahash == a2hash
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:10,代码来源:test_dotnet.py


示例19: test_iteritems

def test_iteritems():
    DT = Dict(Signed, Float)
    d = new(DT)
    d.ll_set(42, 43.0)
    d.ll_set(52, 53.0)
    it = d.ll_get_items_iterator()
    items = []
    while it.ll_go_next():
        items.append((it.ll_current_key(), it.ll_current_value()))
    items.sort()
    assert items == [(42, 43.0), (52, 53.0)]
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:11,代码来源:test_oodict.py


示例20: get_meta_instance

 def get_meta_instance(self, cast_to_root_meta=True):
     if self.lowleveltype == ootype.Class:
         raise TyperError("no meta-instance for class %r" % 
                          (self.classdef,))
     if self.meta_instance is None:
         self.meta_instance = ootype.new(self.lowleveltype) 
         self.setup_meta_instance(self.meta_instance, self)
     
     meta_instance = self.meta_instance
     if cast_to_root_meta:
         meta_instance = ootype.ooupcast(META, meta_instance)
     return meta_instance
开发者ID:alkorzt,项目名称:pypy,代码行数:12,代码来源:rclass.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python ootype.null函数代码示例发布时间:2022-05-27
下一篇:
Python ootype.cast_to_object函数代码示例发布时间: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