[pypy-svn] r21825 - in pypy/dist/pypy/translator: . goal test

pedronis at codespeak.net pedronis at codespeak.net
Sun Jan 8 23:22:20 CET 2006


Author: pedronis
Date: Sun Jan  8 23:22:18 2006
New Revision: 21825

Modified:
   pypy/dist/pypy/translator/goal/driver.py
   pypy/dist/pypy/translator/interactive.py
   pypy/dist/pypy/translator/test/test_interactive.py
Log:
a bit more progress



Modified: pypy/dist/pypy/translator/goal/driver.py
==============================================================================
--- pypy/dist/pypy/translator/goal/driver.py	(original)
+++ pypy/dist/pypy/translator/goal/driver.py	Sun Jan  8 23:22:18 2006
@@ -47,7 +47,7 @@
         self.log = log
 
         if options is None:
-            options = DEFAULT_OPTIONS 
+            options = DEFAULT_OPTIONS
         self.options = options
  
         self.done = {}
@@ -341,7 +341,7 @@
         if args is None:
             args = []
         if options is None:
-            options = DEFAULT_OPTIONS.copy()
+            options = DEFAULT_OPTIONS
 
         driver = TranslationDriver(options, default_goal, disable)
             

Modified: pypy/dist/pypy/translator/interactive.py
==============================================================================
--- pypy/dist/pypy/translator/interactive.py	(original)
+++ pypy/dist/pypy/translator/interactive.py	Sun Jan  8 23:22:18 2006
@@ -3,7 +3,7 @@
 from pypy.translator.translator import TranslationContext
 from pypy.translator.goal import driver
 
-DEFAULT_OPTIONS = optparse.Values(defaults={
+DEFAULT_OPTIONS = {
   'gc': 'ref',
 
   'thread': False, # influences GC policy
@@ -15,8 +15,10 @@
    'backend': None,
    'lowmem': False,
 
-   'fork_before': None
-})
+   'fork_before': None,
+
+   'merge_if_blocks': True
+}
 
 class Translation(object):
 
@@ -27,8 +29,9 @@
         graph = self.context.buildflowgraph(entry_point)
         self.context._prebuilt_graphs[entry_point] = graph
 
-        self.driver = driver.TranslationDriver(DEFAULT_OPTIONS)
-        
+        self.driver = driver.TranslationDriver(
+            optparse.Values(defaults=DEFAULT_OPTIONS))
+         
         # hook into driver events
         driver_own_event = self.driver._event
         def _event(kind, goal, func):
@@ -44,6 +47,10 @@
     GOAL_USES_OPTS = {
         'annotate': ['debug'],
         'rtype': ['insist'],
+        'backendopt': ['merge_if_blocks'],
+        'database_c': ['gc', 'stackless'],
+        'source_llvm': ['gc', 'stackless'],
+        'source_c': [],
     }
 
     def driver_event(self, kind, goal, func):
@@ -72,7 +79,7 @@
     def update_options(self, argtypes, kwds):
         if argtypes or kwds.get('policy'):
             self.ensure_setup(argtypes, kwds.get('policy'))
-        for optname, value in kwds:
+        for optname, value in kwds.iteritems():
             if optname in self.frozen_options:
                 if getattr(self.driver.options, optname) != value:
                      raise Exception("incosistent option supplied: %s" % optname)
@@ -80,6 +87,13 @@
                 setattr(self.driver.options, optname, value)
                 self.frozen_options[optname] = True
 
+    def ensure_backend(self, backend=None):
+        if backend is not None:
+            self.update_options(None, {'backend': backend})
+        if self.driver.options.backend is None:
+            raise Exception("a backend should have been specified at this point")
+        return self.driver.options.backend
+
     # backend independent
 
     def annotate(self, argtypes=None, **kwds):
@@ -90,15 +104,32 @@
         self.update_options(argtypes, kwds)
         return self.driver.rtype()
 
-    # backend depedent xxx
+    # backend depedent
+    # xxx finish
+    # xxx how to skip a goal?
+
+    def backendopt(self, argtypes=None, **kwds):
+        self.update_options(argtypes, kwds)
+        self.ensure_backend()
+        self.driver.backendopt()
 
-    def source(self, argtypes, **kwds):
+    def backendopt_c(self, argtypes=None, **kwds):
+        self.update_options(argtypes, kwds)
+        self.ensure_backend('c')
+        self.driver.backendopt()
+            
+    def source(self, argtypes=None, **kwds):
         backend = self.ensure_backend()
         self.update_options(argtypes, kwds)
         getattr(self.driver, 'source_'+backend)()
        
-    def source_c(self, argtypes, **kwds):
+    def source_c(self, argtypes=None, **kwds):
         self.ensure_backend('c')
         self.update_options(argtypes, kwds)
         self.driver.source_c()
+
+    def source_llvm(self, argtypes=None, **kwds):
+        self.ensure_backend('llvm')
+        self.update_options(argtypes, kwds)
+        self.driver.source_c()
         

Modified: pypy/dist/pypy/translator/test/test_interactive.py
==============================================================================
--- pypy/dist/pypy/translator/test/test_interactive.py	(original)
+++ pypy/dist/pypy/translator/test/test_interactive.py	Sun Jan  8 23:22:18 2006
@@ -38,3 +38,36 @@
     t = Translation(f, [int, int])
     t.annotate()
     py.test.raises(Exception, "t.rtype([int, int],debug=False)")
+
+def test_simple_backendopt():
+    def f(x, y):
+        return x,y
+
+    t = Translation(f, [int, int], backend='c')
+    t.backendopt()
+
+    t = Translation(f, [int, int])
+    t.backendopt_c()
+
+    t = Translation(f, [int, int])
+    py.test.raises(Exception, "t.backendopt()")
+
+def test_simple_source():
+    def f(x, y):
+        return x,y
+
+    t = Translation(f, backend='c')
+    t.annotate([int, int])
+    t.source()
+
+    t = Translation(f, [int, int])
+    t.source_c()
+
+    # this doesn't work, there is to be a bug in llvm backend code
+    #t = Translation(f, [int, int], backend='llvm')
+    #t.source()
+    #t = Translation(f, [int, int])
+    #t.source_llvm()
+
+    t = Translation(f, [int, int])
+    py.test.raises(Exception, "t.source()")



More information about the Pypy-commit mailing list