Re: Java bytecode to WebAssembly compiler

Hey Alexey!

Quickie personal note: I'm experimenting with a similar project for the 
.NET world; languages like C# etc.

An important note, from what I can tell from your project, is that you 
might be taking the wrong approach. WebAssembly doesn't currently have 
GC - you've got to manually allocate memory so outputting WebAssembly is 
very different from outputting JavaScript source as your project 
currently does. What others have typically been trying is port a C++ 
Java VM through to WebAssembly via Emscripten with mixed success. 
Essentially porting all the system calls that Java VM's do to web APIs 
is a big task - it seems like your project has covered many of those 
already though? So, the best approach is probably a kind of hybrid - 
port a C++ VM and hook in your system call wrapper code. At least until 
WebAssembly gains GC anyway (it's being pulled in lots of directions so 
that's quite a way off yet), at which point going directly from 
Java->WebAssembly would get a lot simpler.

As for the actual errors you're seeing, it seems like you're missing 
some value(s) from your wasm stream and it's basically going out of 
alignment. I haven't taken a look at your source yet though so the best 
thing to do would be open up an issue on the WebAssembly Github design 
repo (https://github.com/WebAssembly/design) and reference your source 
file(s) which output the wasm. That'll save people searching your repo 
to find where the wasm files come from so you'll more likely get some 
useful help.

Hope that helps anyway! VM's are awesome; I wish you all the best :)
Luke Briggs
----------------
Head developer,
Kulestar UK

On 2016-09-03 13:37, Alexey Andreev wrote:
> I'm developing my project called TeaVM which is capable of compiling
> JVM bytecode to JavaScript. Now I'm trying to emit proper WebAssembly
> output, and I have some results already. I use wasm command that I
> compiled from ml-proto to debug my compiler. Currently, my compiler
> produces both wast and binary formats. However, when I try to run
> binary file in browsers, they report errors. Here is my example:
> http://teavm.org/live-examples/wasm/
> 
> Google Chrome 53.0.2785.89 says: Uncaught (in promise)
> Wasm.instantiateModule(): Result = section "code" shorter (16199
> bytes) than specified (17858 bytes) @+16878
> 
> Firefox nightly 51.0a1 (2016-09-02) says: TypeError: wasm error:
> compile error at offset 703: bad type
> 
> With no any further information to debug the problem. Moreover, when I
> compile http://teavm.org/live-examples/wasm/classes.wast with
> ml-proto, I get the same errors.
> 
> Can anyone help me to debug the problem?

Received on Saturday, 3 September 2016 20:19:18 UTC