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

arigo at codespeak.net arigo at codespeak.net
Mon Jun 20 14:30:50 CEST 2005


Author: arigo
Date: Mon Jun 20 14:30:46 2005
New Revision: 13617

Modified:
   pypy/dist/pypy/rpython/rmodel.py
   pypy/dist/pypy/translator/c/int_include.h
   pypy/dist/pypy/translator/c/symboltable.py
   pypy/dist/pypy/translator/c/test/test_symboltable.py
Log:
Implement id() in rtyper and genc.  Use it to return from small examples the
address of global structures.  From this address, the SymbolTable can inspect
the global structures and recursively everything reachable from them.



Modified: pypy/dist/pypy/rpython/rmodel.py
==============================================================================
--- pypy/dist/pypy/rpython/rmodel.py	(original)
+++ pypy/dist/pypy/rpython/rmodel.py	Mon Jun 20 14:30:46 2005
@@ -72,6 +72,14 @@
         else:
             return hop.genop('int_is_true', [vlen], resulttype=Bool)
 
+    def rtype_id(self, hop):
+        if not isinstance(self.lowleveltype, Ptr):
+            raise TyperError('id() of an instance of the non-pointer %r' % (
+                self,))
+        vobj, = hop.inputargs(self)
+        # XXX
+        return hop.genop('cast_ptr_to_int', [vobj], resulttype=Signed)
+
     def rtype_iter(self, hop):
         r_iter = self.make_iterator_repr()
         return r_iter.newiter(hop)

Modified: pypy/dist/pypy/translator/c/int_include.h
==============================================================================
--- pypy/dist/pypy/translator/c/int_include.h	(original)
+++ pypy/dist/pypy/translator/c/int_include.h	Mon Jun 20 14:30:46 2005
@@ -143,6 +143,7 @@
 #define OP_CAST_INT_TO_UINT(x,r,err)    r = (unsigned long)(x);
 #define OP_CAST_CHAR_TO_INT(x,r,err)    r = (long)(x);
 #define OP_CAST_INT_TO_CHAR(x,r,err)    r = (char)(x);
+#define OP_CAST_PTR_TO_INT(x,r,err)     r = (long)(x);    /* XXX */
 
 /* _________________ certain implementations __________________ */
 

Modified: pypy/dist/pypy/translator/c/symboltable.py
==============================================================================
--- pypy/dist/pypy/translator/c/symboltable.py	(original)
+++ pypy/dist/pypy/translator/c/symboltable.py	Mon Jun 20 14:30:46 2005
@@ -34,9 +34,18 @@
     def keys(self):
         return self.globals.keys()
 
-    def __getitem__(self, globalname):
-        ptrindex, T = self.globals[globalname]
-        address = self.module.debuginfo_global(ptrindex)
+    def __getitem__(self, globalname_or_address):
+        if isinstance(globalname_or_address, str):
+            ptrindex, T = self.globals[globalname]
+            address = self.module.debuginfo_global(ptrindex)
+        else:
+            for ptrindex, T in self.globals.values():
+                address = self.module.debuginfo_global(ptrindex)
+                if address == globalname_or_address:
+                    break
+            else:
+                raise KeyError("no global object at 0x%x" %
+                               (globalname_or_address,))
         return debugptr(Ptr(T), address, self)
 
     def __iter__(self):

Modified: pypy/dist/pypy/translator/c/test/test_symboltable.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_symboltable.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_symboltable.py	Mon Jun 20 14:30:46 2005
@@ -4,17 +4,17 @@
 def test_simple():
     glist = [4, 5, 6]
     def f(x):
-        return glist[x]
+        return glist[x], id(glist)
     t = Translator(f)
     t.annotate([int])
     t.specialize()
 
     f = t.ccompile()
-    assert f(1) == 5
-    assert f(2) == 6
+    res, addr = f(1)
+    assert res == 5
 
     symtable = getsymboltable(f.__module__)
-    debug_list = symtable['g_list']    # XXX find a way to find this name
+    debug_list = symtable[addr]
     assert len(debug_list.items) == 3
     assert debug_list.items[0] == 4
     assert debug_list.items[1] == 5



More information about the Pypy-commit mailing list