[pypy-svn] r16339 - in pypy/dist/pypy/translator/c: . src test

pedronis at codespeak.net pedronis at codespeak.net
Tue Aug 23 20:22:59 CEST 2005


Author: pedronis
Date: Tue Aug 23 20:22:57 2005
New Revision: 16339

Added:
   pypy/dist/pypy/translator/c/test/test_boehm.py   (contents, props changed)
Modified:
   pypy/dist/pypy/translator/c/database.py
   pypy/dist/pypy/translator/c/gc.py
   pypy/dist/pypy/translator/c/genc.py
   pypy/dist/pypy/translator/c/src/main.h
   pypy/dist/pypy/translator/c/src/module.h
Log:
groundwork for starting with a BoehmGcPolicy

(cfbolz, pedronis)



Modified: pypy/dist/pypy/translator/c/database.py
==============================================================================
--- pypy/dist/pypy/translator/c/database.py	(original)
+++ pypy/dist/pypy/translator/c/database.py	Tue Aug 23 20:22:57 2005
@@ -14,7 +14,7 @@
 
 class LowLevelDatabase:
 
-    def __init__(self, translator=None, standalone=False, gcpolicy=gc.RefcountingGcPolicy):
+    def __init__(self, translator=None, standalone=False, gcpolicy=None):
         self.translator = translator
         self.standalone = standalone
         self.structdefnodes = {}
@@ -24,6 +24,8 @@
         self.namespace = CNameManager()
         if not standalone:
             self.pyobjmaker = PyObjMaker(self.namespace, self.get, translator)
+        if gcpolicy is None:
+            gcpolicy = gc.RefcountingGcPolicy
         self.gcpolicy = gcpolicy(self)
 
     def gettypedefnode(self, T, varlength=1):

Modified: pypy/dist/pypy/translator/c/gc.py
==============================================================================
--- pypy/dist/pypy/translator/c/gc.py	(original)
+++ pypy/dist/pypy/translator/c/gc.py	Tue Aug 23 20:22:57 2005
@@ -35,6 +35,12 @@
                 return self.pop_alive_nopyobj(expr, T)
         return ''
 
+    def pre_gc_code(self):
+        return []
+
+    def gc_startup_code(self):
+        return []
+
 class RefcountingInfo:
     deallocator = None
     static_deallocator = None
@@ -215,3 +221,5 @@
         yield  'OP_ZERO_MALLOC(%s, %s, %s);' % (esize,
                                                 eresult,
                                                 err)
+
+

Modified: pypy/dist/pypy/translator/c/genc.py
==============================================================================
--- pypy/dist/pypy/translator/c/genc.py	(original)
+++ pypy/dist/pypy/translator/c/genc.py	Tue Aug 23 20:22:57 2005
@@ -16,14 +16,15 @@
     _compiled = False
     symboltable = None
     
-    def __init__(self, translator):
+    def __init__(self, translator, gcpolicy=None):
         self.translator = translator
+        self.gcpolicy = gcpolicy
     
     def generate_source(self):
         assert self.c_source_filename is None
         translator = self.translator
         pf = self.getentrypointptr()
-        db = LowLevelDatabase(translator, standalone=self.standalone)
+        db = LowLevelDatabase(translator, standalone=self.standalone, gcpolicy=self.gcpolicy)
         pfname = db.get(pf)
         db.complete()
 
@@ -163,6 +164,9 @@
     # generate the start-up code and put it into a function
     print >> f, 'char *RPython_StartupCode(void) {'
     print >> f, '\tchar *error = NULL;'
+    for line in database.gcpolicy.gc_startup_code():
+        print >> f,"\t" + line
+
     firsttime = True
     for node in database.containerlist:
         lines = list(node.startupcode())
@@ -223,6 +227,10 @@
     for key, value in defines.items():
         print >> f, '#define %s %s' % (key, value)
     print >> f, '#include "src/g_prerequisite.h"'
+
+    for line in database.gcpolicy.pre_gc_code():
+        print >> f, line
+
     includes = {}
     for node in database.globalcontainers():
         for include in node.includes:

Modified: pypy/dist/pypy/translator/c/src/main.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/main.h	(original)
+++ pypy/dist/pypy/translator/c/src/main.h	Tue Aug 23 20:22:57 2005
@@ -8,15 +8,18 @@
 {
     char *errmsg = "out of memory";
     int i;
-    RPyListOfString *list = RPyListOfString_New(argc);
+    RPyListOfString *list;
+    errmsg = RPython_StartupCode();
+    if (errmsg) goto error;
+
+    list = RPyListOfString_New(argc);
     if (RPyExceptionOccurred()) goto error;
     for (i=0; i<argc; i++) {
         RPyString *s = RPyString_FromString(argv[i]);
         if (RPyExceptionOccurred()) goto error;
         RPyListOfString_SetItem(list, i, s);
     }
-    errmsg = RPython_StartupCode();
-    if (errmsg) goto error;
+
 
     return STANDALONE_ENTRY_POINT(list);
 

Modified: pypy/dist/pypy/translator/c/src/module.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/module.h	(original)
+++ pypy/dist/pypy/translator/c/src/module.h	Tue Aug 23 20:22:57 2005
@@ -30,17 +30,17 @@
 	if (RPythonError == NULL) \
 		return; \
 	PyModule_AddObject(m, "RPythonError", RPythonError); \
+	errmsg = RPython_StartupCode(); \
+	if (errmsg) { \
+		PyErr_SetString(PyExc_RuntimeError, errmsg); \
+		return; \
+	} \
 	if (setup_globalfunctions(globalfunctiondefs, #modname) < 0) \
 		return;	\
 	if (setup_initcode(frozen_initcode, FROZEN_INITCODE_SIZE) < 0) \
 		return;	\
 	if (setup_globalobjects(globalobjectdefs) < 0) \
-		return; \
-	errmsg = RPython_StartupCode(); \
-	if (errmsg) { \
-		PyErr_SetString(PyExc_RuntimeError, errmsg); \
-		return; \
-	} 
+		return;
 
 /*** table of global objects ***/
 

Added: pypy/dist/pypy/translator/c/test/test_boehm.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/c/test/test_boehm.py	Tue Aug 23 20:22:57 2005
@@ -0,0 +1,41 @@
+from pypy.translator.translator import Translator
+from pypy.translator.tool.cbuild import skip_missing_compiler
+from pypy.translator.c.genc import CExtModuleBuilder
+
+class TestBoehmTestCase:
+
+    def getcompiled(self, func):
+        from pypy.translator.c.gc import BoehmGcPolicy
+        t = Translator(func, simplifying=True)
+        # builds starting-types from func_defs 
+        argstypelist = []
+        if func.func_defaults:
+            for spec in func.func_defaults:
+                if isinstance(spec, tuple):
+                    spec = spec[0] # use the first type only for the tests
+                argstypelist.append(spec)
+        a = t.annotate(argstypelist)
+        a.simplify()
+        t.specialize()
+        t.checkgraphs()
+        def compile():
+            cbuilder = CExtModuleBuilder(t, gcpolicy=BoehmGcPolicy)
+            c_source_filename = cbuilder.generate_source()
+            cbuilder.compile()
+            cbuilder.import_module()    
+            return cbuilder.get_entry_point()
+        return skip_missing_compiler(compile)
+
+
+    def DONTtest_malloc_a_lot(self):
+        def malloc_a_lot():
+            i = 0
+            while i < 10:
+                i += 1
+                a = [1] * 10
+                j = 0
+                while j < 20:
+                    j += 1
+                    a.append(j)
+        fn = self.getcompiled(malloc_a_lot)
+        fn()



More information about the Pypy-commit mailing list