[pypy-svn] r17978 - pypy/dist/pypy/translator/goal

pedronis at codespeak.net pedronis at codespeak.net
Thu Sep 29 15:22:14 CEST 2005


Author: pedronis
Date: Thu Sep 29 15:22:10 2005
New Revision: 17978

Modified:
   pypy/dist/pypy/translator/goal/driver.py
   pypy/dist/pypy/translator/goal/target_pypy-llvm.py
   pypy/dist/pypy/translator/goal/targetcompiler.py
   pypy/dist/pypy/translator/goal/targetnopstandalone.py
   pypy/dist/pypy/translator/goal/targetpypymain.py
   pypy/dist/pypy/translator/goal/targetpypystandalone.py
   pypy/dist/pypy/translator/goal/translate_pypy.py
   pypy/dist/pypy/translator/goal/translate_pypy_new.py
Log:
- refactor target() signature

- change targets

- some reorg in driver



Modified: pypy/dist/pypy/translator/goal/driver.py
==============================================================================
--- pypy/dist/pypy/translator/goal/driver.py	(original)
+++ pypy/dist/pypy/translator/goal/driver.py	Thu Sep 29 15:22:10 2005
@@ -8,6 +8,13 @@
 from pypy.annotation import policy as annpolicy
 import optparse
 
+DEFAULT_OPTIONS = optparse.Values(defaults={
+  'gc': 'ref',
+  'insist': False,
+  'backend': 'c',
+  'lowmem': False,
+})
+
 def taskdef(taskfunc, deps, title, new_state=None, expected_states=[]):
     taskfunc.task_deps = deps
     taskfunc.task_title = title
@@ -17,7 +24,8 @@
 
 class TranslationDriver(SimpleTaskEngine):
 
-    def __init__(self, translator, inputtypes, policy, options, runner, disable=[]):
+    def __init__(self, translator, inputtypes, policy=None, options=None,
+                 runner=None, disable=[]):
         SimpleTaskEngine.__init__(self)
 
         self.translator = translator
@@ -28,10 +36,17 @@
             inputtypes = [annmodel.SomeList(ldef)]
         self.inputtypes = inputtypes
 
+        if policy is None:
+            policy = annpolicy.AnnotatorPolicy()            
         self.policy = policy
+        if options is None:
+            options = DEFAULT_OPTIONS
         self.options = options
         self.standalone = standalone
 
+        if runner is None:
+            def runner(f):
+                f()
         self.runner = runner
 
         self.done = {}
@@ -121,7 +136,6 @@
             newexename = mkexename('./pypy-' + backend)
             shutil.copy(exename, newexename)
             c_entryp = newexename
-        update_usession_dir()
         if standalone:
             os.system(c_entryp)
         else:
@@ -162,13 +176,31 @@
     def proceed(self, goal):
         self._execute([goal])
 
-    def __getattr__(self, name):
+    def __getattr__(self, name): # xxx
         if name in self.tasks:
             def proceed_with_task():
                 self.proceed(name)
             return proceed_with_task
         raise AttribueError, name
 
+    def from_targetspec(targetspec_dic, options=None):
+        target = targetspec_dic['target']
+        spec = target(not options.lowmem)
+        try:
+            entry_point, inputtypes, policy = spec
+        except ValueError:
+            entry_point, inputtypes = spec
+            policy = None
+
+        translator = Translator(entry_point, verbose=True, simplifying=True)
+            
+        driver = TranslationDriver(translator, inputtypes,
+                                   policy, options, targetspec_dic['run'])
+
+        return translation
+
+    from_targetspec = staticmethod(from_targetspec)
+        
 
 # xxx reorg/move around
 
@@ -181,30 +213,6 @@
     execfile(targetspec, targetspec_dic)
     return targetspec_dic
 
-DEFAULT_OPTIONS = optparse.Values(defaults={
-  'gc': 'ref',
-  'insist': False,
-  'backend': 'c',
-  'lowmem': False,
-})
-
-def make_translation(targetspec_dic, options=DEFAULT_OPTIONS):
-    policy = annpolicy.AnnotatorPolicy()
-    target = targetspec_dic['target']
-    spec = target(not options.lowmem)
-    try:
-        entry_point, inputtypes, policy = spec
-    except ValueError:
-        entry_point, inputtypes = spec
-
-    translator = Translator(entry_point, verbose=True, simplifying=True)
-    
-    translation = TranslationDriver(translator, inputtypes, policy, options, targetspec_dic['run'])
-
-    return translation
-    
-    
-    
 
 # __________ helpers
 
@@ -222,4 +230,4 @@
     percent = int(tot and (100.0*so / tot) or 0)
     print "-- someobjectness %2d (%d of %d functions polluted by SomeObjects)" % (percent, so, tot)
 
-from pypy.translator.tool.util import update_usession_dir, mkexename
+from pypy.translator.tool.util import mkexename

Modified: pypy/dist/pypy/translator/goal/target_pypy-llvm.py
==============================================================================
--- pypy/dist/pypy/translator/goal/target_pypy-llvm.py	(original)
+++ pypy/dist/pypy/translator/goal/target_pypy-llvm.py	Thu Sep 29 15:22:10 2005
@@ -44,8 +44,11 @@
 
 # _____ Define and setup target ___
 
-def target(geninterp=True):
+def target(options, args):
     global space, w_entry_point
+
+    geninterp = not getattr(options, 'lowmem', False)
+    
     # disable translation of the whole of classobjinterp.py
     StdObjSpace.setup_old_style_classes = lambda self: None
     space = StdObjSpace(nofaking=True,

Modified: pypy/dist/pypy/translator/goal/targetcompiler.py
==============================================================================
--- pypy/dist/pypy/translator/goal/targetcompiler.py	(original)
+++ pypy/dist/pypy/translator/goal/targetcompiler.py	Thu Sep 29 15:22:10 2005
@@ -23,8 +23,11 @@
     return 'target_ast_compile --> %r' % (pycode,)
 
 # _____ Define and setup target ___
-def target(geninterp=True):
+def target(options, args):
     global space, w_entry_point
+
+    geniterp = not getattr(options, 'lowmem', False)
+    
     # disable translation of the whole of classobjinterp.py
     StdObjSpace.setup_old_style_classes = lambda self: None
     # disable geninterp for now -- we have faaar toooo much interp-level code

Modified: pypy/dist/pypy/translator/goal/targetnopstandalone.py
==============================================================================
--- pypy/dist/pypy/translator/goal/targetnopstandalone.py	(original)
+++ pypy/dist/pypy/translator/goal/targetnopstandalone.py	Thu Sep 29 15:22:10 2005
@@ -11,6 +11,6 @@
 
 # _____ Define and setup target ___
 
-def target(geninterp=True):
+def target(*args):
     return entry_point, None
 

Modified: pypy/dist/pypy/translator/goal/targetpypymain.py
==============================================================================
--- pypy/dist/pypy/translator/goal/targetpypymain.py	(original)
+++ pypy/dist/pypy/translator/goal/targetpypymain.py	Thu Sep 29 15:22:10 2005
@@ -49,8 +49,11 @@
 
 # _____ Define and setup target ___
 
-def target(geninterp=True):
+def target(options, args):
     global space, w_entry_point
+
+    geninterp = not getattr(options, 'lowmem', False)
+
     # disable translation of the whole of classobjinterp.py
     StdObjSpace.setup_old_style_classes = lambda self: None
     space = StdObjSpace(nofaking=True,

Modified: pypy/dist/pypy/translator/goal/targetpypystandalone.py
==============================================================================
--- pypy/dist/pypy/translator/goal/targetpypystandalone.py	(original)
+++ pypy/dist/pypy/translator/goal/targetpypystandalone.py	Thu Sep 29 15:22:10 2005
@@ -44,9 +44,11 @@
 
 # _____ Define and setup target ___
 
-def target(geninterp=True):
+def target(options, args):
     global space, w_entry_point
 
+    geninterp = not getattr(options, 'lowmem', False)
+    
     # obscure hack to stuff the translation options into the translated PyPy
     import __main__, pypy.module.sys
     options = {}

Modified: pypy/dist/pypy/translator/goal/translate_pypy.py
==============================================================================
--- pypy/dist/pypy/translator/goal/translate_pypy.py	(original)
+++ pypy/dist/pypy/translator/goal/translate_pypy.py	Thu Sep 29 15:22:10 2005
@@ -95,7 +95,7 @@
 
 # XXX this tries to make compiling faster
 from pypy.translator.tool import cbuild
-cbuild.enable_fast_compilation()
+#cbuild.enable_fast_compilation()
 
 annmodel.DEBUG = False
 
@@ -108,7 +108,10 @@
 
     policy = AnnotatorPolicy()
     if target:
-        spec = target(not options['-t-lowmem'])
+        # forward compatibility
+        import optparse
+        opts = optparse.Values({'lowmem': options['-t-lowmem']})
+        spec = target(opts, [])
         try:
             entry_point, inputtypes, policy = spec
         except ValueError:

Modified: pypy/dist/pypy/translator/goal/translate_pypy_new.py
==============================================================================
--- pypy/dist/pypy/translator/goal/translate_pypy_new.py	(original)
+++ pypy/dist/pypy/translator/goal/translate_pypy_new.py	Thu Sep 29 15:22:10 2005
@@ -271,7 +271,7 @@
         policy = AnnotatorPolicy()
         target = targetspec_dic['target']
         if target:
-            spec = target(not cmd_line_opt.lowmem)
+            spec = target(cmd_line_opt, []) # xxx rest args
             try:
                 entry_point, inputtypes, policy = spec
             except ValueError:



More information about the Pypy-commit mailing list