-
-
Notifications
You must be signed in to change notification settings - Fork 667
Home
AssemblyScript compiles a strictly-typed subset of TypeScript (a typed superset of JavaScript) to WebAssembly ahead of time. It is not really a language on its own, though it provides several new WebAssembly-specific types and built-ins, but rather a very similar dialect on top of a compiler variant that integrates with Binaryen, Emscripten's WebAssembly backend, instead.
It is both possible to write close-to-the-metal WebAssembly as well as portable code that compiles to WebAssembly using asc
and JavaScript using tsc
. As the syntax is just TypeScript, existing tooling can be used in development as well (e.g. for syntax highlighting and refactoring) and common code can easily be shared between the two compilers.
Note, though, that it is unlikely that existing TypeScript code "just works" with the AssemblyScript compiler because the code is not strict enough (yet). Remember, TypeScript is a superset of JavaScript and as such contains a lot of JS, while AssemblyScript drops a significant amount of the dynamicness of JavaScript. However, when taking care of the limitations, programs that are relatively strict already can be made compatible with the AssemblyScript compiler.
In order to work with classes and their instances, AssemblyScript includes an as-minimal-as-reasonable runtime for memory management and garbage collection on top of otherwise static memory with each binary. This is likely to receive more options once WebAssembly GC becomes available, but enables users to build something working today and, in the future, to use AssemblyScript in scenarios where the host doesn't provide GC capabilities, like blockchain.
Integrating with Binaryen provides rich validation, optimization (for size and/or speed) and output (WebAssembly text and binary format, asm.js, source maps) capabilities on top of that.