I would like to allow my application to be "scripted". The script language should be typed and C-like. It should have the usual control statements, primitive types, arrays, and operators that can be both found in C and Java. The scripts should be able to define functions, and call pre-defined API functions, like sin() ... that I choose to offer. If the script pass the syntax check, it would then be translated by the application to Java and then compiled on the fly, but it should also be possible to translate it to C/C++, and have it natively compiled. The syntax-check and translation to Java/C should run in the JVM. I don't need an interpreter for it, since it would always be translated to Java/C. Only a syntax-checker and translator.
Is there such a language out there? If not, what is the easiest way of doing this in the JVM, taking into consideration that I'm not knowledgeable in compiler/interpreter programming? (If I was, I would not need to ask this question ...)
If there is a "Scala" solution, it would also be fine, since I'm actually moving my Java code to Scala.
[EDIT] The only reason I want C/C++ translation is performance. I expect a lot of "bit manipulation" over arrays, which Java isn't really suited for, in particular due to range-checking at every array index operation. I also expect many objects, which costs indirectly in GC cycles.
[EDIT#2] OK, I see I have to get concrete. I am considering programming a Minecraft clone, as an exercise, to get my mind off "Business Computing". I'm talking about the engine, not the gameplay. And I'm more interested in the server-side than in the 3D, because I'm a "server guy". We're talking about using the flightweight pattern to represent millions of objects (blocks/voxels), and accessing them all many times per seconds. This isn't what the JVM was made for. Look at this article for an example of what I mean: Why we chose CPP over Java
I don't want to program everything in C/C++, but I suspect this is the only way to get a good performance. Another example of what I mean is VoltDB, which is arguably the fastest SQL database out there. They wrote it in Java and C/C++, using Java for I/O and network, and C for the heavy memory manipulation and bit fumbling. The user-written stored procedures are in Java, but I don't think it needs to be. I think it should be possible to compile to Java on the client and in tests builds, and compile to C on the server, where a full development environment can be configured.
Maybe Haxe will suit your needs. It is an intermediate high-level language that can be compiled into C++ source code. Java targets are in development.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With