本文整理汇总了Python中pypy.rlib.rarithmetic.r_uint函数的典型用法代码示例。如果您正苦于以下问题:Python r_uint函数的具体用法?Python r_uint怎么用?Python r_uint使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了r_uint函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: fromint
def fromint(intval):
if intval < 0:
sign = -1
ival = r_uint(-intval)
elif intval > 0:
sign = 1
ival = r_uint(intval)
else:
return rbigint()
# Count the number of Python digits.
# We used to pick 5 ("big enough for anything"), but that's a
# waste of time and space given that 5*15 = 75 bits are rarely
# needed.
t = ival
ndigits = 0
while t:
ndigits += 1
t >>= SHIFT
v = rbigint([0] * ndigits, sign)
t = ival
p = 0
while t:
v._setdigit(p, t)
t >>= SHIFT
p += 1
return v
开发者ID:alkorzt,项目名称:pypy,代码行数:26,代码来源:rbigint.py
示例2: min_max_acc_method
def min_max_acc_method(size, signed):
if signed:
min = -(2 ** (8*size-1))
max = (2 ** (8*size-1)) - 1
if size <= native_int_size:
accept_method = 'accept_int_arg'
min = int(min)
max = int(max)
else:
accept_method = 'accept_longlong_arg'
min = r_longlong(min)
max = r_longlong(max)
else:
min = 0
max = (2 ** (8*size)) - 1
if size < native_int_size:
accept_method = 'accept_int_arg'
elif size == native_int_size:
accept_method = 'accept_uint_arg'
min = r_uint(min)
max = r_uint(max)
else:
accept_method = 'accept_ulonglong_arg'
min = r_ulonglong(min)
max = r_ulonglong(max)
return min, max, accept_method
开发者ID:antoine1fr,项目名称:pygirl,代码行数:26,代码来源:standardfmttable.py
示例3: test_unsigned
def test_unsigned(self):
for op, fn in [
("x + y", lambda x, y: x + y),
("x - y", lambda x, y: x - y),
("x * y", lambda x, y: x * y),
("x // y", lambda x, y: x // y),
("x % y", lambda x, y: x % y),
("x << y", lambda x, y: x << y),
("x >> y", lambda x, y: x >> y),
("x ^ y", lambda x, y: x ^ y),
("x & y", lambda x, y: x & y),
("x | y", lambda x, y: x | y),
("-y", lambda x, y: -y),
("~y", lambda x, y: ~y),
]:
fp = self.rgen(fn, [r_uint, r_uint])
print op
fn1 = lambda x, y: fn(r_uint(x), r_uint(y))
fp1 = lambda x, y: r_uint(fp(x, y))
assert fp1(40, 2) == fn1(40, 2)
assert fp1(25, 3) == fn1(25, 3)
assert fp1(40, 2) == fn1(40, 2)
assert fp1(25, 3) == fn1(25, 3)
assert fp1(149, 32) == fn1(149, 32)
assert fp1(149, 33) == fn1(149, 33)
assert fp1(149, 65) == fn1(149, 65)
assert fp1(149, 150) == fn1(149, 150)
big = r_uint(-42)
assert fp1(big, 3) == fn1(big, 3)
if op not in ("x << y", "x >> y"):
assert fp1(38, big) == fn1(38, big)
assert fp1(big - 5, big - 12) == fn1(big - 5, big - 12)
开发者ID:camillobruni,项目名称:pygirl,代码行数:32,代码来源:operation_tests.py
示例4: ll_dict_lookup
def ll_dict_lookup(d, key, hash):
DICT = lltype.typeOf(d).TO
entries = d.entries
mask = len(entries) - 1
i = hash & mask
# do the first try before any looping
if entries.valid(i):
checkingkey = entries[i].key
if checkingkey == key:
return i # found the entry
if d.keyeq is not None and entries.hash(i) == hash:
# correct hash, maybe the key is e.g. a different pointer to
# an equal object
found = d.keyeq(checkingkey, key)
if DICT.paranoia:
if (entries != d.entries or
not entries.valid(i) or entries[i].key != checkingkey):
# the compare did major nasty stuff to the dict: start over
return ll_dict_lookup(d, key, hash)
if found:
return i # found the entry
freeslot = -1
elif entries.everused(i):
freeslot = i
else:
return i # pristine entry -- lookup failed
# In the loop, a deleted entry (everused and not valid) is by far
# (factor of 100s) the least likely outcome, so test for that last.
perturb = r_uint(hash)
while 1:
# compute the next index using unsigned arithmetic
i = r_uint(i)
i = (i << 2) + i + perturb + 1
i = intmask(i) & mask
# keep 'i' as a signed number here, to consistently pass signed
# arguments to the small helper methods.
if not entries.everused(i):
if freeslot == -1:
freeslot = i
return freeslot
elif entries.valid(i):
checkingkey = entries[i].key
if checkingkey == key:
return i
if d.keyeq is not None and entries.hash(i) == hash:
# correct hash, maybe the key is e.g. a different pointer to
# an equal object
found = d.keyeq(checkingkey, key)
if DICT.paranoia:
if (entries != d.entries or
not entries.valid(i) or entries[i].key != checkingkey):
# the compare did major nasty stuff to the dict:
# start over
return ll_dict_lookup(d, key, hash)
if found:
return i # found the entry
elif freeslot == -1:
freeslot = i
perturb >>= PERTURB_SHIFT
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:60,代码来源:rdict.py
示例5: test_uintmask
def test_uintmask(self):
assert rbigint.fromint(-1).uintmask() == r_uint(-1)
assert rbigint.fromint(0).uintmask() == r_uint(0)
assert (rbigint.fromint(sys.maxint).uintmask() ==
r_uint(sys.maxint))
assert (rbigint.fromlong(sys.maxint+1).uintmask() ==
r_uint(-sys.maxint-1))
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:7,代码来源:test_rbigint.py
示例6: wrapint
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)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:29,代码来源:inttype.py
示例7: ll_int2oct
def ll_int2oct(i, addPrefix):
from pypy.rpython.lltypesystem.rstr import mallocstr
if i == 0:
result = mallocstr(1)
result.hash = 0
result.chars[0] = '0'
return result
temp = malloc(CHAR_ARRAY, 25)
len = 0
sign = 0
if i < 0:
sign = 1
i = r_uint(-i)
else:
i = r_uint(i)
while i:
temp[len] = hex_chars[i & 0x7]
i >>= 3
len += 1
len += sign
if addPrefix:
len += 1
result = mallocstr(len)
result.hash = 0
j = 0
if sign:
result.chars[0] = '-'
j = 1
if addPrefix:
result.chars[j] = '0'
j += 1
while j < len:
result.chars[j] = temp[len-j-1]
j += 1
return result
开发者ID:antoine1fr,项目名称:pygirl,代码行数:35,代码来源:ll_str.py
示例8: test_unsigned
def test_unsigned(self):
for op, fn in [('x + y', lambda x, y: x + y),
('x - y', lambda x, y: x - y),
('x * y', lambda x, y: x * y),
('x // y', lambda x, y: x // y),
('x % y', lambda x, y: x % y),
('x << y', lambda x, y: x << y),
('x >> y', lambda x, y: x >> y),
('x ^ y', lambda x, y: x ^ y),
('x & y', lambda x, y: x & y),
('x | y', lambda x, y: x | y),
('-y', lambda x, y: -y),
('~y', lambda x, y: ~y),
]:
fp = self.rgen(fn, [r_uint, r_uint])
print op
fn1 = lambda x, y: fn(r_uint(x), r_uint(y))
fp1 = lambda x, y: r_uint(fp(x, y))
assert fp1(40, 2) == fn1(40, 2)
assert fp1(25, 3) == fn1(25, 3)
assert fp1(40, 2) == fn1(40, 2)
assert fp1(25, 3) == fn1(25, 3)
assert fp1(149, 32) == fn1(149, 32)
assert fp1(149, 33) == fn1(149, 33)
assert fp1(149, 65) == fn1(149, 65)
assert fp1(149, 150) == fn1(149, 150)
big = r_uint(-42)
assert fp1(big, 3) == fn1(big, 3)
if op not in ('x << y', 'x >> y'):
assert fp1(38, big) == fn1(38, big)
assert fp1(big-5, big-12) == fn1(big-5, big-12)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:31,代码来源:operation_tests.py
示例9: ll_int2hex
def ll_int2hex(i, addPrefix):
from pypy.rpython.lltypesystem.rstr import mallocstr
temp = malloc(CHAR_ARRAY, 20)
len = 0
sign = 0
if i < 0:
sign = 1
i = r_uint(-i)
else:
i = r_uint(i)
if i == 0:
len = 1
temp[0] = '0'
else:
while i:
temp[len] = hex_chars[i & 0xf]
i >>= 4
len += 1
len += sign
if addPrefix:
len += 2
result = mallocstr(len)
result.hash = 0
j = 0
if sign:
result.chars[0] = '-'
j = 1
if addPrefix:
result.chars[j] = '0'
result.chars[j+1] = 'x'
j += 2
while j < len:
result.chars[j] = temp[len-j-1]
j += 1
return result
开发者ID:antoine1fr,项目名称:pygirl,代码行数:35,代码来源:ll_str.py
示例10: test_cast_primitive
def test_cast_primitive(self):
from pypy.rpython.annlowlevel import LowLevelAnnotatorPolicy
def llf(u):
return lltype.cast_primitive(lltype.Signed, u)
res = self.interpret(llf, [r_uint(-1)], policy=LowLevelAnnotatorPolicy())
assert res == -1
res = self.interpret(llf, ['x'], policy=LowLevelAnnotatorPolicy())
assert res == ord('x')
def llf(v):
return lltype.cast_primitive(lltype.Unsigned, v)
res = self.interpret(llf, [-1], policy=LowLevelAnnotatorPolicy())
assert res == r_uint(-1)
res = self.interpret(llf, [u'x'], policy=LowLevelAnnotatorPolicy())
assert res == ord(u'x')
res = self.interpret(llf, [1.0], policy=LowLevelAnnotatorPolicy())
assert res == r_uint(1)
def llf(v):
return lltype.cast_primitive(lltype.Char, v)
res = self.interpret(llf, [ord('x')], policy=LowLevelAnnotatorPolicy())
assert res == 'x'
def llf(v):
return lltype.cast_primitive(lltype.UniChar, v)
res = self.interpret(llf, [ord('x')], policy=LowLevelAnnotatorPolicy())
assert res == u'x'
def llf(v):
return lltype.cast_primitive(rffi.SHORT, v)
res = self.interpret(llf, [123], policy=LowLevelAnnotatorPolicy())
assert res == 123
def llf(v):
return lltype.cast_primitive(lltype.Signed, v)
res = self.interpret(llf, [rffi.r_short(123)], policy=LowLevelAnnotatorPolicy())
assert res == 123
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:32,代码来源:test_rbuiltin.py
示例11: _index_cache
def _index_cache(self, selector):
space = self.space
cache = space.fromcache(IndexCache)
SHIFT2 = r_uint.BITS - space.config.objspace.std.methodcachesizeexp
SHIFT1 = SHIFT2 - 5
attrs_as_int = objectmodel.current_object_addr_as_int(self)
# ^^^Note: see comment in typeobject.py for
# _pure_lookup_where_with_method_cache()
hash_selector = objectmodel.compute_hash(selector)
product = intmask(attrs_as_int * hash_selector)
index_hash = (r_uint(product) ^ (r_uint(product) << SHIFT1)) >> SHIFT2
# ^^^Note2: same comment too
cached_attr = cache.attrs[index_hash]
if cached_attr is self:
cached_selector = cache.selectors[index_hash]
if cached_selector == selector:
index = cache.indices[index_hash]
if space.config.objspace.std.withmethodcachecounter:
name = selector[0]
cache.hits[name] = cache.hits.get(name, 0) + 1
return index
index = self._index(selector)
cache.attrs[index_hash] = self
cache.selectors[index_hash] = selector
cache.indices[index_hash] = index
if space.config.objspace.std.withmethodcachecounter:
name = selector[0]
cache.misses[name] = cache.misses.get(name, 0) + 1
return index
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:29,代码来源:mapdict.py
示例12: test_blit_rect
def test_blit_rect(self):
surface = RSDL.CreateRGBSurface(0, 150, 50, 32,
r_uint(0x000000FF),
r_uint(0x0000FF00),
r_uint(0x00FF0000),
r_uint(0xFF000000))
fmt = surface.c_format
color = RSDL.MapRGB(fmt, 255, 0, 0)
RSDL.FillRect(surface, lltype.nullptr(RSDL.Rect), color)
paintrect = RSDL_helper.mallocrect(75, 0, 150, 50)
dstrect = lltype.malloc(RSDL.Rect, flavor='raw')
try:
color = RSDL.MapRGB(fmt, 255, 128, 0)
RSDL.FillRect(surface, paintrect, color)
rffi.setintfield(dstrect, 'c_x', 10)
rffi.setintfield(dstrect, 'c_y', 10)
rffi.setintfield(dstrect, 'c_w', 150)
rffi.setintfield(dstrect, 'c_h', 50)
RSDL.BlitSurface(surface, lltype.nullptr(RSDL.Rect), self.screen, dstrect)
RSDL.Flip(self.screen)
finally:
lltype.free(dstrect, flavor='raw')
lltype.free(paintrect, flavor='raw')
RSDL.FreeSurface(surface)
self.check("Half Red/Orange rectangle(150px * 50px) at the top left, 10 pixels from the border")
开发者ID:ParitoshThapliyal59,项目名称:pypy,代码行数:27,代码来源:test_video.py
示例13: test_invert
def test_invert():
def f(x):
return ~x
res = interpret(f, [3])
assert res == ~3
assert interpret(f, [r_uint(3)]) == ~r_uint(3)
开发者ID:are-prabhu,项目名称:pypy,代码行数:7,代码来源:test_llinterp.py
示例14: ll_int2dec
def ll_int2dec(i):
from pypy.rpython.lltypesystem.rstr import mallocstr
temp = malloc(CHAR_ARRAY, 20)
len = 0
sign = 0
if i < 0:
sign = 1
i = r_uint(-i)
else:
i = r_uint(i)
if i == 0:
len = 1
temp[0] = '0'
else:
while i:
temp[len] = chr(i%10+ord('0'))
i //= 10
len += 1
len += sign
result = mallocstr(len)
result.hash = 0
if sign:
result.chars[0] = '-'
j = 1
else:
j = 0
while j < len:
result.chars[j] = temp[len-j-1]
j += 1
return result
开发者ID:antoine1fr,项目名称:pygirl,代码行数:30,代码来源:ll_str.py
示例15: _GetContents
def _GetContents(self, fp):
endrec = _EndRecData(fp)
if not endrec:
raise BadZipfile, "File is not a zip file"
size_cd = endrec.stuff[5] # bytes in central directory
offset_cd = endrec.stuff[6] # offset of central directory
self.comment = endrec.comment
x = endrec.filesize - size_cd
concat = x - offset_cd
self.start_dir = offset_cd + concat
fp.seek(self.start_dir, 0)
total = 0
while total < size_cd:
centdir = fp.read(46)
total = total + 46
if centdir[0:4] != stringCentralDir:
raise BadZipfile, "Bad magic number for central directory"
centdir = runpack(structCentralDir, centdir)
filename = fp.read(centdir[_CD_FILENAME_LENGTH])
# Create ZipInfo instance to store file information
x = RZipInfo(filename)
x.extra = fp.read(centdir[_CD_EXTRA_FIELD_LENGTH])
x.comment = fp.read(centdir[_CD_COMMENT_LENGTH])
total = (total + centdir[_CD_FILENAME_LENGTH]
+ centdir[_CD_EXTRA_FIELD_LENGTH]
+ centdir[_CD_COMMENT_LENGTH])
x.header_offset = centdir[_CD_LOCAL_HEADER_OFFSET] + concat
# file_offset must be computed below...
(x.create_version, x.create_system, x.extract_version, x.reserved,
x.flag_bits, x.compress_type, t, d,
crc, x.compress_size, x.file_size) = centdir[1:12]
x.CRC = r_uint(crc) & r_uint(0xffffffff)
x.dostime = t
x.dosdate = d
x.volume, x.internal_attr, x.external_attr = centdir[15:18]
# Convert date/time code to (year, month, day, hour, min, sec)
x.date_time = ( (d>>9)+1980, (d>>5)&0xF, d&0x1F,
t>>11, (t>>5)&0x3F, (t&0x1F) * 2 )
self.filelist.append(x)
self.NameToInfo[x.filename] = x
for data in self.filelist:
fp.seek(data.header_offset, 0)
fheader = fp.read(30)
if fheader[0:4] != stringFileHeader:
raise BadZipfile, "Bad magic number for file header"
fheader = runpack(structFileHeader, fheader)
# file_offset is computed here, since the extra field for
# the central directory and for the local file header
# refer to different fields, and they can have different
# lengths
data.file_offset = (data.header_offset + 30
+ fheader[_FH_FILENAME_LENGTH]
+ fheader[_FH_EXTRA_FIELD_LENGTH])
fname = fp.read(fheader[_FH_FILENAME_LENGTH])
if fname != data.orig_filename:
raise BadZipfile, \
'File name in directory "%s" and header "%s" differ.' % (
data.orig_filename, fname)
fp.seek(self.start_dir, 0)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:59,代码来源:rzipfile.py
示例16: f
def f(x):
if x == r_uint(3):
return 9
elif x == r_uint(9):
return 27
elif x == r_uint(27):
return 3
return 0
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:8,代码来源:test_backendoptimized.py
示例17: test_uint_floordiv
def test_uint_floordiv(self):
from pypy.rlib.rarithmetic import r_uint
def f(a, b):
return a/b
res = self.interp_operations(f, [r_uint(4), r_uint(3)])
assert res == 1
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:test_basic.py
示例18: test_crc32
def test_crc32():
"""
When called with a string, rzlib.crc32 should compute its CRC32 and
return it as a unsigned 32 bit integer.
"""
assert rzlib.crc32('') == r_uint(0)
assert rzlib.crc32('\0') == r_uint(3523407757)
assert rzlib.crc32('hello, world.') == r_uint(3358036098)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:8,代码来源:test_rzlib.py
示例19: test_adler32
def test_adler32():
"""
When called with a string, zlib.crc32 should compute its adler 32
checksum and return it as an unsigned 32 bit integer.
"""
assert rzlib.adler32('') == r_uint(1)
assert rzlib.adler32('\0') == r_uint(65537)
assert rzlib.adler32('hello, world.') == r_uint(571147447)
assert rzlib.adler32('x' * 23) == r_uint(2172062409)
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:9,代码来源:test_rzlib.py
示例20: test_unsigned
def test_unsigned(self):
space = self.space
self.check(app_types.uint, space.wrap(42), r_uint(42))
self.check(app_types.uint, space.wrap(-1), r_uint(sys.maxint*2 +1))
self.check(app_types.uint, space.wrap(sys.maxint*3),
r_uint(sys.maxint - 2))
self.check(app_types.ulong, space.wrap(sys.maxint+12),
r_uint(sys.maxint+12))
self.check(app_types.ulong, space.wrap(sys.maxint*2+3), r_uint(1))
开发者ID:Debug-Orz,项目名称:Sypy,代码行数:9,代码来源:test_type_converter.py
注:本文中的pypy.rlib.rarithmetic.r_uint函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论