[pypy-svn] r27259 - in pypy/dist/pypy/rpython/lltypesystem: . test
pedronis at codespeak.net
pedronis at codespeak.net
Tue May 16 02:41:45 CEST 2006
Author: pedronis
Date: Tue May 16 02:41:41 2006
New Revision: 27259
Modified:
pypy/dist/pypy/rpython/lltypesystem/llmemory.py
pypy/dist/pypy/rpython/lltypesystem/test/test_llmemory.py
Log:
start experimenting with primitives bump and arena to express copy collectors such that they can be run
without the simulator.
Modified: pypy/dist/pypy/rpython/lltypesystem/llmemory.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/llmemory.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/llmemory.py Tue May 16 02:41:41 2006
@@ -480,3 +480,49 @@
from pypy.rpython.memory.lltypelayout import convert_offset_to_int
size = convert_offset_to_int(size)
return size
+
+# ____________________________________________________________
+
+class _arena(object):
+
+ def __init__(self, rng):
+ self.rng = rng
+ self.items = []
+
+class ArenaItem(AddressOffset):
+
+ def __init__(self, nr):
+ self.nr = nr
+
+ def ref(self, ref):
+ assert isinstance(ref, _obref)
+ assert isinstance(ref.ob, _arena)
+ arena = ref.ob
+ itemadr = arena.items[self.nr]
+ return itemadr.ref()
+
+class ArenaRange(AddressOffset):
+ def __init__(self, unitsize, n):
+ self.unitsize = unitsize
+ self.n = n
+
+ def raw_malloc(self, rest):
+ assert not rest
+ return fakeaddress(_arena(self), ArenaItem(0))
+
+def arena(TYPE, n):
+ return ArenaRange(sizeof(TYPE), n)
+
+def bump(adr, size):
+ assert isinstance(adr.ob, _arena)
+ assert isinstance(adr.offset, ArenaItem)
+ arena = adr.ob
+ nr = adr.offset.nr
+ if len(arena.items) == nr: # reserve
+ # xxx check that we are not larger than unitsize*n
+ itemadr = raw_malloc(size)
+ arena.items.append(itemadr)
+ else:
+ assert nr < len(arena.items)
+ # xxx check that size matches
+ return fakeaddress(arena, ArenaItem(nr+1))
Modified: pypy/dist/pypy/rpython/lltypesystem/test/test_llmemory.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/test/test_llmemory.py (original)
+++ pypy/dist/pypy/rpython/lltypesystem/test/test_llmemory.py Tue May 16 02:41:41 2006
@@ -282,3 +282,23 @@
assert p.y[7] == 18187
py.test.raises(IndexError,
"(adr + offsetof(S, 'y') + itemoffsetof(A, 10)).signed[0]")
+
+def test_arena_bump_ptr():
+ S = lltype.Struct('S', ('x',lltype.Signed))
+ SPTR = lltype.Ptr(S)
+ badr = start = raw_malloc(arena(S, 4))
+ s_adr = badr
+ badr = bump(badr, sizeof(S))
+ s_ptr = cast_adr_to_ptr(s_adr, SPTR)
+ s_ptr.x = 1
+ s2_adr = badr
+ badr = bump(badr, sizeof(S))
+ s2_ptr = cast_adr_to_ptr(s2_adr, SPTR)
+ s2_ptr.x = 2
+ badr = start
+ s_ptr = cast_adr_to_ptr(badr, SPTR)
+ assert s_ptr.x == 1
+ badr = bump(badr, sizeof(S))
+ s2_ptr = cast_adr_to_ptr(badr, SPTR)
+ assert s2_ptr.x == 2
+ # release(start)
More information about the Pypy-commit
mailing list