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

arigo at codespeak.net arigo at codespeak.net
Sat May 6 12:13:09 CEST 2006


Author: arigo
Date: Sat May  6 12:13:08 2006
New Revision: 26852

Modified:
   pypy/dist/pypy/translator/driver.py
   pypy/dist/pypy/translator/goal/translate.py
   pypy/dist/pypy/translator/interactive.py
Log:
Allow the interactive.Translation to compile stand-alone executables too.


Modified: pypy/dist/pypy/translator/driver.py
==============================================================================
--- pypy/dist/pypy/translator/driver.py	(original)
+++ pypy/dist/pypy/translator/driver.py	Sat May  6 12:13:08 2006
@@ -42,7 +42,7 @@
 class TranslationDriver(SimpleTaskEngine):
 
     def __init__(self, options=None, default_goal=None, disable=[],
-                 exe_name = 'target-%(backend)s', extmod_name=None):
+                 exe_name=None, extmod_name=None):
         SimpleTaskEngine.__init__(self)
 
         self.log = log
@@ -155,6 +155,10 @@
         annotator = translator.buildannotator(policy=policy)
         s = annotator.build_types(self.entry_point, self.inputtypes)
         self.sanity_check_annotation()
+        if self.standalone and s.knowntype != int:
+            raise Exception("stand-alone program entry point must return an "
+                            "int (and not, e.g., None or always raise an "
+                            "exception).")
         annotator.simplify()
         return s
     #
@@ -267,14 +271,15 @@
     task_source_c = taskdef(task_source_c, ['database_c'], "Generating c source")
 
     def create_exe(self):
-        import shutil
-        exename = mkexename(self.c_entryp)
-        newexename = self.exe_name % self.options.__dict__
-        if '/' not in newexename and '\\' not in newexename:
-            newexename = './' + newexename
-        newexename = mkexename(newexename)
-        shutil.copy(exename, newexename)
-        self.c_entryp = newexename
+        if self.exe_name is not None:
+            import shutil
+            exename = mkexename(self.c_entryp)
+            newexename = self.exe_name % self.options.__dict__
+            if '/' not in newexename and '\\' not in newexename:
+                newexename = './' + newexename
+            newexename = mkexename(newexename)
+            shutil.copy(exename, newexename)
+            self.c_entryp = newexename
         self.log.info("created: %s" % (self.c_entryp,))
 
     def task_compile_c(self): # xxx messy
@@ -346,7 +351,7 @@
     def task_compile_llvm(self):
         gen = self.llvmgen
         if self.standalone:
-            exe_name = self.exe_name % self.options.__dict__
+            exe_name = (self.exe_name or 'testing') % self.options.__dict__
             self.c_entryp = gen.compile_llvm_source(exe_name=exe_name)
             self.create_exe()
         else:
@@ -420,9 +425,6 @@
             options = DEFAULT_OPTIONS
 
         driver = TranslationDriver(options, default_goal, disable)
-        if '__name__' in targetspec_dic:
-            driver.exe_name = targetspec_dic['__name__'] + '-%(backend)s'
-
         target = targetspec_dic['target']
         spec = target(driver, args)
 

Modified: pypy/dist/pypy/translator/goal/translate.py
==============================================================================
--- pypy/dist/pypy/translator/goal/translate.py	(original)
+++ pypy/dist/pypy/translator/goal/translate.py	Sat May  6 12:13:08 2006
@@ -316,6 +316,9 @@
                                                       default_goal='compile')
         pdb_plus_show.expose({'drv': drv})
 
+        if drv.exe_name is None and '__name__' in targetspec_dic:
+            drv.exe_name = targetspec_dic['__name__'] + '-%(backend)s'
+
         goals = options.goals
         drv.proceed(goals)
         

Modified: pypy/dist/pypy/translator/interactive.py
==============================================================================
--- pypy/dist/pypy/translator/interactive.py	(original)
+++ pypy/dist/pypy/translator/interactive.py	Sat May  6 12:13:08 2006
@@ -73,24 +73,31 @@
             used_opts = dict.fromkeys(self.GOAL_USES_OPTS[goal], True)
             self.frozen_options.update(used_opts)
 
-    def ensure_setup(self, argtypes=None, policy=None):
+    def ensure_setup(self, argtypes=None, policy=None, standalone=False):
         if not self.driver_setup:
-            if argtypes is None:
-                 argtypes = []
+            if standalone:
+                assert argtypes is None
+            else:
+                if argtypes is None:
+                    argtypes = []
             self.driver.setup(self.entry_point, argtypes, policy, empty_translator=self.context)
             self.ann_argtypes = argtypes
             self.ann_policy = policy
             self.driver_setup = True
         else:
             # check consistency
-            if argtypes is not None and argtypes != self.ann_argtypes:
+            if standalone:
+                assert argtypes is None
+                assert self.ann_argtypes is None
+            elif argtypes is not None and argtypes != self.ann_argtypes:
                 raise Exception("inconsistent argtype supplied")
             if policy is not None and policy != self.ann_policy:
                 raise Exception("inconsistent annotation polish supplied")
 
     def update_options(self, argtypes, kwds):
-        if argtypes or kwds.get('policy'):
-            self.ensure_setup(argtypes, kwds.get('policy'))
+        if argtypes or kwds.get('policy') or kwds.get('standalone'):
+            self.ensure_setup(argtypes, kwds.get('policy'),
+                                        kwds.get('standalone'))
         for optname, value in kwds.iteritems():
             if optname in self.frozen_options:
                 if getattr(self.driver.options, optname) != value:



More information about the Pypy-commit mailing list