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

pedronis at codespeak.net pedronis at codespeak.net
Mon Jan 9 21:39:37 CET 2006


Author: pedronis
Date: Mon Jan  9 21:39:35 2006
New Revision: 21846

Modified:
   pypy/dist/pypy/translator/goal/driver.py
   pypy/dist/pypy/translator/interactive.py
   pypy/dist/pypy/translator/test/test_interactive.py
Log:
- added Translation.disable([goal...]) to be able to specify goals/steps to skip
  (with tests)

- some fixes

- interactive.py completed with compile goals 




Modified: pypy/dist/pypy/translator/goal/driver.py
==============================================================================
--- pypy/dist/pypy/translator/goal/driver.py	(original)
+++ pypy/dist/pypy/translator/goal/driver.py	Mon Jan  9 21:39:35 2006
@@ -52,15 +52,11 @@
  
         self.done = {}
 
-        maybe_skip = []
-        if disable:
-             for goal in  self.backend_select_goals(disable):
-                 maybe_skip.extend(self._depending_on_closure(goal))
-        self.maybe_skip = dict.fromkeys(maybe_skip).keys()
+        self.disable(disable)
 
         if default_goal:
             default_goal, = self.backend_select_goals([default_goal])
-            if default_goal in self.maybe_skip:
+            if default_goal in self._maybe_skip():
                 default_goal = None
         
         self.default_goal = default_goal
@@ -91,6 +87,17 @@
                 l.append(goal)
         return l
 
+    def disable(self, to_disable):
+        self._disabled = to_disable
+
+    def _maybe_skip(self):
+        maybe_skip = []
+        if self._disabled:
+             for goal in  self.backend_select_goals(self._disabled):
+                 maybe_skip.extend(self._depending_on_closure(goal))
+        return dict.fromkeys(maybe_skip).keys()
+
+
     def setup(self, entry_point, inputtypes, policy=None, extra={}, empty_translator=None):
         standalone = inputtypes is None
         self.standalone = standalone
@@ -333,7 +340,7 @@
         elif isinstance(goals, str):
             goals = [goals]
         goals = self.backend_select_goals(goals)
-        return self._execute(goals, task_skip = self.maybe_skip)
+        return self._execute(goals, task_skip = self._maybe_skip())
 
     def from_targetspec(targetspec_dic, options=None, args=None, empty_translator=None, 
                         disable=[],

Modified: pypy/dist/pypy/translator/interactive.py
==============================================================================
--- pypy/dist/pypy/translator/interactive.py	(original)
+++ pypy/dist/pypy/translator/interactive.py	Mon Jan  9 21:39:35 2006
@@ -51,11 +51,13 @@
         'database_c': ['gc', 'stackless'],
         'source_llvm': ['gc', 'stackless'],
         'source_c': [],
+        'compile_c': [],
+        'compile_llvm': [],
     }
 
     def driver_event(self, kind, goal, func):
         if kind == 'pre':
-             print goal
+             #print goal
              self.ensure_setup()
         elif kind == 'post':
             used_opts = dict.fromkeys(self.GOAL_USES_OPTS[goal], True)
@@ -97,6 +99,10 @@
             self.update_options(None, {'gc': 'boehm'})
         return backend
 
+    # disable some goals (steps)
+    def disable(self, to_disable):
+        self.driver.disable(to_disable)
+
     # backend independent
 
     def annotate(self, argtypes=None, **kwds):
@@ -108,8 +114,6 @@
         return self.driver.rtype()
 
     # backend depedent
-    # xxx finish
-    # xxx how to skip a goal?
 
     def backendopt(self, argtypes=None, **kwds):
         self.update_options(argtypes, kwds)
@@ -122,17 +126,35 @@
         self.driver.backendopt()
             
     def source(self, argtypes=None, **kwds):
-        backend = self.ensure_backend()
         self.update_options(argtypes, kwds)
+        backend = self.ensure_backend()
         getattr(self.driver, 'source_'+backend)()
        
     def source_c(self, argtypes=None, **kwds):
-        self.ensure_backend('c')
         self.update_options(argtypes, kwds)
+        self.ensure_backend('c')
         self.driver.source_c()
 
     def source_llvm(self, argtypes=None, **kwds):
+        self.update_options(argtypes, kwds)
         self.ensure_backend('llvm')
+        self.driver.source_llvm()
+
+    def compile(self, argtypes=None, **kwds):
         self.update_options(argtypes, kwds)
-        self.driver.source_c()
-        
+        backend = self.ensure_backend()
+        getattr(self.driver, 'compile_'+backend)()
+        return self.driver.c_entryp
+       
+    def compile_c(self, argtypes=None, **kwds):
+        self.update_options(argtypes, kwds)
+        self.ensure_backend('c')
+        self.driver.compile_c()
+        return self.driver.c_entryp
+
+    def compile_llvm(self, argtypes=None, **kwds):
+        self.update_options(argtypes, kwds)
+        self.ensure_backend('llvm')
+        self.driver.compile_llvm()
+        return self.driver.c_entryp
+  

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	Mon Jan  9 21:39:35 2006
@@ -59,9 +59,11 @@
     t = Translation(f, backend='c')
     t.annotate([int, int])
     t.source()
+    assert 'source_c' in t.driver.done
 
     t = Translation(f, [int, int])
     t.source_c()
+    assert 'source_c' in t.driver.done
 
     t = Translation(f, [int, int])
     py.test.raises(Exception, "t.source()")
@@ -73,10 +75,51 @@
     def f(x,y):
         return x+y
 
-
     t = Translation(f, [int, int], backend='llvm')
     t.source(gc='boehm')
+    assert 'source_llvm' in t.driver.done
     
     t = Translation(f, [int, int])
     t.source_llvm()
+    assert 'source_llvm' in t.driver.done
     
+def test_disable_logic():
+
+    def f(x,y):
+        return x+y
+
+    t = Translation(f, [int, int])
+    t.disable(['backendopt'])
+    t.source_c()
+
+    assert 'backendopt' not in t.driver.done
+
+    t = Translation(f, [int, int])
+    t.disable(['annotate'])
+    t.source_c()
+
+    assert 'annotate' not in t.driver.done and 'rtype' not in t.driver.done
+
+    t = Translation(f, [int, int])
+    t.disable(['rtype'])
+    t.source_c()
+
+    assert 'annotate' in t.driver.done
+    assert 'rtype' not in t.driver.done and 'backendopt' not in t.driver.done
+
+def test_simple_compile_c():
+    def f(x,y):
+        return x+y
+
+    t = Translation(f, [int, int])
+    t.source(backend='c')
+    t_f = t.compile()
+
+    res = t_f(2,3)
+    assert res == 5
+
+    t = Translation(f, [int, int])
+    t_f = t.compile_c()
+
+    res = t_f(2,3)
+    assert res == 5



More information about the Pypy-commit mailing list