[pypy-svn] r41725 - in pypy/dist/pypy: doc translator translator/jvm

niko at codespeak.net niko at codespeak.net
Fri Mar 30 18:27:10 CEST 2007


Author: niko
Date: Fri Mar 30 18:27:09 2007
New Revision: 41725

Modified:
   pypy/dist/pypy/doc/getting-started.txt
   pypy/dist/pypy/translator/driver.py
   pypy/dist/pypy/translator/interactive.py
   pypy/dist/pypy/translator/jvm/node.py
Log:
integrate jvm backend with interactive translator and update the docs

Modified: pypy/dist/pypy/doc/getting-started.txt
==============================================================================
--- pypy/dist/pypy/doc/getting-started.txt	(original)
+++ pypy/dist/pypy/doc/getting-started.txt	Fri Mar 30 18:27:09 2007
@@ -557,25 +557,38 @@
 Translating RPystone to JVM code
 ++++++++++++++++++++++++++++++++
 
-Although the JVM backend has not yet been integrated with the
-interactive translator, you can use it to translate the RPystone
-benchmark with the ``pypy/goal/translate.py`` script.
+Although the JVM backend cannot yet translate the entire interpreter,
+you can use it with the interactive shell for small functions, and 
+with the ``pypy/goal/translate.py`` for some larger benchmarks such as
+RPystone.
+
+Using the interactive shell with the JVM is basically the same as any
+other backend.  For example, you might enter:
+
+    >>> def myfunc(a, b):
+    ...     return a+b
+    >>> t = Translation(myfunc)
+    >>> t.annotate([int, int])
+    >>> f = t.compile_jvm()
+    >>> f(4, 5)
+    9
+
+As with the CLI, the object returned by ``compile_jvm`` is a wrapper
+around the real executable.  When invoked, it actually starts a JVM
+process, passing the parameters as command line arguments and the
+result as a string over stdout. Therefore, the interface works best
+with simple types like integers and strings.
+
+If you prefer to run the compiled code directly, you will find it in
+one of the ``/tmp/usession-*`` directories.  You can run it like so:
 
-To do so, run the following commands:
+    $java -cp /tmp/usession-<username>/pypy/ pypy.Main 4 5
+    9
 
-    $ cd pypy/translator/goal/
-    $ python translate.py -b jvm targetrpystonedalone.py
-    ... lots of output follows ...
+Note that the main entrypoint is always ``pypy.Main``.
 
-If all is successful, the resulting files will be stored in the
-``/tmp/usession-*`` directories.  It can be executed as follows:
-
-    $ java -cp /tmp/usession-<username>/pypy pypy.Main
-    RPystone(41682) time for 10000000 passes = 13.0
-    This machine benchmarks at 769230.7692307692 pystones/second
-
-To successfully use the JVM, however, you will need to have both a
-`JDK`_ installed (at least version 5), and the `Jasmin assembler`_.
+To successfully use the JVM you will need to have both a `JDK`_
+installed (at least version 5), and the `Jasmin assembler`_.
 Furthermore, you need a script on your path called ``jasmin`` which
 runs the Jasmin jar file, something like the following:
 
@@ -586,9 +599,6 @@
     #!/bin/bash
     java -jar $PATH_TO_JASMIN_JAR "$@"
 
-As the JVM backend matures, it will naturally be more fully
-integrated into the PyPy toolchain.  
-
 A slightly larger example
 +++++++++++++++++++++++++
 

Modified: pypy/dist/pypy/translator/driver.py
==============================================================================
--- pypy/dist/pypy/translator/driver.py	(original)
+++ pypy/dist/pypy/translator/driver.py	Fri Mar 30 18:27:09 2007
@@ -677,7 +677,8 @@
         from pypy.translator.jvm.node import EntryPoint
 
         entry_point_graph = self.translator.graphs[0]
-        entry_point = EntryPoint(entry_point_graph, False, False)
+        is_func = not self.standalone
+        entry_point = EntryPoint(entry_point_graph, is_func, is_func)
         self.gen = GenJvm(udir, self.translator, entry_point)
         self.jvmsource = self.gen.generate_source()
         self.log.info("Wrote JVM code")
@@ -686,6 +687,7 @@
 
     def task_compile_jvm(self):
         self.jvmsource.compile()
+        self.c_entryp = lambda *args: eval(self.jvmsource.execute(args))
         self.log.info("Compiled JVM source")
     task_compile_jvm = taskdef(task_compile_jvm, ['source_jvm'],
                               'Compiling JVM source')

Modified: pypy/dist/pypy/translator/interactive.py
==============================================================================
--- pypy/dist/pypy/translator/interactive.py	(original)
+++ pypy/dist/pypy/translator/interactive.py	Fri Mar 30 18:27:09 2007
@@ -176,3 +176,14 @@
         self.update_options(argtypes, kwds)
         self.ensure_backend('cli')
         self.driver.source_cli()
+
+    def compile_jvm(self, argtypes=None, **kwds):
+        self.update_options(argtypes, kwds)
+        self.ensure_backend('jvm')
+        self.driver.compile_jvm()
+        return self.driver.c_entryp
+
+    def source_jvm(self, argtypes=None, **kwds):
+        self.update_options(argtypes, kwds)
+        self.ensure_backend('jvm')
+        self.driver.source_jvm()

Modified: pypy/dist/pypy/translator/jvm/node.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/node.py	(original)
+++ pypy/dist/pypy/translator/jvm/node.py	Fri Mar 30 18:27:09 2007
@@ -55,6 +55,8 @@
         'graph' --- The initial graph to invoke from main()
         'expandargs' --- controls whether the arguments passed to main()
         are passed as a list, or expanded to match each argument to the graph
+        'printresult' --- controls whether the result is printed to stdout
+        when the program finishes
 
         The 'expandargs' option deserves explanation:
         



More information about the Pypy-commit mailing list