Thursday, February 12, 2015

Java Frontend

Mixing languages, generated bindings, it makes development hard. Calling a Java function from C++ or Python through an FFI, converting types and objects, things quickly break apart. An alternative way to integrate with Java is with a frontend that converts it into another language, and completely bypass the JVM and Java compiler.

Java was supposed to run everywhere, but there is no official support for it on iOS, and you need to use a transpiler of some kind like Tom's j2objc to convert it to Objective-C. Rusthon's Java frontend can be used in a similar way, by converting Java into Rusthon syntax, and then translating that with the C++ backend, you have portable C++ that could be then compiled on iOS.

source code

Java Input

hand written java code example program with two class methods, foo takes a string.
public class HelloWorld {
    public static void test() {
        System.out.println("Hello, World test");

    public static void foo(String msg) {


Rusthon Output

output from java2python in rusthon syntax.

class HelloWorld(object):
    def test(cls:object):
        print("Hello, World test")

    def foo(cls:object, msg:string):

C++ Output

final translation to c++11
class HelloWorld {
 std::string __class__;
 static void test();
 static void foo(std::string msg);
 HelloWorld() {__class__ = std::string("HelloWorld");}
 virtual std::string getclassname() {return this->__class__;}
 void HelloWorld::test() {
  std::cout << std::string("Hello, World test") << std::endl;

 void HelloWorld::foo(std::string msg) {
  std::cout << msg << std::endl;

No comments:

Post a Comment