Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
July 30, 2019 07:01 pm GMT

There's a Mountain to Climb

AssemblyScript is a TypeScript to Web Assembly compiler. It's currently maturing at a very fast rate, but like all projects, it requires a lot of hard work and dedication to become better. The call of responsibility must be heeded to obtain the gold from the dragon's den.

GitHub logo AssemblyScript / assemblyscript

Definitely not a TypeScript to WebAssembly compiler

AssemblyScript

Build Status

AssemblyScript compiles a strict subset of TypeScript (basically JavaScript with types) to WebAssembly using Binaryen. It generates lean and mean WebAssembly modules while being just an npm install away.

Check out the documentation or try it out in WebAssembly Studio!

Our Sponsors

Our Backers

The core team members and most contributors do this open source work in their free time. If you use AssemblyScript for a serious task or plan to do so, and you'd like us to invest more time on it, please donate to our OpenCollective. By sponsoring this project, your logo will show up above. Thank you so much for your support!

Motivation

You are now able to write WebAssembly, without learning a new language, and harness all these benefits WebAssembly might offer you. I think that is kind of powerful. [...] It [AssemblyScript] is absolutely usable, and very enjoyable! - Surma, WebAssembly





Some of the functions in the std library are currently incomplete. This isn't because the creators are incompetent at all! There's just a mountain of work to be done. If you happen to be an expert in the algorithms required to implement the JavaScript prototypes, there is a very large possibility you could contribute to AssemblyScript in a very big way! There is plenty of low hanging fruit you could grab at!

Some of the functions that I personally helped implement are quite large and hard to read, but the payoff was worth it. For example, I helped introduce the MAP<T>() higher-order function last year that enabled the TypedArray.prototype.map function to get implemented in an earlier version of AssemblyScript. Since then, the function had to be reimplemented because the memory model for AssemblyScript changed (for the better.) As an example, this is what the MAP higher-order function looks like today.

// @ts-ignore: This is a top level decorator that can be used in AssemblyScript@inline// ArrayBufferView is the parent class for Array<T> and TypedArray.// AssemblyScript uses ArrayBuffers to represent raw heap allocations. function MAP<TArray extends ArrayBufferView, T>(  array: TArray,  fn: (value: T, index: i32, self: TArray) => T,): TArray {  var length = array.length;  // get the usize pointer to the start of the source ArrayBuffer  var dataStart = array.dataStart;  // create a new array to store the results  var out = instantiate<TArray>(length);  // get the usize pointer to the start of the result array  var outDataStart = out.dataStart;  // for each item in the source array  for (let i = 0; i < length; i++) {    // store it in the result array    store<T>(      // This calculation depends on the type of the TypedArray.      // alignof<T>() helps us to calculate how many bytes are needed to store      // the result in Web Assembly linear memory.      outDataStart + (<usize>i << alignof<T>()),      // call the function for each source element      fn(load<T>(dataStart + (<usize>i << alignof<T>())), i, array)    );  }  // return the result  return out;}

The ArrayBuffer class is the cornerstone of this function. Using a specialized ArrayBufferView class, we can store a pointer to the start of the data in linear Web Assembly memory and treat it like JavaScript treats ArrayBuffer instances.

It even comes with it's own array accessor methods.

  @operator("[]") // unchecked is built-in  private __get(index: i32): f64 {    if (<u32>index >= <u32>this.dataLength >>> alignof<f64>()) throw new RangeError(E_INDEXOUTOFRANGE);    return load<f64>(this.dataStart + (<usize>index << alignof<f64>()));  }  @operator("[]=") // unchecked is built-in  private __set(index: i32, value: f64): void {    if (<u32>index >= <u32>this.dataLength >>> alignof<f64>()) throw new RangeError(E_INDEXOUTOFRANGE);    store<f64>(this.dataStart + (<usize>index << alignof<f64>()), value);  }

This is the Float64Array __get and __set methods currently used in the std library. These functions are hard to read if you're a beginner and know nothing about bitwise operators, but that doesn't mean you won't understand it with a little studying and elbow grease.

If you think you have the time and energy to help out, you can also check out the following project to see what is possible using AssemblyScript.

GitHub logo AssemblyScript / node

Implementations of the node.js APIs for use with AssemblyScript.

AS node

Implementations of the node.js APIs for AssemblyScript, utilizing WASI.

Introduction

This library aims to provide a convenient node.js-like environment for AssemblyScript programsPlease note that it is still in its early stages and that both the library and WASI are not evenclose to be finalized.

As always, if the idea sounds appealing to you, feel free to improve existing APIs or to contributeadditional ones.

Instructions

Install the library components as a dependency of your project

$> npm install --save-dev AssemblyScript/node

and include it in your build step to gain access to the implementations it provides:

$> asc --lib ./node_modules/@assemblyscript/node/assembly [...]

Doing so will automatically register common globals like the Buffer class and enables requiringfor example the filesystem module through import * as fs from "fs".

Documentation

Building

To run the tests, first make sure that

This library was born because the community was asking for a node Buffer implementation. It plans on using the WASI interfaces to access the system level APIs while cutting corners where it makes sense. At the moment, the Buffer class could use plenty of work, and people who are experts in the algorithms currently used by node.js could find a deep challenge in implementing these modules and functions.

If testing is your thing, and you want to help AssemblyScript develop its tooling, there's a whole testing framework I developed called as-pect.

GitHub logo jtenner / as-pect

Blazing fast testing with AssemblyScript

jtenner/as-pect

This packages is a monorepo that contains the cli and the core for the @as-pectpackages.

Greenkeeper badgeBuild StatusCoverage Status

Write your module in AssemblyScript and get blazing fast bootstrapped testswith WebAssembly speeds!

Table of contents

  1. Philosophy
  2. Usage
  3. Comparisons
  4. Configuration File
  5. Types And Tooling
  6. CI Usage
  7. AssemblyScript Compiler Options
  8. Reporters
  9. Portability
  10. RTrace and Memory Leaks
  11. Performance Testing
  12. Custom Imports Using CLI
  13. Using as-pect as a Package
  14. Contributors

Philosophy

Testing is the first step of every project and you have a responsibility tomake sure that the software you write works as intended. The as-pect projectwas created to help quickly scaffold and bootstrap AssemblyScript tests sothat you can be confident in yourself and the software you write.

One of the goals of this project is 100% portability to jest so that tests

This cli tool is designed to help developers bootstrap their tests with as little downtime as possible.

Are you afraid to get started or need to immerse yourself in the community first? Feel free to message me here on dev.to to get access to our Slack server. There are plenty of people waiting to help you get started and we definitely don't want to do this all the hard work ourselves.

There's a mountain waiting to be climbed, and you could climb it. That is, if you think you're up for the challenge.

Best Regards,
@jtenner


Original Link: https://dev.to/jtenner/there-s-a-mountain-to-climb-3402

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To