Coder Social home page Coder Social logo

docs's Introduction

description
Let's attempt the unthinkable, shall we?

Introduction

AssemblyScript compiles a strict subset of TypeScript (a typed superset of JavaScript) to WebAssembly using Binaryen, looking like:

{% code-tabs %} {% code-tabs-item title="fib.ts" %}

export function fib(n: i32): i32 {
  var a = 0, b = 1;
  for (let i = 0; i < n; i++) {
    let t = a + b; a = b; b = t;
  }
  return b;
}

{% endcode-tabs-item %} {% endcode-tabs %}

$> asc fib.ts -b fib.wasm -O3

Its architecture differs from a JavaScript VM in that it compiles a program ahead of time, quite similar to other static compilers. On top of WebAssembly types, it provides both low-level built-ins to access WebAssembly features directly as well as a JavaScript-like standard library on top of a relatively small managed runtime enabling the creation of programs that look and feel much like TypeScript.

For example, on the lowest level, memory can be accessed using the load<T>(offset) and store<T>(offset, value) built-ins that compile to WebAssembly instructions directly

store<i32>(8, load<i32>(0) + load<i32>(4));

while the standard library provides implementations of ArrayBuffer , Uint8Array , String , Map etc. on a higher level:

var view = new Int32Array(12);
view[2] = view[0] + view[1];

The compiler still has its limitations and we are still waiting for WebAssembly features that are currently undergoing specification (marked as ๐Ÿฆ„ throughout the documentation) to unleash its full potential. But it is open source and everyone can contribute, so we are getting there.

Sounds appealing to you? Read on!

docs's People

Contributors

dcodeio avatar gitbook-bot avatar maxgraey avatar nidin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.