assemblyscript/README.md

86 lines
3.6 KiB
Markdown
Raw Normal View History

2017-09-28 13:08:25 +02:00
AssemblyScript NEXT
===================
2017-12-02 20:58:39 +01:00
[![Build Status](https://travis-ci.org/AssemblyScript/next.svg?branch=master)](https://travis-ci.org/AssemblyScript/next)
2017-12-12 01:35:48 +01:00
**AssemblyScript** is a new compiler targeting [WebAssembly](http://webassembly.org) while utilizing [TypeScript](http://www.typescriptlang.org)'s syntax and [node](https://nodejs.org)'s vibrant ecosystem. Instead of requiring complex toolchains to set up, you can simply `npm install` it - or run it in a browser.
2017-09-28 13:08:25 +02:00
By compiling a variant of TypeScript to [Binaryen](https://github.com/WebAssembly/binaryen) IR, the resulting module can be validated, optimized, emitted in WebAssembly text or binary format and converted to [asm.js](http://asmjs.org) as a polyfill.
2017-09-28 13:08:25 +02:00
The compiler itself is written in "portable AssemblyScript" so it can be compiled to both JavaScript using `tsc` and, eventually, to WebAssembly using `asc`.
2017-09-28 13:08:25 +02:00
Development status
------------------
This version of the compiler (0.5.0, NEXT) is relatively new and does not yet support some features a TypeScript programmer might expect, e.g., strings, arrays and classes. For now, you can see the [compiler tests](https://github.com/AssemblyScript/next/tree/master/tests/compiler) for an overview of what's supposed to be working already.
A few early examples to get an idea:
2017-12-11 18:56:32 +01:00
* **memcpy** using load/store derived from [musl](http://www.musl-libc.org)<br />
[source](./tests/compiler/memcpy.ts) - [wast](./tests/compiler/memcpy.optimized.wast)
* **Conway's Game of Life** as seen on [dcode.io](http://dcode.io)<br />
[source](./tests/compiler/game-of-life.ts) - [wast](./tests/compiler/game-of-life.optimized.wast) - [html](./tests/compiler/game-of-life.html)
2017-12-11 22:04:30 +01:00
* **i64 polyfill** using 32-bit integers<br />
[source](./tests/compiler/i64.ts) - [wast](./tests/compiler/i64.optimized.wast)
2017-12-05 13:35:14 +01:00
Getting started
---------------
If you'd like to try it today or even plan to contribute, this is how you do it:
2017-12-05 13:35:14 +01:00
```
$> git clone https://github.com/AssemblyScript/next.git
$> cd next
$> npm install
```
2017-12-12 16:08:54 +01:00
Author your module in AssemblyScript ([definitions](./std/assembly.d.ts), [base config](./std/assembly.json)) or portable AssemblyScript ([definitions](./std/portable.d.ts), [base config](./std/portable.json)) and run:
2017-12-05 13:35:14 +01:00
```
2017-12-12 16:08:54 +01:00
$> node bin/asc yourModule.ts
2017-12-05 13:35:14 +01:00
```
2017-12-09 00:45:12 +01:00
Using the CLI
-------------
```
2017-12-09 02:52:20 +01:00
Syntax: asc [options] [entryFile ...]
2017-12-09 00:45:12 +01:00
Examples: asc hello.ts
2017-12-09 02:52:20 +01:00
asc hello.ts -b hello.wasm -t hello.wast -a hello.js
asc hello.ts -b > hello.wasm
2017-12-09 00:45:12 +01:00
Options:
-v, --version Prints the compiler's version.
-h, --help Prints this message.
-O, --optimize Optimizes the module.
-c, --validate Validates the module.
-o, --outFile Specifies the output file. Format is determined by file extension.
-b, --binaryFile Specifies the binary format output file (.wasm).
-t, --textFile Specifies the text format output file (.wast).
-a, --asmjsFile Specifies the asm.js format output file (.js).
--noTreeShaking Disables tree-shaking.
--noDebug Disables assertions.
--trapMode Sets the trap mode to use.
allow Allow trapping operations. This is the default.
clamp Replace trapping operations with clamping semantics.
js Replace trapping operations with JS semantics.
2017-12-09 00:45:12 +01:00
```
Unless a bundle has been built to `dist/`, `asc` runs the TypeScript sources on the fly via [ts-node](https://www.npmjs.com/package/ts-node). Useful for development.
Building
--------
Building an UMD bundle to `dist/assemblyscript.js` (does not bundle [binaryen.js](https://github.com/AssemblyScript/binaryen.js)):
```
$> npm run build
```
Running the [tests](./tests):
```
$> npm test
```