blue said:
ObJava: Does anyone here have much experience interoperating Java code
with code written for other languages targeting the JVM? (Jython, Clojure,
etc.) I imagine there might be problems, especially with those two, since
they're weakly typed (Python and Lisp derivatives, respectively) and Java
is strongly typed. (Even the JVM has a built in notion of types and built
in type checking, does it not? So I expect weakly typed languages
targeting the JVM have all their objects appear to be Object or some other
common type as far as the JVM bytecode verifier's view of the type system
is concerned.)
I have occasionally experimented with Jython and jGnat.
You would usually do Jython->Java not Java->Jython which somewhat
reduces the problem.
Also note that even though Object references will be used then
the actual objects will still be specific types.
Let me give an example.
J.java:
public class J {
public void print(int v) {
System.out.println("int: " + v);
}
public void print(String v) {
System.out.println("String: " + v);
}
}
P.py:
import J
o = J()
v = 123
print v
o.print(v)
v = "abc"
print v
o.print(v)
Output:
123
int: 123
abc
String: abc
Decompile of compiled Python code:
// Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov Date:
10-02-2009 21:03:36
// Home Page :
http://members.fortunecity.com/neshkov/dj.html - Check
often for new version!
// Decompiler options: packimports(3)
// Source File Name: P.java
import org.python.core.*;
public class P
{
public static class _PyInner extends PyFunctionTable
implements PyRunnable
{
private static void initConstants()
{
i$0 = Py.newInteger(123);
s$1 = Py.newString("abc");
s$2 = Py.newString("C:\\P.py");
funcTable = new _PyInner();
c$0_main = Py.newCode(0, new String[0], "C:\\P.py", "main",
false, false, funcTable, 0, null, null, 0, 0);
}
public PyCode getMain()
{
if(c$0_main == null)
initConstants();
return c$0_main;
}
public PyObject call_function(int i, PyFrame pyframe)
{
switch(i)
{
case 0: // '\0'
return main$1(pyframe);
}
return null;
}
private static PyObject main$1(PyFrame pyframe)
{
pyframe.setglobal("__file__", s$2);
pyframe.setlocal("J", imp.importOne("J", pyframe));
pyframe.setlocal("o", pyframe.getname("J").__call__());
pyframe.setlocal("v", i$0);
Py.println(pyframe.getname("v"));
pyframe.getname("o").invoke("print", pyframe.getname("v"));
pyframe.setlocal("v", s$1);
Py.println(pyframe.getname("v"));
pyframe.getname("o").invoke("print", pyframe.getname("v"));
return Py.None;
}
private static PyObject i$0;
private static PyObject s$1;
private static PyObject s$2;
private static PyFunctionTable funcTable;
private static PyCode c$0_main;
public _PyInner()
{
}
}
public P()
{
}
public static void moduleDictInit(PyObject pyobject)
{
pyobject.__setitem__("__name__", new PyString("P"));
Py.runCode((new _PyInner()).getMain(), pyobject, pyobject);
}
public static void main(String args[])
throws Exception
{
String args1[] = new String[args.length + 1];
args1[0] = "P";
System.arraycopy(args, 0, args1, 1, args.length);
Py.runMain(P$_PyInner.class, args1, jpy$packages,
jpy$mainProperties, null, new String[] {
"P"
});
}
static String jpy$mainProperties[] = {
"python.modules.builtin", "exceptions

rg.python.core.exceptions"
};
static String jpy$proxyProperties[] = {
"python.modules.builtin",
"exceptions

rg.python.core.exceptions",
"python.options.showJavaExceptions", "true"
};
static String jpy$packages[] = new String[0];
}
Also, what else has targeted the JVM in the way of ports of preexisting
languages? Smalltalk and Eiffel would be interesting. I've never seen an
Eiffel with a good host integration/network/gui/goodies library, but one
that readily interoperated with Java would get access to one, and Eiffel
is strongly typed. Likewise, I've never seen a Smalltalk with preemptive
multithreading or decent performance, likewise, but implementing one that
used Hotspot as its VM would get you both of those pretty much for free.
The links at
http://user.cs.tu-berlin.de/~tolk/vmlanguages.html does not
all seem to be valid, but maybe you can track down the software.
Arne