RyanLamansky / dotnet-webassembly

Create, read, modify, write and execute WebAssembly (WASM) files from .NET-based applications.
Apache License 2.0
792 stars 74 forks source link

Opcode "Loop" is not permitted in intializer expressions.' #9

Closed NicolasDorier closed 5 years ago

NicolasDorier commented 5 years ago

If I try to compile: https://aois.blob.core.windows.net/public/secp256k1.wasm I get Opcode "Loop" is not permitted in intializer expressions.' when attempting to load.

RyanLamansky commented 5 years ago

I can take a closer look this weekend, but if there is indeed a loop in the initializer expression, it seems it would be in violation of the spec: https://webassembly.org/docs/modules/#initializer-expression

NicolasDorier commented 5 years ago

I see. If that is of interest, I did this to build the wasm file:

https://github.com/bitjson/bitcoin-ts/blob/master/wasm/docker/secp256k1.Dockerfile

This would suggest the compiler is not following the spec. Do you have another C to wasm compile to advise?

RyanLamansky commented 5 years ago

Unfortunately I don't; the spare time I've spent on this project has been focused on making it able to run any WASM files that already work in browsers, not actually making new WASMs of my own. And there's plenty of work left to do to get 100% of just that accomplished.

I do know that the WebAssembly working group is always looking to expand the capabilities, and it's possible that initializer expressions with loops are legal in a prototype version of the spec. If you haven't already, my instinct would be to ensure that a solid published-spec-ready compiler is used and not the latest beta/preview version.

NicolasDorier commented 5 years ago

I asked on the repo of the compiler, maybe we'll know why soon.

NicolasDorier commented 5 years ago

Just to keep you up to date, I tried with the latest version of the WASM compiler, same issue. I am trying to find relevant documentation about it.

RyanLamansky commented 5 years ago

I've been digging into this and here's the story so far:

I'm working on fixing the parser now so you can at least inspect this file. I'll see what it'll take to get it to run after that.

RyanLamansky commented 5 years ago

Parsing via Module.ReadFromBinary is now able to handle this file as of v 0.3.6-preview. To actually run it, imports for Table and Global need to be supported. This is high on my to-do list.

You can help me get this working faster if you can publish the complete solution as a simple web page run in a browser. That will give me a reference for a correct working implementation. Please let me know if you're able done this!

Since the original problem covered by this issue is addressed, I'll close it now.

NicolasDorier commented 5 years ago

Sure will do.