[pypy-svn] r15599 - in pypy/dist/pypy/translator: . c c/src goal

arigo at codespeak.net arigo at codespeak.net
Thu Aug 4 11:42:02 CEST 2005


Author: arigo
Date: Thu Aug  4 11:41:59 2005
New Revision: 15599

Added:
   pypy/dist/pypy/translator/goal/app_basic_example.py
      - copied unchanged from r15587, pypy/dist/pypy/translator/goal/app_example.py
   pypy/dist/pypy/translator/goal/targetpypystandalone.py
      - copied, changed from r15588, pypy/dist/pypy/translator/goal/targetpypymain.py
Modified:
   pypy/dist/pypy/translator/c/funcgen.py
   pypy/dist/pypy/translator/c/src/g_include.h
   pypy/dist/pypy/translator/goal/app_main.py
   pypy/dist/pypy/translator/goal/targetpypymain.py
   pypy/dist/pypy/translator/goal/translate_pypy.py
   pypy/dist/pypy/translator/translator.py
Log:
Support for stand-alone translation targets, with a standalone PyPy in
targetpypystandalone.py:

* added the standalone flag to Translator.ccompile(), for convenience
* app_main.entry_point() now takes an explicit argument for sys.executable
* app_basic_example.py is the previous version of app_example.py, i.e. the
    one not dropping in the interactive console (otherwise, we get the
    interactive console at the beginning of translate_pypy)
* always #include "Python.h" for now, for the macros
* fix for a bug I'm not sure I understood fully -- avoids "None" PyObject
    constants.  (might be introduced by backend_optimizations.)


Modified: pypy/dist/pypy/translator/c/funcgen.py
==============================================================================
--- pypy/dist/pypy/translator/c/funcgen.py	(original)
+++ pypy/dist/pypy/translator/c/funcgen.py	Thu Aug  4 11:41:59 2005
@@ -38,7 +38,7 @@
                     mix.extend(link.args)
                     if hasattr(link, 'llexitcase'):
                         self.more_ll_values.append(link.llexitcase)
-                    else:
+                    elif link.exitcase is not None:
                         mix.append(Constant(link.exitcase))
         traverse(visit, graph)
         resultvar = graph.getreturnvar()

Modified: pypy/dist/pypy/translator/c/src/g_include.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/g_include.h	(original)
+++ pypy/dist/pypy/translator/c/src/g_include.h	Thu Aug  4 11:41:59 2005
@@ -2,8 +2,12 @@
 /************************************************************/
 /***  C header file for code produced by genc.py          ***/
 
+/* XXX for now we always include Python.h even to produce stand-alone
+ * executables (which are *not* linked against CPython then),
+ * to get the convenient macro definitions
+ */
+#include "Python.h"
 #ifndef PYPY_STANDALONE
-#  include "Python.h"
 #  include "compile.h"
 #  include "frameobject.h"
 #  include "structmember.h"

Modified: pypy/dist/pypy/translator/goal/app_main.py
==============================================================================
--- pypy/dist/pypy/translator/goal/app_main.py	(original)
+++ pypy/dist/pypy/translator/goal/app_main.py	Thu Aug  4 11:41:59 2005
@@ -2,9 +2,9 @@
 # XXX very incomplete!  Blindly runs the file named as first argument.
 # No option checking, no interactive console, no fancy hooks.
 
-def entry_point(argv):
+def entry_point(executable, argv):
     import sys
-    sys.executable = "pypy" 
+    sys.executable = executable
     sys.argv = argv
     # with PyPy in top of CPython we can only have around 100 
     # but we need more in the translated PyPy for the compiler package 

Modified: pypy/dist/pypy/translator/goal/targetpypymain.py
==============================================================================
--- pypy/dist/pypy/translator/goal/targetpypymain.py	(original)
+++ pypy/dist/pypy/translator/goal/targetpypymain.py	Thu Aug  4 11:41:59 2005
@@ -32,8 +32,9 @@
     for arg in argv: 
         debug(" argv -> " + arg)
     try:
+        w_executable = space.wrap("pypy")
         w_argv = space.newlist([space.wrap(s) for s in argv])
-        w_exitcode = space.call_function(w_entry_point, w_argv)
+        w_exitcode = space.call_function(w_entry_point, w_executable, w_argv)
         # try to pull it all in
     ##    from pypy.interpreter import main, interactive, error
     ##    con = interactive.PyPyConsole(space)
@@ -67,7 +68,7 @@
     w_entry_point = space.getitem(w_dict, space.wrap('entry_point'))
 
     # sanity-check: call the entry point
-    res = entry_point("app_example.py")
+    res = entry_point("app_basic_example.py")
     assert res == 0
 
     return entry_point, [SomeString()]

Copied: pypy/dist/pypy/translator/goal/targetpypystandalone.py (from r15588, pypy/dist/pypy/translator/goal/targetpypymain.py)
==============================================================================
--- pypy/dist/pypy/translator/goal/targetpypymain.py	(original)
+++ pypy/dist/pypy/translator/goal/targetpypystandalone.py	Thu Aug  4 11:41:59 2005
@@ -22,18 +22,14 @@
 
 # __________  Entry point  __________
 
-def entry_point(argvstring):
+def entry_point(argv):
     debug("entry point starting") 
-    debug(argvstring) 
-    if argvstring: 
-        argv = [argvstring]
-    else:
-        argv = []
     for arg in argv: 
         debug(" argv -> " + arg)
     try:
-        w_argv = space.newlist([space.wrap(s) for s in argv])
-        w_exitcode = space.call_function(w_entry_point, w_argv)
+        w_executable = space.wrap(argv[0])
+        w_argv = space.newlist([space.wrap(s) for s in argv[1:]])
+        w_exitcode = space.call_function(w_entry_point, w_executable, w_argv)
         # try to pull it all in
     ##    from pypy.interpreter import main, interactive, error
     ##    con = interactive.PyPyConsole(space)
@@ -67,18 +63,8 @@
     w_entry_point = space.getitem(w_dict, space.wrap('entry_point'))
 
     # sanity-check: call the entry point
-    res = entry_point("app_example.py")
+    res = entry_point(["pypy", "app_basic_example.py"])
     assert res == 0
 
-    return entry_point, [SomeString()]
+    return entry_point, None
 
-def get_llinterp_args():
-    from pypy.rpython import rstr
-    ll_str = rstr.string_repr.convert_const("app_example.py")
-    return [ll_str]
-
-
-# _____ Run translated _____
-def run(c_entry_point):
-    exitcode = c_entry_point(os.path.join(this_dir, 'app_example.py'))
-    assert exitcode == 0

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 Aug  4 11:41:59 2005
@@ -72,6 +72,7 @@
 from pypy.translator.translator import Translator
 from pypy.translator.ann_override import PyPyAnnotatorPolicy
 from pypy.annotation import model as annmodel
+from pypy.annotation import listdef
 from pypy.tool.cache import Cache
 from pypy.annotation.model import SomeObject
 from pypy.tool.udir import udir 
@@ -93,7 +94,7 @@
 # __________  Main  __________
 
 def analyse(target):
-    global t, entry_point, inputtypes
+    global t, entry_point, inputtypes, standalone
 
     if target:
         entry_point, inputtypes = target()
@@ -103,6 +104,11 @@
         # otherwise we have been loaded
         a = t.annotator
         t.frozen = False
+    standalone = inputtypes is None
+    if standalone:
+        ldef = listdef.ListDef(None, annmodel.SomeString())
+        inputtypes = [annmodel.SomeList(ldef)]
+
     if listen_port:
         run_async_server()
     if not options['-no-a']:
@@ -590,16 +596,20 @@
             print 'Not generating C code.'
         elif options['-c']:
             print 'Generating C code without compiling it...'
-            filename = t.ccompile(really_compile=False)
+            filename = t.ccompile(really_compile=False,
+                                  standalone=standalone)
             update_usession_dir()
             print 'Written %s.' % (filename,)
         else:
             print 'Generating and compiling C code...'
-            c_entry_point = t.ccompile()
+            c_entry_point = t.ccompile(standalone=standalone)
             update_usession_dir()
             if not options['-o']:
                 print 'Running!'
-                targetspec_dic['run'](c_entry_point)
+                if standalone:
+                    os.system(c_entry_point)
+                else:
+                    targetspec_dic['run'](c_entry_point)
     except SystemExit:
         raise
     except:

Modified: pypy/dist/pypy/translator/translator.py
==============================================================================
--- pypy/dist/pypy/translator/translator.py	(original)
+++ pypy/dist/pypy/translator/translator.py	Thu Aug  4 11:41:59 2005
@@ -252,17 +252,19 @@
         mod = make_module_from_pyxstring(name, udir, pyxcode)
         return getattr(mod, name)
 
-    def ccompile(self, really_compile=True):
+    def ccompile(self, really_compile=True, standalone=False):
         """Returns compiled function (living in a new C-extension module), 
            compiled using the C generator.
         """
         if self.annotator is not None:
             self.frozen = True
-        cbuilder = self.cbuilder(standalone=False)
+        cbuilder = self.cbuilder(standalone=standalone)
         c_source_filename = cbuilder.generate_source()
         if not really_compile: 
             return c_source_filename
         cbuilder.compile()
+        if standalone:
+            return cbuilder.executable_name
         cbuilder.import_module()    
         return cbuilder.get_entry_point()
 



More information about the Pypy-commit mailing list