AssemblyScript: A variant of TypeScript targeting WebAssembly
assemblyscript.org
assemblyscript.org
So if you want to write a low-level WASM code in WebAssembly text format (WAT), it is probably a good idea to use AssemblyScript instead.
Honestly I'm all for it, and wouldn't change much since most JavaScript written today goes through compilation anyway (TypeScript and/or Babel). Only executing bytecode and taking out JavaScript parsers/interpreters would simplify browser implementations too. Just... what a roundabout trip it has been.
COBOL Common Lisp Haskell JavaScript
Most of the languages are not similar to Java.
You're probably thinking of something like cpythons bytecode which is unstable internal only thing (breaking compatibility with minor python versions). Java bytecode has to be stable since it had to be shared by multiple jvm implementations. And even then a famous ruby hacker made a ruby-to-python-bytecode-compiler(now probably broken by version changes).
No. There are far more languages that compile to Wasm.
Let’s not forget that when applets were a thing Java was a proprietary, although liberally licensed, from Sun Microsystems and the only JVM available was though them. I don’t even know what the status of it is to this day even though there are far more options than there were then.
I didn’t touch Java for years because it was risky to invest time and energy into a language were the owner, Sun and now Oracle, could just yank it or start charging for the JDK at any time. It only became safe when it was successful enough that it became unlikely that thy would do something like that and there started to be viable alternatives. It’s easy to forget that Java had a huge cloud over its head foe many years.
* Can JS functions call Assemblyscript functions? * Can AssemblyScript functions call JS functions? * Can Assemblyscript manipulate Javascript objects? Or is the communication restricted to low-level types such as integers, WASM byte arrays, and so forth?
There are also exists other projects which simplify this: https://github.com/torch2424/as-bind
1. AssemblyScript functions can be exposed to Javascript via the loader utility. If the arguments are primitive types then calling them is straightforward. Complex types like strings and arrays must be converted between the JS version of the type and the AS version of the type.
2. AssemblyScript code cannot call Javascript functions or directly manipulate Javascript objects. However, Javascript objects and functions can be passed around as an opaque anyref.
Opaque anyref (externref) or reference-types WebAssembly proposal not yet in all browsers, but after it interop will become much easier. At least you don't need glue code for JS side any more.
I had seen it a while ago when it was still very early and the amount of work that has been done is phenomenal.
I think the documentation and examples are also very polished and make me really want to start using this.
Congrats to the developers, I wish I could upvote this more!
I guess AssemblyScript isn't self-hosted (yet)? Seems like your life might be easier if you could compile the compiler to WASM.
Would a JavaScript interpreter be too slow for your use case? I can find a few of those written in Rust (e.g. https://github.com/boa-dev/boa), although some look abandoned and others seem incomplete.
Serious question: I feel like I am missing the use case for something like this - is it primarily useful for multi-tenant scenarios where you want to sandbox the workload or ??
Its minimal runtime can be run outside of browser easily. Even Rust requires complex interfaces, requires big runtime binaries to run on WASM, and it sometimes is not portable that it can run only on browsers.
So it sounds like it's not aligned-enough to take advantage of TS's expansive ecosystem? It's more just "a high-level language designed for WASM, with syntactic decisions familiar to people who know TS but which don't actually make it compatible". That's a much less compelling proposition
However, because it’s not actually compiling to JavaScript like typescript is normally, this means there must be quirks and differences that must be understood to solve harder problems. Depending on how friendly the compiler is, this can be very painful or intuitive.
I’m guessing it’s infeasible to compile TS to WASM since they’re targeting very different outputs - a ahead of time, dynamic weakly typed scripting language can’t possibly be compatible with an ahead of time, strongly typed, binary output.
And if someone tells you it is, I suspect they’re doing a lot of magic that’s hiding problems that only become obvious after writing nontrivial programs.
On Firefix and Safari we have the same missing optimizations. Basically wasm in all browsers reuse the same codegen from JS. But this will improved in the future.
Also, don't forget about SIMD, multi-threading with stared buffers and atomics and multi-values, a lot of special instructions like popcnt, ctz, clz, rotl/rotr and etc which not supported by JS and usually emulate not in the best way that complicates or make impossible to optimize this by the JS compiler.
In some points JS is really fast, so much that it is not inferior, for example, to the C language with the LLVM compiler without vectorization (-O2). Obviously WebAssembly can't outperform JS in such cases.
https://medium.com/@robaboukhalil/webassembly-and-simd-7a7da...
https://news.ycombinator.com/item?id=20079367
DonHopkins on June 3, 2019 | parent | favorite | on: Compiling C to WebAssembly Without Emscripten
Anybody used or have opinions about AssemblyScript? https://github.com/AssemblyScript/assemblyscript
>AssemblyScript compiles strictly typed TypeScript (basically JavaScript with types) to WebAssembly using Binaryen. It generates lean and mean WebAssembly modules while being just an npm install away.
https://dev.to/jtenner/an-assemblyscript-primer-for-typescri...
Here's a great example of a project that uses it:
https://github.com/torch2424/wasmboy
>Gameboy Emulator Library written in Web Assembly using AssemblyScript, Debugger/Shell in Preact
Here's an excellent talk about wasmboy by the author, Aaron Turner -- he's done some really outstanding work:
https://www.youtube.com/watch?v=ZlL1nduatZQ
Since you can compile AssemblyScript into JavaScript with the TypeScript compiler as well as into WebAssembly, you can compare the speed of JavaScript -vs- WebAssembly on the same source code. Aaron did some interesting benchmarks using wasmboy, in the great tradition of using GameBoy emulators to benchmark JavaScript engines:
https://medium.com/@torch2424/webassembly-is-fast-a-real-wor...
Aaron Turner posted this useful link to a good AssemblyScript example a while ago: https://news.ycombinator.com/threads?id=torch2424
torch2424 7 months ago | unvote | parent [-] | on: Walt: JavaScript-like syntax for WebAssembly
I help out every once and a while on the AssemblyScript team with like issues, docs, and things. And made wasmboy, which uses AssemblyScript:
https://github.com/torch2424/wasmBoy
But that being said, usually when people are interested in the language, we usually direct them to the "n-body" example: https://github.com/AssemblyScript/assemblyscript/blob/master... . Which kind of looks more typescript-y :)
Also, just to stay on topic, I think walt is awesome. Stoked to see so many projects coming up with a "Wasm for JS devs" approach/story.
torch2424 on June 3, 2019 [–]
Hello!
Aaron Turner here, thank you for all the kind words! :) Yes I did all those things, and stoked to see people excited about it!
Definitely feel free to reach out anytime about AssemblyScript or WasmBoy. Would love to chat with you / anyone interested.
We also have a slack channel you can reach out and get invited to (see the wiki sidebar): https://github.com/AssemblyScript/assemblyscript/wiki
Thanks again!
https://mathworld.wolfram.com/BinetsFibonacciNumberFormula.h...