What do you think about JVM backend for Nim? For example, my main project consists of three parts. Frontend is written in JavaScript, so I can implement it in Nim. Second part is client's proxy for HTTPS, digital signature, scanning and so on, it's C++, and here I can use Nim too. But backend is written in Scala. And here is the problem.
Maybe someone thought about it too?
From http://nim-lang.org/question.html
What about JVM/CLR backends?
A JVM backend is almost impossible. The JVM is not expressive enough. It has never been designed as a general purpose VM anyway. A CLR backend is possible but would require much work.
Maybe it's outdated info? There are many languages that use JVM as the general purpose VM. And low level too, for example, here is C to JVM tools: https://github.com/davidar/lljvm:
Functions are mapped to individual JVM methods, and all function calls are made
with native JVM invocation instructions. This allows compiled code to be linked
against arbitrary Java classes, and Java programs to natively call individual
functions in the compiled code. It also allows programs to be split across
multiple classes (comparable to dynamic linking), rather than statically linking
everything into a single class.
It's not just cast, it uses bit representation. For example, one of the casts:
The java.lang.Double.longBitsToDouble() method returns the double value corresponding to a given
bit representation. The argument is considered to be a representation of a floating-point value
according to the IEEE 754 floating-point "double format" bit layout.
And from LLVM docs: "The ‘bitcast‘ instruction converts value to type ty2 without changing any bits.". I tried pointer cast for js backend:
var x = 1
var y = 2
proc calc(x: uint64, y: uint64) =
echo cast[ptr int](x)[] + cast[ptr int](y)[]
calc(cast[uint64](x.addr), cast[uint64](y.addr))
, but the compiler failed with the error:
pointers.nim(5, 24) Error: internal error: genDeref
Is this code must be valid for js backend?