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


Python space.unwind函数代码示例

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


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

示例1: Integer_to_string

def Integer_to_string(integer, base):
    base = 10 if base is None else base.value
    if base >= len(digits):
        raise space.unwind(space.LError(u"not enough digits to represent this base %d" % base))
    if base < 0:
        raise space.unwind(space.LError(u"negative base not supported"))
    return space.String(integer_to_string(integer.value, base))
开发者ID:cheery,项目名称:lever,代码行数:7,代码来源:numbers.py

示例2: setitem

 def setitem(self, index, value):
     if not isinstance(index, Integer):
         raise space.unwind(space.LTypeError(u"index not an integer"))
     if not 0 <= index.value < len(self.contents):
         raise space.unwind(space.LKeyError(self, index))
     self.contents[index.value] = value
     return value
开发者ID:pombredanne,项目名称:lever,代码行数:7,代码来源:listobject.py

示例3: cast

def cast(x, cls, info=u"something"):
    if isinstance(x, cls): # This here means that cast won't change object
        return x           # if it is already correct type.
    try:
        fn = cast_methods[cls]
    except KeyError as _:
        raise space.unwind(space.LTypeError(u"expected %s is %s, got %s" % (
            info, cls.interface.name, x.repr())))
    res = fn(x)
    if isinstance(res, cls):
        return res
    # TODO: Consider alternative ways to say it. :)
    raise space.unwind(space.LTypeError(u"implicit conversion of %s at %s into %s returned %s" % (
        x.repr(), info, cls.interface.name, res.repr())))
开发者ID:cheery,项目名称:lever,代码行数:14,代码来源:interface.py

示例4: setitem

 def setitem(self, index, value):
     # TODO: Add slice support to this side.
     index = space.cast(index, Integer, u"index not an integer")
     if not 0 <= index.value < len(self.contents):
         raise space.unwind(space.LKeyError(self, index))
     self.contents[index.value] = value
     return value
开发者ID:cheery,项目名称:lever,代码行数:7,代码来源:listobject.py

示例5: call

 def call(self, argv):
     varargs = self.function.flags & 1 == 1
     argc = self.function.argc
     topc = self.function.topc
     L = len(argv)
     if L < argc:
         # The pc=0 refers to the function itself. This entry
         # is really helpful when trying to determine the origin of a CallError.
         head_entry = TraceEntry(rffi.r_long(0),
             self.function.unit.sources,
             self.function.sourcemap, self.function.unit.path)
         unwinder = space.unwind(space.LCallError(argc, topc, varargs, L))
         unwinder.traceback.contents.append(head_entry)
         raise unwinder
     # We are using this trait.
     #if L > topc and not varargs:
     #    raise space.Error(u"too many arguments [%d], from %d to %d arguments allowed" % (L, argc, topc))
     frame = Frame(self.function, self.frame.module, self.frame)
     for i in range(min(topc, L)):
         frame.local[i] = argv[i]
     if varargs:
         frame.local[topc] = space.List(argv[min(topc, L):])
     regv = new_register_array(self.function.regc)
     if self.function.flags & 2 != 0:
         return Generator(0, self.function.block, regv, frame)
     else:
         return interpret(0, self.function.block, regv, frame)
开发者ID:cheery,项目名称:lever,代码行数:27,代码来源:loader.py

示例6: from_object

def from_object(obj):
    if as_i(obj.getitem(space.String(u"version"))) != 0:
        raise space.unwind(space.LError(u"bytecode version=0 required"))

    sources = as_list(obj.getitem(space.String(u"sources")))
    constants = as_list(obj.getitem(space.String(u"constants")))

    functions = []
    for function_list in as_list(obj.getitem(space.String(u"functions"))):
        flags = as_i( function_list.getitem(space.String(u"flags")))
        regc = as_i( function_list.getitem(space.String(u"regc")))
        argc = rffi.r_ulong(as_i( function_list.getitem(space.String(u"argc"))))
        topc = rffi.r_ulong(as_i( function_list.getitem(space.String(u"topc"))))
        localc = as_i( function_list.getitem(space.String(u"localc")))
        block_list = as_u8a(function_list.getitem(space.String(u"code")))
        sourcemap = function_list.getitem(space.String(u"sourcemap"))
        exc_table = as_list(function_list.getitem(space.String(u"exceptions")))
        block = lltype.malloc(u16_array, block_list.length/2)
        for i in range(block_list.length/2):
            a = rffi.r_long(block_list.uint8data[i*2+0])
            b = rffi.r_long(block_list.uint8data[i*2+1])
            block[i] = rffi.r_ushort((a << 8) | b)
        excs = []
        for n in exc_table:
            excs.append(Exc(
                rffi.r_ulong(as_i(n.getitem(space.Integer(0)))),
                rffi.r_ulong(as_i(n.getitem(space.Integer(1)))),
                rffi.r_ulong(as_i(n.getitem(space.Integer(2)))),
                rffi.r_ulong(as_i(n.getitem(space.Integer(3)))),
            ))
        functions.append(Function(flags, regc, argc, topc, localc, block, sourcemap, excs[:]))
    return Program(Unit(constants[:], functions[:], sources[:]))
开发者ID:pombredanne,项目名称:lever,代码行数:32,代码来源:loader.py

示例7: setitem

 def setitem(self, index, value):
     index = space.cast(index, numbers.Integer, u"index not an integer")
     if not 0 <= index.value < self.length:
         raise space.unwind(space.LKeyError(self, index))
     value = space.cast(value, numbers.Integer, u"value not an integer")
     self.uint8data[index.value] = rffi.r_uchar(value.value)
     return value
开发者ID:cheery,项目名称:lever,代码行数:7,代码来源:uint8array.py

示例8: List_pop

def List_pop(self, index):
    if index:
        index = index.value
    else:
        index = len(self.contents) - 1
    if not 0 <= index < len(self.contents):
        raise space.unwind(space.LKeyError(self, space.Integer(index)))
    return self.contents.pop(index)
开发者ID:cheery,项目名称:lever,代码行数:8,代码来源:listobject.py

示例9: sizeof_a

def sizeof_a(tp, n):
    assert isinstance(tp, Type)
    if tp.size == 0 or tp.align == 0:
        raise unwind(LTypeError(u"cannot determine size of opaque type"))
    if tp.parameter is not None:
        return tp.size + sizeof(tp.parameter)*n
    else:
        return tp.size * n
开发者ID:cheery,项目名称:lever,代码行数:8,代码来源:simple.py

示例10: store

 def store(self, pool, offset, value):
     for rtype in signed_types:
         if self.size == rffi.sizeof(rtype):
             pnt = rffi.cast(rffi.CArrayPtr(rtype), offset)
             pnt[0] = rffi.cast(rtype, to_int(value))
             break
     else:
         raise unwind(LTypeError(u"undefined ffi type: %s" % self.repr()))
     return value
开发者ID:cheery,项目名称:lever,代码行数:9,代码来源:simple.py

示例11: call

 def call(self, argv):
     if len(argv) != 1:
         raise space.unwind(space.LCallError(1, 1, False, len(argv)))
     module = argv[0]
     assert isinstance(module, space.Module)
     entry = self.unit.functions[0]
     frame = Frame(entry, module, None)
     regv = new_register_array(entry.regc)
     return interpret(0, entry.block, regv, frame)
开发者ID:pombredanne,项目名称:lever,代码行数:9,代码来源:loader.py

示例12: getitem

 def getitem(self, index):
     if isinstance(index, space.Slice):
         start, stop, step = index.clamped(0, len(self.contents))
         result = []
         for i in range(start, stop, step):
             result.append(self.contents[i])
         return List(result)
     index = space.cast(index, Integer, u"index not an integer")
     if not 0 <= index.value < len(self.contents):
         raise space.unwind(space.LKeyError(self, index))
     return self.contents[index.value]
开发者ID:cheery,项目名称:lever,代码行数:11,代码来源:listobject.py

示例13: getitem

 def getitem(self, index):
     if isinstance(index, space.Slice):
         result = []
         start, stop, step = index.clamped(0, len(self.string))
         for i in range(start, stop, step):
             result.append(self.string[i])
         return String(u"".join(result))
     index = space.cast(index, numbers.Integer, u"index not an integer")
     if not 0 <= index.value < len(self.string):
         raise space.unwind(space.LKeyError(self, index))
     return String(self.string[index.value])
开发者ID:cheery,项目名称:lever,代码行数:11,代码来源:string.py

示例14: to_float

def to_float(obj):
    if isinstance(obj, Float):
        return obj.number
    elif isinstance(obj, Integer):
        return float(obj.value)
    elif isinstance(obj, Boolean):
        if is_true(obj):
            return 1.0
        else:
            return 0.0
    else:
        raise space.unwind(space.LTypeError(u"expected float value"))
开发者ID:cheery,项目名称:lever,代码行数:12,代码来源:numbers.py

示例15: to_int

def to_int(obj):
    if isinstance(obj, Float):
        return int(obj.number)
    elif isinstance(obj, Integer):
        return obj.value
    elif isinstance(obj, Boolean):
        if is_true(obj):
            return 1
        else:
            return 0
    else:
        raise space.unwind(space.LTypeError(u"expected int value"))
开发者ID:cheery,项目名称:lever,代码行数:12,代码来源:numbers.py


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