[pypy-svn] r22795 - pypy/branch/genc-gc-refactoring
cfbolz at codespeak.net
cfbolz at codespeak.net
Sat Jan 28 16:07:44 CET 2006
Author: cfbolz
Date: Sat Jan 28 16:07:42 2006
New Revision: 22795
Modified:
pypy/branch/genc-gc-refactoring/funcgen.py
Log:
(cfbolz, mwh):
generate the correct cleanup code. remove all the incref/pop_alive methods on
the function generator.
Modified: pypy/branch/genc-gc-refactoring/funcgen.py
==============================================================================
--- pypy/branch/genc-gc-refactoring/funcgen.py (original)
+++ pypy/branch/genc-gc-refactoring/funcgen.py Sat Jan 28 16:07:42 2006
@@ -163,26 +163,19 @@
graph = self.graph
# generate the body of each block
- push_alive_op_result = self.gcpolicy.push_alive_op_result
for block in graph.iterblocks():
self.currentblock = block
myblocknum = self.blocknum[block]
yield ''
yield 'block%d:' % myblocknum
- to_release = list(block.inputargs)
- reachable_err = -1 # the number of the first reachable err label
- for op in block.operations:
- err = 'err%d_%d' % (myblocknum, len(to_release))
+ for i, op in enumerate(block.operations):
+ err = 'err%d_%d' % (myblocknum, i)
line = self.gen_op(op, err)
if '\n' in line:
- for subline in line.split('\n'):
+ for subline in line.splitlines():
yield subline
else:
yield line
- if line.find(err) >= 0:
- reachable_err = len(to_release)
- to_release.append(op.result)
-
fallthrough = False
if len(block.exits) == 0:
if len(block.inputargs) == 2: # exc_cls, exc_value
@@ -200,7 +193,7 @@
elif block.exitswitch is None:
# single-exit block
assert len(block.exits) == 1
- for op in self.gen_link(block.exits[0], to_release):
+ for op in self.gen_link(block.exits[0]):
yield op
yield ''
elif block.exitswitch == c_last_exception:
@@ -208,14 +201,12 @@
# we handle the non-exceptional case first
link = block.exits[0]
assert link.exitcase is None
- for op in self.gen_link(link, to_release):
+ for op in self.gen_link(link):
yield op
# we must catch the exception raised by the last operation,
# which goes to the last err%d_%d label written above.
yield ''
- to_release.pop() # skip default error handling for this label
- yield 'err%d_%d:' % (myblocknum, len(to_release))
- reachable_err = len(to_release) # XXX assert they are == ?
+ yield 'err%d_%d:' % (myblocknum, len(block.operations) - 1)
yield ''
for link in block.exits[1:]:
assert issubclass(link.exitcase, Exception)
@@ -246,7 +237,7 @@
d[link.last_exc_value] = 'exc_value'
else:
yield '\t' + self.pop_alive_expr('exc_value', T2)
- for op in self.gen_link(link, to_release, d):
+ for op in self.gen_link(link, d):
yield '\t' + op
yield '}'
fallthrough = True
@@ -268,14 +259,14 @@
else:
expr = '%s == Py_False' % expr
yield 'if (%s) {' % expr
- for op in self.gen_link(link, to_release):
+ for op in self.gen_link(link):
yield '\t' + op
yield '}'
link = block.exits[-1]
assert link.exitcase in (False, True)
#yield 'assert(%s == %s);' % (self.expr(block.exitswitch),
# self.genc.nameofvalue(link.exitcase, ct))
- for op in self.gen_link(block.exits[-1], to_release):
+ for op in self.gen_link(block.exits[-1]):
yield op
yield ''
elif TYPE in (Signed, Unsigned, SignedLongLong,
@@ -288,7 +279,7 @@
defaultlink = link
continue
yield 'case %s:' % self.db.get(link.llexitcase)
- for op in self.gen_link(link, to_release):
+ for op in self.gen_link(link):
yield '\t' + op
yield 'break;'
@@ -296,7 +287,7 @@
if defaultlink is None:
raise TypeError('switches must have a default case.')
yield 'default:'
- for op in self.gen_link(defaultlink, to_release):
+ for op in self.gen_link(defaultlink):
yield '\t' + op
yield '}'
@@ -304,23 +295,25 @@
raise TypeError("exitswitch type not supported"
" Got %r" % (TYPE,))
- for i in range(reachable_err, -1, -1):
+ 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
- if i == 0:
- for line in self.return_with_error():
+ 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
+ else:
yield line
- else:
- yield self.pop_alive(to_release[i-1])
+ for line in self.return_with_error():
+ yield line
- def gen_link(self, link, to_release, linklocalvars=None):
+ def gen_link(self, link, linklocalvars=None):
"Generate the code to jump across the given Link."
is_alive = {}
linklocalvars = linklocalvars or {}
- for v in to_release:
- linklocalvars[v] = self.expr(v)
assignments = []
for a1, a2 in zip(link.args, link.target.inputargs):
a2type, a2typename = self.lltypes[id(a2)]
@@ -613,13 +606,6 @@
def pyobj_incref_expr(self, expr, T):
return self.gcpolicy.pyobj_incref(expr, T)
- def pyobj_decref_expr(self, expr, T):
- return self.gcpolicy.pyobj_decref(expr, T)
-
- def push_alive(self, v):
- T = self.lltypemap(v)
- return self.gcpolicy.push_alive(LOCALVAR % v.name, T)
-
def pop_alive(self, v, expr=None):
T = self.lltypemap(v)
return self.gcpolicy.pop_alive(expr or (LOCALVAR % v.name), T)
More information about the Pypy-commit
mailing list