
Show HN: Asmble – Compile WebAssembly to the JVM - kodablah
https://github.com/cretz/asmble
======
hackcasual
> Everyone is focused on targeting WASM with several languages but is missing
> the big problem: lack of a standard library

I'm not so sure that's a problem that would benefit WASM to solve. Right now
the imports Emscripten provide are the defacto standard lib, which does shape
how other projects approach WASM.

I feel a large reason behind seeing so many interesting toy projects that use
WASM (and it's quick cross browser adoption) is due to it having such a small
scope. Define a portable, easily optimizable VM.

The big challenge there is to support higher level concepts like GC, you need
to make that work at a machine level, not a standard library level.

~~~
kodablah
Agreed it is not for WASM to solve. I'm just stating the ecosystem issue
because everyone thinks compiling their favorite language to WASM provides
immediate interoperability.

~~~
wrmsr
When I was working on it the accepted solution was to compile as linux and
statically link musl into the wasm binary, leaving mostly __syscallN symbols
unresolved. As such it's a matter of implementing those on an as-needed basis
(in javascript for emscripten and in java here). I at least successfully got
sqlite opening a database in a pure java transpile that way. While it's a
possibly inelegant approach on the face of it linux does at least have an
aggressive 'dont break userspace' attitude and there is longstanding prior art
for this on freebsd.

see:
[https://github.com/kripken/emscripten/blob/6dc4ac5f9e4d8484e...](https://github.com/kripken/emscripten/blob/6dc4ac5f9e4d8484e273e4dcc554f809738cedd6/src/library_syscall.js)

------
wrmsr
Hey, I wrote one of those too :P I went the route of compiling to java source
code rather than bytecode though. I'll definitely give this a look through
when I get some free time, glad to see others want it to happen (though as you
allude to jvmci / truffle / sulong and friends are kind of a game changer).

* [https://github.com/wrmsr/wava](https://github.com/wrmsr/wava) \- be forewarned though I never got around to giving it any polish and it's based on a dated version of wasm

~~~
kodablah
Nice! I too thought about transpiling to it (as I have in other projects
transpiling to things like Go) but I wanted to see how close to the bytecode I
could get some of the translations.

------
EpicBlackCrayon
I think we've come full circle.

~~~
elviejo
to java applets??

I don't quite get the joke...

~~~
indolering
HN should convert the homepage to a transcompiled Java Applet for the next
April Fools.

------
sqeaky
I see what it is and I think I understand what it does, at least as far as the
high level description goes. I am re-working some C++ code to work when built
with emscripten as asm.js and I have a passing familiarity with web assembly.

But why does this webassembly to JVM bytecode converter exist?

Is this some kind of research project? If so, great no more explanation
someone wanted to see their limits and learn in the process, great.

Is this for some professional purpose? If so then I am much more curious. Who
has a need to convert stuff in the browser to JVM code, and what benefit do
they gain?

~~~
kodablah
I touched on it in the README FAQ under "Why?". Basically I am just doing it
for fun and becoming more familiar w/ the technologies involved.

Also, it's not "convert stuff in the browser", WebAssembly has non-web goals
[0]. There can be benefit in libraries sharing a common bytecode.

0 - [http://webassembly.org/docs/non-web/](http://webassembly.org/docs/non-
web/)

~~~
sqeaky
"Just for fun" is a great reason.

I was unaware of the non-web goals of WebAssembly, Thank you.

------
mwcampbell
Might this be useful for incorporating C or C++ code in an Android app without
having to use the NDK, compile for multiple architectures, and have to use JNI
to bridge to the Dalvik/ART world?

~~~
kodablah
Probably not without some considerable effort. I touched on this in the README
FAQ, but basically to use Emscripten-compiled code with this, a runtime layer
will need to be written which I haven't done yet.

------
jeffreportmill1
Where are the Java bytecode to WASM compilers?

~~~
niftich
TeaVM [1] does this, but I don't know much about it.

[1]
[https://github.com/konsoletyper/teavm](https://github.com/konsoletyper/teavm)

