Why doesn't Sun do a C# to Java byte code compiler?

后端 未结 18 1863
清酒与你
清酒与你 2021-02-01 01:20

We Want to Run Our C# Code on the JVM

My company has a large C# code base. Well over half of this code is our core engine for creating, reading, modifying, calculating

相关标签:
18条回答
  • 2021-02-01 02:07

    If i was doing something like cross platform cross language support, I would create a 'common api' since the languages are similar in syntax you could make a translator easy enough. Then instead of calling java or .net apis directly from the core, you would call your 'common api' which would re implement the java and .net apis you would need. In this way you could create a cross language sandbox if you will. Since the main differences in java and c# are object definitions, I would get those by reflecting the C# dlls, and then reconstruct the constructs, then it would be easy to have an interpreter run through and implement the function bodies and convert properties to getters setters already knowing the structure of the files. This of course is assuming .net 2.0, some of the features in 3.0 and 3.5 become very difficult to 'interpret'

    It would be complex, but probably not as complex as reconstructing a core in java by hand, and having to have 2 teams working on them seperatly. If this idea sparks some inspiration i might create one. I would really rather see a simpler stable mono installation for mac.

    Basically I think a code level interpreter based on a set of common api classes is something very possible to write with a team in a week or two.

    0 讨论(0)
  • 2021-02-01 02:07

    I think you will find that the Mainsoft, Enterprise Edition tool allows you to run most/maybe all your .NET code under the Java JVM... Seems to be focused more on ASP.NET but will allow C#. It has been available for some time, pity they don't publicize it better!

    Warning blurb follows....

    Mainsoft® is Java-.NET interoperability software that enables IT organizations to move to Java-enabled platforms such as Linux while preserving existing investments in .NET code and skills. The software integrates seamlessly into the Visual Studio® development environment, enabling C# and Visual Basic developers to rapidly develop and maintain server and Web applications that run on Windows, Java EE platforms or both, thereby reducing application development and maintenance costs, time-to-production and total cost of ownership.

    0 讨论(0)
  • 2021-02-01 02:10

    "So, we would like to build a Java version of our core engine, ideally without maintaining a separate Java source code base."

    Basically, you want to compile your C# code unmodified, and have it run in a Java-only environment.

    IKVM is not what you want. IKVM is three main things.

    a. ikvm - CLI implementation of a Java virtual machine (note that this uses Classpath (now OpenJDK) for the Java class library).

    b. ikvmc - Compiles java bytecode to CLI bytecode.

    c. ikvmstub - Generates java stub classes that call CLI code.

    Note that all of these tools depend on CLI at runtime. What you want is exactly the opposite of IKVM, which is of course MVKI (Most Venerable Kompiler Intermediary) :):

    a. mvki - Java implementation of a CLI virtual machine (presumably this would use Mono or DotGNU for the class library).

    b. mvkic - Compiles CLI bytecode to Java bytecode.

    c. mvkistub - Generates CLI stub classes that call Java

    Note that none of these would require an existing implementation of the .NET Framework at runtime, so they should be satisfactory to your Java-only customers.

    Unfortunately, as far as I know MVKI does not exist, so you're best off doing a manual port (which would inevitably be cleaner, albeit more work).

    Edit: Based on the description of Mainsoft, it appears to be similar to MVKI, though I'm not sure what they do for the class library, and unlike IKVM it's not FOSS.

    0 讨论(0)
  • 2021-02-01 02:10

    I guess the better question is why don't you write a C# to Java byte code compiler, if you want one to exist. Waiting for corporate overlords to do something is a bad idea.

    A suggestion for creating such an implementation: take Mono's or .GNU's C# front end. Don't bother writing your own.

    0 讨论(0)
  • 2021-02-01 02:11

    Have fun.

    1. Must break checked exceptions.
    2. Must find a way to implement delegates (which are like single-method interfaces added no earlier than load time).
    0 讨论(0)
  • 2021-02-01 02:12

    JACIL is an apparently dead project that attempts to do the reverse of IKVM. Perhaps some motivated folks could use it as a starting point for a viable .Net to JVM compiler.

    0 讨论(0)
提交回复
热议问题