Bridging the chasm

Paul Prescod paul at prescod.net
Sat Oct 16 10:58:17 EDT 1999


Apologies if I missed an earlier discussion of this idea.

Increasingly I have this problem that there is a lot of cool software in
the "Java world" and a lot of cool software in the "C" world and I want
to use them together. CPython is awesome for gluing together "C" stuff
and JPython is awesome for gluing together "Java" stuff but there is no
glue between them. I propose (for Python 2) to abolish the distinction
between CPython and JPython and have a single Python implementation that
can talk to both worlds.

Obviously such an implementation would need to be written in C (or C++).
Obviously it would also need to embed a Java Virtual Machine in order to
run Java code. Managing these requirement is not a problem: after all,
every virtual machine is already written in C++ and there is a lot of
JVM code around that we could use as a starting point for our new Python
interpreter.

Of course a Python interpreter also needs a Python virtual machine and a
Python compiler. Well if we've already got a JVM and we've already got
JPython then we HAVE a python compiler and virtual machine.

Of course if this were all there were to it, I'd be really proposing
that we just get rid of CPython in favor of JPython. That's not what I'm
proposing, however. Unlike today's JPython, I believe that we should
have our OWN implementation of the JVM with the following features:

 * optimized "extension" byte codes for common Python-specific
primitives like INVOKE_DYNAMIC

 * support for "Python-style" embedding in C (maybe backwards
compatible, maybe only similar)

 * Python finalization semantics

 * Circular reference detection and removal

 * a combined Python/Java stack

As we add type inferencing and type declarations to Python we could use
the appropriate Java bytecodes.

I propose that all of the "extension" byte codes be optional
optimizations for code that can be otherwise implemented by a "runtime"
class library like the current JPython runtime. Running Python with a
-compile_java option could compile to "pure" bytecodes in "real" Java
classfiles. Those classfiles could be used on regular JVM
implementations. 

Of course if you leave the Python interpreter then you may lose

 a) speed (in some cases)
 b) compatibility with "C" extensions
 c) reliable finalization

But you might gain portability and speed (in some cases).

 Paul Prescod




More information about the Python-list mailing list