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


Python model.registerimplementation函数代码示例

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


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

示例1: W_FloatObject

class W_FloatObject(W_AbstractFloatObject):
    """This is a implementation of the app-level 'float' type.
    The constructor takes an RPython float as an argument."""
    from pypy.objspace.std.floattype import float_typedef as typedef
    _immutable_fields_ = ['floatval']

    def __init__(w_self, floatval):
        w_self.floatval = floatval

    def unwrap(w_self, space):
        return w_self.floatval

    def __repr__(self):
        return "<W_FloatObject(%f)>" % self.floatval

registerimplementation(W_FloatObject)

# bool-to-float delegation
def delegate_Bool2Float(space, w_bool):
    return W_FloatObject(float(w_bool.boolval))

# int-to-float delegation
def delegate_Int2Float(space, w_intobj):
    return W_FloatObject(float(w_intobj.intval))

# long-to-float delegation
def delegate_Long2Float(space, w_longobj):
    try:
        return W_FloatObject(w_longobj.tofloat())
    except OverflowError:
        raise OperationError(space.w_OverflowError,
开发者ID:craigkerstiens,项目名称:pypy,代码行数:31,代码来源:floatobject.py

示例2: W_BytearrayObject

    new_bytearray
)
from pypy.tool.sourcetools import func_with_new_name


class W_BytearrayObject(W_Object):
    from pypy.objspace.std.bytearraytype import bytearray_typedef as typedef

    def __init__(w_self, data):
        w_self.data = data

    def __repr__(w_self):
        """ representation for debugging purposes """
        return "%s(%s)" % (w_self.__class__.__name__, ''.join(w_self.data))

registerimplementation(W_BytearrayObject)

init_signature = Signature(['source', 'encoding', 'errors'], None, None)
init_defaults = [None, None, None]

def init__Bytearray(space, w_bytearray, __args__):
    # this is on the silly side
    w_source, w_encoding, w_errors = __args__.parse_obj(
            None, 'bytearray', init_signature, init_defaults)

    if w_source is None:
        w_source = space.wrap('')
    if w_encoding is None:
        w_encoding = space.w_None
    if w_errors is None:
        w_errors = space.w_None
开发者ID:ieure,项目名称:pypy,代码行数:31,代码来源:bytearrayobject.py

示例3: __repr__

            return s
        else:
            return self.w_str._value

    def __repr__(w_self):
        """ representation for debugging purposes """
        return "%s(%r[:%d])" % (
            w_self.__class__.__name__, w_self.builder, w_self.length)

    def unwrap(self, space):
        return self.force()

    def str_w(self, space):
        return self.force()

registerimplementation(W_StringBufferObject)

# ____________________________________________________________

def joined2(str1, str2):
    builder = StringBuilder()
    builder.append(str1)
    builder.append(str2)
    return W_StringBufferObject(builder)

# ____________________________________________________________

def delegate_buf2str(space, w_strbuf):
    w_strbuf.force()
    return w_strbuf.w_str
开发者ID:charred,项目名称:pypy,代码行数:30,代码来源:strbufobject.py

示例4: OperationError

        except OperationError, e:
            w_rangeiter.w_seq = None
            if not e.match(space, space.w_IndexError):
                raise
            raise OperationError(space.w_StopIteration, space.w_None)
    else:
        if index >= w_rangelist.length:
            w_rangeiter.w_seq = None
            raise OperationError(space.w_StopIteration, space.w_None)
        w_item = wrapint(
            space,
            w_rangelist.getitem_unchecked(index))
    w_rangeiter.index = index + 1
    return w_item

# XXX __length_hint__()
##def len__RangeIter(space,  w_rangeiter):
##    if w_rangeiter.w_seq is None:
##        return wrapint(space, 0)
##    index = w_rangeiter.index
##    w_length = space.len(w_rangeiter.w_seq)
##    w_len = space.sub(w_length, wrapint(space, index))
##    if space.is_true(space.lt(w_len, wrapint(space, 0))):
##        w_len = wrapint(space, 0)
##    return w_len

registerimplementation(W_RangeListObject)
registerimplementation(W_RangeIterObject)

register_all(vars(), listtype)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:30,代码来源:rangeobject.py

示例5: W_NoneObject

"""
  None Object implementation

  ok and tested
"""

from pypy.objspace.std.model import registerimplementation, W_Object
from pypy.objspace.std.register_all import register_all

class W_NoneObject(W_Object):
    from pypy.objspace.std.nonetype import none_typedef as typedef

    def unwrap(w_self, space):
        return None

registerimplementation(W_NoneObject)

W_NoneObject.w_None = W_NoneObject()

def nonzero__None(space, w_none):
    return space.w_False

def repr__None(space, w_none):
    return space.wrap('None')

register_all(vars())

开发者ID:Debug-Orz,项目名称:Sypy,代码行数:26,代码来源:noneobject.py

示例6: W_TransparentFunction

    PyFrame, PyCode

class W_TransparentFunction(W_Transparent):
    typedef = Function.typedef

class W_TransparentTraceback(W_Transparent):
    typedef = PyTraceback.typedef

class W_TransparentCode(W_Transparent):
    typedef = PyCode.typedef

class W_TransparentFrame(W_Transparent):
    typedef = PyFrame.typedef

class W_TransparentGenerator(W_Transparent):
    typedef = GeneratorIterator.typedef

class W_TransparentList(W_TransparentObject):
    from pypy.objspace.std.listobject import W_ListObject as original
    from pypy.objspace.std.listtype import list_typedef as typedef

class W_TransparentDict(W_TransparentObject):
    from pypy.objspace.std.dictmultiobject import W_DictMultiObject as original
    from pypy.objspace.std.dicttype import dict_typedef as typedef

registerimplementation(W_TransparentList)
registerimplementation(W_TransparentDict)

register_type(W_TransparentList)
register_type(W_TransparentDict)
开发者ID:ieure,项目名称:pypy,代码行数:30,代码来源:proxyobject.py

示例7: make_specialized_class

                mult += 82520 + z + z
            x += 97531
            return space.wrap(intmask(x))

    cls.__name__ = "W_SmallTupleObject%s" % n
    return cls

W_SmallTupleObject2 = make_specialized_class(2)
W_SmallTupleObject3 = make_specialized_class(3)
W_SmallTupleObject4 = make_specialized_class(4)
W_SmallTupleObject5 = make_specialized_class(5)
W_SmallTupleObject6 = make_specialized_class(6)
W_SmallTupleObject7 = make_specialized_class(7)
W_SmallTupleObject8 = make_specialized_class(8)

registerimplementation(W_SmallTupleObject)

def delegate_SmallTuple2Tuple(space, w_small):
    return W_TupleObject(w_small.tolist())

def len__SmallTuple(space, w_tuple):
    return space.wrap(w_tuple.length())

def getitem__SmallTuple_ANY(space, w_tuple, w_index):
    index = space.getindex_w(w_index, space.w_IndexError, "tuple index")
    if index < 0:
        index += w_tuple.length()
    try:
        return w_tuple.getitem(index)
    except IndexError:
        raise OperationError(space.w_IndexError,
开发者ID:sota,项目名称:pypy,代码行数:31,代码来源:smalltupleobject.py

示例8: int

        return int(w_self.intval)
    int_w = unwrap

    def uint_w(w_self, space):
        intval = w_self.intval
        if intval < 0:
            raise OperationError(space.w_ValueError,
                                 space.wrap("cannot convert negative integer to unsigned"))
        else:
            return r_uint(intval)

    def bigint_w(w_self, space):
        return rbigint.fromint(w_self.intval)


registerimplementation(W_SmallIntObject)


def delegate_SmallInt2Int(space, w_small):
    return W_IntObject(w_small.intval)

def delegate_SmallInt2Long(space, w_small):
    return space.newlong(w_small.intval)

def delegate_SmallInt2Float(space, w_small):
    return space.newfloat(float(w_small.intval))

def delegate_SmallInt2Complex(space, w_small):
    return space.newcomplex(float(w_small.intval), 0.0)

def add__SmallInt_SmallInt(space, w_a, w_b):
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:31,代码来源:smallintobject.py

示例9: unwrap

    def unwrap(w_self, space):
        return w_self.boolval

    def int_w(w_self, space):
        return int(w_self.boolval)

    def uint_w(w_self, space):
        intval = int(w_self.boolval)
        return r_uint(intval)

    def bigint_w(w_self, space):
        return rbigint.fromint(int(w_self.boolval))


registerimplementation(W_BoolObject)

W_BoolObject.w_False = W_BoolObject(False)
W_BoolObject.w_True  = W_BoolObject(True)

# bool-to-int delegation requires translating the .boolvar attribute
# to an .intval one
def delegate_Bool2IntObject(space, w_bool):
    return W_IntObject(int(w_bool.boolval))

def delegate_Bool2SmallInt(space, w_bool):
    from pypy.objspace.std.smallintobject import W_SmallIntObject
    return W_SmallIntObject(int(w_bool.boolval))   # cannot overflow


def nonzero__Bool(space, w_bool):
开发者ID:ParitoshThapliyal59,项目名称:pypy,代码行数:30,代码来源:boolobject.py

示例10: Cls_oi

        #else:
        #    if w_type2 is space.w_int:
        #        return Cls_oi(space, w_arg1, w_arg2)
        #    elif w_type2 is space.w_str:
        #        return Cls_os(space, w_arg1, w_arg2)
        #    else:
        return Cls_oo(space, w_arg1, w_arg2)
        #
    #elif len(list_w) == 3:
    #    return Cls_ooo(space, list_w[0], list_w[1], list_w[2])
    else:
        raise NotSpecialised

# ____________________________________________________________

registerimplementation(W_SpecialisedTupleObject)

def delegate_SpecialisedTuple2Tuple(space, w_specialised):
    w_specialised.delegating()
    return W_TupleObject(w_specialised.tolist())

def len__SpecialisedTuple(space, w_tuple):
    return space.wrap(w_tuple.length())

def getitem__SpecialisedTuple_ANY(space, w_tuple, w_index):
    index = space.getindex_w(w_index, space.w_IndexError, "tuple index")
    if index < 0:
        index += w_tuple.length()
    try:
        return w_tuple.getitem(index)
    except IndexError:
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:31,代码来源:specialisedtupleobject.py

示例11: registerimplementation

from pypy.interpreter.mixedmodule import MixedModule
from pypy.module.array.interp_array import types, W_ArrayBase
from pypy.objspace.std.model import registerimplementation

for mytype in types.values():
    registerimplementation(mytype.w_class)


class Module(MixedModule):

    interpleveldefs = {
        'array': 'interp_array.W_ArrayBase',
        'ArrayType': 'interp_array.W_ArrayBase',
    }

    appleveldefs = {
    }
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:17,代码来源:__init__.py

示例12: create_if_subclassed

        return w_self._value

    def create_if_subclassed(w_self):
        if type(w_self) is W_UnicodeObject:
            return w_self
        return W_UnicodeObject(w_self._value)

    def str_w(self, space):
        return space.str_w(space.str(self))

    def unicode_w(self, space):
        return self._value

W_UnicodeObject.EMPTY = W_UnicodeObject(u'')

registerimplementation(W_UnicodeObject)

# Helper for converting int/long
def unicode_to_decimal_w(space, w_unistr):
    if not isinstance(w_unistr, W_UnicodeObject):
        raise operationerrfmt(space.w_TypeError,
                              "expected unicode, got '%s'",
                              space.type(w_unistr).getname(space))
    unistr = w_unistr._value
    result = ['\0'] * len(unistr)
    digits = [ '0', '1', '2', '3', '4',
               '5', '6', '7', '8', '9']
    for i in xrange(len(unistr)):
        uchr = ord(unistr[i])
        if unicodedb.isspace(uchr):
            result[i] = ' '
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:31,代码来源:unicodeobject.py

示例13: uint_w

    def uint_w(w_self, space):
        a = w_self.longlong
        if a < 0:
            raise OperationError(space.w_ValueError, space.wrap(
                "cannot convert negative integer to unsigned int"))
        b = r_uint(a)
        if r_longlong(b) == a:
            return b
        else:
            raise OperationError(space.w_OverflowError, space.wrap(
                "long int too large to convert to unsigned int"))

    def bigint_w(w_self, space):
        return w_self.asbigint()

registerimplementation(W_SmallLongObject)

# ____________________________________________________________

def llong_mul_ovf(a, b):
    # xxx duplication of the logic from translator/c/src/int.h
    longprod = a * b
    doubleprod = float(a) * float(b)
    doubled_longprod = float(longprod)

    # Fast path for normal case:  small multiplicands, and no info
    # is lost in either method.
    if doubled_longprod == doubleprod:
        return longprod

    # Somebody somewhere lost info.  Close enough, or way off?  Note
开发者ID:ParitoshThapliyal59,项目名称:pypy,代码行数:31,代码来源:smalllongobject.py

示例14: __repr__

            return w_self.joined_strs[0]
        res = "".join(w_self.joined_strs[:w_self.until])
        w_self.joined_strs = [res]
        w_self.until = 1
        return res

    def __repr__(w_self):
        """ representation for debugging purposes """
        return "%s(%r, %r)" % (
            w_self.__class__.__name__, w_self.joined_strs, w_self.until)

    def unwrap(w_self, space):
        return w_self.force()
    str_w = unwrap

registerimplementation(W_StringJoinObject)

def delegate_join2str(space, w_strjoin):
    return wrapstr(space, w_strjoin.force())

def delegate_join2unicode(space, w_strjoin):
    w_str = wrapstr(space, w_strjoin.force())
    return delegate_String2Unicode(space, w_str)

def len__StringJoin(space, w_self):
    result = 0
    for i in range(w_self.until):
        result += len(w_self.joined_strs[i])
    return space.wrap(result)

def add__StringJoin_StringJoin(space, w_self, w_other):
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:31,代码来源:strjoinobject.py

示例15: __init__

    def __init__(w_self, wrappeditems):
        w_self.wrappeditems = wrappeditems

    def __repr__(w_self):
        """ representation for debugging purposes """
        return "%s(%s)" % (w_self.__class__.__name__, w_self.wrappeditems)

    def unwrap(w_list, space):
        items = [space.unwrap(w_item) for w_item in w_list.wrappeditems]# XXX generic mixed types unwrap
        return list(items)

    def append(w_list, w_item):
        w_list.wrappeditems.append(w_item)

registerimplementation(W_ListObject)


init_signature = Signature(['sequence'], None, None)
init_defaults = [None]

def init__List(space, w_list, __args__):
    from pypy.objspace.std.tupleobject import W_TupleObject
    # this is on the silly side
    w_iterable, = __args__.parse_obj(
            None, 'list', init_signature, init_defaults)
    items_w = w_list.wrappeditems
    del items_w[:]
    if w_iterable is not None:
        # unfortunately this is duplicating space.unpackiterable to avoid
        # assigning a new RPython list to 'wrappeditems', which defeats the
开发者ID:gorakhargosh,项目名称:pypy,代码行数:30,代码来源:listobject.py


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