Well the Perl would compile into something like this (I wrote this in PIR instead of PASM because I am not that much of a masocist :)
.namespace [ "MyPerlClass" ]
.sub "__onload" :load
.local pmc klass
newclass klass, "MyPerlClass"
.return ()
.end
.sub foo
$S0 = "MyPerlClass::foo"
.return($S0)
.end
.sub bar
$S0 = "MyPerlClass::bar"
.return($S0)
.end
And the Java would compile into something like this:
.namespace [ "MyJavaClass" ]
.sub "__onload" :load
.local pmc klass
$P0 = getclass "MyPerlClass" # load the Perl class
subclass klass, $P0, "MyJavaClass"
.return ()
.end
.sub output
.local pmc System
.local pmc String
$S0 = self.foo()
$S1 = self.bar()
concat $S2, $S0, $S1
# assume that the Java
# standard libraries exist
System = getclass "java.lang.System"
String = getclass "java.lang.String"
# assume that a String object can be
# constructed from a native Parrot string
$P0 = String.new($S2)
$P1 = System.out()
$P1.println($P0)
.return ()
.end
Of course I am simpliying here, Java classes would need to inherit from java.lang.Object somehow, so maybe the Java compiler writer would have a special PMC specifically for Java classes (although compatible with normal PMC classes too). As for how we know that the return values of self.foo() and self.bar() are Parrot strings and not java.lang.String. It is not outside the range of the compiler's abilities to determine this, especially since it would be known that foo and bar are not defined in MyJavaClass, and could (maybe) be assumed to be coming from MyPerlClass. Of course it does get trickier if either of those methods actually came from MyPythonClass which maybe MyPerlClass would inherit from (not shown in the example).
But what I am trying to get at really is that once everything is compiled to PIR/PASM, it really doesn't make much difference. Most of the problems you are bringing up are problems that the compiler writers will have, and should not be problems that users are made to deal with. If users have to deal with these issues, then the compiler is not doing it's job correctly.
UPDATE:
I forgot to address your last question :)
Add or concatonate? The programmer still needs additional interfacing definitions, or castings or something. It doesn't look seamless.
Does the programmer need to deal with this in regular (non Parrot) Java? Of course not javac handles it. Why would a Java to Parrot compiler be any different? Given enough static anaylsis, this is a likely a fairly trivial case.
|