[pypy-svn] r22842 - pypy/branch/genc-gc-refactoring
mwh at codespeak.net
mwh at codespeak.net
Sun Jan 29 15:04:56 CET 2006
Author: mwh
Date: Sun Jan 29 15:04:54 2006
New Revision: 22842
Modified:
pypy/branch/genc-gc-refactoring/funcgen.py
pypy/branch/genc-gc-refactoring/gc.py
Log:
slight cleanups and de-crufting.
Modified: pypy/branch/genc-gc-refactoring/funcgen.py
==============================================================================
--- pypy/branch/genc-gc-refactoring/funcgen.py (original)
+++ pypy/branch/genc-gc-refactoring/funcgen.py Sun Jan 29 15:04:54 2006
@@ -35,6 +35,7 @@
self.functionname = functionname
# apply the gc transformation
self.db.gctransformer.transform_graph(self.graph)
+ #self.graph.show()
self.blocknum = {}
#
@@ -127,13 +128,18 @@
def return_with_error(self):
if self.cpython_exc:
+ # this should most likely be done on the graph level!
lltype_of_exception_value = self.db.get_lltype_of_exception_value()
exc_value_typename = self.db.gettype(lltype_of_exception_value)
assert self.lltypemap(self.graph.getreturnvar()) == PyObjPtr
yield '{'
yield '\t%s;' % cdecl(exc_value_typename, 'vanishing_exc_value')
yield '\tRPyConvertExceptionToCPython(vanishing_exc_value);'
- yield '\t%s' % self.pop_alive_expr('vanishing_exc_value', lltype_of_exception_value)
+ if lltype_of_exception_value == PyObjPtr:
+ yield '\tPy_XDECREF(vanishing_exc_value);'
+ else:
+ yield '\t%s' % self.gcpolicy.pop_alive_nopyobj(
+ 'vanishing_exc_value', lltype_of_exception_value)
yield '}'
yield 'return %s; ' % self.error_return_value()
@@ -231,12 +237,8 @@
d = {}
if isinstance(link.last_exception, Variable):
d[link.last_exception] = 'exc_cls'
- else:
- yield '\t' + self.pop_alive_expr('exc_cls', T1)
if isinstance(link.last_exc_value, Variable):
d[link.last_exc_value] = 'exc_value'
- else:
- yield '\t' + self.pop_alive_expr('exc_value', T2)
for op in self.gen_link(link, d):
yield '\t' + op
yield '}'
@@ -296,19 +298,20 @@
" Got %r" % (TYPE,))
for i, op in list(enumerate(block.operations))[::-1]:
- if not fallthrough:
- yield 'err%d_%d:' % (myblocknum, i)
- else:
- fallthrough = False # this label was already generated
- for cleanupop in getattr(op, 'cleanup', ()):
- line = self.gen_op(cleanupop, 'should_never_be_jumped_to')
- if '\\n' in line:
- for l in line.splitlines():
- yield l
+ if hasattr(op, 'cleanup'):
+ if not fallthrough:
+ yield 'err%d_%d:' % (myblocknum, i)
else:
+ fallthrough = False # this label was already generated
+ for cleanupop in op.cleanup:
+ line = self.gen_op(cleanupop, 'should_never_be_jumped_to')
+ if '\\n' in line:
+ for l in line.splitlines():
+ yield l
+ else:
+ yield line
+ for line in self.return_with_error():
yield line
- for line in self.return_with_error():
- yield line
def gen_link(self, link, linklocalvars=None):
"Generate the code to jump across the given Link."
@@ -412,7 +415,7 @@
result = ['%s = %s;' % (newvalue, sourceexpr)]
# need to adjust the refcount of the result only for PyObjects
if T == PyObjPtr:
- result.append(self.pyobj_incref_expr(newvalue, T))
+ result.append('Py_XINCREF(%s);' % newvalue)
result = '\n'.join(result)
if T is Void:
result = '/* %s */' % result
@@ -555,7 +558,7 @@
self.expr(op.args[0])))
if TYPE == PyObjPtr:
- result.append(self.pyobj_incref(op.result))
+ result.append('Py_XINCREF(%s);'%(LOCAL_VAR % op.result.name))
return '\t'.join(result)
def OP_CAST_INT_TO_PTR(self, op, err):
@@ -572,7 +575,7 @@
result.append('%s = %s;' % (self.expr(op.result),
self.expr(op.args[0])))
if TYPE == PyObjPtr:
- result.append(self.pyobj_incref(op.result))
+ result.append('Py_XINCREF(%s);'%(LOCAL_VAR % op.result.name))
return '\t'.join(result)
def OP_HINT(self, op, err):
@@ -599,19 +602,6 @@
typename = self.db.gettype(TYPE).replace("@", "*") #XXX see above
return "%(result)s = *(((%(typename)s) %(addr)s ) + %(offset)s);" % locals()
- def pyobj_incref(self, v):
- T = self.lltypemap(v)
- return self.pyobj_incref_expr(LOCALVAR % v.name, T)
-
- def pyobj_incref_expr(self, expr, T):
- return self.gcpolicy.pyobj_incref(expr, T)
-
- def pop_alive(self, v, expr=None):
- T = self.lltypemap(v)
- return self.gcpolicy.pop_alive(expr or (LOCALVAR % v.name), T)
-
- def pop_alive_expr(self, expr, T):
- return self.gcpolicy.pop_alive(expr, T)
assert not USESLOTS or '__dict__' not in dir(FunctionCodeGenerator)
Modified: pypy/branch/genc-gc-refactoring/gc.py
==============================================================================
--- pypy/branch/genc-gc-refactoring/gc.py (original)
+++ pypy/branch/genc-gc-refactoring/gc.py Sun Jan 29 15:04:54 2006
@@ -14,10 +14,10 @@
self.db = db
self.thread_enabled = thread_enabled
- def pyobj_incref(self, expr, T):
+ def pyobj_incref(self, expr):
return 'Py_XINCREF(%s);' % expr
- def pyobj_decref(self, expr, T):
+ def pyobj_decref(self, expr):
return 'Py_XDECREF(%s);' % expr
def push_alive(self, expr, T):
@@ -25,7 +25,7 @@
if expr == 'NULL': # hum
return ''
if T.TO == PyObject:
- return self.pyobj_incref(expr, T)
+ return self.pyobj_incref(expr)
else:
return self.push_alive_nopyobj(expr, T)
return ''
@@ -33,7 +33,7 @@
def pop_alive(self, expr, T):
if isinstance(T, Ptr) and T._needsgc():
if T.TO == PyObject:
- return self.pyobj_decref(expr, T)
+ return self.pyobj_decref(expr)
else:
return self.pop_alive_nopyobj(expr, T)
return ''
More information about the Pypy-commit
mailing list