[pypy-svn] r22755 - in pypy/dist/pypy/translator/c: . test
mwh at codespeak.net
mwh at codespeak.net
Fri Jan 27 19:37:11 CET 2006
Author: mwh
Date: Fri Jan 27 19:37:09 2006
New Revision: 22755
Modified:
pypy/dist/pypy/translator/c/newfuncgen.py
pypy/dist/pypy/translator/c/newgc.py
pypy/dist/pypy/translator/c/test/test_newgc.py
Log:
(cfbolz,mwh)
First hacks towards using the new gc related operation.
Modified: pypy/dist/pypy/translator/c/newfuncgen.py
==============================================================================
--- pypy/dist/pypy/translator/c/newfuncgen.py (original)
+++ pypy/dist/pypy/translator/c/newfuncgen.py Fri Jan 27 19:37:09 2006
@@ -171,9 +171,7 @@
linklocalvars = linklocalvars or {}
for v in to_release:
linklocalvars[v] = self.expr(v)
- is_alive_and_dies = linklocalvars.copy()
assignments = []
- multiple_times_alive = []
for a1, a2 in zip(link.args, link.target.inputargs):
a2type, a2typename = self.lltypes[id(a2)]
if a2type is Void:
@@ -184,25 +182,8 @@
src = self.expr(a1)
dest = LOCALVAR % a2.name
assignments.append((a2typename, dest, src))
- if a1 in is_alive_and_dies:
- del is_alive_and_dies[a1]
- else:
- #assert self.lltypemap(a1) == self.lltypemap(a2)
- multiple_times_alive.append(a2)
- # warning, the order below is delicate to get right:
- # 1. forget the old variables that are not passed over
- for v in is_alive_and_dies:
- line = self.pop_alive(v, linklocalvars[v])
- if line:
- yield line
- # 2. perform the assignments with collision-avoidance
for line in gen_assignments(assignments):
yield line
- # 3. keep alive the new variables if needed
- for a2 in multiple_times_alive:
- line = self.push_alive(a2)
- if line:
- yield line
yield 'goto block%d;' % blocknum[link.target]
# collect all blocks
@@ -226,11 +207,13 @@
macro = 'OP_%s' % op.opname.upper()
if op.opname.startswith('gc_'):
meth = getattr(self.gcpolicy, macro, None)
+ if meth:
+ line = meth(self, op, err)
else:
meth = getattr(self, macro, None)
- if meth:
- line = meth(op, err)
- else:
+ if meth:
+ line = meth(op, err)
+ if meth is None:
lst = [self.expr(v) for v in op.args]
lst.append(self.expr(op.result))
lst.append(err)
@@ -244,13 +227,6 @@
reachable_err = len(to_release)
to_release.append(op.result)
- T = self.lltypemap(op.result)
- if T is not Void:
- res = LOCALVAR % op.result.name
- line = push_alive_op_result(op.opname, res, T)
- if line:
- yield line
-
fallthrough = False
if len(block.exits) == 0:
if len(block.inputargs) == 2: # exc_cls, exc_value
Modified: pypy/dist/pypy/translator/c/newgc.py
==============================================================================
--- pypy/dist/pypy/translator/c/newgc.py (original)
+++ pypy/dist/pypy/translator/c/newgc.py Fri Jan 27 19:37:09 2006
@@ -283,6 +283,27 @@
eresult,
err)
+ def OP_GC_PUSH_ALIVE(self, funcgen, op, err):
+ expr = funcgen.expr(op.args[0])
+ defnode = self.db.gettypedefnode(op.args[0].concretetype.TO)
+ assert defnode.gcheader is not None
+ return 'pypy_IncRf_%s(%s);' % (defnode.barename, expr)
+
+ def OP_GC_POP_ALIVE(self, funcgen, op, err):
+ expr = funcgen.expr(op.args[0])
+ defnode = self.db.gettypedefnode(op.args[0].concretetype.TO)
+ assert defnode.gcheader is not None
+ return 'pypy_DecRf_%s(%s);' % (defnode.barename, expr)
+
+ def OP_GC_PUSH_ALIVE_PYOBJ(self, funcgen, op, err):
+ expr = funcgen.expr(op.args[0])
+ return 'Py_XINCREF(%s);' % expr
+
+ def OP_GC_POP_ALIVE_PYOBJ(self, funcgen, op, err):
+ expr = funcgen.expr(op.args[0])
+ return 'Py_XDECREF(%s);' % expr
+
+
class RefcountingRuntimeTypeInfo_OpaqueNode(ContainerNode):
nodekind = 'refcnt rtti'
globalcontainer = True
Modified: pypy/dist/pypy/translator/c/test/test_newgc.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_newgc.py (original)
+++ pypy/dist/pypy/translator/c/test/test_newgc.py Fri Jan 27 19:37:09 2006
@@ -6,6 +6,7 @@
from pypy.translator.tool.cbuild import skip_missing_compiler
from pypy.translator.translator import TranslationContext
from pypy.translator.c import genc, newgc
+from pypy.rpython.lltypesystem import lltype
from pypy.rpython.memory.gctransform import GCTransformer
@@ -13,7 +14,7 @@
t = TranslationContext()
t.buildannotator().build_types(fn, inputtypes)
t.buildrtyper().specialize()
-# GCTransformer(t.graphs).transform()
+ GCTransformer(t.graphs).transform()
builder = genc.CExtModuleBuilder(t, fn, use_new_funcgen=True,
gcpolicy=newgc.RefcountingGcPolicy)
@@ -28,3 +29,12 @@
return 1
fn = compile_func(f, [])
assert fn() == 1
+
+def test_something_more():
+ S = lltype.GcStruct("S", ('x', lltype.Signed))
+ def f(x):
+ s = lltype.malloc(S)
+ s.x = x
+ return s.x
+ fn = compile_func(f, [int])
+ assert fn(1) == 1
More information about the Pypy-commit
mailing list