[pypy-svn] r23128 - in pypy/branch/genc-gc-refactoring: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Tue Feb 7 23:23:45 CET 2006
Author: cfbolz
Date: Tue Feb 7 23:23:45 2006
New Revision: 23128
Modified:
pypy/branch/genc-gc-refactoring/gc.py
pypy/branch/genc-gc-refactoring/test/test_backendoptimized.py
Log:
(cfbolz, pedronis around)
intermediate checkin: remove most of the old string templated gc code. tests
are broken, though :-(
Modified: pypy/branch/genc-gc-refactoring/gc.py
==============================================================================
--- pypy/branch/genc-gc-refactoring/gc.py (original)
+++ pypy/branch/genc-gc-refactoring/gc.py Tue Feb 7 23:23:45 2006
@@ -5,6 +5,7 @@
typeOf, Ptr, PyObject, ContainerType, GcArray, GcStruct, \
RuntimeTypeInfo, getRuntimeTypeInfo
from pypy.rpython.memory import gctransform
+from pypy.rpython.lltypesystem import lltype, llmemory
PyObjPtr = Ptr(PyObject)
@@ -105,21 +106,6 @@
return self.push_alive(expr, T)
return ''
- def generic_dealloc(self, expr, T):
- db = self.db
- if isinstance(T, Ptr) and T._needsgc():
- line = self.pop_alive(expr, T)
- if line:
- yield line
- elif isinstance(T, ContainerType):
- defnode = db.gettypedefnode(T)
- from pypy.translator.c.node import ExtTypeOpaqueDefNode
- if isinstance(defnode, ExtTypeOpaqueDefNode):
- yield 'RPyOpaqueDealloc_%s(&(%s));' % (defnode.T.tag, expr)
- else:
- for line in defnode.visitor_lines(expr, self.generic_dealloc):
- yield line
-
def gcheader_field_name(self, defnode):
return 'refcount'
@@ -127,133 +113,44 @@
return 'long refcount;'
def common_after_definition(self, defnode):
- if defnode.gcinfo:
- gcinfo = defnode.gcinfo
- if gcinfo.deallocator:
- yield 'void %s(struct %s *);' % (gcinfo.deallocator, defnode.name)
- if defnode.gcheader is not None:
- dealloc = 'OP_FREE'
- if defnode.gcinfo:
- dealloc = defnode.gcinfo.deallocator or dealloc
- yield '#define pypy_IncRf_%s(x) if (x) (x)->%s++' % (
- defnode.barename, defnode.gcheader,)
- yield '#define pypy_DecRf_%s(x) if ((x) && !--(x)->%s) %s(x)' % (
- defnode.barename, defnode.gcheader, dealloc)
+ return ''
def common_gcheader_initializationexpr(self, defnode):
return 'REFCOUNT_IMMORTAL,'
- def deallocator_lines(self, defnode, prefix):
- return defnode.visitor_lines(prefix, self.generic_dealloc)
-
# for structs
- def prepare_nested_gcstruct(self, structdefnode, INNER):
- # check here that there is enough run-time type information to
- # handle this case
- getRuntimeTypeInfo(structdefnode.STRUCT)
- getRuntimeTypeInfo(INNER)
-
def struct_setup(self, structdefnode, rtti):
- if structdefnode.gcheader:
- db = self.db
- gcinfo = structdefnode.gcinfo = RefcountingInfo()
-
- gcinfo.deallocator = db.namespace.uniquename('dealloc_'+structdefnode.barename)
-
- # are two deallocators needed (a dynamic one for DECREF, which checks
- # the real type of the structure and calls the static deallocator) ?
- if rtti is not None:
- gcinfo.static_deallocator = db.namespace.uniquename(
- 'staticdealloc_'+structdefnode.barename)
- fnptr = rtti._obj.query_funcptr
- if fnptr is None:
- raise NotImplementedError(
- "attachRuntimeTypeInfo(): please provide a function")
- gcinfo.rtti_query_funcptr = db.get(fnptr)
- T = typeOf(fnptr).TO.ARGS[0]
- gcinfo.rtti_query_funcptr_argtype = db.gettype(T)
- if hasattr(rtti._obj, 'destructor_funcptr'):
- destrptr = rtti._obj.destructor_funcptr
- gcinfo.destructor = db.get(destrptr)
- T = typeOf(destrptr).TO.ARGS[0]
- gcinfo.destructor_argtype = db.gettype(T)
- else:
- # is a deallocator really needed, or would it be empty?
- if list(self.deallocator_lines(structdefnode, '')):
- gcinfo.static_deallocator = gcinfo.deallocator
- else:
- gcinfo.deallocator = None
+ if rtti is not None:
+ transformer = structdefnode.db.gctransformer
+ graph = transformer.static_deallocation_graph_for_type(structdefnode.STRUCT)
+ # XXX come up with a nicer interface in gctransformer
+ structdefnode.db.translator.rtyper.specialize_more_blocks()
+ FUNCTYPE = lltype.FuncType([llmemory.Address], lltype.Void)
+ fptr = lltype.functionptr(FUNCTYPE, graph.name, graph=graph)
+ structdefnode.gcinfo = RefcountingInfo()
+ structdefnode.gcinfo.static_deallocator = structdefnode.db.get(fptr)
struct_gcheader_definition = common_gcheader_definition
struct_after_definition = common_after_definition
def struct_implementationcode(self, structdefnode):
- if structdefnode.gcinfo:
- gcinfo = structdefnode.gcinfo
- has_dynamic_deallocator = gcinfo.deallocator and gcinfo.deallocator != gcinfo.static_deallocator
- if gcinfo.static_deallocator and not has_dynamic_deallocator:
- yield 'void %s(struct %s *p) {' % (gcinfo.static_deallocator,
- structdefnode.name)
- # insert decrefs to objects we have a reference to
- for line in self.deallocator_lines(structdefnode, '(*p)'):
- yield '\t' + line
- yield '\tOP_FREE(p);'
- yield '}'
- elif has_dynamic_deallocator:
- # write static deallocator
- yield 'void %s(struct %s *p) {' % (gcinfo.static_deallocator,
- structdefnode.name)
- # insert call to __del__ if necessary
- if gcinfo.destructor:
- yield "\t%s((%s) p);" % (gcinfo.destructor,
- cdecl(gcinfo.destructor_argtype, ''))
- # decref the refcount. if it is zero (e.g. the object was not
- # resurrected by the __del__), decref all objects we have a
- # reference to
- yield '\tif (!--p->%s) {' % (structdefnode.gcheader,)
- for line in self.deallocator_lines(structdefnode, '(*p)'):
- yield '\t\t' + line
- yield '\t\tOP_FREE(p);'
- yield '\t}'
- yield '}'
-
- # write dynamic deallocator
- yield 'void %s(struct %s *p) {' % (gcinfo.deallocator, structdefnode.name)
- yield '\tvoid (*staticdealloc) (void *);'
- # the refcount should be 0; temporarily bump it to 1
- yield '\tp->%s = 1;' % (structdefnode.gcheader,)
- # cast 'p' to the type expected by the rtti_query function
- yield '\tstaticdealloc = %s((%s) p);' % (
- gcinfo.rtti_query_funcptr,
- cdecl(gcinfo.rtti_query_funcptr_argtype, ''))
- yield '\tstaticdealloc(p);'
- yield '}'
-
+ yield ""
struct_gcheader_initializationexpr = common_gcheader_initializationexpr
# for arrays
def array_setup(self, arraydefnode):
- if arraydefnode.gcheader and list(self.deallocator_lines(arraydefnode, '')):
- gcinfo = arraydefnode.gcinfo = RefcountingInfo()
- gcinfo.deallocator = self.db.namespace.uniquename('dealloc_'+arraydefnode.barename)
+ pass
array_gcheader_definition = common_gcheader_definition
array_after_definition = common_after_definition
def array_implementationcode(self, arraydefnode):
- if arraydefnode.gcinfo:
- gcinfo = arraydefnode.gcinfo
- if gcinfo.deallocator:
- yield 'void %s(struct %s *a) {' % (gcinfo.deallocator, arraydefnode.name)
- for line in self.deallocator_lines(arraydefnode, '(*a)'):
- yield '\t' + line
- yield '\tOP_FREE(a);'
- yield '}'
+ yield ""
array_gcheader_initializationexpr = common_gcheader_initializationexpr
@@ -305,8 +202,7 @@
self.T = T
self.obj = obj
defnode = db.gettypedefnode(obj.about)
- self.implementationtypename = 'void (@)(struct %s *)' % (
- defnode.name,)
+ self.implementationtypename = 'void (@)(void *)'
self.name = defnode.gcinfo.static_deallocator
self.ptrname = '((void (*)(void *)) %s)' % (self.name,)
@@ -321,6 +217,7 @@
class BoehmInfo:
finalizer = None
+"""
class BoehmGcPolicy(BasicGcPolicy):
generic_dealloc = RefcountingGcPolicy.generic_dealloc.im_func
@@ -470,3 +367,4 @@
def struct_implementationcode(self, structdefnode):
return []
array_implementationcode = struct_implementationcode
+"""
Modified: pypy/branch/genc-gc-refactoring/test/test_backendoptimized.py
==============================================================================
--- pypy/branch/genc-gc-refactoring/test/test_backendoptimized.py (original)
+++ pypy/branch/genc-gc-refactoring/test/test_backendoptimized.py Tue Feb 7 23:23:45 2006
@@ -3,6 +3,7 @@
from pypy.translator.backendopt.all import backend_optimizations
from pypy.rpython import objectmodel
from pypy.rpython.rarithmetic import r_uint, r_longlong, r_ulonglong
+from pypy import conftest
class TestTypedOptimizedTestCase(_TestTypedTestCase):
@@ -10,6 +11,8 @@
_TestTypedTestCase.process(self, t)
self.t = t
backend_optimizations(t, merge_if_blocks_to_switch=False)
+ if conftest.option.view:
+ t.view()
def test_remove_same_as(self):
def f(n=bool):
More information about the Pypy-commit
mailing list