예제 #1
0
파일: inttype.py 프로젝트: njues/Sypy
def wrapint(space, x, w_symbolic=False, w_s=''):
    if space.config.objspace.std.withsmallint:
        from pypy.objspace.std.smallintobject import W_SmallIntObject
        try:
            return W_SmallIntObject(x)
        except OverflowError:
            from pypy.objspace.std.intobject import W_IntObject
            return W_IntObject(x, w_symbolic, w_s)
    elif space.config.objspace.std.withprebuiltint:
        from pypy.objspace.std.intobject import W_IntObject
        lower = space.config.objspace.std.prebuiltintfrom
        upper =  space.config.objspace.std.prebuiltintto
        # use r_uint to perform a single comparison (this whole function
        # is getting inlined into every caller so keeping the branching
        # to a minimum is a good idea)
        index = r_uint(x - lower)
        if index >= r_uint(upper - lower):
            w_res = instantiate(W_IntObject)
        else:
            w_res = W_IntObject.PREBUILT[index]
        # obscure hack to help the CPU cache: we store 'x' even into
        # a prebuilt integer's intval.  This makes sure that the intval
        # field is present in the cache in the common case where it is
        # quickly reused.  (we could use a prefetch hint if we had that)
        w_res.intval = x
        return w_res
    else:
        from pypy.objspace.std.intobject import W_IntObject
        return W_IntObject(x, w_symbolic, w_s)
예제 #2
0
def delegate_Bool2IntObject(space, w_bool):
    return W_IntObject(int(w_bool.boolval))
예제 #3
0
def delegate_SmallInt2Int(space, w_small):
    return W_IntObject(w_small.intval)