[pypy-svn] r32806 - in pypy/branch/even-more-config/pypy: config translator translator/c translator/c/test

cfbolz at codespeak.net cfbolz at codespeak.net
Mon Oct 2 00:55:20 CEST 2006


Author: cfbolz
Date: Mon Oct  2 00:55:15 2006
New Revision: 32806

Modified:
   pypy/branch/even-more-config/pypy/config/pypyoption.py
   pypy/branch/even-more-config/pypy/translator/c/database.py
   pypy/branch/even-more-config/pypy/translator/c/gc.py
   pypy/branch/even-more-config/pypy/translator/c/genc.py
   pypy/branch/even-more-config/pypy/translator/c/test/test_boehm.py
   pypy/branch/even-more-config/pypy/translator/c/test/test_genc.py
   pypy/branch/even-more-config/pypy/translator/c/test/test_newgc.py
   pypy/branch/even-more-config/pypy/translator/c/test/test_stackless.py
   pypy/branch/even-more-config/pypy/translator/driver.py
Log:
intermediate checkin to use the config in genc. Some tests fail but the
majority passes.


Modified: pypy/branch/even-more-config/pypy/config/pypyoption.py
==============================================================================
--- pypy/branch/even-more-config/pypy/config/pypyoption.py	(original)
+++ pypy/branch/even-more-config/pypy/config/pypyoption.py	Mon Oct  2 00:55:15 2006
@@ -120,7 +120,8 @@
                          "cl":     [("translation.type_system", "ootype")],
                          }),
         ChoiceOption("gc", "Garbage Collection Strategy",
-                     ["boehm", "ref", "framework", "none", "stacklessgc"],
+                     ["boehm", "ref", "framework", "none", "stacklessgc",
+                      "exact_boehm"],
                       "boehm", requires={
                          "stacklessgc": [("translation.stackless", True)]},
                       cmdline="--gc"),
@@ -131,6 +132,8 @@
         BoolOption("debug", "Record extra annotation information",
                    default=True),
         BoolOption("insist", "Try hard to go on RTyping", default=False),
+        BoolOption("countmallocs", "Count mallocs and frees", default=False,
+                   cmdline=None),
         BoolOption("lowmem", "Try to use little memory during translation",
                    default=False, cmdline="--lowmem",
                    requires=[("objspace.geninterp", False)]),

Modified: pypy/branch/even-more-config/pypy/translator/c/database.py
==============================================================================
--- pypy/branch/even-more-config/pypy/translator/c/database.py	(original)
+++ pypy/branch/even-more-config/pypy/translator/c/database.py	Mon Oct  2 00:55:15 2006
@@ -15,17 +15,25 @@
 from pypy.translator.c.support import log
 from pypy.translator.c.extfunc import do_the_getting
 from pypy import conftest
+from pypy.translator.c import gc
+
 
 # ____________________________________________________________
 
 class LowLevelDatabase(object):
-    stacklesstransformer = None
     gctransformer = None
 
-    def __init__(self, translator=None, standalone=False, gcpolicy=None, thread_enabled=False):
+    def __init__(self, translator=None, standalone=False,
+                 gcpolicyclass=None,
+                 stacklesstransformer=None,
+                 thread_enabled=False):
         self.translator = translator
         self.standalone = standalone
-        self.thread_enabled = thread_enabled
+        self.stacklesstransformer = stacklesstransformer
+        if gcpolicyclass is None:
+            gcpolicyclass = gc.RefcountingGcPolicy
+        self.gcpolicy = gcpolicyclass(self, thread_enabled)
+
         self.structdefnodes = {}
         self.pendingsetupnodes = []
         self.containernodes = {}
@@ -47,31 +55,12 @@
             from pypy.translator.c.pyobj import PyObjMaker
             self.pyobjmaker = PyObjMaker(self.namespace, self, translator)
 
-        gcpolicy = gcpolicy or conftest.option.gcpolicy or 'ref'
-        if isinstance(gcpolicy, str):
-            from pypy.translator.c import gc
-            polname = gcpolicy
-            if polname == 'boehm':
-                gcpolicy = gc.BoehmGcPolicy
-            elif polname == 'exact_boehm':
-                gcpolicy = gc.MoreExactBoehmGcPolicy
-            elif polname == 'ref':
-                gcpolicy = gc.RefcountingGcPolicy
-            elif polname == 'none':
-                gcpolicy = gc.NoneGcPolicy
-            elif polname == 'framework':
-                gcpolicy = gc.FrameworkGcPolicy
-            elif polname == 'stacklessgc':
-                gcpolicy = gc.StacklessFrameworkGcPolicy
-            else:
-                assert False, "unknown gc policy %r"%polname
         if translator is None or translator.rtyper is None:
             self.exctransformer = None
         else:
             self.exctransformer = translator.getexceptiontransformer()
-        self.gcpolicy = gcpolicy(self, thread_enabled)
         if translator is not None:
-            self.gctransformer = gcpolicy.transformerclass(translator)
+            self.gctransformer = self.gcpolicy.transformerclass(translator)
         self.completed = False
 
     def gettypedefnode(self, T, varlength=1):

Modified: pypy/branch/even-more-config/pypy/translator/c/gc.py
==============================================================================
--- pypy/branch/even-more-config/pypy/translator/c/gc.py	(original)
+++ pypy/branch/even-more-config/pypy/translator/c/gc.py	Mon Oct  2 00:55:15 2006
@@ -423,3 +423,15 @@
 class StacklessFrameworkGcPolicy(FrameworkGcPolicy):
     transformerclass = gctransform.StacklessFrameworkGCTransformer
     requires_stackless = True
+
+
+name_to_gcpolicy = {
+    'boehm': BoehmGcPolicy,
+    'exact_boehm': MoreExactBoehmGcPolicy,
+    'ref': RefcountingGcPolicy,
+    'none': NoneGcPolicy,
+    'framework': FrameworkGcPolicy,
+    'stacklessgc': StacklessFrameworkGcPolicy,
+}
+
+

Modified: pypy/branch/even-more-config/pypy/translator/c/genc.py
==============================================================================
--- pypy/branch/even-more-config/pypy/translator/c/genc.py	(original)
+++ pypy/branch/even-more-config/pypy/translator/c/genc.py	Mon Oct  2 00:55:15 2006
@@ -14,20 +14,23 @@
 from pypy.translator.locality.calltree import CallTree
 from pypy.translator.c.support import log, c_string_constant
 from pypy.rpython.typesystem import getfunctionptr
+from pypy.translator.c import gc
 
 class CBuilder(object):
     c_source_filename = None
     _compiled = False
     symboltable = None
-    stackless = False
     modulename = None
     
-    def __init__(self, translator, entrypoint, gcpolicy=None, libraries=None, thread_enabled=False):
+    def __init__(self, translator, entrypoint, config=None, libraries=None):
         self.translator = translator
         self.entrypoint = entrypoint
         self.originalentrypoint = entrypoint
-        self.gcpolicy = gcpolicy
-        self.thread_enabled = thread_enabled
+        if config is None:
+            from pypy.config.config import Config
+            from pypy.config.pypyoption import pypy_optiondescription
+            config = Config(pypy_optiondescription)
+        self.config = config
 
         if libraries is None:
             libraries = []
@@ -36,23 +39,25 @@
 
     def build_database(self, exports=[], pyobj_options=None):
         translator = self.translator
-        db = LowLevelDatabase(translator, standalone=self.standalone, 
-                              gcpolicy=self.gcpolicy, thread_enabled=self.thread_enabled)
 
-        assert self.stackless in (False, True)
-        if db.gcpolicy.requires_stackless:
-            assert self.stackless != 'old'    # incompatible
-            self.stackless = True
-        if self.stackless:
+        gcpolicyclass = gc.name_to_gcpolicy[self.config.translation.gc]
+
+        if self.config.translation.stackless:
             if not self.standalone:
                 raise Exception("stackless: only for stand-alone builds")
-
+            
             from pypy.translator.stackless.transform import StacklessTransformer
-            db.stacklesstransformer = StacklessTransformer(translator,
-                                                           self.originalentrypoint,
-                                                           db.gcpolicy.requires_stackless)
-            self.entrypoint = db.stacklesstransformer.slp_entry_point
+            stacklesstransformer = StacklessTransformer(
+                translator, self.originalentrypoint,
+                gcpolicyclass.requires_stackless)
+            self.entrypoint = stacklesstransformer.slp_entry_point
+        else:
+            stacklesstransformer = None
 
+        db = LowLevelDatabase(translator, standalone=self.standalone,
+                              gcpolicyclass=gcpolicyclass,
+                              stacklesstransformer=stacklesstransformer,
+                              thread_enabled=self.config.translation.thread)
         # pass extra options into pyobjmaker
         if pyobj_options:
             for key, value in pyobj_options.items():
@@ -112,7 +117,8 @@
         targetdir = udir.ensure(modulename, dir=1)
         self.targetdir = targetdir
         defines = defines.copy()
-        # defines={'COUNT_OP_MALLOCS': 1}
+        if self.config.translation.countmallocs:
+            defines['COUNT_OP_MALLOCS'] = 1
         if CBuilder.have___thread is None:
             CBuilder.have___thread = check_under_under_thread()
         if not self.standalone:
@@ -281,7 +287,10 @@
         print >> f
         print >> f, 'CFLAGS  =', ' '.join(compiler.compile_extra)
         print >> f, 'LDFLAGS =', ' '.join(compiler.link_extra)
-        print >> f, 'TFLAGS  = ' + ('', '-pthread')[self.thread_enabled]
+        if self.config.translation.thread:
+            print >> f, 'TFLAGS  = ' + '-pthread'
+        else:
+            print >> f, 'TFLAGS  = ' + ''
         print >> f, 'PROFOPT = ' + profopt
         print >> f, 'CC      = ' + cc
         print >> f

Modified: pypy/branch/even-more-config/pypy/translator/c/test/test_boehm.py
==============================================================================
--- pypy/branch/even-more-config/pypy/translator/c/test/test_boehm.py	(original)
+++ pypy/branch/even-more-config/pypy/translator/c/test/test_boehm.py	Mon Oct  2 00:55:15 2006
@@ -3,6 +3,8 @@
 from pypy.translator.tool.cbuild import check_boehm_presence
 from pypy.translator.c.genc import CExtModuleBuilder
 from pypy import conftest
+from pypy.config.config import Config
+from pypy.config.pypyoption import pypy_optiondescription
 
 def setup_module(mod):
     if not check_boehm_presence():
@@ -32,7 +34,9 @@
         t.buildrtyper().specialize()
         t.checkgraphs()
         def compile():
-            cbuilder = CExtModuleBuilder(t, func, gcpolicy=self.gcpolicy)
+            config = Config(pypy_optiondescription)
+            config.translation.gc = self.gcpolicy
+            cbuilder = CExtModuleBuilder(t, func, config=config)
             c_source_filename = cbuilder.generate_source()
             if conftest.option.view:
                 t.view()
@@ -44,7 +48,7 @@
 
 
 class TestUsingBoehm(AbstractTestClass):
-    from pypy.translator.c.gc import BoehmGcPolicy as gcpolicy
+    gcpolicy = "boehm"
 
     def test_malloc_a_lot(self):
         def malloc_a_lot():
@@ -140,7 +144,7 @@
         s = State()
         s.dels = 0
         def g():
-            a = A()            
+            a = A()
         def f():
             s.dels = 0
             for i in range(10):
@@ -178,6 +182,6 @@
         
 
 class TestUsingExactBoehm(TestUsingBoehm):
-    from pypy.translator.c.gc import MoreExactBoehmGcPolicy as gcpolicy
+    gcpolicy = "exact_boehm"
 
 

Modified: pypy/branch/even-more-config/pypy/translator/c/test/test_genc.py
==============================================================================
--- pypy/branch/even-more-config/pypy/translator/c/test/test_genc.py	(original)
+++ pypy/branch/even-more-config/pypy/translator/c/test/test_genc.py	Mon Oct  2 00:55:15 2006
@@ -12,6 +12,7 @@
 from pypy.translator.tool.cbuild import enable_fast_compilation
 from pypy.translator.gensupp import uniquemodulename
 from pypy.translator.backendopt.all import backend_optimizations
+from pypy.translator.interactive import Translation
 from pypy import conftest
 
 # XXX this tries to make compiling faster for full-scale testing
@@ -19,7 +20,6 @@
 #from pypy.translator.tool import cbuild
 #cbuild.enable_fast_compilation()
 
-
 def compile_db(db):
     enable_fast_compilation()  # for testing
     modulename = uniquemodulename('testing')
@@ -30,21 +30,17 @@
                            libraries = db.gcpolicy.gc_libraries())
     return m
 
-def compile(fn, argtypes, view=False, gcpolicy=None, backendopt=True,
+def compile(fn, argtypes, view=False, gcpolicy="ref", backendopt=True,
             annotatorpolicy=None):
-    t = TranslationContext()
-    a = t.buildannotator(policy=annotatorpolicy)
-    a.build_types(fn, argtypes)
-    t.buildrtyper().specialize()
-    if backendopt:
-        backend_optimizations(t)
-    db = LowLevelDatabase(t, gcpolicy=gcpolicy)
-    entrypoint = db.get(pyobjectptr(fn))
-    db.complete()
-    module = compile_db(db)
-    if view or conftest.option.view:
-        t.view()
-    compiled_fn = getattr(module, entrypoint)
+    t = Translation(fn, argtypes, gc=gcpolicy, backend="c")
+    if not backendopt:
+        t.disable(["backendopt_lltype"])
+    t.annotate()
+    # XXX fish
+    t.driver.config.translation.countmallocs = True
+    compiled_fn = t.compile_c()
+    # XXX fish fish fish some more
+    module = t.driver.cbuilder.c_ext_module
     def checking_fn(*args, **kwds):
         if 'expected_extra_mallocs' in kwds:
             expected_extra_mallocs = kwds.pop('expected_extra_mallocs')

Modified: pypy/branch/even-more-config/pypy/translator/c/test/test_newgc.py
==============================================================================
--- pypy/branch/even-more-config/pypy/translator/c/test/test_newgc.py	(original)
+++ pypy/branch/even-more-config/pypy/translator/c/test/test_newgc.py	Mon Oct  2 00:55:15 2006
@@ -10,16 +10,19 @@
 from pypy.rpython.lltypesystem.lloperation import llop
 from pypy.rpython.objectmodel import cast_weakgcaddress_to_object, cast_object_to_weakgcaddress
 from pypy.rpython.memory.gctransform import GCTransformer
-
+from pypy.config.config import Config
+from pypy.config.pypyoption import pypy_optiondescription
 from pypy import conftest
 
-def compile_func(fn, inputtypes, t=None, gcpolicy=gc.RefcountingGcPolicy):
+def compile_func(fn, inputtypes, t=None, gcpolicy="ref"):
+    config = Config(pypy_optiondescription)
+    config.translation.gc = gcpolicy
     if t is None:
-        t = TranslationContext()
+        t = TranslationContext(config=config)
     if inputtypes is not None:
         t.buildannotator().build_types(fn, inputtypes)
         t.buildrtyper().specialize()
-    builder = genc.CExtModuleBuilder(t, fn, gcpolicy=gcpolicy)
+    builder = genc.CExtModuleBuilder(t, fn, config=config)
     builder.generate_source(defines={'COUNT_OP_MALLOCS': 1})
     builder.compile()
     builder.import_module()
@@ -144,7 +147,7 @@
     assert fn(0) == 5
 
 def test_del_basic():
-    for gcpolicy in [gc.RefcountingGcPolicy]:  #, gc.FrameworkGcPolicy]:
+    for gcpolicy in ["ref"]: #, "framework"]:
         S = lltype.GcStruct('S', ('x', lltype.Signed))
         TRASH = lltype.GcStruct('TRASH', ('x', lltype.Signed))
         lltype.attachRuntimeTypeInfo(S)
@@ -400,7 +403,7 @@
 from pypy.translator.c.test.test_boehm import AbstractTestClass
 
 class TestUsingFramework(AbstractTestClass):
-    from pypy.translator.c.gc import FrameworkGcPolicy as gcpolicy
+    gcpolicy = "framework"
 
     def test_empty_collect(self):
         def f():
@@ -863,7 +866,7 @@
         res = fn()
 
 class TestUsingStacklessFramework(TestUsingFramework):
-    from pypy.translator.c.gc import StacklessFrameworkGcPolicy as gcpolicy
+    gcpolicy = "stacklessgc"
 
     def getcompiled(self, f):
         # XXX quick hack

Modified: pypy/branch/even-more-config/pypy/translator/c/test/test_stackless.py
==============================================================================
--- pypy/branch/even-more-config/pypy/translator/c/test/test_stackless.py	(original)
+++ pypy/branch/even-more-config/pypy/translator/c/test/test_stackless.py	Mon Oct  2 00:55:15 2006
@@ -5,13 +5,15 @@
 from pypy.annotation.listdef import s_list_of_strings
 from pypy.rpython.rstack import stack_unwind, stack_frames_depth, stack_too_big
 from pypy.rpython.rstack import yield_current_frame_to_caller
+from pypy.config.config import Config
+from pypy.config.pypyoption import pypy_optiondescription
 import os
 
 
 class StacklessTest(object):
     backendopt = False
     stacklessmode = True
-    gcpolicy = gc.BoehmGcPolicy
+    gcpolicy = "boehm"
 
     def setup_class(cls):
         import py
@@ -31,7 +33,10 @@
             os.write(1, str(fn())+"\n")
             return 0
 
-        t = TranslationContext()
+        config = Config(pypy_optiondescription)
+        config.translation.gc = self.gcpolicy
+        config.translation.stackless = True
+        t = TranslationContext(config=config)
         self.t = t
         t.buildannotator().build_types(entry_point, [s_list_of_strings])
         t.buildrtyper().specialize()
@@ -41,7 +46,7 @@
         from pypy.translator.transform import insert_ll_stackcheck
         insert_ll_stackcheck(t)
 
-        cbuilder = CStandaloneBuilder(t, entry_point, gcpolicy=self.gcpolicy)
+        cbuilder = CStandaloneBuilder(t, entry_point, config=config)
         cbuilder.stackless = self.stacklessmode
         cbuilder.generate_source()
         cbuilder.compile()

Modified: pypy/branch/even-more-config/pypy/translator/driver.py
==============================================================================
--- pypy/branch/even-more-config/pypy/translator/driver.py	(original)
+++ pypy/branch/even-more-config/pypy/translator/driver.py	Mon Oct  2 00:55:15 2006
@@ -308,8 +308,8 @@
         insert_ll_stackcheck(self.translator)
         
     task_stackcheckinsertion_lltype = taskdef(
-        task_stackcheckinsertion_lltype, 
-        ['?'+BACKENDOPT, RTYPE, 'annotate'], 
+        task_stackcheckinsertion_lltype,
+        ['?'+BACKENDOPT, RTYPE, 'annotate'],
         "inserting stack checks")
     STACKCHECKINSERTION = 'stackcheckinsertion_lltype'
 
@@ -325,8 +325,7 @@
         else:
             from pypy.translator.c.genc import CExtModuleBuilder as CBuilder
         cbuilder = CBuilder(self.translator, self.entry_point,
-                            gcpolicy       = self.config.translation.gc,
-                            thread_enabled = self.config.translation.thread)
+                            config=self.config)
         cbuilder.stackless = self.config.translation.stackless
         if not standalone:     # xxx more messy
             cbuilder.modulename = self.extmod_name
@@ -335,7 +334,7 @@
         self.cbuilder = cbuilder
         self.database = database
     #
-    task_database_c = taskdef(task_database_c, 
+    task_database_c = taskdef(task_database_c,
                             [STACKCHECKINSERTION, '?'+BACKENDOPT, RTYPE, '?annotate'], 
                             "Creating database for generating c source")
     



More information about the Pypy-commit mailing list