本文整理汇总了Python中pypy.rpython.lltypesystem.llmemory.cast_adr_to_int函数的典型用法代码示例。如果您正苦于以下问题:Python cast_adr_to_int函数的具体用法?Python cast_adr_to_int怎么用?Python cast_adr_to_int使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cast_adr_to_int函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_force_to_int
def test_force_to_int(self):
S = lltype.Struct('S')
p = lltype.malloc(S, flavor='raw')
a = llmemory.cast_ptr_to_adr(p)
i = llmemory.cast_adr_to_int(a, "forced")
assert type(i) is int
assert i == llmemory.cast_adr_to_int(a, "forced")
lltype.free(p, flavor='raw')
示例2: fn
def fn(n):
a = llmemory.cast_ptr_to_adr(p)
if n == 2:
return llmemory.cast_adr_to_int(a, "emulated")
elif n == 4:
return llmemory.cast_adr_to_int(a, "symbolic")
else:
return llmemory.cast_adr_to_int(a, "forced")
示例3: get_identityhash_from_addr
def get_identityhash_from_addr(self, obj):
if translated_to_c():
return llmemory.cast_adr_to_int(obj) # direct case
else:
try:
adr = llarena.getfakearenaaddress(obj) # -> arena address
except RuntimeError:
return llmemory.cast_adr_to_int(obj) # not in an arena...
return adr - self.space
示例4: test_address_eq_as_int
def test_address_eq_as_int():
a = arena_malloc(50, False)
arena_reserve(a, precomputed_size)
p = llmemory.cast_adr_to_ptr(a, SPTR)
a1 = llmemory.cast_ptr_to_adr(p)
assert a == a1
assert not (a != a1)
assert (a+1) != a1
assert not ((a+1) == a1)
py.test.skip("cast_adr_to_int() is hard to get consistent")
assert llmemory.cast_adr_to_int(a) == llmemory.cast_adr_to_int(a1)
assert llmemory.cast_adr_to_int(a+1) == llmemory.cast_adr_to_int(a1) + 1
示例5: id
def id(self, ptr):
# Default implementation for id(), assuming that "external" objects
# never move. Overriden in the HybridGC.
obj = llmemory.cast_ptr_to_adr(ptr)
# is it a tagged pointer? or an external object?
if not self.is_valid_gc_object(obj) or self._is_external(obj):
return llmemory.cast_adr_to_int(obj)
# tagged pointers have ids of the form 2n + 1
# external objects have ids of the form 4n (due to word alignment)
# self._compute_id returns addresses of the form 2n + 1
# if we multiply by 2, we get ids of the form 4n + 2, thus we get no
# clashes
return llmemory.cast_adr_to_int(self._compute_id(obj)) * 2
示例6: get_address_of_gcref
def get_address_of_gcref(self, gcref):
assert lltype.typeOf(gcref) == llmemory.GCREF
# first look in the hashtable, using an inexact hash (fails after
# the object moves)
addr = llmemory.cast_ptr_to_adr(gcref)
hash = llmemory.cast_adr_to_int(addr)
hash -= hash >> self.HASHTABLE_BITS
hash &= self.HASHTABLE_SIZE - 1
addr_ref = self.hashtable[hash]
# the following test is safe anyway, because the addresses found
# in the hashtable are always the addresses of nonmovable stuff
# ('addr_ref' is an address inside self.list, not directly the
# address of a real moving GC object -- that's 'addr_ref.address[0]'.)
if addr_ref.address[0] == addr:
return addr_ref
# if it fails, add an entry to the list
if self.nextindex == len(self.list):
# reallocate first, increasing a bit the size every time
self.oldlists.append(self.list)
self.list = self.alloc_gcref_list(len(self.list) // 4 * 5)
self.nextindex = 0
# add it
index = self.nextindex
self.list[index] = gcref
addr_ref = lltype.direct_ptradd(lltype.direct_arrayitems(self.list),
index)
addr_ref = llmemory.cast_ptr_to_adr(addr_ref)
self.nextindex = index + 1
# record it in the hashtable
self.hashtable[hash] = addr_ref
return addr_ref
示例7: start_of_page
def start_of_page(addr, page_size):
"""Return the address of the start of the page that contains 'addr'."""
if we_are_translated():
offset = llmemory.cast_adr_to_int(addr) % page_size
return addr - offset
else:
return _start_of_page_untranslated(addr, page_size)
示例8: cast_whatever_to_int
def cast_whatever_to_int(T, value):
if isinstance(T, lltype.Ptr):
return lltype.cast_ptr_to_int(value)
elif T is llmemory.Address:
return llmemory.cast_adr_to_int(value)
else:
return lltype.cast_primitive(lltype.Signed, value)
示例9: identityhash
def identityhash(self, gcobj):
# The following code should run at most twice.
while 1:
obj = llmemory.cast_ptr_to_adr(gcobj)
hdr = self.header(obj)
#
if hdr.tid & GCFLAG_HASHFIELD: # the hash is in a field at the end
obj += self.get_size(obj)
return obj.signed[0]
#
if not (hdr.tid & GCFLAG_HASHTAKEN):
# It's the first time we ask for a hash, and it's not an
# external object. Shrink the top of space by the extra
# hash word that will be needed after a collect.
shrunk_top = self.top_of_space - llmemory.sizeof(lltype.Signed)
if shrunk_top < self.free:
# Cannot shrink! Do a collection, asking for at least
# one word of free space, and try again. May raise
# MemoryError. Obscure: not called directly, but
# across an llop, to make sure that there is the
# correct push_roots/pop_roots around the call...
llop.gc_obtain_free_space(llmemory.Address,
llmemory.sizeof(lltype.Signed))
continue
# Now we can have side-effects: set GCFLAG_HASHTAKEN
# and lower the top of space.
self.top_of_space = shrunk_top
hdr.tid |= GCFLAG_HASHTAKEN
#
return llmemory.cast_adr_to_int(obj) # direct case
示例10: writeobj
def writeobj(self, obj):
gc = self.gc
typeid = gc.get_type_id(obj)
self.write(llmemory.cast_adr_to_int(obj))
self.write(gc.get_member_index(typeid))
self.write(gc.get_size_incl_hash(obj))
gc.trace(obj, self._writeref, None)
self.write(-1)
示例11: identityhash
def identityhash(self, obj):
obj = llmemory.cast_ptr_to_adr(obj)
hdr = self.header(obj)
if ord(hdr.flags) & FL_WITHHASH:
obj += self.get_size(obj)
return obj.signed[0]
else:
return llmemory.cast_adr_to_int(obj)
示例12: id
def id(self, ptr):
# Default implementation for id(), assuming that "external" objects
# never move. Overriden in the HybridGC.
obj = llmemory.cast_ptr_to_adr(ptr)
if self._is_external(obj):
result = obj
else:
result = self._compute_id(obj)
return llmemory.cast_adr_to_int(result)
示例13: cast_adr_to_whatever
def cast_adr_to_whatever(T, addr):
if T is llmemory.Address:
return addr
elif isinstance(T, lltype.Ptr):
return llmemory.cast_adr_to_ptr(addr, T)
elif T is lltype.Signed:
return llmemory.cast_adr_to_int(addr)
else:
assert 0, "XXX not implemented"
示例14: load_now
def load_now(self, asm, loc):
value = llmemory.cast_adr_to_int(self.addr)
if loc.is_register:
assert isinstance(loc, insn.GPR)
asm.load_word(loc.number, value)
else:
#print 'load_now to', loc.offset
asm.load_word(rSCRATCH, value)
asm.stw(rSCRATCH, rFP, loc.offset)
示例15: revealconst
def revealconst(self, T):
if T is llmemory.Address:
return self.addr
elif isinstance(T, lltype.Ptr):
return llmemory.cast_adr_to_ptr(self.addr, T)
elif T is lltype.Signed:
return llmemory.cast_adr_to_int(self.addr)
else:
assert 0, "XXX not implemented"