News for hackers. Stuff that matters.
Re:WebAssembly Browser Preview by wvenable on Monday October 31, 2016 @01:11PM (#12838721)
Is there any sort of open source non-browser interpreter for Webassembly?
Re:WebAssembly Browser Preview by dschuff on Monday October 31, 2016 @01:41PM (#12839062)
WABT (https://github.com/WebAssembly/wabt/) and Binaryen (https://github.com/WebAssembly/binaryen) as well as the spec itself (https://github.com/WebAssembly/spec/tree/master/interpreter) all have interpreters for the WebAssembly language. What they don't have is the same import and export binding mechanisms that the JavaScript engines have. JS engines can bind wasm imports and exports with JS functions. The interpreters that exist today are great for testing implementations or compilers but don't have interesting capabilities to interact with an embedding environment. There have been a few experiments with non-JS embeddings (for example, implementations build on LLVM which could easily define bindings to native functions) but nothing really usable or productized yet.
Re:WebAssembly Browser Preview by kibwen on Monday October 31, 2016 @01:22PM (#12838857)
There are nascent plans from the Rust project to retrofit Spidermonkey's WASM compiler (called Cretonne, and which is apparently already written in Rust) to serve as a general-purpose compiler backend: https://internals.rust-lang.org/t/possible-alternative-compi...
Re:WebAssembly Browser Preview by AgentME on Monday October 31, 2016 @02:01PM (#12839277)
What does that have to do with a non-browser interpreter? I think you might've responded to the wrong post.
Re:WebAssembly Browser Preview by kibwen on Monday October 31, 2016 @02:23PM (#12839529)
I believe I've responded to the right post. :) Currently, WASM (and Javascript, when JIT'ed) are lowered to Cretonne IR, which is then optimized and translated to native code by the Cretonne engine, which is then executed by Spidermonkey. What the link above is proposing is to extract Cretonne into a standalone component capable of producing object files which can be linked into other programs as expected. The Rust project would intend to use such a backend by writing a pass to translate Rust to Cretonne IR. However, the important observation is that WASM and Javascript are already being translated to Cretonne IR, which means that if the Rust developers do the work of creating a standalone backend out of Cretonne, then WASM and Javascript should be able to leverage it to produce code that's independent of the browser (though for JS you'd probably need to implement some additional external runtime support).
Re:WebAssembly Browser Preview by AgentME on Monday October 31, 2016 @05:26PM (#12841039)
So Rust is considering making a general backend which compiles to WASM first and then compiling that to native code, which could be faster and means that they would be creating a general WASM->native compiler in the process? That sounds pretty useful and clever if I'm getting it right.
Re:WebAssembly Browser Preview by kibwen on Monday October 31, 2016 @06:38PM (#12841596)
You're close (it's tricky to follow all these things feeding into all these other things). What they have right now is a prototype WASM -> IR -> pseudo-native code compiler (producing code only fit for being directly executed by a JS VM). What they're proposing is to flesh out the native code backend so that its output can be fed into the usual platform-native compiler toolchains. Then, they'd modify the Rust compiler to be able to produce the IR that this project (Cretonne) operates upon (which may be similar to, but is not precisely, WASM). So Rust would not be producing WASM directly, it would be producing code that is conceptually one level "below" WASM, but still one level above machine code. And yes, in the process this work would also enable the lower levels of a platform-native WASM toolchain.
Re:WebAssembly Browser Preview by icefox on Monday October 31, 2016 @04:58PM (#12840870)
WAVM https://github.com/AndrewScheidecker/WAVM

Which has some nice capabilities such as the ability to call functions with arguments from the command line

wavm ../Test/spec/fac.wast --function fac-iter 5

stdin/stderr/stdout is also supported for pure command line applications all while being sandboxed.

Re:WebAssembly Browser Preview by pizlonator on Monday October 31, 2016 @03:04PM (#12839886)
Part of the spec is a reference interpreter written in OCaml.

Edit: link: https://github.com/WebAssembly/spec/tree/master/interpreter

Re:WebAssembly Browser Preview by nickpsecurity on Monday October 31, 2016 @06:47PM (#12841654)
A semi-formal, reference spec done declaratively in Ocaml using s-expressions for the AST? When did The Right Thing become popular in browser developments!? I'm impressed. Way better than trying to get compatible, correct implementations out of a pile of English and text art as done by some other groups.
Re:WebAssembly Browser Preview by pizlonator on Monday October 31, 2016 @09:18PM (#12842583)
The jury is still out on whether this interpreter gets to be called a reference spec, or even a spec. It may be a reference interpreter that is offered as a companion to the official English text. It all depends on what others feel comfortable with.

But I'd rather that this OCaml program was _the_ spec. I found it enjoyable to read the other day when I was trying to figure out WebAssembly verification semantics. Much better than reading an English description of a verification algorithm.

Re:WebAssembly Browser Preview by m12k on Monday October 31, 2016 @01:25PM (#12838888)
Here's a Node package: https://www.npmjs.com/package/wasm
Re:WebAssembly Browser Preview by singularity2001 on Monday October 31, 2016 @05:26PM (#12841054)
That package is highly deprecated and unnecessary:

You can now simply do

node --expose-wasm

> buffer=fs.readFileSync('test.wasm')

> WebAssembly.compile(buffer)

Re:WebAssembly Browser Preview by binji on Monday October 31, 2016 @04:01PM (#12840366)
That appears to use https://github.com/WebAssembly/polyfill-prototype-1, which does not match the current binary format at all.

The current way to do the equivalent would be to use Binaryen's asm2wasm tool.

https://github.com/WebAssembly/binaryen

Re:WebAssembly Browser Preview by tsavola on Tuesday November 01, 2016 @07:00AM (#12844649)
Here's mine (although it's not an interpreter): https://github.com/tsavola/wag
Re:WebAssembly Browser Preview by dubcanada on Monday October 31, 2016 @01:19PM (#12838823)
I don't know how useful that would be, it's still javascript (just a lower level version of it) after all. It's coupled pretty tightly with the browser.
Re:WebAssembly Browser Preview by kibwen on Monday October 31, 2016 @01:28PM (#12838923)
I've also linked this in a sibling comment to yours, but this post from the Rust project developers talks about a few of the potential upsides to a general-purpose compiler backend derived from the WASM initiative: https://internals.rust-lang.org/t/possible-alternative-compi...

TL;DR: compilers written for the JIT use case are designed to minimize latency (compilation times) while still producing above-average code, so having such an alternative backend would be a boon for regular users of compilers with heavyweight backends (e.g. LLVM, which produces excellent code but at the cost of very large compilation times, even in unoptimized builds). Additionally, a compiler built to process WASM is more security-aware than your typical compiler, and thus won't include optimizations that attempt to exploit undefined behavior (thus losing out on potential optimizing opportunities, but hopefully producing code that's a bit more bulletproof).

Re:WebAssembly Browser Preview by aspirin on Monday October 31, 2016 @01:26PM (#12838896)
WASM isn't related to JavaScript in any way. Maybe you were thinking of asm.js?

You cannot access the browser APIs from WASM so there is no tight coupling with the browser environment. I think non-browser use could make definately sense.

Re:WebAssembly Browser Preview by detaro on Monday October 31, 2016 @01:38PM (#12839027)
According to the docs, high-level goals of WASM are to allow synchronous calls to and from JavaScript; enforce the same-origin and permissions security policies; access browser functionality through the same Web APIs that are accessible to JavaScript; ?

https://github.com/WebAssembly/design/blob/master/HighLevelG...

Re:WebAssembly Browser Preview by s3th on Monday October 31, 2016 @02:21PM (#12839517)
Here's how to interact with browser APIs and import/export functions via the WebAssembly JS API: http://webassembly.org/getting-started/js-api/
Re:WebAssembly Browser Preview by 0xdeadbeefbabe on Monday October 31, 2016 @01:34PM (#12838979)
> You cannot access the browser APIs from WASM

Do you have a reference? I'm confused about why you wouldn't want to access browser APIs.

Re:WebAssembly Browser Preview by aspirin on Monday October 31, 2016 @03:24PM (#12840063)
The high level goals of WASM do include access to browser APIs, but the MVP version that is being implemented now, does not yet allow it: https://github.com/WebAssembly/design/blob/master/JS.md

WASM code can call external functions defined per module, and the external code can be JS code that interacts with browser APIs. So indirect use of browser APIs is possible.

Re:WebAssembly Browser Preview by smitherfield on Monday October 31, 2016 @01:39PM (#12839034)
Right now it's more like Flash or Java applets, running in a sandbox within a sandbox.
Re:WebAssembly Browser Preview by TazeTSchnitzel on Monday October 31, 2016 @02:03PM (#12839305)
Huh? WebAssembly, like asm.js before it, can access Web APIs (albeit via JS).
Re:WebAssembly Browser Preview by hackcasual on Monday October 31, 2016 @03:22PM (#12840043)
Not exactly. You have to export those APIs into the WebAssembly module. It's certainly possible to have a WASM implementation that doesn't provide web APIs, but is still WASM.
Re:WebAssembly Browser Preview by rubber_duck on Monday October 31, 2016 @01:38PM (#12839021)
As others said it has nothing to do with JS, i'd like to add how it's usefull - it's a low level VM spec (lower than say JVM or CLR) so it will hopefully be easy to compile various languages to it (hopefully because they need to fit a GC mechanism in to it yet to support higher level languages) but it's still safe/sandboxed and portable.
Re:WebAssembly Browser Preview by Touche on Monday October 31, 2016 @01:25PM (#12838889)
I think you're confusing asm.js with wasm. wasm is not JavaScript.