[pypy-svn] r22536 - in pypy/dist/pypy: rpython/l3interp rpython/l3interp/test translator/c

mwh at codespeak.net mwh at codespeak.net
Mon Jan 23 17:51:03 CET 2006


Author: mwh
Date: Mon Jan 23 17:51:00 2006
New Revision: 22536

Modified:
   pypy/dist/pypy/rpython/l3interp/l3interp.py
   pypy/dist/pypy/rpython/l3interp/test/test_convert.py
   pypy/dist/pypy/rpython/l3interp/test/test_l3interp.py
   pypy/dist/pypy/translator/c/database.py
Log:
(arre, mwh)
Actually test the translation of a non-trivial use of offsets.
This meant fixing the c generation, and finding that really weird
things happen if you let a translationcontext go away before graphs
that it made.


Modified: pypy/dist/pypy/rpython/l3interp/l3interp.py
==============================================================================
--- pypy/dist/pypy/rpython/l3interp/l3interp.py	(original)
+++ pypy/dist/pypy/rpython/l3interp/l3interp.py	Mon Jan 23 17:51:00 2006
@@ -50,6 +50,10 @@
     def __init__(self, graph, stack_int, stack_dbl, stack_ptr):
         self.graph = graph
         self.block = self.graph.startblock
+        # XXX aaaaaaaargh!
+        if self.block.constants_int is None:
+            self.block.constants_int = [0]
+            self.block.constants_int = None
         if self.block.constants_ptr is None:
             self.block.constants_ptr = [constant_fakeaddress]
             self.block.constants_ptr = None

Modified: pypy/dist/pypy/rpython/l3interp/test/test_convert.py
==============================================================================
--- pypy/dist/pypy/rpython/l3interp/test/test_convert.py	(original)
+++ pypy/dist/pypy/rpython/l3interp/test/test_convert.py	Mon Jan 23 17:51:00 2006
@@ -7,7 +7,14 @@
     t.buildannotator().build_types(f, inputargs)
     t.buildrtyper().specialize()
     conv = convertgraph.LL2L3Converter()
-    return conv.convert_graph(t.graphs[0])
+    g = conv.convert_graph(t.graphs[0])
+    # XXX this vile, vile hack prevents the TranslationContext from
+    # being deallocated which leads to the vtables of certain
+    # important types (like object) going away, which is generally
+    # very, very confusing.
+    # XXX work out why, fix it
+    g.keepthislotalive = t
+    return g
 
 
 def test_convert_add():

Modified: pypy/dist/pypy/rpython/l3interp/test/test_l3interp.py
==============================================================================
--- pypy/dist/pypy/rpython/l3interp/test/test_l3interp.py	(original)
+++ pypy/dist/pypy/rpython/l3interp/test/test_l3interp.py	Mon Jan 23 17:51:00 2006
@@ -121,3 +121,33 @@
     fn = translate(eval_call, [int]) 
     assert fn(4) == 7 
     assert fn(0) == 3
+
+#----------------------------------------------------------------------
+
+from pypy.rpython.l3interp.test.test_convert import l3ify
+
+def test_getfield():
+    class C:
+        def __init__(self, x):
+            self.x = x
+    one = C(1)
+    two = C(2)
+
+    def f(n):
+        if n:
+            return one.x
+        else:
+            return two.x
+
+    l3graph = l3ify(f, [int])
+
+    def entry_point(x):
+        value = l3interp.l3interpret(l3graph, [x], [], [])
+        assert isinstance(value, l3interp.L3Integer)
+        return value.intval
+
+    fn = translate(entry_point, [int])
+
+    assert fn(3) == f(3)
+    assert fn(0) == f(0)
+        

Modified: pypy/dist/pypy/translator/c/database.py
==============================================================================
--- pypy/dist/pypy/translator/c/database.py	(original)
+++ pypy/dist/pypy/translator/c/database.py	Mon Jan 23 17:51:00 2006
@@ -126,8 +126,10 @@
                 if len(obj.fldnames) == 0:
                     return '0 /*offsetof*/'
                 else:
-                    return 'offsetof(%s, %s)'%(
-                        self.gettype(obj.TYPE), obj.fldnames[0])
+                    structnode = self.gettypedefnode(obj.TYPE.TO)
+                    return 'offsetof(struct %s, %s)'%(
+                        structnode.name,
+                        structnode.c_struct_field_name(obj.fldnames[0]))
             elif T is Address and obj is not NULL:
                 if obj.ob is None:
                     return 'NULL'



More information about the Pypy-commit mailing list