assemblyscript/README.md

91 lines
3.4 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)
This repository contains compiler components for the next iteration of the AssemblyScript compiler written in AssemblyScript itself.
2017-09-28 13:08:25 +02:00
Note that the code uses some features and standard library components that are not yet supported by any version of asc. To account for this, the code has been written in "portable AssemblyScript", a TypeScript-compatible subset of a subset of a superset of JavaScript, that also compiles to JavaScript using TSC.
Why is this necessary?
----------------------
Well, it isn't, but: In order to be able to compile the AssemblyScript compiler itself to WebAssembly eventually, we cannot depend on TypeScript because it is written in vanilla TypeScript and makes use of quite a few non-AOT-compatible dynamic features of JavaScript.
Cons:
- A lot of work
- Dealing with TypeScript compatibility issues
Pros:
- One day compiling to WebAssembly for performance
- Necessary features only, reducing binary size
- Linking against Binaryen compiled to WebAssembly, reducing overhead
Side effects:
- Good fire test for the compiler
- Good benchmark when comparing both versions
- Benefits standard library design ideas
2017-12-05 13:35:14 +01:00
How does it work?
-----------------
2017-12-09 00:45:12 +01:00
AssemblyScript NEXT compiles a subset (or variant) of TypeScript to [Binaryen](https://github.com/WebAssembly/binaryen) IR. The resulting module can then be optimized, emitted in text or binary format or converted to [asm.js](http://asmjs.org) as a polyfill.
2017-12-05 13:35:14 +01:00
Getting started
---------------
If you'd like to try out NEXT today or even plan to contribute, this is how you do it:
```
$> git clone https://github.com/AssemblyScript/next.git
$> cd next
$> npm install
$> node bin\asc yourModule.ts
```
Building an UMD bundle to `dist/assemblyscript.js` (does not bundle [binaryen.js](https://github.com/AssemblyScript/binaryen.js)):
2017-12-05 13:35:14 +01:00
```
$> npm run build
```
Running the [tests](./tests):
```
$> npm test
```
Development status
------------------
For now, see the [compiler tests](https://github.com/AssemblyScript/next/tree/master/tests/compiler) for an overview of what's supposed to be working already.
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.
none Do not modify 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 directly via [ts-node](https://www.npmjs.com/package/ts-node). Useful for development.