HOME

TheInfoList



OR:

AssemblyScript is a
TypeScript TypeScript is a free and open source programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are ...
-based
programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
that is optimized for, and statically compiled to,
WebAssembly WebAssembly (sometimes abbreviated Wasm) defines a portable binary-code format and a corresponding text format for executable programs as well as software interfaces for facilitating interactions between such programs and their host environment ...
(currently using , the reference AssemblyScript compiler). Resembling
ECMAScript ECMAScript (; ES) is a JavaScript standard intended to ensure the interoperability of web pages across different browsers. It is standardized by Ecma International in the documenECMA-262 ECMAScript is commonly used for client-side scripting o ...
and
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
, but with static types, the language is developed by the AssemblyScript Project with contributions from the AssemblyScript community.


Overview

In 2017, the availability of support for
WebAssembly WebAssembly (sometimes abbreviated Wasm) defines a portable binary-code format and a corresponding text format for executable programs as well as software interfaces for facilitating interactions between such programs and their host environment ...
, a standard definition for a low-level
bytecode Bytecode (also called portable code or p-code) is a form of instruction set designed for efficient execution by a software interpreter. Unlike human-readable source code, bytecodes are compact numeric codes, constants, and references (norma ...
and an associated
virtual machine In computing, a virtual machine (VM) is the virtualization/emulation of a computer system. Virtual machines are based on computer architectures and provide functionality of a physical computer. Their implementations may involve specialized hardw ...
, became widespread among major
Web browsers A web browser is application software for accessing websites. When a user requests a web page from a particular website, the browser retrieves its files from a web server and then displays the page on the user's screen. Browsers are used on ...
, providing Web developers a lower-level and potentially higher-performance compilation target for
client-side Client-side refers to operations that are performed by the client in a client–server relationship in a computer network. General concepts Typically, a client is a computer application, such as a web browser, that runs on a user's local comput ...
programs and applications to execute within Web browsers, in addition to the interpreted (and in practice dynamically compiled)
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
Web scripting language. WebAssembly allows programs and code to be statically compiled ahead of time in order to run at potentially native-level or “
bare-metal In computer science, bare machine (or bare metal) refers to a computer executing instructions directly on logic hardware without an intervening operating system. Modern operating systems evolved through various stages, from elementary to the pre ...
” performance within Web browsers, without the overhead of interpretation or the initial latency of dynamic compilation. With the adoption of WebAssembly in major Web browsers, Alon Zakai, creator of Emscripten, an
LLVM LLVM is a set of compiler and toolchain technologies that can be used to develop a front end for any programming language and a back end for any instruction set architecture. LLVM is designed around a language-independent intermediate repre ...
/
Clang Clang is a compiler front end for the C, C++, Objective-C, and Objective-C++ programming languages, as well as the OpenMP, OpenCL, RenderScript, CUDA, and HIP frameworks. It acts as a drop-in replacement for the GNU Compiler Collection ...
-based C and
C++ C++ (pronounced "C plus plus") is a high-level general-purpose programming language created by Danish computer scientist Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significan ...
compiler that targeted a subset of
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
called asm.js, added support for WebAssembly as a compilation target in Emscripten, allowing C and/or C++ programs and code to be compiled directly to WebAssembly. While Emscripten and similar compilers allow Web developers to write new code, or
port A port is a maritime facility comprising one or more wharves or loading areas, where ships load and discharge cargo and passengers. Although usually situated on a sea coast or estuary, ports can also be found far inland, such as Ham ...
existing code, written in a high-level language such as C, C++, Go, and
Rust Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxide-hydroxide (FeO(OH ...
to WebAssembly to achieve potentially higher, native-level execution performance in Web browsers, this forces Web developers accustomed to developing client-side Web scripts and applications in ECMAScript/JavaScript (the ''de facto'' client-side programming language in Web browsers) to use a different language for targeting WebAssembly than JavaScript. AssemblyScript, as a variant of TypeScript that is syntactically similar to JavaScript, allows developers accustomed to JavaScript to use a familiar language for targeting WebAssembly, potentially reducing the learning curve of a separate language that can be compiled to WebAssembly. Furthermore, because AssemblyScript was designed to be an optimal source language for WebAssembly, the language’s type system closely reflects that of WebAssembly, and the language provides standard low-level functions (typically implemented as macros) that map directly to WebAssembly instructions that mirror instructions available on modern processors such as
SIMD Single instruction, multiple data (SIMD) is a type of parallel processing in Flynn's taxonomy. SIMD can be internal (part of the hardware design) and it can be directly accessible through an instruction set architecture (ISA), but it shoul ...
and
vector Vector most often refers to: *Euclidean vector, a quantity with a magnitude and a direction *Vector (epidemiology), an agent that carries and transmits an infectious pathogen into another living organism Vector may also refer to: Mathematic ...
instructions and more specialized instructions such as clz (count leading zero bits), ctz (count trailing zero bits), and popcnt ( population count), used in applications such as encryption and cryptographic libraries. , the reference AssemblyScript compiler, is based on Binaryen, a back-end compiler toolchain developed by Alon Zakai that compiles to WebAssembly and is a component of Emscripten (which Zakai also developed). The compiler and other tooling are available via the npm package manager. While WebAssembly was originally designed for execution within Web browsers, the development of WASI (WebAssembly System Interface), a community specification for a standard
API An application programming interface (API) is a way for two or more computer programs to communicate with each other. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how ...
that allows WebAssembly programs access to system calls and other
operating system An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs. Time-sharing operating systems schedule tasks for efficient use of the system and may also in ...
functions, has led to the development of WebAssembly runtime environments from projects such as Wasmtime and Wasmer that allow WebAssembly, and code written in languages such as AssemblyScript that can compile to it, to run in non-Web environments as well.


Compatibility with JavaScript

AssemblyScript is compiled to WebAssembly modules, which can then be instantiated into client-side Web pages using standard JavaScript methods such as WebAssembly.compileStreaming and WebAssembly.instantiateStreaming just like standard WebAssembly binaries. Data passing between JavaScript and the compiled WebAssembly modules, as well as function calls between JavaScript and WebAssembly, are then the same as for any WebAssembly module. Because the AssemblyScript language is largely a subset of TypeScript, it is theoretically possible to write an AssemblyScript program using this subset and compile it to both plain JavaScript and WebAssembly, using the TypeScript compiler and AssemblyScript compiler, respectively. This potentially allows for portable code that can be deployed in either JavaScript or WebAssembly run-time environments.


Usage

more than 12,000 projects hosted on
GitHub GitHub, Inc. () is an Internet hosting service for software development and version control using Git. It provides the distributed version control of Git plus access control, bug tracking, software feature requests, task management, continuous ...
are written, either wholly or partially, in AssemblyScript, with roughly 18,000 downloads of the AssemblyScript compiler per week via npm. In 2021,
Webpack Webpack is a free and open-source module bundler for JavaScript. It is made primarily for JavaScript, but it can transform front-end assets such as HTML, CSS, and images if the corresponding loaders are included. Webpack takes modules with depen ...
started using AssemblyScript to speed up the calculation of hash functions such as xxhash and md
sources
This also made it possible to get rid of native dependencies.


Reception

Lead Emscripten developer Alon Zakai has characterized AssemblyScript as being “designed with WebAssembly and code size in mind. It’s not an existing language that we are using for a new purpose, but it’s a language designed for WebAssembly. It has great wasm-opt integration—in fact, it’s built with it—and it’s very easy to get good code size.” Norwegian musician Peter Salomonsen, in a 2020 WebAssembly Summit talk titled, “WebAssembly Music,” demonstrated the use of AssemblyScript for real-time compilation to WebAssembly in live electronic music synthesis, saying, “I chose AssemblyScript because it has high-level readability and low-level control; it’s like a high-level language, but you get that low-level feeling, and you can even write direct WebAssembly intrinsics if you want to.” Aaron Turner, a senior engineer at
Fastly Fastly is an American cloud computing services provider. It describes its network as an edge cloud platform, which is designed to help developers extend their core cloud infrastructure to the edge of the network, closer to users. The Fastly edge ...
, a cloud computing services provider that uses WebAssembly for the company’s Compute@Edge serverless compute environment, in a review of AssemblyScript wrote:
While AssemblyScript requires stricter typing than TypeScript does, it sticks as close as possible to TypeScript syntax and semantics—which means that most JavaScript developers will find AssemblyScript comfortable to use—and it enables great support for the modern JavaScript ecosystem. For instance, the AssemblyScript compiler is available on , as well as common AssemblyScript tools and libraries like . AssemblyScript files also use TypeScript’s ‘’ file extension, and it includes proper typings for allowing AssemblyScript to piggy-back on TypeScript tooling, such as the TypeScript linter. With the right small tweaks, AssemblyScript can even be used with the TypeScript compiler. This is very exciting, as AssemblyScript offers a low-overhead entry-point for JavaScript developers to pick up a language to output WebAssembly—both in terms of learning to read and write AssemblyScript, as well as using a lot of the pre-existing tooling that may already be in a JavaScript developer’s workflow. AssemblyScript is often referred to in the WebAssembly community as a great gateway to picking up WebAssembly. It offers a large group of developers who already write applications for the web a path to pick up and learn WebAssembly. Even if you are starting from scratch and are not particularly familiar with JavaScript or TypeScript, AssemblyScript is a solid choice when picking a language to start outputting WebAssembly.
However, Turner went on to cite the language’s relative newness and thus its lack of some features available in larger, more complex and established programming languages as potential but temporary shortcomings of the language.


See also

* Emscripten *
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of Website, websites use JavaScript on the Client (computing), client side ...
*
TypeScript TypeScript is a free and open source programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are ...
*
WebAssembly WebAssembly (sometimes abbreviated Wasm) defines a portable binary-code format and a corresponding text format for executable programs as well as software interfaces for facilitating interactions between such programs and their host environment ...


References


External links


AssemblyScript.org
(official site)

(project page)
The AssemblyScript Project
(on GitHub)
assemblyscript
(on npm) {{JavaScript, state=collapsed TypeScript JavaScript programming language family Statically typed programming languages Cross-platform software Software using the Apache license